From: Sohail on 12 Aug 2010 11:56 Hi, When I define my own production rules for the grammar the code below runs fine. Can anyone tell me how to use the built in grammars of nltk (if there are any)? >>> groucho_grammar = nltk.parse_cfg(""" .... S -> NP VP .... PP -> P NP .... NP -> Det N | Det N PP | 'I' .... VP -> V NP | VP PP .... Det -> 'an' | 'my' .... N -> 'elephant' | 'pajamas' .... V -> 'shot' .... P -> 'in' .... """) >>> sent = ['I', 'shot', 'an', 'elephant', 'in', 'my', 'pajamas'] >>> parser = nltk.ChartParser(groucho_grammar) >>> trees = parser.nbest_parse(sent) >>> for tree in trees: .... print tree thanks
|
Pages: 1 Prev: unicode string alteration Next: OptParse and Constant values |