Skip to content

Commit 470380e

Browse files
manningStanford NLP
authored andcommitted
Avoid the double curly braces initializer anti-pattern
1 parent fa84e06 commit 470380e

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/edu/stanford/nlp/simple/Document.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import edu.stanford.nlp.ling.CoreAnnotations;
99
import edu.stanford.nlp.ling.CoreLabel;
1010
import edu.stanford.nlp.naturalli.NaturalLogicAnnotations;
11+
import edu.stanford.nlp.naturalli.OperatorSpec;
12+
import edu.stanford.nlp.naturalli.Polarity;
1113
import edu.stanford.nlp.pipeline.*;
1214
import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations;
1315
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
@@ -36,32 +38,32 @@ public class Document {
3638
/**
3739
* The empty {@link java.util.Properties} object, for use with creating default annotators.
3840
*/
39-
static final Properties EMPTY_PROPS = new Properties() {{
40-
setProperty("language", "english");
41-
setProperty("annotators", "");
42-
setProperty("tokenize.class", "PTBTokenizer");
43-
setProperty("tokenize.language", "en");
44-
setProperty("parse.binaryTrees", "true");
45-
}};
41+
static final Properties EMPTY_PROPS = PropertiesUtils.asProperties(
42+
"language", "english",
43+
"annotators", "",
44+
"tokenize.class", "PTBTokenizer",
45+
"tokenize.language", "en",
46+
"parse.binaryTrees", "true");
47+
4648

4749
/**
4850
* The caseless {@link java.util.Properties} object.
4951
*
5052
* @see Document#caseless()
5153
* @see Sentence#caseless()
5254
*/
53-
static final Properties CASELESS_PROPS = new Properties() {{
54-
setProperty("language", "english");
55-
setProperty("annotators", "");
56-
setProperty("tokenize.class", "PTBTokenizer");
57-
setProperty("tokenize.language", "en");
58-
setProperty("parse.binaryTrees", "true");
59-
setProperty("pos.model", "edu/stanford/nlp/models/pos-tagger/wsj-0-18-caseless-left3words-distsim.tagger");
60-
setProperty("parse.model", "edu/stanford/nlp/models/lexparser/englishPCFG.caseless.ser.gz");
61-
setProperty("ner.model", "edu/stanford/nlp/models/ner/english.muc.7class.caseless.distsim.crf.ser.gz," +
55+
static final Properties CASELESS_PROPS = PropertiesUtils.asProperties(
56+
"language", "english",
57+
"annotators", "",
58+
"tokenize.class", "PTBTokenizer",
59+
"tokenize.language", "en",
60+
"parse.binaryTrees", "true",
61+
"pos.model", "edu/stanford/nlp/models/pos-tagger/wsj-0-18-caseless-left3words-distsim.tagger",
62+
"parse.model", "edu/stanford/nlp/models/lexparser/englishPCFG.caseless.ser.gz",
63+
"ner.model", "edu/stanford/nlp/models/ner/english.muc.7class.caseless.distsim.crf.ser.gz," +
6264
"edu/stanford/nlp/models/ner/english.conll.4class.caseless.distsim.crf.ser.gz," +
6365
"edu/stanford/nlp/models/ner/english.all.3class.caseless.distsim.crf.ser.gz");
64-
}};
66+
6567

6668
/**
6769
* The backend to use for constructing {@link edu.stanford.nlp.pipeline.AnnotatorFactory}s.
@@ -382,7 +384,7 @@ public static void useServer(String host,
382384
}
383385

384386

385-
/**
387+
/*
386388
* A static block that'll automatically fault in the CoreNLP server, if the appropriate environment
387389
* variables are set.
388390
* These are:
@@ -966,8 +968,8 @@ Document runNatlog(Properties props) {
966968
// Update data
967969
synchronized (serializer) {
968970
for (int i = 0; i < sentences.size(); ++i) {
969-
sentences.get(i).updateTokens(ann.get(CoreAnnotations.SentencesAnnotation.class).get(i).get(CoreAnnotations.TokensAnnotation.class), (pair) -> pair.first.setPolarity(ProtobufAnnotationSerializer.toProto(pair.second)), x -> x.get(NaturalLogicAnnotations.PolarityAnnotation.class));
970-
sentences.get(i).updateTokens(ann.get(CoreAnnotations.SentencesAnnotation.class).get(i).get(CoreAnnotations.TokensAnnotation.class), (pair) -> pair.first.setOperator(ProtobufAnnotationSerializer.toProto(pair.second)), x -> x.get(NaturalLogicAnnotations.OperatorAnnotation.class));
971+
sentences.get(i).updateTokens(ann.get(CoreAnnotations.SentencesAnnotation.class).get(i).get(CoreAnnotations.TokensAnnotation.class), (Pair<CoreNLPProtos.Token.Builder, Polarity> pair) -> pair.first().setPolarity(ProtobufAnnotationSerializer.toProto(pair.second())), x -> x.get(NaturalLogicAnnotations.PolarityAnnotation.class));
972+
sentences.get(i).updateTokens(ann.get(CoreAnnotations.SentencesAnnotation.class).get(i).get(CoreAnnotations.TokensAnnotation.class), (Pair<CoreNLPProtos.Token.Builder, OperatorSpec> pair) -> pair.first().setOperator(ProtobufAnnotationSerializer.toProto(pair.second())), x -> x.get(NaturalLogicAnnotations.OperatorAnnotation.class));
971973
}
972974
}
973975
return this;
@@ -1108,7 +1110,7 @@ private CorefChain fromProto(CoreNLPProtos.CorefChain proto) {
11081110
StringBuilder mentionSpan = new StringBuilder();
11091111
Sentence sentence = sentence(mentionProto.getSentenceIndex());
11101112
for (int k = mentionProto.getBeginIndex(); k < mentionProto.getEndIndex(); ++k) {
1111-
mentionSpan.append(" ").append(sentence.word(k));
1113+
mentionSpan.append(' ').append(sentence.word(k));
11121114
}
11131115
// Set the coref cluster id for the token
11141116
CorefChain.CorefMention mention = new CorefChain.CorefMention(

0 commit comments

Comments
 (0)