Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

This coding problem (code is in java): Fake reviews can be slanted positive or negative. To create a positive review the program only needs to

This coding problem (code is in java):

Fake reviews can be slanted positive or negative. To create a positive review the program only needs to substitute positive adjectives for neutral or negative adjectives. To create a negative review the program would substitute only negative adjectives for neutral or positive adjectives.

In this activity youll write a new method modeled off the fakeReview method you wrote in Activity 3. The method will be redesigned so that it will make reviews stronger; that is, either more negative or more positive. Use the positiveOrNegative method provided in the Review class to write your new method, and name it after the type of fake review you plan on making.

Remember, we can determine how positive or negative an adjective is by using our sentimentVal method. If a word is above a specific threshold (0), that word is positive!

This is what there is so far in code:

positiveAdjectives.txt

amazing awesome blithesome excellent fabulous fantastic favorable fortuitous gorgeous incredible ineffable mirthful outstanding perfect propitious remarkable rousing spectacular splendid stellar stupendous super upbeat unbelievable wondrous

ReviewTester.java

public class ReviewTester { public static void main(String[] args) { //Test your positive or negative fakeReview here! } }

Review.java

import java.util.Scanner; import java.io.File; import java.util.HashMap; import java.util.ArrayList; import java.util.Random; import java.io.*;

/** * Class that contains helper methods for the Review Lab **/ public class Review { private static HashMap sentiment = new HashMap(); private static ArrayList posAdjectives = new ArrayList(); private static ArrayList negAdjectives = new ArrayList(); private static final String SPACE = " "; static{ try { Scanner input = new Scanner(new File("cleanSentiment.csv")); while(input.hasNextLine()){ String[] temp = input.nextLine().split(","); sentiment.put(temp[0],Double.parseDouble(temp[1])); //System.out.println("added "+ temp[0]+", "+temp[1]); } input.close(); } catch(Exception e){ System.out.println("Error reading or parsing cleanSentiment.csv"); } //read in the positive adjectives in postiveAdjectives.txt try { Scanner input = new Scanner(new File("positiveAdjectives.txt")); while(input.hasNextLine()){ String temp = input.nextLine().trim(); System.out.println(temp); posAdjectives.add(temp); } input.close(); } catch(Exception e){ System.out.println("Error reading or parsing postitiveAdjectives.txt " + e); } //read in the negative adjectives in negativeAdjectives.txt try { Scanner input = new Scanner(new File("negativeAdjectives.txt")); while(input.hasNextLine()){ negAdjectives.add(input.nextLine().trim()); } input.close(); } catch(Exception e){ System.out.println("Error reading or parsing negativeAdjectives.txt"); } } /** * returns a string containing all of the text in fileName (including punctuation), * with words separated by a single space */ public static String textToString( String fileName ) { String temp = ""; try { Scanner input = new Scanner(new File(fileName)); //add 'words' in the file to the string, separated by a single space while(input.hasNext()){ temp = temp + input.next() + " "; } input.close(); } catch(Exception e){ System.out.println("Unable to locate " + fileName); } //make sure to remove any additional space that may have been added at the end of the string. return temp.trim(); } /** * @returns the sentiment value of word as a number between -1 (very negative) to 1 (very positive sentiment) */ public static double sentimentVal( String word ) { try { return sentiment.get(word.toLowerCase()); } catch(Exception e) { return 0; } } /** * Returns the ending punctuation of a string, or the empty string if there is none */ public static String getPunctuation( String word ) { String punc = ""; for(int i=word.length()-1; i >= 0; i--){ if(!Character.isLetterOrDigit(word.charAt(i))){ punc = punc + word.charAt(i); } else { return punc; } } return punc; } /** * Randomly picks a positive adjective from the positiveAdjectives.txt file and returns it. */ public static String randomPositiveAdj() { int index = (int)(Math.random() * posAdjectives.size()); return posAdjectives.get(index); } /** * Randomly picks a negative adjective from the negativeAdjectives.txt file and returns it. */ public static String randomNegativeAdj() { int index = (int)(Math.random() * negAdjectives.size()); return negAdjectives.get(index); } /** * Randomly picks a positive or negative adjective and returns it. */ public static String randomAdjective() { boolean positive = Math.random() < .5; if(positive){ return randomPositiveAdj(); } else { return randomNegativeAdj(); } } //Copy your totalSentiment, starRating, and fakeReview methods to this class public static double totalSentiment(String fileName) { } public static double starRating(String fileName) { } public static String fakeReview(String fileName) { } //Feel free to change the name of this method to match the method you'd like to create. //This method returns either negative or positive review taking a .txt file and returning a String. public static String positiveOrNegative(String fileName) { } }

cleanSentiment.csv

1960s,0.09 1970s,-0.07 1980s,-0.15 1990s,0.05 aaron,-0.32 abandoned,-0.09 abby,0.64 ability,-0.03 able,-0.04 abnormal,-0.34 aboard,-0.15 above,0.2 abrupt,-0.83 abruptly,-1.11 abs,0.58 absence,-0.8 absent,0.08 absolute,-1.51

(all of this a-z)

SimpleReview.txt

This was a terrible restaurant! The pizza crust was too chewy, and I disliked the pasta. I would definitely not come back.

negativeAdjectives.txt

aggressive arrogant belligerent bigoted blunt callous critical cynical dishonest distant envious greedy guarded hostile indifferent intolerant irresponsible jealous pessimistic prejudiced prideful resentful rude sad selfish skeptical suspicious thoughtless unemotional untrusting

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students explore these related Databases questions