use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project CoreNLP by stanfordnlp.
the class SceneGraphImageCleaner method getPipeline.
private static StanfordCoreNLP getPipeline() {
if (pipeline == null) {
Properties props = new Properties();
props.put("annotators", "tokenize,ssplit,pos,lemma,ner");
// props.put("tokenize.whitespace", "true");
props.put("ssplit.eolonly", "true");
pipeline = new StanfordCoreNLP(props);
}
return pipeline;
}
use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project CoreNLP by stanfordnlp.
the class DcorefExactOutputITest method main.
/**
* If run as a program, writes the expected output of args[0] to args[1].
* This is useful for updating the desired test results when CoreNLP changes.
*/
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.err.println("Expected args <input> <output>");
throw new IllegalArgumentException();
}
String input = args[0];
String output = args[1];
Properties props = new Properties();
props.setProperty("annotators", "tokenize, cleanxml, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// for example
// "edu/stanford/nlp/dcoref/STILLALONEWOLF_20050102.1100.eng.LDC2005E83.sgm"
String doc = IOUtils.slurpFile(input);
Annotation annotation = pipeline.process(doc);
Map<Integer, CorefChain> chains = annotation.get(CorefCoreAnnotations.CorefChainAnnotation.class);
saveResults(output, chains);
}
use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project CoreNLP by stanfordnlp.
the class NumberSequenceClassifierITest method makeNumericPipeline.
private static StanfordCoreNLP makeNumericPipeline() {
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, number, qen");
props.setProperty("tokenize.options", "splitHyphenated=false");
props.setProperty("customAnnotatorClass.number", "edu.stanford.nlp.pipeline.NumberAnnotator");
props.setProperty("customAnnotatorClass.qen", "edu.stanford.nlp.pipeline.QuantifiableEntityNormalizingAnnotator");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
return pipeline;
}
use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project CoreNLP by stanfordnlp.
the class GetPatternsFromDataMultiClass method runPOSNEROnTokens.
public static Map<String, DataInstance> runPOSNEROnTokens(List<CoreMap> sentsCM, String posModelPath, boolean useTargetNERRestriction, String prefix, boolean useTargetParserParentRestriction, String numThreads, PatternFactory.PatternType type) {
Annotation doc = new Annotation(sentsCM);
Properties props = new Properties();
List<String> anns = new ArrayList<>();
anns.add("pos");
anns.add("lemma");
if (useTargetParserParentRestriction) {
anns.add("parse");
} else if (type.equals(PatternFactory.PatternType.DEP))
anns.add("depparse");
if (useTargetNERRestriction) {
anns.add("ner");
}
props.setProperty("annotators", StringUtils.join(anns, ","));
props.setProperty("parse.maxlen", "80");
props.setProperty("nthreads", numThreads);
props.setProperty("threads", numThreads);
if (posModelPath != null) {
props.setProperty("pos.model", posModelPath);
}
StanfordCoreNLP pipeline = new StanfordCoreNLP(props, false);
Redwood.log(Redwood.DBG, "Annotating text");
pipeline.annotate(doc);
Redwood.log(Redwood.DBG, "Done annotating text");
Map<String, DataInstance> sents = new HashMap<>();
for (CoreMap s : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
if (useTargetParserParentRestriction)
inferParentParseTag(s.get(TreeAnnotation.class));
DataInstance d = DataInstance.getNewInstance(type, s);
sents.put(prefix + s.get(CoreAnnotations.DocIDAnnotation.class), d);
}
return sents;
}
use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project CoreNLP by stanfordnlp.
the class SentenceTest method tokenizeAndSplitAnnotation.
public Sentence tokenizeAndSplitAnnotation(Annotation ann) {
StanfordCoreNLP pipeline = new StanfordCoreNLP(new Properties() {
{
setProperty("annotators", "tokenize,ssplit");
}
});
pipeline.annotate(ann);
CoreMap map = ann.get(CoreAnnotations.SentencesAnnotation.class).get(0);
return new Sentence(map);
}
Aggregations