Skip to content

Commit e1de675

Browse files
J38Stanford NLP
authored andcommitted
update version
1 parent 40989cb commit e1de675

File tree

9 files changed

+259
-16953
lines changed

9 files changed

+259
-16953
lines changed

doc/corenlp/pom-full.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
</license>
1515
</licenses>
1616
<scm>
17-
<url>https://nlp.stanford.edu/software/stanford-corenlp-4.1.0.zip</url>
18-
<connection>https://nlp.stanford.edu/software/stanford-corenlp-4.1.0.zip</connection>
17+
<url>https://nlp.stanford.edu/software/stanford-corenlp-full-2020-07-31.zip</url>
18+
<connection>https://nlp.stanford.edu/software/stanford-corenlp-full-2020-07-31.zip</connection>
1919
</scm>
2020
<developers>
2121
<developer>

doc/releasenotes/v4.1.0/corenlp.out

Lines changed: 0 additions & 16938 deletions
This file was deleted.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package edu.stanford.nlp.international.german.process;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.util.Arrays;
6+
import java.util.List;
7+
import java.util.Properties;
8+
import java.util.stream.Collectors;
9+
10+
import org.junit.Before;
11+
import org.junit.Test;
12+
13+
import edu.stanford.nlp.ling.CoreAnnotations;
14+
import edu.stanford.nlp.ling.CoreLabel;
15+
import edu.stanford.nlp.pipeline.CoreDocument;
16+
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
17+
import edu.stanford.nlp.util.StringUtils;
18+
19+
/**
20+
* Testing for the module that alters tokenization during German NER.
21+
* German tokenization matches the CoNLL 2018 standard, but during
22+
* NER we want to use a tokenization that doesn't split on hyphens for
23+
* improved F1. The GermanNERCoreLabelProcessor merges tokens originally
24+
* split on hyphen, passes that token list to the CRFClassifier, and then
25+
* creates a final tokens list with the correct NER-related annotations.
26+
*/
27+
28+
public class GermanNERCoreLabelProcessorITest {
29+
30+
public StanfordCoreNLP pipeline;
31+
public GermanNERCoreLabelProcessor germanNERCoreLabelProcessor;
32+
33+
@Before
34+
public void setUp() {
35+
Properties props = StringUtils.argsToProperties("-props", "german");
36+
props.setProperty("annotators", "tokenize,ssplit");
37+
pipeline = new StanfordCoreNLP(props);
38+
germanNERCoreLabelProcessor = new GermanNERCoreLabelProcessor();
39+
}
40+
41+
public void runTestProcessorExampleNoTags(String text, List<String> goldProcessedTokens) {
42+
runTestProcessorExample(text, goldProcessedTokens, null, null);
43+
}
44+
45+
public void runTestProcessorExample(String text, List<String> goldProcessedTokens, List<String> tagsToApply,
46+
List<String> finalTags) {
47+
// tokenize and sentence split
48+
CoreDocument document = new CoreDocument(pipeline.process(text));
49+
// test processed tokens match expected tokenization pattern
50+
System.err.println("---");
51+
System.err.println("original tokens: "+document.sentences().get(0).tokensAsStrings());
52+
List<CoreLabel> processedTokens = germanNERCoreLabelProcessor.process(document.sentences().get(0).tokens());
53+
System.err.println("processed tokens: "+processedTokens.stream().map(
54+
tok -> tok.word()).collect(Collectors.toList()));
55+
assertEquals(goldProcessedTokens, processedTokens.stream().map(tok -> tok.word()).collect(Collectors.toList()));
56+
// if there are tags to apply, apply them
57+
if (tagsToApply != null) {
58+
for (int i = 0 ; i < tagsToApply.size() ; i++) {
59+
processedTokens.get(i).setNER(tagsToApply.get(i));
60+
}
61+
}
62+
List<CoreLabel> restoredTokens = germanNERCoreLabelProcessor.restore(document.tokens(), processedTokens);
63+
// test if tags were set correctly for the restored list
64+
if (finalTags != null) {
65+
List<String> restoredTags = restoredTokens.stream().map(tok -> tok.ner()).collect(Collectors.toList());
66+
assertEquals(finalTags, restoredTags);
67+
for (int i = 0 ; i < finalTags.size() ; i++) {
68+
restoredTokens.get(i).remove(CoreAnnotations.NamedEntityTagAnnotation.class);
69+
}
70+
}
71+
// test that restored tokens match the original tokenization
72+
System.err.println("restored tokens :"+restoredTokens.stream().map(tok -> tok.word()).collect(Collectors.toList()));
73+
assertEquals(document.tokens(), restoredTokens);
74+
}
75+
76+
@Test
77+
public void testProcessor() {
78+
// basic example
79+
// should split "Microsoft-Aktie" into "Microsoft", "-", and "Aktie", merge during NER, then restore to split
80+
String basicExample = "Die Microsoft-Aktie sank daraufhin an der Wall Street um über vier Dollar auf 89,87 Dollar.";
81+
List<String> basicGoldTokens = Arrays.asList("Die", "Microsoft-Aktie", "sank", "daraufhin", "an", "der",
82+
"Wall", "Street", "um", "über", "vier", "Dollar", "auf", "89,87", "Dollar", ".");
83+
List<String> basicTagsAppliedToProcessed = Arrays.asList("O", "MISC", "O", "O", "O", "O", "LOC", "LOC", "O", "O",
84+
"O", "O", "O", "O", "O", "O");
85+
List<String> basicFinalTags = Arrays.asList("O", "MISC", "MISC", "MISC", "O", "O", "O", "O", "LOC", "LOC", "O", "O", "O",
86+
"O", "O", "O", "O", "O");
87+
runTestProcessorExample(basicExample, basicGoldTokens, basicTagsAppliedToProcessed, basicFinalTags);
88+
// basic example with multiple instances
89+
// split both "Mathematik-Lehrpläne" and "Nordrhein-Westfalen"
90+
String multiBasicExample = "Es sei wichtig, daß sich ein breiter Kreis mit den von Heymann vorgelegten Thesen " +
91+
"beschäftigt, meint Ringel, denn immerhin sei dieser offizieller Berater bei der Erarbeitung neuer " +
92+
"Mathematik-Lehrpläne in Nordrhein-Westfalen.";
93+
List<String> multiBasicGoldTokens = Arrays.asList("Es", "sei", "wichtig", ",", "daß", "sich", "ein", "breiter",
94+
"Kreis", "mit", "den", "von", "Heymann", "vorgelegten", "Thesen", "beschäftigt", ",", "meint", "Ringel", ",",
95+
"denn", "immerhin", "sei", "dieser", "offizieller", "Berater", "bei", "der", "Erarbeitung", "neuer",
96+
"Mathematik-Lehrpläne", "in", "Nordrhein-Westfalen", ".");
97+
List<String> multiBasicTagsAppliedToProcessed = Arrays.asList("O", "O", "O", "O", "O", "O", "O", "O", "O", "O",
98+
"O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "MISC", "O",
99+
"LOC", "O");
100+
List<String> multiBasicFinalTags = Arrays.asList("O", "O", "O", "O", "O", "O", "O", "O", "O", "O",
101+
"O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "MISC",
102+
"MISC", "MISC", "O", "LOC", "LOC", "LOC", "O");
103+
runTestProcessorExample(multiBasicExample, multiBasicGoldTokens, multiBasicTagsAppliedToProcessed,
104+
multiBasicFinalTags);
105+
// not just letters example
106+
String notJustLettersExample = "Darüber hinaus gibt es Adobe - Trainings, Firmen-/Inhouse-Seminare sowie Coaching " +
107+
"für 1-2 Personen.";
108+
// triple example
109+
String tripleHyphenatedExample = "IG-Metall-Chef Klaus Zwickel hat in Mannheim überaus deutlich an diese Partei, " +
110+
"die auch die seine ist, als Verbündete appelliert.";
111+
// original tokenization throughout
112+
String originalHyphenSplitExample = "Mit dem Carsch - Haus verfügt der Stadtteil über ein Luxuskaufhaus.";
113+
// original tokenization throughout
114+
String wordEndingWithHyphenExample = "Rund 30 000 Tier- und Pflanzenarten sind weltweit in ihrer Existenz bedroht.";
115+
// original tokenization throughout
116+
String doubleHyphenExample = "Er will Ende November in Washington mit der US -- Regierung über den Friedensprozeß " +
117+
"sprechen.";
118+
}
119+
120+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package edu.stanford.nlp.pipeline;
2+
3+
import edu.stanford.nlp.international.german.process.GermanNERCoreLabelProcessor;
4+
import edu.stanford.nlp.ling.*;
5+
6+
import java.util.*;
7+
8+
/**
9+
* An Annotator that matches tokenization when German text is sent to CRFClassifier.
10+
* Note, this annotator just alters the document tokens, and is only meant for a
11+
* benchmarking test. This won't alter the list of sentence tokens.
12+
*/
13+
14+
public class GermanNERTokenizerAnnotator implements Annotator {
15+
16+
public GermanNERCoreLabelProcessor germanCoreLabelProcessor = new GermanNERCoreLabelProcessor();
17+
18+
@Override
19+
public void annotate(Annotation ann) {
20+
ann.set(CoreAnnotations.TokensAnnotation.class,
21+
germanCoreLabelProcessor.process(ann.get(CoreAnnotations.TokensAnnotation.class)));
22+
}
23+
24+
@Override
25+
public Set<Class<? extends CoreAnnotation>> requires() {
26+
return Collections.emptySet();
27+
}
28+
29+
@Override
30+
public Set<Class<? extends CoreAnnotation>> requirementsSatisfied() {
31+
return Collections.emptySet();
32+
}
33+
34+
35+
36+
}

pom-java-11.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>edu.stanford.nlp</groupId>
44
<artifactId>stanford-corenlp</artifactId>
5-
<version>4.1.0</version>
5+
<version>4.0.0</version>
66
<packaging>jar</packaging>
77
<name>Stanford CoreNLP</name>
88
<description>Stanford CoreNLP provides a set of natural language analysis tools which can take raw English language text input and give the base forms of words, their parts of speech, whether they are names of companies, people, etc., normalize dates, times, and numeric quantities, mark up the structure of sentences in terms of phrases and word dependencies, and indicate which noun phrases refer to the same entities. It provides the foundational building blocks for higher level text understanding applications.</description>
@@ -14,8 +14,8 @@
1414
</license>
1515
</licenses>
1616
<scm>
17-
<url>https://nlp.stanford.edu/software/stanford-corenlp-4.1.0.zip</url>
18-
<connection>https://nlp.stanford.edu/software/stanford-corenlp-4.1.0.zip</connection>
17+
<url>https://nlp.stanford.edu/software/stanford-corenlp-full-2020-04-16.zip</url>
18+
<connection>https://nlp.stanford.edu/software/stanford-corenlp-full-2020-04-16.zip</connection>
1919
</scm>
2020
<developers>
2121
<developer>
@@ -193,7 +193,7 @@
193193
<configuration>
194194
<artifacts>
195195
<artifact>
196-
<file>${project.basedir}/stanford-corenlp-4.1.0-models.jar</file>
196+
<file>${project.basedir}/stanford-corenlp-4.0.0-models.jar</file>
197197
<type>jar</type>
198198
<classifier>models</classifier>
199199
</artifact>

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>edu.stanford.nlp</groupId>
44
<artifactId>stanford-corenlp</artifactId>
5-
<version>4.1.0</version>
5+
<version>4.0.0</version>
66
<packaging>jar</packaging>
77
<name>Stanford CoreNLP</name>
88
<description>Stanford CoreNLP provides a set of natural language analysis tools which can take raw English language text input and give the base forms of words, their parts of speech, whether they are names of companies, people, etc., normalize dates, times, and numeric quantities, mark up the structure of sentences in terms of phrases and word dependencies, and indicate which noun phrases refer to the same entities. It provides the foundational building blocks for higher level text understanding applications.</description>
@@ -14,8 +14,8 @@
1414
</license>
1515
</licenses>
1616
<scm>
17-
<url>https://nlp.stanford.edu/software/stanford-corenlp-4.1.0.zip</url>
18-
<connection>https://nlp.stanford.edu/software/stanford-corenlp-4.1.0.zip</connection>
17+
<url>https://nlp.stanford.edu/software/stanford-corenlp-full-2020-04-16.zip</url>
18+
<connection>https://nlp.stanford.edu/software/stanford-corenlp-full-2020-04-16.zip</connection>
1919
</scm>
2020
<developers>
2121
<developer>
@@ -195,7 +195,7 @@
195195
<configuration>
196196
<artifacts>
197197
<artifact>
198-
<file>${project.basedir}/stanford-corenlp-4.1.0-models.jar</file>
198+
<file>${project.basedir}/stanford-corenlp-4.0.0-models.jar</file>
199199
<type>jar</type>
200200
<classifier>models</classifier>
201201
</artifact>

src/edu/stanford/nlp/ie/util/RelationTriple.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package edu.stanford.nlp.ie.util;
22

3-
import java.io.Serializable;
43
import java.text.DecimalFormat;
54
import java.util.*;
65
import java.util.function.ToIntFunction;
@@ -23,9 +22,7 @@
2322
* @author Gabor Angeli
2423
*/
2524
@SuppressWarnings("UnusedDeclaration")
26-
public class RelationTriple implements Comparable<RelationTriple>, Iterable<CoreLabel>, Serializable {
27-
28-
private static final long serialVersionUID = 43758623469716523L;
25+
public class RelationTriple implements Comparable<RelationTriple>, Iterable<CoreLabel> {
2926

3027
/** The subject (first argument) of this triple */
3128
public final List<CoreLabel> subject;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package edu.stanford.nlp.international.german.process;
2+
3+
import edu.stanford.nlp.ling.*;
4+
import edu.stanford.nlp.process.*;
5+
6+
import java.util.*;
7+
import java.util.function.*;
8+
9+
10+
/**
11+
* Class for mapping CoNLL 2018 tokenized German text to German NER tokenization
12+
* and vice versa. The CoNLL 2018 German tokenization splits words such as
13+
* "CDU-Parlamentarier" into "CDU", "-", and "Parlamentarier". This causes
14+
* a performance drop for German NER of several F1 points, so this module will
15+
* facilitate retokenizing CoNLL 2018 tokenized text to match our internal German
16+
* NER training data which does not split on hyphens. Post classification this
17+
* module can restore the tokenization to the CoNLL 2018 style.
18+
*/
19+
20+
public class GermanNERCoreLabelProcessor extends CoreLabelProcessor {
21+
22+
/** Check that after() is not null and the empty string **/
23+
public Function<CoreLabel, Boolean> afterIsEmpty = tok ->
24+
tok.containsKey(CoreAnnotations.AfterAnnotation.class) && tok.after().equals("");
25+
26+
/**
27+
* merge the contents of two tokens
28+
**/
29+
public static void mergeTokens(CoreLabel token, CoreLabel nextToken) {
30+
// NOTE: right now the merged tokens get the part-of-speech tag of the first token
31+
token.setWord(token.word() + nextToken.word());
32+
token.setAfter(nextToken.after());
33+
token.setEndPosition(nextToken.endPosition());
34+
token.setValue(token.word()+"-"+token.sentIndex());
35+
}
36+
37+
@Override
38+
public List<CoreLabel> process(List<CoreLabel> tokens) {
39+
List<CoreLabel> processedTokens = new ArrayList<CoreLabel>();
40+
for (CoreLabel currToken : tokens) {
41+
CoreLabel processedToken = new CoreLabel(currToken);
42+
CoreLabel lastProcessedToken =
43+
processedTokens.size() > 0 ? processedTokens.get(processedTokens.size() - 1) : null;
44+
if (lastProcessedToken != null && afterIsEmpty.apply(lastProcessedToken) && currToken.word().equals("-")) {
45+
mergeTokens(lastProcessedToken, currToken);
46+
} else if (lastProcessedToken != null && lastProcessedToken.word().endsWith("-") &&
47+
afterIsEmpty.apply(lastProcessedToken)) {
48+
mergeTokens(lastProcessedToken, currToken);
49+
} else {
50+
processedTokens.add(processedToken);
51+
}
52+
}
53+
return processedTokens;
54+
}
55+
56+
@Override
57+
public List<CoreLabel> restore(List<CoreLabel> originalTokens, List<CoreLabel> processedTokens) {
58+
List<CoreLabel> restoredTokens = new ArrayList<>();
59+
for (int i = 0, j = 0 ; i < processedTokens.size() ; i++) {
60+
// for each processed token, loop through the 1 or more original tokens
61+
// that correspond to the merged token
62+
CoreLabel processedToken = processedTokens.get(i);
63+
while (j < originalTokens.size()) {
64+
CoreLabel originalToken = originalTokens.get(j);
65+
if (originalToken.beginPosition() >= processedToken.endPosition())
66+
break;
67+
// copy most info from processed token (such as NER tag)
68+
CoreLabel restoredToken = new CoreLabel(processedToken);
69+
// copy text and character info from original token
70+
restoredToken.setWord(originalToken.word());
71+
restoredToken.setOriginalText(originalToken.originalText());
72+
restoredToken.setBeginPosition(originalToken.beginPosition());
73+
restoredToken.setEndPosition(originalToken.endPosition());
74+
restoredToken.set(CoreAnnotations.TokenBeginAnnotation.class, originalToken.get(
75+
CoreAnnotations.TokenBeginAnnotation.class));
76+
restoredToken.set(CoreAnnotations.TokenEndAnnotation.class, originalToken.get(
77+
CoreAnnotations.TokenEndAnnotation.class));
78+
restoredToken.setAfter(originalToken.after());
79+
restoredToken.setBefore(originalToken.before());
80+
restoredToken.setIndex(j+1);
81+
restoredToken.setValue(restoredToken.word());
82+
// add restored token to list
83+
restoredTokens.add(restoredToken);
84+
// move on to next original token
85+
j++;
86+
}
87+
}
88+
return restoredTokens;
89+
}
90+
91+
}

src/edu/stanford/nlp/pipeline/demo/corenlp-brat.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<nav class="navbar navbar-default navbar-static-top">
2929
<div class="container">
3030
<div class="navbar-header">
31-
<a class="navbar-brand" href="https://stanfordnlp.github.io/CoreNLP/">Stanford CoreNLP 4.0.0 (updated 2020-04-16)</a>
31+
<a class="navbar-brand" href="https://stanfordnlp.github.io/CoreNLP/">Stanford CoreNLP 4.1.0 (updated 2020-07-31)</a>
3232
</div>
3333
</div>
3434
</nav>

0 commit comments

Comments
 (0)