Hi,
21 sep 2014 kl. 20:09 skrev
hebahal...@gmail.com:
> i'm trying to parse this simple grammar that works will without the epsilon production:
Epsilon rules are written like this:
VP ->
or, if you want to merge several right-hand sides:
VP -> V Adj | V NP | V S | V NP PP |
With your grammar below, "the little fish" is not a sentence, but just an NP. If you write the epsilon rule as I suggested, it should work.
best,
Peter Ljunglöf
> S -> NP VP
> NP -> Det Nom | PropN
> Nom -> Adj Nom | N
> VP -> V Adj | V NP | V S | V NP PP | epsilon
> PP -> P 'bad' NP
> PropN -> 'Buster' | 'Chatterer' | 'Joe'
> Det -> 'the' | 'a'
> N -> 'bear' | 'squirrel' | 'tree' | 'fish' | 'log'
> Adj -> 'angry' | 'frightened' | 'little' | 'tall'
> V -> 'chased' | 'saw' | 'said' | 'thought' | 'was' | 'put'
> P -> 'on'
>
> grammar1 = nltk.data.load('file:mygram.cfg')
> sent = "the little fish".split()
> rd_parser = nltk.RecursiveDescentParser(grammar1)
> for tree in rd_parser.parse(sent):
> print(tree)
>
> with this grammar i suppose to have the sentence "the little fish" parsed correctly but no parse tree is printed out!!!