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);
}
Aggregations