/* Movies test in Picat. Playing with http://swish.swi-prolog.org/example/movies.pl From http://www.cs.ubbcluj.ro/~csatol/log_funk/prolog/movies.pl This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. % import cp. main => go. %%% From http://swish.swi-prolog.org/example/movies.pl % """ % Here's a first version of a set of exercises for practising the querying % of a simple Prolog database, in this case a movie database (see below). % Modified from exercises found on the web. Not sure who first made them. % % EXERCISES % % Part 1: Write queries to answer the following questions. % a. In which year was the movie American Beauty released? % b. Find the movies released in the year 2000. % c. Find the movies released before 2000. % d. Find the movies released after 1990. % e. Find an actor who has appeared in more than one movie. % f. Find a director of a movie in which Scarlett Johansson appeared. % g. Find an actor who has also directed a movie. % h. Find an actor or actress who has also directed a movie. % i. Find the movie in which John Goodman and Jeff Bridges were co-stars. % % Part 2: Add rules to the database to do the following, % % a. released_after(M, Y) <- the movie was released after the given year. % b. released_before(M, Y) <- the movie was released before the given year. % c. same_year(M1, M2) <- the movies are released in the same year. % d. co_star(A1, A2) <- the actor/actress are in the same movie. % (Remove these if you want to give the exercises to students!) % ?- movie(american_beauty, Y). % ?- movie(M, 2000). % ?- movie(M, Y), Y < 2000. % ?- movie(M, Y), Y > 1999. % ?- actor(M1, A, _), actor(M2, A, _), M1 @> M2. % ?- actress(M, scarlett_johansson, _), director(M, D). % ?- actor(_, A, _), director(_, A). % ?- (actor(_, A, _) ; actress(_, A, _)), director(_, A). % ?- actor(M, john_goodman, _), actor(M, jeff_bridges, _). % % """ go => cl(movies), % http://hakank.org/picat/movies.pi println('year of american_beaty'=findall(Y,movie(american_beauty, Y))), nl, println('movie = 2000'=findall(M, movie(M, 2000))), nl, println('movies_ < 2000'=findall([M,Y], (movie(M, Y), Y < 2000))), nl, println('movies Y > 1999'=findall([M,Y], (movie(M, Y), Y > 1999))), nl, % Too many results % println('movies for actor A'=findall([M1,A,M2], (actor(M1, A, _), actor(M2, A, _), M1 @> M2))), % nl, println('director of scarlett movies'=findall([M,D], (actress(M, scarlett_johansson, _), director(M, D)))), nl, println('actor which is also a director'=findall(A, (actor(_, A, _), director(_, A))).sort_remove_dups), nl, println('actor or actress that is also a director'=findall(A, ((actor(_, A, _) ; actress(_, A, _)), director(_, A))).sort_remove_dups), nl, println('movies where John Goodman and Jeff Bridges acted'=findall(M,(actor(M, john_goodman, _), actor(M, jeff_bridges, _)))), nl, nl. go2 => garbage_collect(200_000_000), cl(movies), % http://hakank.org/picat/movies.pi L=findall([Movie1,Movie2,Year,Actor],( movie(Movie1,Year), movie(Movie2,Year), Movie1 != Movie2, actor(Movie1,Actor,_), actor(Movie2,Actor,_) ) ), foreach([Movie1,Movie2,Year,Actor] in L) println([Movie1,Movie2,Year,Actor]) end, nl.