0
$\begingroup$

To read Context Free Grammars we can use

nltk.CFG.fromstring(""" 
S-> NP VP`...
    """)

But it can't read a feature based grammar which is like?

S -> NP[NUM=?n] VP[NUM=?n]

So how to read feature based grammar from a string without actually having to save it in a fcfg file to load it later?

$\endgroup$
1
$\begingroup$

You need to take care of NP and VP expansion production.

# ###################
# Grammar Productions
# ###################
# S expansion productions
S -> NP[NUM=?n] VP[NUM=?n]
# NP expansion productions
NP[NUM=?n] -> N[NUM=?n]
NP[NUM=?n] -> PropN[NUM=?n]
NP[NUM=?n] -> Det[NUM=?n] N[NUM=?n]
NP[NUM=pl] -> N[NUM=pl]
# VP expansion productions
VP[TENSE=?t, NUM=?n] -> IV[TENSE=?t, NUM=?n]
VP[TENSE=?t, NUM=?n] -> TV[TENSE=?t, NUM=?n] NP
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.