Conversation
src/test/java/nearsoft/academy/bigdata/recommendation/MovieRecommender.java
Show resolved
Hide resolved
| BufferedReader br = new BufferedReader(new FileReader(file)); | ||
| FileWriter writer = new FileWriter("data.csv"); | ||
| BufferedWriter bw = new BufferedWriter(writer); | ||
| String csv = ""; |
There was a problem hiding this comment.
Why string? Did you consider a string builder?
There was a problem hiding this comment.
I didn't consider the inefficiency of string vs. stringBuilder in this case. I'll keep it in mind for the next occasion I do something similar.
| private int reviews; | ||
| private long users; | ||
| private int products; | ||
| public UserBasedRecommender recommender; | ||
| private HashMap<String, Integer> productTable = new HashMap(); | ||
| private HashMap<String, Long> userTable = new HashMap(); | ||
| private HashMap<Integer, String> iProductsTable = new HashMap(); |
There was a problem hiding this comment.
Do we need all of these as global variables?
There was a problem hiding this comment.
Not all of them, but I decided to leave all of them like that instead of a few regarding the aesthetics. I'll consider not doing this again on a future case.
| } | ||
|
|
||
| public List<String> getRecommendationsForUser(String user) throws Exception { | ||
| List<String> results = new ArrayList(); |
There was a problem hiding this comment.
Because the list consisted only of three elements and the order wasn't an issue. Also no removal or rearrangement was needed, so I thought an arrayList was more fitting for this specific case.
Created and implemented a new class called MovieRecommender.java.
This new class creates a .csv file for reading from a .txt file of Amazon reviews. This class has 5 methods: "readReviewsFile" which receives the .txt file and generates a .csv file for its reading. "getTotalReviews", "getTotalProducts" and "getTotalUsers" were each of this gets an integer value (except for users which is a long) that represents the total amount of reviews, products and users respectively. "getRecommendationsForUser" receives a user id and generates product recommendations for that user (in this case 3 recommendations are given).