You will be using iteration, selection, String Processing, and implementing methods to analyze a large data file to rate words based on how they were used in user reactions.
Reaction Analysis is a Big Data problem which seeks to determine the general attitude of a writer given some text they have written. For instance, we would like to have a program that could look at the text “The film was a breath of fresh air\" and realize that it was a positive statement while \"It made me want to poke out my eye balls\" is negative One algorithm that we can use for this is to assign a numeric value to any given word based on how positive or negative that word is and then score the statement based on the values of the words. But, how do we come up with our word scores in the first place? That\'s the problem that we\'ll solve in this assignment. You are going to search through a file containing movie reviews from the Rotten Tomatoes website which have both a numeric score as well as text. You\'lI use this to learn which words are positive and which are negative. The data file looks like this 1 A series of escapades demonstrating the adage that what is good for the go 4 This quiet , introspective and entertaining independent is worth seeking . 1 Even fans of Ismail Merchant \'s work, I suspect would have a hard time s 3 A positively thrilling combination of ethnography and all the intrigue, be 1 Aggressive self-glorification and a manipulative whitewash 4 A comedy-drama of nearly epic proportions rooted in a sincere performance I Narratively , Trouble Every Day is a plodding mess . 3 The Importance of Being Earnest, so thick with wit it plays like a reading 1 But it does n\'t leave you with much . 1 You could hate it for the same reason . 1 There \'s little to recommend Snow Dogs, unless one considers cliched dial 1 Kung Pow is 0edekerk realization of his childhood dream to be in a marti 4 The performances are an absolute joy . 3 Fresnadillo has something serious to say about the ways in which extravagar 3 I still like Moonlight Mile , better judgment be damned . 3 A welcome relief from baseball movies that try too hard to be mythic, this 3 a bilingual charmer, just like the woman who inspired it 2 Like a less dizzily gorgeous companion to Mr. Wong ·s In the Mood for Love 1 As inept as big-screen remakes of The Avengers and The Wild Wild West 2 It \'s everything you ·d expect-but nothing more . Note that each review starts with a number 0 through 4 with the following meaning 0: negative I: somewhat negative 2: neutral 3: somewhat positive 4: postive 1. The program should be named ReactionAnalysis.java. It will prompt the user to enter a word, and then it will search every movie review for that word. If found, add the score for that review to the word\'s running score total. You also will need to keep track of how many appearances the word made so that you can report the average score of reviews containing that word back to the user Some sample runs of the program might look like this a\". Problems @ Javadoc Declaration Console X cterminated> WordScore lava Application /LibrarylJava/JavaVirtualMachines/jdk1.8.0 20.jdk Contents/H Enter a ord: horribl horrible appears 11.8 times The average score for reviens contoining the word horrible s .6363636363636364
Dear Asker,
Following is the code to the problem\'s first part:
Note: I assumed that the review file too big to fit into the memory
ReactionAnalysis.java
import java.io.*;
public class ReactionAnalysis {
private String filename;
public ReactionAnalysis(String filename) {
this.filename = filename;
}
public void analyzeWordScore(String word) throws FileNotFoundException, IOException {
double score = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
int count = 0;
for (String line = br.readLine(); line != null; line = br.readLine()) {
if (line.contains(word)) {
count++;
score += Integer.parseInt(line.substring(0, 1));
}
}
score /= count;
System.out.println(\"The word appears \" + count + \"times\");
System.out.println(\"The score is :\" + score);
}
}
Main.java
import java.io.IOException;
import java.util.Scanner;
public class Main{
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
ReactionAnalysis ra = new ReactionAnalysis(\"ProvideReviewFileName.txt\");
Scanner input = new Scanner(System.in);
System.out.println(\"Enter the word to be analysed\");
String word = input.nextLine().trim();
ra.analyzeWordScore(word);
}
}