%%% Movies Database Queries %%% %%% Q1 %%% % In which year was the movie American Beauty released % ?- movie(american_beauty,Y). % NB. This is a query to be typed in at the Prolog prompt; % you can turn it into a clause by naming the query, e.g. american_beauty_year(Y) :- movie(american_beauty,Y). % Find a movie that was released in the year 2000? % ?- movie(M,2000). % Find a movie that was released before 2000? % ?- movie(M,Y),Y<2000. % Find the name and year of a movie? % ?- movie(M,Y). % Find an actor who has appeared in more than one movie? % ?- actor(M1,A,_),actor(M2,A,_),M1@Y. % released_between(M,Y1,Y2) <- movie M was released between year X and year Y inclusive released_between(M,Y1,Y2) :- movie(M,Y), Y>=Y1, Y=Y2. % cast_member(A,M) <- person A was an actor or actress in movie M % (Give as a two predicates) cast_member(A,M) :- actor(M,A,_). cast_member(A,M) :- actress(M,A,_). % cast_member2(A,M) <- person A was an actor or actress in movie M % (Give as a single predicate using the ; disjunction operator) cast_member2(A,M) :- actor(M,A,_) ; actress(M,A,_). % directed_by(X,Y) <- person X has been in a movie directed by Y % (Hint: re-use your cast_member/2 predicate) directed_by(X,Y) :- director(M,Y), cast_member(X,M). %%% Q3 %%% % What's the difference between these queries? % ?- actor(M1,D,_),actor(M2,D,_). -- returns every actor as M1 and M2 are not necessarily different % ?- actor(M1,D,_),actor(M2,D,_),M1\=M2. -- succeeds twice for every pair of different movies % ?- actor(M1,D,_),actor(M2,D,_),M1@