/* * CS 60, Spring 2008, Assignment 8 * * Movie Database Questions * * Due: Sunday, March 29 by 11:59 PM * * Note: This is a starter Prolog file which you should name movies.pl, * and which you should augment with your solutions! */ /* * This next uncommented line makes sure that the movies_db.pl file is loaded - * it contains all of the movie facts we'll use. * */ :- ensure_loaded('movies_db.pl'). /* * Problem: Complete the definitions of Prolog predicates that respond to * the following queries. * * For reference, you should look over the movies_db.pl file. * * That database defines the following predicates: * * movie([Title, Year], Director, [... categories]) * * actress(Name, [Birth City, Birth State], Birthyear) * * actor(Name, [Birth City, Birth State], Birthyear) * * plays(Player, Role, [Title, Year]) * * Since the essence of the solutions is in your predicate definitions and * not the actual answers, we will provide the answers in test cases. * * In defining your predicates, remove the _ (the underscore character) * from the variables. These are present so the compiler doesn't complain about singleton * variables (once-used names), which are often the sign of an error, such as a spelling error. * * ** TESTING ** * * You should be able to test your predicates by loading this file with * [movies]. * and then running * test. * */ /* * 1. directedBandits(Director) iff Director is the director of the movie * ['Bandits', 2001]. */ directedBandits(_Director) :- tbd. /* * 2. directedByBay(Movie) iff Movie is directed by 'Michael Bay'. */ directedByBay(_Movie) :- tbd. /* * 3. actressAfter1970(Actress) iff Actress was born after 1970. */ actressAfter1970(_Actress) :- tbd. /* * 4. player(Name, BirthPlace, Birthyear) iff either * actor(Name, BirthPlace, Birthyear) * or actress(Name, BirthPlace, Birthyear). */ player(_Name, _Birthplace, _Birthyear) :- tbd. /* * 5. bornInLondon(Player) iff Player was born in ['London', 'England']. */ bornInLondon(_Player) :- tbd. /* * 6. playerAndDirector(Player) iff Player is a player that directed * some movie. */ playerAndDirector(_Player) :- tbd. /* * 7. playedAndDirected(Player) iff Player is a player that directed a movie * in which he or she played. */ playedAndDirected(_Player) :- tbd. /* * 8. playedMultiple(Player) iff Player played in more than one movie. */ playedMultiple(_Player) :- tbd. /* * 9. playedInComedy(Player) iff Player played in a comedy. */ playedInComedy(_Player) :- tbd. /* * 10. playedNotDirected(Director) iff Director directed some movies, but * played in at least one movie he/she did not direct. */ playedNotDirected(_Director) :- tbd. tbd :- fail. % This will make uncompleted problems fail. % % Don't change this :-) % /* * The following will be used for testing your answers. * * It's not crucial that you understand all of this prolog right away * or this week, but these do have some helpful constructs, e.g., "write" . */ test(Name, Var, Query, Desired) :- setof(Var, Query, Ans), !, ( Ans == Desired -> write('*** test '), write(Name), write(' passed'), nl ; write('*** test '), write(Name), write(' failed'), nl, write(' desired was '), write(Desired), nl, write(' actual was '), write(Ans), nl ). test(Name, _Var, _Query, []) :- !, write('*** test '), write(Name), write(' passed'), nl. test(Name, _Var, _Query, Desired) :- write('*** test '), write(Name), write(' failed'), nl, write(' desired was '), write(Desired), nl, write(' no answer produced'), nl. test(1) :- test(1, D, directedBandits(D), ['Barry Levinson']). test(2) :- test(2, M, directedByBay(M), [['Armageddon',1998], ['Pearl Harbor',2001]]). test(3) :- test(3, A, actressAfter1970(A), ['Amanda Peet','Cameron Diaz','Drew Barrymore', 'Gwyneth Paltrow','Kate Beckinsale','Liv Tyler']). test(4) :- test(4, [N, B, Y], player(N, B, Y), [['Adam Garcia',['Wahroonga','New South Wales'],1973], ['Al Pacino',['South Bronx','New York'],1940], ['Alec Guinness',['London','England'],1914], ['Amanda Peet',['New York','New York'],1972], ['Ben Affleck',['Berkeley','California'],1972], ['Ben Stiller',['New York','New York'],1965], ['Billy Bob Thornton',['Hot Springs','Arkansas'],1955], ['Bruce Willis',['Idar-Oberstein','Germany'],1955], ['Cameron Diaz',['San Diego','California'],1972], ['Cate Blanchett',['Melbourne','Australia'],1969], ['David Arquette',['Winchester','Virginia'],1971], ['Drew Barrymore',['Culver City','California'],1975], ['Gary Oldman',['London','England'],1958], ['Glenn Close',['Greenwich','Connecticut'],1947], ['Gwyneth Paltrow',['Los Angeles','California'],1972], ['Harrison Ford',['Chicago','Illinois'],1942], ['Jack Black',['Hermosa Beach','California'],1969], ['Jason Alexander',['Newark','New Jersey'],1959], ['John Cusack',['Evanston','Illinois'],1966], ['John Leguizamo',['Bogota','Colombia'],1964], ['John Malkovich',['Christopher','Illinois'],1953], ['Jose Ferrer',['Santurce','Peurto Rico'],1909], ['Josh Hartnett',['San Francisco','California'],1978], ['Kate Beckinsale',['London','England'],1973], ['Kris Kristofferson',['Brownsville','Texas'],1936], ['Liv Tyler',['Portland','Maine'],1977], ['Martin Landau',['Brooklyn','NY'],1931], ['Matt Dillon',['New Rochelle','New York'],1964], ['Nicole Kidman',['Honolulu','Hawaii'],1967], ['Steve Zahn',['Marshall','Minnesota'],1968], ['Tom Everett Scott',['East Bridgewater','Massachussets'],1970], ['Zsa Zsa Gabor',['Budapest','Hungary'],1916]]). test(5) :- test(5, L, bornInLondon(L), ['Alec Guinness','Gary Oldman','Kate Beckinsale']). test(6) :- test(6, P, playerAndDirector(P), ['Ben Stiller']). test(7) :- test(7, P, playedAndDirected(P), ['Ben Stiller']). test(8) :- test(8, P, playedMultiple(P), ['Al Pacino','Ben Affleck','Ben Stiller','Billy Bob Thornton', 'Bruce Willis','Cameron Diaz','Cate Blanchett','Drew Barrymore', 'Gary Oldman','Glenn Close','Gwyneth Paltrow','Harrison Ford', 'Jack Black','John Cusack','Kate Beckinsale','Liv Tyler', 'Martin Landau','Matt Dillon','Nicole Kidman','Steve Zahn']). test(9) :- test(9, P, playedInComedy(P), ['Adam Garcia','Amanda Peet','Ben Stiller','Billy Bob Thornton', 'Bruce Willis','Cameron Diaz','Cate Blanchett','David Arquette', 'Drew Barrymore','Gary Oldman','Glenn Close','Gwyneth Paltrow', 'Jack Black','Jason Alexander','John Cusack','John Malkovich', 'Kate Beckinsale', 'Liv Tyler','Matt Dillon','Nicole Kidman','Steve Zahn', 'Tom Everett Scott']). test(10) :- test(10, D, playedNotDirected(D), ['Ben Stiller']). /* test all solutions, by backtracking */ test :- test(_), fail; true. /* * A few Prolog gotcha's to note: * * // is not a comment symbol. It means integer division. * * The two comment forms are: * * slash-star to star-slash * * percent (%) to end-of-line * * Identifiers starting with upper-case are variables, unless they are in * single quotes '...' which may be treated as string quotes. * * Identifiers starting with lower-case are either constants or predicate * names. * * Do not use double quotes "...", as his is a shorthand for the list of * individual characters inside the double quotes. * * Using arithmetic symbols such as +, *, -, / WILL not cause evaluation * unless within the right-hand side of an 'is' expression. */