Example usage for edu.stanford.nlp.ie.machinereading.structure RelationMention getEntityMentionArgs

List of usage examples for edu.stanford.nlp.ie.machinereading.structure RelationMention getEntityMentionArgs

Introduction

In this page you can find the example usage for edu.stanford.nlp.ie.machinereading.structure RelationMention getEntityMentionArgs.

Prototype

public List<EntityMention> getEntityMentionArgs() 

Source Link

Document

Fetches the arguments of this relation that are entity mentions

Usage

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   w ww .  j a  v a  2s.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);
}