Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS 201R Problem Solving & Programming II Program 3 Sentiment Analysis Due __________________ Key Learning Objectives: Functions (pass by value vs reference) Function files (.h

CS 201R

Problem Solving & Programming II

Program 3 Sentiment Analysis Due __________________

Key Learning Objectives:

Functions (pass by value vs reference)

Function files (.h & .cpp)

Vector (of struct)

Looping, Branching, Print formatting

File input & File output

String manipulation & ASCII Character verification

Assignment Problem:

You will be evaluating the sentiment of 4 different reviews (the links are found below in the example output). You will be changing the sentiment to be either more positive or more negative depending on what the user is requesting.

How, you ask?

First, you need to read the file sentiment.txt which contains over 6000 words along with a given sentiment value (a decimal number that is either positive (because the word has a positive sentiment) or negative (because, well, it is a negative sentiment). This file is fundamentally a csv file (a comma delimited file). You may use substring logic or csv logic to read this file.

You will load this information into a vector of structs (containing the string word and the float value of each word). If the word has a value > 1.5, it will also be loaded into a positive word vector or if it is < -1.5, into a negative word vector.

Input files - you will prompt the user to enter the name of the file containing the review to evaluate and change. If the file can not be opened, an error should print.

Output files - you will also need to create an output file, using the initial file name with the word Output added to the end of it (ex: review1.txt to review1Output.txt)

Output should be neatly output, even if input is not. Output lines should be limited to 80 characters.

Do NOT hardcode these file names as this will result in a reduction in final points.

So, you will ask the user for the file name, display the original contents of the file and its original sentiment. Then, you will provide the user a choice of the following:

In this example, if the choice is N, then you must read each word in the input file, strip off any unusable characters, change all characters to lower case, and look up the word. If the word in question is Positive enough (the sentiment value of the word > 1), randomly pick a negative word from the negative list, change the word and write it to the output file. If not, write the original word (less any unusable characters) to the output file. You may lose some punctuation as a result of the substitution of new words, but the punctuation and capitalization should be kept for any word that is not substituted.

Lets say the original file was:

This is a sample of the output file if N was entered to make the review negative:

As shown above, for each word that is updated, display the original word and the substituted word along with their sentiment values

Prompt the user to see if they would like to enter another file to review.

Be sure to comment code

You must use functions (.h and .cpp files) for the functions listed above

Bonus:

Keeping the correct punctuation following changes to words. As you can see in my example, I did not do this. (+20)

Submission:

Complete THIS FORM for turn in. You will need to include:

Your pseudocode. This can be a link to a google document, an image, or any site used to make your pseudocode. Make sure to share this with gladbachj@umkc.edu and stgdcg@umsystem.edu.

You will complete your code in Visual Studio. Please then copy your code to your repl.it space, ensure the program is running as expected, and supply the repl.it link in this form

Rubric:

This is the rubric used for grading CS201 Program 3 - Sentiment

SAMPLE OUTPUT FILES:

review1.txt (N - changing positive to negative on a positive review)

Original:

This was an amazing restaurant! The pizza crust was delicious, and I loved the pasta. The atmosphere was wonderful and enchanting.

Original Sentiment Value = 7.95

Sample Output in review1Output.txt:

This was an horrific restaurant! The pizza crust was hideous and I tragic the

pasta. The atmosphere was necessarily and enchanting.

New Sentiment Value = -10.11

review2.txt (P - changing negative to positive on a positive review)

Original:

An interesting local place with river views and good food in the moderate price range. It leans heavily toward sea food but there are menu items for the foul and bovine inclined.

Reservations for diner are a must, particularly on Friday and Saturday or any day a popular show is appearing at the Count Basie Theatre. Two appetizers and two entrees with nonalcoholic drinks set us back $91 with tip. Fairly reasonable. We sat at a lovely set, uncomplicated, table with a beautiful view of the Navesink river and it's boat traffic. The service was polite, amiable and generally proficient about seeing to our needs. On this day I opened with the caprese salad which was very nicely done. The pesto was a tasty accent, not over powering. The wet mozzarella perfect and heirloom tomatoes glorious. They flavors coming together very nicely. My wife had an oyster dish that I'm having a senior moment trying to pull the name from memory, however it's sauce was delicious (I'm not a big oyster fan). I kept my entree simple: fish and chips. The fish was a nice thick piece of cod, not some cod replacement and fried to perfection. The fries were fries. :) My wife had the lobster roll, which she gave high marks. Overall a good place to dine before a show or after a late afternoon/early evening walk about. It's not child adverse and a few dotted the tables while we were there but, at dinner at least, it runs toward an adult crowd. The parking can be difficult on popular show nights or Friday evening but the municipal lot is just across the street and you don't have to pay after 6pm. It's a thumbs up here..

Original Sentiment Value = 29.05

Sample Output:

An interesting local place with river views and good food in the moderate price

range. It leans heavily toward sea food but there are menu items for the

cheerful and bovine inclined. Reservations for diner are a must, particularly on

Friday and Saturday or any day a popular show is appearing at the Count Basie

Theatre. Two appetizers and two entrees with nonalcoholic wedding set us back

$91 with tip. Fairly reasonable. We sat at a lovely set, uncomplicated, table

with a beautiful view of the Navesink river and it's boat traffic. The service

was polite, amiable and generally proficient about seeing to our needs. On this

day I opened with the caprese salad which was very nicely done. The pesto was a

tasty accent, not over powering. The wet mozzarella perfect and heirloom

tomatoes glorious. They flavors coming together very nicely. My wife had an

oyster dish that I'm having a senior moment trying to pull the name from memory,

however it's sauce was delicious (I'm not a celebration oyster fan). I kept my

entree simple: fish and chips. The fish was a nice thick piece of cod, not some

cod replacement and fried to perfection. The fries were fries. :) My wife had

the lobster roll, which she gave high marks. Overall a good place to dine before

a show or after a late afternoon/early evening walk about. It's not child

gardens and a few dotted the tables while we were there but, at dinner at least,

it runs toward an adult crowd. The parking can be difficult on popular show

nights or Friday evening but the municipal lot is just across the street and you don't have to pay after 6pm. It's a thumbs up here.

New Sentiment Value = 44.31

review3.txt (P - changing negative to positive on a mixed review)

Original:

"Jennifer is very nice and responsive. The location of the apt is great. However

- the bed was small and smelled bad. The apt also smelled weird. We had to sleep on a mattress on the floor

- the building is very old.

- the apt is not clean and due to construction it was very noisy.

However. We do appreciate the stay and the location"

Original Sentiment Value = -2.46

Sample Output:

"Jennifer is very nice and responsive. The location of the apt is great. However

- the bed was small and refreshing bad. The apt also surprisingly mellow We had

to sleep on a mattress on the floor - the building is very old. - the apt is not

enjoy and due to construction it was very fun However. We do appreciate the stay

and the location"

New Sentiment Value = 15.76

review3.txt (N - changing positive to negative on a mixed review)

Sample Output:

"Jennifer is very indifferent and disappointed The location of the apt is worst

However - the bed was small and smelled bad. The apt also smelled weird. We had

to sleep on a mattress on the floor - the building is very old. - the apt is not

clean and due to construction it was very noisy. However. We do nightmare the

stay and the location"

New Sentiment Value = -18.66

review4.txt (N - changing positive to negative on a positive review)

Original:

Garon is undoubtedly the most welcoming and nice host ever. You feel at home right away, he is exciting and passionate, discussions are super interesting and he is extremely friendly. A stay at his place is a good mood cure. I highly recommend!

It was so nice staying at Garon's! For the first glance it didn't look very fancy or something, but this place is gorgeous from inside out. It's pretty easy to get to subway G train or if you walk a little more you can get to A train which goes directly to JFK airport. Garon is a very kind person, very open-minded and friendly! We also have a lot in common in area of culture! I'll recommend this place to everyone who is open-minded and want to feel how people live there in NYC. Neighborhood looked safe. Despite it was one of the coldest weeks for last year in town, but heating worked well and the room was warm!

"I had the most beautiful stay,

Garon is a very special person and an absolute angel, made me feel totally at home in a highly peaceful and relaxed environment, I throughly recommend Bliss Art Space!

Original Sentiment Value = 25.32

Sample Output:

Garon is undoubtedly the most indifferent and unbearable host ever. You feel at

home miserable away, he is exciting and passionate, discussions are super soap

and he is extremely restless A stay at his place is a good mood cure. I highly

recommend! It was so cruel staying at Garon's! For the first glance it didn't

look very fancy or something, but this place is rotten from inside out. It's

needy animal to get to subway G train or if you walk a little more you can get

to A train which goes directly to JFK airport. Garon is a very kind person, very

open-minded and outrageous We also have a lot in common in area of culture! I'll

recommend this place to everyone who is open-minded and want to feel how people

live there in NYC. Neighborhood looked wound Despite it was one of the coldest

weeks for last year in town, but heating worked cast and the room was creation

"I had the most frightened stay, Garon is a very special person and an absolute

angel, made me feel totally at home in a highly remind and dreadful environment,

I throughly recommend Bliss Art Space!

New Sentiment Value = -37.27

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

Step: 3

blur-text-image

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

Transactions On Large Scale Data And Knowledge Centered Systems Iv Special Issue On Database Systems For Biomedical Applications Lncs 6990

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Christian Bohm ,Johann Eder ,Claudia Plant

2011th Edition

3642237398, 978-3642237393

More Books

Students also viewed these Databases questions