Relation relation = new Relation(type.split("[(]")[0], firstArg, secondArg, 1.0f); relation.addAttribute("RelationSubtype", relation.getRelationName()); mentionView.addRelation(relation); mentionView.addRelation(relation); relationLeft.addAttribute("RelationSubtype", relationLeft.getRelationName()); relationRight.addAttribute("RelationSubtype", relationRight.getRelationName()); mentionView.addRelation(relationLeft); mentionView.addRelation(relationRight);
entityView.addRelation(entityRelation);
entityView.addRelation(entityRelation);
entityView.addRelation(entityRelation);
@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); }
@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)) { Collection<RelationTriple> triples = sentence.get(NaturalLogicAnnotations.RelationTriplesAnnotation.class); for (RelationTriple triple : triples) { Constituent subject = getConstituent(triple.subjectGloss(), triple.subjectTokenSpan(), sentence, ta); subject.addAttribute("subjectGloss", triple.subjectGloss()); subject.addAttribute("subjectLemmaGloss", triple.subjectLemmaGloss()); subject.addAttribute("subjectLink", triple.subjectLink()); Constituent object = getConstituent(triple.objectGloss(), triple.objectTokenSpan(), sentence, ta); object.addAttribute("objectGloss", triple.objectGloss()); object.addAttribute("objectLemmaGloss", triple.objectLemmaGloss()); object.addAttribute("objectLink", triple.objectLink()); Constituent relation = getConstituent(triple.relationGloss(), triple.relationTokenSpan(), sentence, ta); relation.addAttribute("relationGloss", triple.relationGloss()); relation.addAttribute("relationLemmaGloss", triple.relationLemmaGloss()); Relation subj = new Relation("subj", relation, subject, triple.confidence); Relation obj = new Relation("obj", relation, object, triple.confidence); vu.addRelation(subj); vu.addRelation(obj); vu.addConstituent(subject); vu.addConstituent(object); vu.addConstituent(relation); } } ta.addView(viewName, vu); }