Python NLTK parsing error? 'str' object has no attribute 'check_coverage' -


i trying use nltk determine if sentence valid. loaded grammar, whenever try parser not work , error "attributeerror: 'str' object has no attribute 'check_coverage'" code:

sentence = ['show', 'me', 'northwest', 'flights', 'to', 'detroit', '.'] grammar = nltk.data.load('grammars/large_grammars/atis.cfg', 'text') parser =  nltk.parse.bottomupchartparser(grammar) chart = parser.chart_parse(sentence) 

here full traceback: traceback (most recent call last):

 file "<ipython-input-448-852d3bb24984>", line 1, in <module>  chart = parser.chart_parse(sentence)   file "c:\users\class2016\anaconda3\lib\site-packages\nltk\parse\chart.py",   line 1310, in chart_parse   self._grammar.check_coverage(tokens)  attributeerror: 'str' object has no attribute 'check_coverage' 

i got part of code example listed here under unit tests large context-free grammars: http://www.nltk.org/howto/parse.html

any information on why happening or how correct appreciated.

thanks!

going this link, might want parse rules first using nltk.parse_cfg:

rules = nltk.data.load('grammars/large_grammars/atis.cfg', 'text') grammar = nltk.parse_cfg(rules) parser =  nltk.parse.bottomupchartparser(parsed_grammar) 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -