Accessing a parse tree

John Machin sjmachin at lexicon.net
Thu Apr 16 23:16:07 EDT 2009


On Apr 17, 8:55 am, Clarendon <jine... at hotmail.com> wrote:
> Hello!
>
> 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.
>
> (ROOT
>   (S
>     (NP (PRP I))
>     (VP (VBD came)
>       (NP (DT a) (JJ long) (NN way))
>       (PP (IN in)
>         (S
>           (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.

Why is the answer not (S (VP (NP (DT ? You may need to explain what
you mean by "before" and "after" ... also the parentheses are an
artifact of this particular method of representing a parse tree. What
in general terms are you trying to do?

> Then the program should

some text is missing here

> that
> the designated wordssee are followed by (PP (IN in) and then by  (S

what is "wordssee"?

> (VP (VBG.
>
> 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.

Having a clear statement of requirements would make a good start.



More information about the Python-list mailing list