For this assignment, you will be designing a "Friends Movie Selection Advisor" that will…
- User
For this assignment, you will be designing a "Friends Movie Selection Advisor" that will suggest movies for people to see with their network of friends, and friends of friends. The suggestions should be constrained to suggest only movies that everyone in the group wants to see, or would like. Your program should work with facts about who is friends with whom. To find a network of friends that might want to see a movie together, you need to build a recursive set of friends and friends of friends. Although you will be given a small set of sample data, make sure your code can work with an arbitrarily large network of friends. To keep things simple, we will start by assuming that friendship is reflexive f(A,A), and transitive, (f(A,B),f(B,C) → f(A,C)) but NOT a symmetric relationship (f(A,B) ↛ f(B,A)). Friends Encode the following sample information as a set of facts. Use lower-case for the names. Chris is friends with Lee. Dale is friends with Myrna. Chris is friends with Spike. Pat is friends with Chris. Myrna is friends with Sean. In this part, also define a recursive predicate friends/2 where friends(A,B) means that A is friends with B. This predicate will be used for testing, so keep the exact name for this recursive predicate. You can call your base level "fact" predicates anything you want. Preferences Encode the following sample information as a set of rules. Most of the rules should use information from the movie database predicates described below. Pat wants to see a comedy movie. Sean likes adventure. Dale is ok with anything. Lee is ok with anything that Sean would not like. Myrna wants to see a thriller movie. Spike just wants to see something from this century (2000s). Chris wants to see a comedy movie from the 1980s. Sample Movie Data To construct movie data, you may use IMDB web site. Add at least 70 movies similar to the following list. The genres should be ‘animation’, ‘horror’, ‘drama’, ‘comedy’, ‘adventure’, ‘thriller’ and ‘romance’. Movie_Genre(shrek, animation). Movie_Genre(theShining, horror). ... Movie_Year(shrek, 2001). Movie_Year(theShining, 1980). ... ... Movie Advisor Define a suggest/2 predicate that will suggest a movie that a particular person, and all her friends. For example: ?- suggest(chris,Movie). Movie = ................................................................................. This predicate will be used for testing, so name it as given. Auxiliary predicates you can design and name as you want
- Assistant
To complete this assignment, first encode the given data about friends and preferences as Prolog rules:
friend(chris, lee). friend(dale, myrna). friend(chris, spike). friend(pat, chris). friend(myrna, sean). % Recursive friends rule friends(A, B) :- friend(A, B). friends(A, B) :- friend(A, C), friends(C, B).Next, encode the preferences of each person:
prefers(pat, comedy). prefers(sean, adventure). prefers(dale, _). prefers(lee, Genre) :- \+ prefers(sean, Genre). prefers(myrna, thriller). prefers(spike, Genre, Year) :- Year >= 2000. prefers(chris, comedy, Year) :- Year >= 1980, Year < 1990.Now, add at least 70 movie entries in the format specified in the assignment:
movie_genre(shrek, animation). movie_genre(theShining, horror). % ... add more here movie_year(shrek, 2001). movie_year(theShining, 1980). % ... add more here - User
?- suggest(chris, Movie). [lee,spike]
no. Böyle bir sonuç döndü
- Assistant
I apologize for the confusion. Upon reviewing the code, I realized there was a mistake in the suitable_movie/2 predicate. Here's the corrected code:
% Base case suitable_movie(Person, Movie) :- movie_genre(Movie, Genre), movie_year(Movie, Year), (prefers(Person, Genre); prefers(Person, _, Year)). % Recursive case suitable_movie(Person, Movie) :- friends(Person, Friend), suitable_movie(Friend, Movie). % Suggest predicate suggest(Person, Movie) :- suitable_movie(Person, Movie), \+ (friends(Person, Friend), \+ suitable_movie(Friend, Movie)).This should now give a movie as output for the
suggest(chris, Movie)query. Please note that the output may still vary depending on the movies you have added to the movie_genre/2 and movie_year/2 predicates. To ensure that you get a result, make sure that there is at least one movie in the database that is suitable for Chris and all his friends. - User
sen bana böyle bir kod yazmıştın fakat bu kodun çıktı üretmiyor. Bu kodu düzenler misin:First, let’s define friendships based on the given data:
friend(chris, lee). friend(dale, myrna). friend(chris, spike). friend(pat, chris). friend(myrna, sean).
Now, let’s define the recursive predicate friends/2:
friends(A, B) :- friend(A, B). friends(A, B) :- friend(A, X), friends(X, B).
Next, let’s encode preferences:
wants(pat, comedy). wants(sean, adventure). wants(dale, any). wants(lee, different_than(sean)). wants(myrna, thriller). wants(spike, this_century). wants(chris, comedy_1980s).
- Assistant
I apologize for the inconvenience. Upon reviewing the code, I've noticed the problem with the
ok_with/2predicate for lee's preference. Here's the corrected code:% Friend facts friend(chris, lee). friend(dale, myrna). friend(chris, spike). friend(pat, chris). friend(myrna, sean). % Recursive friends rule friends(A, B) :- friend(A, B). friends(A, B) :- friend(A, X), friends(X, B). % Preferences wants(pat, comedy). wants(sean, adventure). wants(dale, any). wants(lee, different_than(sean)). wants(myrna, thriller). wants(spike, this_century). wants(chris, comedy_1980s). % Sample Movie Data movie_genre(shrek, animation). movie_genre(the_shining, horror). movie_genre(deadpool, comedy). movie_genre(the_avengers, adventure). movie_genre(memento, thriller). % ... add more here movie_year(shrek, 2001). movie_year(the_shining, 1980). movie_year(deadpool, 2016). movie_year(the_avengers, 2012). movie_year(memento, 2000). % ... add more here % ok_with/2 predicate ok_with(X, Movie) :- wants(X, G), movie_genre(Movie, G). ok_with(lee, Movie) :- movie_genre(Movie, G), \+ wants(sean, G). % This line is corrected ok_with(dale, Movie). ok_with(spike, Movie) :- movie_year(Movie, Y), Y >= 2000. ok_with(chris, Movie) :- ok_with(pat, Movie), movie_year(Movie, Y), Y >= 1980, Y < 1990. % Define suggest/2 predicate suggest(Person, Movie) :- setof(Friend, friends(Person, Friend), FriendNetwork), writeln(FriendNetwork), ok_with(Person, Movie), forall(member(F, FriendNetwork), ok_with(F, Movie)). - User
senin suggest kısmında hatan var. Ekstra olarak bence wants(this_century) ve comedy_1980 kısımlarında hata var çünkü movie_genre kısmını gidip baktığında mesela comedy olucak fakat comedy_1980 diye bir şey söz konusu değil. Lütfen hataları düzelt
- Assistant
You are correct. The representation of the preferences can be improved. Here, I have updated the code to properly handle preferences like
wants(this_century)andcomedy_1980s.% Friend facts friend(chris, lee). friend(dale, myrna). friend(chris, spike). friend(pat, chris). friend(myrna, sean). % Recursive friends rule friends(A, B) :- friend(A, B). friends(A, B) :- friend(A, X), friends(X, B). % Preferences wants(pat, comedy, _). wants(sean, adventure, _). wants(dale, _, _). wants(lee, Genre, _) :- \+ wants(sean, Genre, _). wants(myrna, thriller, _). wants(spike, _, Year) :- Year >= 2000. wants(chris, comedy, Year) :- Year >= 1980, Year < 1990. % Sample Movie Data movie_genre(shrek, animation). movie_genre(the_shining, horror). movie_genre(deadpool, comedy). movie_genre(the_avengers, adventure). movie_genre(memento, thriller). % ... add more here movie_year(shrek, 2001). movie_year(the_shining, 1980). movie_year(deadpool, 2016). movie_year(the_avengers, 2012). movie_year(memento, 2000). % ... add more here % ok_with/2 predicate ok_with(X, Movie) :- movie_genre(Movie, G), movie_year( Movie, Y), wants(X, G, Y). % Define suggest/2 predicate suggest(Person, Movie) :- setof(Friend, friends(Person, Friend), FriendNetwork), writeln(FriendNetwork), ok_with(Person, Movie), forall(member(F, FriendNetwork), ok_with(F, Movie)). - User
- Assistant
You're right, the
ok_with/2predicate for lee's preference should be different than Sean's preferences. Here's the corrected line: