Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

201107/blob/master/data/opinion-lexicon-English/positive-words.txt] and here (https://github.com/jeffreybreen/twitter-sentiment-analysis-tutorial- 201107/blob/master/data/opinion-lexicon-Englishegative-words.txt). Since you may wish to copy/paste this part to start Part 3.3: 1. You should traverse the given string from

image text in transcribedimage text in transcribedimage text in transcribed
201107/blob/master/data/opinion-lexicon-English/positive-words.txt] and here (https://github.com/jeffreybreen/twitter-sentiment-analysis-tutorial- 201107/blob/master/data/opinion-lexicon-Englishegative-words.txt). Since you may wish to copy/paste this part to start Part 3.3: 1. You should traverse the given string from start to finish. 2. There are no hidden test cases for this part, and you should not start Part 3.3 until you are certain that this part is correct. Hint: Make sure to review the discussion 08 slides (or go to discussion) before trying this one. . Hint: If you are not sure where to start, consider trying to print all of the words in the given string out. This should only take one loop, if you follow the advice in the discussion 08 slides. Once you have that completed, then you need to figure out what to do with each word. . Challenge: Do this problem without storing the words (of the body of text) in a data structure such as a list or dictionary. You can still store the positiveegative words in their respective lists. Except for format ( ) and isalpha ( ), all string methods are banned. . Except for append () and extend (), all list methods are banned. . You may not use the in operator, except to create a for loop (i.e. for . . . in . . .). 523 count words_by_sentiment ( "I am a cat in the hat." ) 523 count_words_by_sentiment ( "I am glad to have this much fun.") (2, 0) pa count_words_by_sentiment ( "I think it is wrong to win by dirty means." ) (1, 2) * # Note that in the below, "amazingly" and "boring" do not count, even though "amazing" and "bored" are in the lists. 523 count_words_by_sentiment ( "This is amazingly boring.") (8, 8) pas count words_by_sentiment ( "Aaron is not cool.") (1, 0) 523 count_words_by_sentiment ( "Dell laptops are waste of money. I am so mad. ") (8, 2) 535 count_words_by_sentiment ( "I am not mad. " ) (0, 1) 523 count_words_by_sentiment ( "I am not mad") (0, 1) >23 count_words_by_sentiment ( "I am kind of sick of seeing the same error") (1, 2)Part 3.1: Counting Words (20 Points) Write a function called count_words_by_sentiment. This function will take a body of text (as one string) and return a 2-tuple in which the first element is the number of positive words in the body of text and the second element is the number of negative words. . A "word" is defined as a contiguous string of alphabetic letters. Thus, characters that are not alphabetic letters, such as numbers, punctuation, and spaces, can be considered "word boundaries". - Hint: You may use the isalpha string method discussed in slide 38 of Lecture 06. . Words are case-sensitive, so if "cool" is in the list of positive words and "Cool" is not, then the sentence "Aaron is Cool." has zero positive words in it. . Note that part of speech is not taken into account, so "amaze" does not count as a positive word, for example, even though "amazing" is in the list of positive words. . The lists of positive and negative words are big, so I have placed them in h6- starter . py in the Canvas Files (you might need to download the file, open it, and then copy/paste, because the Canvas file viewer might mess the formatting up). They are also here, but the PDF might also mess the formatting up: positive_words = ["amazing", "appreciate", "awesome", "beautiful", "best", "brilliant", "celebrate", "cheer", "cool", "delicious", "eager", "enjoy", "fortunate", "fun", "glad", "good", "happy", "kind", "merry", "nice", "pleasant", "polite", "praise", "relax", "sweet", "top-notch", "win", "yay" ] negative_words = [ "aggressive", "anger", "annoy", "bloody", "bored", "careless", "cocky", "death", "defy", "denial", "detest", "dirty", "error", "fail", "guilt", "haunt", "idiot", "implode", "inhumane" "insult", "irritate", "lousy", "mad", "outrage", "poor", "refute", "sick", "strict", "stuck", "unequal", "waste", "wrong" ]example, there is a space between "have" and "been", "poor" and "player", and "be." and "and". 532 count words by sentiment ("She should have died hereafter; \ There would have been a time for such a word. 'n- To-morrow, and to-morrow, and to- morrow, 'nCreeps in this petty pace from day to day, inTo the last syllable of recorded time; nAnd all our yesterdays have lighted fools\ The way to dusty death. Out, out, brief candle! nLife's but a walking shadow, a poor player\ That struts and frets his hour upon the stage nAnd then is heard no more. It is a tale nTold by an idiot, full of sound and fury nSignifying nothing.") (0, 3) 535 count words by sentiment ("I appreciate trying to be the best that I can be, and I have a fun time doing so. Even when I fail, I get back up. Even when I feel stuck, I try my best to rise to the occassion. I don't let any insult take me down. And when I look back 20 years from now, I will cheer and celebrate. I will be glad that I did not give up.") (7, 3)

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

Students also viewed these Programming questions