I didn’t found any example on this problem, so I want to provide sample code for someone who is not that familiar with reading API.
# Construct nltk.tree.Tree s = '(ROOT (S (NP (NP (DT The) (JJ old) (NN oak) (NN tree)) (PP (IN from) (NP (NNP India)))) (VP (VBD fell) (PRT (RP down)))))' my_tree = Tree.fromstring(s) # Convert my_tree to ParentedTree my_parented_tree = ParentedTree(0, []) my_parented_tree = my_parented_tree.convert(my_tree) # Check result print(type(my_parented_tree)) my_parented_tree.draw()
Reference: