/* LEXICON OF OCCURRING FORMS */ np([mary]). np([the_girl]). np([bill]). np([the_boy]). np([a_living]). np([the_house]). aux([can]). aux([will]). aux([shall]). verb([see]). verb([touch]). verb([know]). v([eke]). v([spruce]). prt([up]). prt([out]). /* CORPUS-to-KERNEL TRANSFORMATIONS */ transf-1([A,B,C,D],[B,A,C,D]) :- np(A),aux(B), verb(C),np(D). transf-2([A,B,C,D,E],[A,B,C,E,D]) :- np(A),aux(B), v(C),prt(D),np(E). transf-3([A,B,C,D],[D,B,be,C,en,by,A]) :- np(A),aux(B), verb(C),np(D). fact(dog). fact(X). fact_a(X). fact_b(_). fact_c(_). /* Harris (1964: 193) */ /* LEXICON OF OCCURRING FORMS */ np(the_lady). np(a_man). np(the_fellows). np(she). np(it). np(i). np(tess). np(sean). rel_pronoun(that). rel_pronoun(which). aux(may). aux(shall). verb(see). verb(got). prep(for). /* CORPUS-to-KERNEL TRANSFORMATIONS */ transf-4([A,B,C,D],[C,B,,D,someone] :- np(A),aux(B), verb(C),np(D). transf-5([A,B,C,D,E],[A,and,C,D,E,A]) :- np(A), rel_pronoun([B]), np(C),aux(D), verb(E)./* Program: p0311 databse2.pro */ /* */ /* This is the database_file to load into */ /* prolog2. Notice the filename is eight */ /* characters and ends in the extension .PRO. */ word([t,a,b]). word([e,p,a]). word([b,a,t]). word([t,e,n]). word([t,a,n]). word([r,a,t]). word([r,a,n]). word([a,t,e]). word([j,a,b]). word([j,o,e]). word([b,e,t]). word([a,p,e]). word([n,e,t]). word([a,p,t]). word([o,f,t]). word([o,p,t])./* Program: g0701 PROFUNCT.a */ /* append is a basic combinatorial tool for */ /* analyzing large constituents into smaller */ /* ones or synthesizing large constituents from */ /* smaller ones. */ append([],X,X). append([A|B],C,[A|D]) :- append(B,C,D). /* append is a built-in function in Quintus and */ /* therefore */ /* append MUST NOT BE DEFINED IN ANY OF YOUR */ /* QUINTUS PROGRAMS */ /* YOU WILL GET THE ERROR IN SESSION 3.6 */ /* ATTEMPTING TO DEFINE A SYSTEM PREDICATE */ /* append is not a built-in function in C-Prolog and */ /* therefore */ /* append must be defined by you on one of your */ /* programs. */ /* BE CERTAIN THAT, IF YOU LOAD TWO OR MORE PROGRAMS */ /* ONLY ONE OF THE PROGRAMS DEFINES append, OR YOU */ /* WILL HAVE append DEFINED MORE THAN ONCE,AND THIS */ /* CAN GIVE CONFUSING RESULTS. *//* Program: g0702 lexicon_7a */ /* This is a database of prefixes and suffixes. */ suf([a,b,l,e]). suf([a,t,i,o,n]). suf([e,r]). suf([i,d,e]). suf([i,n,g]). suf([i,v,e]). suf([m,e,n,t]). suf([a,r,y]). suf([a,b,i,l]). suf([a,l]). suf([i,s,h]). suf([i,a,l]). suf([i,s,m]). suf([i,a,n]). suf([m,e,n,t]). suf([a,r]). suf([l,i]). suf([e,d]). suf([l,i,k,e]). suf([l,y]). suf([u,r,e]). suf([i,c]). suf([l,e,s,s]). suf([a,t,e]). suf([o,u,s]). suf([a,t,e]). suf([i,t,y]). suf([i,z,e]). suf([i,z]). suf([n,e,s,s]). suf([u,r,e]). pre([e,x]). pre([i,n]). pre([d,e]). pre([i,n,t,e,r]). pre([h,y,p,e,r]). pre([a,n,t,i]). pre([u,n]). pre([r,e]). pre([i,l]). pre([d,i,s]). pre([s,u,p,e,r]). pre([s,u,b]). root([b,o,y]). root([h,u,m,a,n]). root([d,e,c,i,d,e]). root([g,e,n,t,l,e]). root([m,a,n]). root([h,u,n,t]). root([c,h,a,n,g,e]). root([h,o,m,e]). root([h,o,s,p,i,t,a,l]). /* Program: g0703 suffix.prg */ suffixation(SHORT,LONG) :- suf(SUF), append(SHORT,SUF,LONG), nl,nl,write(LONG), nl,write(SHORT), write(' + '),write(SUF). suf_all(BIG) :- suffixation(SMALL,BIG), suf_all(SMALL). append([],X,X). append([A|B],C,[A|D]) :- append(B,C,D). /* In C-PROLOG: */ /* you can either load g0701, the definition of */ /* the append relation, and g0703, OR */ /* you can erase the comment marks in g0703 and */ /* define append in g0703. */ /* you can also erase the comment marks in g070e*/ /* and load both g0701 and g0703, but this */ /* will give you very odd results and volumes */ /* of results that you do not want. */ /* append must be defined only one time */ /* In QUINTUS, simply load g0703, and it will */ /* give the results discussed in the text. */ /* Program: g0704 prefix.prg */ prefixation(SHORT,LONG) :- pre(PRE), append(PRE,SHORT,LONG), nl,nl,write(LONG), nl,write(PRE),write(' + '), write(SHORT). pref_all(BIG) :- prefixation(SMALL,BIG), pref_all(SMALL). affix_all(WORD) :- pref_all(WORD);nl,suf_all(WORD). affix_all_1(WORD) :- nl,nl,write('Find all prefixes.'), pref_all(WORD); nl,nl,write('Find all suffixes.'), suf_all(WORD). /* Program: g0705 RootFinder */ root(R,WORD) :- nl,write('List of all prefixes: '), pref_alle(NO_PREF,WORD), nl,write('List of all suffixes: '), suf_alle(R,NO_PREF). pref_alle(R,BIG) :- prefixation(SM,BIG),pref_alle(R,SM). pref_alle(R,R). prefixation(SHORT,LONG) :- pre(PRE), append(PRE,SHORT,LONG), nl,write(PRE). suf_alle(R,BIG) :- suffixation(SM,BIG),suf_alle(R,SM). suf_alle(R,R). suffixation(SHORT,LONG) :- suf(SUF), append(SHORT,SUF,LONG), nl,write(SUF). append([],X,X). append([A|B],C,[A|D]) :- append(B,C,D). /* Program: g0706 plural.prg */ /* The following flavor pill must be in */ /* the Prolog2 version of this file. */ /* Remove this line in all other Prologs. */ :- state(token_class,_,dec10). plural(Sing,Plural) :- name(Sing,Sexpl), append(Sexpl,"s",Pexpl), name(Plural,Pexpl). append([],X,X). append([A|B],C,[A|D]) :- append(B,C,D). /* Program: g0707 pluralc.prg */ /* The following flavor pill must be in */ /* Prolog2. Remove this line in all other */ /* versions of Prolog. */ :- state(token_class,_,dec10). plural(Sing,Plural) :- write('Sing = '),write(Sing),nl, name(Sing,Sexpl), write('Sexpl = '),write(Sexpl),nl, append(Sexpl,"es",Pexpl), /* notice this line has the */ /* element */ /* "es" */ /* and not */ /* [e,s]] */ /* Whether to use a string */ /* or a list varies from one */ /* version of prolog to */ /* another. */ write('Pexpl = '),write(Pexpl),nl, name(Plural,Pexpl), write('Plural = '),write(Plural),nl. append([],X,X). append([A|B],C,[A|D]) :- append(B,C,D). /* Program: 0708 plural1.prg */ /* The following line is required in */ /* Prolog2. Remove it in other cases. */ /* This is a flavor pill which gives the */ /* file its flavor. */ :- state(token_class,_,dec10). plural(man,men) :- !. plural(woman,women) :- !. plural(child,children) :- !. plural(Sing,Plural) :- name(Sing,Sexpl), append(JUNK,"x",Sexpl), append(Sexpl,"es",Pexpl), name(Plural,Pexpl),!. plural(Sing,Plural) :- name(Sing,Sexpl), append(Sexpl,"s",Pexpl), name(Plural,Pexpl). append([],X,X). append([A|B],C,[A|D]) :- append(B,C,D). /* Program: g0709 past_tense */ /* The following flavor pill is required in */ /* Prolog2. Remove it in all other versions. */ :- state(token_class,_,dec10). past(go,went) :- !. past(take,took) :- !. past(see, saw) :- !. past(have,had) :- !. past(dive,dove). past(dream,dreamt). past(Present,Past) :- name(Present,A), append(A,"ed",B), name(Past,B). append([],X,X). append([A|B],C,[A|D]) :- append(B,C,D). /* Program: g0710 Universal_Grammar */ /* Program Name: Universal_Grammar_1 */ sd(X,Y) :- pf(X),lf(Y). pf(X) :- overt_syntax(X,Y),cond_on_pf(X). lf(Y) :- overt_syntax(X,Y),cond_on_lf(Y). cond_on_lf(Y) :- binding(Y),theta(Y),control(Y),case(Y). /* Program Name: Universal_Grammar_2 */ sd(X,Y) :- overt_syntax(X,Y),cond_on_pf(X),cond_on_lf(Y). cond_on_lf(Y) :- binding(Y),theta(Y),control(Y),case(Y). /* Program Name: Universal_Grammar_3 */ sd(X,Y) :- overt_syntax(X,Y),cond_on_pf(X), binding(Y),theta(Y),control(Y),case(Y)./* Program: g0711 Universal_Grammar_4 */ sd(X,Y) :- orth_rep(X),log_form(Y). orth_rep(X) :- overt_syntax(X,Y),condx_orth_rep(X). condx_on_orth_rep(X) :- orthography(X),morphology(X). log_form(Y) :- control(Y),binding(Y)./* Program: g0801 lexicon_8a */ /* lexical entries: the units to be combined */ det([the]). det([a]). n([boy]). n([girl]). v([remembered]). v([forgot]). v([saw]). v([knew])./* Program: g0802 grammar1 */ /* This grammar defines a small set of sentences. */ /* syntactic rules of combination */ sent(X) :- np(A),vp(B),append(A,B,X). vp(X) :- v(A),np(B),append(A,B,X). np(X) :- det(A),n(B),append(A,B,X). /* general derivational mechanisms */ append([],L,L). append([X|L1],L2,[X|L3]) :- append(L1,L2,L3)./* Program: g0803 grammar2 */ /* This grammar makes infinite use of finite means. */ /* English definitions of combination of elements */ s(X) :- append(A,B,X),np(A),vp(B). vp(X) :- append(A,B,X),v(A),np(B). vp(X) :- append(A,B,X),v(A),s(B). /* recursive definition */ np(X) :- append(A,B,X),det(A),n(B). /* general derivational mechanisms */ append([],L,L). append([X|L1],L2,[X|L3]) :- append(L1,L2,L3)./* Program: g0804 */ /* A grammar of a fragment of English. */ /* A definition which identifies and labels the */ /* constituents of a simple noun phrase. */ /* DATABASE OF ELEMENTS AT A LEVEL */ /* lexical entries for determiners and nouns */ det([the]). det([a]). det([this]). det([that]). n([boy]). n([girl]). n([man]). n([woman]). /* PRINCIPLES OF COMBINATION OF ELEMENTS */ /* definition to recognize and label */ /* constiituents of a noun phrase */ np(X) :- append(A,B,X),det(A),n(B), /* pattern recog */ /* format output */ nl,nl,write('det = '),write(A), /* label determiner */ write(' n = '),write(B), /* label noun */ nl,write('np = '),write(X). /* label noun phr */ /* UNIVERSAL COMPUTATIONAL PRINCIPLES */ /* general derivational mechanisms */ /* append([],X,X). */ /* append([A|B],C,[A|D]) :- append(B,C,D). *//* Program: g0805 */ /* The definition of noun phrase of grammar3, but modified. */ /* When continue(yes) is true, the structure of the np is */ /* output.. */ /* When continue(no) is true, the structure of the np is */ /* not output. */ /* program to enable us to turn on/off output of structure */ continue(yes). structure :- retract(continue(_)),assert(continue(yes)). no_structure :- retract(continue(_)),assert(continue(no)). /* lexicon of forms */ det([the]). det([a]). n([boy]). n([girl]). /* definition to identify and label constituents */ /* of a noun phrase */ np(X) :- append(A,B,X),det(A),n(B), /* pattern recog */ /* format output */ ( /* start either-or */ continue(no) /* stop */ ; /* or */ (nl,nl,write('det = '),write(A), /* otherwise */ write(' n = '), write(B), /* label */ nl,write('np = '),write(X)) /* label */ ). /* end or */ /* general derivational mechanisms */ append([],L,L). append([X|L1],L2,[X|L3]) :- append(L1,L2,L3). /* Program: g0806 */ /* This grammar defines a small set of sentences. */ /* It identifies and labels the constituents of a */ /* sentence. */ /* lexicon of elements which function in the grammar */ det([the]). det([a]). n([boy]). n([girl]). v([remembered]). v([forgot]). /* English rules of combination */ s(X) :- append(A,B,X),np(A),vp(B), nl,nl,write('np = '),write(A), write(' vp = '),write(B), nl,write('s = '),write(X). vp(X) :- append(A,B,X),v(A),np(B), nl,nl,write('v = '),write(A), write(' np = '),write(B), nl,write('vp = '),write(X). np(X) :- append(A,B,X),det(A),n(B), nl,nl,write('det = '),write(A), write(' n = '),write(B), nl,write('np = '),write(X). /* general derivational mechanisms */ append([],L,L). append([X|L1],L2,[X|L3]) :- append(L1,L2,L3). /* Program: g0807 */ /* Two different strategies to identify noun phrase */ /* npl assigns structure with append last */ /* npf assigns structure with append first */ /* LEXICON OF FORMS */ det([the]). det([a]). det([this]). det([that]). n([boy]). n([girl]). n([man]). n([woman]). /* DEFINITIONS TO IDENTIFY CONSTITUENTS */ npl(X) :- det(A),n(B),append(A,B,X). /* append last parser */ npf(X) :- append(A,B,X),det(A),n(B). /* append first parser */ /* GENERAL DERIVATIONAL MECHANISMS */ append([],L,L). append([X|L1],L2,[X|L3]) :- append(L1,L2,L3)./* Program: g0808 */ /* Two strategies for assigning structure to */ /* noun phrases. */ /* LEXICON OF FORMS */ det([the]). det([a]). det([this]). det([that]). n([boy]). n([girl]). n([man]). n([woman]). /* DEFINITIONS TO IDENTIFY AND LABEL CONSTITUENTS */ npl(X) :- det(A),n(B), /* pattern recognition */ nl,write('det = '),write(A), /* format output */ write(' n = '),write(B), /* format output */ append(A,B,X). /* pattern recognition */ npf(X) :- append(A,B,X), /* pattern recognition */ nl,write('det = '),write(A), /* format output */ write(' n = '),write(B), /* format output */ det(A),n(B). /* pattern recognition */ /* GENERAL DERIVATIONAL MECHANISMS */ append([],L,L). append([X|L1],L2,[X|L3]) :- append(L1,L2,L3)./* Program: g0809 */ /* An append-first version of grammar1 */ /* LEXICON OF FORMS */ det([the]). det([a]). n([boy]). n([girl]). v([remembered]). v([forgot]). /* DEFINITIONS TO IDENTIFY CONSTITUENTS */ sent(X) :- append(A,B,X),np(A),vp(B). vp(X) :- append(A,B,X),v(A),np(B). np(X) :- append(A,B,X),det(A),n(B). /* GENERAL DERIVATIONAL MECHANISMS */ append([],L,L). append([X|L1],L2,[X|L3]) :- append(L1,L2,L3)./* Program: g0810 lexicon_8b */ /* No complement or selections restrictions */ /* indicated. */ /* entries for nouns */ n([boy]). n([girl]). n([time]). n([truck]). n([hay]). /* entries for adjectives */ adj([happy]). adj([kind]). /* entries for determiners */ det([the]). det([a]). /* entries for prepositions */ p([on]). p([from]). p([with]). p([to]). /* entries for verbs */ v1([sees]). v1([eats]). v1([ate]). v2([depends]). v3([remembers]). v4([seems]). v4([appears]). v5([elapses]). v5([elapsed]). v5([eats]). v5([ate]). v6([gives]). v6([put]). v6([handed]). v7([goes]). v8([tells]). v8([reminded]). v8([told]). v9([explains]). v9([describes]). v9([shouted]). /* Program: g0811 */ /* A simple grammar to define sentences that */ /* contain verbs with various complement structures. */ /* You must load a lexicon to get results. */ s(X) :- append(A,B,X),np(A),vp(B). /* s */ np(X) :- append(A,B,X),det(A),n(B). /* np */ pp(X) :- append(A,B,X),p(A),np(B). /* pp */ vp(X) :- append(A,B,X),v1(A),np(B). /* v np */ vp(X) :- append(A,B,X),v2(A),pp(B). /* v pp */ vp(X) :- append(A,B,X),v3(A),s(B). /* v s */ vp(X) :- append(A,B,X),v4(A),adj(B). /* v adj */ vp(X) :- v5(X). /* v */ vp(X) :- append(A,B,X),v6(A), /* v np pp */ append(C,D,B),np(C),pp(D). vp(X) :- append(A,B,X),v7(A), /* v pp pp */ append(C,D,B),pp(C),pp(D). vp(X) :- append(A,B,X),v8(A), /* v np s */ append(C,D,B),np(C),s(D). vp(X) :- append(A,B,X),v9(A), /* v pp s */ append(C,D,B),pp(C),s(D). append([],L,L). append([X|L1],L2,[X|L3]) :- append(L1,L2,L3). /* Program: g0812 lexicon_8c */ /* Lexical entries with verbs marked for complements */ /* and preposition selection */ /* entries for nouns */ n([boy]). n([girl]). n([truck]). n([car]). /* entries for prepositions */ p([on]). p([to]). p([at]). p([from]). /* entries for determiners */ det([the]). det([a]). /* entries for verbs */ v1([sees]). v1([left]). v2([depends],[on]). v2([looks],[at]). v3([remembers]). v4([seems]). v5([elapses]). v5([left]). v6([gives],[to]). v6([takes],[from]). v7([goes],[from],[to]). v7([drives],[from],[to]). v8([tells]). v9([explains],[to]). v9([shouts],[to])./* Program: g0813 */ vp(X) :- v5(X). vp(X) :- append(A,B,X),v2(A,P),pp(B),append(P,_,B). vp(X) :- append(A,B,X),v6(A,P),append(C,D,B), np(C),pp(D),append(P,_,D). vp(X) :- append(A,B,X),v7(A,P1,P2), append(C,D,B),pp(C),append(P1,_,C), pp(D),append(P2,_,D). vp(X) :- append(A,B,X),v9(A,P),append(C,D,B), pp(C),append(P,_,C),s(D). np(X) :- append(A,B,X),det(A),n(B). s(X) :- append(A,B,X),np(A),vp(B). pp(X) :- append(A,B,X),p(A),np(B). append([],L,L). append([X|L1],L2,[X|L3]) :- append(L1,L2,L3)./* Program Name: g0901 */ /* This grammar will input an ordered string of elements */ /* and produce a labeled bracketing for that string */ det([the]). det([a]). n([girl]). n([boy]). np(X,LBX) :- append(A,B,X),det(A),n(B), /* format output */ append(['(np (det '],A,Z1), append(Z1,[')(n '],Z2), append(Z2,B,Z3), append(Z3,['))'],LBX),nl, write(LBX),nl. np1(X,LBX) :- append(A,B,X),det(A),n(B), /* format output */ append(['(np (det '],A,Z1),nl, write('Z1 = '),write(Z1), append(Z1,[')(n '],Z2), nl,write('Z2 = '),write(Z2), append(Z2,B,Z3),nl,write('Z3 = '),write(Z3), append(Z3,['))'],LBX),nl, write('LBX = '),write(LBX),nl. append([],L,L). append([X|L1],L2,[X|L3]) :- append(L1,L2,L3)./* Program Name: g0902 lexicon_09a */ /* determiners */ det([the]). det([a]). det([this]). det([that]). /* prepositions */ prep([on]). prep([in]). prep([at]). prep([under]). prep([to]). /* nouns */ noun([house]). noun([table]). noun([man]). noun([woman]). /* verbs */ verb([sees]). verb([sits]). verb([looks]). verb([persuades]). verb([thinks]). verb([knows]). verb([puts])./* 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). append([],L,L). append([X|L1],L2,[X|L3]) :- append(L1,L2,L3). /* Program Name: g0904 */ /* Y is identical to X, except all commas are missing. */ /* This function converts a list to an atom, and thereby, */ /* elminates all commas. */ function1(X,Y) :- function1a(X,A),name(Y,A). function1a([],[]). function1a([X|Y],Z) :- name(X,A),append(A,Z1,Z), function1a(Y,Z1). /* Y is identical to X, except commas in X are spaces in Y. */ /* This function converts all commas to spaces */ 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). /* This function is an output routine. */ /* The input to the function is an atom with underlines. */ /* The function writes the atom substituting a space for an */ /* underline. */ 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: g0905 */ function4(X,Y :- s(X,A),function1(A,Y). function5(X) :- s(X,A),function1(A,B),function3(B). function6(X) :- s(X,A),function2(X,C), nl,write('THIS STRING:'),nl,write(C),nl, write('HAS THIS LABELED BRACKETING:'), nl,function1(A,B),function3(B)./* Program Name: g0906 */ /* function7(X) parses X and prints out a phrase marker */ function7(X) :- s(X,A),function1(A,B),out(B). /* out(X) inputs an atom, not a list. There are no */ /* commas in X. */ /* if X = (, do(X), moves five spaces right. */ /* If X = ), do(X) moves five spaces left. */ /* If X is anything else, do(X) prints it. */ out(X) :- nl,assert(lm(0)),name(X,A),do(A),retract(lm(_)). do([]). do([X|Y]) :- ((X==40),uplm,nl,tabover,do(Y)); ((X==41),dnlm,nl,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)) ). /* File Name: g0907 lexicon_9b */ /* determiners */ det([the]). det([a]). det([this]). det([that]). /* prepositions */ prep([on]). prep([in]). prep([at]). prep([under]). prep([to]). /* nouns */ noun([house]). noun([table]). noun([man]). noun([woman]). noun([library]). noun([kitchen]). noun([book]). /* verbs */ v2([read]). v6([put])./* Program Name: g0908 */ s(X,LBS) :- append(A,B,X),np(A,LBNP),append(C,D,B), vp(C,LBVP),pp(D,LBPP), /* construct (S... */ append(['(S_'],LBNP,Z1),append(Z1,LBVP,Z2), append(Z2,LBPP,Z3),append(Z3,[')'],LBS). s(X,LBS) :- append(A,B,X),np(A,LBNP),vp(B,LBVP), /* construct (s... */ append(['(s_'],LBNP,Z1),append(Z1,LBVP,Z2), append(Z2,[')'],LBS). vp(X,LBVP) :- append(A,B,X),v6(A),append(C,D,B), np(C,LBNP),pp(D,LBPP), /* construct */ append(['(vp_(v_'],A,Z1),append(Z1,[')'],Z2), append(Z2,LBNP,Z3),append(Z3,LBPP,Z4), append(Z4,[')'],LBVP). vp(X,LBVP) :- append(A,B,X),v2(A),np(B,LBNP), /* construct */ append(['(vp_(v_'],A,Z1),append(Z1,[')'],Z2), append(Z2,LBNP,Z3),append(Z3,[')'],LBVP). pp(X,LBPP) :- append(A,B,X),prep(A),np(B,LBNP), /* construct */ append(['(pp_'],A,Z1),append(Z1,B,Z2), append(Z2,[')'],LBPP). np(X,LBNP) :- append(A,B,X),det(A),noun(B), /* construct (np... */ append(['(np_'],A,Z1), append(Z1,B,Z2),append(Z2,[')'],LBNP). np(X,LBNP) :- append(A,B,X),det(A), append(C,D,B),noun(C),pp(D,LBPP), /* construct (NP... */ append(['(NP_'],A,Z1),append(Z1,C,Z2), append(Z2,LBPP,Z3),append(Z3,[')'],LBNP). append([],L,L). append([X|L1],L2,[X|L3]) :- append(L1,L2,L3)./* Program: g0909 remove commas */ /* parses X and yields a labeled /* bracketing */ /* with no commas */ function8(X,Y) :- s(X,A),function2(A,Y)./* Program Name: g0910 */ /* formdash */ tree(X) :- s(X,A),phmark(A),fail. phmark(X) :- function9(X,A),out(A),!. /* function9 converts all commas to dashes */ /* all commas in X are dashes [95] in Y */ function9(X,Y) :- function9a(X,A),name(Y,A). function9a([],[]). function9a([X|Y],Z) :- name(X,A),append(A,[95],B), append(B,Z1,Z),function9a(Y,Z1). out(X) :- nl,assert(lm(0)),name(X,A),do(A),retract(lm(_)). uplm :- m(A),B is A+5,retract(lm(_)),assert(lm(B)). dnlm :- lm(A),B is A-5,retract(lm(_)),assert(lm(B)). /* [40] = ( [41] = ) [95] = _ (underline) */ /* If [40], then add five to the left margin (lm(N)) */ /* If [41], then subtract five from the left margin (lm(N)) */ /* If [41], is followed by [95], a left parenthesis is */ /* followed by a dash, */ /* then do not print the dash and continue with the /* rest of the list */ do([]). do([X|Y]) :- ((X==40),uplm,nl,tabover,do(Y)); ((X==41),dnlm,nl,tabover, (dashdel(Y);do(Y))); (name(A,[X]),write(A),do(Y)). dashdel([X|Y]) :- (X==95),do(Y). tabover :- lm(X),writesp(X). writesp(X) :- ( (X==0); write(' '),Y is X-1,writesp(Y) ). /* Program Name: g0911 lexicon_9c */ noun([book],[on]). noun([book],[about]). noun([line],[to]). noun([clockface],[at]). noun([line],[on]). noun([gift],[of]). noun([predilection],[for]). noun([look],[through]). noun([lien],[against]). noun([glimpse],[at]). noun([attitude],[towards]). noun([liason],[between]). noun([difference],[between]). noun([removal],[from]). noun(X) :- noun(X,_),!. noun([tables]). noun([table]). noun([question]). noun([problem]). noun([clockface]). noun([noon]). noun([students]). noun([journals]). noun([draft]). noun([prepositions]). prep([in]). prep([at]). prep([through]). prep([between]). prep([towards]). prep([of]). prep([on]). prep_loc([in]). prep_loc([on]). prep_loc([at]). prep_loc([near]). det([the]). det([a]). det([an]). det([this])./* Program Name: g0911 lexicon_9c */ noun([book],[on]). noun([book],[about]). noun([line],[to]). noun([clockface],[at]). noun([line],[on]). noun([gift],[of]). noun([predilection],[for]). noun([look],[through]). noun([lien],[against]). noun([glimpse],[at]). noun([attitude],[towards]). noun([liason],[between]). noun([difference],[between]). noun([removal],[from]). noun(X) :- noun(X,_),!. noun([tables]). noun([table]). noun([question]). noun([problem]). noun([clockface]). noun([noon]). noun([students]). noun([journals]). noun([draft]). noun([prepositions]). prep([in]). prep([at]). prep([through]). prep([between]). prep([towards]). prep([of]). prep([on]). prep_loc([in]). prep_loc([on]). prep_loc([at]). prep_loc([near]). det([the]). det([a]). det([an]). det([this])./* Program Name: g0912 */ pp(X,LBPP) :- nl,write('Try to match the structure (pp p np ) with'),write(X),nl, append(A,B,X),prep(A),np(B,LBNP), /* construct */ append(['(pp_'],A,Z1),append(Z1,B,Z2), append(Z2,[')'],LBPP). np(X,LBNP) :- nl,write('Try to match the structure (np det n) to '), write(X),nl, append(A,B,X),det(A),noun(B), /* construct (np... */ append(['(np_'],A,Z1),append(Z1,B,Z2), append(Z2,[')'],LBNP). np(X,LBNP) :- nl,write('Try to match the structure (np n) to '),write(X),nl,noun(X), /* construct */ append(['(np_'],X,Z1), append(Z1,[')'],LBNP)./* Program Name: g0913 */ np1(X,LBNP) :- nl,write('Try to pair '), write(X),write(' with PM(1).'),nl, append(A,B,X),det(A), append(C,D,B),noun(C), pp(D,LBPP),(append([of],_,D); (noun(C,PREPc),append(PREPc,_,D))), /* construct PM(1) */ append(['(np_(det_'],A,Z1), append(Z1,[')(n_'],Z2), append(Z2,C,Z3),append(Z3,[')'],Z4), append(Z4,LBPP,Z5),append(Z5,[')'],LBNP). np2(X,LBNP) :- nl,write('Try to pair '),write(X), write(' with PM(2).'),nl, append(A,B,X),np(A,LBNP1), pp(B,LBPP),prep_loc(PREP), append(PREP,_,B), /* construct PM(2) */ append(['(np_'],LBNP1,Z1), append(Z1,LBPP,Z2),append(Z2,[')'],LBNP). np3(X,LBNP) :- nl,write('Try to pair '),write(X), write(' with PM(3).'),nl, append(A,B,X),np(A,LBNP1), append([of],D,B),np(D,LBNP2), /* construct PM(3) */ append(['(np_'],LBNP1,Z1), append(Z1,['(p_of)'],Z2), append(Z2,LBNP2,Z3), append(Z3,[')'],LBNP). /* Program Name: g0914 */ /* simple database of letters */ let([a]). let([b]). let([c]). let([d]). let([e]). /* bottom up definitions of n-ary branching, n = 1, 2, 3, 4 */ go1bu(X) :- let(X). go2bu(X) :- append(A,B,X),let(A),let(B). go3bu(X) :- tripend(A,B,C,X),let(A),let(B),let(C). go4bu(X) :- quadpend(A,B,C,D,X),let(A),let(B),let(C),let(D). /* top down definitons of n-ary branching, n = 1, 2, 3, 4 */ go1td(X) :- let(X). go2td(X) :- let(A),let(B),append(A,B,X). go3td(X) :- let(A),let(B),let(C),tripend(A,B,C,X). go4td(X) :- let(A),let(B),let(C),let(D),quadpend(A,B,C,D,X). /* general derivational mechanisms 8? tripend(A,B,C,X) :- append(A,Y,X),append(B,C,Y). quadpend(A,B,C,D,X) :- append(A,Y,X),append(B,Z,Y), append(C,D,Z)./* Program Name: g0915 */ /* Feature Percolation */ /* Selection between quantifiers and */ /* coordinating conjunctions. */ np([sean]). np([tess]). np([tracy]). c([and]). c([or]). c([nor]). q([both]). q([either]). q([neither]). qc([both],[and]). qc([either],[or]). qc([neither],[nor]). /* np C np */ np1bu(X) :- tripend(A,B,C,X),np(A),c(B),np(C). np1td(X) :- np(A),c(B),np(C),tripend(A,B,C,X). /* Q np C np no selection between Q and C */ np2bu(X) :- quadpend(A,B,C,D,X),q(A),np(B),c(C),np(D). np2td(X) :- q(A),np(B),c(C),np(D),quadpend(A,B,C,D,X). /* Q np C np selection between Q and C */ np3bu(X) :- quadpend(A,B,C,D,X),qc(A,C),np(B),np(D). np3td(X) :- qc(A,C),np(B),np(D),quadpend(A,B,C,D,X). tripend(A,B,C,X) :- append(A,Y,X),append(B,C,Y). quadpend(A,B,C,D,X) :- append(A,Y,X),append(B,Z,Y), append(C,D,Z). /* Program Name g0916 */ pronoun([we],nominative). pronoun([us],objective). pronoun([she],nominative). pronoun([they],nominative). pronoun([them],objective). pronoun([we],plu). pronoun([us],plu). pronoun([she],sg). pronoun([him],sg). pronoun([they],plu). pronoun([them],plu). quantifier([each]). quantifier([all]). quantifier([both]). v2([compare],_,[all]). v2([share],[all],_). v5([will_be_similar],[all]). v5([will_be,tall],_). v5([will_meet],[all]). nppl(X,Q) :- pronoun(A,plu),quantifier(Q), append(A,Q,X). nppl(X,Q) :- quantifier(Q),pronoun(C,plu), pronoun(C,objective), append([of],C,B),append(Q,B,X). vp(X,Qs) :- v5(X,Qs). vp(X,Qs) :- v2(A,Qs,Qo),nppl(B,Qo),append(A,B,X). s(X) :- nppl(A,Qs),vp(B,Qs),append(A,B,X). /* Program Name: g0917 */ /* A grammar which illustrates the principles of */ /* selection with coordination/quantifers. */ /* lexicon of items marked for cooccurrence */ /* restrictions */ np([sean]). np([tess]). np([tracy]). v5([will_be_similar],[all]). v5([will_meet],[all]). v5([will_be_tall],_). v5([will_eat],_). qc([each],[and]). qc([all],[and]). /* English category definitions */ /* a quantified coordination: sean, tess, and tracy each... */ nppl(X,Q) :- qc(Q,C),np(A),np(B),np(D), pentpend(A,B,C,D,Q,X). vp(X,Qs) :- v5(X,Qs). s(X) :- nppl(A,Qs),vp(B,Qs),append(A,B,X). /* general derivational mechanisms */ pentpend(A,B,C,D,E,X) :- append(A,X1,X),append(B,X2,X1), append(C,X3,X2),append(D,E,X3). :- state(token_class,_,dec10). /* Program Name: g0902 lexicon_09a */ /* determiners */ det([the]). det([a]). det([this]). det([that]). /* prepositions */ prep([on]). prep([in]). prep([at]). prep([under]). prep([to]). /* nouns */ noun([house]). noun([table]). noun([man]). noun([woman]). /* verbs */ verb([sees]). verb([sits]). verb([looks]). verb([persuades]). verb([thinks]). verb([knows]). verb([puts]). /* 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). append([],L,L). append([X|L1],L2,[X|L3]) :- append(L1,L2,L3). /* 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 */ function7(X) :- s(X,A),function1(A,B),out(B). out(X) :- nl,assert(lm(0)),name(X,A),do(A),retract(lm(_)). do([]). do([X|Y]) :- ((X==40),uplm,nl,tabover,do(Y)); ((X==41),dnlm,nl,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)) ). /* Program: 5.# Harris Transformations */ /* */ /* LEXICON OF OCCURRING FORMS */ np(mary). np(the_girl). np(bill). np(the_boy). np(a_living). np(the_house). aux(can). aux(will). aux(shall). verb(see). verb(touch). verb(know). v(eke). v(spruce). prt(up). prt(out). /* CORPUS-to-KERNEL TRANSFORMATIONS */ transf-1([A,B,C,D],[B,A,C,D]) :- np(A),aux(B), verb(C),np(D). transf-2([A,B,C,D,E],[A,B,C,E,D]) :- np(A),aux(B), v(C),prt(D),np(E). transf-3([A,B,C,D],[D,B,be,C,en,by,A]) :- np(A),aux(B), verb(C),np(D). /* Harris (1964: 193) */ /* LEXICON OF OCCURRING FORMS */ np(the_lady). np(a_man). np(the_fellows). np(she). np(it). np(i). np(tess). np(sean). rel_pronoun(that). rel_pronoun(which). aux(may). aux(shall). verb(see). verb(got). prep(for). /* CORPUS-to-KERNEL TRANSFORMATIONS */ transf-4([A,B,C,D],[C,B,,D,someone] :- np(A),aux(B), verb(C),np(D). transf-5([A,B,C,D,E],[A,and,C,D,E,A]) :- np(A), rel_pronoun([B]), np(C),aux(D), verb(E)./* FILENAME: p0201 database_letters_dictionary */ /* Any text between these slash-asterisk symbols */ /* will be ignored by the prolog interpreter. These */ /* are called comment lines and can occur almost */ /* anywhere. Some examples are given below. */ /* simple facts: A list of the letters of the word boulder. */ letter(b). /* a consonant */ letter(o). /* a vowel */ letter(u). /* line x */ letter(l). /* line y */ letter(d). letter(e). letter(r). /* complex facts: A list of the spellings of all */ /* English Words, including: */ word([m,a,n]). word([o,l,d]). word([p,u,t]). word([l,e,d]). word([r,e,d]). word([b,e,d]). word([o,n,l,y]). /* last word */ /* FILENAME: p0202 query_file */ possible_words_a(A,B,C) :- /* the first query */ letter(A),letter(B),letter(C), word([A,B,C]). possible_words_b(A,B,C) :- /* the second query */ word([A,B,C]), letter(A),letter(B),letter(C). possible_words_c :- /* the third query */ letter(A),letter(B),letter(C), word([A,B,C]), nl,write(A),write(B),write(C), fail. possible_words_d :- /* the fourth query */ word([A,B,C]), letter(A),letter(B),letter(C), nl,write(A),write(B),write(C), fail./* FILENAME: p0203 databse1.pro */ /* This file must be an ASCII DOS text file. */ /* Any text between these slash-asterisk symbols will be */ /* ignored by the prolog interpreter. These are called */ /* comment lines and can occur almost anywhere. */ /* simple facts: A list of the letters of the word boulder. */ letter(b). letter(o). letter(u). letter(l). letter(d). letter(e). letter(r). /* complex facts: A list of the spellings of all */ /* English Words, including: */ word([m,a,n]). word([o,l,d]). word([p,u,t]). word([l,e,d]). word([r,e,d]). word([b,e,d]). word([o,n,l,y])./* Program: p0204 query1.pro */ /* This must be an ASCII DOS text file. */ possible_words_a(A,B,C) :- /* the first query */ letter(A),letter(B),letter(C), word([A,B,C]). possible_words_b(A,B,C) :- /* the second query */ word([A,B,C]), letter(A),letter(B),letter(C). possible_words_c :- /* the third query */ letter(A),letter(B),letter(C), word([A,B,C]), nl,write(A),write(B),write(C), fail. possible_words_d :- /* the fourth query */ word([A,B,C]), letter(A),letter(B),letter(C), nl,write(A),write(B),write(C), fail./* Program: p0301 query.one */ /* Notice this program name contains a period. */ /* This means it must be loaded between quotes. */ poss_word_1(A,B,C) :- letter(A),word([A,B,C]),letter(B),letter(C). poss_word_2(A,B,C) :- letter(C),letter(B),word([A,B,C]),letter(A). poss_word_3(A,B,C) :- letter(C),letter(A), word([A,B,C]),letter(B). poss_word_4(A,B,C) :- letter(B),letter(C),letter(B),word([A,B,C])./* Program: p0302 bad_news_1 */ /* Notice the missing period on the second fact. */ letter([b]). letter([o]) letter([u])./* Program: p0303 bad_news_2 */ /* Notice the capital on the second fact. */ letter([b]). Letter([o]). letter([u])./* Program: p0304 bad_news_3 */ /* Notice the mismatched parentheses */ /* and brackets. */ word([r,a,t). word(p,i,g]). word[a,n,t]. word([d,o,g)]./* Program: p0305 worst_news */ /* These will all load normally, but some are not */ /* formatted correctly to be dictionary entries. */ /* We require a dictionary entry to have each letter */ /* separated by commas. */ word([do,g]). word([C,a,t]). word([p_i_g]). word([bug]). word(fly). word([r,a,t]). word([a,n,t]). word([p,u,p])./* Program: p0306 origin_query1 */ /* Query to resolve issue of which came first */ chicken(X) :- egg(Y). egg(Y) :- chicken(X)./* Program: p0307 origin_query2 */ /* Query to resolve issue of which came first */ /* and print out the results. */ chicken(X) :- nl,write('X is a chicken if Y is an egg. '),egg(Y). egg(Y) :- write('Y is an egg if X is a chicken.'),chicken(X)./* Program: p0308 test_file */ /* This file attempts to redefine a system predicate */ number(a)./* Program: p0309 database_dict */ word([t,a,b]). word([e,p,a]). word([b,a,t]). word([t,e,n]). word([t,a,n]). word([r,a,t]). word([r,a,n]). word([a,t,e]). word([j,a,b]). word([j,o,e]). word([b,e,t]). word([a,p,e]). word([n,e,t]). word([a,p,t]). word([o,f,t]). word([o,p,t])./* Program: p0310 query_word_sq */ wordsq(A,B,C,D,E,F,G,H,I) :- /* 1 */ word([A,B,C]), /* 2 */ word([D,E,F]), /* 3 */ word([G,H,I]), /* 4 */ word([A,D,G]), /* 5 */ word([B,E,H]), /* 6 */ word([C,F,I]). /* 7 */ sqword :- /* 1 */ word([A,B,C]), /* 2 */ word([D,E,F]), /* 3 */ word([G,H,I]), /* 4 */ word([A,D,G]), /* 5 */ word([B,E,H]), /* 6 */ word([C,F,I]), /* 7 */ write(A),write(B),write(C),nl, /* 8 */ write(D),write(E),write(F),nl, /* 9 */ write(G),write(H),write(I),nl,nl, /* 10 */ fail. /* 11 */ /* Program: p0311 databse2.pro */ /* */ /* This is the database_file to load into */ /* prolog2. Notice the filename is eight */ /* characters and ends in the extension .PRO. */ word([t,a,b]). word([e,p,a]). word([b,a,t]). word([t,e,n]). word([t,a,n]). word([r,a,t]). word([r,a,n]). word([a,t,e]). word([j,a,b]). word([j,o,e]). word([b,e,t]). word([a,p,e]). word([n,e,t]). word([a,p,t]). word([o,f,t]). word([o,p,t])./* Program: p0312 query2.pro */ /* */ /* This file contains the queries to be loaded into */ /* prolog2. Notice the filename ends in */ /* the extension .PRO */ wordsq(A,B,C,D,E,F,G,H,I) :- /* 1 */ word([A,B,C]), /* 2 */ word([D,E,F]), /* 3 */ word([G,H,I]), /* 4 */ word([A,D,G]), /* 5 */ word([B,E,H]), /* 6 */ word([C,F,I]). /* 7 */ sqword :- /* 1 */ word([A,B,C]), /* 2 */ word([D,E,F]), /* 3 */ word([G,H,I]), /* 4 */ word([A,D,G]), /* 5 */ word([B,E,H]), /* 6 */ word([C,F,I]), /* 7 */ write(A),write(B),write(C),nl, /* 8 */ write(D),write(E),write(F),nl, /* 9 */ write(G),write(H),write(I),nl,nl, /* 10 */ fail. /* 11 *//* Program: p0313 query_diagonals */ /* In order to load this file into Prolog-2 the filename */ /* will have to be changed to have only eight letters */ /* and end in .PRO */ /* The two queries are logically equivalent. */ wordsq1(A,B,C,D,E,F,G,H,I) :- word([A,B,C]), word([D,E,F]), word([G,H,I]), word([A,D,G]), word([B,E,H]), word([C,F,I]), word([A,E,I]), /* diag test */ word([C,E,G]). /* diag test */ wordsq2(A,B,C,D,E,F,G,H,I) :- word([C,E,G]), /* diag test */ word([A,B,C]), word([D,E,F]), word([G,H,I]), word([A,D,G]), word([A,E,I]), /* diag test */ word([B,E,H]), word([C,F,I])./* Program: p0314 query_both_ways */ /* This query outputs word squares in which */ /* each horizontal (left-right) and vertical (up-down)*/ /* sequence of letters is a valid three letter word. */ /* The word definitions, which are separated by */ /* commas, can occur in any order. */ wordsq3(A,B,C,D,E,F,G,H) :- word([A,B,C]), word([C,B,A]), word([D,E,F]), word([F,E,D]), word([G,H,I]), word([I,H,G]), word([A,D,G]), word([G,D,A]), word([B,E,H]), word([H,E,B]), word([C,F,I]), word([I,F,C]). /* Program: p0315 query_e */ /* These queries will only find word squares */ /* in which the center letter, E, is a "t". */ /* The two queries are logically equivalent, but */ /* differ radically in efficiency. */ wordsq4(A,B,C,D,E,F,G,H,I) :- word([A,B,C]), word([D,E,F]), word([G,H,I]), word([A,D,G]), word([B,E,H]), word([C,F,I]), E == "t". wordsq5(A,B,C,D,E,F,G,H,I) :- word([A,B,C]), word([D,E,F]), E == "t", word([G,H,I]), word([A,D,G]), word([B,E,H]), word([C,F,I])./* Program: p0401 tobe_ppf.prg */ /* row and column labels and names of tables */ root(be). tense(pres). tense(past). tense(fut). person(1). person(2). person(3). numero(sg). numero(pl). /* entries in the tables */ form(am). form(are). form(is). form(was). form(were). form(will_be). /* table 4.1 information: present tense of verb to be */ verb_form(root(be),tense(pres),person(1),numero(sg),form(am)). verb_form(root(be),tense(pres),person(2),numero(sg),form(are)). verb_form(root(be),tense(pres),person(3),numero(sg),form(is)). verb_form(root(be),tense(pres),person(1),numero(pl),form(are)). verb_form(root(be),tense(pres),person(2),numero(pl),form(are)). verb_form(root(be),tense(pres),person(3),numero(pl),form(are)). /* table 4.2 information: past tense of verb to be */ verb_form(root(be),tense(past),person(1),numero(sg),form(was)). verb_form(root(be),tense(past),person(2),numero(sg),form(were)). verb_form(root(be),tense(past),person(3),numero(sg),form(was)). verb_form(root(be),tense(past),person(1),numero(pl),form(were)). verb_form(root(be),tense(past),person(2),numero(pl),form(were)). verb_form(root(be),tense(past),person(3),numero(pl),form(were)). /* table 4.3 information: future tense of the verb to be*/ verb_form(root(be),tense(fut),person(1),numero(sg),form(will_be)). verb_form(root(be),tense(fut),person(2),numero(sg),form(will_be)). verb_form(root(be),tense(fut),person(3),numero(sg),form(will_be)). verb_form(root(be),tense(fut),person(1),numero(pl),form(will_be)). verb_form(root(be),tense(fut),person(2),numero(pl),form(will_be)). verb_form(root(be),tense(fut),person(3),numero(pl),form(will_be))./* Program: p0402 search.prg */ /* Date: November 17, 1989 */ data(R,T,P,N,F) :- root(R),tense(T),person(P),numero(N), form(F),verb_form(root(R),tense(T), person(P),numero(N), form(F))./* Program: p0403 Extract of: tobe_ppf.prg */ /* table 4.1 information: present tense of */ /* the verb to be */ verb_form(root(be),tense(pres),person(1),numero(sg),form(am)). verb_form(root(be),tense(pres),person(2),numero(sg),form(are)). verb_form(root(be),tense(pres),person(3),numero(sg),form(is)). verb_form(root(be),tense(pres),person(1),numero(pl),form(are)). verb_form(root(be),tense(pres),person(2),numero(pl),form(are)). verb_form(root(be),tense(pres),person(3),numero(pl),form(are))./* Program: p0404 Version 2 */ /* table 4.1 information: present tense of */ /* the verb to be */ verb_form(root(be),tense(pres),person(1),numero(sg),form(am)). verb_form(root(be),tense(pres),person(2),numero(sg),form(are)). verb_form(root(be),tense(pres),person(3),numero(sg),form(is)). verb_form(root(be),tense(pres),person(X),numero(pl),form(are))./* Program: p0405 Version 3 */ /* table 4.1 information: present tense of */ /* the verb to be */ verb_form(root(be),tense(pres),person(X),numero(pl),form(are)). verb_form(root(be),tense(pres),person(1),numero(sg),form(am)). verb_form(root(be),tense(pres),person(2),numero(sg),form(are)). verb_form(root(be),tense(pres),person(3),numero(sg),form(is))./* Program: p0406 Version 4 */ /* table 4.1 information: present tense of */ /* the verb to be */ root(be). tense(pres). tense(past). tense(fut). person(1). person(2). person(3). numero(sg). numero(pl). form(am). form(are). form(is). form(was). form(were). form(will_be). verb_form(root(be),tense(pres),person(1),numero(sg),form(am)). verb_form(root(be),tense(pres),person(3),numero(sg),form(is)). verb_form(root(be),tense(pres),person(_),numero(_),form(are)). /* Program: p0407 Version 5 */ /* table 4.1 information: present tense of */ /* the verb to be */ root(be). tense(pres). tense(past). tense(fut). person(1). person(2). person(3). numero(sg). numero(pl). form(are). form(am). form(is). form(was). form(were). form(will_be). verb_form(root(be),tense(pres),person(_),numero(_),form(are)). verb_form(root(be),tense(pres),person(1),numero(sg),form(am)). verb_form(root(be),tense(pres),person(3),numero(sg),form(is)). /* Program: p0408 articles.prg */ type(definite). type(indefinite). numero(pl). numero(sing). form(the). form(a). form(''). determiner(type(definite),numero(sing),form(the)). determiner(type(definite),numero(pl),form(the)). determiner(type(indefinite),numero(sing),form(a)). determiner(type(indefinite),numero(pl),form('')). /* Program: p0409 detlook.prg */ det(X) :- type(T),numero(N), determiner(type(T),numero(N),form(X)), write('The '), write(T), write(' '), write(N), write(' determiner is: '), write(X), write('.'), nl. /* Program: p0410 form_nt.prg */ /* row and column labels */ tense(pres). tense(past). tense(fut). person(1). person(2). person(3). numero(sg). numero(pl). /* forms in tables */ form(hasnt). form(havent). form(doesnt). form(dont). form(wont). form(cant). form(couldnt). form(wasnt). form(werent). form(arent). form(isnt)./* Program: p0411 negcont.prg */ root(have). /* root forms of verbs */ root(be). root(do). root(will). root(can). /* tables of negative contraction forms for root verbs */ neg_cont(root(have),tense(pres),person(3),numero(sg),form(hasnt)). neg_cont(root(have),tense(pres),person(X),numero(Y),form(havent)). neg_cont(root(have),tense(past),person(X),numero(Y),form(hadnt)). neg_cont(root(do),tense(pres),person(3),numero(sg),form(doesnt)). neg_cont(root(do),tense(past),person(X),numero(Y),form(didnt)). neg_cont(root(will),tense(fut),person(X),numero(Y),form(wont)). neg_cont(root(can),tense(pres),person(X),numero(Y),form(cant)). neg_cont(root(can),tense(past),person(X),numero(Y),form(couldnt)). neg_cont(root(be),tense(past),person(3),numero(sg),form(wasnt)). neg_cont(root(be),tense(past),person(1),numero(sg),form(wasnt)). neg_cont(root(be),tense(past),person(X),numero(Y),form(werent)). neg_cont(root(be),tense(pres),person(1),numero(sg),form(X)) :- !,fail. neg_cont(root(be),tense(pres),person(3),numero(sg),form(isnt)). neg_cont(root(be),tense(pres),person(X),numero(Y),form(arent))./* Program: p0412 nc_look.prg */ nc(R,T,P,N,F) :- root(R),tense(T),person(P),numero(N), neg_cont(root(R),tense(T), person(P),numero(N),form(F))./* Program: p0501 books1.prg */ /* contains the information in bibliography 2 */ /* entries for author and title ordered by date */ entry(franklin,ben,1789,autobiography). entry(durber,tess,1885,he_done_her_wrong). entry(benton,tess,1933,accounting_primer). entry(morton,ann,1943,introduction_to_geometry). entry(adler,ben,1944,democracy_in_action). entry(morton,zeke,1974,plants_of_the_carolinas). entry(zabrisky,albert,1982,space_reentry_vehicles). entry(talbot,ann,1984,spanish_for_travelers). entry(douglas,ben,1989,bread_baking_in_france). entry(durber,tracy,1991,advanced_calculus). /* alphabetically ordered list of last names */ last(adler). last(benton). last(douglas). last(durber). last(franklin). last(morton). last(talbot). last(zabrisky). /* alphabetically ordered list of first names */ first(albert). first(ann). first(ben). first(tess). first(tracy). first(zeke)./* Program: p0502 search1_2.pr */ /* Date: 9/2/76 */ search1(L,F,T) :- last(L),first(F),entry(L,F,D,T). search2(L,F,T) :- first(F),last(L),entry(L,F,D,T)./* Program: p0503 books2.prg */ /* entries for author and title ordered by date */ entry(X,Y,2000,real_world_semantics). /* alphabetically ordered list of last names */ last(adler). last(douglas). last(durber). last(zabrisky). /* alphabetically ordered list of first names */ first(ann). first(ben). first(tess). first(zeke)./* Program: p0504 gensort.prg */ /* Date: 3/28/86 */ /* load: books1.prg */ /* Basic search relations for first and last names */ search1(L,F,T) :- first(F),last(L),entry(L,F,D,T). search2(L,F,T) :- last(L),first(F),entry(L,F,D,T). /* Unordered facts about the gender associated */ /* with first names */ male(albert). male(zeke). female(tracy). female(ann). male(ben). female(tess). /* These relations enable searches for female authors */ search3(L,F,T) :- first(F),last(L),female(F),entry(L,F,D,T). search4(L,F,T) :- last(L),first(F),female(F),entry(L,F,D,T)./* Program: p0505 samelast.prg */ /* Date: 11/17/90 */ /* load: books1.prg */ /* Relation to search for same last name, but */ /* different first names */ search5(L1,F1,T1,L2,F2,T2) :- first(F1),last(L1),entry(L1,F1,XD,T1), last(L2),L2==L1, first(F2),not(F1==F2), entry(L2,F2,YD,T2)./* Program: p0506 . search68.prg */ /* Date: Jan 5, 1992 */ search6(L,F,D,T) :- last(L),first(F),entry(L,F,D,T). search7(L,F,D,T) :- last(L),first(F),title(T),entry(L,F,D,T). search8(L,F,D,T) :- first(F),entry(L,F,D,T)./* Program: p0507 newitem.prg */ /* Add this to the database books1.prg. */ entry(abbot,albert,1985,history_of_the_erie_canal)./* Program: p0508 */ search9(L,F,T) :- last(L),first(F),censorship_record(F,L,R), acceptable(R),entry(L,F,D,T)./* Program: p0509 search10.prg */ test(F,L,R) :- censorship_record(F,L,R),acceptable(R). search10(L,F,T) :- last(L),first(F),test(F,L,R),entry(L,F,D,T)./* Program Name: p0510 censor.prg */ /* Date: September 18, 1992 */ /* load: books1.prg */ acceptable(r). acceptable(pg). censorship_record(ben,franklin,pg). censorship_record(tess,durber,r). censorship_record(tess,benton,pg). censorship_record(ann,morton,r). censorship_record(adler,ben,x). censorship_record(zeke,morton,x). censorship_record(albert,zabrisky,pg). censorship_record(ann,talbot,f). censorship_record(ben,douglas,f). censorship_record(tracy,durber,r). search9(L,F,T) :- last(L),first(F),censorship_record(F,L,R), acceptable(R),entry(L,F,D,T). test(F,L,R) :- censorship_record(F,L,R),acceptable(R). search10(L,F,T) :- last(L),first(F),test(F,L,R),entry(L,F,D,T). /* Program: p0511 censorship example 1 */ test(A,B,C) :- censorship_record(A,B,C),acceptable(C). search10(L,F,T) :- last(L),first(F),test(F,L,R),entry(L,F,D,T). /* Program: p0512 censorship example 2 */ test(F,L,R) :- censorship_record(F,L,R),acceptable(R). search10(L,F,T) :- last(L),first(F),test(F,L,R),entry(L,F,D,T)./* Program: p0513 */ /* censorship example 3 */ search9(L,F,T) :- last(L),first(F),censorship_record(A,B,C), acceptable(C),entry(L,F,D,T). /* censorship example 4 */ search9(L,F,T) :- last(L),first(F),censorship_record(F,L,R), acceptable(R),entry(L,F,D,T)./* Program: p0514 gensort.lst */ /* sort by gender */ /* load books1.lst */ /* unordered facts about the gender associated */ /* with first names */ male(albert). male(zeke). female(tracy). female(ann). male(ben). female(tess). /* relations which enable a search for woman authors */ man(X) :- first(X),male(X). woman(X) :- first(X),female(X). search11(L,F,T) :- woman(F),entry(L,F,D,T). search12(L,F,T) :- last(L),woman(F),entry(L,F,D,T). /* Program: p0515 realthng.prg */ /* Date: November 17, 1989 */ /* alphabetical list of last names */ last(chomsky). last(jespersen). last(lorenz). /* alphabetical list of first names */ first(carol). first(konrad). first(noam). first(otto). entry(chomsky, noam, 1957,syntactic_structures,the_hague, mouton). entry(jespersen,otto,1964,essentials_of_english_grammar, forge_valley_mass,murray_co). entry(chomsky,noam,1965,aspects_of_the_theory_of_syntax, cambridge_mass,mit_press). entry(chomsky,carol,1969,the_acquisition_of_syntax_in_children_from_5_to_10, cambridge_mass,mit_press). entry(lorenz,konrad,1973,behind_the_mirror,new_york,harcourt_brace_co). /* Program: p0516 bibliog.prg */ /* Date: November 18, 1990 */ format1(L,F,D,T,W,P) :- write(L),write(', '),write(F),write('. '), write(D),write('. '),write(T),write('. '), write(W),write(': '),write(P),write('.'),nl. format2(L,F,D,T,W,P) :- write(L),write(', '),write(F),write('. '), write('('),write(D),write(') '), write(T),write(' '), write('('),write(P),write(') '), write(W),write('.'),nl. search13(L,F) :- last(L),first(F),entry(L,F,D,T,W,P), format1(L,F,D,T,W,P). search14(L,F) :- last(L),first(F),entry(L,F,D,T,W,P), format2(L,F,D,T,W,P). /* Program: p0517 bibliog1.prg */ /* Date: March 28, 1986 */ search15 :- last(L),first(F),entry(L,F,D,T,W,P), format1(L,F,D,T,W,P). search16 :- last(L),first(F),entry(L,F,D,T,W,P), format2(L,F,D,T,W,P). search17 :- last(L),first(F),entry(L,F,D,T,W,P), format1(L,F,D,T,W,P),fail. search18 :- last(L),first(F),entry(L,F,D,T,W,P), format2(L,F,D,T,W,P),fail. /* Program: p0601 irreg.prg */ root(cost). root(look). root(dive). root(hit). root(lay). root(shine). tense(past). tense(pres). tense(fut). person(1). person(2). person(3). numero(sg). numero(plu). form(shines). form(shine). form(shined). form(will_shine). form(costs). form(cost). form(will_cost). form(dives). form(dive). form(dove). form(dived). form(will_dive). form(looks). form(look). form(looked). form(will_look). form(hits). form(hit). form(will_hit). form(lays). form(lay). form(laid). form(will_lay). vf(shine,pres,3,sg,shines). vf(shine,pres,X,Y,shine). vf(shine,past,X,Y,shined). vf(shine,past,X,Y,shone). vf(shine,fut,X,Y,will_shine). vf(cost,pres,3,sg,costs). vf(cost,pres,X,Y,cost). vf(cost,past,X,Y,cost). vf(cost,fut,X,Y,will_cost). vf(dive,pres,3,sg,dives). vf(dive,pres,X,Y,dive). vf(dive,past,X,Y,dove). vf(dive,past,X,Y,dived). vf(dive,fut,X,Y,will_dive). vf(look,pres,3,sg,looks). vf(look,pres,X,Y,look). vf(look,past,X,Y,looked). vf(look,fut,X,Y,will_look). vf(hit,pres,3,sg,hits). vf(hit,pres,X,Y,hit). vf(hit,past,X,Y,hit). vf(hit,fut,X,Y,will_hit). vf(lay,pres,3,sg,lays). vf(lay,pres,X,Y,lay). vf(lay,past,X,Y,lay). vf(lay,past,X,Y,laid). vf(lay,fut,X,Y,will_lay)./* Program: p0602 irreg.prg */ /* wh-: Which verb roots have the same form in */ /* two tenses? */ searcha(R) :- root(R),tense(T1),tense(T2),form(F1), form(F2),person(P),numero(N), not(T1==T2),F1==F2, vf(R,T1,P,N,F1), vf(R,T2,P,N,F2), fail. /* yes/no Which verb roots have the same form */ /* in two tenses? */ searchb :- root(R),tense(T1),tense(T2),form(F1), form(F2),person(P),numero(N), not(T1==T2),F1==F2, vf(R,T1,P,N,F1), vf(R,T2,P,N,F2), write('Root verb = '),write(R),nl, fail. /* Program: p0603 irreg1.prg */ /* wh-: Which verb root has the same form (F12) in */ /* the past tense and the present tense? */ searchc(R) :- root(R),form(F12),person(P),numero(N), vf(R,past,P,N,F12), vf(R,pres,P,N,F12), fail. /* yes/no: Which verb root has the same form (F12) */ /* in the past tense and the present tense? */ searchd :- root(R),form(F12),person(P),numero(N), vf(R,past,P,N,F12), vf(R,pres,P,N,F12),nl, write('Root verb = '),write(R),write('.'), fail. /* Program: p0604 samelast.prg */ /* load: books1.lst */ /* relation to search for same last name, but */ /* different first names */ search5(L1,F1,T1,L2,F2,T2) :- first(F1),last(L1),entry(L1,F1,XD,T1), last(L2),L2==L1, first(F2),not(F1==F2), entry(L2,F2,YD,T2)./* Program: p0605 samelst1.prg */ search5a(L1,F1,T1,L2,F2,T2) :- first(F1),last(L1),first(F2),last(L2), L2==L1,not(F1==F2), entry(L1,F1,XD,T1), entry(L2,F2,YD,T2). /* Program: p0606 prespas1.prg */ /* Which verbs have the same form in the present */ /* and the past? */ searchd :- /* 1 */ root(R), /* 2 */ form(F12),person(P),numero(N), /* 3 */ vf(R,past,P,N,F12), /* 4 */ vf(R,pres,P,N,F12), /* 5 */ write('Root verb = '),write(R),write('.'),nl, /* 6 */ fail. /* 7 *//* Program: p0607 prespas2.prg */ /* Which verbs have the same form in the */ /* present and the past? */ searche :- root(R),dbtest(R),fail. dbtest(R) :- form(F12),person(P),numero(N), vf(R,past,P,N,F12), vf(R,pres,P,N,F12), write('Root verb = '),write(R),write('.'),nl,!./* Program: p0608 prespas3.prg */ /* wh- Which verbs have the same form in the */ /* present and past? */ searchf(R) :- root(R),dbtest(R). dbtest(R) :- form(F12),person(P),numero(N), vf(R,past,P,N,F12), vf(R,pres,P,N,F12), write('Root verb = '),write(R),write('.'),nl,!. /* Program: p0609 test1.prg */ /* Relation to illustrate the or in prolog. */ test1 :- ( (nl,write('first case')); (nl,write('second case')); (nl,write('third case')); (nl,write('fourth case')) ), nl,write(' steps to do in any case'), fail./* Program: p0610 test1a.prg */ /* Relation to illustrate the or in prolog. */ test1a :- test1b, nl,write(' steps to do in any case'), fail. test1b :- nl,write('first case'). test1b :- nl,write('second case'). test1b :- nl,write('third case'). test1b :- nl,write('fourth case')./* Program: p0611 test2x.pgr */ /* This illustrates an or with one branch */ /* being a /stop (cut-fail). */ /* Instructions: Enter a number from 1 to 4. */ test2(X) :- ( ((X==1),nl,write('one')); ((X==2),nl,write('two')); ((X==3),nl,write('three')); ((X==4),nl,write('four')); (nl,write('You failed to follow instructions.'),!,fail) ), nl,write('You successfully followed instructions')./* Program: p0612 test2ax.prg */ /* This illustrates an or with one branch being */ /* a stop (cut-fail). */ /* Instructions: Enter a number from 1 to 4. */ test2a(X) :- test2b(X), nl,write('You successfully followed instructions.'). test2b(X) :- (X==1),nl,write('one'). test2b(X) :- (X==2),nl,write('two'). test2b(X) :- (X==3),nl,write('three'). test2b(X) :- (X==4),nl,write('four'). test2b(X) :- nl,write('You failed to follow instructions'),!,fail./* Program: p0613 test3.prg */ adj(yellow). adj(orange). noun(yellow). noun(grape). noun(look). noun(orange). verb(yellow). verb(look). /* The bad search relation */ test3(X) :- ( (noun(X),nl,write(X),write(' is a noun')); (verb(X),nl,write(X),write(' is a verb')); (adj(X),nl,write(X),write(' is an adjective')); (nl,write(X),write(' is not in the lexicon')) ), fail. /* The good search relation */ form(X) :- noun(X);verb(X);adj(X). test3a(X) :- ( (noun(X),nl,write(X),write(' is a noun')); (verb(X),nl,write(X),write(' is a verb')); (adj(X),nl,write(X),write(' is an adjective')); (not(form(X)),nl,write(X), write(' is not in the lexicon')) ), fail./* Program: p0614 test3b.prg */ /* Another good test relation */ test3b(X) :- not(noun(X);verb(X);adj(X)), nl,write(X),write(' is not in the lexicon'),!. test3b(X) :- ( (noun(X),nl,write(X),write(' is a noun')); (verb(X),nl,write(X),write(' is a verb')); (adj(X),nl,write(X), write(' is an adjective')) ), fail. /* Program: p0615 test4x.prg */ /* The better search relation */ /* The makes only one pass through the lexicon */ test4(X) :- ( ( (noun(X),nl,write('X is a noun.')); (verb(X),nl,write('X is a verb.')); (adj(X),nl,write('X is an adjective.')) ); nl,write('X is not in the lexicon.') ), nl,write(' I hope you are satisfied.'),fail. /* Program: p0616 */ /* The ugly search relation */ equal(X,X). test3ug(X) :- equal(Check,0), ( (noun(X),nl,write(X),write(' is a noun'), equal(Check,1)); (verb(X),nl,write(X),write(' is a verb'), equal(Check,1)); (adj(X),nl,write(X),write(' is an adjective'), equal(Check,1)); ((Check==0),nl,write(X),write(' is not in the lexicon')) ), fail./* Program: p0617 */ search1(R) :- ( (root(R),nl,write('R is in the database.')); (nl,write('R is not in the database.')) ), nl,write('Your doubts about R should be assuaged.'). /* Program: p0618 */ search2(F) :- ( (form(F),nl,(write('F is a form in the database.'))); (nl,write('F is not a form in the database.')) ), nl,write('Your doubts about F should be lifted.')./* Program: p0619 */ search3(F) :- ( (vf(R,T,P,N,F),nl,write('F is a form in the database.')); (nl,write('F is not a form in the database.')) ), nl,write('Your doubts about F should be lifted.'). /* Program: p0620 */ search4(F) :- ( (vf(R,T,P,N,F),nl,write('F is a part of a complex fact in the database.')); (form(F),nl,write('F is a simple fact in the database.')); (nl,write('F is not a form in the database.')) ), nl,write('Your doubts about F should be lifted.'). search5(F) :- ( ( (vf(R,T,P,N,F);form(F)), nl,write('F is in the database.') ); (nl,write('F is not in the database.')) ), nl,write('Your doubts about F should be lifted.')./* Program: p0621 */ /* load program: irreg.prg */ searchg(R) :- (not(root(R)),error(R)); dbtest(R). dbtest(R) :- form(F12),person(P),numero(N), vf(R,past,P,N,F12), vf(R,pres,P,N,F12), write('Root verb = '),write(R),write('.'),nl,!. error(R) :- nl,write('This search fails because '),write(R), write(' is not in the lexicon.'), nl,write('There is no simple fact like the following:'), nl,write('root('),write(R),write(').'),nl,!,fail./* Program: p0622 */ /* Which verb root has two past tense forms? */ search_1 :- /* head */ root(R),tense(T),person(P),numero(N), /* generator */ form(F1),form(F2), not(F1=F2), /* filter */ vf(R,T,P,N,F1),vf(R,T,P,N,F2), /* database */ write(R), /* output */ fail. /* backtrack *//* Program: p0623 */ /* Which verb root has two past tense forms? */ search_2 :- root(R), vf(R,past,X,Y,F1),vf(R,past,X,Y,F2), not(F1==F2), nl,write('The verb root '),write(R), write(' has two past tense forms: '), write(F1),write(' and '),write(F2),write('.'), fail. /* Program: p0624 irreg1.prg */ root(cost). root(look). root(dive). root(hit). root(lay). root(shine). vf(shine,pres,3,sg,shines). vf(shine,pres,X,Y,shine). vf(shine,past,X,Y,shined). vf(shine,past,X,Y,shone). vf(shine,fut,X,Y,will_shine). vf(cost,pres,3,sg,costs). vf(cost,pres,X,Y,cost). vf(cost,past,X,Y,cost). vf(cost,fut,X,Y,will_cost). vf(dive,pres,3,sg,dives). vf(dive,pres,X,Y,dive). vf(dive,past,X,Y,dove). vf(dive,past,X,Y,dived). vf(dive,fut,X,Y,will_dive). vf(look,pres,3,sg,looks). vf(look,pres,X,Y,look). vf(look,past,X,Y,looked). vf(look,fut,X,Y,will_look). vf(hit,pres,3,sg,hits). vf(hit,pres,X,Y,hit). vf(hit,past,X,Y,hit). vf(hit,fut,X,Y,will_hit). vf(lay,pres,3,sg,lays). vf(lay,pres,X,Y,lay). vf(lay,past,X,Y,lay). vf(lay,past,X,Y,laid). vf(lay,fut,X,Y,will_lay). /* Program: p0625 */ search_3 :- root(R),datatest(R),fail. datatest(R) :- vf(R,past,X,Y,F1),vf(R,past,X,Y,F2), not(F1==F2), nl,write('The following root has two past tense forms: '), write(R),!./* Program: p0626 */ search_4 :- root(R), vf(R,past,X,Y,F1),vf(R,pres,X,Y,F1), vf(R,past,X,Y,F2), not(F1==F2), nl,write(R), fail./* Program: p0627 */ search_5 :- nl, /* Print Heading */ write('The following roots have two past tense forms.'),nl, write('One of the forms is both present and past tense.'),nl,nl, write('ROOT FORM1 FORM2'),nl, write(' past/pres past'),nl, /* Start Search of Database */ root(R), vf(R,past,X,Y,F1),vf(R,pres,X,Y,F1), vf(R,past,X,Y,F2), not(F1==F2), /* Output Results of Search */ write(R),write(' '), write(F1),write(' '), write(F2),nl, fail./* Program: p0312 query2.pro */ /* */ /* This file contains the queries to be loaded into */ /* prolog2. Notice the filename ends in */ /* the extension .PRO */ wordsq(A,B,C,D,E,F,G,H,I) :- /* 1 */ word([A,B,C]), /* 2 */ word([D,E,F]), /* 3 */ word([G,H,I]), /* 4 */ word([A,D,G]), /* 5 */ word([B,E,H]), /* 6 */ word([C,F,I]). /* 7 */ sqword :- /* 1 */ word([A,B,C]), /* 2 */ word([D,E,F]), /* 3 */ word([G,H,I]), /* 4 */ word([A,D,G]), /* 5 */ word([B,E,H]), /* 6 */ word([C,F,I]), /* 7 */ write(A),write(B),write(C),nl, /* 8 */ write(D),write(E),write(F),nl, /* 9 */ write(G),write(H),write(I),nl,nl, /* 10 */ fail. /* 11 */