%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% %% %% Syntactic structure-building DCG in DCG notation %% %% %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Stuff to overcome Sictus' ever-so-helpful abbreviation of list terms portray(Term) :- is_list(Term), write(Term). is_list([]). is_list([_|_]). %%%% End of stuff s([s,[NP, VP]]) --> np(NP), vp(VP). np([np,[PN]]) --> pn(PN). np([np,[Det, N, Rel]]) --> det(Det), n(N),optrel(Rel). vp([vp,[TV, NP]]) --> tv(TV), np(NP). vp([vp,[IV]]) --> iv(IV). optrel([rel,[epsilon]]) --> []. optrel([rel,[that, VP]]) --> [that], vp(VP). %pn(harry) --> [harry]. %% etc. -- very tedious, therefore .... pn(Word) --> [Word], {pn(Word)}. pn(harry). pn(barry). pn(they). iv(Word) --> [Word], {iv(Word)}. iv(walks). iv(walk). tv(Word) --> [Word], {tv(Word)}. tv(sees). tv(see). det(Word) --> [Word], {det(Word)}. det(a). det(some). n(Word) --> [Word], {n(Word)}. n(frog). n(frogs). %| ?- ['hw1.p']. %% consulting /amd/nfs/pegasus/disk/ptn053/steedman/lectures/tl/hw1.p... %% consulted /amd/nfs/pegasus/disk/ptn053/steedman/lectures/tl/hw1.p in module user, 0 msec -88 bytes %yes %| ?- s(T, [harry, walks], []). % %T = [s,[[np,[harry]],[vp,[walks]]]] ? % %yes %| ?- s(T, [harry, walk], []). % %T = [s,[[np,[harry]],[vp,[walk]]]] ? % Note the overgeneralisation ! % %yes %| ?- s(T, [harry, sees, a, frog, that, walks], []). % %T = [s,[[np,[harry]],[vp,[sees,[np,[a,frog,[rel,[that,[vp,[walks]]]]]]]]]] ? % %yes %| ?- s(T, [harry, sees, a, frog, that, walk], []). % %T = [s,[[np,[harry]],[vp,[sees,[np,[a,frog,[rel,[that,[vp,[walk]]]]]]]]]] ? % %yes %| ?- %%%%Running s in (-,+,+) mode: %| ?- s([s,[[np,[harry]],[vp,[sees,[np,[a,frog,[rel,[that,[vp,[walks]]]]]]]]]], L, []). %L = [harry,sees,a,frog,that,walks] ? %yes %| ?- s([s,[[np,[a,frog,[rel,[epsilon]]]],[vp,[sees,[np,[harry]]]]]], L, []). %L = [a,frog,sees,harry] ? %yes %| ?-