I want to analyze sentences with NLTK and display their chunks as a tree. NLTK offers the method tree.draw()
to draw a tree. This following code draws a tree for the sentence "the little yellow dog barked at the cat":
import nltk
sentence = [("the", "DT"), ("little", "JJ"), ("yellow", "JJ"), ("dog", "NN"), ("barked","VBD"), ("at", "IN"), ("the", "DT"), ("cat", "NN")]
pattern = "NP: {<DT>?<JJ>*<NN>}"
NPChunker = nltk.RegexpParser(pattern)
result = NPChunker.parse(sentence)
result.draw()
The result is this tree:
How do i get a tree with one more level like this?