I have the following code in Python.
sent = [("very","ADJ"),("colourful","ADJ"),("ice","NN"),("cream","NN"),("van","NN")] patterns= r""" NP:{<ADJ>*<NN>+} """ NPChunker=nltk.RegexpParser(patterns) # create chunk parser for s in NPChunker.nbest_parse(sent): print s.draw()
Output:
(S (NP very/ADJ colourful/ADJ ice/NN cream/NN van/NN))
But the output should be 2 more parsing trees.
(S (NP very/ADJ colourful/ADJ ice/NN) (NP cream/NN) (NP van/NN)) (S (NP very/ADJ colourful/ADJ ice/NN cream/NN) van/NN)
The problem is that only the first regular expression is taken by RegexpParser. How can I generate all possible parsing trees at once?
python regex nlp nltk
gamma
source share