Search in sources :

Example 36 with Relation

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation 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)

Aggregations

Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)36 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)28 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)18 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)10 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)9 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)8 DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)7 ArrayList (java.util.ArrayList)7 LinkedHashSet (java.util.LinkedHashSet)7 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)5 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)5 BatchTrainer (edu.illinois.cs.cogcomp.lbjava.learn.BatchTrainer)5 Learner (edu.illinois.cs.cogcomp.lbjava.learn.Learner)5 Lexicon (edu.illinois.cs.cogcomp.lbjava.learn.Lexicon)5 LbjGen.relation_classifier (org.cogcomp.re.LbjGen.relation_classifier)4 Test (org.junit.Test)3 JsonObject (com.google.gson.JsonObject)2 ChunkerAnnotator (edu.illinois.cs.cogcomp.chunker.main.ChunkerAnnotator)2 ChunkerConfigurator (edu.illinois.cs.cogcomp.chunker.main.ChunkerConfigurator)2 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)2