本文整理汇总了Python中nltk.Tree.height方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.height方法的具体用法?Python Tree.height怎么用?Python Tree.height使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.Tree
的用法示例。
在下文中一共展示了Tree.height方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_psd_sent_2_segmentation_2
# 需要导入模块: from nltk import Tree [as 别名]
# 或者: from nltk.Tree import height [as 别名]
def convert_psd_sent_2_segmentation_2(parsed_corpus):
SegCorpus=[]
for top_k_psd_of_the_sent in parsed_corpus:
segmentation=[]
best_score, best_parse_tree_str= top_k_psd_of_the_sent[0]
tree=Tree(best_parse_tree_str)
# tree=ROOT, tree[0]=S, tree[0, ] is the subtrees of S, i.e. POS tags, we can use alternative methods
# note that it is highly dependent on the format of the parser outputs!!
for subtree in tree.subtrees(lambda t: t.height()==tree.height()-2):
segmentation.append(''.join(subtree.leaves()))
SegCorpus.append(segmentation)
if not ''.join(segmentation)==''.join(tree.leaves()):
print('Error! Leaves/characters in thee segmentation != total characters in the tree (as leaves), Double check the format and/or code!')
break
return SegCorpus