/* dcg.pl: this one does Number agreement and Structure building and illustrates how prolog calls can be embedded in DCGs. This is illustrated in the lexical entries and also in the structure building for relative clauses*/ s(s(NP,VP)) --> np(Num,NP), vp(Num,VP). np(Num,NP) --> det(Num,Det), n(Num,N), pp(_,PP), {build_np(Det,N,PP,NP)}. vp(Num,VP) --> iv(Num,V), pp(_,PP), {build_vp(V,PP,VP)}. vp(Num,VP)--> tv(Num,V), np(_,NP), pp(_,PP), {build_vp(V,NP,PP,VP)}. vp(Num,VP)--> dv(Num,V), np(_,NP), pp(_,PP), {build_vp(V,NP,PP,VP)}. pp(Num,pp(P,NP)) --> p(P), np(Num,NP). pp(Num,pp(empty)) --> []. det(Num,det(Word)) --> [Word], {det(Num,Word)}. det(_,the). det(sing,a). det(sing,his). n(Num,n(Word)) --> [Word], {n(Num,Word)}. n(sing,man). n(sing,bank). n(sing,water_rat). n(sing,letter). n(sing,pilot). n(sing,airplane). n(sing,shopkeeper). n(sing,money). n(sing,ball). n(sing,hill). n(sing,midnight). n(sing,pen). n(sing,present). n(sing,museum). n(sing,van_gogh). n(sing,horse). n(sing,telescope). n(sing,tail). n(sing,yesterday). n(sing,tomorrow). p(p(to)) --> [to]. p(p(till)) --> [till]. p(p(down)) --> [down]. p(p(with)) --> [with]. dv(Num,v(Word)) --> [Word], {dv(Num,Word)}. %% i.e. ditransitives dv(_,gave). tv(Num,v(Word)) --> [Word], {tv(Num,Word)}. %% i.e. transitives tv(_,wrote). tv(_,banked). tv(_,lasted). tv(_,rolled). tv(_,visited). tv(_,saw). iv(Num,v(Word)) --> [Word], {iv(Num,Word)}. %% i.e. intransitives iv(_,went). iv(_,ate). build_np(Det,N,pp(empty),np(Det,N)). build_np(Det,N,pp(P,NP),np(Det,N,pp(P,NP))). build_vp(V,pp(empty),vp(V)). build_vp(V,pp(P,NP),vp(V,pp(P,NP))). build_vp(V,NP,pp(empty),vp(V,NP)). build_vp(V,NP,pp(P,NP2),vp(V,NP,pp(P,NP2))). /* For those of you with short memories, you query the DCG as follows: ?- s(X,[the,man,wrote,a,letter],[]). X = s(np(det(the),n(man)),vp(vp(v(wrote),np(det(a),n(letter))))) ? yes | ?- Andy Way, 25/09/00. */