Reputation: 67
I searched a long time the internet for an answer, but didn't find one. So you are my last hope :) Maybe someone here can help me.
I have a sentence/question which I want to process: "How much could you rent a Volkswagen bug for in 1966?"
I want to get the relations between the words, like in this picture Sorry, I can not post images, so here a link. http://s24.postimg.org/kl6uc1xrp/Bildschirmfoto_2015_03_11_um_22_34_27.png
But I don't know how to do that. I tried for example:
text = nltk.word_tokenize("How much could you rent a Volkswagen bug for in 1966?")
posTagged = nltk.pos_tag(text)
n = nltk.chunk.ne_chunk(posTagged)
n.draw()
But I get only a flat tree and that isn't helping me at all. I would be very, very happy if anyone could help me :)
With best regards, Oliver
Upvotes: 0
Views: 977
Reputation: 1281
Not sure what you mean by 'inter-term relations', but it sounds like you need dependency parsing. (google it, it's an active field of NLP research).
If all you care about is producing a parse tree for a given input sentence, I'd suggest you use some freely available parser for this, such as the one from stanford: http://nlp.stanford.edu/software/stanford-dependencies.shtml
If you explicitly have/want to use nltk for this, look here for some examples: http://www.nltk.org/howto/parse.html There are some very basic grammars in there that you could use, but if you need to get a little more out of this, pretty soon you'll have to start writing your own grammar. The nltk regexpParser is particularly simple and easy to use. I don't have any experience with producing graphical output/trees in nltk, but I guess it should be possible.
Upvotes: 1