List of usage examples for edu.stanford.nlp.ie.machinereading.structure RelationMention getType
public String getType()
From source file:edu.illinois.cs.cogcomp.pipeline.handlers.StanfordRelationsHandler.java
License:Open Source License
@Override protected void addView(TextAnnotation ta) throws AnnotatorException { Annotation document = new Annotation(ta.text); pipeline.annotate(document);/*from ww w . j ava 2 s.c o m*/ 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); }