You are on page 1of 1

from nltk import CFG //context free grammer

import nltk
grammar =CFG.fromstring("""

S->NP VP
NP->DET NOUN
NP->DET ADJ NOUN
NP ->ADJ NOUN
VP->VERB
VP->VERB NP
DET->'an' || 'a' | 'the'
NOUN ->girl | 'apple'| 'song' | 'boy'
ADJ->'cute' |'smart'
VERB->'sings'| 'eats'| 'are'

""")

You might also like