aleheux-tc
/
Java-Programming-and-Software-Engineering-Fundamentals-Java-Programming-Build-a-Recommendation-Syst
Public
forked from mxc19912008/Java-Programming-and-Software-Engineering-Fundamentals-Java-Programming-Build-a-Recommendation-Syst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovieRunnerSimilarRatings.java
165 lines (157 loc) · 7.29 KB
/
MovieRunnerSimilarRatings.java
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* Programming Exercise: Step Four
*
* @author Kuei
* @version August 10, 2016
*/
import java.util.ArrayList;
import java.util.Collections;
public class MovieRunnerSimilarRatings {
public void printAverageRatings() {
RaterDatabase.initialize("ratings_short.csv");
System.out.println("read data for " + RaterDatabase.size() + " raters");
MovieDatabase.initialize("ratedmovies_short.csv");
System.out.println("read data for " + MovieDatabase.size() + " movies");
FourthRatings fr = new FourthRatings();
int minimalRaters = 1;
ArrayList<Rating> ratings = fr.getAverageRatings(minimalRaters);
System.out.println("found " + ratings.size() + " movies");
Collections.sort(ratings);
for(Rating r: ratings) {
System.out.println(r.getValue() + " " + MovieDatabase.getTitle(r.getItem()));
}
}
public void printAverageRatingsByYearAfterAndGenre() {
RaterDatabase.initialize("ratings_short.csv");
System.out.println("read data for " + RaterDatabase.size() + " raters");
MovieDatabase.initialize("ratedmovies_short.csv");
System.out.println("read data for " + MovieDatabase.size() + " movies");
FourthRatings fr = new FourthRatings();
int minimalRaters = 1;
int year = 1980;
String genre = "Romance";
AllFilters filterCriteria = new AllFilters();
filterCriteria.addFilter(new YearAfterFilter(year));
filterCriteria.addFilter(new GenreFilter(genre));
ArrayList<Rating> ratings = fr.getAverageRatingsByFilter(minimalRaters, filterCriteria);
if (ratings.size() == 0 || ratings.size() == 1)
System.out.println(ratings.size() + " movie matched");
else
System.out.println(ratings.size() + " movies matched");
Collections.sort(ratings);
for(Rating r: ratings) {
System.out.println(r.getValue() + " " + MovieDatabase.getYear(r.getItem()) + " " + MovieDatabase.getTitle(r.getItem()) + "\n " + MovieDatabase.getGenres(r.getItem()));
}
}
public void printSimilarRatings() {
RaterDatabase.initialize("ratings.csv ");
System.out.println("read data for " + RaterDatabase.size() + " raters");
MovieDatabase.initialize("ratedmoviesfull.csv");
System.out.println("read data for " + MovieDatabase.size() + " movies");
FourthRatings fr = new FourthRatings();
String raterID = "71";
int numSimilarRaters = 20;
int minimalRaters = 5;
ArrayList<Rating> ratings = fr.getSimilarRatings(raterID, numSimilarRaters, minimalRaters);
if (ratings.size() == 0 || ratings.size() == 1)
System.out.println(ratings.size() + " movie matched");
else
System.out.println(ratings.size() + " movies matched");
for(int i=0; i< ratings.size(); i++) {
if (i<15)
System.out.printf("%d %.2f %s\n", i, ratings.get(i).getValue(), MovieDatabase.getTitle(ratings.get(i).getItem()));
}
}
public void printSimilarRatingsByGenre() {
RaterDatabase.initialize("ratings.csv ");
System.out.println("read data for " + RaterDatabase.size() + " raters");
MovieDatabase.initialize("ratedmoviesfull.csv");
System.out.println("read data for " + MovieDatabase.size() + " movies");
FourthRatings fr = new FourthRatings();
String raterID = "964";
int numSimilarRaters = 20;
int minimalRaters = 5;
String genre = "Mystery";
Filter filterCriteria = new GenreFilter(genre);
ArrayList<Rating> ratings = fr.getSimilarRatingsByFilter(raterID, numSimilarRaters, minimalRaters, filterCriteria);
if (ratings.size() == 0 || ratings.size() == 1)
System.out.println(ratings.size() + " movie matched");
else
System.out.println(ratings.size() + " movies matched");
for(int i=0; i< ratings.size(); i++) {
if (i<15)
System.out.printf("%d %.2f %s\n", i, ratings.get(i).getValue(), MovieDatabase.getTitle(ratings.get(i).getItem()));
}
}
public void printSimilarRatingsByDirector() {
RaterDatabase.initialize("ratings.csv ");
System.out.println("read data for " + RaterDatabase.size() + " raters");
MovieDatabase.initialize("ratedmoviesfull.csv");
System.out.println("read data for " + MovieDatabase.size() + " movies");
FourthRatings fr = new FourthRatings();
String raterID = "120";
int numSimilarRaters = 10;
int minimalRaters = 2;
String directors = "Clint Eastwood,J.J. Abrams,Alfred Hitchcock,Sydney Pollack,David Cronenberg,Oliver Stone,Mike Leigh";
Filter filterCriteria = new DirectorsFilter(directors);
ArrayList<Rating> ratings = fr.getSimilarRatingsByFilter(raterID, numSimilarRaters, minimalRaters, filterCriteria);
if (ratings.size() == 0 || ratings.size() == 1)
System.out.println(ratings.size() + " movie matched");
else
System.out.println(ratings.size() + " movies matched");
for(int i=0; i< ratings.size(); i++) {
if (i<15)
System.out.printf("%d %.2f %s\n", i, ratings.get(i).getValue(), MovieDatabase.getTitle(ratings.get(i).getItem()));
}
}
public void printSimilarRatingsByGenreAndMinutes() {
RaterDatabase.initialize("ratings.csv ");
System.out.println("read data for " + RaterDatabase.size() + " raters");
MovieDatabase.initialize("ratedmoviesfull.csv");
System.out.println("read data for " + MovieDatabase.size() + " movies");
FourthRatings fr = new FourthRatings();
String raterID = "168";
int numSimilarRaters = 10;
int minimalRaters = 3;
String genre = "Drama";
int min = 80;
int max = 160;
AllFilters filterCriteria = new AllFilters();
filterCriteria.addFilter(new GenreFilter(genre));
filterCriteria.addFilter(new MinutesFilter(min, max));
ArrayList<Rating> ratings = fr.getSimilarRatingsByFilter(raterID, numSimilarRaters, minimalRaters, filterCriteria);
if (ratings.size() == 0 || ratings.size() == 1)
System.out.println(ratings.size() + " movie matched");
else
System.out.println(ratings.size() + " movies matched");
for(int i=0; i< ratings.size(); i++) {
if (i<15)
System.out.printf("%d %.2f %s\n", i, ratings.get(i).getValue(), MovieDatabase.getTitle(ratings.get(i).getItem()));
}
}
public void printSimilarRatingsByYearAfterAndMinutes() {
RaterDatabase.initialize("ratings.csv ");
System.out.println("read data for " + RaterDatabase.size() + " raters");
MovieDatabase.initialize("ratedmoviesfull.csv");
System.out.println("read data for " + MovieDatabase.size() + " movies");
FourthRatings fr = new FourthRatings();
String raterID = "314";
int numSimilarRaters = 10;
int minimalRaters = 5;
int year = 1975;
int min = 70;
int max = 200;
AllFilters filterCriteria = new AllFilters();
filterCriteria.addFilter(new YearAfterFilter(year));
filterCriteria.addFilter(new MinutesFilter(min, max));
ArrayList<Rating> ratings = fr.getSimilarRatingsByFilter(raterID, numSimilarRaters, minimalRaters, filterCriteria);
if (ratings.size() == 0 || ratings.size() == 1)
System.out.println(ratings.size() + " movie matched");
else
System.out.println(ratings.size() + " movies matched");
for(int i=0; i< ratings.size(); i++) {
if (i<15)
System.out.printf("%d %.2f %s\n", i, ratings.get(i).getValue(), MovieDatabase.getTitle(ratings.get(i).getItem()));
}
}
}