I have to create a DCG in Prolog with the following features:
- handle subject/object distinction
- singular/plural distinction
- capable of producing parse trees
- make use of a separate lexicon
Here's the given lexicon:
lex(the,det,_).
lex(a,det,singular).
lex(man,n,singular).
lex(men,n,plural).
lex(woman,n,singular).
lex(women,n,plural).
lex(apple,n,singular).
lex(apples,n,plural).
lex(pear,n,singular).
lex(pears,n,plural).
lex(eat,v,plural).
lex(eats,v,singular).
lex(know,v,plural).
lex(knows,v,singular).
lex(i,pronoun,singular,subject).
lex(we,pronoun,plural,subject).
lex(me,pronoun,singular,object).
lex(us,pronoun,plural,object).
lex(you,pronoun,_,_).
lex(he,pronoun,singular,subject).
lex(she,pronoun,singular,subject).
lex(him,pronoun,singular,object).
lex(her,pronoun,singular,object).
lex(they,pronoun,plural,subject).
lex(them,pronoun,plural,object).
lex(it,pronoun,singular,_).
And here's my code:
s(s(NP,VP)) --> np(NP,X,subject), vp(VP,X).
np(np(DET,N),X,_) --> det(DET,X), n(N,X).
np(np(PRO),X,Y) --> pro(PRO,X,Y).
vp(vp(V,NP),X) --> v(V,X), np(NP,_,object).
vp(vp(V),X) --> v(V,X).
det(det(DET),X) --> [DET], {lex(DET,det,X)}.
n(n(N),X) --> [N], {lex(N,n,X)}.
pro(pro(PRO),X,Y) --> [PRO], {lex(PRO,pro,X,Y)}.
v(v(V),X) --> [V], {lex(V,v,X)}.
When I input:
s(X, [the, man, eats, the, apple], []).
I should get:
X = s(np(det(the, singular), n(man, singular, subject)), vp(v(eats, singular), np(det(the, singular), n(apple, singular, object))))
But instead I get:
X = s(np(det(the), n(man)), vp(v(eats), np(det(the), n(apple))))
And I'm not sure why it's not outputting the full thing.