use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project useful-java-links by Vedenin.
the class StanfordCoreNLPSentenceDetectors method testStanfordCoreNLP.
private static String[] testStanfordCoreNLP(String text) throws Exception {
StanfordCoreNLP coreNLP = getStanfordCoreNLP();
Annotation document = new Annotation(text);
coreNLP.annotate(document);
List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
String[] result = new String[sentences.size()];
int i = 0;
for (CoreMap sentence : sentences) {
result[i] = sentence.toString();
i++;
}
return result;
}
use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project useful-java-links by Vedenin.
the class StanfordCoreNLPSentenceDetectors method getStanfordCoreNLP.
private static StanfordCoreNLP getStanfordCoreNLP() {
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
return new StanfordCoreNLP(props);
}
use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project ud381 by udacity.
the class SentimentAnalyzer method init.
public static void init() {
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,parse,sentiment");
pipeline = new StanfordCoreNLP(props);
}
use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project CoreNLP by stanfordnlp.
the class SemgrexPatternITest method testNERStanfordDependencies.
@Test
public void testNERStanfordDependencies() throws Exception {
String sentence = "John lives in Washington.";
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse");
props.setProperty("parse.originalDependencies", "true");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation doc = new Annotation(sentence);
pipeline.annotate(doc);
CoreMap sent = doc.get(CoreAnnotations.SentencesAnnotation.class).get(0);
SemanticGraph graph = sent.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class);
graph.prettyPrint();
String patStr = "({word:/lives/} >/prep_in/ {word:/\\QCalifornia\\E|\\QWashington\\E/} >nsubj {ner:PERSON})";
SemgrexPattern pat = SemgrexPattern.compile(patStr);
SemgrexMatcher mat = pat.matcher(graph, true);
assertTrue(mat.find());
}
use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project CoreNLP by stanfordnlp.
the class GenericDataSetReader method modifyUsingCoreNLPNER.
private void modifyUsingCoreNLPNER(Annotation doc) {
Properties ann = new Properties();
ann.setProperty("annotators", "pos, lemma, ner");
StanfordCoreNLP pipeline = new StanfordCoreNLP(ann, false);
pipeline.annotate(doc);
for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
List<EntityMention> entities = sentence.get(MachineReadingAnnotations.EntityMentionsAnnotation.class);
if (entities != null) {
List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
for (EntityMention en : entities) {
//System.out.println("old ner tag for " + en.getExtentString() + " was " + en.getType());
Span s = en.getExtent();
Counter<String> allNertagforSpan = new ClassicCounter<>();
for (int i = s.start(); i < s.end(); i++) {
allNertagforSpan.incrementCount(tokens.get(i).ner());
}
String entityNertag = Counters.argmax(allNertagforSpan);
en.setType(entityNertag);
//System.out.println("new ner tag is " + entityNertag);
}
}
}
}
Aggregations