Search in sources :

Example 21 with StanfordCoreNLP

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;
}
Also used : CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) CoreMap(edu.stanford.nlp.util.CoreMap) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) Annotation(edu.stanford.nlp.pipeline.Annotation)

Example 22 with StanfordCoreNLP

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);
}
Also used : Properties(java.util.Properties) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP)

Example 23 with StanfordCoreNLP

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);
}
Also used : Properties(java.util.Properties) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP)

Example 24 with StanfordCoreNLP

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());
}
Also used : SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) SemanticGraph(edu.stanford.nlp.semgraph.SemanticGraph) Properties(java.util.Properties) CoreMap(edu.stanford.nlp.util.CoreMap) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) Annotation(edu.stanford.nlp.pipeline.Annotation) Test(org.junit.Test)

Example 25 with StanfordCoreNLP

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);
            }
        }
    }
}
Also used : Properties(java.util.Properties) Span(edu.stanford.nlp.ie.machinereading.structure.Span) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) ParserConstraint(edu.stanford.nlp.parser.common.ParserConstraint) MachineReadingAnnotations(edu.stanford.nlp.ie.machinereading.structure.MachineReadingAnnotations) CoreLabel(edu.stanford.nlp.ling.CoreLabel) EntityMention(edu.stanford.nlp.ie.machinereading.structure.EntityMention) TreeCoreAnnotations(edu.stanford.nlp.trees.TreeCoreAnnotations) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) ClassicCounter(edu.stanford.nlp.stats.ClassicCounter) CoreMap(edu.stanford.nlp.util.CoreMap)

Aggregations

StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)44 Properties (java.util.Properties)33 Annotation (edu.stanford.nlp.pipeline.Annotation)27 CoreMap (edu.stanford.nlp.util.CoreMap)20 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)17 CoreLabel (edu.stanford.nlp.ling.CoreLabel)7 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)7 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)5 Test (org.junit.Test)5 SentencesAnnotation (edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation)4 CollapsedDependenciesAnnotation (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation)4 ArrayList (java.util.ArrayList)4 GoldAnswerAnnotation (edu.stanford.nlp.ling.CoreAnnotations.GoldAnswerAnnotation)3 IndexedWord (edu.stanford.nlp.ling.IndexedWord)3 SemanticGraphEdge (edu.stanford.nlp.semgraph.SemanticGraphEdge)3 TreeAnnotation (edu.stanford.nlp.trees.TreeCoreAnnotations.TreeAnnotation)3 PrintWriter (java.io.PrintWriter)3 CorefCoreAnnotations (edu.stanford.nlp.coref.CorefCoreAnnotations)2 CorefChain (edu.stanford.nlp.coref.data.CorefChain)2 RelationTriple (edu.stanford.nlp.ie.util.RelationTriple)2