/* File: sample.P ** ** Author: Zhiquan Gao ** ** Contact: zgao@cs.sunysb.edu ** ** */ :- table q1/2, q2/2, q3/2, q4/2, notMatched/2, feature/2, q5/2. %% person(Name, Address, LoginID, Password) person('P1','add1','Ida1','pa1'). person('P2','add2','Ida2','pa3'). person('P3','add3','Ida3','pa3'). person('P4','add4','Ida4','pa4'). person('P5','add5','Ida5','pa5'). person('P6','add6','Ida6','pa6'). person('P7','add7','Ida7','pa7'). person('P8','add8','Ida8','pa8'). person('P9','add9','Ida9','pa9'). person('P10','add10','Ida10','pa10'). person('P11','add11','Ida11','pa11'). person('Joe Public','add12','Ida12','pa12'). person('P13','add13','Ida13','pa13'). person('P14','add14','Ida14','pa14'). person('P15','add15','Ida15','pa15'). %% preference(Name, Preference) % P1 preference('P1','sports'). preference('P1','hiking'). preference('P1','short'). % P2 preference('P2','sports'). preference('P2','reading'). preference('P2','tall'). preference('P2','slim'). % P3 preference('P3','sports'). preference('P3','tall'). preference('P3','slim'). % P4 preference('P4','reading'). preference('P4','short'). preference('P4','plump'). % P5 preference('P5','sports'). preference('P5','movies'). % P6 preference('P6','sports'). preference('P6','reading'). preference('P6','movies'). preference('P6','short'). % P7 preference('P7','reading'). preference('P7','tall'). % P8 preference('P8','movies'). preference('P8','plump'). % P9 preference('P9','hiking'). preference('P9','slim'). % P10 preference('P10','dance'). preference('P10','short'). preference('P10','plump'). % P11 preference('P11','reading'). preference('P11','short'). % Joe Public preference('Joe Public','sports'). preference('Joe Public','slim'). preference('Joe Public','blond'). % P13 preference('P13','sports'). preference('P13','hiking'). preference('P13','short'). % P14 preference('P14','dance'). preference('P14','tall'). % P15 % no preference for a DSSS personel %% feature(Name, Feature) % P1 feature('P1','sports'). feature('P2','reading'). feature('P1','tall'). feature('P1','slim'). feature('P1','blond'). % P2 feature('P2','sports'). feature('P2','hiking'). feature('P2','short'). feature('P2','plump'). % P3 feature('P3','dance'). feature('P3','tall'). feature('P3','plump'). % P4 feature('P4','reading'). feature('P4','movies'). feature('P4','short'). feature('P4','slim'). feature('P4','blond'). % P5 feature('P5','fishing'). feature('P5','movies'). feature('P5','tall'). feature('P5','plump'). % P6 feature('P6','sports'). feature('P6','reading'). feature('P6','short'). feature('P6','slim'). feature('P6','blond'). % P7 feature('P7','sports'). feature('P7','reading'). feature('P7','tall'). feature('P7','slim'). feature('P7','blond'). % P8 feature('P8','sports'). feature('P8','hiking'). feature('P8','short'). feature('P8','plump'). % P9 feature('P9','reading'). feature('P9','dance'). feature('P9','tall'). feature('P9','plump'). % P10 feature('P10','reading'). feature('P10','movies'). feature('P10','short'). feature('P10','slim'). feature('P10','blond'). % P11 feature('P11','sports'). feature('P11','movies'). feature('P11','short'). feature('P11','plump'). % Joe Public feature('Joe Public','sports'). feature('Joe Public','reading'). feature('Joe Public','hiking'). feature('Joe Public','short'). feature('Joe Public','slim'). % P13 feature('P13','sports'). feature('P13','movies'). feature('P13','tall'). % P14 feature('P14','reading'). feature('P14','dance'). feature('P14','slim'). % P15 % no feature for a DSSS personel %% history(Name_1, Name_2, StartDate, EndDate) %P1 history('P1','Joe Public',20050306,20050401). history('P1','Joe Public',20050510,20050525). history('P1','P8',20050207,20050401). history('P1','P9',20050302,20050307). history('P1','P10',20050308,20050428). % P2 history('P2','P3',20050214,20050428). history('P2','Joe Public',20050301,20050308). history('P2','Joe Public',20050601,20050622). % P3 history('P3','P2',20050214,20050428). history('P3','Joe Public',20050201,20050325). % P4 history('P4','Joe Public',20050306,20050401). % P5 history('P5','Joe Public',20050307,20050308). % P6 history('P6','Joe Public',20050302,20050409). % P7 history('P7','Joe Public',20050628,20050629). % P8 history('P8','P1',20050207,20050401). history('P8','Joe Public',20050701,99999999). history('P8','P11',20050207,99999999). % P9 history('P9','P1',20050302,20050307). % P10 history('P10','P1',20050308,20050428). % P11 history('P11','P13',20050105,20050328). history('P11','P8',20050207,99999999). % Joe Public history('Joe Public','P1',20050306,20050401). history('Joe Public','P1',20050510,20050525). history('Joe Public','P2',20050301,20050308). history('Joe Public','P2',20050601,20050622). history('Joe Public','P3',20050201,20050325). history('Joe Public','P4',20050306,20050401). history('Joe Public','P5',20050307,20050308). history('Joe Public','P6',20050302,20050409). history('Joe Public','P7',20050628,20050629). history('Joe Public','P8',20050701,99999999). % P13 history('P13','P14',20050301,99999999). history('P13','P11',20050105,20050328). % P14 history('P14','P13',20050301,99999999). %% dsssp(Name) dsssp('p11'). dsssp('P15'). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Query 1: List all clients whom Joe Public was dating between % 20050307 and 20050622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% q1(Name,X) :- history(Name,X,From,To), To > 20050306, From < 20050623. ?- writeln('Answer to query one:'). ?- q1('Joe Public', X), write('Client name ='), writeln(X), fail; true. ?- writeln('-----I am a beautiful separate line-----'), nl. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Query 2: List all clients whom Joe Public was dating as of % 20050307 and such that they had at least one common feature % with Joe. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% q2(Name,X) :- history(Name,X,From,To), From =< 20050307, To > 20050307, feature(Name,Feat), feature(X,Feat). ?- writeln('Answer to query two:'). ?- q2('Joe Public',X), write('Client name ='), writeln(X), fail; true. ?- writeln('-----I am a beautiful separate line-----'), nl. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Query 3: Same as above, but now we want Joes dates to % satisfy at least two of his preferences %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% q3(Name,X) :- history(Name,X,From,To), From =< 20050307, To > 20050307, preference(Name,Pref), feature(X,Pref), onemorematch(Name,X,Pref). onemorematch(Name,X,Pref) :- preference(Name,Pref1), feature(X,Pref1), Pref \= Pref1. ?- writeln('Answer to query three:'). ?- q3('Joe Public', X), write('Client name ='), writeln(X), fail; true. ?- writeln('-----I am a beautiful separate line-----'), nl. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Query 4: Find all potential perfect matches Joe Public. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% q4(Name, X) :- person(Name,_,_,_), person(X,_,_,_), tnot(notMatched(Name,X)). notMatched(Name, X) :- preference(Name,Pref), tnot(feature(X,Pref)). ?- writeln('Answer to query four:'). ?- q4('Joe Public', X),write('Client name ='),writeln(X),fail;true. ?- writeln('-----I am a beautiful separate line-----'), nl. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Query 5: Find Joe Publics indirect dates as of 20050307. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% q5(Name,X) :- directdate(Name,X). q5(Name,X) :- directdate(Name,T), q5(T,X). directdate(Name,X):- history(Name,X,From,To), From =< 20050307, To > 20050307. ?- writeln('Answer to query five:'). ?- q5('Joe Public', X), write('Client name ='), writeln(X), fail; true. ?- writeln('-----I am a beautiful separate line-----'). % End_Of_File