"Vt -> 'ate' | 'book' | 'Book' | 'gave' | 'told'", #transitive "Vdt -> 'gave' | 'told' ", #ditransitive "Subconj -> 'that'", #subordinating conjunction "Mod -> 'Can' | 'will'", #modal verbs "Aux -> 'did' ", #auxiliary verbs "WhAdv -> 'Why'", "PropN -> 'John' | 'Mary' | 'NYC' | 'London'", "Adj -> 'nice' | 'drawing'", "Pro -> 'you' | 'he'", "Adv -> 'today'" ]) print(grammar) #the simpler grammar chart=CKY(grammar) #this illustrates tracing of a very simple sentence; feel free to try others. chart.recognise(tokenise("the frogs swim"),True) chart.pprint() #build a chart with the larger grammar chart2=CKY(grammar2) # Note, please do _not_ use the Tree.draw() method uncommented # _anywhere in this file_ (you are encouraged to use it in preparing # your report). # The sentences to examine. # for s in ["John gave a book to Mary.", "John gave Mary a book.", "John gave Mary a nice drawing book.", "John ate salad with mushrooms with a fork.",
Det -> NP "'s" Nom -> N SRel | N VP -> Vi | Vt NP | VP PP PP -> Prep NP SRel -> Relpro VP Det -> 'a' | 'the' N -> 'fish' | 'frogs' | 'soup' | 'children' | 'books' Prep -> 'in' | 'for' Vt -> 'saw' | 'ate' | 'read' Vi -> 'fish' | 'swim' Relpro -> 'that' """) print(grammar) chart = CKY(grammar) chart.recognise("the frogs swim".split()) # Should use # tokenise(s) once that's fixed chart.pprint() # Q1: Uncomment this once you've completed Q1 chart.recognise(tokenise("the frogs swim"), True) # Q3 Uncomment the next three once when you're working on Q3 chart.recognise(tokenise("fish fish")) chart.pprint() chart.recognise(tokenise("fish fish"), True) # Use this grammar for the rest of the assignment grammar2 = parse_grammar([ "S -> Sdecl '.' | Simp '.' | Sq '?' ", "Sdecl -> NP VP", "Simp -> VP", "Sq -> Sqyn | Swhadv", "Sqyn -> Mod Sdecl | Aux Sdecl", "Swhadv -> WhAdv Sqyn", "Sc -> Subconj Sdecl", "NP -> PropN | Pro | NP0 ",
"Vt -> 'ate' | 'book' | 'Book' | 'gave' | 'told'", #transitive "Vdt -> 'gave' | 'told' ", #ditransitive "Subconj -> 'that'", #subordinating conjunction "Mod -> 'Can' | 'will'", #modal verbs "Aux -> 'did' ", #auxiliary verbs "WhAdv -> 'Why'", "PropN -> 'John' | 'Mary' | 'NYC' | 'London'", "Adj -> 'nice' | 'drawing'", "Pro -> 'you' | 'he'", "Adv -> 'today'" ]) print(grammar) #the simpler grammar chart = CKY(grammar) #this illustrates tracing of a very simple sentence; feel free to try others. chart.recognise(tokenise("the frogs swim"), True) chart.pprint() #build a chart with the larger grammar chart2 = CKY(grammar2) # Note, please do _not_ use the Tree.draw() method uncommented # _anywhere in this file_ (you are encouraged to use it in preparing # your report). # The sentences to examine. # # for s in ["John gave a book to Mary.", # "John gave Mary a book.", # "John gave Mary a nice drawing book.", # "John ate salad with mushrooms with a fork.",
"Adj -> 'nice' | 'drawing'", "Pro -> 'you' | 'he'", "Adv -> 'today'" ]) print(grammar) #the simpler grammar chart = CKY(grammar) #this illustrates tracing of a very simple sentence; feel free to try others. # chart.recognise(tokenise("the frogs swim"),True) # chart.pprint() #build a chart with the larger grammar chart2 = CKY(grammar2) # Note, please do _not_ use the Tree.draw() method uncommented # _anywhere in this file_ (you are encouraged to use it in preparing # your report). # The sentences to examine. # for s in ["Book a flight to NYC."]: print(s, chart2.recognise(tokenise(s), True)) chart2.pprint() # print(s, chart2.recognise(tokenise(s), True)) # Task 5 # for s in [...]: # print(s, chart2.parse(tokenise(s))) # print(chart2.firstTree().pprint())
#chart.pprint() #build a chart with the larger grammar chart2=CKY(grammar2) #chart2.recognise(tokenise("John gave a book to Mary."),True) #chart2.pprint() # Note, please do _not_ use the Tree.draw() method uncommented # _anywhere in this file_ (you are encouraged to use it in preparing # your report). # The sentences to examine. for s in ["John gave a book to Mary.", "John gave Mary a book.", "John gave Mary a nice drawing book.", "John ate salad with mushrooms with a fork.", "Book a flight to NYC.", "Can you book a flight to London?", "Why did John book the flight?", "John told Mary that he will book a flight today."]: print(s, chart2.recognise(tokenise(s))) chart2.pprint() # Task 5 # for s in [...]: # print(s, chart2.parse(tokenise(s))) # print(chart2.firstTree().pprint())