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