Java - DukeJava 4-3 Step Three Interfaces, Filters, Database
[toc]
DukeJava 4-4 Step Four Calculating Weighted Averages
Java-Programming-and-Software-Engineering-Fundamentals-Specialization
- 5.Java-Programming-Build-a-Recommendation-System
- Step One : get the rating, rater, movie from the file
- Step Two : Simple recommendations
- Step Three : Interfaces, Filters, Database
- Step Four : Calculating Weighted Averages
Resource Link: https://www.coursera.org/learn/java-programming-recommender/supplement/KTrOQ/programming-exercise-step-two
starter files: https://www.dukelearntoprogram.com//course5/files.php
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
Movie (String anID, String aTitle, String aYear, String theGenres, String aDirector, String aCountry, String aPoster, int theMinutes)
Rater(String id, ArrayList<Rating>())
EfficientRater (String id, HashMap<String,Rating>)
Rating (String anItem, double aValue)
MovieDatabase ( HashMap<String movieID, Movie m> ourMovies)
// ---------------------------------
public interface Rater {
public void addRating(String item, double rating);
public boolean hasRating(String item);
public String getID();
public double getRating(String item);
public int numRatings();
public ArrayList<String> getItemsRated();
public void printRatingHash();
}
public class PlainRater implements Rater{}
public class EfficientRater implements Rater{}
// ---------------------------------
public class MovieDatabase {
private static HashMap<String, Movie> ourMovies;
private static void initialize() {
if (ourMovies == null) {
ourMovies = new HashMap<String,Movie>();
loadMovies("data/ratedmoviesfull.csv");
}
}
public static HashMap<String, Movie> initialize(String moviefile){}
private static void loadMovies(String filename) {
FirstRatings fr = new FirstRatings();
ArrayList<Movie> list = fr.loadMovies(filename);
for (Movie m : list) {ourMovies.put(m.getID(), m);}
}
public static boolean containsID(String id){}
public static int getYear(String id){}
public static String getGenres(String id){}
public static String getTitle(String id){}
public static Movie getMovie(String id){}
public static String getPoster(String id){}
public static int getMinutes(String id){}
public static String getCountry(String id){}
public static String getDirector(String id){}
public static int size(){}
public static ArrayList<String> filterBy(Filter f){}
}
// ---------------------------------
public interface Filter {
public boolean satisfies(String id);
}
public class AllFilters implements Filter {
ArrayList<Filter> filters;
public AllFilters() {filters = new ArrayList<Filter>();}
public void addFilter(Filter f) {filters.add(f);}
@Override
public boolean satisfies(String id){}
}
public class TrueFilter implements Filter {
@Override
public boolean satisfies(String id) {return true;}
}
public class YearAfterFilter implements Filter {
private int myYear;
public YearAfterFilter(int year){}
@Override
public boolean satisfies(String id){}
}
// ---------------------------------
public class FirstRatings{
private ArrayList<Movie> csvMovieme(CSVParser parser){}
public ArrayList<Movie> loadMovies(String filename){}
public void testLoadMovies(){}
private ArrayList<Rater> csvRater(CSVParser parser){}
public ArrayList<Rater> loadRaters(String filename){}
public void testLoadRaters(int raterID, String movieID){}
}
public class SecondRatings {
private ArrayList<Movie> myMovies;
private ArrayList<Rater> myRaters;
public SecondRatings(){}
public SecondRatings(String moviefile, String ratingsfile){}
public int getMovieSize() {return myMovies.size();}
public int getRaterSize() {return myRaters.size();}
public double getAverageByID(String id, int minimalRaters){}
public ArrayList<Rating> getAverageRatings(int minimalRaters){}
public String getTitle(String id){}
public String getID(String title){}
}
public class ThirdRatings {
private ArrayList<Rater> myRaters;
public ThirdRatings(){}
public ThirdRatings(String ratingsfile){}
public int getRaterSize() {return myRaters.size();}
public double getAverageByID(String id, int minimalRaters){}
public ArrayList<Rating> getAverageRatings(int minimalRaters){}
public ArrayList<Rating> getAverageRatingsByFilter(int minimalRaters, Filter filterCriteria){}
}
// ---------------------------------
public class MovieRunnerAverage {
public void printAverageRatings(){}
public void getAverageRatingOneMovie(){}
}
public class MovieRunnerWithFilters {
private int helperMoviesAndRatings() {}
public void printAverageRatings(){}
public void printAverageRatingsByYear() {}
public void printAverageRatingsByGenre() {}
public void printAverageRatingsByMinutes() {}
}
Calculating Weighted Averages:
Calculating closeness:
Calculating close:
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
13
81
The method getSimilarRatings can be written with just one line of code that returns the result of a call to getSimilarRatingsByFilter.
---------initialize the MovieRunnerSimilarRatings---------
Number of total of Raters: 1048
Number of total of movies: 3143
------------------ getSimilarRatings() ------------------
The movie returned with the top rated average is: Frozen, weighted is: 212.75
---------------- printSimilarRatingsByGenre ---------------- xxx
finding Genre: Mystery
The movie returned with the top rated average is: Divergent, weighted is: 467.0
------------------ getSimilarRatings() ------------------ xxx
The movie returned with the top rated average is: Boyhood, weighted is: 1565.375
---------------- printSimilarRatingsByDirector ----------------
The movie returned with the top rated average is: Star Trek, weighted is: 646.5
---------------- printSimilarRatingsByGenreAndMinutes ----------------
finding Genre: Drama
time period: 80 - 160
The movie returned with the top rated average is: The Imitation Game, weighted is: 1204.25
---------------- printSimilarRatingsByYearAfterAndMinutes ----------------
time period: 70 - 200
The movie returned with the top rated average is: Nightcrawler, weighted is: 828.125
.
This post is licensed under CC BY 4.0 by the author.
Comments powered by Disqus.