What constraints are required to correctly parse word sequences like I am happy and she is happy but not you is happy or they am happy? Implement two solutions for the present tense paradigm of the verb be in English, first taking Grammar (8) as your starting point, and then taking Grammar (20) as the starting point.
In [ ]:
S -> NP_SG V
S -> NP_SG2 V
NP_SG -> N_SG Det_SG
NP_PL -> N_SG2 Det_SG2
VP -> V
Det_SG -> 'AM'
Det_SG2 -> 'IS'
N_SG -> 'I'
N_SG2 -> 'HE' | 'SHE'
V -> 'HAPPY'
In [ ]:
S -> NP[AGR=?n] VP[AGR=?n]
NP[AGR=?n] -> PropN[AGR=?n]
VP[TENSE=?t, AGR=?n] -> Cop[TENSE=?t, AGR=?n] Adj
Cop[TENSE=pres, AGR=[NUM=sg, PER=3]] -> 'is'
PropN[AGR=[NUM=sg, PER=3]] -> 'He'
Adj -> 'happy'
Develop a variant of grammar in 9.1 that uses a feature count to make the distinctions shown below:
In [ ]:
Det[NUM=sg] -> 'the'
N[NUM=sg] -> 'boy'
V[NUM=sg] -> 'runs'
S -> NP[NUM=?n] VP[NUM=?n]
NP[NUM=?n] -> Det[NUM=?n] N[NUM=?n]
VP[NUM=?n] -> V[NUM=?n]
In [ ]:
Det[NUM=pl] -> 'the'
N[NUM=pl] -> 'boys'
V -> 'sing'
S -> NP[NUM=?n] VP
NP[NUM=?n] -> Det[NUM=?n] N[NUM=?n] | N[NUM=?n]
VP -> V
In [ ]:
Det[NUM=pl] -> 'the'
N[NUM=pl] -> 'boys'
V -> 'sing'
S -> NP[NUM=?n] VP
NP[NUM=?n] -> Det[NUM=?n] N[NUM=?n] | N[NUM=?n]
VP -> V
In [ ]:
Det[NUM=pl] -> 'The'
N[NUM=pl] -> 'water'
V -> 'precious'
S -> NP[NUM=?n] VP
NP[NUM=?n] -> Det[NUM=?n] N[NUM=?n] | N[NUM=?n]
VP -> V
Write a function subsumes() which holds of two feature structures fs1 and fs2 just in case fs1 subsumes fs2.
In [ ]:
#this is a pseudocode
def subsumes(fs1,fs2):
var unification = fs2.unify(fs1)
if unification is_more_specific than fs1 and fs2:
return True
else
return False
Modify the grammar illustrated in (30) to incorporate a bar feature for dealing with phrasal projections.
In [ ]:
VP[TENSE=?t, NUM=?n] -> V[SUBCAT=intrans, TENSE=?t, NUM=?n]
VP[TENSE=?t, NUM=?n] -> V[SUBCAT=trans, TENSE=?t, NUM=?n] NP
VP[TENSE=?t, NUM=?n] -> V[SUBCAT=clause, TENSE=?t, NUM=?n] SBar
Modify the German grammar in 9.5 to incorporate the treatment of subcategorization presented in 9.3.
In [ ]:
nltk.data.show_cfg('grammars/book_grammars/german.fcfg')
% start S
# Grammar Productions
S -> NP[CASE=nom, AGR=?a] VP[AGR=?a]
NP[CASE=?c, AGR=?a] -> PRO[CASE=?c, AGR=?a] N[CASE=?c, AGR=?a]
NP[CASE=?c, AGR=?a] -> Det[CASE=?c, AGR=?a] N[CASE=?c, AGR=?a]
VP[AGR=?a] -> IV[AGR=?a] PRO[CASE=?c, AGR=?a]
VP[AGR=?a] -> TV[OBJCASE=?c, AGR=?a] NP[CASE=?c]