Question
package a6; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ReviewAnalysis { public static void main(String[] args) { String[] lines = null; // need to
package a6; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ReviewAnalysis { public static void main(String[] args) { String[] lines = null; // need to declare outside the try scope for later use. // Read the file and put each line in a String array. try { lines = convertFileToStringArray("src/a6/MovieReviews.txt"); } catch (FileNotFoundException e) { // Report and quit if the file wasn't found. System.out.println("File was not found"); return; } // Create three arrays with our known maximum size of 16444 elements. // 1. words: All the words in the reviews // 2. word_score: A word at index x has a total point value at word_score[x] // 3. word_count: A word at index x has a total number of appearances at // word_count[x] String[] words = new String[16444]; // Cheat by knowing # of words in advance. double[] wordScore = new double[16444]; int[] wordCount = new int[16444]; // We need to track how many words have been added to the arrays. // As words gets added, this number should go up to match. int numberOfSpacesUsedInWords = 0; // This variable is super important. If you don't know the point of it - stop - and figure it out. // Go through each review. For each review // 1. Pull off the movie score from the front of the review. // 2. Go through the text of the review. Process each word by adding to its // score and count. for (int i = 0; i = 2.0 && estimatedScore >= 2.0) || (actualScore
package a6; import static org.junit.Assert.*; import java.io.FileNotFoundException; import java.util.Scanner; import org.junit.Test; public class ReviewAnalysisTest { @Test public void testScoreReview() { String review = "this is good"; String[] words = {"this", "is", "good"}; double[] scores = {1.0, 1.5, 3.5}; int[] wordCount = {1, 1, 1}; int numberOfWordsSoFar = 3; double score = ReviewAnalysis.scoreReview(review, words, scores, wordCount, numberOfWordsSoFar); assertEquals("failed normal test", 2.0, score, 1e-9); } @Test public void testIndexOfBestWord() { double[] scores = {4.0, 1.5, 3.5}; int[] wordCount = {1, 5, 3}; int numberOfWordsSoFar = 3; int index = ReviewAnalysis.indexOfBestWord(scores, wordCount, 0, numberOfWordsSoFar); assertEquals("failed normal test", 0, index); index = ReviewAnalysis.indexOfBestWord(scores, wordCount, 3, numberOfWordsSoFar); assertEquals("failed normal test with a cutoff count", 1, index); } @Test public void testIndexOfBestWordNoWordsAboveCount() { double[] scores = {4.0, 1.5, 3.5}; int[] wordCount = {1, 5, 3}; int numberOfWordsSoFar = 3; int index = ReviewAnalysis.indexOfBestWord(scores, wordCount, 10, numberOfWordsSoFar); assertEquals("failed no words with high enough count test", -1, index); } @Test public void testIndexOfWordInArray() { String[] words = {"this", "is", "good"}; int numberOfWordsSoFar = 3; int index = ReviewAnalysis.indexOfWordInArray(words, "this", numberOfWordsSoFar); assertEquals("failed normal test", 0, index); index = ReviewAnalysis.indexOfWordInArray(words, "good", numberOfWordsSoFar); assertEquals("failed normal test", 2, index); index = ReviewAnalysis.indexOfWordInArray(words, "boy", numberOfWordsSoFar); assertEquals("failed normal test word not in array", -1, index); } @Test public void testProcessWords() { String[] words = {"this", "is", "good", ""}; double[] scores = {1.0, 2.0, 3.0, 0.0}; int[] wordCount = {1, 1, 1, 0}; int numberOfWordsSoFar = 3; String more = "this a"; Scanner s = new Scanner(more); int reviewScore = 3; numberOfWordsSoFar = ReviewAnalysis.processWords(s, reviewScore, words, scores, wordCount, numberOfWordsSoFar); assertEquals("failed to add word to numberOfWordsSoFar", 4, numberOfWordsSoFar); assertEquals("failed to update scores", 4.0, scores[0], 1e-9); assertEquals("failed to update wordCount", 2, wordCount[0]); assertEquals("failed to update wordCount", 1, wordCount[3]); } @Test public void testConvertFileToStringArray() { try { String[] lines = ReviewAnalysis.convertFileToStringArray("src/a6/testFile.txt"); assertEquals("failed to add lines to array", 2, lines.length); assertEquals("failed to add make all text lower case", "this is a test", lines[0]); } catch (FileNotFoundException e) { fail("File reported as not found but should have been found."); } } }movie review txt: 1 A series of escapades demonstrating the adage that what is good for the goose is also good for the gander , some of which occasionally amuses but none of which amounts to much of a story . 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 sitting through this one . 3 A positively thrilling combination of ethnography and all the intrigue , betrayal , deceit and murder of a Shakespearean tragedy or a juicy soap opera .......
test file txt: This is a test of the file processing
You should make an a6 package in Eclipse. To that package. add these files ReviewAnalysis,java e ReviewAnalysisTest.javae MovieReviews.txt testFile.txt e Note that the provided code to with the fle names of the text files uses the relative path "src/a6ameOfFile.txt" so instead of finding the file in the project folder, Java goes down into the src and package folders to look for the file there. Assignment Write the program to analyze movie reviews as described in ReviewAnalysis.java. In this file there is an implemented main method which will drive the overall program. The code is provided in there, but it calls methods that need to be implemented. There is a basic set of JUnit tests in ReviewAnalysisTest.java. You might have to add Junit 4 to your build path or do some other setup for the unit tests to run. Look on Piazza for discussion about this if you have issues (or start a discussion) The tests give the behavior for some simple cases. The expected behavior of these methods is much more difficult to understand than earlier methods we have worked on - look at the JUnit cases to see if they help you understand what the methods are supposed to do. This program is more complicated that you have done so far. Do not get discouraged. Take some time to figure what the overall goal of the program is - ook carefully at the lecture slides that worked through the process of scoring a review. Make your own example by hand to see if you can do it. Then, try to see how the methods all work together to solve the problem. Know what the methods to implement are and what they do - you will want to use some to help solve other methods you need to write. Use the test cases to see if you are on the right track. Ask questions! After finishing the program and running it, look at the output of the program where it predicts the score a review should get and compares it to the actual score Write a paragraph describing what you see. Think about how well the prediction does and if there are any trends in the prediction. Can you explain this behavior that you see? Do not just ramble on without a point- look at the output until you see something worth discussing. Add this paragraph as a comment to the bottom of your code fle. Code Style Redo the Javadoc comments to not be assignment-oriented - state what the methods do. Add you and your partner (if you have one) as authors in a Javadoc for the class. Check formatting and naming in your code Submission Submit your ReviewAnalysis.java file to gradescope Sample Output My code, when run, produces this output: The best scoring word is wonderful with a count of 26 and average score of 3.423076923076923 estimated score: 2.2 actual score: 3 Sentiment Predication: Correct I Review: bigelow offers some flashy twists and turns that occasionally fortify t his turgid fable. estimated score: 1.9 actual score: 1 Sentiment Predication: Correct I Review: an unsophisticated sci-fi drama that takes itself all too seriously estimated score: 1.5 actual score: Sentiment Predication: Correct I Review: stupid, infantile, redundant, sloppy, over-the-top, and amateurish estimated score: 2.0 actual score: 2 Sentiment Predication: CorrectI Review: resident evil is what comes from taking john carpenter 's ghosts of mar s and eliminating the beheadings . estimated score: 1.8 actual score Sentiment Predication: Correct Review: the movie resolutely avoids all the comic possibilities of its situatio n, and becomes one more dumb high school comedy about sex gags and prom dates. estimated score: 2.3 actual score: 4 Sentiment Predication: Correct I Review: with or without the sex, a wonderful tale of love and destiny, told w ell by a master storyteller estimated score: 2.2 actual score: 3 Sentiment Predication: CorrectI Review: though it goes further than both, anyone who has seen the hunger or coa t people will find little new here, but a tasty performance from vincent gallo lifts this tale of cannibal lust above the ordinary estimated score: 2.3 actual score: 3 Sentiment Predication: Correct I Review: a terrific date movie, whatever your orientation estimated score: 1.9 actual score: Sentiment Predication: Correct I Review: once the expectation of laughter has been quashed by whatever obscenity is at hand, even the funniest idea is n't funny estimated score: 1.9 actual score: 1 Sentiment Predication: Correct I Review: how do you make a movie with depth about a man who lacked any? estimated score: 1.8 actual score: 1 Sentiment Predication: Correct I Review: translationwe do n't need to try very hard. estimated score: 2.2 actual score: 4 Sentiment Predication: Correct I Review round a campfire around midnight, telling creepy stories to give each other the willies estimated score: 2.0 actual score: 2 Sentiment Predication: Wrong Review: less front-loaded and more shapely than the two-hour version released her e in 1990 estimated score: 2.2 actual score: 4 Sentiment Predication: Correct I Review: an ambitious movie that, like shiner 's organizing of the big fight, pulls off enough of its effects to make up for the ones that do n't come off. estimated score: 2.3 actual score: 4 Sentiment Predication: Correct I Review: some movies suck you in despite their flaws, and heaven is one such be ast. estimated score: 2.4 actual score: 4 Sentiment Predication: Correct I Review: very well written and directed with brutal honesty and respect for its audience estimated score: 2.5 actual score: 4 Sentiment Predication: Correct I Review: twenty years after its first release, e.t. remains the most wondrous o f all hollywood fantasies and the apex of steven spielberg 's misunderstood career. estimated score: 1.9 actual score 1 Sentiment Predication: Correct Review: gooding offers a desperately ingratiating performance . estimated score: 1.8 actual score:1 Sentiment Predication: Correct I Review:.stumbles over every cheap trick in the book trying to make the outr age come even easier estimated score: 2.4 actual score: 3 Sentiment Predication: Correct I Review: nicely combines the enigmatic features of memento with the hallucin atory drug culture of requiem for a dream frailtyoffers chills much like those that you get when sitting a You should make an a6 package in Eclipse. To that package. add these files ReviewAnalysis,java e ReviewAnalysisTest.javae MovieReviews.txt testFile.txt e Note that the provided code to with the fle names of the text files uses the relative path "src/a6ameOfFile.txt" so instead of finding the file in the project folder, Java goes down into the src and package folders to look for the file there. Assignment Write the program to analyze movie reviews as described in ReviewAnalysis.java. In this file there is an implemented main method which will drive the overall program. The code is provided in there, but it calls methods that need to be implemented. There is a basic set of JUnit tests in ReviewAnalysisTest.java. You might have to add Junit 4 to your build path or do some other setup for the unit tests to run. Look on Piazza for discussion about this if you have issues (or start a discussion) The tests give the behavior for some simple cases. The expected behavior of these methods is much more difficult to understand than earlier methods we have worked on - look at the JUnit cases to see if they help you understand what the methods are supposed to do. This program is more complicated that you have done so far. Do not get discouraged. Take some time to figure what the overall goal of the program is - ook carefully at the lecture slides that worked through the process of scoring a review. Make your own example by hand to see if you can do it. Then, try to see how the methods all work together to solve the problem. Know what the methods to implement are and what they do - you will want to use some to help solve other methods you need to write. Use the test cases to see if you are on the right track. Ask questions! After finishing the program and running it, look at the output of the program where it predicts the score a review should get and compares it to the actual score Write a paragraph describing what you see. Think about how well the prediction does and if there are any trends in the prediction. Can you explain this behavior that you see? Do not just ramble on without a point- look at the output until you see something worth discussing. Add this paragraph as a comment to the bottom of your code fle. Code Style Redo the Javadoc comments to not be assignment-oriented - state what the methods do. Add you and your partner (if you have one) as authors in a Javadoc for the class. Check formatting and naming in your code Submission Submit your ReviewAnalysis.java file to gradescope Sample Output My code, when run, produces this output: The best scoring word is wonderful with a count of 26 and average score of 3.423076923076923 estimated score: 2.2 actual score: 3 Sentiment Predication: Correct I Review: bigelow offers some flashy twists and turns that occasionally fortify t his turgid fable. estimated score: 1.9 actual score: 1 Sentiment Predication: Correct I Review: an unsophisticated sci-fi drama that takes itself all too seriously estimated score: 1.5 actual score: Sentiment Predication: Correct I Review: stupid, infantile, redundant, sloppy, over-the-top, and amateurish estimated score: 2.0 actual score: 2 Sentiment Predication: CorrectI Review: resident evil is what comes from taking john carpenter 's ghosts of mar s and eliminating the beheadings . estimated score: 1.8 actual score Sentiment Predication: Correct Review: the movie resolutely avoids all the comic possibilities of its situatio n, and becomes one more dumb high school comedy about sex gags and prom dates. estimated score: 2.3 actual score: 4 Sentiment Predication: Correct I Review: with or without the sex, a wonderful tale of love and destiny, told w ell by a master storyteller estimated score: 2.2 actual score: 3 Sentiment Predication: CorrectI Review: though it goes further than both, anyone who has seen the hunger or coa t people will find little new here, but a tasty performance from vincent gallo lifts this tale of cannibal lust above the ordinary estimated score: 2.3 actual score: 3 Sentiment Predication: Correct I Review: a terrific date movie, whatever your orientation estimated score: 1.9 actual score: Sentiment Predication: Correct I Review: once the expectation of laughter has been quashed by whatever obscenity is at hand, even the funniest idea is n't funny estimated score: 1.9 actual score: 1 Sentiment Predication: Correct I Review: how do you make a movie with depth about a man who lacked any? estimated score: 1.8 actual score: 1 Sentiment Predication: Correct I Review: translationwe do n't need to try very hard. estimated score: 2.2 actual score: 4 Sentiment Predication: Correct I Review round a campfire around midnight, telling creepy stories to give each other the willies estimated score: 2.0 actual score: 2 Sentiment Predication: Wrong Review: less front-loaded and more shapely than the two-hour version released her e in 1990 estimated score: 2.2 actual score: 4 Sentiment Predication: Correct I Review: an ambitious movie that, like shiner 's organizing of the big fight, pulls off enough of its effects to make up for the ones that do n't come off. estimated score: 2.3 actual score: 4 Sentiment Predication: Correct I Review: some movies suck you in despite their flaws, and heaven is one such be ast. estimated score: 2.4 actual score: 4 Sentiment Predication: Correct I Review: very well written and directed with brutal honesty and respect for its audience estimated score: 2.5 actual score: 4 Sentiment Predication: Correct I Review: twenty years after its first release, e.t. remains the most wondrous o f all hollywood fantasies and the apex of steven spielberg 's misunderstood career. estimated score: 1.9 actual score 1 Sentiment Predication: Correct Review: gooding offers a desperately ingratiating performance . estimated score: 1.8 actual score:1 Sentiment Predication: Correct I Review:.stumbles over every cheap trick in the book trying to make the outr age come even easier estimated score: 2.4 actual score: 3 Sentiment Predication: Correct I Review: nicely combines the enigmatic features of memento with the hallucin atory drug culture of requiem for a dream frailtyoffers chills much like those that you get when sitting a
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started