Solution for Movie Recommender 2019b#63
Conversation
| private Hashtable<String, Integer> HashProduct = new Hashtable<String, Integer>(); | ||
| private Hashtable<Integer, String> InvertedHashProduct = new Hashtable<Integer, String>(); | ||
| private Hashtable<String, Integer> HashUser = new Hashtable<String, Integer>(); | ||
| private int users =0, products =0, reviews = 0; |
There was a problem hiding this comment.
always format your code =0 vs = 0
|
|
||
| public class MovieRecommender { | ||
| private String file; | ||
| private Hashtable<String, Integer> HashProduct = new Hashtable<String, Integer>(); |
There was a problem hiding this comment.
why did you choose Hashtable vs HashMap?
There was a problem hiding this comment.
I was trying different ways of handling bigs amounts of data to see which would give me faster results for the tests, and that's the way I found when working on the solution and thought was the one that would do better, but after doing some research, I understand now that there is nothing in the hashtable that can't be done using hashmap...
There was a problem hiding this comment.
cool, just wanted you to investigate the difference, which is synchronization please research on that
There was a problem hiding this comment.
I actually was reading about that. I also read that Hashtables would be used for thread-safe applications, but now we can use Collections.synchronizedMap() or ConcurrentHash instead.
| } | ||
| } | ||
| } | ||
| br.close(); |
There was a problem hiding this comment.
I don't like this is not in a finally block. have you heard about try-catch-with-resources? please investigate about it.
|
|
||
| int userValue = HashUser.get(user); | ||
|
|
||
| List RecommendedProducts = new ArrayList<String>(); |
There was a problem hiding this comment.
ArrayList has a constructor that receives an initialCapacity why not using it based in recommendations size?
Can you answer what benefit would it bring implementing this suggestion?
There was a problem hiding this comment.
Giving an initial capacity to the ArrayList will reduce the use of memory keeping the size of the array only at whatever we are going to use
| //download movies.txt.gz from | ||
| // http://snap.stanford.edu/data/web-Movies.html | ||
| MovieRecommender recommender = new MovieRecommender("/path/to/movies.txt.gz"); | ||
| MovieRecommender recommender = new MovieRecommender("/Users/alonso/Documents/big-data-exercises/movies.txt.gz"); |
There was a problem hiding this comment.
hard coded paths doesn't looks good at all
| if (line.length() >= 0) { | ||
| sp = line.split(" "); | ||
| key = sp[0]; | ||
| if (key.equals("product/productId:")) { |
There was a problem hiding this comment.
key.equals("product/productId:") can produce a null pointer exception,
"product/productId:".equals(key) can't, something to have in mind.
| getData(); | ||
| } | ||
|
|
||
| public String getData() throws IOException { |
|
|
||
| while((line = br.readLine()) != null) { | ||
| if (line.length() >= 0) { | ||
| sp = line.split(" "); |
There was a problem hiding this comment.
what if there are no blank spaces in the line being split?
There was a problem hiding this comment.
I would not be able to get the correct values or keys... Fixed
| } | ||
| br.close(); | ||
| bw.close(); | ||
| return null; |
There was a problem hiding this comment.
returning always null will be helpful somehow?
There was a problem hiding this comment.
Changed getData() to private void instead of public String
Solution for Movie Recommender using Mahout in Java.
Alonso Gutierrez. Academy 2019b