I want to generate sentence from grammar retrived from stanford parser, but NLTK is not able to interpret PRP$.
from nltk.parse.stanford import StanfordParser
f
ValueError: Unable to parse line 11: NP -> PRP$ NNS
Expected a nonterminal, found: $ NNS
I've no idea why you are trying to combine a hand-built CFG with the output of the Stanford parser, but here's a solution to this problem:
I quick inspection of nltk/grammar.py
shows that $
is not a legal character for a non-terminal name. This can be easily corrected by patching the module like this:
import nltk
import re
nltk.grammar._STANDARD_NONTERM_RE = re.compile('( [\w/][\w$/^<>-]* ) \s*', re.VERBOSE)
In the above I just added $
to the regexp that you'll find in nltk/grammar.py
. You can then create and use grammars that have $
in their productions:
grammar = nltk.grammar.CFG.fromstring("NP -> PRP$ NNS")