本文整理匯總了Java中edu.stanford.nlp.trees.Tree.firstChild方法的典型用法代碼示例。如果您正苦於以下問題:Java Tree.firstChild方法的具體用法?Java Tree.firstChild怎麽用?Java Tree.firstChild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edu.stanford.nlp.trees.Tree
的用法示例。
在下文中一共展示了Tree.firstChild方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: countLeaves
import edu.stanford.nlp.trees.Tree; //導入方法依賴的package包/類
/**
* @return The number of leaves (words) in this tree
*/
// public static int treeWordLength(Tree tree) {
// return countLeaves(tree)-1;
// }
public static int countLeaves(Tree tree) {
int sum = 0;
// System.out.println("top with tree " + tree);
// if( tree.isPreTerminal() ) {
// Phone numbers are (CD (727) 894-1000) ... but they aren't in the
// "preterminal" definition of the function, so we much explicitly check.
// if( tree.isPreTerminal() || tree.label().value().equals("CD") ) {
if( tree.firstChild() != null && tree.firstChild().isLeaf() ) {
// System.out.println("leaf: " + tree);
return 1;
}
else {
// System.out.println("getchildren " + tree.getChildrenAsList().size());
for( Tree child : tree.getChildrenAsList() ) {
sum += countLeaves(child);
}
}
return sum;
}