/* Check out this site at NYU Linguistics for information */ /* about how to run this program */ /* http://www.nyu.edu/pages/linguistics/workbook/chapter2/work0011.txt */ /* In SWI-PROLOG, this should be called: tree.pl */ /* and it should be in the directory c:\pl or c:\pl\bin.*/ /*These programs are used in courses at NYU. The numbering, */ /* such as g0902 indicates it is/was the second program discussed in */ /* some graduate class. */ /* If you have any comments: doughert@acf2.nyu.edu */ /* Program Name: g0902 lexicon_09a */ /* determiners */ det([the]). det([a]). det([this]). det([that]). det([some]). /* indented are added to work001.pl */ det([each]). det([any]). /* prepositions */ prep([on]). prep([in]). prep([at]). prep([under]). prep([to]). prep([before]). /* nouns */ noun([house]). noun([table]). noun([man]). noun([woman]). noun([worm]). noun([worms]). noun([bird]). noun([birds]). /* verbs */ verb([sees]). verb([sits]). verb([looks]). /* verb([persuades]). */ verb([thinks]). verb([knows]). /* verb([puts]). */ /* modified by RCD, December 1996 */ verb([dined]). verb([dine]). verb([arise]). /* Program Name: g0903 */ detvar(0). detail :- retract(detvar(_)),assert(detvar(1)). no_detail :- retract(detvar(_)),assert(detvar(0)). s(X,LBS) :- append(A,B,X),np(A,LBNP),vp(B,LBVP), /* construct labeled bracketing for S */ append(['(s_'],LBNP,Z1), append(Z1,LBVP,Z2), append(Z2,[')'],LBS), (detvar(0);write(LBS),nl). vp(X,LBVP) :- append(A,B,X),verb(A),pp(B,LBPP), /* construct labeled bracketing */ append(['(vp_(v_'],A,Z1), append(Z1,[')'],Z2), append(Z2,LBPP,Z5), append(Z5,[')'],LBVP), (detvar(0);write(LBVP),nl). pp(X,LBPP) :- append(A,B,X),prep(A),np(B,LBNP), /* construct labeled bracketing */ append(['(pp_(p_'],A,Z1), append(Z1,[')'],Z2), append(Z2,LBNP,Z5), append(Z5,[')'],LBPP), (detvar(0);write(LBPP),nl). np(X,LBNP) :- append(A,B,X),det(A),noun(B), /* construct labeled bracketing */ append(['(np_(det_'],A,Z1), append(Z1,[')(n_'],Z2), append(Z2,B,Z3), append(Z3,['))'],LBNP),nl, (detvar(0);write(LBNP),nl). /* Program Name: g0904 */ function1(X,Y) :- function1a(X,A),name(Y,A). function1a([],[]). function1a([X|Y],Z) :- name(X,A),append(A,Z1,Z), function1a(Y,Z1). function2(X,Y) :- function2a(X,A),name(Y,A). function2a([],[]). function2a([X|Y],Z) :- name(X,A),append(A,[32],B), append(B,Z1,Z),function2a(Y,Z1). function3(""). function3(X) :- name(X,A),output(A). output([]). output([X|Y]) :- (X==95,write(' '),output(Y)); (name(Z,[X]),write(Z),output(Y)). /* Program Name: g0906 */ tree(X) :- s(X,A),function1(A,B),out(B). labelbracket(X) :- s(X,A),function1(A,B),write(B). out(X) :- assert(lm(0)),name(X,A),do(A),retract(lm(_)). do([]). do([X|Y]) :- ((X==40),uplm,nl,tabover,do(Y)); ((X==41),dnlm,tabover,do(Y)); (name(A,[X]),write(A),do(Y)). uplm :- lm(A),B is A+5,retract(lm(_)),assert(lm(B)). dnlm :- lm(A),B is A-5,retract(lm(_)),assert(lm(B)). tabover :- lm(X),writesp(X). writesp(X) :- ( (X==0); (write(' '),Y is X-1,writesp(Y)) ).