Created
July 6, 2018 15:40
-
-
Save abhisheksoni27/dcf39313384cdf7a953a7c1f21ec5099 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import re | |
import matplotlib.pyplot as plt | |
import nltk | |
from utilities import cleanText | |
from nltk.sentiment.vader import SentimentIntensityAnalyzer | |
sentiment_analyzer = SentimentIntensityAnalyzer() # Our Great Sentiment Analyzer | |
def analyze(name): | |
linesList = cleanText(name + '.txt') | |
neutral, negative, positive = 0, 0, 0 | |
for index, sentence in enumerate(linesList): | |
print("Processing {0}%".format(str((index * 100) / len(linesList)))) | |
# Ignore Emoji | |
if re.match(r'^[\w]', sentence): | |
continue | |
scores = sentiment_analyzer.polarity_scores(sentence) | |
# We don't need that component | |
scores.pop('compound', None) | |
maxAttribute = max(scores, key=lambda k: scores[k]) | |
if maxAttribute == "neu": | |
neutral += 1 | |
elif maxAttribute == "neg": | |
negative += 1 | |
else: | |
positive += 1 | |
total = neutral + negative + positive | |
print("Negative: {0}% | Neutral: {1}% | Positive: {2}%".format( | |
negative*100/total, neutral*100/total, positive*100/total)) | |
# Plot | |
#### Code Omitted #### | |
analyze(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment