Loading And Editing A Cfg File For Grammar Parsing
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"