0
votes

I'm playing with NLTK and I meet a problem with the grammar. (I didn't find any topics about this problem) For example with a grammar gram.cfg:

S -> NP VP
NP -> 'I'
VP -> V ADJ WHO
ADJ -> 'tall' | 'big' | 'white'
V -> 'am'
WHO -> 'Groot'

and the sentence "I am tall Groot" it's worked. I want to have a grammar like

VP -> V (ADJ)* WHO

to have the possibility to obtain sentences like:

"I am white big tall Groot"

"I am big Groot"

"I am tall white Groot"

Only with the same rule VP

How can I do to multiply possibilities with one grammar rule (as showed in example) ?

Is there a documentation about that ? (dynamic rules, about optional rules, undefined number of rules ...etc)

1

1 Answers

0
votes

If it is possible for you to use a recursive grammar the following may work.

ADJ -> 'tall' | 'big' | 'white' | ADG