Skip to content Skip to sidebar Skip to footer

Loading And Editing A Cfg File For Grammar Parsing

I am following the steps mentioned here - http://www.nltk.org/book/ch10.html to load and parse data using a cfg file. When I use the code below I don't face any issue. cp = load_

Solution 1:

The prototype for nltk.load_parser is

nltk.load_parser(grammar_url, trace=0, parser=None, chart_class=None, beam_size=0, **load_args)

Note that the first argument is a "url", not just a file path (See the data Module documentation for a very brief explanation). An nltk URL starts with a protocol followed by a colon, so it will interpret C: as a protocol. You should probably be explicit: file:C:/Users/212757677/Desktop/mygrammar.fcfg. (Or perhaps it's file:///C:/Users/212757677/Desktop/mygrammar.fcfg -- I don't have a Windows machine to test it on.)

nltk.load_parser guesses the grammar format based on the filename extension. In this case, you're loading a feature grammar (.fcfg), not a simple CFG. If you want to create the parser manually, you should follow the example in the NLTK how-to on feature grammar parsing.

Post a Comment for "Loading And Editing A Cfg File For Grammar Parsing"