Search in sources :

Example 1 with Sentence

use of se.lth.cs.srl.corpus.Sentence 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;
}
Also used : Word(se.lth.cs.srl.corpus.Word) ArrayList(java.util.ArrayList) IntPair(edu.illinois.cs.cogcomp.core.datastructures.IntPair) PredicateArgumentView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView) LinkedList(java.util.LinkedList) Predicate(se.lth.cs.srl.corpus.Predicate) TreeSet(java.util.TreeSet) Yield(se.lth.cs.srl.corpus.Yield) Sentence(se.lth.cs.srl.corpus.Sentence) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Aggregations

IntPair (edu.illinois.cs.cogcomp.core.datastructures.IntPair)1 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)1 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 TreeSet (java.util.TreeSet)1 Predicate (se.lth.cs.srl.corpus.Predicate)1 Sentence (se.lth.cs.srl.corpus.Sentence)1 Word (se.lth.cs.srl.corpus.Word)1 Yield (se.lth.cs.srl.corpus.Yield)1