Search in sources :

Example 16 with ScoredObject

use of edu.stanford.nlp.util.ScoredObject in project CoreNLP by stanfordnlp.

the class LexicalizedParserQuery method getKGoodFactoredParses.

public List<ScoredObject<Tree>> getKGoodFactoredParses(int k) {
    if (bparser == null || parseSkipped) {
        return null;
    }
    List<ScoredObject<Tree>> binaryTrees = bparser.getKGoodParses(k);
    if (binaryTrees == null) {
        return null;
    }
    List<ScoredObject<Tree>> trees = new ArrayList<>(k);
    for (ScoredObject<Tree> tp : binaryTrees) {
        Tree t = debinarizer.transformTree(tp.object());
        if (op.nodePrune) {
            NodePruner np = new NodePruner(pparser, debinarizer);
            t = np.prune(t);
        }
        t = subcategoryStripper.transformTree(t);
        restoreOriginalWords(t);
        trees.add(new ScoredObject<>(t, tp.score()));
    }
    return trees;
}
Also used : ScoredObject(edu.stanford.nlp.util.ScoredObject) ArrayList(java.util.ArrayList) Tree(edu.stanford.nlp.trees.Tree)

Example 17 with ScoredObject

use of edu.stanford.nlp.util.ScoredObject in project CoreNLP by stanfordnlp.

the class LexicalizedParserQuery method getKBestPCFGParses.

/**
 * Returns the trees (and scores) corresponding to the
 * k-best derivations of the sentence.  This cannot be
 * a Counter because frequently there will be multiple
 * derivations which lead to the same parse tree.
 *
 * @param k The number of best parses to return
 * @return The list of trees with their scores (log prob).
 */
public List<ScoredObject<Tree>> getKBestPCFGParses(int k) {
    if (pparser == null) {
        return null;
    }
    List<ScoredObject<Tree>> binaryTrees = pparser.getKBestParses(k);
    if (binaryTrees == null) {
        return null;
    }
    List<ScoredObject<Tree>> trees = new ArrayList<>(k);
    for (ScoredObject<Tree> p : binaryTrees) {
        Tree t = debinarizer.transformTree(p.object());
        t = subcategoryStripper.transformTree(t);
        restoreOriginalWords(t);
        trees.add(new ScoredObject<>(t, p.score()));
    }
    return trees;
}
Also used : ScoredObject(edu.stanford.nlp.util.ScoredObject) ArrayList(java.util.ArrayList) Tree(edu.stanford.nlp.trees.Tree)

Aggregations

ScoredObject (edu.stanford.nlp.util.ScoredObject)17 Tree (edu.stanford.nlp.trees.Tree)11 ArrayList (java.util.ArrayList)11 ParserConstraint (edu.stanford.nlp.parser.common.ParserConstraint)7 List (java.util.List)6 PriorityQueue (java.util.PriorityQueue)5 Pair (edu.stanford.nlp.util.Pair)4 NoSuchParseException (edu.stanford.nlp.parser.common.NoSuchParseException)3 Word (edu.stanford.nlp.ling.Word)2 ParserQuery (edu.stanford.nlp.parser.common.ParserQuery)2 TreePrint (edu.stanford.nlp.trees.TreePrint)2 Timing (edu.stanford.nlp.util.Timing)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 CoreLabel (edu.stanford.nlp.ling.CoreLabel)1 EvaluateTreebank (edu.stanford.nlp.parser.lexparser.EvaluateTreebank)1 LexicalizedParser (edu.stanford.nlp.parser.lexparser.LexicalizedParser)1 RerankingParserQuery (edu.stanford.nlp.parser.lexparser.RerankingParserQuery)1 AbstractEval (edu.stanford.nlp.parser.metrics.AbstractEval)1