├── Build a Recemmendation System.pdf ├── README.md ├── Recommendation System Assignment.pdf ├── StepFive-Final ├── AllFilters.java ├── DirectorsFilter.java ├── EfficientRater.java ├── Filter.java ├── FirstRatings.java ├── FourthRatings.java ├── FourthRatingsOptimizedByWeiXu.java ├── GenreFilter.java ├── MinutesFilter.java ├── Movie.java ├── MovieDatabase.java ├── MovieRunnerAverage.java ├── MovieRunnerSimilarRatings.java ├── MovieRunnerSimilarRatingsOptimizedByWeiXu.java ├── MovieRunnerWithFilters.java ├── PlainRater.java ├── Rater.java ├── RaterDatabase.java ├── Rating.java ├── RecommendationRunner.java ├── Recommender.java ├── SecondRatings.java ├── StepFive-Final.iml ├── StepFour-Weighted Averages.iml ├── StepOneStarterProgram.iml ├── StepThree-Interfaces, Filters, Database.iml ├── StepTwo-Simple Recommendations.iml ├── ThirdRatings.java ├── TrueFilter.java ├── YearAfterFilter.java ├── data │ ├── ratedmovies_short.csv │ ├── ratedmoviesfull.csv │ ├── ratings.csv │ └── ratings_short.csv ├── out │ └── production │ │ └── StepFive-Final │ │ ├── Archive.zip │ │ ├── EfficientRater.class │ │ ├── Filter.class │ │ ├── FirstRatings.class │ │ ├── FourthRatingsOptimizedByWeiXu.class │ │ ├── Movie.class │ │ ├── MovieDatabase.class │ │ ├── MovieRunnerSimilarRatingsOptimizedByWeiXu.class │ │ ├── Rater.class │ │ ├── RaterDatabase.class │ │ ├── Rating.class │ │ ├── RecommendationRunner.class │ │ ├── Recommender.class │ │ ├── StepFive-Final.iml │ │ ├── StepFour-Weighted Averages.iml │ │ ├── StepOneStarterProgram.iml │ │ ├── StepThree-Interfaces, Filters, Database.iml │ │ ├── StepTwo-Simple Recommendations.iml │ │ ├── TrueFilter.class │ │ ├── data │ │ ├── ratedmovies_short.csv │ │ ├── ratedmoviesfull.csv │ │ ├── ratings.csv │ │ └── ratings_short.csv │ │ └── output.png └── output.png ├── StepFour-Weighted Averages ├── AllFilters.java ├── DUKE Algorithm Output.png ├── DirectorsFilter.java ├── EfficientRater.java ├── Filter.java ├── FirstRatings.java ├── FourthRatings.java ├── FourthRatingsOptimizedByWeiXu.java ├── GenreFilter.java ├── MinutesFilter.java ├── Movie.java ├── MovieDatabase.java ├── MovieRunnerAverage.java ├── MovieRunnerSimilarRatings.java ├── MovieRunnerSimilarRatingsOptimizedByWeiXu.java ├── MovieRunnerWithFilters.java ├── PlainRater.java ├── Rater.java ├── RaterDatabase.java ├── Rating.java ├── SecondRatings.java ├── StepFour-Weighted Averages.iml ├── StepOneStarterProgram.iml ├── StepThree-Interfaces, Filters, Database.iml ├── StepTwo-Simple Recommendations.iml ├── ThirdRatings.java ├── TrueFilter.java ├── Wei Xu Algorithm Output.png ├── YearAfterFilter.java ├── data │ ├── ratedmovies_short.csv │ ├── ratedmoviesfull.csv │ ├── ratings.csv │ └── ratings_short.csv └── out │ └── production │ └── StepFour-Weighted Averages │ ├── AllFilters.class │ ├── DirectorsFilter.class │ ├── EfficientRater.class │ ├── Filter.class │ ├── FirstRatings.class │ ├── FourthRatings.class │ ├── GenreFilter.class │ ├── MinutesFilter.class │ ├── Movie.class │ ├── MovieDatabase.class │ ├── MovieRunnerAverage.class │ ├── MovieRunnerSimilarRatings.class │ ├── MovieRunnerWithFilters.class │ ├── Rater.class │ ├── RaterDatabase.class │ ├── Rating.class │ ├── SecondRatings.class │ ├── StepFour-Weighted Averages.iml │ ├── StepOneStarterProgram.iml │ ├── StepThree-Interfaces, Filters, Database.iml │ ├── StepTwo-Simple Recommendations.iml │ ├── ThirdRatings.class │ ├── TrueFilter.class │ └── YearAfterFilter.class ├── StepOneStarterProgram ├── FirstRatings.java ├── Movie.java ├── Rater.java ├── Rating.java ├── StepOneStarterProgram.iml ├── data │ ├── ratedmovies_short.csv │ ├── ratedmoviesfull.csv │ ├── ratings.csv │ └── ratings_short.csv └── out │ └── production │ └── StepOneStarterProgram │ ├── FirstRatings.class │ ├── Movie.class │ ├── Rater.class │ ├── Rating.class │ ├── StepOneStarterProgram.iml │ └── data │ ├── ratedmovies_short.csv │ ├── ratedmoviesfull.csv │ ├── ratings.csv │ └── ratings_short.csv ├── StepThree-Interfaces, Filters, Database ├── AllFilters.java ├── DirectorsFilter.java ├── EfficientRater.java ├── Filter.java ├── FirstRatings.java ├── GenreFilter.java ├── MinutesFilter.java ├── Movie.java ├── MovieDatabase.java ├── MovieRunnerAverage.java ├── MovieRunnerWithFilters.java ├── PlainRater.java ├── Rater.java ├── Rating.java ├── SecondRatings.java ├── StepOneStarterProgram.iml ├── StepThree-Interfaces, Filters, Database.iml ├── StepTwo-Simple Recommendations.iml ├── ThirdRatings.java ├── TrueFilter.java ├── YearAfterFilter.java ├── data │ ├── ratedmovies_short.csv │ ├── ratedmoviesfull.csv │ ├── ratings.csv │ └── ratings_short.csv ├── out │ └── production │ │ ├── StepOneStarterProgram │ │ ├── FirstRatings.class │ │ ├── Movie.class │ │ ├── MovieRunnerAverage.class │ │ ├── Rater.class │ │ ├── Rating.class │ │ ├── SecondRatings.class │ │ ├── StepOneStarterProgram.iml │ │ └── data │ │ │ ├── ratedmovies_short.csv │ │ │ ├── ratedmoviesfull.csv │ │ │ ├── ratings.csv │ │ │ └── ratings_short.csv │ │ ├── StepThree-Interfaces, Filters, Database │ │ ├── AllFilters.class │ │ ├── DirectorsFilter.class │ │ ├── EfficientRater.class │ │ ├── Filter.class │ │ ├── FirstRatings.class │ │ ├── GenreFilter.class │ │ ├── MinutesFilter.class │ │ ├── Movie.class │ │ ├── MovieDatabase.class │ │ ├── MovieRunnerAverage.class │ │ ├── MovieRunnerWithFilters.class │ │ ├── PlainRater.class │ │ ├── Rater.class │ │ ├── Rating.class │ │ ├── SecondRatings.class │ │ ├── StepOneStarterProgram.iml │ │ ├── StepThree-Interfaces, Filters, Database.iml │ │ ├── StepTwo-Simple Recommendations.iml │ │ ├── ThirdRatings.class │ │ ├── TrueFilter.class │ │ ├── YearAfterFilter.class │ │ ├── data │ │ │ ├── ratedmovies_short.csv │ │ │ ├── ratedmoviesfull.csv │ │ │ ├── ratings.csv │ │ │ └── ratings_short.csv │ │ └── output1.png │ │ └── StepTwo-Simple Recommendations │ │ ├── FirstRatings.class │ │ ├── Movie.class │ │ ├── MovieRunnerAverage.class │ │ ├── Rater.class │ │ ├── Rating.class │ │ ├── SecondRatings.class │ │ ├── StepOneStarterProgram.iml │ │ ├── StepTwo-Simple Recommendations.iml │ │ └── data │ │ ├── ratedmovies_short.csv │ │ ├── ratedmoviesfull.csv │ │ ├── ratings.csv │ │ └── ratings_short.csv ├── output1.png ├── output2.png └── output3.png └── StepTwo-Simple Recommendations ├── FirstRatings.java ├── Movie.java ├── MovieRunnerAverage.java ├── Rater.java ├── Rating.java ├── SecondRatings.java ├── StepOneStarterProgram.iml ├── StepTwo-Simple Recommendations.iml ├── data ├── ratedmovies_short.csv ├── ratedmoviesfull.csv ├── ratings.csv └── ratings_short.csv ├── out └── production │ ├── StepOneStarterProgram │ ├── FirstRatings.class │ ├── Movie.class │ ├── MovieRunnerAverage.class │ ├── Rater.class │ ├── Rating.class │ ├── SecondRatings.class │ ├── StepOneStarterProgram.iml │ └── data │ │ ├── ratedmovies_short.csv │ │ ├── ratedmoviesfull.csv │ │ ├── ratings.csv │ │ └── ratings_short.csv │ └── StepTwo-Simple Recommendations │ ├── FirstRatings.class │ ├── Movie.class │ ├── MovieRunnerAverage.class │ ├── Rater.class │ ├── Rating.class │ ├── SecondRatings.class │ ├── StepOneStarterProgram.iml │ ├── StepTwo-Simple Recommendations.iml │ └── data │ ├── ratedmovies_short.csv │ ├── ratedmoviesfull.csv │ ├── ratings.csv │ └── ratings_short.csv └── output.png /Build a Recemmendation System.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/Build a Recemmendation System.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Java Programming:A DIY Version of Netflix And Amazon Recommendation Engines 2 | Learn without enrollment! I searched almost the online resources and finally made it. I tried to find if there are open resources on other website. I tried to get the video and assignment link from the Coursera inspect. I tried to connect several users’ LinkedIn who uploaded their code on Github. God bless, finally, thanks for a user who uploaded all assignment instructions on his Github. I’ve already collect almost all the material and write in a pdf file and will share it here. Hope that may help you. 3 | 4 | ### Run this project [HERE](http://www.dukelearntoprogram.com/capstone/recommender.php?id=doM6ILtR7zHlFA)! 5 | ### An Example of Input and Output: 6 | Screen Shot 2019-12-16 at 7 31 36 PM 7 | output 8 | 9 | The rank and rating of the recommendation are based on the raters who have similar ratings with you, which means you two may have the same preferences for movies. 10 | The calculation is based on the weighted average from the top similar raters: 11 | 12 | #### The closer to your rating, the greater their rating weight 13 |
14 | In this way, you will receive more accurate recommendation because we've already ignored those people have different preferences that may result in bias.

15 | 16 | 17 | ### More: 18 | This is a Capstone project, which is the last Course ([Java Programming: Build a Recommendation System](https://www.coursera.org/learn/java-programming-design-principles?specialization=java-programming)) of the
19 | [Java Programming and Software Engineering Fundamentals Specialization](https://www.coursera.org/specializations/java-programming) that designed by Duke University. 20 | 21 | ### Thank you Duke, I have learned a lot from this specialization. Strongly recommend to beginners. 22 | -------------------------------------------------------------------------------- /Recommendation System Assignment.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/Recommendation System Assignment.pdf -------------------------------------------------------------------------------- /StepFive-Final/AllFilters.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 12th, 2019 7 | * 8 | * Description: -------------------STEP THREE------------------------- 9 | * Now use the AllFilters class to combine asking questions 10 | * about average ratings by genre and films on or after a 11 | * particular year. 12 | * 13 | ****************************************************************/ 14 | 15 | public class AllFilters implements Filter { 16 | ArrayList filters; 17 | 18 | public AllFilters() { 19 | filters = new ArrayList(); 20 | } 21 | 22 | public void addFilter(Filter f) { 23 | filters.add(f); 24 | } 25 | 26 | @Override 27 | public boolean satisfies(String id) { 28 | for (Filter f : filters) { 29 | if (!f.satisfies(id)) { 30 | return false; 31 | } 32 | } 33 | return true; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /StepFive-Final/DirectorsFilter.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 12th, 2019 5 | * 6 | * Description: -------------------STEP THREE------------------------- 7 | * Create a new class named DirectorsFilter that implements Filter. 8 | * The constructor should have one parameter named directors 9 | * representing a list of directors separated by commas. 10 | * 11 | * (Example: "Charles Chaplin,Michael Mann,Spike Jonze", 12 | * and its satisfies method should return true if a movie has 13 | * at least one of these directors as one of its directors. 14 | * Note that each movie may have several directors. 15 | * 16 | ****************************************************************/ 17 | public class DirectorsFilter implements Filter { 18 | private String directors; 19 | 20 | public DirectorsFilter(String directors) { 21 | this.directors = directors; 22 | } 23 | 24 | @Override 25 | public boolean satisfies(String id) { 26 | String[] dir = directors.split(","); 27 | //boolean exist = false; 28 | for (String i : dir) { 29 | //System.out.println(id + " : " + MovieDatabase.getDirector(id) + " : " + MovieDatabase.getTitle(id)); 30 | if (MovieDatabase.getDirector(id).contains(i)) { 31 | return true; 32 | //break; 33 | } 34 | } 35 | return false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /StepFive-Final/EfficientRater.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.HashMap; 3 | 4 | /*************************************************************************** 5 | * Name: Wei Xu 6 | * 7 | * Date: Dec 12th, 2019 8 | * 9 | * Description: -------------------STEP Three---------------------------- 10 | * Create a new class named EfficientRater, and copy the 11 | * PlainRater class into this class. You will make several 12 | * changes to this class, including: 13 | * 14 | * Change the ArrayList of type Rating private variable to a 15 | * HashMap. The key in the HashMap is a movie ID, 16 | * and its value is a rating associated with this movie. 17 | * You will need to change addRating to instead add a new Rating 18 | * to the HashMap with the value associated with the movie ID 19 | * String item as the key in the HashMap. The method hasRating 20 | * should now be much shorter; it no longer needs a loop. 21 | * More method need change....... 22 | * 23 | ***************************************************************************/ 24 | public class EfficientRater implements Rater { 25 | private String myID; 26 | /* Change the ArrayList of type Rating private variable to a HashMap. 27 | The key in the HashMap is a movie ID, and 28 | its value is a rating associated with this movie.*/ 29 | //private HashMap> myRatings;//why not this one? 30 | private HashMap myRatings; 31 | 32 | public EfficientRater(String id) { 33 | myID = id; 34 | myRatings = new HashMap<>(); 35 | } 36 | 37 | public void addRating(String item, double rating) { 38 | myRatings.put(item, new Rating(item, rating));//item is string id? 39 | } 40 | 41 | public boolean hasRating(String item) { 42 | return myRatings.containsKey(item); 43 | } 44 | 45 | public String getID() { 46 | return myID; 47 | } 48 | 49 | public double getRating(String item) { 50 | // for (int k = 0; k < myRatings.size(); k++) { 51 | // if (myRatings.get(k).getItem().equals(item)) { 52 | // return myRatings.get(k).getValue(); 53 | // } 54 | // } 55 | if (myRatings.containsKey(item)) { 56 | return myRatings.get(item).getValue(); 57 | } 58 | return -1; 59 | } 60 | 61 | public int numRatings() { 62 | return myRatings.size(); 63 | } 64 | 65 | public ArrayList getItemsRated() { 66 | ArrayList list = new ArrayList<>(myRatings.keySet()); 67 | // for (int k = 0; k < myRatings.size(); k++) { 68 | // list.add(myRatings.get(k).getItem()); 69 | // } 70 | // 71 | return list;//arrayList of item; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /StepFive-Final/Filter.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 12th, 2019 5 | * 6 | * Description: -------------------STEP THREE-------- 7 | * The interface Filter has only one signature for 8 | * the method satisfies. Any filters that implement 9 | * this interface must also have this method. 10 | * The method satisfies has one String parameter 11 | * named id representing a movie ID. This method returns 12 | * true if the movie satisfies the criteria in the method 13 | * and returns false otherwise. 14 | * 15 | ****************************************************************/ 16 | 17 | public interface Filter { 18 | public boolean satisfies(String id); 19 | } 20 | -------------------------------------------------------------------------------- /StepFive-Final/GenreFilter.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 12th, 2019 5 | * 6 | * Description: -------------------STEP THREE------------------------- 7 | * Create a new class named GenreFilter that implements Filter. 8 | * The constructor should have one parameter named genre 9 | * representing one genre, and the satisfies method should 10 | * return true if a movie has this genre. Note that movies 11 | * may have several genres. 12 | * 13 | ****************************************************************/ 14 | 15 | public class GenreFilter implements Filter { 16 | private String genre; 17 | 18 | public GenreFilter(String genre) { 19 | this.genre = genre; 20 | } 21 | 22 | @Override 23 | public boolean satisfies(String id) { 24 | return MovieDatabase.getGenres(id).contains(genre); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /StepFive-Final/MinutesFilter.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 12th, 2019 5 | * 6 | * Description: -------------------STEP THREE------------------------- 7 | * Create a new class named MinutesFilter that implements Filter. 8 | * Its satisfies method should return true if a movie’s running time 9 | * is at least min minutes and no more than max minutes. 10 | * 11 | ****************************************************************/ 12 | public class MinutesFilter implements Filter { 13 | private int min; 14 | private int max; 15 | 16 | 17 | public MinutesFilter(int min, int max) { 18 | this.min = min; 19 | this.max = max; 20 | } 21 | 22 | @Override 23 | public boolean satisfies(String id) { 24 | return MovieDatabase.getMinutes(id) >= min && MovieDatabase.getMinutes(id) <= max; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /StepFive-Final/Movie.java: -------------------------------------------------------------------------------- 1 | //Plain Old Java Object (POJO) class for storing the data about one movie 2 | // An immutable passive data object (PDO) to represent item data 3 | public class Movie { 4 | private String id; 5 | private String title; 6 | private int year; 7 | private String genres; 8 | private String director; 9 | private String country; 10 | private String poster; 11 | private int minutes; 12 | 13 | public Movie(String anID, String aTitle, String aYear, String theGenres) { 14 | // just in case data file contains extra whitespace 15 | id = anID.trim(); 16 | title = aTitle.trim(); 17 | year = Integer.parseInt(aYear.trim()); 18 | genres = theGenres; 19 | } 20 | 21 | public Movie(String anID, String aTitle, String aYear, String theGenres, String aDirector, 22 | String aCountry, String aPoster, int theMinutes) { 23 | // just in case data file contains extra whitespace 24 | id = anID.trim(); 25 | title = aTitle.trim(); 26 | year = Integer.parseInt(aYear.trim()); 27 | genres = theGenres; 28 | director = aDirector; 29 | country = aCountry; 30 | poster = aPoster; 31 | minutes = theMinutes; 32 | } 33 | 34 | // Returns ID associated with this item 35 | public String getID() { 36 | return id; 37 | } 38 | 39 | // Returns title of this item 40 | public String getTitle() { 41 | return title; 42 | } 43 | 44 | // Returns year in which this item was published 45 | public int getYear() { 46 | return year; 47 | } 48 | 49 | // Returns genres associated with this item 50 | public String getGenres() { 51 | return genres; 52 | } 53 | 54 | public String getCountry() { 55 | return country; 56 | } 57 | 58 | public String getDirector() { 59 | return director; 60 | } 61 | 62 | public String getPoster() { 63 | return poster; 64 | } 65 | 66 | public int getMinutes() { 67 | return minutes; 68 | } 69 | 70 | // Returns a string of the item's information 71 | public String toString() { 72 | String result = "Movie [id=" + id + ", title=" + title + ", year=" + year; 73 | result += ", genres= " + genres + "]"; 74 | return result; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /StepFive-Final/MovieDatabase.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.HashMap; 3 | 4 | /*************************************************************** 5 | * Name: Wei Xu 6 | * 7 | * Date: Dec 12th, 2019 8 | * 9 | * Description: -------------------STEP THREE-------- 10 | * The class MovieDatabase—This class is an efficient way to get 11 | * information about movies. It stores movie information in a HashMap 12 | * for fast lookup of movie information given a movie ID. 13 | * The class also allows filtering movies based on queries. All methods 14 | * and fields in the class are static. 15 | * This means you'll be able to access methods in MovieDatabase 16 | * without using new to create objects, but by calling methods like 17 | * MovieDatabase.getMovie("0120915"). 18 | * 19 | ****************************************************************/ 20 | public class MovieDatabase { 21 | private static HashMap ourMovies; 22 | //before it's an Arraylist 23 | 24 | public static void initialize(String moviefile) { 25 | if (ourMovies == null) { 26 | ourMovies = new HashMap(); 27 | loadMovies("data/" + moviefile); 28 | } 29 | } 30 | 31 | private static void initialize() { 32 | if (ourMovies == null) { 33 | ourMovies = new HashMap(); 34 | loadMovies("data/ratedmoviesfull.csv"); 35 | } 36 | } 37 | 38 | private static void loadMovies(String filename) { 39 | FirstRatings fr = new FirstRatings(); 40 | ArrayList list = fr.loadMovies(filename); 41 | for (Movie m : list) { 42 | ourMovies.put(m.getID(), m); 43 | } 44 | } 45 | 46 | public static boolean containsID(String id) { 47 | initialize(); 48 | return ourMovies.containsKey(id); 49 | } 50 | 51 | public static int getYear(String id) { 52 | initialize(); 53 | return ourMovies.get(id).getYear(); 54 | } 55 | 56 | public static String getGenres(String id) { 57 | initialize(); 58 | return ourMovies.get(id).getGenres(); 59 | } 60 | 61 | public static String getTitle(String id) { 62 | initialize(); 63 | return ourMovies.get(id).getTitle(); 64 | } 65 | 66 | public static Movie getMovie(String id) { 67 | initialize(); 68 | return ourMovies.get(id); 69 | } 70 | 71 | public static String getPoster(String id) { 72 | initialize(); 73 | return ourMovies.get(id).getPoster(); 74 | } 75 | 76 | public static int getMinutes(String id) { 77 | initialize(); 78 | return ourMovies.get(id).getMinutes(); 79 | } 80 | 81 | public static String getCountry(String id) { 82 | initialize(); 83 | return ourMovies.get(id).getCountry(); 84 | } 85 | 86 | public static String getDirector(String id) { 87 | initialize(); 88 | return ourMovies.get(id).getDirector(); 89 | } 90 | 91 | public static int size() { 92 | return ourMovies.size(); 93 | } 94 | 95 | // why no need implement filter? 96 | public static ArrayList filterBy(Filter f) { 97 | initialize(); 98 | ArrayList list = new ArrayList(); 99 | for (String id : ourMovies.keySet()) { 100 | if (f.satisfies(id)) { 101 | list.add(id); 102 | } 103 | } 104 | return list;//ArrayList of movie id 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /StepFive-Final/MovieRunnerAverage.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collections; 3 | 4 | /*************************************************************** 5 | * Name: Wei Xu 6 | * 7 | * Date: Dec 11th, 2019 8 | * 9 | * Description: -------------------STEP TWO------------------------- 10 | * You will build on this assignment by calculating 11 | * average ratings of movies. 12 | * In this assignment you will modify a new class named SecondRatings, 13 | * which has been started for you, to do many of the calculations 14 | * focusing on computing averages on movie ratings. 15 | * You will also create a second new class named MovieRunnerAverage, 16 | * which you will use to test the methods you created in SecondRatings 17 | * by creating a SecondRatings object in MovieRunnerAverage and 18 | * calling its methods. 19 | * 20 | ****************************************************************/ 21 | public class MovieRunnerAverage { 22 | public void printAverageRatings() { 23 | SecondRatings sr = new SecondRatings("data/ratedmovies_short.csv", "data/ratings_short.csv");//do i need put filename here? 24 | System.out.println("Movie size = " + sr.getMovieSize()); 25 | System.out.println("Rater size = " + sr.getRaterSize()); 26 | ArrayList ratingList = sr.getAverageRatings(2); 27 | Collections.sort(ratingList); 28 | for (Rating i : ratingList) { 29 | System.out.printf("%-10.2f%s%n", i.getValue(), sr.getTitle(i.getItem())); 30 | } 31 | } 32 | 33 | public void getAverageRatingOneMovie() { 34 | SecondRatings sr = new SecondRatings("data/ratedmovies_short.csv", "data/ratings_short.csv");//do i need put filename here? 35 | ArrayList ratingList = sr.getAverageRatings(2); 36 | String movieTitle = "The Godfather"; 37 | for (Rating i : ratingList) { 38 | if (sr.getTitle(i.getItem()).equals(movieTitle)) { 39 | System.out.printf("%-10.2f%s%n", i.getValue(), sr.getTitle(i.getItem())); 40 | } 41 | } 42 | } 43 | 44 | public static void main(String[] args) { 45 | MovieRunnerAverage mra = new MovieRunnerAverage(); 46 | System.out.println("---------------print test----------------"); 47 | mra.printAverageRatings(); 48 | System.out.println("---------------get average rating one movie test----------------"); 49 | mra.getAverageRatingOneMovie(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /StepFive-Final/PlainRater.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 12th, 2019 7 | * 8 | * Description: -------------------STEP Three-------- 9 | * Change the name of the class Rater.java to PlainRater.java. 10 | * Be sure to compile it to make sure your newly named class 11 | * works—that you've made the changes necessary for the class 12 | * to function with the name PlainRater. 13 | * 14 | ***************************************************************************/ 15 | public class PlainRater implements Rater { 16 | private String myID; 17 | private ArrayList myRatings; 18 | 19 | public PlainRater(String id) { 20 | myID = id; 21 | myRatings = new ArrayList(); 22 | } 23 | 24 | public void addRating(String item, double rating) { 25 | myRatings.add(new Rating(item, rating));//item is string id? 26 | } 27 | 28 | public boolean hasRating(String item) { 29 | for (int k = 0; k < myRatings.size(); k++) { 30 | if (myRatings.get(k).getItem().equals(item)) { 31 | return true; 32 | } 33 | } 34 | 35 | return false; 36 | } 37 | 38 | public String getID() { 39 | return myID; 40 | } 41 | 42 | public double getRating(String item) { 43 | for (int k = 0; k < myRatings.size(); k++) { 44 | if (myRatings.get(k).getItem().equals(item)) { 45 | return myRatings.get(k).getValue(); 46 | } 47 | } 48 | 49 | return -1; 50 | } 51 | 52 | public int numRatings() { 53 | return myRatings.size(); 54 | } 55 | 56 | public ArrayList getItemsRated() { 57 | ArrayList list = new ArrayList(); 58 | for (int k = 0; k < myRatings.size(); k++) { 59 | list.add(myRatings.get(k).getItem()); 60 | } 61 | 62 | return list;//arrayList of item; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /StepFive-Final/Rater.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 12th, 2019 7 | * 8 | * Description: -------------------STEP Three-------- 9 | * Create a new public interface named Rater. Add methods to 10 | * this new interface by copying all the method signatures 11 | * from the PlainRater class. 12 | * 13 | ***************************************************************************/ 14 | 15 | public interface Rater { 16 | public void addRating(String item, double rating); 17 | 18 | public boolean hasRating(String item); 19 | 20 | public String getID(); 21 | 22 | public double getRating(String item); 23 | 24 | public int numRatings(); 25 | 26 | public ArrayList getItemsRated(); 27 | } 28 | -------------------------------------------------------------------------------- /StepFive-Final/RaterDatabase.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 13th, 2019 5 | * 6 | * Description: -------------------STEP FOUR-------- 7 | * The class RaterDatabase—This class is an efficient way to get 8 | * information about raters. 9 | * 10 | ****************************************************************/ 11 | 12 | import edu.duke.FileResource; 13 | import org.apache.commons.csv.CSVParser; 14 | import org.apache.commons.csv.CSVRecord; 15 | 16 | import java.util.ArrayList; 17 | import java.util.HashMap; 18 | 19 | public class RaterDatabase { 20 | private static HashMap ourRaters;//key:rater id, value: rater object 21 | 22 | /** 23 | * A private initialize method with no parameters that initializes 24 | * the HashMap ourRaters if it does not exist. 25 | **/ 26 | private static void initialize() { 27 | // this method is only called from addRatings 28 | if (ourRaters == null) { 29 | ourRaters = new HashMap(); 30 | } 31 | } 32 | 33 | public static void initialize(String filename) { 34 | if (ourRaters == null) { 35 | ourRaters = new HashMap(); 36 | addRatings("data/" + filename); 37 | } 38 | } 39 | 40 | public static void addRatings(String filename) { 41 | initialize(); 42 | FileResource fr = new FileResource(filename); 43 | CSVParser csvp = fr.getCSVParser(); 44 | for (CSVRecord rec : csvp) { 45 | String id = rec.get("rater_id"); 46 | String item = rec.get("movie_id"); 47 | String rating = rec.get("rating"); 48 | addRaterRating(id, item, Double.parseDouble(rating)); 49 | } 50 | } 51 | 52 | public static void addRaterRating(String raterID, String movieID, double rating) { 53 | initialize(); 54 | Rater rater = null; 55 | if (ourRaters.containsKey(raterID)) { 56 | rater = ourRaters.get(raterID); 57 | } else { 58 | rater = new EfficientRater(raterID); 59 | ourRaters.put(raterID, rater); 60 | } 61 | rater.addRating(movieID, rating);//this is the method in EfficientRater class 62 | } 63 | 64 | public static Rater getRater(String id) { 65 | initialize(); 66 | 67 | return ourRaters.get(id); 68 | } 69 | 70 | public static ArrayList getRaters() { 71 | initialize(); 72 | ArrayList list = new ArrayList(ourRaters.values()); 73 | 74 | return list; 75 | } 76 | 77 | public static int size() { 78 | return ourRaters.size(); 79 | } 80 | 81 | 82 | } 83 | -------------------------------------------------------------------------------- /StepFive-Final/Rating.java: -------------------------------------------------------------------------------- 1 | //a POJO class for storing the data about one rating of an item 2 | // An immutable passive data object (PDO) to represent the rating data 3 | public class Rating implements Comparable { 4 | private String item; 5 | private double value; 6 | 7 | public Rating(String anItem, double aValue) { 8 | item = anItem;//IMDB id 9 | value = aValue; 10 | } 11 | 12 | // Returns item being rated 13 | public String getItem() { 14 | return item; 15 | } 16 | 17 | // Returns the value of this rating (as a number so it can be used in calculations) 18 | public double getValue() { 19 | return value; 20 | } 21 | 22 | // Returns a string of all the rating information 23 | public String toString() { 24 | return "[" + getItem() + ", " + getValue() + "]"; 25 | } 26 | 27 | public int compareTo(Rating other) { 28 | if (value < other.value) return -1; 29 | if (value > other.value) return 1; 30 | 31 | return 0; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /StepFive-Final/Recommender.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | /*************************************************************** 3 | * Name: Wei Xu 4 | * 5 | * Date: Dec 15th, 2019 6 | * 7 | * Description: -------------------STEP FIVE-------- 8 | * a class RecommendationRunner that implements Recommender. 9 | * The two methods you will need to implement are: 10 | * • getItemsToRate() 11 | * • printRecommendationsFor() 12 | * 13 | * When the user first visits the recommender site, our code 14 | * will call the method getItemsToRate() to get a list of movies 15 | * to display on the web page for users to rate. 16 | * After the user submits their ratings, our code will call the 17 | * method printRecommendationsFor() to get your recommendations 18 | * based on the user's ratings and display them. 19 | * 20 | * * IMPORTANT NOTICE: 21 | * * Weighted average algorithm optimized by WEI XU 22 | * * Instead of "sum of (similar rating(i) *rating of the movie(i))/count of the raters" 23 | * * !!!!!I use "sum of (similar rating(i) *rating of the movie(i))/ sum of the similar rating(i)", will achieve better results. 24 | * 25 | ****************************************************************/ 26 | 27 | 28 | /** 29 | * Implement this interface to allow your code to be integrated with our 30 | * web site. 31 | *

32 | * When users first visit the recommender website, our code will call the 33 | * method getItemsToRate() to get a list of movies to display 34 | * on the web page for users to rate. 35 | *

36 | * When a user submits their ratings, our code will call the method 37 | * printRecommendationsFor to get your recommendations based on the 38 | * user's ratings. The ID given to this method is for a new Rater that we 39 | * have already added to the RaterDatabase with ratings for the movies 40 | * returned by the first method. Whatever is printed from that method will 41 | * be displayed on the web page: HTML, plain text, or debugging information. 42 | */ 43 | public interface Recommender { 44 | /** 45 | * This method returns a list of movie IDs that will be used to look up 46 | * the movies in the MovieDatabase and present them to users to rate. 47 | *

48 | * The movies returned in the list will be displayed on a web page, so 49 | * the number you choose may affect how long the page takes to load and 50 | * how willing users are to rate the movies. For example, 10-20 should 51 | * be fine, 50 or more would be too many. 52 | *

53 | * There are no restrictions on the method you use to generate this list 54 | * of movies: the most recent movies, movies from a specific genre, 55 | * randomly chosen movies, or simply your favorite movies. 56 | *

57 | * The ratings for these movies will make the profile for a new Rater 58 | * that will be used to compare to for finding recommendations. 59 | */ 60 | public ArrayList getItemsToRate(); 61 | 62 | /** 63 | * This method returns nothing, but prints out an HTML table of the 64 | * movies recommended for the given rater. 65 | *

66 | * The HTML printed will be displayed on a web page, so the number you 67 | * choose to display may affect how long the page takes to load. For 68 | * example, you may want to limit the number printed to only the top 69 | * 20-50 movies recommended or to movies not rater by the given rater. 70 | *

71 | * You may also include CSS styling for your table using the <style> 72 | * tag before you print the table. There are no restrictions on which 73 | * movies you print, what order you print them in, or what information 74 | * you include about each movie. 75 | * 76 | * @param webRaterID the ID of a new Rater that has been already added to 77 | * the RaterDatabase with ratings for the movies returned by the 78 | * method getItemsToRate 79 | */ 80 | public void printRecommendationsFor(String webRaterID); 81 | } 82 | -------------------------------------------------------------------------------- /StepFive-Final/SecondRatings.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 11th, 2019 7 | * 8 | * Description: -------------------STEP TWO------------------------- 9 | * You will build on this assignment by calculating 10 | * average ratings of movies. 11 | * In this assignment you will modify a new class named SecondRatings, 12 | * which has been started for you, to do many of the calculations 13 | * focusing on computing averages on movie ratings. 14 | * You will also create a second new class named MovieRunnerAverage, 15 | * which you will use to test the methods you created in SecondRatings 16 | * by creating a SecondRatings object in MovieRunnerAverage and 17 | * calling its methods. 18 | * 19 | ****************************************************************/ 20 | public class SecondRatings { 21 | 22 | private ArrayList myMovies; 23 | private ArrayList myRaters; 24 | 25 | public SecondRatings() { 26 | // default constructor 27 | this("ratedmoviesfull.csv", "ratings.csv"); 28 | } 29 | //---------------todo: why only above won't compile???------------- 30 | 31 | public SecondRatings(String movieFile, String ratingFile) { 32 | FirstRatings a = new FirstRatings(); 33 | myMovies = a.loadMovies(movieFile); 34 | myRaters = a.loadRaters(ratingFile); 35 | } 36 | 37 | public int getMovieSize() { 38 | return myMovies.size(); 39 | } 40 | 41 | public int getRaterSize() { 42 | return myRaters.size(); 43 | } 44 | 45 | //private helper method 46 | private double getAverageByID(String movieID, int minimalRaters) { 47 | int count = 0; 48 | double total = 0; 49 | for (Rater i : myRaters) { 50 | // if (i.hasRating(movieID)) { 51 | double rating = i.getRating(movieID); 52 | if (rating != -1) { 53 | count++; 54 | total += rating; 55 | // System.out.println(count + " : " + "id = " + i.getID() + " rating " + rating + " ave " + total); 56 | } 57 | } 58 | //System.out.println("Movie ID = " + movieID + " : " + count + " : " + total + " : " + total / count); 59 | if (count >= minimalRaters) return total / count; 60 | return 0.0; 61 | } 62 | 63 | public ArrayList getAverageRatings(int minimalRaters) { 64 | ArrayList ratingList = new ArrayList<>(); 65 | for (Movie i : myMovies) { 66 | double ave = getAverageByID(i.getID(), minimalRaters); 67 | if (ave > 0) 68 | ratingList.add(new Rating(i.getID(), ave));//item is string id? 69 | } 70 | return ratingList; 71 | } 72 | 73 | public String getTitle(String movieID) { 74 | for (Movie i : myMovies) { 75 | if (i.getID().equals(movieID)) { 76 | return i.getTitle(); 77 | } 78 | } 79 | return "The Movie ID was not found!"; 80 | } 81 | 82 | public String getID(String title) { 83 | for (Movie i : myMovies) { 84 | if (i.getTitle().equals(title)) { 85 | return i.getID(); 86 | } 87 | } 88 | return "NO SUCH TITLE"; 89 | } 90 | 91 | public static void main(String[] args) { 92 | SecondRatings sr = new SecondRatings("data/ratedmovies_short.csv", "data/ratings_short.csv"); 93 | //System.out.println(sr.getAverageByID("0790636", 2)); 94 | System.out.println("---------------test-------------"); 95 | System.out.println(sr.getAverageRatings(2)); 96 | //[[6414, 0.0], [68646, 0.0], [113277, 0.0], [1798709, 8.25], [790636, 0.0]] 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /StepFive-Final/StepFive-Final.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFive-Final/StepFour-Weighted Averages.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFive-Final/StepOneStarterProgram.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFive-Final/StepThree-Interfaces, Filters, Database.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFive-Final/StepTwo-Simple Recommendations.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFive-Final/ThirdRatings.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 12th, 2019 7 | * 8 | * Description: -------------------STEP THREE-------- 9 | * The class MovieDatabase—This class is an efficient way to get 10 | * information about movies. It stores movie information in a HashMap 11 | * for fast lookup of movie information given a movie ID. 12 | * The class also allows filtering movies based on queries. All methods 13 | * and fields in the class are static. 14 | * This means you'll be able to access methods in MovieDatabase 15 | * without using new to create objects, but by calling methods like 16 | * MovieDatabase.getMovie("0120915"). 17 | * 18 | ****************************************************************/ 19 | 20 | public class ThirdRatings { 21 | /** 22 | * Movies will now be stored in the MovieDatabase instead of 23 | * in the instance variable myMovies, 24 | * so you will want to remove the private variable myMovies 25 | **/ 26 | //private ArrayList myMovies; 27 | private ArrayList myRaters; 28 | 29 | public ThirdRatings() { 30 | // default constructor 31 | this("ratings.csv"); 32 | } 33 | //---------------todo: why only above won't compile???------------- 34 | 35 | public ThirdRatings(String ratingFile) { 36 | FirstRatings a = new FirstRatings(); 37 | myRaters = a.loadRaters(ratingFile); 38 | } 39 | 40 | public int getRaterSize() { 41 | return myRaters.size(); 42 | } 43 | 44 | //private helper method 45 | private double getAverageByID(String movieID, int minimalRaters) { 46 | int count = 0; 47 | double total = 0; 48 | for (Rater i : myRaters) { 49 | // if (i.hasRating(movieID)) { 50 | double rating = i.getRating(movieID); 51 | if (rating != -1) { 52 | count++; 53 | total += rating; 54 | // System.out.println(count + " : " + "id = " + i.getID() + " rating " + rating + " ave " + total); 55 | } 56 | } 57 | System.out.printf("Movie ID : Count : Total : Rating = %-10s%-5d%-7.2f%-7.2f%n", movieID, count, total, total / count); 58 | if (count >= minimalRaters) return total / count; 59 | return 0.0; 60 | } 61 | 62 | /** 63 | * Note that myMovies no longer exists. Instead, you’ll need to get all the movies 64 | * from the MovieDatabase class and store them in an ArrayList of movie IDs. 65 | * Thus, you will need to modify getAverageRatings to call MovieDatabase 66 | * with a filter, and in this case you can use the TrueFilter to get every movie. 67 | **/ 68 | public ArrayList getAverageRatings(int minimalRaters) { 69 | ArrayList ratingList = new ArrayList<>(); 70 | //must initialize the filter first. 71 | Filter trueFilter = new TrueFilter(); 72 | for (String i : MovieDatabase.filterBy(trueFilter)) { 73 | double ave = getAverageByID(i, minimalRaters); 74 | if (ave > 0) 75 | ratingList.add(new Rating(i, ave));//item is string id? 76 | } 77 | return ratingList; 78 | } 79 | 80 | /** 81 | * write a public helper method named getAverageRatingsByFilter that has 82 | * two parameters, an int named minimalRaters for the minimum number of 83 | * ratings a movie must have and a Filter named filterCriteria. This method 84 | * should create and return an ArrayList of type Rating of all the movies 85 | * that have at least minimalRaters ratings and satisfies the filter criteria. 86 | * This method will need to create the ArrayList of type String of movie IDs 87 | * from the MovieDatabase using the filterBy method before calculating those averages. 88 | */ 89 | public ArrayList getAverageRatingsByFilter(int minimalRaters, Filter f) { 90 | ArrayList ratingList = new ArrayList<>(); 91 | //must initialize the filter first. 92 | Filter trueFilter = new TrueFilter(); 93 | ArrayList movieID = MovieDatabase.filterBy(trueFilter); 94 | 95 | // for (String i : movieID) { 96 | // double ave = getAverageByID(i, minimalRaters); 97 | // if (ave > 0) 98 | // ratingList.add(new Rating(i, ave)); 99 | // } 100 | for (String i : movieID) { 101 | if (f.satisfies(i)) { 102 | double ave = getAverageByID(i, minimalRaters); 103 | if (ave > 0) 104 | ratingList.add(new Rating(i, ave)); 105 | } 106 | } 107 | return ratingList; 108 | } 109 | 110 | // 111 | // public String getTitle(String movieID) { 112 | // for (Movie i : myMovies) { 113 | // if (i.getID().equals(movieID)) { 114 | // return i.getTitle(); 115 | // } 116 | // } 117 | // return "The Movie ID was not found!"; 118 | // } 119 | // 120 | // public String getID(String title) { 121 | // for (Movie i : myMovies) { 122 | // if (i.getTitle().equals(title)) { 123 | // return i.getID(); 124 | // } 125 | // } 126 | // return "NO SUCH TITLE"; 127 | // } 128 | // 129 | public static void main(String[] args) { 130 | ThirdRatings sr = new ThirdRatings("data/ratings_short.csv"); 131 | //System.out.println(sr.getAverageByID("0790636", 2)); 132 | System.out.println("---------------test-------------"); 133 | System.out.println(sr.getAverageRatings(2)); 134 | // System.out.println(a); 135 | /** movie from "full.csv", raters from "short.csv" 136 | * ................ 137 | * Movie ID = 0430922 : 0 : 0.0 : NaN 138 | * Movie ID = 0060176 : 0 : 0.0 : NaN 139 | * Movie ID = 1270262 : 0 : 0.0 : NaN 140 | * Movie ID = 3007512 : 0 : 0.0 : NaN 141 | * Movie ID = 0043618 : 0 : 0.0 : NaN 142 | * Movie ID = 1621039 : 0 : 0.0 : NaN 143 | * Movie ID = 2713180 : 0 : 0.0 : NaN 144 | * [[1798709, 8.25], [0068646, 9.0]] 145 | * */ 146 | } 147 | 148 | } 149 | -------------------------------------------------------------------------------- /StepFive-Final/TrueFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The class TrueFilter can be used to select every movie from 3 | * MovieDatabase. It’s satisfies method always returns true. 4 | */ 5 | public class TrueFilter implements Filter { 6 | @Override 7 | public boolean satisfies(String id) { 8 | return true; 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /StepFive-Final/YearAfterFilter.java: -------------------------------------------------------------------------------- 1 | public class YearAfterFilter implements Filter { 2 | private int myYear; 3 | 4 | public YearAfterFilter(int year) { 5 | myYear = year; 6 | } 7 | 8 | @Override 9 | public boolean satisfies(String id) { 10 | return MovieDatabase.getYear(id) >= myYear; 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /StepFive-Final/data/ratedmovies_short.csv: -------------------------------------------------------------------------------- 1 | id,title,year,country,genre,director,minutes,poster 2 | 0006414,Behind the Screen,1916,USA,"Short, Comedy, Romance",Charles Chaplin,30,http://ia.media-imdb.com/images/M/MV5BMTkyNDYyNTczNF5BMl5BanBnXkFtZTgwMDU2MzAwMzE@._V1_SX300.jpg 3 | 0068646,The Godfather,1972,USA,"Crime, Drama",Francis Ford Coppola,175,http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg 4 | 0113277,Heat,1995,USA,"Action, Crime, Drama",Michael Mann,170,http://ia.media-imdb.com/images/M/MV5BMTM1NDc4ODkxNV5BMl5BanBnXkFtZTcwNTI4ODE3MQ@@._V1_SX300.jpg 5 | 1798709,Her,2013,USA,"Drama, Romance, Sci-Fi",Spike Jonze,126,http://ia.media-imdb.com/images/M/MV5BMjA1Nzk0OTM2OF5BMl5BanBnXkFtZTgwNjU2NjEwMDE@._V1_SX300.jpg 6 | 0790636,Dallas Buyers Club,2013,USA,"Biography, Drama",Jean-Marc Vallée,117,N/A -------------------------------------------------------------------------------- /StepFive-Final/data/ratings_short.csv: -------------------------------------------------------------------------------- 1 | rater_id,movie_id,rating,time 2 | 1,0068646,10,1381620027 3 | 1,0113277,10,1379466669 4 | 2,1798709,10,1389948338 5 | 2,0790636,7,1389963947 6 | 2,0068646,9,1382460093 7 | 3,1798709,9,1388641438 8 | 4,0068646,8,1362440416 9 | 4,1798709,6,1398043318 10 | 5,0068646,9,1364834910 11 | 5,1798709,8,1404338202 -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/Archive.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/Archive.zip -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/EfficientRater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/EfficientRater.class -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/Filter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/Filter.class -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/FirstRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/FirstRatings.class -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/FourthRatingsOptimizedByWeiXu.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/FourthRatingsOptimizedByWeiXu.class -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/Movie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/Movie.class -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/MovieDatabase.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/MovieDatabase.class -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/MovieRunnerSimilarRatingsOptimizedByWeiXu.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/MovieRunnerSimilarRatingsOptimizedByWeiXu.class -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/Rater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/Rater.class -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/RaterDatabase.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/RaterDatabase.class -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/Rating.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/Rating.class -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/RecommendationRunner.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/RecommendationRunner.class -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/Recommender.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/Recommender.class -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/StepFive-Final.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/StepFour-Weighted Averages.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/StepOneStarterProgram.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/StepThree-Interfaces, Filters, Database.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/StepTwo-Simple Recommendations.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/TrueFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/TrueFilter.class -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/data/ratedmovies_short.csv: -------------------------------------------------------------------------------- 1 | id,title,year,country,genre,director,minutes,poster 2 | 0006414,Behind the Screen,1916,USA,"Short, Comedy, Romance",Charles Chaplin,30,http://ia.media-imdb.com/images/M/MV5BMTkyNDYyNTczNF5BMl5BanBnXkFtZTgwMDU2MzAwMzE@._V1_SX300.jpg 3 | 0068646,The Godfather,1972,USA,"Crime, Drama",Francis Ford Coppola,175,http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg 4 | 0113277,Heat,1995,USA,"Action, Crime, Drama",Michael Mann,170,http://ia.media-imdb.com/images/M/MV5BMTM1NDc4ODkxNV5BMl5BanBnXkFtZTcwNTI4ODE3MQ@@._V1_SX300.jpg 5 | 1798709,Her,2013,USA,"Drama, Romance, Sci-Fi",Spike Jonze,126,http://ia.media-imdb.com/images/M/MV5BMjA1Nzk0OTM2OF5BMl5BanBnXkFtZTgwNjU2NjEwMDE@._V1_SX300.jpg 6 | 0790636,Dallas Buyers Club,2013,USA,"Biography, Drama",Jean-Marc Vallée,117,N/A -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/data/ratings_short.csv: -------------------------------------------------------------------------------- 1 | rater_id,movie_id,rating,time 2 | 1,0068646,10,1381620027 3 | 1,0113277,10,1379466669 4 | 2,1798709,10,1389948338 5 | 2,0790636,7,1389963947 6 | 2,0068646,9,1382460093 7 | 3,1798709,9,1388641438 8 | 4,0068646,8,1362440416 9 | 4,1798709,6,1398043318 10 | 5,0068646,9,1364834910 11 | 5,1798709,8,1404338202 -------------------------------------------------------------------------------- /StepFive-Final/out/production/StepFive-Final/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/out/production/StepFive-Final/output.png -------------------------------------------------------------------------------- /StepFive-Final/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFive-Final/output.png -------------------------------------------------------------------------------- /StepFour-Weighted Averages/AllFilters.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 12th, 2019 7 | * 8 | * Description: -------------------STEP THREE------------------------- 9 | * Now use the AllFilters class to combine asking questions 10 | * about average ratings by genre and films on or after a 11 | * particular year. 12 | * 13 | ****************************************************************/ 14 | 15 | public class AllFilters implements Filter { 16 | ArrayList filters; 17 | 18 | public AllFilters() { 19 | filters = new ArrayList(); 20 | } 21 | 22 | public void addFilter(Filter f) { 23 | filters.add(f); 24 | } 25 | 26 | @Override 27 | public boolean satisfies(String id) { 28 | for (Filter f : filters) { 29 | if (!f.satisfies(id)) { 30 | return false; 31 | } 32 | } 33 | return true; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/DUKE Algorithm Output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/DUKE Algorithm Output.png -------------------------------------------------------------------------------- /StepFour-Weighted Averages/DirectorsFilter.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 12th, 2019 5 | * 6 | * Description: -------------------STEP THREE------------------------- 7 | * Create a new class named DirectorsFilter that implements Filter. 8 | * The constructor should have one parameter named directors 9 | * representing a list of directors separated by commas. 10 | * 11 | * (Example: "Charles Chaplin,Michael Mann,Spike Jonze", 12 | * and its satisfies method should return true if a movie has 13 | * at least one of these directors as one of its directors. 14 | * Note that each movie may have several directors. 15 | * 16 | ****************************************************************/ 17 | public class DirectorsFilter implements Filter { 18 | private String directors; 19 | 20 | public DirectorsFilter(String directors) { 21 | this.directors = directors; 22 | } 23 | 24 | @Override 25 | public boolean satisfies(String id) { 26 | String[] dir = directors.split(","); 27 | //boolean exist = false; 28 | for (String i : dir) { 29 | //System.out.println(id + " : " + MovieDatabase.getDirector(id) + " : " + MovieDatabase.getTitle(id)); 30 | if (MovieDatabase.getDirector(id).contains(i)) { 31 | return true; 32 | //break; 33 | } 34 | } 35 | return false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/EfficientRater.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.HashMap; 3 | 4 | /*************************************************************************** 5 | * Name: Wei Xu 6 | * 7 | * Date: Dec 12th, 2019 8 | * 9 | * Description: -------------------STEP Three---------------------------- 10 | * Create a new class named EfficientRater, and copy the 11 | * PlainRater class into this class. You will make several 12 | * changes to this class, including: 13 | * 14 | * Change the ArrayList of type Rating private variable to a 15 | * HashMap. The key in the HashMap is a movie ID, 16 | * and its value is a rating associated with this movie. 17 | * You will need to change addRating to instead add a new Rating 18 | * to the HashMap with the value associated with the movie ID 19 | * String item as the key in the HashMap. The method hasRating 20 | * should now be much shorter; it no longer needs a loop. 21 | * More method need change....... 22 | * 23 | ***************************************************************************/ 24 | public class EfficientRater implements Rater { 25 | private String myID; 26 | /* Change the ArrayList of type Rating private variable to a HashMap. 27 | The key in the HashMap is a movie ID, and 28 | its value is a rating associated with this movie.*/ 29 | //private HashMap> myRatings;//why not this one? 30 | private HashMap myRatings; 31 | 32 | public EfficientRater(String id) { 33 | myID = id; 34 | myRatings = new HashMap<>(); 35 | } 36 | 37 | public void addRating(String item, double rating) { 38 | myRatings.put(item, new Rating(item, rating));//item is string id? 39 | } 40 | 41 | public boolean hasRating(String item) { 42 | return myRatings.containsKey(item); 43 | } 44 | 45 | public String getID() { 46 | return myID; 47 | } 48 | 49 | public double getRating(String item) { 50 | // for (int k = 0; k < myRatings.size(); k++) { 51 | // if (myRatings.get(k).getItem().equals(item)) { 52 | // return myRatings.get(k).getValue(); 53 | // } 54 | // } 55 | if (myRatings.containsKey(item)) { 56 | return myRatings.get(item).getValue(); 57 | } 58 | return -1; 59 | } 60 | 61 | public int numRatings() { 62 | return myRatings.size(); 63 | } 64 | 65 | public ArrayList getItemsRated() { 66 | ArrayList list = new ArrayList<>(myRatings.keySet()); 67 | // for (int k = 0; k < myRatings.size(); k++) { 68 | // list.add(myRatings.get(k).getItem()); 69 | // } 70 | // 71 | return list;//arrayList of item; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/Filter.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 12th, 2019 5 | * 6 | * Description: -------------------STEP THREE-------- 7 | * The interface Filter has only one signature for 8 | * the method satisfies. Any filters that implement 9 | * this interface must also have this method. 10 | * The method satisfies has one String parameter 11 | * named id representing a movie ID. This method returns 12 | * true if the movie satisfies the criteria in the method 13 | * and returns false otherwise. 14 | * 15 | ****************************************************************/ 16 | 17 | public interface Filter { 18 | public boolean satisfies(String id); 19 | } 20 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/GenreFilter.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 12th, 2019 5 | * 6 | * Description: -------------------STEP THREE------------------------- 7 | * Create a new class named GenreFilter that implements Filter. 8 | * The constructor should have one parameter named genre 9 | * representing one genre, and the satisfies method should 10 | * return true if a movie has this genre. Note that movies 11 | * may have several genres. 12 | * 13 | ****************************************************************/ 14 | 15 | public class GenreFilter implements Filter { 16 | private String genre; 17 | 18 | public GenreFilter(String genre) { 19 | this.genre = genre; 20 | } 21 | 22 | @Override 23 | public boolean satisfies(String id) { 24 | return MovieDatabase.getGenres(id).contains(genre); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/MinutesFilter.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 12th, 2019 5 | * 6 | * Description: -------------------STEP THREE------------------------- 7 | * Create a new class named MinutesFilter that implements Filter. 8 | * Its satisfies method should return true if a movie’s running time 9 | * is at least min minutes and no more than max minutes. 10 | * 11 | ****************************************************************/ 12 | public class MinutesFilter implements Filter { 13 | private int min; 14 | private int max; 15 | 16 | 17 | public MinutesFilter(int min, int max) { 18 | this.min = min; 19 | this.max = max; 20 | } 21 | 22 | @Override 23 | public boolean satisfies(String id) { 24 | return MovieDatabase.getMinutes(id) >= min && MovieDatabase.getMinutes(id) <= max; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/Movie.java: -------------------------------------------------------------------------------- 1 | //Plain Old Java Object (POJO) class for storing the data about one movie 2 | // An immutable passive data object (PDO) to represent item data 3 | public class Movie { 4 | private String id; 5 | private String title; 6 | private int year; 7 | private String genres; 8 | private String director; 9 | private String country; 10 | private String poster; 11 | private int minutes; 12 | 13 | public Movie(String anID, String aTitle, String aYear, String theGenres) { 14 | // just in case data file contains extra whitespace 15 | id = anID.trim(); 16 | title = aTitle.trim(); 17 | year = Integer.parseInt(aYear.trim()); 18 | genres = theGenres; 19 | } 20 | 21 | public Movie(String anID, String aTitle, String aYear, String theGenres, String aDirector, 22 | String aCountry, String aPoster, int theMinutes) { 23 | // just in case data file contains extra whitespace 24 | id = anID.trim(); 25 | title = aTitle.trim(); 26 | year = Integer.parseInt(aYear.trim()); 27 | genres = theGenres; 28 | director = aDirector; 29 | country = aCountry; 30 | poster = aPoster; 31 | minutes = theMinutes; 32 | } 33 | 34 | // Returns ID associated with this item 35 | public String getID() { 36 | return id; 37 | } 38 | 39 | // Returns title of this item 40 | public String getTitle() { 41 | return title; 42 | } 43 | 44 | // Returns year in which this item was published 45 | public int getYear() { 46 | return year; 47 | } 48 | 49 | // Returns genres associated with this item 50 | public String getGenres() { 51 | return genres; 52 | } 53 | 54 | public String getCountry() { 55 | return country; 56 | } 57 | 58 | public String getDirector() { 59 | return director; 60 | } 61 | 62 | public String getPoster() { 63 | return poster; 64 | } 65 | 66 | public int getMinutes() { 67 | return minutes; 68 | } 69 | 70 | // Returns a string of the item's information 71 | public String toString() { 72 | String result = "Movie [id=" + id + ", title=" + title + ", year=" + year; 73 | result += ", genres= " + genres + "]"; 74 | return result; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/MovieDatabase.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.HashMap; 3 | 4 | /*************************************************************** 5 | * Name: Wei Xu 6 | * 7 | * Date: Dec 12th, 2019 8 | * 9 | * Description: -------------------STEP THREE-------- 10 | * The class MovieDatabase—This class is an efficient way to get 11 | * information about movies. It stores movie information in a HashMap 12 | * for fast lookup of movie information given a movie ID. 13 | * The class also allows filtering movies based on queries. All methods 14 | * and fields in the class are static. 15 | * This means you'll be able to access methods in MovieDatabase 16 | * without using new to create objects, but by calling methods like 17 | * MovieDatabase.getMovie("0120915"). 18 | * 19 | ****************************************************************/ 20 | public class MovieDatabase { 21 | private static HashMap ourMovies; 22 | //before it's an Arraylist 23 | 24 | public static void initialize(String moviefile) { 25 | if (ourMovies == null) { 26 | ourMovies = new HashMap(); 27 | loadMovies("data/" + moviefile); 28 | } 29 | } 30 | 31 | private static void initialize() { 32 | if (ourMovies == null) { 33 | ourMovies = new HashMap(); 34 | loadMovies("data/ratedmoviesfull.csv"); 35 | } 36 | } 37 | 38 | private static void loadMovies(String filename) { 39 | FirstRatings fr = new FirstRatings(); 40 | ArrayList list = fr.loadMovies(filename); 41 | for (Movie m : list) { 42 | ourMovies.put(m.getID(), m); 43 | } 44 | } 45 | 46 | public static boolean containsID(String id) { 47 | initialize(); 48 | return ourMovies.containsKey(id); 49 | } 50 | 51 | public static int getYear(String id) { 52 | initialize(); 53 | return ourMovies.get(id).getYear(); 54 | } 55 | 56 | public static String getGenres(String id) { 57 | initialize(); 58 | return ourMovies.get(id).getGenres(); 59 | } 60 | 61 | public static String getTitle(String id) { 62 | initialize(); 63 | return ourMovies.get(id).getTitle(); 64 | } 65 | 66 | public static Movie getMovie(String id) { 67 | initialize(); 68 | return ourMovies.get(id); 69 | } 70 | 71 | public static String getPoster(String id) { 72 | initialize(); 73 | return ourMovies.get(id).getPoster(); 74 | } 75 | 76 | public static int getMinutes(String id) { 77 | initialize(); 78 | return ourMovies.get(id).getMinutes(); 79 | } 80 | 81 | public static String getCountry(String id) { 82 | initialize(); 83 | return ourMovies.get(id).getCountry(); 84 | } 85 | 86 | public static String getDirector(String id) { 87 | initialize(); 88 | return ourMovies.get(id).getDirector(); 89 | } 90 | 91 | public static int size() { 92 | return ourMovies.size(); 93 | } 94 | 95 | // why no need implement filter? 96 | public static ArrayList filterBy(Filter f) { 97 | initialize(); 98 | ArrayList list = new ArrayList(); 99 | for (String id : ourMovies.keySet()) { 100 | if (f.satisfies(id)) { 101 | list.add(id); 102 | } 103 | } 104 | return list;//ArrayList of movie id 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/MovieRunnerAverage.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collections; 3 | 4 | /*************************************************************** 5 | * Name: Wei Xu 6 | * 7 | * Date: Dec 11th, 2019 8 | * 9 | * Description: -------------------STEP TWO------------------------- 10 | * You will build on this assignment by calculating 11 | * average ratings of movies. 12 | * In this assignment you will modify a new class named SecondRatings, 13 | * which has been started for you, to do many of the calculations 14 | * focusing on computing averages on movie ratings. 15 | * You will also create a second new class named MovieRunnerAverage, 16 | * which you will use to test the methods you created in SecondRatings 17 | * by creating a SecondRatings object in MovieRunnerAverage and 18 | * calling its methods. 19 | * 20 | ****************************************************************/ 21 | public class MovieRunnerAverage { 22 | public void printAverageRatings() { 23 | SecondRatings sr = new SecondRatings("data/ratedmovies_short.csv", "data/ratings_short.csv");//do i need put filename here? 24 | System.out.println("Movie size = " + sr.getMovieSize()); 25 | System.out.println("Rater size = " + sr.getRaterSize()); 26 | ArrayList ratingList = sr.getAverageRatings(2); 27 | Collections.sort(ratingList); 28 | for (Rating i : ratingList) { 29 | System.out.printf("%-10.2f%s%n", i.getValue(), sr.getTitle(i.getItem())); 30 | } 31 | } 32 | 33 | public void getAverageRatingOneMovie() { 34 | SecondRatings sr = new SecondRatings("data/ratedmovies_short.csv", "data/ratings_short.csv");//do i need put filename here? 35 | ArrayList ratingList = sr.getAverageRatings(2); 36 | String movieTitle = "The Godfather"; 37 | for (Rating i : ratingList) { 38 | if (sr.getTitle(i.getItem()).equals(movieTitle)) { 39 | System.out.printf("%-10.2f%s%n", i.getValue(), sr.getTitle(i.getItem())); 40 | } 41 | } 42 | } 43 | 44 | public static void main(String[] args) { 45 | MovieRunnerAverage mra = new MovieRunnerAverage(); 46 | System.out.println("---------------print test----------------"); 47 | mra.printAverageRatings(); 48 | System.out.println("---------------get average rating one movie test----------------"); 49 | mra.getAverageRatingOneMovie(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/PlainRater.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 12th, 2019 7 | * 8 | * Description: -------------------STEP Three-------- 9 | * Change the name of the class Rater.java to PlainRater.java. 10 | * Be sure to compile it to make sure your newly named class 11 | * works—that you've made the changes necessary for the class 12 | * to function with the name PlainRater. 13 | * 14 | ***************************************************************************/ 15 | public class PlainRater implements Rater { 16 | private String myID; 17 | private ArrayList myRatings; 18 | 19 | public PlainRater(String id) { 20 | myID = id; 21 | myRatings = new ArrayList(); 22 | } 23 | 24 | public void addRating(String item, double rating) { 25 | myRatings.add(new Rating(item, rating));//item is string id? 26 | } 27 | 28 | public boolean hasRating(String item) { 29 | for (int k = 0; k < myRatings.size(); k++) { 30 | if (myRatings.get(k).getItem().equals(item)) { 31 | return true; 32 | } 33 | } 34 | 35 | return false; 36 | } 37 | 38 | public String getID() { 39 | return myID; 40 | } 41 | 42 | public double getRating(String item) { 43 | for (int k = 0; k < myRatings.size(); k++) { 44 | if (myRatings.get(k).getItem().equals(item)) { 45 | return myRatings.get(k).getValue(); 46 | } 47 | } 48 | 49 | return -1; 50 | } 51 | 52 | public int numRatings() { 53 | return myRatings.size(); 54 | } 55 | 56 | public ArrayList getItemsRated() { 57 | ArrayList list = new ArrayList(); 58 | for (int k = 0; k < myRatings.size(); k++) { 59 | list.add(myRatings.get(k).getItem()); 60 | } 61 | 62 | return list;//arrayList of item; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/Rater.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 12th, 2019 7 | * 8 | * Description: -------------------STEP Three-------- 9 | * Create a new public interface named Rater. Add methods to 10 | * this new interface by copying all the method signatures 11 | * from the PlainRater class. 12 | * 13 | ***************************************************************************/ 14 | 15 | public interface Rater { 16 | public void addRating(String item, double rating); 17 | 18 | public boolean hasRating(String item); 19 | 20 | public String getID(); 21 | 22 | public double getRating(String item); 23 | 24 | public int numRatings(); 25 | 26 | public ArrayList getItemsRated(); 27 | } 28 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/RaterDatabase.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 13th, 2019 5 | * 6 | * Description: -------------------STEP FOUR-------- 7 | * The class RaterDatabase—This class is an efficient way to get 8 | * information about raters. 9 | * 10 | ****************************************************************/ 11 | 12 | import edu.duke.FileResource; 13 | import org.apache.commons.csv.CSVParser; 14 | import org.apache.commons.csv.CSVRecord; 15 | 16 | import java.util.ArrayList; 17 | import java.util.HashMap; 18 | 19 | public class RaterDatabase { 20 | private static HashMap ourRaters;//key:rater id, value: rater object 21 | 22 | /** 23 | * A private initialize method with no parameters that initializes 24 | * the HashMap ourRaters if it does not exist. 25 | **/ 26 | private static void initialize() { 27 | // this method is only called from addRatings 28 | if (ourRaters == null) { 29 | ourRaters = new HashMap(); 30 | } 31 | } 32 | 33 | public static void initialize(String filename) { 34 | if (ourRaters == null) { 35 | ourRaters = new HashMap(); 36 | addRatings("data/" + filename); 37 | } 38 | } 39 | 40 | public static void addRatings(String filename) { 41 | initialize(); 42 | FileResource fr = new FileResource(filename); 43 | CSVParser csvp = fr.getCSVParser(); 44 | for (CSVRecord rec : csvp) { 45 | String id = rec.get("rater_id"); 46 | String item = rec.get("movie_id"); 47 | String rating = rec.get("rating"); 48 | addRaterRating(id, item, Double.parseDouble(rating)); 49 | } 50 | } 51 | 52 | public static void addRaterRating(String raterID, String movieID, double rating) { 53 | initialize(); 54 | Rater rater = null; 55 | if (ourRaters.containsKey(raterID)) { 56 | rater = ourRaters.get(raterID); 57 | } else { 58 | rater = new EfficientRater(raterID); 59 | ourRaters.put(raterID, rater); 60 | } 61 | rater.addRating(movieID, rating);//this is the method in EfficientRater class 62 | } 63 | 64 | public static Rater getRater(String id) { 65 | initialize(); 66 | 67 | return ourRaters.get(id); 68 | } 69 | 70 | public static ArrayList getRaters() { 71 | initialize(); 72 | ArrayList list = new ArrayList(ourRaters.values()); 73 | 74 | return list; 75 | } 76 | 77 | public static int size() { 78 | return ourRaters.size(); 79 | } 80 | 81 | 82 | } 83 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/Rating.java: -------------------------------------------------------------------------------- 1 | //a POJO class for storing the data about one rating of an item 2 | // An immutable passive data object (PDO) to represent the rating data 3 | public class Rating implements Comparable { 4 | private String item; 5 | private double value; 6 | 7 | public Rating(String anItem, double aValue) { 8 | item = anItem;//IMDB id 9 | value = aValue; 10 | } 11 | 12 | // Returns item being rated 13 | public String getItem() { 14 | return item; 15 | } 16 | 17 | // Returns the value of this rating (as a number so it can be used in calculations) 18 | public double getValue() { 19 | return value; 20 | } 21 | 22 | // Returns a string of all the rating information 23 | public String toString() { 24 | return "[" + getItem() + ", " + getValue() + "]"; 25 | } 26 | 27 | public int compareTo(Rating other) { 28 | if (value < other.value) return -1; 29 | if (value > other.value) return 1; 30 | 31 | return 0; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/SecondRatings.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 11th, 2019 7 | * 8 | * Description: -------------------STEP TWO------------------------- 9 | * You will build on this assignment by calculating 10 | * average ratings of movies. 11 | * In this assignment you will modify a new class named SecondRatings, 12 | * which has been started for you, to do many of the calculations 13 | * focusing on computing averages on movie ratings. 14 | * You will also create a second new class named MovieRunnerAverage, 15 | * which you will use to test the methods you created in SecondRatings 16 | * by creating a SecondRatings object in MovieRunnerAverage and 17 | * calling its methods. 18 | * 19 | ****************************************************************/ 20 | public class SecondRatings { 21 | 22 | private ArrayList myMovies; 23 | private ArrayList myRaters; 24 | 25 | public SecondRatings() { 26 | // default constructor 27 | this("ratedmoviesfull.csv", "ratings.csv"); 28 | } 29 | //---------------todo: why only above won't compile???------------- 30 | 31 | public SecondRatings(String movieFile, String ratingFile) { 32 | FirstRatings a = new FirstRatings(); 33 | myMovies = a.loadMovies(movieFile); 34 | myRaters = a.loadRaters(ratingFile); 35 | } 36 | 37 | public int getMovieSize() { 38 | return myMovies.size(); 39 | } 40 | 41 | public int getRaterSize() { 42 | return myRaters.size(); 43 | } 44 | 45 | //private helper method 46 | private double getAverageByID(String movieID, int minimalRaters) { 47 | int count = 0; 48 | double total = 0; 49 | for (Rater i : myRaters) { 50 | // if (i.hasRating(movieID)) { 51 | double rating = i.getRating(movieID); 52 | if (rating != -1) { 53 | count++; 54 | total += rating; 55 | // System.out.println(count + " : " + "id = " + i.getID() + " rating " + rating + " ave " + total); 56 | } 57 | } 58 | //System.out.println("Movie ID = " + movieID + " : " + count + " : " + total + " : " + total / count); 59 | if (count >= minimalRaters) return total / count; 60 | return 0.0; 61 | } 62 | 63 | public ArrayList getAverageRatings(int minimalRaters) { 64 | ArrayList ratingList = new ArrayList<>(); 65 | for (Movie i : myMovies) { 66 | double ave = getAverageByID(i.getID(), minimalRaters); 67 | if (ave > 0) 68 | ratingList.add(new Rating(i.getID(), ave));//item is string id? 69 | } 70 | return ratingList; 71 | } 72 | 73 | public String getTitle(String movieID) { 74 | for (Movie i : myMovies) { 75 | if (i.getID().equals(movieID)) { 76 | return i.getTitle(); 77 | } 78 | } 79 | return "The Movie ID was not found!"; 80 | } 81 | 82 | public String getID(String title) { 83 | for (Movie i : myMovies) { 84 | if (i.getTitle().equals(title)) { 85 | return i.getID(); 86 | } 87 | } 88 | return "NO SUCH TITLE"; 89 | } 90 | 91 | public static void main(String[] args) { 92 | SecondRatings sr = new SecondRatings("data/ratedmovies_short.csv", "data/ratings_short.csv"); 93 | //System.out.println(sr.getAverageByID("0790636", 2)); 94 | System.out.println("---------------test-------------"); 95 | System.out.println(sr.getAverageRatings(2)); 96 | //[[6414, 0.0], [68646, 0.0], [113277, 0.0], [1798709, 8.25], [790636, 0.0]] 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/StepFour-Weighted Averages.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/StepOneStarterProgram.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/StepThree-Interfaces, Filters, Database.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/StepTwo-Simple Recommendations.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/TrueFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The class TrueFilter can be used to select every movie from 3 | * MovieDatabase. It’s satisfies method always returns true. 4 | */ 5 | public class TrueFilter implements Filter { 6 | @Override 7 | public boolean satisfies(String id) { 8 | return true; 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/Wei Xu Algorithm Output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/Wei Xu Algorithm Output.png -------------------------------------------------------------------------------- /StepFour-Weighted Averages/YearAfterFilter.java: -------------------------------------------------------------------------------- 1 | public class YearAfterFilter implements Filter { 2 | private int myYear; 3 | 4 | public YearAfterFilter(int year) { 5 | myYear = year; 6 | } 7 | 8 | @Override 9 | public boolean satisfies(String id) { 10 | return MovieDatabase.getYear(id) >= myYear; 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/data/ratedmovies_short.csv: -------------------------------------------------------------------------------- 1 | id,title,year,country,genre,director,minutes,poster 2 | 0006414,Behind the Screen,1916,USA,"Short, Comedy, Romance",Charles Chaplin,30,http://ia.media-imdb.com/images/M/MV5BMTkyNDYyNTczNF5BMl5BanBnXkFtZTgwMDU2MzAwMzE@._V1_SX300.jpg 3 | 0068646,The Godfather,1972,USA,"Crime, Drama",Francis Ford Coppola,175,http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg 4 | 0113277,Heat,1995,USA,"Action, Crime, Drama",Michael Mann,170,http://ia.media-imdb.com/images/M/MV5BMTM1NDc4ODkxNV5BMl5BanBnXkFtZTcwNTI4ODE3MQ@@._V1_SX300.jpg 5 | 1798709,Her,2013,USA,"Drama, Romance, Sci-Fi",Spike Jonze,126,http://ia.media-imdb.com/images/M/MV5BMjA1Nzk0OTM2OF5BMl5BanBnXkFtZTgwNjU2NjEwMDE@._V1_SX300.jpg 6 | 0790636,Dallas Buyers Club,2013,USA,"Biography, Drama",Jean-Marc Vallée,117,N/A -------------------------------------------------------------------------------- /StepFour-Weighted Averages/data/ratings_short.csv: -------------------------------------------------------------------------------- 1 | rater_id,movie_id,rating,time 2 | 1,0068646,10,1381620027 3 | 1,0113277,10,1379466669 4 | 2,1798709,10,1389948338 5 | 2,0790636,7,1389963947 6 | 2,0068646,9,1382460093 7 | 3,1798709,9,1388641438 8 | 4,0068646,8,1362440416 9 | 4,1798709,6,1398043318 10 | 5,0068646,9,1364834910 11 | 5,1798709,8,1404338202 -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/AllFilters.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/AllFilters.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/DirectorsFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/DirectorsFilter.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/EfficientRater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/EfficientRater.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/Filter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/Filter.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/FirstRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/FirstRatings.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/FourthRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/FourthRatings.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/GenreFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/GenreFilter.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/MinutesFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/MinutesFilter.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/Movie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/Movie.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/MovieDatabase.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/MovieDatabase.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/MovieRunnerAverage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/MovieRunnerAverage.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/MovieRunnerSimilarRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/MovieRunnerSimilarRatings.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/MovieRunnerWithFilters.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/MovieRunnerWithFilters.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/Rater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/Rater.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/RaterDatabase.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/RaterDatabase.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/Rating.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/Rating.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/SecondRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/SecondRatings.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/StepFour-Weighted Averages.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/StepOneStarterProgram.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/StepThree-Interfaces, Filters, Database.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/StepTwo-Simple Recommendations.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/ThirdRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/ThirdRatings.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/TrueFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/TrueFilter.class -------------------------------------------------------------------------------- /StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/YearAfterFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepFour-Weighted Averages/out/production/StepFour-Weighted Averages/YearAfterFilter.class -------------------------------------------------------------------------------- /StepOneStarterProgram/Movie.java: -------------------------------------------------------------------------------- 1 | //Plain Old Java Object (POJO) class for storing the data about one movie 2 | // An immutable passive data object (PDO) to represent item data 3 | public class Movie { 4 | private String id; 5 | private String title; 6 | private int year; 7 | private String genres; 8 | private String director; 9 | private String country; 10 | private String poster; 11 | private int minutes; 12 | 13 | public Movie(String anID, String aTitle, String aYear, String theGenres) { 14 | // just in case data file contains extra whitespace 15 | id = anID.trim(); 16 | title = aTitle.trim(); 17 | year = Integer.parseInt(aYear.trim()); 18 | genres = theGenres; 19 | } 20 | 21 | public Movie(String anID, String aTitle, String aYear, String theGenres, String aDirector, 22 | String aCountry, String aPoster, int theMinutes) { 23 | // just in case data file contains extra whitespace 24 | id = anID.trim(); 25 | title = aTitle.trim(); 26 | year = Integer.parseInt(aYear.trim()); 27 | genres = theGenres; 28 | director = aDirector; 29 | country = aCountry; 30 | poster = aPoster; 31 | minutes = theMinutes; 32 | } 33 | 34 | // Returns ID associated with this item 35 | public String getID() { 36 | return id; 37 | } 38 | 39 | // Returns title of this item 40 | public String getTitle() { 41 | return title; 42 | } 43 | 44 | // Returns year in which this item was published 45 | public int getYear() { 46 | return year; 47 | } 48 | 49 | // Returns genres associated with this item 50 | public String getGenres() { 51 | return genres; 52 | } 53 | 54 | public String getCountry() { 55 | return country; 56 | } 57 | 58 | public String getDirector() { 59 | return director; 60 | } 61 | 62 | public String getPoster() { 63 | return poster; 64 | } 65 | 66 | public int getMinutes() { 67 | return minutes; 68 | } 69 | 70 | // Returns a string of the item's information 71 | public String toString() { 72 | String result = "Movie [id=" + id + ", title=" + title + ", year=" + year; 73 | result += ", genres= " + genres + "]"; 74 | return result; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /StepOneStarterProgram/Rater.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Write a description of class Rater here. 3 | * 4 | * @author (your name) 5 | * @version (a version number or a date) 6 | */ 7 | 8 | import java.util.ArrayList; 9 | 10 | public class Rater { 11 | private String myID; 12 | private ArrayList myRatings; 13 | 14 | public Rater(String id) { 15 | myID = id; 16 | myRatings = new ArrayList(); 17 | } 18 | 19 | public void addRating(String item, double rating) { 20 | myRatings.add(new Rating(item, rating));//item is string id? 21 | } 22 | 23 | public boolean hasRating(String item) { 24 | for (int k = 0; k < myRatings.size(); k++) { 25 | if (myRatings.get(k).getItem().equals(item)) { 26 | return true; 27 | } 28 | } 29 | 30 | return false; 31 | } 32 | 33 | public String getID() { 34 | return myID; 35 | } 36 | 37 | public double getRating(String item) { 38 | for (int k = 0; k < myRatings.size(); k++) { 39 | if (myRatings.get(k).getItem().equals(item)) { 40 | return myRatings.get(k).getValue(); 41 | } 42 | } 43 | 44 | return -1; 45 | } 46 | 47 | public int numRatings() { 48 | return myRatings.size(); 49 | } 50 | 51 | public ArrayList getItemsRated() { 52 | ArrayList list = new ArrayList(); 53 | for (int k = 0; k < myRatings.size(); k++) { 54 | list.add(myRatings.get(k).getItem()); 55 | } 56 | 57 | return list;//arrayList of item; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /StepOneStarterProgram/Rating.java: -------------------------------------------------------------------------------- 1 | //a POJO class for storing the data about one rating of an item 2 | // An immutable passive data object (PDO) to represent the rating data 3 | public class Rating implements Comparable { 4 | private String item; 5 | private double value; 6 | 7 | public Rating(String anItem, double aValue) { 8 | item = anItem;//IMDB id 9 | value = aValue; 10 | } 11 | 12 | // Returns item being rated 13 | public String getItem() { 14 | return item; 15 | } 16 | 17 | // Returns the value of this rating (as a number so it can be used in calculations) 18 | public double getValue() { 19 | return value; 20 | } 21 | 22 | // Returns a string of all the rating information 23 | public String toString() { 24 | return "[" + getItem() + ", " + getValue() + "]"; 25 | } 26 | 27 | public int compareTo(Rating other) { 28 | if (value < other.value) return -1; 29 | if (value > other.value) return 1; 30 | 31 | return 0; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /StepOneStarterProgram/StepOneStarterProgram.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepOneStarterProgram/data/ratedmovies_short.csv: -------------------------------------------------------------------------------- 1 | id,title,year,country,genre,director,minutes,poster 2 | 6414,Behind the Screen,1916,USA,"Short, Comedy, Romance",Charles Chaplin,30,http://ia.media-imdb.com/images/M/MV5BMTkyNDYyNTczNF5BMl5BanBnXkFtZTgwMDU2MzAwMzE@._V1_SX300.jpg 3 | 68646,The Godfather,1972,USA,"Crime, Drama",Francis Ford Coppola,175,http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg 4 | 113277,Heat,1995,USA,"Action, Crime, Drama",Michael Mann,170,http://ia.media-imdb.com/images/M/MV5BMTM1NDc4ODkxNV5BMl5BanBnXkFtZTcwNTI4ODE3MQ@@._V1_SX300.jpg 5 | 1798709,Her,2013,USA,"Drama, Romance, Sci-Fi",Spike Jonze,126,http://ia.media-imdb.com/images/M/MV5BMjA1Nzk0OTM2OF5BMl5BanBnXkFtZTgwNjU2NjEwMDE@._V1_SX300.jpg 6 | 790636,Dallas Buyers Club,2013,USA,"Biography, Drama",Jean-Marc Vallée,117,N/A -------------------------------------------------------------------------------- /StepOneStarterProgram/data/ratings_short.csv: -------------------------------------------------------------------------------- 1 | rater_id,movie_id,rating,time 2 | 1,0068646,10,1381620027 3 | 1,0113277,10,1379466669 4 | 2,1798709,10,1389948338 5 | 2,0790636,7,1389963947 6 | 2,0068646,9,1382460093 7 | 3,1798709,9,1388641438 8 | 4,0068646,8,1362440416 9 | 4,1798709,6,1398043318 10 | 5,0068646,9,1364834910 11 | 5,1798709,8,1404338202 12 | -------------------------------------------------------------------------------- /StepOneStarterProgram/out/production/StepOneStarterProgram/FirstRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepOneStarterProgram/out/production/StepOneStarterProgram/FirstRatings.class -------------------------------------------------------------------------------- /StepOneStarterProgram/out/production/StepOneStarterProgram/Movie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepOneStarterProgram/out/production/StepOneStarterProgram/Movie.class -------------------------------------------------------------------------------- /StepOneStarterProgram/out/production/StepOneStarterProgram/Rater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepOneStarterProgram/out/production/StepOneStarterProgram/Rater.class -------------------------------------------------------------------------------- /StepOneStarterProgram/out/production/StepOneStarterProgram/Rating.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepOneStarterProgram/out/production/StepOneStarterProgram/Rating.class -------------------------------------------------------------------------------- /StepOneStarterProgram/out/production/StepOneStarterProgram/StepOneStarterProgram.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepOneStarterProgram/out/production/StepOneStarterProgram/data/ratedmovies_short.csv: -------------------------------------------------------------------------------- 1 | id,title,year,country,genre,director,minutes,poster 2 | 6414,Behind the Screen,1916,USA,"Short, Comedy, Romance",Charles Chaplin,30,http://ia.media-imdb.com/images/M/MV5BMTkyNDYyNTczNF5BMl5BanBnXkFtZTgwMDU2MzAwMzE@._V1_SX300.jpg 3 | 68646,The Godfather,1972,USA,"Crime, Drama",Francis Ford Coppola,175,http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg 4 | 113277,Heat,1995,USA,"Action, Crime, Drama",Michael Mann,170,http://ia.media-imdb.com/images/M/MV5BMTM1NDc4ODkxNV5BMl5BanBnXkFtZTcwNTI4ODE3MQ@@._V1_SX300.jpg 5 | 1798709,Her,2013,USA,"Drama, Romance, Sci-Fi",Spike Jonze,126,http://ia.media-imdb.com/images/M/MV5BMjA1Nzk0OTM2OF5BMl5BanBnXkFtZTgwNjU2NjEwMDE@._V1_SX300.jpg 6 | 790636,Dallas Buyers Club,2013,USA,"Biography, Drama",Jean-Marc Vallée,117,N/A -------------------------------------------------------------------------------- /StepOneStarterProgram/out/production/StepOneStarterProgram/data/ratings_short.csv: -------------------------------------------------------------------------------- 1 | rater_id,movie_id,rating,time 2 | 1,0068646,10,1381620027 3 | 1,0113277,10,1379466669 4 | 2,1798709,10,1389948338 5 | 2,0790636,7,1389963947 6 | 2,0068646,9,1382460093 7 | 3,1798709,9,1388641438 8 | 4,0068646,8,1362440416 9 | 4,1798709,6,1398043318 10 | 5,0068646,9,1364834910 11 | 5,1798709,8,1404338202 12 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/AllFilters.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 12th, 2019 7 | * 8 | * Description: -------------------STEP THREE------------------------- 9 | * Now use the AllFilters class to combine asking questions 10 | * about average ratings by genre and films on or after a 11 | * particular year. 12 | * 13 | ****************************************************************/ 14 | 15 | public class AllFilters implements Filter { 16 | ArrayList filters; 17 | 18 | public AllFilters() { 19 | filters = new ArrayList(); 20 | } 21 | 22 | public void addFilter(Filter f) { 23 | filters.add(f); 24 | } 25 | 26 | @Override 27 | public boolean satisfies(String id) { 28 | for (Filter f : filters) { 29 | if (!f.satisfies(id)) { 30 | return false; 31 | } 32 | } 33 | return true; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/DirectorsFilter.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 12th, 2019 5 | * 6 | * Description: -------------------STEP THREE------------------------- 7 | * Create a new class named DirectorsFilter that implements Filter. 8 | * The constructor should have one parameter named directors 9 | * representing a list of directors separated by commas. 10 | * 11 | * (Example: "Charles Chaplin,Michael Mann,Spike Jonze", 12 | * and its satisfies method should return true if a movie has 13 | * at least one of these directors as one of its directors. 14 | * Note that each movie may have several directors. 15 | * 16 | ****************************************************************/ 17 | public class DirectorsFilter implements Filter { 18 | private String directors; 19 | 20 | public DirectorsFilter(String directors) { 21 | this.directors = directors; 22 | } 23 | 24 | @Override 25 | public boolean satisfies(String id) { 26 | String[] dir = directors.split(","); 27 | //boolean exist = false; 28 | for (String i : dir) { 29 | //System.out.println(id + " : " + MovieDatabase.getDirector(id) + " : " + MovieDatabase.getTitle(id)); 30 | if (MovieDatabase.getDirector(id).contains(i)) { 31 | return true; 32 | //break; 33 | } 34 | } 35 | return false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/EfficientRater.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.HashMap; 3 | 4 | /*************************************************************************** 5 | * Name: Wei Xu 6 | * 7 | * Date: Dec 12th, 2019 8 | * 9 | * Description: -------------------STEP Three---------------------------- 10 | * Create a new class named EfficientRater, and copy the 11 | * PlainRater class into this class. You will make several 12 | * changes to this class, including: 13 | * 14 | * Change the ArrayList of type Rating private variable to a 15 | * HashMap. The key in the HashMap is a movie ID, 16 | * and its value is a rating associated with this movie. 17 | * You will need to change addRating to instead add a new Rating 18 | * to the HashMap with the value associated with the movie ID 19 | * String item as the key in the HashMap. The method hasRating 20 | * should now be much shorter; it no longer needs a loop. 21 | * More method need change....... 22 | * 23 | ***************************************************************************/ 24 | public class EfficientRater implements Rater { 25 | private String myID; 26 | /* Change the ArrayList of type Rating private variable to a HashMap. 27 | The key in the HashMap is a movie ID, and 28 | its value is a rating associated with this movie.*/ 29 | //private HashMap> myRatings;//why not this one? 30 | private HashMap myRatings; 31 | 32 | public EfficientRater(String id) { 33 | myID = id; 34 | myRatings = new HashMap<>(); 35 | } 36 | 37 | public void addRating(String item, double rating) { 38 | myRatings.put(item, new Rating(item, rating));//item is string id? 39 | } 40 | 41 | public boolean hasRating(String item) { 42 | return myRatings.containsKey(item); 43 | } 44 | 45 | public String getID() { 46 | return myID; 47 | } 48 | 49 | public double getRating(String item) { 50 | // for (int k = 0; k < myRatings.size(); k++) { 51 | // if (myRatings.get(k).getItem().equals(item)) { 52 | // return myRatings.get(k).getValue(); 53 | // } 54 | // } 55 | if (myRatings.containsKey(item)) { 56 | return myRatings.get(item).getValue(); 57 | } 58 | return -1; 59 | } 60 | 61 | public int numRatings() { 62 | return myRatings.size(); 63 | } 64 | 65 | public ArrayList getItemsRated() { 66 | ArrayList list = new ArrayList<>(myRatings.keySet()); 67 | // for (int k = 0; k < myRatings.size(); k++) { 68 | // list.add(myRatings.get(k).getItem()); 69 | // } 70 | // 71 | return list;//arrayList of item; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/Filter.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 12th, 2019 5 | * 6 | * Description: -------------------STEP THREE-------- 7 | * The interface Filter has only one signature for 8 | * the method satisfies. Any filters that implement 9 | * this interface must also have this method. 10 | * The method satisfies has one String parameter 11 | * named id representing a movie ID. This method returns 12 | * true if the movie satisfies the criteria in the method 13 | * and returns false otherwise. 14 | * 15 | ****************************************************************/ 16 | 17 | public interface Filter { 18 | public boolean satisfies(String id); 19 | } 20 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/GenreFilter.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 12th, 2019 5 | * 6 | * Description: -------------------STEP THREE------------------------- 7 | * Create a new class named GenreFilter that implements Filter. 8 | * The constructor should have one parameter named genre 9 | * representing one genre, and the satisfies method should 10 | * return true if a movie has this genre. Note that movies 11 | * may have several genres. 12 | * 13 | ****************************************************************/ 14 | 15 | public class GenreFilter implements Filter { 16 | private String genre; 17 | 18 | public GenreFilter(String genre) { 19 | this.genre = genre; 20 | } 21 | 22 | @Override 23 | public boolean satisfies(String id) { 24 | return MovieDatabase.getGenres(id).contains(genre); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/MinutesFilter.java: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Name: Wei Xu 3 | * 4 | * Date: Dec 12th, 2019 5 | * 6 | * Description: -------------------STEP THREE------------------------- 7 | * Create a new class named MinutesFilter that implements Filter. 8 | * Its satisfies method should return true if a movie’s running time 9 | * is at least min minutes and no more than max minutes. 10 | * 11 | ****************************************************************/ 12 | public class MinutesFilter implements Filter { 13 | private int min; 14 | private int max; 15 | 16 | 17 | public MinutesFilter(int min, int max) { 18 | this.min = min; 19 | this.max = max; 20 | } 21 | 22 | @Override 23 | public boolean satisfies(String id) { 24 | return MovieDatabase.getMinutes(id) >= min && MovieDatabase.getMinutes(id) <= max; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/Movie.java: -------------------------------------------------------------------------------- 1 | //Plain Old Java Object (POJO) class for storing the data about one movie 2 | // An immutable passive data object (PDO) to represent item data 3 | public class Movie { 4 | private String id; 5 | private String title; 6 | private int year; 7 | private String genres; 8 | private String director; 9 | private String country; 10 | private String poster; 11 | private int minutes; 12 | 13 | public Movie(String anID, String aTitle, String aYear, String theGenres) { 14 | // just in case data file contains extra whitespace 15 | id = anID.trim(); 16 | title = aTitle.trim(); 17 | year = Integer.parseInt(aYear.trim()); 18 | genres = theGenres; 19 | } 20 | 21 | public Movie(String anID, String aTitle, String aYear, String theGenres, String aDirector, 22 | String aCountry, String aPoster, int theMinutes) { 23 | // just in case data file contains extra whitespace 24 | id = anID.trim(); 25 | title = aTitle.trim(); 26 | year = Integer.parseInt(aYear.trim()); 27 | genres = theGenres; 28 | director = aDirector; 29 | country = aCountry; 30 | poster = aPoster; 31 | minutes = theMinutes; 32 | } 33 | 34 | // Returns ID associated with this item 35 | public String getID() { 36 | return id; 37 | } 38 | 39 | // Returns title of this item 40 | public String getTitle() { 41 | return title; 42 | } 43 | 44 | // Returns year in which this item was published 45 | public int getYear() { 46 | return year; 47 | } 48 | 49 | // Returns genres associated with this item 50 | public String getGenres() { 51 | return genres; 52 | } 53 | 54 | public String getCountry() { 55 | return country; 56 | } 57 | 58 | public String getDirector() { 59 | return director; 60 | } 61 | 62 | public String getPoster() { 63 | return poster; 64 | } 65 | 66 | public int getMinutes() { 67 | return minutes; 68 | } 69 | 70 | // Returns a string of the item's information 71 | public String toString() { 72 | String result = "Movie [id=" + id + ", title=" + title + ", year=" + year; 73 | result += ", genres= " + genres + "]"; 74 | return result; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/MovieDatabase.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.HashMap; 3 | 4 | /*************************************************************** 5 | * Name: Wei Xu 6 | * 7 | * Date: Dec 12th, 2019 8 | * 9 | * Description: -------------------STEP THREE-------- 10 | * The class MovieDatabase—This class is an efficient way to get 11 | * information about movies. It stores movie information in a HashMap 12 | * for fast lookup of movie information given a movie ID. 13 | * The class also allows filtering movies based on queries. All methods 14 | * and fields in the class are static. 15 | * This means you'll be able to access methods in MovieDatabase 16 | * without using new to create objects, but by calling methods like 17 | * MovieDatabase.getMovie("0120915"). 18 | * 19 | ****************************************************************/ 20 | public class MovieDatabase { 21 | private static HashMap ourMovies; 22 | //before it's an Arraylist 23 | 24 | public static void initialize(String moviefile) { 25 | if (ourMovies == null) { 26 | ourMovies = new HashMap(); 27 | loadMovies("data/" + moviefile); 28 | } 29 | } 30 | 31 | private static void initialize() { 32 | if (ourMovies == null) { 33 | ourMovies = new HashMap(); 34 | loadMovies("data/ratedmoviesfull.csv"); 35 | } 36 | } 37 | 38 | private static void loadMovies(String filename) { 39 | FirstRatings fr = new FirstRatings(); 40 | ArrayList list = fr.loadMovies(filename); 41 | for (Movie m : list) { 42 | ourMovies.put(m.getID(), m); 43 | } 44 | } 45 | 46 | public static boolean containsID(String id) { 47 | initialize(); 48 | return ourMovies.containsKey(id); 49 | } 50 | 51 | public static int getYear(String id) { 52 | initialize(); 53 | return ourMovies.get(id).getYear(); 54 | } 55 | 56 | public static String getGenres(String id) { 57 | initialize(); 58 | return ourMovies.get(id).getGenres(); 59 | } 60 | 61 | public static String getTitle(String id) { 62 | initialize(); 63 | return ourMovies.get(id).getTitle(); 64 | } 65 | 66 | public static Movie getMovie(String id) { 67 | initialize(); 68 | return ourMovies.get(id); 69 | } 70 | 71 | public static String getPoster(String id) { 72 | initialize(); 73 | return ourMovies.get(id).getPoster(); 74 | } 75 | 76 | public static int getMinutes(String id) { 77 | initialize(); 78 | return ourMovies.get(id).getMinutes(); 79 | } 80 | 81 | public static String getCountry(String id) { 82 | initialize(); 83 | return ourMovies.get(id).getCountry(); 84 | } 85 | 86 | public static String getDirector(String id) { 87 | initialize(); 88 | return ourMovies.get(id).getDirector(); 89 | } 90 | 91 | public static int size() { 92 | return ourMovies.size(); 93 | } 94 | 95 | // why no need implement filter? 96 | public static ArrayList filterBy(Filter f) { 97 | initialize(); 98 | ArrayList list = new ArrayList(); 99 | for (String id : ourMovies.keySet()) { 100 | if (f.satisfies(id)) { 101 | list.add(id); 102 | } 103 | } 104 | return list;//ArrayList of movie id 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/MovieRunnerAverage.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collections; 3 | 4 | /*************************************************************** 5 | * Name: Wei Xu 6 | * 7 | * Date: Dec 11th, 2019 8 | * 9 | * Description: -------------------STEP TWO------------------------- 10 | * You will build on this assignment by calculating 11 | * average ratings of movies. 12 | * In this assignment you will modify a new class named SecondRatings, 13 | * which has been started for you, to do many of the calculations 14 | * focusing on computing averages on movie ratings. 15 | * You will also create a second new class named MovieRunnerAverage, 16 | * which you will use to test the methods you created in SecondRatings 17 | * by creating a SecondRatings object in MovieRunnerAverage and 18 | * calling its methods. 19 | * 20 | ****************************************************************/ 21 | public class MovieRunnerAverage { 22 | public void printAverageRatings() { 23 | SecondRatings sr = new SecondRatings("data/ratedmovies_short.csv", "data/ratings_short.csv");//do i need put filename here? 24 | System.out.println("Movie size = " + sr.getMovieSize()); 25 | System.out.println("Rater size = " + sr.getRaterSize()); 26 | ArrayList ratingList = sr.getAverageRatings(2); 27 | Collections.sort(ratingList); 28 | for (Rating i : ratingList) { 29 | System.out.printf("%-10.2f%s%n", i.getValue(), sr.getTitle(i.getItem())); 30 | } 31 | } 32 | 33 | public void getAverageRatingOneMovie() { 34 | SecondRatings sr = new SecondRatings("data/ratedmovies_short.csv", "data/ratings_short.csv");//do i need put filename here? 35 | ArrayList ratingList = sr.getAverageRatings(2); 36 | String movieTitle = "The Godfather"; 37 | for (Rating i : ratingList) { 38 | if (sr.getTitle(i.getItem()).equals(movieTitle)) { 39 | System.out.printf("%-10.2f%s%n", i.getValue(), sr.getTitle(i.getItem())); 40 | } 41 | } 42 | } 43 | 44 | public static void main(String[] args) { 45 | MovieRunnerAverage mra = new MovieRunnerAverage(); 46 | System.out.println("---------------print test----------------"); 47 | mra.printAverageRatings(); 48 | System.out.println("---------------get average rating one movie test----------------"); 49 | mra.getAverageRatingOneMovie(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/PlainRater.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 12th, 2019 7 | * 8 | * Description: -------------------STEP Three-------- 9 | * Change the name of the class Rater.java to PlainRater.java. 10 | * Be sure to compile it to make sure your newly named class 11 | * works—that you've made the changes necessary for the class 12 | * to function with the name PlainRater. 13 | * 14 | ***************************************************************************/ 15 | public class PlainRater implements Rater { 16 | private String myID; 17 | private ArrayList myRatings; 18 | 19 | public PlainRater(String id) { 20 | myID = id; 21 | myRatings = new ArrayList(); 22 | } 23 | 24 | public void addRating(String item, double rating) { 25 | myRatings.add(new Rating(item, rating));//item is string id? 26 | } 27 | 28 | public boolean hasRating(String item) { 29 | for (int k = 0; k < myRatings.size(); k++) { 30 | if (myRatings.get(k).getItem().equals(item)) { 31 | return true; 32 | } 33 | } 34 | 35 | return false; 36 | } 37 | 38 | public String getID() { 39 | return myID; 40 | } 41 | 42 | public double getRating(String item) { 43 | for (int k = 0; k < myRatings.size(); k++) { 44 | if (myRatings.get(k).getItem().equals(item)) { 45 | return myRatings.get(k).getValue(); 46 | } 47 | } 48 | 49 | return -1; 50 | } 51 | 52 | public int numRatings() { 53 | return myRatings.size(); 54 | } 55 | 56 | public ArrayList getItemsRated() { 57 | ArrayList list = new ArrayList(); 58 | for (int k = 0; k < myRatings.size(); k++) { 59 | list.add(myRatings.get(k).getItem()); 60 | } 61 | 62 | return list;//arrayList of item; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/Rater.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 12th, 2019 7 | * 8 | * Description: -------------------STEP Three-------- 9 | * Create a new public interface named Rater. Add methods to 10 | * this new interface by copying all the method signatures 11 | * from the PlainRater class. 12 | * 13 | ***************************************************************************/ 14 | 15 | public interface Rater { 16 | public void addRating(String item, double rating); 17 | 18 | public boolean hasRating(String item); 19 | 20 | public String getID(); 21 | 22 | public double getRating(String item); 23 | 24 | public int numRatings(); 25 | 26 | public ArrayList getItemsRated(); 27 | } 28 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/Rating.java: -------------------------------------------------------------------------------- 1 | //a POJO class for storing the data about one rating of an item 2 | // An immutable passive data object (PDO) to represent the rating data 3 | public class Rating implements Comparable { 4 | private String item; 5 | private double value; 6 | 7 | public Rating(String anItem, double aValue) { 8 | item = anItem;//IMDB id 9 | value = aValue; 10 | } 11 | 12 | // Returns item being rated 13 | public String getItem() { 14 | return item; 15 | } 16 | 17 | // Returns the value of this rating (as a number so it can be used in calculations) 18 | public double getValue() { 19 | return value; 20 | } 21 | 22 | // Returns a string of all the rating information 23 | public String toString() { 24 | return "[" + getItem() + ", " + getValue() + "]"; 25 | } 26 | 27 | public int compareTo(Rating other) { 28 | if (value < other.value) return -1; 29 | if (value > other.value) return 1; 30 | 31 | return 0; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/SecondRatings.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 11th, 2019 7 | * 8 | * Description: -------------------STEP TWO------------------------- 9 | * You will build on this assignment by calculating 10 | * average ratings of movies. 11 | * In this assignment you will modify a new class named SecondRatings, 12 | * which has been started for you, to do many of the calculations 13 | * focusing on computing averages on movie ratings. 14 | * You will also create a second new class named MovieRunnerAverage, 15 | * which you will use to test the methods you created in SecondRatings 16 | * by creating a SecondRatings object in MovieRunnerAverage and 17 | * calling its methods. 18 | * 19 | ****************************************************************/ 20 | public class SecondRatings { 21 | 22 | private ArrayList myMovies; 23 | private ArrayList myRaters; 24 | 25 | public SecondRatings() { 26 | // default constructor 27 | this("ratedmoviesfull.csv", "ratings.csv"); 28 | } 29 | //---------------todo: why only above won't compile???------------- 30 | 31 | public SecondRatings(String movieFile, String ratingFile) { 32 | FirstRatings a = new FirstRatings(); 33 | myMovies = a.loadMovies(movieFile); 34 | myRaters = a.loadRaters(ratingFile); 35 | } 36 | 37 | public int getMovieSize() { 38 | return myMovies.size(); 39 | } 40 | 41 | public int getRaterSize() { 42 | return myRaters.size(); 43 | } 44 | 45 | //private helper method 46 | private double getAverageByID(String movieID, int minimalRaters) { 47 | int count = 0; 48 | double total = 0; 49 | for (Rater i : myRaters) { 50 | // if (i.hasRating(movieID)) { 51 | double rating = i.getRating(movieID); 52 | if (rating != -1) { 53 | count++; 54 | total += rating; 55 | // System.out.println(count + " : " + "id = " + i.getID() + " rating " + rating + " ave " + total); 56 | } 57 | } 58 | //System.out.println("Movie ID = " + movieID + " : " + count + " : " + total + " : " + total / count); 59 | if (count >= minimalRaters) return total / count; 60 | return 0.0; 61 | } 62 | 63 | public ArrayList getAverageRatings(int minimalRaters) { 64 | ArrayList ratingList = new ArrayList<>(); 65 | for (Movie i : myMovies) { 66 | double ave = getAverageByID(i.getID(), minimalRaters); 67 | if (ave > 0) 68 | ratingList.add(new Rating(i.getID(), ave));//item is string id? 69 | } 70 | return ratingList; 71 | } 72 | 73 | public String getTitle(String movieID) { 74 | for (Movie i : myMovies) { 75 | if (i.getID().equals(movieID)) { 76 | return i.getTitle(); 77 | } 78 | } 79 | return "The Movie ID was not found!"; 80 | } 81 | 82 | public String getID(String title) { 83 | for (Movie i : myMovies) { 84 | if (i.getTitle().equals(title)) { 85 | return i.getID(); 86 | } 87 | } 88 | return "NO SUCH TITLE"; 89 | } 90 | 91 | public static void main(String[] args) { 92 | SecondRatings sr = new SecondRatings("data/ratedmovies_short.csv", "data/ratings_short.csv"); 93 | //System.out.println(sr.getAverageByID("0790636", 2)); 94 | System.out.println("---------------test-------------"); 95 | System.out.println(sr.getAverageRatings(2)); 96 | //[[6414, 0.0], [68646, 0.0], [113277, 0.0], [1798709, 8.25], [790636, 0.0]] 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/StepOneStarterProgram.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/StepThree-Interfaces, Filters, Database.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/StepTwo-Simple Recommendations.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/TrueFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The class TrueFilter can be used to select every movie from 3 | * MovieDatabase. It’s satisfies method always returns true. 4 | */ 5 | public class TrueFilter implements Filter { 6 | @Override 7 | public boolean satisfies(String id) { 8 | return true; 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/YearAfterFilter.java: -------------------------------------------------------------------------------- 1 | 2 | public class YearAfterFilter implements Filter { 3 | private int myYear; 4 | 5 | public YearAfterFilter(int year) { 6 | myYear = year; 7 | } 8 | 9 | @Override 10 | public boolean satisfies(String id) { 11 | return MovieDatabase.getYear(id) >= myYear; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/data/ratedmovies_short.csv: -------------------------------------------------------------------------------- 1 | id,title,year,country,genre,director,minutes,poster 2 | 0006414,Behind the Screen,1916,USA,"Short, Comedy, Romance",Charles Chaplin,30,http://ia.media-imdb.com/images/M/MV5BMTkyNDYyNTczNF5BMl5BanBnXkFtZTgwMDU2MzAwMzE@._V1_SX300.jpg 3 | 0068646,The Godfather,1972,USA,"Crime, Drama",Francis Ford Coppola,175,http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg 4 | 0113277,Heat,1995,USA,"Action, Crime, Drama",Michael Mann,170,http://ia.media-imdb.com/images/M/MV5BMTM1NDc4ODkxNV5BMl5BanBnXkFtZTcwNTI4ODE3MQ@@._V1_SX300.jpg 5 | 1798709,Her,2013,USA,"Drama, Romance, Sci-Fi",Spike Jonze,126,http://ia.media-imdb.com/images/M/MV5BMjA1Nzk0OTM2OF5BMl5BanBnXkFtZTgwNjU2NjEwMDE@._V1_SX300.jpg 6 | 0790636,Dallas Buyers Club,2013,USA,"Biography, Drama",Jean-Marc Vallée,117,N/A -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/data/ratings_short.csv: -------------------------------------------------------------------------------- 1 | rater_id,movie_id,rating,time 2 | 1,0068646,10,1381620027 3 | 1,0113277,10,1379466669 4 | 2,1798709,10,1389948338 5 | 2,0790636,7,1389963947 6 | 2,0068646,9,1382460093 7 | 3,1798709,9,1388641438 8 | 4,0068646,8,1362440416 9 | 4,1798709,6,1398043318 10 | 5,0068646,9,1364834910 11 | 5,1798709,8,1404338202 -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/FirstRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/FirstRatings.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/Movie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/Movie.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/MovieRunnerAverage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/MovieRunnerAverage.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/Rater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/Rater.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/Rating.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/Rating.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/SecondRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/SecondRatings.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/StepOneStarterProgram.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/data/ratedmovies_short.csv: -------------------------------------------------------------------------------- 1 | id,title,year,country,genre,director,minutes,poster 2 | 0006414,Behind the Screen,1916,USA,"Short, Comedy, Romance",Charles Chaplin,30,http://ia.media-imdb.com/images/M/MV5BMTkyNDYyNTczNF5BMl5BanBnXkFtZTgwMDU2MzAwMzE@._V1_SX300.jpg 3 | 0068646,The Godfather,1972,USA,"Crime, Drama",Francis Ford Coppola,175,http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg 4 | 0113277,Heat,1995,USA,"Action, Crime, Drama",Michael Mann,170,http://ia.media-imdb.com/images/M/MV5BMTM1NDc4ODkxNV5BMl5BanBnXkFtZTcwNTI4ODE3MQ@@._V1_SX300.jpg 5 | 1798709,Her,2013,USA,"Drama, Romance, Sci-Fi",Spike Jonze,126,http://ia.media-imdb.com/images/M/MV5BMjA1Nzk0OTM2OF5BMl5BanBnXkFtZTgwNjU2NjEwMDE@._V1_SX300.jpg 6 | 0790636,Dallas Buyers Club,2013,USA,"Biography, Drama",Jean-Marc Vallée,117,N/A -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepOneStarterProgram/data/ratings_short.csv: -------------------------------------------------------------------------------- 1 | rater_id,movie_id,rating,time 2 | 1,0068646,10,1381620027 3 | 1,0113277,10,1379466669 4 | 2,1798709,10,1389948338 5 | 2,0790636,7,1389963947 6 | 2,0068646,9,1382460093 7 | 3,1798709,9,1388641438 8 | 4,0068646,8,1362440416 9 | 4,1798709,6,1398043318 10 | 5,0068646,9,1364834910 11 | 5,1798709,8,1404338202 12 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/AllFilters.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/AllFilters.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/DirectorsFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/DirectorsFilter.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/EfficientRater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/EfficientRater.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/Filter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/Filter.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/FirstRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/FirstRatings.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/GenreFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/GenreFilter.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/MinutesFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/MinutesFilter.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/Movie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/Movie.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/MovieDatabase.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/MovieDatabase.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/MovieRunnerAverage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/MovieRunnerAverage.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/MovieRunnerWithFilters.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/MovieRunnerWithFilters.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/PlainRater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/PlainRater.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/Rater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/Rater.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/Rating.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/Rating.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/SecondRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/SecondRatings.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/StepOneStarterProgram.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/StepThree-Interfaces, Filters, Database.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/StepTwo-Simple Recommendations.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/ThirdRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/ThirdRatings.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/TrueFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/TrueFilter.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/YearAfterFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/YearAfterFilter.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/data/ratedmovies_short.csv: -------------------------------------------------------------------------------- 1 | id,title,year,country,genre,director,minutes,poster 2 | 0006414,Behind the Screen,1916,USA,"Short, Comedy, Romance",Charles Chaplin,30,http://ia.media-imdb.com/images/M/MV5BMTkyNDYyNTczNF5BMl5BanBnXkFtZTgwMDU2MzAwMzE@._V1_SX300.jpg 3 | 0068646,The Godfather,1972,USA,"Crime, Drama",Francis Ford Coppola,175,http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg 4 | 0113277,Heat,1995,USA,"Action, Crime, Drama",Michael Mann,170,http://ia.media-imdb.com/images/M/MV5BMTM1NDc4ODkxNV5BMl5BanBnXkFtZTcwNTI4ODE3MQ@@._V1_SX300.jpg 5 | 1798709,Her,2013,USA,"Drama, Romance, Sci-Fi",Spike Jonze,126,http://ia.media-imdb.com/images/M/MV5BMjA1Nzk0OTM2OF5BMl5BanBnXkFtZTgwNjU2NjEwMDE@._V1_SX300.jpg 6 | 0790636,Dallas Buyers Club,2013,USA,"Biography, Drama",Jean-Marc Vallée,117,N/A -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/data/ratings_short.csv: -------------------------------------------------------------------------------- 1 | rater_id,movie_id,rating,time 2 | 1,0068646,10,1381620027 3 | 1,0113277,10,1379466669 4 | 2,1798709,10,1389948338 5 | 2,0790636,7,1389963947 6 | 2,0068646,9,1382460093 7 | 3,1798709,9,1388641438 8 | 4,0068646,8,1362440416 9 | 4,1798709,6,1398043318 10 | 5,0068646,9,1364834910 11 | 5,1798709,8,1404338202 -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/output1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepThree-Interfaces, Filters, Database/output1.png -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/FirstRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/FirstRatings.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/Movie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/Movie.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/MovieRunnerAverage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/MovieRunnerAverage.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/Rater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/Rater.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/Rating.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/Rating.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/SecondRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/SecondRatings.class -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/StepOneStarterProgram.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/StepTwo-Simple Recommendations.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/data/ratedmovies_short.csv: -------------------------------------------------------------------------------- 1 | id,title,year,country,genre,director,minutes,poster 2 | 0006414,Behind the Screen,1916,USA,"Short, Comedy, Romance",Charles Chaplin,30,http://ia.media-imdb.com/images/M/MV5BMTkyNDYyNTczNF5BMl5BanBnXkFtZTgwMDU2MzAwMzE@._V1_SX300.jpg 3 | 0068646,The Godfather,1972,USA,"Crime, Drama",Francis Ford Coppola,175,http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg 4 | 0113277,Heat,1995,USA,"Action, Crime, Drama",Michael Mann,170,http://ia.media-imdb.com/images/M/MV5BMTM1NDc4ODkxNV5BMl5BanBnXkFtZTcwNTI4ODE3MQ@@._V1_SX300.jpg 5 | 1798709,Her,2013,USA,"Drama, Romance, Sci-Fi",Spike Jonze,126,http://ia.media-imdb.com/images/M/MV5BMjA1Nzk0OTM2OF5BMl5BanBnXkFtZTgwNjU2NjEwMDE@._V1_SX300.jpg 6 | 0790636,Dallas Buyers Club,2013,USA,"Biography, Drama",Jean-Marc Vallée,117,N/A -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/out/production/StepTwo-Simple Recommendations/data/ratings_short.csv: -------------------------------------------------------------------------------- 1 | rater_id,movie_id,rating,time 2 | 1,0068646,10,1381620027 3 | 1,0113277,10,1379466669 4 | 2,1798709,10,1389948338 5 | 2,0790636,7,1389963947 6 | 2,0068646,9,1382460093 7 | 3,1798709,9,1388641438 8 | 4,0068646,8,1362440416 9 | 4,1798709,6,1398043318 10 | 5,0068646,9,1364834910 11 | 5,1798709,8,1404338202 12 | -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/output1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/output1.png -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/output2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/output2.png -------------------------------------------------------------------------------- /StepThree-Interfaces, Filters, Database/output3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepThree-Interfaces, Filters, Database/output3.png -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/Movie.java: -------------------------------------------------------------------------------- 1 | //Plain Old Java Object (POJO) class for storing the data about one movie 2 | // An immutable passive data object (PDO) to represent item data 3 | public class Movie { 4 | private String id; 5 | private String title; 6 | private int year; 7 | private String genres; 8 | private String director; 9 | private String country; 10 | private String poster; 11 | private int minutes; 12 | 13 | public Movie(String anID, String aTitle, String aYear, String theGenres) { 14 | // just in case data file contains extra whitespace 15 | id = anID.trim(); 16 | title = aTitle.trim(); 17 | year = Integer.parseInt(aYear.trim()); 18 | genres = theGenres; 19 | } 20 | 21 | public Movie(String anID, String aTitle, String aYear, String theGenres, String aDirector, 22 | String aCountry, String aPoster, int theMinutes) { 23 | // just in case data file contains extra whitespace 24 | id = anID.trim(); 25 | title = aTitle.trim(); 26 | year = Integer.parseInt(aYear.trim()); 27 | genres = theGenres; 28 | director = aDirector; 29 | country = aCountry; 30 | poster = aPoster; 31 | minutes = theMinutes; 32 | } 33 | 34 | // Returns ID associated with this item 35 | public String getID() { 36 | return id; 37 | } 38 | 39 | // Returns title of this item 40 | public String getTitle() { 41 | return title; 42 | } 43 | 44 | // Returns year in which this item was published 45 | public int getYear() { 46 | return year; 47 | } 48 | 49 | // Returns genres associated with this item 50 | public String getGenres() { 51 | return genres; 52 | } 53 | 54 | public String getCountry() { 55 | return country; 56 | } 57 | 58 | public String getDirector() { 59 | return director; 60 | } 61 | 62 | public String getPoster() { 63 | return poster; 64 | } 65 | 66 | public int getMinutes() { 67 | return minutes; 68 | } 69 | 70 | // Returns a string of the item's information 71 | public String toString() { 72 | String result = "Movie [id=" + id + ", title=" + title + ", year=" + year; 73 | result += ", genres= " + genres + "]"; 74 | return result; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/MovieRunnerAverage.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collections; 3 | 4 | /*************************************************************** 5 | * Name: Wei Xu 6 | * 7 | * Date: Dec 11th, 2019 8 | * 9 | * Description: -------------------STEP TWO------------------------- 10 | * You will build on this assignment by calculating 11 | * average ratings of movies. 12 | * In this assignment you will modify a new class named SecondRatings, 13 | * which has been started for you, to do many of the calculations 14 | * focusing on computing averages on movie ratings. 15 | * You will also create a second new class named MovieRunnerAverage, 16 | * which you will use to test the methods you created in SecondRatings 17 | * by creating a SecondRatings object in MovieRunnerAverage and 18 | * calling its methods. 19 | * 20 | ****************************************************************/ 21 | public class MovieRunnerAverage { 22 | public void printAverageRatings() { 23 | SecondRatings sr = new SecondRatings("data/ratedmovies_short.csv", "data/ratings_short.csv");//do i need put filename here? 24 | System.out.println("Movie size = " + sr.getMovieSize()); 25 | System.out.println("Rater size = " + sr.getRaterSize()); 26 | ArrayList ratingList = sr.getAverageRatings(2); 27 | Collections.sort(ratingList); 28 | for (Rating i : ratingList) { 29 | System.out.printf("%-10.2f%s%n", i.getValue(), sr.getTitle(i.getItem())); 30 | } 31 | } 32 | 33 | public void getAverageRatingOneMovie() { 34 | SecondRatings sr = new SecondRatings("data/ratedmovies_short.csv", "data/ratings_short.csv");//do i need put filename here? 35 | ArrayList ratingList = sr.getAverageRatings(2); 36 | String movieTitle = "The Godfather"; 37 | for (Rating i : ratingList) { 38 | if (sr.getTitle(i.getItem()).equals(movieTitle)) { 39 | System.out.printf("%-10.2f%s%n", i.getValue(), sr.getTitle(i.getItem())); 40 | } 41 | } 42 | 43 | } 44 | 45 | public static void main(String[] args) { 46 | MovieRunnerAverage mra = new MovieRunnerAverage(); 47 | System.out.println("---------------print test----------------"); 48 | mra.printAverageRatings(); 49 | System.out.println("---------------get average rating one movie test----------------"); 50 | mra.getAverageRatingOneMovie(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/Rater.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Write a description of class Rater here. 3 | * 4 | * @author (your name) 5 | * @version (a version number or a date) 6 | */ 7 | 8 | import java.util.ArrayList; 9 | 10 | public class Rater { 11 | private String myID; 12 | private ArrayList myRatings; 13 | 14 | public Rater(String id) { 15 | myID = id; 16 | myRatings = new ArrayList(); 17 | } 18 | 19 | public void addRating(String item, double rating) { 20 | myRatings.add(new Rating(item, rating));//item is string id? 21 | } 22 | 23 | public boolean hasRating(String item) { 24 | for (int k = 0; k < myRatings.size(); k++) { 25 | if (myRatings.get(k).getItem().equals(item)) { 26 | return true; 27 | } 28 | } 29 | 30 | return false; 31 | } 32 | 33 | public String getID() { 34 | return myID; 35 | } 36 | 37 | public double getRating(String item) { 38 | for (int k = 0; k < myRatings.size(); k++) { 39 | if (myRatings.get(k).getItem().equals(item)) { 40 | return myRatings.get(k).getValue(); 41 | } 42 | } 43 | 44 | return -1; 45 | } 46 | 47 | public int numRatings() { 48 | return myRatings.size(); 49 | } 50 | 51 | public ArrayList getItemsRated() { 52 | ArrayList list = new ArrayList(); 53 | for (int k = 0; k < myRatings.size(); k++) { 54 | list.add(myRatings.get(k).getItem()); 55 | } 56 | 57 | return list;//arrayList of item; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/Rating.java: -------------------------------------------------------------------------------- 1 | //a POJO class for storing the data about one rating of an item 2 | // An immutable passive data object (PDO) to represent the rating data 3 | public class Rating implements Comparable { 4 | private String item; 5 | private double value; 6 | 7 | public Rating(String anItem, double aValue) { 8 | item = anItem;//IMDB id 9 | value = aValue; 10 | } 11 | 12 | // Returns item being rated 13 | public String getItem() { 14 | return item; 15 | } 16 | 17 | // Returns the value of this rating (as a number so it can be used in calculations) 18 | public double getValue() { 19 | return value; 20 | } 21 | 22 | // Returns a string of all the rating information 23 | public String toString() { 24 | return "[" + getItem() + ", " + getValue() + "]"; 25 | } 26 | 27 | public int compareTo(Rating other) { 28 | if (value < other.value) return -1; 29 | if (value > other.value) return 1; 30 | 31 | return 0; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/SecondRatings.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | /*************************************************************** 4 | * Name: Wei Xu 5 | * 6 | * Date: Dec 11th, 2019 7 | * 8 | * Description: -------------------STEP TWO------------------------- 9 | * You will build on this assignment by calculating 10 | * average ratings of movies. 11 | * In this assignment you will modify a new class named SecondRatings, 12 | * which has been started for you, to do many of the calculations 13 | * focusing on computing averages on movie ratings. 14 | * You will also create a second new class named MovieRunnerAverage, 15 | * which you will use to test the methods you created in SecondRatings 16 | * by creating a SecondRatings object in MovieRunnerAverage and 17 | * calling its methods. 18 | * 19 | ****************************************************************/ 20 | public class SecondRatings { 21 | 22 | private ArrayList myMovies; 23 | private ArrayList myRaters; 24 | 25 | public SecondRatings() { 26 | // default constructor 27 | this("ratedmoviesfull.csv", "ratings.csv"); 28 | } 29 | //---------------todo: why only above won't compile???------------- 30 | 31 | public SecondRatings(String movieFile, String ratingFile) { 32 | FirstRatings a = new FirstRatings(); 33 | myMovies = a.loadMovies(movieFile); 34 | myRaters = a.loadRaters(ratingFile); 35 | } 36 | 37 | public int getMovieSize() { 38 | return myMovies.size(); 39 | } 40 | 41 | public int getRaterSize() { 42 | return myRaters.size(); 43 | } 44 | 45 | //private helper method 46 | private double getAverageByID(String movieID, int minimalRaters) { 47 | int count = 0; 48 | double total = 0; 49 | for (Rater i : myRaters) { 50 | // if (i.hasRating(movieID)) { 51 | double rating = i.getRating(movieID); 52 | if (rating != -1) { 53 | count++; 54 | total += rating; 55 | // System.out.println(count + " : " + "id = " + i.getID() + " rating " + rating + " ave " + total); 56 | } 57 | } 58 | //System.out.println("Movie ID = " + movieID + " : " + count + " : " + total + " : " + total / count); 59 | if (count >= minimalRaters) return total / count; 60 | return 0.0; 61 | } 62 | 63 | public ArrayList getAverageRatings(int minimalRaters) { 64 | ArrayList ratingList = new ArrayList<>(); 65 | for (Movie i : myMovies) { 66 | double ave = getAverageByID(i.getID(), minimalRaters); 67 | if (ave > 0) 68 | ratingList.add(new Rating(i.getID(), ave));//item is string id? 69 | } 70 | return ratingList; 71 | } 72 | 73 | public String getTitle(String movieID) { 74 | for (Movie i : myMovies) { 75 | if (i.getID().equals(movieID)) { 76 | return i.getTitle(); 77 | } 78 | } 79 | return "The Movie ID was not found!"; 80 | } 81 | 82 | public String getID(String title) { 83 | for (Movie i : myMovies) { 84 | if (i.getTitle().equals(title)) { 85 | return i.getID(); 86 | } 87 | } 88 | return "NO SUCH TITLE"; 89 | } 90 | 91 | public static void main(String[] args) { 92 | SecondRatings sr = new SecondRatings("data/ratedmovies_short.csv", "data/ratings_short.csv"); 93 | //System.out.println(sr.getAverageByID("0790636", 2)); 94 | System.out.println("---------------test-------------"); 95 | System.out.println(sr.getAverageRatings(2)); 96 | //[[6414, 0.0], [68646, 0.0], [113277, 0.0], [1798709, 8.25], [790636, 0.0]] 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/StepOneStarterProgram.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/StepTwo-Simple Recommendations.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/data/ratedmovies_short.csv: -------------------------------------------------------------------------------- 1 | id,title,year,country,genre,director,minutes,poster 2 | 0006414,Behind the Screen,1916,USA,"Short, Comedy, Romance",Charles Chaplin,30,http://ia.media-imdb.com/images/M/MV5BMTkyNDYyNTczNF5BMl5BanBnXkFtZTgwMDU2MzAwMzE@._V1_SX300.jpg 3 | 0068646,The Godfather,1972,USA,"Crime, Drama",Francis Ford Coppola,175,http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg 4 | 0113277,Heat,1995,USA,"Action, Crime, Drama",Michael Mann,170,http://ia.media-imdb.com/images/M/MV5BMTM1NDc4ODkxNV5BMl5BanBnXkFtZTcwNTI4ODE3MQ@@._V1_SX300.jpg 5 | 1798709,Her,2013,USA,"Drama, Romance, Sci-Fi",Spike Jonze,126,http://ia.media-imdb.com/images/M/MV5BMjA1Nzk0OTM2OF5BMl5BanBnXkFtZTgwNjU2NjEwMDE@._V1_SX300.jpg 6 | 0790636,Dallas Buyers Club,2013,USA,"Biography, Drama",Jean-Marc Vallée,117,N/A -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/data/ratings_short.csv: -------------------------------------------------------------------------------- 1 | rater_id,movie_id,rating,time 2 | 1,0068646,10,1381620027 3 | 1,0113277,10,1379466669 4 | 2,1798709,10,1389948338 5 | 2,0790636,7,1389963947 6 | 2,0068646,9,1382460093 7 | 3,1798709,9,1388641438 8 | 4,0068646,8,1362440416 9 | 4,1798709,6,1398043318 10 | 5,0068646,9,1364834910 11 | 5,1798709,8,1404338202 12 | -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/FirstRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/FirstRatings.class -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/Movie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/Movie.class -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/MovieRunnerAverage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/MovieRunnerAverage.class -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/Rater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/Rater.class -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/Rating.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/Rating.class -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/SecondRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/SecondRatings.class -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/StepOneStarterProgram.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/data/ratedmovies_short.csv: -------------------------------------------------------------------------------- 1 | id,title,year,country,genre,director,minutes,poster 2 | 0006414,Behind the Screen,1916,USA,"Short, Comedy, Romance",Charles Chaplin,30,http://ia.media-imdb.com/images/M/MV5BMTkyNDYyNTczNF5BMl5BanBnXkFtZTgwMDU2MzAwMzE@._V1_SX300.jpg 3 | 0068646,The Godfather,1972,USA,"Crime, Drama",Francis Ford Coppola,175,http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg 4 | 0113277,Heat,1995,USA,"Action, Crime, Drama",Michael Mann,170,http://ia.media-imdb.com/images/M/MV5BMTM1NDc4ODkxNV5BMl5BanBnXkFtZTcwNTI4ODE3MQ@@._V1_SX300.jpg 5 | 1798709,Her,2013,USA,"Drama, Romance, Sci-Fi",Spike Jonze,126,http://ia.media-imdb.com/images/M/MV5BMjA1Nzk0OTM2OF5BMl5BanBnXkFtZTgwNjU2NjEwMDE@._V1_SX300.jpg 6 | 0790636,Dallas Buyers Club,2013,USA,"Biography, Drama",Jean-Marc Vallée,117,N/A -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepOneStarterProgram/data/ratings_short.csv: -------------------------------------------------------------------------------- 1 | rater_id,movie_id,rating,time 2 | 1,0068646,10,1381620027 3 | 1,0113277,10,1379466669 4 | 2,1798709,10,1389948338 5 | 2,0790636,7,1389963947 6 | 2,0068646,9,1382460093 7 | 3,1798709,9,1388641438 8 | 4,0068646,8,1362440416 9 | 4,1798709,6,1398043318 10 | 5,0068646,9,1364834910 11 | 5,1798709,8,1404338202 12 | -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/FirstRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/FirstRatings.class -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/Movie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/Movie.class -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/MovieRunnerAverage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/MovieRunnerAverage.class -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/Rater.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/Rater.class -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/Rating.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/Rating.class -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/SecondRatings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/SecondRatings.class -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/StepOneStarterProgram.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/StepTwo-Simple Recommendations.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/data/ratedmovies_short.csv: -------------------------------------------------------------------------------- 1 | id,title,year,country,genre,director,minutes,poster 2 | 0006414,Behind the Screen,1916,USA,"Short, Comedy, Romance",Charles Chaplin,30,http://ia.media-imdb.com/images/M/MV5BMTkyNDYyNTczNF5BMl5BanBnXkFtZTgwMDU2MzAwMzE@._V1_SX300.jpg 3 | 0068646,The Godfather,1972,USA,"Crime, Drama",Francis Ford Coppola,175,http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg 4 | 0113277,Heat,1995,USA,"Action, Crime, Drama",Michael Mann,170,http://ia.media-imdb.com/images/M/MV5BMTM1NDc4ODkxNV5BMl5BanBnXkFtZTcwNTI4ODE3MQ@@._V1_SX300.jpg 5 | 1798709,Her,2013,USA,"Drama, Romance, Sci-Fi",Spike Jonze,126,http://ia.media-imdb.com/images/M/MV5BMjA1Nzk0OTM2OF5BMl5BanBnXkFtZTgwNjU2NjEwMDE@._V1_SX300.jpg 6 | 0790636,Dallas Buyers Club,2013,USA,"Biography, Drama",Jean-Marc Vallée,117,N/A -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/out/production/StepTwo-Simple Recommendations/data/ratings_short.csv: -------------------------------------------------------------------------------- 1 | rater_id,movie_id,rating,time 2 | 1,0068646,10,1381620027 3 | 1,0113277,10,1379466669 4 | 2,1798709,10,1389948338 5 | 2,0790636,7,1389963947 6 | 2,0068646,9,1382460093 7 | 3,1798709,9,1388641438 8 | 4,0068646,8,1362440416 9 | 4,1798709,6,1398043318 10 | 5,0068646,9,1364834910 11 | 5,1798709,8,1404338202 12 | -------------------------------------------------------------------------------- /StepTwo-Simple Recommendations/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx468/Java-Programming-Build-a-Recommendation-System/d7c4774942534eb5a6391df4d3fea9e4dd3a055e/StepTwo-Simple Recommendations/output.png --------------------------------------------------------------------------------