Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************* database **********************/
- male(austin).
- male(brock).
- male(callum).
- male(dominic).
- male(eastwood).
- male(ferris).
- male(guy).
- male(houston).
- male(irving).
- male(jace).
- male(kingston).
- male(landon).
- male(mickey).
- female(natalia).
- female(ophelia).
- female(phoenix).
- female(quinn).
- female(renee).
- female(sky).
- female(tessa).
- female(ursula).
- female(victoria).
- female(waverly).
- female(xenia).
- female(ysabelle).
- female(zahra).
- person(P) :- male(P).
- person(P) :- female(P).
- home(austin,toronto).
- home(brock,montreal).
- home(callum,vancouver).
- home(dominic,vancouver).
- home(eastwood,toronto).
- home(ferris,brampton).
- home(guy,brampton).
- home(houston,tokyo).
- home(irving,orlando).
- home(jace,newYork).
- home(kingston,newYork).
- home(landon,london).
- home(mickey,beijing).
- home(natalia,toronto).
- home(ophelia,montreal).
- home(phoenix,vancouver).
- home(quinn,vancouver).
- home(renee,toronto).
- home(sky,brampton).
- home(tessa,boston).
- home(ursula,tokyo).
- home(victoria,orlando).
- home(waverly,newYork).
- home(xenia,london).
- home(ysabelle,beijing).
- home(zahra,london).
- city(toronto).
- city(montreal).
- city(vancouver).
- city(brampton).
- city(orlando).
- city(boston).
- city(newYork).
- city(tokyo).
- city(beijing).
- city(london).
- country(canada).
- country(usa).
- country(england).
- country(japan).
- country(china).
- country(kenya).
- country(spain).
- country(australia).
- country(greece).
- country(jamaica).
- location(toronto,canada).
- location(montreal,canada).
- location(vancouver,canada).
- location(brampton,canada).
- location(orlando,usa).
- location(boston,usa).
- location(newYork,usa).
- location(tokyo,japan).
- location(beijing,china).
- location(london,england).
- population(toronto,1000000). /* big */
- population(montreal,45000). /* small */
- population(vancouver,500000). /* big */
- population(brampton,20000). /* small */
- population(orlando,3000). /* small */
- population(newYork,700000). /* big */
- population(boston,51000). /* big */
- population(tokyo,72000). /* big */
- population(beijing,10000). /* small */
- population(london,49000). /* small */
- married(austin,natalia).
- married(natalia,austin).
- married(brock,ophelia).
- married(ophelia,brock).
- married(callum,phoenix).
- married(phoenix,callum).
- married(dominic,quinn).
- married(quinn,dominic).
- married(eastwood,renee).
- married(renee,eastwood).
- married(guy,sky).
- married(sky,guy).
- married(houston,ursula).
- married(ursula,houston).
- married(irving,victoria).
- married(victoria,irving).
- married(kingston,waverly).
- married(waverly,kingston).
- married(landon,xenia).
- married(xenia,landon).
- married(mickey,ysabelle).
- married(ysabelle,mickey).
- parent(austin,callum).
- parent(natalia,callum).
- parent(brock,phoenix).
- parent(ophelia,phoenix).
- parent(callum,dominic).
- parent(phoenix,dominic).
- parent(callum,eastwood).
- parent(phoenix,eastwood).
- parent(dominic,ferris).
- parent(quinn,ferris).
- parent(dominic,sky).
- parent(quinn,sky).
- parent(guy,tessa).
- parent(sky,tessa).
- parent(houston,irving).
- parent(ursula,irving).
- parent(houston,jace).
- parent(ursula,jace).
- parent(houston,waverly).
- parent(ursula,waverly).
- parent(landon,mickey).
- parent(xenia,mickey).
- parent(mickey,zahra).
- parent(ysabelle,zahra).
- friend(austin,brock).
- friend(brock,austin).
- friend(eastwood,jace).
- friend(jace,eastwood).
- friend(guy,mickey).
- friend(mickey,guy).
- friend(natalia,ophelia).
- friend(ophelia,natalia).
- friend(quinn,renee).
- friend(renee,quinn).
- friend(sky,ysabelle).
- friend(ysabelle,sky).
- friend(tessa,zahra).
- friend(zahra,tessa).
- friend(victoria,waverly).
- friend(waverly,victoria).
- father(X,Y) :- male(X), parent(X,Y).
- mother(X,Y) :- female(X), parent(X,Y).
- brother(X,Y) :- male(X), parent(Z,X), parent(Z,Y), not(X=Y).
- sister(X,Y) :- female(X), parent(Z,X), parent(Z,Y), not(X=Y).
- grandfather(X,Y) :- father(X,Z), parent(Z,Y).
- grandmother(X,Y) :- mother(X,Z), parent(Z,Y).
- uncle(X,Y) :- brother(X,Z), parent(Z,Y).
- auntie(X,Y) :- sister(X,Z), parent(Z,Y).
- % an ancestor is a parent, grandparent, great-grandparent, great-great-grandparent, and so forth
- ancestor(X,Y) :- parent(X,Y).
- ancestor(X,Y) :- parent(X,Z), ancestor(Z,Y).
- % a relative is someone you share a common ancestor with
- relative(X,Y) :- ancestor(X,Y), not(X=Y).
- relative(X,Y) :- ancestor(Y,X), not(X=Y).
- relative(X,Y) :- ancestor(Z,X), ancestor(Z,Y), not(X=Y).
- /******************* lexicon **********************/
- article(a). article(an). article(any).
- common_noun(man,X) :- male(X).
- common_noun(woman,X) :- female(X).
- common_noun(person,X) :- person(X).
- common_noun(city,X) :- city(X).
- common_noun(country,X) :- country(X).
- common_noun(parent,X) :- parent(X,_).
- common_noun(friend,X) :- friend(X,_).
- common_noun(father,X) :- father(X,_).
- common_noun(mother,X) :- mother(X,_).
- common_noun(husband,X) :- male(X), married(X,_).
- common_noun(wife,X) :- female(X), married(_,X).
- common_noun(child,X) :- parent(_,X).
- common_noun(brother,X) :- brother(X,_).
- common_noun(sister,X) :- sister(X,_).
- common_noun(grandfather,X) :- grandfather(X,_).
- common_noun(grandmother,X) :- grandmother(X,_).
- common_noun(uncle,X) :- uncle(X,_).
- common_noun(auntie,X) :- auntie(X,_).
- common_noun(relative,X) :- relative(X,_).
- common_noun(ancestor,X) :- ancestor(X,_).
- adjective(large,X) :- population(X,Y), Y >= 50000.
- adjective(small,X) :- population(X,Y), Y < 50000.
- adjective(largest,X) :- location(X,Z), population(X,Y), Y >= 50000, \+ (location(X2,Z), population(X2,Y2), Y2 >= 50000, not(X=X2), Y2 > Y).
- adjective(smallest,X) :- location(X,Z), population(X,Y), Y < 50000, \+ (location(X2,Z), population(X2,Y2), Y2 < 50000, not(X=X2), Y2 < Y).
- adjective(single,X) :- not(married(X,_)).
- adjective(married,X) :- married(X,_).
- adjective(american,X) :- home(X,C), location(C,usa).
- adjective(canadian,X) :- home(X,C), location(C,canada).
- adjective(chinese,X) :- home(X,C), location(C,china).
- preposition(with,X,Y) :- friend(Y,X).
- preposition(with,X,Y) :- married(Y,X).
- preposition(with,X,Y) :- relative(Y,X).
- preposition(with,X,Y) :- ancestor(Y,X).
- preposition(of,X,Y) :- friend(Y,X).
- preposition(of,X,Y) :- married(Y,X).
- preposition(of,X,Y) :- relative(Y,X).
- preposition(of,X,Y) :- ancestor(Y,X).
- preposition(from,X,Y) :- home(X,Y).
- preposition(from,X,Y) :- home(X,C), location(C,Y).
- preposition(in,X,Y) :- location(X,Y).
- proper_noun(X) :- not(article(X)), not(adjective(X,_)), not(common_noun(X,_)), not(preposition(X,_,_)).
- /******************* parser **********************/
- who(Words,Ref) :- np(Words,Ref).
- what(Words,Ref) :- np(Words,Ref).
- /* Noun phrase can be a proper name or can start with an article */
- np([Name],Name) :- proper_noun(Name).
- np([Art|Rest],Who) :- article(Art), np2(Rest,Who).
- /* If a noun phrase starts with an article,then it must be followed
- by another noun phrase that starts either with an adjective
- or with a common noun. */
- np2([Adj|Rest],Who) :- adjective(Adj,Who), np2(Rest,Who).
- np2([Noun|Rest],Who) :- common_noun(Noun,Who), mods(Rest,Who).
- /* Modifier(s) provide an additional specific info about nouns.
- Modifier can be a prepositional phrase followed by none,one or more
- additional modifiers. */
- mods([],_).
- mods(Words,Who) :- appendLists(Start,End,Words), prepPhrase(Start,Who), mods(End,Who).
- prepPhrase([Prep|Rest],Who) :- preposition(Prep,Who,Ref), np(Rest,Ref).
- appendLists([],L,L).
- appendLists([H|L1],L2,[H|L3]) :- appendLists(L1,L2,L3).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement