Question: I need to parse a sentence using these rules S VP S VP NP S NP VP VP Verb NP VP Verb NP (PP*) VP

I need to parse a sentence using these rules S VP

S VP NP

S NP VP

VP Verb NP

VP Verb NP (PP*)

VP VP PP

VP VP CC VP

VP Verb

VP Verb VP

NP Noun NP

NP NP PP

NP NP CC NP

NP Det Adj Noun |

Det Noun (PP)

NP Det Noun

NP (Art) (Adj) Noun

PP Prep NP

CC Conjunction this is the code I did but I got no output import nltk

grammar = nltk.CFG.fromstring(""" S -> NP VP NP -> N NP | Adj VP -> Verb VP | Verb NP Adj -> 'visiting' | 'tiresome' N -> 'relatives' V -> 'can' | 'be' """)

sent = ['visiting', 'relatives', 'can', 'be', 'tiresome'] parser = nltk.ChartParser(grammar) for tree in parser.parse(sent): print(tree)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!