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

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

Introduction

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

Prototype

public Counter<String> getTypeProbabilities() 

Source Link

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  www.  jav  a2s  .c om*/
    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);
}