Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose you have a text file (.txt) and want to analyze the sentiment of the tex

ID: 3741714 • Letter: S

Question

 Suppose you have a text file (.txt) and want to analyze the sentiment of the text on the sentence level. That is, we want to classify each sentence in this text as having either positive, neutral, or negative sentiment. The following three sentences illustrate each sentiment type. For example,   I am so excited about my new car. (Positive sentiment)  I feel tired and moody today. (Negative sentiment)  There is parked car on the street. (Neutral sentiment)  To aid us in deciding which words carry positive, neutral, or negative sentiment, we will consult the two files  positivesentimentwords.txt (http://homepages.math.uic.edu/~adrovic/mcs260-s2018/project2/positivesentimentwords.txt) and negativesentimentwords.txt (http://homepages.math.uic.edu/~adrovic/mcs260-s2018/project2/negativesentimentwords.txt). Each of these files contains a list of words that are generally associated with positive/negativesentiment.   The classification of each sentence as being positive, neutral, or negative is based on the following assessment. If more words in a sentence carry the positive sentiment than negative, we will classify that sentence as having a positive sentiment. If the number of positive and negative words in a sentence is equal, we will classify that sentence as neutral. Otherwise, the sentence is classified as having a negative sentiment.   Upon completion, your code should print sentence counts for each sentiment type:   Positive:   Negative: 

Explanation / Answer

The following code should achieve whats been asked:

Sample Output:-

F:Python34python.exe "F:/Python Codes/Chegg_Codes/sentiment/program.py"
Positive: 2
Negative: 2

Process finished with exit code 0

input.txt:-

The code works in the following way.

1. We read each line of the input.txt file. That line is split into individual words.

2. For each word in the line, we check if it is a positive or negative word by looking it up in respective lists.

3. If a word is found positive , the score for that line is incremented by 1.

if a word is found negative , the score for that line is decremented by 1.

else (neutral) the score remains unchanged.

4. Once we do this process for all words in the line, we get a final score for that line.

If the final score is > 0 (positive value) then the line is positive and we increment by 1 the counter for positive lines

If the final score is < 0 (negative value) then the line is negative and we decrement by 1 the counter for negative lines.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote