Search in sources :

Example 86 with Annotation

use of edu.stanford.nlp.pipeline.Annotation in project ud381 by udacity.

the class SentimentAnalyzer method findSentiment.

public static int findSentiment(String tweet) {
    int mainSentiment = 0;
    if (tweet != null && tweet.length() > 0) {
        int longest = 0;
        Annotation annotation = pipeline.process(tweet);
        for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
            Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);
            int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
            String partText = sentence.toString();
            if (partText.length() > longest) {
                mainSentiment = sentiment;
                longest = partText.length();
            }
        }
    }
    return mainSentiment;
}
Also used : SentimentCoreAnnotations(edu.stanford.nlp.sentiment.SentimentCoreAnnotations) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) SentimentCoreAnnotations(edu.stanford.nlp.sentiment.SentimentCoreAnnotations) RNNCoreAnnotations(edu.stanford.nlp.neural.rnn.RNNCoreAnnotations) Tree(edu.stanford.nlp.trees.Tree) CoreMap(edu.stanford.nlp.util.CoreMap) Annotation(edu.stanford.nlp.pipeline.Annotation)

Example 87 with Annotation

use of edu.stanford.nlp.pipeline.Annotation in project cogcomp-nlp by CogComp.

the class StanfordRelationsHandler method addView.

@Override
protected void addView(TextAnnotation ta) throws AnnotatorException {
    Annotation document = new Annotation(ta.text);
    pipeline.annotate(document);
    SpanLabelView vu = new SpanLabelView(viewName, ta);
    for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
        for (RelationMention rm : sentence.get(MachineReadingAnnotations.RelationMentionsAnnotation.class)) {
            if (rm.getType().equals("_NR"))
                continue;
            Map<String, Double> scores = new HashMap<>();
            for (String label : rm.getTypeProbabilities().keySet()) scores.put(label, rm.getTypeProbabilities().getCount(label));
            Constituent c1 = createConstituentGivenMention(rm.getEntityMentionArgs().get(0), ta);
            Constituent c2 = createConstituentGivenMention(rm.getEntityMentionArgs().get(1), ta);
            Relation r = new Relation(scores, c1, c2);
            vu.addRelation(r);
            if (!vu.containsConstituent(c1))
                vu.addConstituent(c1);
            if (!vu.containsConstituent(c2))
                vu.addConstituent(c2);
        }
    }
    for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
        for (EntityMention rm : sentence.get(MachineReadingAnnotations.EntityMentionsAnnotation.class)) {
            Constituent c = createConstituentGivenMention(rm, ta);
            if (!vu.containsConstituent(c))
                vu.addConstituent(c);
        }
    }
    ta.addView(viewName, vu);
}
Also used : RelationMention(edu.stanford.nlp.ie.machinereading.structure.RelationMention) SpanLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Annotation(edu.stanford.nlp.pipeline.Annotation) MachineReadingAnnotations(edu.stanford.nlp.ie.machinereading.structure.MachineReadingAnnotations) Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) EntityMention(edu.stanford.nlp.ie.machinereading.structure.EntityMention) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) CoreMap(edu.stanford.nlp.util.CoreMap) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 88 with Annotation

use of edu.stanford.nlp.pipeline.Annotation in project Info-Evaluation by TechnionYP5777.

the class AnalyzeParagragh method InteractiveAnalyze.

public InteractiveTableTuple InteractiveAnalyze() {
    final String $ = getName();
    final String input_date = getDate(year);
    String accurate_name = "";
    LinkedList<ReasonPair> reasons = InteractiveReasonFinding();
    final Properties props = new Properties();
    props.put("annotators", "tokenize,ssplit, pos, regexner, parse,lemma,natlog,openie");
    final StanfordCoreNLP pipeLine = new StanfordCoreNLP(props);
    final String inputText = input + "";
    final Annotation document = new Annotation(inputText);
    pipeLine.annotate(document);
    for (final CoreMap sentence : document.get(SentencesAnnotation.class)) {
        final SemanticGraph dependencies = sentence.get(CollapsedDependenciesAnnotation.class);
        for (final IndexedWord root : dependencies.getRoots()) for (final SemanticGraphEdge edge : dependencies.getOutEdgesSorted(root)) {
            final IndexedWord dep = edge.getDependent();
            if ("nsubjpass".equals((edge.getRelation() + ""))) {
                for (final SemanticGraphEdge keshet : dependencies.getOutEdgesSorted(dep)) {
                    final IndexedWord dep2 = keshet.getDependent();
                    final String rel2 = keshet.getRelation() + "";
                    if ("arrested".equals(edge.getGovernor().word()) && ((dep2.ner() != null && "PERSON".equals(dep2.ner())) || "compound".equals(rel2) || "det".equals(rel2)))
                        accurate_name += dep2.word() + " ";
                }
                accurate_name += dep.word();
            }
        }
    }
    return new InteractiveTableTuple(accurate_name.isEmpty() ? $ : accurate_name, input_date, reasons);
}
Also used : SemanticGraph(edu.stanford.nlp.semgraph.SemanticGraph) ReasonPair(main.database.ReasonPair) Properties(java.util.Properties) IndexedWord(edu.stanford.nlp.ling.IndexedWord) CoreMap(edu.stanford.nlp.util.CoreMap) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) SentencesAnnotation(edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation) Annotation(edu.stanford.nlp.pipeline.Annotation) CollapsedDependenciesAnnotation(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation) SemanticGraphEdge(edu.stanford.nlp.semgraph.SemanticGraphEdge) InteractiveTableTuple(main.database.InteractiveTableTuple)

Example 89 with Annotation

use of edu.stanford.nlp.pipeline.Annotation in project Info-Evaluation by TechnionYP5777.

the class AnalyzePage method createParagraphs.

private List<String> createParagraphs() {
    final Properties props = new Properties();
    props.setProperty("annotators", "tokenize, ssplit");
    props.setProperty("ssplit.eolonly", "true");
    final StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
    final Annotation document1 = new Annotation(originalText);
    pipeline.annotate(document1);
    final List<CoreMap> sentences = document1.get(CoreAnnotations.SentencesAnnotation.class);
    final List<String> $ = new ArrayList<>();
    for (final CoreMap ¢ : sentences) $.add(¢ + "");
    return $;
}
Also used : CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) ArrayList(java.util.ArrayList) Properties(java.util.Properties) CoreMap(edu.stanford.nlp.util.CoreMap) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) Annotation(edu.stanford.nlp.pipeline.Annotation)

Aggregations

Annotation (edu.stanford.nlp.pipeline.Annotation)89 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)56 CoreMap (edu.stanford.nlp.util.CoreMap)48 CoreLabel (edu.stanford.nlp.ling.CoreLabel)29 StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)26 ArrayList (java.util.ArrayList)24 Properties (java.util.Properties)24 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)19 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)14 TreeCoreAnnotations (edu.stanford.nlp.trees.TreeCoreAnnotations)13 SentencesAnnotation (edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation)12 TreeAnnotation (edu.stanford.nlp.trees.TreeCoreAnnotations.TreeAnnotation)12 List (java.util.List)11 Tree (edu.stanford.nlp.trees.Tree)9 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)8 IOException (java.io.IOException)8 TokensAnnotation (edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation)7 CorefChain (edu.stanford.nlp.coref.data.CorefChain)6 EntityMentionsAnnotation (edu.stanford.nlp.ie.machinereading.structure.MachineReadingAnnotations.EntityMentionsAnnotation)6 CoreAnnotation (edu.stanford.nlp.ling.CoreAnnotation)6