Python Forum

Full Version: [nltk] Parsing with CFG
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi

I am reading "Natural Language Processing with Python" and the author gives example of use of CFG in nltk

 grammar2 = nltk.parse_cfg("""
 S -> NP VP
 NP -> Det Nom | PropN
 Nom -> Adj Nom | N
 VP -> V Adj | V NP | V S | V NP PP
 PP -> P NP
 PropN -> 'Buster' | 'Chatterer' | 'Joe'
 Det -> 'the' | 'a'
 N -> 'bear' | 'squirrel' | 'tree' | 'fish' | 'log'
 Adj -> 'angry' | 'frightened' | 'little' | 'tall'
 V -> 'chased' | 'saw' | 'said' | 'thought' | 'was' | 'put'
 P -> 'on'
 """)


But what if I want to parse arbitary sentence? How I can automize the process of description of given sentence? I was thinking that I can use tagged sentence, but nltk functions for parsing take only list of words (not list of tuples with word and tag).