%**************************THIS PART CONTAINS FACTS*********************************** % Customer information % customerInfo(UserId, UserName, Address, Phone). customerInfo("C0001", "Duong Doan", "706 Main St.", "444-0484"). customerInfo("C0002", "Christa Wang", "46 Dineen St.", "444-0389"). customerInfo("C0003", "Khaled Slhoub", "567 Waterloo Rd." , "454-1234"). customerInfo("C0004", "Chunying Wang", "321 Regent St.", "454-0203"). customerInfo("C0005", "Sean McDonald", "123 University Rd.", "444-1234"). customerInfo("C0006", "Rebecca Millers", "814 Windsor St.", "455-3890"). customerInfo("C0007", "Erin Taylor", "34 Graham Ave.", "454-2345"). customerInfo("C0008", "Andrew Smith", "567 Albert St.", "454-7890"). customerInfo("C0009", "Bo Cyr", "23 Smyth St.", "455-2456"). customerInfo("C0010", "Jenifer Wilson", "99 York St.", "455-9011"). customerInfo("C0011", "Kevin Joe", "33 Regent St.", "455-9111"). % customerPref(UserId, Language, Genre, Actor[], Actress[], Director[]). customerPref("C0001", "En", "Action", ["Harrison Ford","Owen Wilson"], [], []). customerPref("C0002", "En", "Drama", ["Tom Cruise", "George Clooney"], ["Nicole Kidman", "Julianne Moore"], ["Ang Lee"]). customerPref("C0003", "En", "Documentary", [], [], ["Michael Moore"]). customerPref("C0004", "Fr", "Comedy", ["Owen Wilson"], ["Gwyneth Paltrow"], ["David Dobkin","Steven Soderbergh"]). customerPref("C0005", "Fr", "Romantic", ["Owen Wilson"], ["Gwyneth Paltrow"], ["David Dobkin","Steven Soderbergh"]). customerPref("C0006", "En", "Series", ["Kiefer Sutherland"], ["Sarah Clarke,Teri Hatcher"], ["Richard Lewis", "Duane Clark"]). customerPref("C0007", "Fr", "Cartoon", [], [], ["Steve Box", "Nick Park"]). customerPref("C0008", "En", "Action", ["Brad Pitt", "Matt Damon"], ["Andy Garcia", "Julia Robert"], ["Steven Soderbergh", "Steven Spielberg"]). customerPref("C0009", "Fr", "Drama", ["Denzel Washington"], ["Meg Ryan"], ["Charles S. Dutton"]). customerPref("C0010", "En", "Biography", ["Jamie Faxx"], ["Kerry Washington"], []). customerPref("C0011", "En", "Series", ["Kiefer Sutherland"], ["Julia Roberts","Sandra Bullock"], ["Richard Lewis", "Duane Clark"]). %Movie Information % movieInfo(MovieId, MovieName, Genre, Actor, Actress, Director, Language, New/Old, TotalCopies, Price, Duration). movieInfo("M0001", "Crash", "Drama", "Don Cheadle", "Sandra Bullock", "Paul Haggis", "En", "New", 10, 4.99, "2 nights"). movieInfo("M0002", "Wedding Crash", "Comedy", "Owen Wilson", "Rachel McAdams", "David Dobkin", "En", "Old", 10, 4.99, "7 night"). movieInfo("M0003","Oceans Eleven", "Action", "George Clooney","Julia Roberts","Steven Soderbergh","En","New",10, 6.6,"2 nights"). movieInfo("M0004", "Fahrenheit 9/11", "Documentary", "", "", "Michael Moore", "En", "Old", 10, 4.5, "7 nights"). movieInfo("M0005", "Proof", "Action", "Anthony Hopkin", "Gwyneth Paltrow", "John Madden", "En", "New", 10, 3.7, "2 nights"). movieInfo("M0006", "We Were Soldiers", "Drama", "Mel Gibson", "Medeleine Stowe", "Randall Wallace", "En", "Old", 10, 3.5, "7 nights"). movieInfo("M0007", "For All Eternity", "Romance", "Nina Proll", "Zhiwen Wang", "Hei Hu", "Gr", "Old", 10, 4.5, "7 nights"). movieInfo("M0008", "Return of the Living Dead: Necropolis", "Ghost", "Aimee Chadwick", "Cory Hardrict", "Ellory Elkayem", "En", "New", 10, 3.5, "2 nights"). movieInfo("M0009", "Big Momma's House 2", "Comedy", "Martin Lawernce", "Elton LeBlane", "John Whitesell", "En", "New", 10, 4.00, "2 nights"). movieInfo("M0010", "The Backyardigans: Cave Party", "Cartoon", "Jonah Bobo", "Sean Curley", "Janice Burgess", "En", "New", 10, 3.00, "2 nights"). MovieInfo("M0011", "Good night and good luck", "Drama","George Clooney", "Patricia Clarkson", "George Clooney", "En", "New", 10, 6.6, "2 nights"). %Movie Taxonomy subclassOf("Movies","Documentary"). subclassOf("Documentary","Biograhphy"). subclassOf("Documentary","History"). subclassOf("Movies","Fiction"). subclassOf("Fiction","Drama"). subclassOf("Fiction","Action"). subclassOf("Fiction","Comedy"). subclassOf("Fiction","Series"). subclassOf("Fiction","Romantic"). subclassOf("Fiction","Ghost"). subclassOf("Movies","Cartoon"). %Movie Status % movieStatus(MovieId, AvailableCopies). movieStatus("M0001",5). movieStatus("M0002",8). movieStatus("M0003",0). movieStatus("M0004",4). movieStatus("M0005",3). movieStatus("M0006", 0). movieStatus("M0007", 1). movieStatus("M0008", 2). movieStatus("M0009", 3). movieStatus("M0010", 6). movieStatus("M0011", 10). %Customer Record %customerRecord(UserId, MovieId, CheckOutTime, DueTime, Monthly-Rent). customerRecord("C0001", "M0004", "20060401", "20060408", 10). customerRecord("C0002", "M0005", "20060405", "20060407", 15). customerRecord("C0003", "M0003", "20060403", "20060405", 5). customerRecord("C0004", "M0005", "20060405", "20060407", 8). customerRecord("C0005", "M0010", "20060405", "20060407", 3). customerRecord("C0006", "M0006", "20060403", "20060410", 10). customerRecord("C0007", "M0007", "20060401", "20060408", 3). customerRecord("C0008", "M0008", "20060404", "20060406", 7). customerRecord("C0009", "M0005", "20060410", "20060417", 15). customerRecord("C0010", "M0005", "20060401", "20060405", 10). customerRecord("C0011", "M0011", "20060405", "20060407", 15). %********************************END OF FACTS************************************ %**************************THIS PART DO SEARCH********************************** % (1) Movie Title Search %movieInfo(X1, "Crash", X2, X3, X4, X5, X6, X7, X8, X9, X10) % (2) Query search based on customers preferences % required the movie is not available %movieInfo(X1,"Oceans eleven", X2, X3, X4, X5, X6, X7, X8, X9, X10) % Search customer preferences % returns customer preferences in terms of Language, Genre, Actor, Actress, Director %customerPref("C0001", Language, Genre, Actor, Actress, Director) %Results when executed by Relfun is as follows: %rfi-p> customerPref("C0001", Language, Genre, Action, Actress, Director) %true %Language="En" %Genre="Action" %Actor="Harrison Ford" %Actress="" %Director="" % Query Search for recommended movie % returns recommended movies based on customers’ preferences % returns movie information: price, available copies, price, and duration for further % processing %movieInfo(MovieId, MovieName, "Action", Actor, Actress, Director, New, TotalCopies, Price, Duration). %Results when executed by Relfun is as follows: %rfi-p> movieInfo(MovieId, MovieName, "Action", Actor, Actress, Director, New, TotalCopies, Price, Duration) %true %Movieid="M0003" %Moviename="Ocean’s eleven" %Actor="George Clooney" %Actress="Julia Roberts" %Director="Steven Soderbergh" %New="En" %Totalcopies="New" %Price=0 %Duration="2 nights" % if there is nothing returned, we will do query search based on preferred actor, actress, and director %**************************END OF DO SIMPLE SEARCH********************************** % Check customer record for monthly rent information %customerRecord("C0001", MovieId, CheckOutTime, DueTime, MonthlyRent) %Results when executed by Relfun is as follows: %rfi-p> customerRecord("C0001", MovieId, CheckOutTime, DueTime, MonthlyRent) %true %Movieid="M0004" %Checkouttime="20060311" %Duetime="20060318" %Monthly-rent=10 %******************************************THIS PART DO PRICE DETERMINATION****************************** % Check movie status checkAvailableMovie (MovieId) :- movieStatus(MovieId, AvailableCopies) & AvailableCopies. % Check Monthly-Rent for user checkMonthlyRent(UserID) :- customerRecord(UserId, MovieId, CheckOutTime, DueTime, Monthly-Rent) & Monthly-Rent. % ******************************this customer is not overdue, his monthly-rent is 10.******************** %Rules % (3) price determination % (a) Award customer: if the monthly-rent is greater than or equal to 10, then he/she will % receive 20% discount; otherwise, he/she will get the regular price price(UserId) :- customerRecord(UserId, MovieId, CheckOutTime, DueTime, MonthlyRent), >=(MonthlyRent,10), movieInfo(MovieId, MovieName, Genre, Actor, Actress, Director, Language, New, TotalCopies, Price, Duration) & FinalPrice .= *(0.8,Price). price(UserId) :- customerRecord(UserId, MovieId, CheckOutTime, DueTime, MonthlyRent), <(MonthlyRent,10), movieInfo(MovieId, MovieName, Genre, Actor, Actress, Director, Language, New, TotalCopies, Price, Duration) & FinalPrice .= Price. % (b) Penalized customer: if the Duetime is expired, then he/she will receive double price % for this new rent. price(UserId, Today) :- customerRecord(UserId, MovieId, CheckOutTime, DueTime, MonthlyRent), string<=(DueTime,Today), movieInfo(MovieId, MovieName, Genre, Actor, Actress, Director, Language, New, TotalCopies, Price, Duration)& FinalPrice .= *(2,Price). price(UserId, Today) :- customerRecord(UserId, MovieId, CheckOutTime, DueTime, MonthlyRent), string>(DueTime,Today), movieInfo(MovieId, MovieName, Genre, Actor, Actress, Director, Language, New, TotalCopies, Price, Duration)& FinalPrice .=Price. %(c) Regular price: if the customer’s monthly-rent is greater than or equal to 10, then % he/she is supposed to get award; however, he/she might hold a movie which is % overdue, then he/she might get the regular price. price(UserId,Today,NewMovieId):-customerRecord(UserId,MovieId, CheckOutTime,DueTime,MonthlyRent),>=(MonthlyRent,10),string<=(DueTime,Today),movieInfo(NewMovieId,MovieName,Genre,Actor,Actress,Director,Language,New,TotalCopies,Price,Duration)&FinalPrice.=Price. % (4) After checking out, updating Customer Record % updating Movie information in terms of AvailableCopies % We suppose there is an operator who will do the update manually %rx customerRecord("C0001", "M0004", "20060311", "20060318", 10). %az customerRecord("C0001", "M0001", "20060315", "20060317", 11). %rx movieStatus("M0001", 5). %az movieStatus("M0001", 4). %******************************************END OF PRICE DETERMINATION****************************** %*********************************Search for movies based on many criteria ***************************** % Search based on three criteria (Genre="Action",Language="En",New/Old="New") %movieInfo(MovieId, MovieName, "Action", Actor, Actress, Director, "En", "New", TotalCopies, Price, Duration) % End of search for movies based on many criteria %Recomendation based on prefered Actor, Actress and Director %Recomend based on prefered Actor recomendbasedactor(UserID) :- customerPref(UserID, Language, Genre, Actor, Actress, Director), movieInfo(MovieId, MovieName, Genre1, MainActor, Actress1, Director1, Language1, New/Old, TotalCopies, Price, Duration),exist(MainActor,Actor) & MovieId. % Results when executed in Relfun %rfi-p> recomendbasedactor("C0001") %"M0002" %Recomend based on prefered Actress recomendbasedActress(UserID) :- customerPref(UserID, Language, Genre, Actor, Actress, Director), movieInfo(MovieId, MovieName, Genre1, MainActor, Actress1, Director1, Language1, New/Old, TotalCopies, Price, Duration),exist(Actress1,Actress) & MovieId. % Results when executed in Relfun %rfi-p> recomendbasedActress(UserID) %"M0005" %Userid="C0004" %Recomend based on prefered Director recomendbasedDirector(UserID) :- customerPref(UserID, Language, Genre, Actor, Actress, Director), movieInfo(MovieId, MovieName, Genre1, MainActor, Actress1, Director1, Language1, New/Old, TotalCopies, Price, Duration),exist(Director1,Director) & MovieId. % Results when executed in Relfun %rfi-p> recomendbasedDirector(UserID) %"M0004" %Userid="C0003" %Check if an element belong to a list exist(E,[]) :& false. exist(E,[E|T]) :& true. exist(E,[H|T]) :& exist(E,T). %End of recomendation based on prefered Actor, Actress and Director %Recomendation based on prefered Genre % Applying the cut operator to remove nondeterministic problem. % Only recomend a specific Genre at a time recomendbasedGenre(UserID) :- customerPref(UserID, Language, Genre, Actor, Actress, Director), movieInfo(MovieId, MovieName, Genre1, MainActor, Actress1, Director1, Language1, New/Old, TotalCopies, Price,Duration), relatedGenre(Genre1,Genre) ! & MovieId. relatedGenre(Genre1,Genre) :- subclassOf(CommonGenre,Genre), subclassOf(CommonGenre,Genre1),string/=(Genre1,Genre).