Created
December 11, 2016 02:49
-
-
Save butsugiri/6b97c3e9e328f3cfc47e2b4bc513bde9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from nltk.tree import Tree | |
from nltk.tree import ParentedTree | |
from nltk.tree import ImmutableParentedTree | |
def main(): | |
tree = ImmutableParentedTree.fromstring("(ROOT (S (NP (NNP Dog)) (VP (VBZ likes) (NP (NN cat))) (. .)))") | |
t = tree.leaf_treeposition(1) | |
x = tree.leaf_treeposition(2) | |
print([tree[t[:i]].parent() for i in range(1, len(t))]) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment