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);
}
Aggregations