Accessing a parse tree

Clarendon jineu21 at
Fri Apr 17 00:55:16 CEST 2009


I need a program that accesses a parse tree based on the designated
words (terminals) within the tree. For instance, in:

I came a long way in changing my habit.

    (NP (PRP I))
    (VP (VBD came)
      (NP (DT a) (JJ long) (NN way))
      (PP (IN in)
          (VP (VBG changing)
            (NP (PRP$ my) (NN habit))))))

the designated words are "a long way". I need the program to recognize
how many parentheses there are after them. Currently two: NN way)).
Then I need it to see how many parentheses there are before it.
Currently there are two as well: (NP (DT. Then the program should that
the designated wordssee are followed by (PP (IN in) and then by  (S

I looked at the NLTK Tree class but it does not seem to have a method
that works with designated words. Is there some kind of tree navigator
that does something like this? If I need to write one myself, I would
appreciate any tips about where to start.


More information about the Python-list mailing list