Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Movie Recommender solved (Bryan) #32

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions big-data.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.apache.mahout:mahout-core:0.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.mahout:mahout-math:0.9" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:16.0" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-core-asl:1.9.12" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-mapper-asl:1.9.12" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.5" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.1" level="project" />
<orderEntry type="library" name="Maven: com.thoughtworks.xstream:xstream:1.4.4" level="project" />
<orderEntry type="library" name="Maven: xmlpull:xmlpull:1.1.3.1" level="project" />
<orderEntry type="library" name="Maven: xpp3:xpp3_min:1.1.4c" level="project" />
<orderEntry type="library" name="Maven: org.apache.lucene:lucene-core:4.6.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.lucene:lucene-analyzers-common:4.6.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.mahout.commons:commons-cli:2.0-mahout" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.solr:solr-commons-csv:3.5.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.hadoop:hadoop-core:1.2.1" level="project" />
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.2" level="project" />
<orderEntry type="library" name="Maven: com.sun.jersey:jersey-core:1.8" level="project" />
<orderEntry type="library" name="Maven: com.sun.jersey:jersey-json:1.8" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.jettison:jettison:1.1" level="project" />
<orderEntry type="library" name="Maven: stax:stax-api:1.0.1" level="project" />
<orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-impl:2.2.3-1" level="project" />
<orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.2.2" level="project" />
<orderEntry type="library" name="Maven: javax.xml.stream:stax-api:1.0-2" level="project" />
<orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-jaxrs:1.7.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-xc:1.7.1" level="project" />
<orderEntry type="library" name="Maven: com.sun.jersey:jersey-server:1.8" level="project" />
<orderEntry type="library" name="Maven: asm:asm:3.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.1" level="project" />
<orderEntry type="library" name="Maven: commons-httpclient:commons-httpclient:3.0.1" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.3" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math:2.1" level="project" />
<orderEntry type="library" name="Maven: commons-configuration:commons-configuration:1.6" level="project" />
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.4" level="project" />
<orderEntry type="library" name="Maven: commons-digester:commons-digester:1.8" level="project" />
<orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.7.0" level="project" />
<orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils-core:1.8.0" level="project" />
<orderEntry type="library" name="Maven: commons-net:commons-net:1.4.1" level="project" />
<orderEntry type="library" name="Maven: commons-el:commons-el:1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.7" level="project" />
</component>
</module>
4 changes: 4 additions & 0 deletions movies.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0,0,3.0
1,0,3.0
2,0,5.0
3,0,3.0
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are this changes required? Are they part of the requirements?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! I've used maven, which allowed me to create a java project. In order to run, I had to add those dependencies.

<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
Expand Down
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/data/.DS_Store
Binary file not shown.
35 changes: 35 additions & 0 deletions src/data/movies_rapid_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
product/productId: B003AI2VGA
review/userId: A141HP4LYPWMSR
review/profileName: Brian E. Erland "Rainbow Sphinx"
review/helpfulness: 7/7
review/score: 3.0
review/time: 1182729600
review/summary: "There Is So Much Darkness Now ~ Come For The Miracle"
review/text: Synopsis: On the daily trek from Juarez, Mexico to El Paso, Texas an ever increasing number of female workers are found raped and murdered in the surrounding desert. Investigative reporter Karina Danes (Minnie Driver) arrives from Los Angeles to pursue the story and angers both the local police and the factory owners who employee the undocumented aliens with her pointed questions and relentless quest for the truth.<br /><br />Her story goes nationwide when a young girl named Mariela (Ana Claudia Talancon) survives a vicious attack and walks out of the desert crediting the Blessed Virgin for her rescue. Her story is further enhanced when the "Wounds of Christ" (stigmata) appear in her palms. She also claims to have received a message of hope for the Virgin Mary and soon a fanatical movement forms around her to fight against the evil that holds such a stranglehold on the area.<br /><br />Critique: Possessing a lifelong fascination with such esoteric matters as Catholic mysticism, miracles and the mysterious appearance of the stigmata, I was immediately attracted to the '05 DVD release `Virgin of Juarez'. The film offers a rather unique storyline blending current socio-political concerns, the constant flow of Mexican migrant workers back and forth across the U.S./Mexican border and the traditional Catholic beliefs of the Hispanic population. I must say I was quite surprised by the unexpected route taken by the plot and the means and methods by which the heavenly message unfolds.<br /><br />`Virgin of Juarez' is not a film that you would care to watch over and over again, but it was interesting enough to merit at least one viewing. Minnie Driver delivers a solid performance and Ana Claudia Talancon is perfect as the fragile and innocent visionary Mariela. Also starring Esai Morales and Angus Macfadyen (Braveheart).

product/productId: B003AI2VGA
review/userId: A328S9RN3U5M68
review/profileName: Grady Harp
review/helpfulness: 4/4
review/score: 3.0
review/time: 1181952000
review/summary: Worthwhile and Important Story Hampered by Poor Script and Production
review/text: THE VIRGIN OF JUAREZ is based on true events surrounding the crime problems of Juarez, Mexico reflected in the gringo exploitation of businesses in neighboring El Paso, Texas. The story contains many important facts that desperately need to be brought into the light, but the impact of the film falters because of the choices made by the writer and director.<br /><br />Karina Danes (Minnie Driver) is a journalist for a Los Angeles newspaper who has flown to Juarez to investigate the multiple (in the hundreds) killings of young women. The targets for these murders seem to be young women working in the US sponsored sweatshops in Juarez who are picked up at night after work, raped, beaten and killed. Danes is convinced the Juarez police force is doing nothing and takes on the mission of exposing the tragedies, in part due to her own past issues of being too idle with similar crimes in the US. She meets Father Herrera (Esai Morales) and a community activist Patrick (Angus MacFadyen) and together they probe the police files and follow the most recent murder, discovering along the way a survivor named Mariela (Ana Claudia Talanc&oacute;n), a frightened young girl whose memory of her rape and beating is erased by her apparent vision of the Virgin Mary. A father of one of the victims, Isidro (Jorge Cervera, Jr.) nurtures Mariela and helps her to escape the hospital, placing her in a 'church' where she becomes a 'saint' to the people of Juarez who long for the crimes to end. Mariela appears to the public with the stigmata of bleeding hands and offers hope to the victims' families. Danes works hard to discover evidence that will expose the perpetrators, taking a sheet of photos of 'most wanted men' from the police office of Detective Lauro (Jacob Vargas), and works with the police and Father Herrera to resolve the tragic chain of events that continue in Juarez. Fearing for Mariela's life, they transport her to Los Angeles where mysterious events end the story.<br /><br />The squeaky, mawkish script was written by Michael Fallon and directed by Kevin James Dobson. Had their vision been more directed toward defining the line between realism and fanaticism, the story would possibly have been better related. There are some good performances by Driver, Talanc&oacute;n, Morales, and Vargas but the minor roles vary in quality. Reporting atrocities such as the one this film addresses is a valid and valuable contribution of contemporary cinema. It is sad when script and the production dull the impact. Grady Harp, June 07

product/productId: B003AI2VGA
review/userId: A1I7QGUDP043DG
review/profileName: Chrissy K. McVay "Writer"
review/helpfulness: 8/10
review/score: 5.0
review/time: 1164844800
review/summary: This movie needed to be made.
review/text: The scenes in this film can be very disquieting due to their graphic re-enactment of real events, but this story needs to be told. I will say the violence was injected into the movie with as much taste as manageable when dealing with rape scenes, etc. Inspired by true events, women are being murdered in Juarez after they leave the factory where they work. A fearful community is suddenly given some hope when one of the young victims not only lives, but experiences 'stigmata' after seeing the Virgin Mary. I was shocked to learn that murders in Juarez are still happening and many are unsolved. I believe this director brought a very important story to the surface. Though it's never pleasant to think about young women being murdered, this movie depicts a harsh reality of the high cost of exploited-cheap labor.<br /><br />Chrissy K. McVay - Author

product/productId: B003AI2VGA
review/userId: A1M5405JH9THP9
review/profileName: golgotha.gov
review/helpfulness: 1/1
review/score: 3.0
review/time: 1197158400
review/summary: distantly based on a real tragedy
review/text: THE VIRGIN OF JUAREZ (2006)<br />directed by Kevin James Dobson<br />approx. 1 hour 25 minutes<br /><br />The town of Juarez, Chihuahua in Mexico is just across the border from El Paso, Texas. It is home to several factories owned by American companies who employ Mexicans at very low wages. Since the early 1990s, Juarez has also been the murder site of hundreds of women. There is a lot of debate as to whether the deaths are the work of a drug gang or a serial killer. It has also been suggested that due to the local police department's failure to solve the crimes, new rapists and thugs have moved to the area knowing that they will never be caught. The situation is an overwhelming tragedy and this movie uses the story as a backdrop.<br /><br />We start off seeing how unsafe women feel as they walk and work in Juarez. Then we meet the hard-headed American journalist played by Minnie Driver. She aggressively questions the local police and befriends a Catholic priest. Within the first twenty minutes or so, we see the terrifying reality of the situation in Juarez.<br /><br />At this point, the story jumps from something that might have happened to something that is only found in this movie. A woman named Mariela survives an brutal attack but is in critical condition in a small hospital. While the priest is speaking to her, she lets out a howl... and her hands begin bleeding*. This "stigmata" is meant to show that she has been blessed by the Virgin Mary. Our reporter protagonist clashes with various authorities on what should be done. Meanwhile Mariela goes underground and attracts a devoted following, eventually landing her own radio show (!) and living under the protection of gang members, whom she refers to as "modern warriors". The only thing missing is "Jes&uacute;s Malverde".<br /><br />Now I understand that we don't know everything about the Juarez murders and that a screenwriter has to "fill in the blanks" when crafting an exciting dramatization. However if you are going to deviate so far from the true story, then don't preface your movie as being "based on the ongoing unsolved murders in Cuidad Juarez". There is plenty of interesting and legitimate information in the REAL stories of Juarez and there is no need to fabricate. This movie may "raise the issue" of the Juarez women, but it isn't really about them at all!<br /><br />If you are interested in learning more about the killings in Juarez, there are a few documentaries. A recent one from Las Perlas Del Mar Films is simply titled 'JUAREZ' and is a good introduction. Zulma Aguiar's 'JUAREZ MOTHERS FIGHT FEMICIDE' (focuses on the families) is also easy to find. There is another one which I haven't seen titled 'BORDER ECHOES'.<br /><br />*- note to Hollywood:<br />the nails that crucified Jesus were through his wrists, not his palms!
Binary file added src/data/movies_rapid_test.txt.gz
Binary file not shown.
Binary file added src/main/.DS_Store
Binary file not shown.
Binary file added src/main/java/.DS_Store
Binary file not shown.
Binary file added src/main/java/nearsoft/.DS_Store
Binary file not shown.
Binary file added src/main/java/nearsoft/academy/.DS_Store
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package nearsoft.academy.bigdata.recommendation;

import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel;
import org.apache.mahout.cf.taste.impl.neighborhood.ThresholdUserNeighborhood;
import org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender;
import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood;
import org.apache.mahout.cf.taste.recommender.RecommendedItem;
import org.apache.mahout.cf.taste.recommender.UserBasedRecommender;
import org.apache.mahout.cf.taste.similarity.UserSimilarity;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.zip.GZIPInputStream;

public class MovieRecommender {
int totalReviews = 0;
int totalProducts = 0;
int totalUsers = 0;

HashMap<String, Integer> products = new HashMap<String, Integer>();
HashMap<String, Integer> users = new HashMap<String, Integer>();

public MovieRecommender(String path) throws IOException {
GZIPInputStream inputFile = new GZIPInputStream(new FileInputStream(path));
Reader decoder = new InputStreamReader(inputFile);
BufferedReader bReader = new BufferedReader(decoder);
String currentLine;

File result = new File("movies.csv");
FileWriter fWriter = new FileWriter(result);
BufferedWriter bWriter = new BufferedWriter(fWriter);

String productList = "";
String userList = "";
String scoreList = "";

int totalProducts = 0;
int totalUsers = 0;
int totalReviews = 0;


while ((currentLine = bReader.readLine()) != null){
if (currentLine.startsWith("product/productId:")){
totalReviews++;
String productId = currentLine.split(" ")[1];

if (!products.containsKey(productId)){
products.put(productId, totalProducts++);
}
productList = products.get(productId).toString();

} else if (currentLine.startsWith("review/userId:")) {
String userID = currentLine.split(" ")[1];

if (!users.containsKey(userID)){
users.put(userID,totalUsers++);
}
userList = users.get(userID).toString();

} else if (currentLine.startsWith("review/score:")){
scoreList = currentLine.split(" ")[1];
String finalList = String.format("%s,%s,%s\n", userList, productList, scoreList);
bWriter.write(finalList);
}
}

bReader.close();
bWriter.close();

this.totalReviews = totalReviews;
this.totalProducts = products.size();
this.totalUsers = users.size();
}

public int getTotalReviews() {
return this.totalReviews;
}

public int getTotalProducts() {
return this.totalProducts;
}

public int getTotalUsers() {
return this.totalUsers;
}


public List<String> getRecommendationsForUser(String userId) throws IOException, TasteException {

List<String> results = new ArrayList<String>();

int user = users.get(userId);

DataModel model = new FileDataModel(new File("movies.csv"));
UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, model);
UserBasedRecommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);

List<RecommendedItem> recommendations = recommender.recommend(user, 3);

for (RecommendedItem recommendation : recommendations) {
for (String key : this.products.keySet()) {
if (this.products.get(key)==recommendation.getItemID()) {
results.add(key);
}
}

}
return results;
}
}
Binary file added src/test/.DS_Store
Binary file not shown.
Binary file added src/test/java/.DS_Store
Binary file not shown.
Binary file added src/test/java/nearsoft/.DS_Store
Binary file not shown.
Binary file added src/test/java/nearsoft/academy/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MovieRecommenderTest {
public void testDataInfo() throws IOException, TasteException {
//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("src/data/movies.txt.gz");
assertEquals(7911684, recommender.getTotalReviews());
assertEquals(253059, recommender.getTotalProducts());
assertEquals(889176, recommender.getTotalUsers());
Expand All @@ -27,4 +27,4 @@ public void testDataInfo() throws IOException, TasteException {

Copy link

@vavimayor159 vavimayor159 Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is usually a good idea to have just the necessary changes on the PR's, we should try not to include format changes unless is required. Avoiding them makes easier to review the PR's.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the advice! I'll restore the original file with only the necessary changes.

}

}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nearsoft/academy/bigdata/recommendation/MovieRecommender.class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/bryan.medina/Desktop/movieRecommenderBryan/academy-exercises/src/main/java/nearsoft/academy/bigdata/recommendation/MovieRecommender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nearsoft/academy/bigdata/recommendation/MovieRecommenderTest.class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/bryan.medina/Desktop/movieRecommenderBryan/academy-exercises/src/test/java/nearsoft/academy/bigdata/recommendation/MovieRecommenderTest.java
Loading