本文整理汇总了Python中nltk.tree.ParentedTree.parent_index方法的典型用法代码示例。如果您正苦于以下问题:Python ParentedTree.parent_index方法的具体用法?Python ParentedTree.parent_index怎么用?Python ParentedTree.parent_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.tree.ParentedTree
的用法示例。
在下文中一共展示了ParentedTree.parent_index方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getTag
# 需要导入模块: from nltk.tree import ParentedTree [as 别名]
# 或者: from nltk.tree.ParentedTree import parent_index [as 别名]
def getTag(senArr, root):
return senArr[int(root.label())][3]
if __name__ == "__main__":
senArr_eg = ["1 I _ NN NN _ 2 _ _ _",
"2 love _ VB VB _ 0 _ _ _",
"3 to _ TO TO _ 4 _ _ _",
"4 eat _ VB VB _ 2 _ _ _",
"5 cabbage _ NN NN _ 4 _ _ _"]
print "****input_example:"
print "\n".join(senArr_eg)
senArr_eg = [line.split("\t") for line in senArr_eg]
root = conll2tree(senArr_eg)
print "****tree", root
print "****height", root.height()
print "root.label", root.label()
print root[0]
children_of_root = getChildren(root)
for child in children_of_root:
print "*** child of root", child.label()
print "tree position", ParentedTree.treeposition(child)
print "parent", ParentedTree.parent(child)
print "parent_idx", ParentedTree.parent_index(child)
print root[ParentedTree.parent_index(child)]