I use nltk trees to read the syntactic syntax expressions of the text in the text (using Tree.fromstring()), and I after finding the position of the sheet of the given subtree in the big tree. In principle, I would like to oppose it leaf_treeposition().
In the tree, tI got a subtree np, what I want is an indexx to:
t.leaves()[x] == np.leaves()[0]
I would not want to use it t.leaves().index(...), because maybe there are several occurrences in the sentence np, and I need the right one, not the first one.
What I have is the position of the tree npinside t(being ParentedTree) np.treeposition(), such that:
t[np.treeposition()] == np
I think that a tedious solution would be to summarize the sheets for all left_siblings npat all levels. Or I could go through all the leaves until leaf_treeposition(leaf)it becomes equal np.treeposition()+"[0]"*, but that sounds suboptimal.
Is there a better way?
source
share