use of se.lth.cs.srl.corpus.Yield 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;
}
Aggregations