How To Get A Node In A Tree By Its Label In Nltk Python?
I have a tree: (S (WH-QUERY Which) (FLIGHT-NP (FLIGHT-CNP (FLIGHT-CNP (FLIGHT-N flight)) (FLIGHT-DEST to (CITY-NP (CITY-NAME Hu
Solution 1:
One way to do it is to walk the tree searching for nodes that match:
for subtree in tree.subtrees():
if subtree.label() == 'CITY-NAME':
print subtree.leaves()
Post a Comment for "How To Get A Node In A Tree By Its Label In Nltk Python?"