use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView in project cogcomp-nlp by CogComp.
the class GoldLabel method addAnnotation.
private void addAnnotation(TextAnnotation ta) {
Tree<String> tree = ParseUtils.getParseTree(ViewNames.PARSE_GOLD, ta, 0);
Tree<Pair<String, IntPair>> spanLabeledTree = ParseUtils.getSpanLabeledTree(tree);
List<Tree<Pair<String, IntPair>>> yield = spanLabeledTree.getYield();
PredicateArgumentView pav = new PredicateArgumentView(srlViewName, "AnnotatedTreebank", ta, 1.0);
Set<Integer> predicates = new HashSet<>();
for (Fields fields : goldFields.get(ta.getId())) {
Constituent predicate = fields.createPredicate(ta, srlViewName, yield);
if (predicates.contains(predicate.getStartSpan()))
continue;
predicates.add(predicate.getStartSpan());
List<Constituent> args = new ArrayList<>();
List<String> labels = new ArrayList<>();
List<Double> scores = new ArrayList<>();
// We need to make sure that the One-Argument-Per-Span constraint is
// respected. Yes sir, we do, even if the data says otherwise!
Set<IntPair> seenSpans = new HashSet<>();
for (GoldLabel arg : fields.getGoldLabels()) {
List<Constituent> aa = arg.getArgument(ta, srlViewName, yield, mergeContiguousCArgs);
List<Constituent> filtered = new ArrayList<>();
for (Constituent possibleArg : aa) {
if (seenSpans.contains(possibleArg.getSpan()))
continue;
seenSpans.add(possibleArg.getSpan());
filtered.add(possibleArg);
}
addArguments(ta, predicate, args, labels, scores, arg, filtered);
}
// for each arg
pav.addPredicateArguments(predicate, args, labels.toArray(new String[labels.size()]), ArrayUtilities.asDoubleArray(scores));
}
if (pav.getPredicates().size() > 0)
ta.addView(srlViewName, pav);
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView in project cogcomp-nlp by CogComp.
the class PathLSTMHandler method getSRL.
private PredicateArgumentView getSRL(TextAnnotation ta) throws Exception {
log.debug("Input: {}", ta.getText());
PredicateArgumentView pav = new PredicateArgumentView(viewName, "PathLSTMGenerator", ta, 1.0);
List<String> words = new LinkedList<String>();
// dummy ROOT token
words.add("<ROOT>");
// pre-tokenized text
words.addAll(Arrays.asList(ta.getTokens()));
// run SRL
Sentence parsed = SRLpipeline.parse(words);
for (Predicate p : parsed.getPredicates()) {
// skip nominal predicates
if (p.getPOS().startsWith("N"))
continue;
IntPair predicateSpan = new IntPair(p.getIdx() - 1, p.getIdx());
String predicateLemma = p.getLemma();
Constituent predicate = new Constituent("Predicate", viewName, ta, predicateSpan.getFirst(), predicateSpan.getSecond());
predicate.addAttribute(PredicateArgumentView.LemmaIdentifier, predicateLemma);
String sense = p.getSense();
predicate.addAttribute(PredicateArgumentView.SenseIdentifer, sense);
List<Constituent> args = new ArrayList<>();
List<String> relations = new ArrayList<>();
for (Word a : p.getArgMap().keySet()) {
Set<Word> singleton = new TreeSet<Word>();
String label = p.getArgumentTag(a);
Yield y = a.getYield(p, label, singleton);
IntPair span = new IntPair(y.first().getIdx() - 1, y.last().getIdx());
assert span.getFirst() <= span.getSecond() : ta;
args.add(new Constituent(label, viewName, ta, span.getFirst(), span.getSecond()));
relations.add(label);
}
pav.addPredicateArguments(predicate, args, relations.toArray(new String[relations.size()]), new double[relations.size()]);
}
return pav;
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView 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