Ejemplo n.º 1
0

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)]
Ejemplo n.º 2
0
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)]