Re: [nltk-users] Parsing grammar with Epsilon production but yet no parse tree is printed out !

541 views
Skip to first unread message

Peter Ljunglöf

unread,
Sep 21, 2014, 3:52:28 PM9/21/14
to nltk-...@googlegroups.com
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!!!



hebahal...@gmail.com

unread,
Sep 22, 2014, 3:47:18 AM9/22/14
to nltk-...@googlegroups.com
Thanx a lot :D :D :D :D :D  
Reply all
Reply to author
Forward
0 new messages