Search in sources :

Example 26 with Relation

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation in project cogcomp-nlp by CogComp.

the class CommaLabeler method addView.

@Override
public void addView(TextAnnotation ta) throws AnnotatorException {
    // Check that we have the required views
    for (String requiredView : requiredViews) {
        if (!ta.hasView(requiredView))
            throw new AnnotatorException("Missing required view " + requiredView);
    }
    // Create the Comma structure
    CommaSRLSentence sentence = new CommaSRLSentence(ta, ta);
    PredicateArgumentView srlView = new PredicateArgumentView(viewName, "illinois-comma", ta, 1.0d);
    for (Comma comma : sentence.getCommas()) {
        String label = classifier.discreteValue(comma);
        int position = comma.getPosition();
        Constituent predicate = new Constituent("Predicate:" + label, viewName, ta, position, position + 1);
        predicate.addAttribute(PredicateArgumentView.SenseIdentifer, label);
        srlView.addConstituent(predicate);
        Constituent leftArg = comma.getPhraseToLeftOfComma(1);
        if (leftArg != null) {
            Constituent leftArgConst = new Constituent(leftArg.getLabel(), viewName, ta, leftArg.getStartSpan(), leftArg.getEndSpan());
            srlView.addConstituent(leftArgConst);
            srlView.addRelation(new Relation("LeftOf" + label, predicate, leftArgConst, 1.0d));
        }
        Constituent rightArg = comma.getPhraseToRightOfComma(1);
        if (rightArg != null) {
            Constituent rightArgConst = new Constituent(rightArg.getLabel(), viewName, ta, rightArg.getStartSpan(), rightArg.getEndSpan());
            srlView.addConstituent(rightArgConst);
            srlView.addRelation(new Relation("RightOf" + label, predicate, rightArgConst, 1.0d));
        }
    }
    ta.addView(viewName, srlView);
}
Also used : Comma(edu.illinois.cs.cogcomp.comma.datastructures.Comma) Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) CommaSRLSentence(edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence) PredicateArgumentView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Aggregations

Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)26 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)25 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)16 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)10 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)9 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)8 DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)7 ArrayList (java.util.ArrayList)7 LinkedHashSet (java.util.LinkedHashSet)7 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)5 JsonObject (com.google.gson.JsonObject)3 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)3 Test (org.junit.Test)3 JsonParser (com.google.gson.JsonParser)2 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)2 Tree (edu.illinois.cs.cogcomp.core.datastructures.trees.Tree)2 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)2 Annotation (edu.stanford.nlp.pipeline.Annotation)2 CoreMap (edu.stanford.nlp.util.CoreMap)2 HashSet (java.util.HashSet)2