本文整理匯總了Java中edu.stanford.nlp.trees.Tree.setChildren方法的典型用法代碼示例。如果您正苦於以下問題:Java Tree.setChildren方法的具體用法?Java Tree.setChildren怎麽用?Java Tree.setChildren使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edu.stanford.nlp.trees.Tree
的用法示例。
在下文中一共展示了Tree.setChildren方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: preorder
import edu.stanford.nlp.trees.Tree; //導入方法依賴的package包/類
private static String preorder(Tree tree) {
List<Tree> queue = new LinkedList<>();
queue.add(tree);
while ( ! queue.isEmpty()) {
Tree currentNode = queue.remove(0);
if (currentNode.isLeaf())
continue;
Tree children[] = currentNode.children();
int childCount = children.length;
IndexedWord hw = (IndexedWord) currentNode.label();
List<FeatureNode> featureNodes = new ArrayList<>(childCount);
for (int i = 0; i < childCount; i++) {
featureNodes.add(new FeatureNode(children[i], hw));
queue.add(children[i]);
}
if (childCount < 8) {
Pair<Double, List<Integer>> result = search(featureNodes, new LinkedList<Integer>(), Double.NEGATIVE_INFINITY);
if (result != null) {
List<Integer> permutation = result.second;
List<Tree> newChildren = new ArrayList<>(Arrays.asList(children));
for (int i = 0; i < childCount; i++) {
int idx = permutation.get(i);
newChildren.set(idx, children[i]);
}
currentNode.setChildren(newChildren);
} else {
System.err.println("Warning: No path found.");
}
}
}
return StringUtils.join(tree.yieldWords());
}