本文整理汇总了Java中edu.stanford.nlp.trees.CollinsHeadFinder类的典型用法代码示例。如果您正苦于以下问题:Java CollinsHeadFinder类的具体用法?Java CollinsHeadFinder怎么用?Java CollinsHeadFinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CollinsHeadFinder类属于edu.stanford.nlp.trees包,在下文中一共展示了CollinsHeadFinder类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: complexityOf
import edu.stanford.nlp.trees.CollinsHeadFinder; //导入依赖的package包/类
/**
* Syntactic complexity as defined by Lin (1996).
*
* @param tree
* @return
*/
private static int complexityOf(Tree tree) {
tree.indexLeaves();
tree.percolateHeads(new CollinsHeadFinder());
tree.percolateHeadIndices();
Set<Dependency<Label,Label,Object>> deps = tree.dependencies();
int complexity = 0;
for (Dependency<Label,Label,Object> dep : deps) {
if (!(dep instanceof UnnamedConcreteDependency)) {
throw new RuntimeException("Cannot measure syntactic complexity.");
}
UnnamedConcreteDependency uDep = (UnnamedConcreteDependency) dep;
int headIndex = uDep.getGovernorIndex();
int depIndex = uDep.getDependentIndex();
complexity += Math.abs(headIndex - depIndex);
}
return complexity;
}