-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
AnnotatorFactories.java
674 lines (605 loc) · 26.9 KB
/
AnnotatorFactories.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
package edu.stanford.nlp.pipeline;
import edu.stanford.nlp.ie.NERClassifierCombiner;
import edu.stanford.nlp.ie.regexp.NumberSequenceClassifier;
import edu.stanford.nlp.io.RuntimeIOException;
import edu.stanford.nlp.process.PTBTokenizer;
import edu.stanford.nlp.process.WordToSentenceProcessor;
import edu.stanford.nlp.util.Generics;
import edu.stanford.nlp.util.PropertiesUtils;
import java.io.IOException;
import java.util.Arrays;
import java.util.Properties;
import java.util.Set;
/**
* A companion to {@link AnnotatorFactory} defining the common annotators.
* These are primarily used in {@link StanfordCoreNLP#getDefaultAnnotatorPool(java.util.Properties, AnnotatorImplementations)}.
*
* @author Gabor Angeli
*/
public class AnnotatorFactories {
private AnnotatorFactories() {} // static factory class
public static AnnotatorFactory tokenize(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
String extraOptions = null;
boolean keepNewline = Boolean.valueOf(properties.getProperty(StanfordCoreNLP.NEWLINE_SPLITTER_PROPERTY, "false")); // ssplit.eolonly
String hasSsplit = properties.getProperty("annotators");
if (hasSsplit != null && hasSsplit.contains(StanfordCoreNLP.STANFORD_SSPLIT)) { // ssplit
// Only possibly put in *NL* if not all one (the Boolean method treats null as false)
if ( ! Boolean.parseBoolean(properties.getProperty("ssplit.isOneSentence"))) {
// Set to { NEVER, ALWAYS, TWO_CONSECUTIVE } based on ssplit.newlineIsSentenceBreak
String nlsbString = properties.getProperty(StanfordCoreNLP.NEWLINE_IS_SENTENCE_BREAK_PROPERTY,
StanfordCoreNLP.DEFAULT_NEWLINE_IS_SENTENCE_BREAK);
WordToSentenceProcessor.NewlineIsSentenceBreak nlsb = WordToSentenceProcessor.stringToNewlineIsSentenceBreak(nlsbString);
if (nlsb != WordToSentenceProcessor.NewlineIsSentenceBreak.NEVER) {
keepNewline = true;
}
}
}
if (keepNewline) {
extraOptions = "tokenizeNLs,";
}
return annotatorImplementation.tokenizer(properties, false, extraOptions);
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
StringBuilder os = new StringBuilder();
os.append("tokenize.whitespace:").append(properties.getProperty("tokenize.whitespace", "false"));
if (properties.getProperty("tokenize.options") != null) {
os.append(":tokenize.options:").append(properties.getProperty("tokenize.options"));
}
if (properties.getProperty("tokenize.language") != null) {
os.append(":tokenize.language:").append(properties.getProperty("tokenize.language"));
}
if (properties.getProperty("tokenize.class") != null) {
os.append(":tokenize.class:").append(properties.getProperty("tokenize.class"));
}
if (Boolean.valueOf(properties.getProperty("tokenize.whitespace", "false"))) {
os.append(TokenizerAnnotator.EOL_PROPERTY + ':').append(properties.getProperty(TokenizerAnnotator.EOL_PROPERTY, "false"));
os.append(StanfordCoreNLP.NEWLINE_SPLITTER_PROPERTY + ':');
os.append(properties.getProperty(StanfordCoreNLP.NEWLINE_SPLITTER_PROPERTY, "false"));
} else {
os.append(StanfordCoreNLP.NEWLINE_SPLITTER_PROPERTY + ':');
os.append(properties.getProperty(StanfordCoreNLP.NEWLINE_SPLITTER_PROPERTY, "false"));
os.append("ssplit.isOneSentence" + ':');
os.append(properties.getProperty("ssplit.isOneSentence", "false"));
os.append(StanfordCoreNLP.NEWLINE_IS_SENTENCE_BREAK_PROPERTY + ':');
os.append(properties.getProperty(StanfordCoreNLP.NEWLINE_IS_SENTENCE_BREAK_PROPERTY, StanfordCoreNLP.DEFAULT_NEWLINE_IS_SENTENCE_BREAK));
}
return os.toString();
}
};
}
public static AnnotatorFactory cleanXML(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
String xmlTags =
properties.getProperty("clean.xmltags",
CleanXmlAnnotator.DEFAULT_XML_TAGS);
String sentenceEndingTags =
properties.getProperty("clean.sentenceendingtags",
CleanXmlAnnotator.DEFAULT_SENTENCE_ENDERS);
String singleSentenceTags =
properties.getProperty("clean.singlesentencetags",
CleanXmlAnnotator.DEFAULT_SINGLE_SENTENCE_TAGS);
String allowFlawedString = properties.getProperty("clean.allowflawedxml");
boolean allowFlawed = CleanXmlAnnotator.DEFAULT_ALLOW_FLAWS;
if (allowFlawedString != null)
allowFlawed = Boolean.valueOf(allowFlawedString);
String dateTags =
properties.getProperty("clean.datetags",
CleanXmlAnnotator.DEFAULT_DATE_TAGS);
String docIdTags =
properties.getProperty("clean.docIdtags",
CleanXmlAnnotator.DEFAULT_DOCID_TAGS);
String docTypeTags =
properties.getProperty("clean.docTypetags",
CleanXmlAnnotator.DEFAULT_DOCTYPE_TAGS);
String utteranceTurnTags =
properties.getProperty("clean.turntags",
CleanXmlAnnotator.DEFAULT_UTTERANCE_TURN_TAGS);
String speakerTags =
properties.getProperty("clean.speakertags",
CleanXmlAnnotator.DEFAULT_SPEAKER_TAGS);
String docAnnotations =
properties.getProperty("clean.docAnnotations",
CleanXmlAnnotator.DEFAULT_DOC_ANNOTATIONS_PATTERNS);
String tokenAnnotations =
properties.getProperty("clean.tokenAnnotations",
CleanXmlAnnotator.DEFAULT_TOKEN_ANNOTATIONS_PATTERNS);
String sectionTags =
properties.getProperty("clean.sectiontags",
CleanXmlAnnotator.DEFAULT_SECTION_TAGS);
String sectionAnnotations =
properties.getProperty("clean.sectionAnnotations",
CleanXmlAnnotator.DEFAULT_SECTION_ANNOTATIONS_PATTERNS);
String ssplitDiscardTokens =
properties.getProperty("clean.ssplitDiscardTokens");
CleanXmlAnnotator annotator = annotatorImplementation.cleanXML(properties, xmlTags,
sentenceEndingTags,
dateTags,
allowFlawed);
annotator.setSingleSentenceTagMatcher(singleSentenceTags);
annotator.setDocIdTagMatcher(docIdTags);
annotator.setDocTypeTagMatcher(docTypeTags);
annotator.setDiscourseTags(utteranceTurnTags, speakerTags);
annotator.setDocAnnotationPatterns(docAnnotations);
annotator.setTokenAnnotationPatterns(tokenAnnotations);
annotator.setSectionTagMatcher(sectionTags);
annotator.setSectionAnnotationPatterns(sectionAnnotations);
annotator.setSsplitDiscardTokensMatcher(ssplitDiscardTokens);
return annotator;
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
return "clean.xmltags:" +
properties.getProperty("clean.xmltags",
CleanXmlAnnotator.DEFAULT_XML_TAGS) +
"clean.sentenceendingtags:" +
properties.getProperty("clean.sentenceendingtags",
CleanXmlAnnotator.DEFAULT_SENTENCE_ENDERS) +
"clean.sentenceendingtags:" +
properties.getProperty("clean.singlesentencetags",
CleanXmlAnnotator.DEFAULT_SINGLE_SENTENCE_TAGS) +
"clean.allowflawedxml:" +
properties.getProperty("clean.allowflawedxml", "") +
"clean.datetags:" +
properties.getProperty("clean.datetags",
CleanXmlAnnotator.DEFAULT_DATE_TAGS) +
"clean.docidtags:" +
properties.getProperty("clean.docid",
CleanXmlAnnotator.DEFAULT_DOCID_TAGS) +
"clean.doctypetags:" +
properties.getProperty("clean.doctype",
CleanXmlAnnotator.DEFAULT_DOCTYPE_TAGS) +
"clean.turntags:" +
properties.getProperty("clean.turntags",
CleanXmlAnnotator.DEFAULT_UTTERANCE_TURN_TAGS) +
"clean.speakertags:" +
properties.getProperty("clean.speakertags",
CleanXmlAnnotator.DEFAULT_SPEAKER_TAGS) +
"clean.docAnnotations:" +
properties.getProperty("clean.docAnnotations",
CleanXmlAnnotator.DEFAULT_DOC_ANNOTATIONS_PATTERNS) +
"clean.tokenAnnotations:" +
properties.getProperty("clean.tokenAnnotations",
CleanXmlAnnotator.DEFAULT_TOKEN_ANNOTATIONS_PATTERNS) +
"clean.sectiontags:" +
properties.getProperty("clean.sectiontags",
CleanXmlAnnotator.DEFAULT_SECTION_TAGS) +
"clean.sectionAnnotations:" +
properties.getProperty("clean.sectionAnnotations",
CleanXmlAnnotator.DEFAULT_SECTION_ANNOTATIONS_PATTERNS);
}
};
}
//
// Sentence splitter: splits the above sequence of tokens into
// sentences. This is required when processing entire documents or
// text consisting of multiple sentences.
//
public static AnnotatorFactory sentenceSplit(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
// System.err.println(signature());
// todo: The above shows that signature is edu.stanford.nlp.pipeline.AnnotatorImplementations: and doesn't reflect what annotator it is! Should fix.
boolean nlSplitting = Boolean.valueOf(properties.getProperty(StanfordCoreNLP.NEWLINE_SPLITTER_PROPERTY, "false"));
if (nlSplitting) {
boolean whitespaceTokenization = Boolean.valueOf(properties.getProperty("tokenize.whitespace", "false"));
if (whitespaceTokenization) {
if (System.getProperty("line.separator").equals("\n")) {
return WordsToSentencesAnnotator.newlineSplitter(false, "\n");
} else {
// throw "\n" in just in case files use that instead of
// the system separator
return WordsToSentencesAnnotator.newlineSplitter(false, System.getProperty("line.separator"), "\n");
}
} else {
return WordsToSentencesAnnotator.newlineSplitter(false, PTBTokenizer.getNewlineToken());
}
} else {
// Treat as one sentence: You get a no-op sentence splitter that always returns all tokens as one sentence.
String isOneSentence = properties.getProperty("ssplit.isOneSentence");
if (Boolean.parseBoolean(isOneSentence)) { // this method treats null as false
return WordsToSentencesAnnotator.nonSplitter(false);
}
// multi token sentence boundaries
String boundaryMultiTokenRegex = properties.getProperty("ssplit.boundaryMultiTokenRegex");
// Discard these tokens without marking them as sentence boundaries
String tokenPatternsToDiscardProp = properties.getProperty("ssplit.tokenPatternsToDiscard");
Set<String> tokenRegexesToDiscard = null;
if (tokenPatternsToDiscardProp != null){
String [] toks = tokenPatternsToDiscardProp.split(",");
tokenRegexesToDiscard = Generics.newHashSet(Arrays.asList(toks));
}
// regular boundaries
String boundaryTokenRegex = properties.getProperty("ssplit.boundaryTokenRegex");
Set<String> boundariesToDiscard = null;
// newline boundaries which are discarded.
String bounds = properties.getProperty("ssplit.boundariesToDiscard");
if (bounds != null) {
String [] toks = bounds.split(",");
boundariesToDiscard = Generics.newHashSet(Arrays.asList(toks));
}
Set<String> htmlElementsToDiscard = null;
// HTML boundaries which are discarded
bounds = properties.getProperty("ssplit.htmlBoundariesToDiscard");
if (bounds != null) {
String [] elements = bounds.split(",");
htmlElementsToDiscard = Generics.newHashSet(Arrays.asList(elements));
}
String nlsb = properties.getProperty(StanfordCoreNLP.NEWLINE_IS_SENTENCE_BREAK_PROPERTY,
StanfordCoreNLP.DEFAULT_NEWLINE_IS_SENTENCE_BREAK);
return annotatorImplementation.wordToSentences(properties,
false, boundaryTokenRegex, boundariesToDiscard, htmlElementsToDiscard,
nlsb, boundaryMultiTokenRegex, tokenRegexesToDiscard);
}
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
StringBuilder os = new StringBuilder();
if (Boolean.valueOf(properties.getProperty(StanfordCoreNLP.NEWLINE_SPLITTER_PROPERTY, "false"))) {
os.append(StanfordCoreNLP.NEWLINE_SPLITTER_PROPERTY + '=').append(properties.getProperty(StanfordCoreNLP.NEWLINE_SPLITTER_PROPERTY, "false")).append('\n');
os.append("tokenize.whitespace=").append(properties.getProperty("tokenize.whitespace", "false")).append('\n');
} else {
os.append(baseSignature(properties, StanfordCoreNLP.STANFORD_SSPLIT));
}
return os.toString();
}
};
}
//
// POS tagger
//
public static AnnotatorFactory posTag(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
try {
return annotatorImplementation.posTagger(properties);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
return POSTaggerAnnotator.signature(properties);
}
};
}
//
// Lemmatizer
//
public static AnnotatorFactory lemma(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
return annotatorImplementation.morpha(properties, false);
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
// nothing for this one
return "";
}
};
}
//
// NER
//
public static AnnotatorFactory nerTag(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
try {
return annotatorImplementation.ner(properties);
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
boolean useSUTime = Boolean.parseBoolean(properties.getProperty(
NumberSequenceClassifier.USE_SUTIME_PROPERTY,
Boolean.toString(NumberSequenceClassifier.USE_SUTIME_DEFAULT)));
String nerSig = "ner.model:" +
properties.getProperty("ner.model", "") +
NERClassifierCombiner.APPLY_NUMERIC_CLASSIFIERS_PROPERTY + ':' +
properties.getProperty(NERClassifierCombiner.APPLY_NUMERIC_CLASSIFIERS_PROPERTY,
Boolean.toString(NERClassifierCombiner.APPLY_NUMERIC_CLASSIFIERS_DEFAULT)) +
NumberSequenceClassifier.USE_SUTIME_PROPERTY + ':' +
properties.getProperty(NumberSequenceClassifier.USE_SUTIME_PROPERTY,
Boolean.toString(NumberSequenceClassifier.USE_SUTIME_DEFAULT));
if (useSUTime) {
String sutimeSig = PropertiesUtils.getSignature(NumberSequenceClassifier.SUTIME_PROPERTY, properties);
if (!sutimeSig.isEmpty()) {
nerSig = nerSig + sutimeSig;
}
}
return nerSig;
}
};
}
//
// Regex NER
//
public static AnnotatorFactory regexNER(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
return annotatorImplementation.tokensRegexNER(properties, Annotator.STANFORD_REGEXNER);
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
return PropertiesUtils.getSignature(Annotator.STANFORD_REGEXNER, properties, TokensRegexNERAnnotator.SUPPORTED_PROPERTIES);
}
};
}
//
// Mentions annotator
//
public static AnnotatorFactory entityMentions(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
return annotatorImplementation.mentions(properties, Annotator.STANFORD_ENTITY_MENTIONS);
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
return PropertiesUtils.getSignature(Annotator.STANFORD_ENTITY_MENTIONS, properties, EntityMentionsAnnotator.SUPPORTED_PROPERTIES);
}
};
}
//
// Gender Annotator
//
public static AnnotatorFactory gender(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
return annotatorImplementation.gender(properties, false);
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
return "gender.firstnames:" +
properties.getProperty("gender.firstnames",
DefaultPaths.DEFAULT_GENDER_FIRST_NAMES);
}
};
}
//
// True caser
//
public static AnnotatorFactory truecase(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
String model = properties.getProperty("truecase.model", DefaultPaths.DEFAULT_TRUECASE_MODEL);
String bias = properties.getProperty("truecase.bias", TrueCaseAnnotator.DEFAULT_MODEL_BIAS);
String mixed = properties.getProperty("truecase.mixedcasefile", DefaultPaths.DEFAULT_TRUECASE_DISAMBIGUATION_LIST);
return annotatorImplementation.trueCase(properties, model, bias, mixed, false);
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
return "truecase.model:" +
properties.getProperty("truecase.model",
DefaultPaths.DEFAULT_TRUECASE_MODEL) +
"truecase.bias:" +
properties.getProperty("truecase.bias",
TrueCaseAnnotator.DEFAULT_MODEL_BIAS) +
"truecase.mixedcasefile:" +
properties.getProperty("truecase.mixedcasefile",
DefaultPaths.DEFAULT_TRUECASE_DISAMBIGUATION_LIST);
}
};
}
//
// Parser
//
public static AnnotatorFactory parse(final Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
return annotatorImplementation.parse(properties);
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
String type = properties.getProperty("parse.type", "stanford");
if (type.equalsIgnoreCase("stanford")) {
return ParserAnnotator.signature("parse", properties);
} else if (type.equalsIgnoreCase("charniak")) {
return "parse.model:" +
properties.getProperty("parse.model", "") +
"parse.executable:" +
properties.getProperty("parse.executable", "") +
"parse.maxlen:" +
properties.getProperty("parse.maxlen", "");
} else {
throw new RuntimeException("Unknown parser type: " + type +
" (currently supported: stanford and charniak)");
}
}
};
}
//
// Coreference resolution
//
public static AnnotatorFactory coref(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
return annotatorImplementation.coref(properties);
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
return DeterministicCorefAnnotator.signature(properties);
}
};
}
public static AnnotatorFactory dcoref(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
return annotatorImplementation.dcoref(properties);
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
return DeterministicCorefAnnotator.signature(properties);
}
};
}
public static AnnotatorFactory relation(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
return annotatorImplementation.relations(properties);
}
@Override
public String additionalSignature() {
// keep track of all relevant properties for this annotator here!
return "sup.relation.verbose:" +
properties.getProperty("sup.relation.verbose",
"false") +
properties.getProperty("sup.relation.model",
DefaultPaths.DEFAULT_SUP_RELATION_EX_RELATION_MODEL);
}
};
}
public static AnnotatorFactory sentiment(Properties properties, final AnnotatorImplementations annotatorImplementation) {
return new AnnotatorFactory(properties, annotatorImplementation) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
return annotatorImplementation.sentiment(properties, StanfordCoreNLP.STANFORD_SENTIMENT);
}
@Override
public String additionalSignature() {
return "sentiment.model=" + properties.get("sentiment.model");
}
};
}
public static AnnotatorFactory columnDataClassifier(Properties properties, final AnnotatorImplementations annotatorImpls) {
return new AnnotatorFactory(properties, annotatorImpls) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
if(!properties.containsKey("loadClassifier"))
throw new RuntimeException("Must load a classifier when creating a column data classifier annotator");
return new ColumnDataClassifierAnnotator(properties);
}
@Override
protected String additionalSignature() {
return "classifier="+properties.get("loadClassifier="+properties.get("loadClassifier"));
}
};
}
//
// Dependency parsing
//
public static AnnotatorFactory dependencies(Properties properties, final AnnotatorImplementations annotatorImpl) {
return new AnnotatorFactory(properties, annotatorImpl) {
private static final long serialVersionUID = 1L;
@Override
public Annotator create() {
return annotatorImpl.dependencies(properties);
}
@Override
protected String additionalSignature() {
return DependencyParseAnnotator.signature(StanfordCoreNLP.STANFORD_DEPENDENCIES, properties);
}
};
}
//
// Monotonicity and Polarity
//
public static AnnotatorFactory natlog(Properties properties, final AnnotatorImplementations annotatorImpl) {
return new AnnotatorFactory(properties, annotatorImpl) {
private static final long serialVersionUID = 4825870963088507811L;
@Override
public Annotator create() {
return annotatorImpl.natlog(properties);
}
@Override
protected String additionalSignature() {
return "";
}
};
}
//
// RelationTriples
//
public static AnnotatorFactory openie(Properties properties, final AnnotatorImplementations annotatorImpl) {
return new AnnotatorFactory(properties, annotatorImpl) {
private static final long serialVersionUID = -2525567112379296672L;
@Override
public Annotator create() {
return annotatorImpl.openie(properties);
}
@Override
protected String additionalSignature() {
return "";
}
};
}
//
// Quote Extractor
//
public static AnnotatorFactory quote(Properties properties, final AnnotatorImplementations annotatorImpl) {
return new AnnotatorFactory(properties, annotatorImpl) {
private static final long serialVersionUID = -2525567112379296672L;
@Override
public Annotator create() {
return annotatorImpl.quote(properties);
}
@Override
protected String additionalSignature() {
return "";
}
};
}
//
// UD Features Extractor
//
public static AnnotatorFactory udfeats(Properties properties, final AnnotatorImplementations annotatorImpl) {
return new AnnotatorFactory(properties, annotatorImpl) {
private static final long serialVersionUID = -2525567112379296672L;
@Override
public Annotator create() {
return annotatorImpl.udfeats(properties);
}
@Override
protected String additionalSignature() {
return "";
}
};
}
}