-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovieRunnerSimilarRatings.java
325 lines (263 loc) · 12.5 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
import edu.duke.*;
import java.util.*;
import org.apache.commons.csv.*;
/**
* Write a description of MovieRunnerSimilarRatings here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MovieRunnerSimilarRatings {
public void printAverageRatings(){
int minimalRaters =35;
String moviefile = "ratedmoviesfull.csv";
String ratingsfile = "ratings.csv";
//String moviefile = "ratedmoviesfull.csv";
//String ratingsfile = "data/ratings.csv";
FourthRatings fr = new FourthRatings();
MovieDatabase.initialize(moviefile);
RaterDatabase.initialize(ratingsfile);
System.out.println("Number of raters: "+ RaterDatabase.size());
System.out.println("Number of movies rated: "+ MovieDatabase.size());
ArrayList<Rating> avgRatingList = fr.getAverageRatings(minimalRaters);
Collections.sort(avgRatingList);
System.out.println("avgRatingList size " + avgRatingList.size());
for(Rating r:avgRatingList){
String Title = MovieDatabase.getTitle(r.getItem());
System.out.println(r.getValue()+ " : " + Title);
}
}
public void printAverageRatingsByYearAfterAndGenre(){
int minimalRaters =25;
String moviefile = "ratedmoviesfull.csv";
String ratingsfile = "ratings.csv";
int yearCount = 1990;
String selecGenre = "Drama";
FourthRatings fr = new FourthRatings();
RaterDatabase.initialize(ratingsfile);
MovieDatabase.initialize(moviefile);
System.out.println("Number of raters: "+ RaterDatabase.size());
System.out.println("read data for "+ MovieDatabase.size() + " movies");
Filter yf = new YearAfterFilter(yearCount);
Filter gf = new GenreFilter(selecGenre);
AllFilters filtersList = new AllFilters();
filtersList.addFilter(yf);
filtersList.addFilter(gf);
ArrayList<Rating> list = fr.getAverageRatingsByFilter(minimalRaters,filtersList);
Collections.sort(list);
System.out.println(list.size() + " movie " + "matched");
for(Rating r:list){
String Title = MovieDatabase.getTitle(r.getItem());
String Genre = MovieDatabase.getGenres(r.getItem());
int Year = MovieDatabase.getYear(r.getItem());
System.out.println(r.getValue()+ " " + Year +" "+ Title );
System.out.println(" "+ Genre);
}
}
public ArrayList<Rating> printSimiliarRatings(double[] rates){
int minimalRaters =4;
// String id = "65";
int numSimilarRaters=15;
String moviefile = "ratedmoviesfull.csv";
String ratingsfile = "ratings.csv";
FourthRatings fr = new FourthRatings();
RaterDatabase.initialize(ratingsfile);
MovieDatabase.initialize(moviefile);
//TRYING MY BEST
RaterDatabase.addRaterRating("1049", "3390572", rates[0]);
RaterDatabase.addRaterRating("1049", "1201607", rates[1]);
RaterDatabase.addRaterRating("1049", "1723121", rates[2]);
RaterDatabase.addRaterRating("1049", "1343092", rates[3]);
RaterDatabase.addRaterRating("1049", "1951261", rates[4]);
RaterDatabase.addRaterRating("1049", "3678782", rates[5]);
RaterDatabase.addRaterRating("1049", "2184339", rates[6]);
RaterDatabase.addRaterRating("1049", "1454468", rates[7]);
RaterDatabase.addRaterRating("1049", "2278388", rates[8]);
RaterDatabase.addRaterRating("1049", "2752200", rates[9]);
// System.out.println("----------------------------" + MovieDatabase.getTitle("1690953"));
ArrayList<Rating> recommendations= fr.getSimilarRatings("1049",numSimilarRaters,minimalRaters);
//Collections.sort(recommendations);
System.out.println(recommendations.size() + " movie " + "matched");
System.out.println("movieSimRatings: " + recommendations);
for(Rating rating:recommendations){
String movieTitle = MovieDatabase.getTitle((rating.getItem()));
System.out.println(movieTitle+ " : " + rating.getValue());
}
return recommendations;
}
public void printSimiliarRatingsByGenre(){
int minimalRaters =5;
String id = "65";
int numSimilarRaters=20;
String selecGenre = "Action";
String moviefile = "ratedmoviesfull.csv";
String ratingsfile = "ratings.csv";
FourthRatings fr = new FourthRatings();
RaterDatabase.initialize(ratingsfile);
MovieDatabase.initialize(moviefile);
Filter gr = new GenreFilter(selecGenre);
ArrayList<Rating> recommendations = fr.getSimilarRatingsByFilter(id,numSimilarRaters,minimalRaters,gr);
System.out.println(recommendations.size() + " movie " + "matched");
//System.out.println("movieSimRatings: " + recommendations);
for(Rating rating:recommendations){
String movieTitle = MovieDatabase.getTitle((rating.getItem()));
System.out.println(movieTitle+ " : " + rating.getValue());
}
}
public void printSimiliarRatingsByDirector(){
int minimalRaters =3;
String id = "1034";
int numSimilarRaters=10;
String inputDirectors = "";
String moviefile = "ratedmoviesfull.csv";
String ratingsfile = "ratings.csv";
FourthRatings fr = new FourthRatings();
RaterDatabase.initialize(ratingsfile);
MovieDatabase.initialize(moviefile);
//TRYING MY BEST
RaterDatabase.addRaterRating("1049", "3390572", 4);
RaterDatabase.addRaterRating("1049", "1201607", 3);
RaterDatabase.addRaterRating("1049", "1723121", 4);
RaterDatabase.addRaterRating("1049", "1343092", 7);
RaterDatabase.addRaterRating("1049", "1951261", 6);
RaterDatabase.addRaterRating("1049", "3678782", 7);
RaterDatabase.addRaterRating("1049", "2184339", 0);
RaterDatabase.addRaterRating("1049", "1454468", 9);
RaterDatabase.addRaterRating("1049", "2278388", 9);
RaterDatabase.addRaterRating("1049", "2752200", 9);
Filter dr = new DirectorsFilter(inputDirectors);
ArrayList<Rating> recommendations = fr.getSimilarRatingsByFilter("1049",numSimilarRaters,minimalRaters,dr);
System.out.println(recommendations.size() + " movie " + "matched");
for(Rating rating:recommendations){
String movieTitle = MovieDatabase.getTitle((rating.getItem()));
System.out.println(movieTitle+ " : " + rating.getValue());
}
}
public void printSimiliarRatingsByGenreAndMinutes(){
int minimalRaters =3;
String id = "65";
int numSimilarRaters=15;
int minMinutes = 50;
int maxMinutes = 200;
String selecGenre = "Action";
String moviefile = "ratedmoviesfull.csv";
String ratingsfile = "ratings.csv";
FourthRatings fr = new FourthRatings();
RaterDatabase.initialize(ratingsfile);
MovieDatabase.initialize(moviefile);
//TRYING MY BEST
RaterDatabase.addRaterRating("1049", "3390572", 4);
RaterDatabase.addRaterRating("1049", "1201607", 3);
RaterDatabase.addRaterRating("1049", "1723121", 4);
RaterDatabase.addRaterRating("1049", "1343092", 7);
RaterDatabase.addRaterRating("1049", "1951261", 6);
RaterDatabase.addRaterRating("1049", "3678782", 7);
RaterDatabase.addRaterRating("1049", "2184339", 0);
RaterDatabase.addRaterRating("1049", "1454468", 9);
RaterDatabase.addRaterRating("1049", "2278388", 9);
RaterDatabase.addRaterRating("1049", "2752200", 9);
Filter gr = new GenreFilter(selecGenre);
Filter mr = new MinutesFilter(minMinutes,maxMinutes);
AllFilters filtersList = new AllFilters();
filtersList.addFilter(mr);
filtersList.addFilter(gr);
ArrayList<Rating> recommendations = fr.getSimilarRatingsByFilter("1049",numSimilarRaters,minimalRaters,filtersList);
System.out.println(recommendations.size() + " movie " + "matched");
for(Rating rating:recommendations){
String movieTitle = MovieDatabase.getTitle((rating.getItem()));
System.out.println(movieTitle+ " : " + rating.getValue());
}
}
public void printAverageRatingsByYearAfterAndMinutes(){
int minimalRaters =5;
String id = "65";
int numSimilarRaters=10;
int minMinutes = 80;
int maxMinutes = 100;
int yearCount = 2000;
String moviefile = "ratedmoviesfull.csv";
String ratingsfile = "ratings.csv";
FourthRatings fr = new FourthRatings();
RaterDatabase.initialize(ratingsfile);
MovieDatabase.initialize(moviefile);
Filter yf = new YearAfterFilter(yearCount);
Filter mr = new MinutesFilter(minMinutes,maxMinutes);
AllFilters filtersList = new AllFilters();
filtersList.addFilter(mr);
filtersList.addFilter(yf);
ArrayList<Rating> recommendations = fr.getSimilarRatingsByFilter(id,numSimilarRaters,minimalRaters,filtersList);
System.out.println(recommendations.size() + " movie " + "matched");
for(Rating rating:recommendations){
String movieTitle = MovieDatabase.getTitle((rating.getItem()));
System.out.println(movieTitle+ " : " + rating.getValue());
}
}
@SuppressWarnings("Duplicates")
public ArrayList<Rating> printSimiliarRatingsByAllFilters(double[] rates, String selecGenre, String minMinutes, String maxMinutes, String dirs, String yearAfter ){
int minimalRaters =3;
String id = "65";
int numSimilarRaters=15;
// int minMinutes = 50;
// int maxMinutes = 200;
// String selecGenre = "Action";
String moviefile = "ratedmoviesfull.csv";
String ratingsfile = "ratings.csv";
FourthRatings fr = new FourthRatings();
RaterDatabase.initialize(ratingsfile);
MovieDatabase.initialize(moviefile);
//TRYING MY BEST
RaterDatabase.addRaterRating("1049", "3390572", rates[0]);
RaterDatabase.addRaterRating("1049", "1201607", rates[1]);
RaterDatabase.addRaterRating("1049", "1723121", rates[2]);
RaterDatabase.addRaterRating("1049", "1343092", rates[3]);
RaterDatabase.addRaterRating("1049", "1951261", rates[4]);
RaterDatabase.addRaterRating("1049", "3678782", rates[5]);
RaterDatabase.addRaterRating("1049", "2184339", rates[6]);
RaterDatabase.addRaterRating("1049", "1454468", rates[7]);
RaterDatabase.addRaterRating("1049", "2278388", rates[8]);
RaterDatabase.addRaterRating("1049", "2752200", rates[9]);
AllFilters filtersList = new AllFilters();
if(!selecGenre.isEmpty()) {
Filter gr = new GenreFilter(selecGenre);
filtersList.addFilter(gr);
}
try {
int minM = Integer.parseInt(minMinutes);
System.out.println("1");
int maxM = Integer.parseInt(maxMinutes);
System.out.println("2");
Filter mr = new MinutesFilter(minM,maxM);
System.out.println(3);
filtersList.addFilter(mr);
System.out.println("4");
} catch(Exception e) {
System.out.println("------------------------------------------------------------------------------------");
System.out.println(e);
System.out.println("------------------------------------------------------------------------------------");
}
if(!dirs.isEmpty()) {
Filter dr = new DirectorsFilter(dirs);
filtersList.addFilter(dr);
}
try {
int yrAfter = Integer.parseInt(yearAfter);
Filter yr = new YearAfterFilter(yrAfter);
filtersList.addFilter(yr);
} catch(Exception e) {
}
ArrayList<Rating> recommendations = fr.getSimilarRatingsByFilter("1049",numSimilarRaters,minimalRaters,filtersList);
System.out.println(recommendations.size() + " movie " + "matched");
for(Rating rating:recommendations){
String movieTitle = MovieDatabase.getTitle((rating.getItem()));
System.out.println(movieTitle+ " : " + rating.getValue());
}
return recommendations;
}
// public static void main(String[] args) {
// MovieRunnerSimilarRatings ref = new MovieRunnerSimilarRatings();
// ref.printSimiliarRatingsByGenreAndMinutes("65");
// ref.printSimiliarRatings();
// ref.printSimiliarRatingsByDirector();
// ref.printSimiliarRatingsByGenreAndMinutes();
// }
}