Skip to content
Snippets Groups Projects
Commit 3086d56e authored by davegii's avatar davegii
Browse files

finished analysis

parent c1341314
No related branches found
No related tags found
No related merge requests found
File added
......@@ -23,7 +23,7 @@ def overall_sentiment(text):
if percent_sentiment['pos'] < 0.1:
if percent_sentiment['pos']-percent_sentiment['neg'] <= 0 or percent_sentiment['compound'] <= -0.5: # The "=" makes it better
print("Sentence overall rated as positive")
print("Sentence overall rated as negative")
print("\n")
#print("Negative")
return "Negative"
......@@ -36,27 +36,27 @@ def overall_sentiment(text):
pos_count = 0
pos_correct = 0
# pos_count = 0
# pos_correct = 0
file_positive = open("positive.txt","r")
file_positive_lines = file_positive.readlines()
for line in file_positive_lines:
sentiment = overall_sentiment(line)
if sentiment == "Positive":
pos_correct += 1
pos_count += 1
# file_positive = open("positive.txt","r")
# file_positive_lines = file_positive.readlines()
# for line in file_positive_lines:
# sentiment = overall_sentiment(line)
# if sentiment == "Positive":
# pos_correct += 1
# pos_count += 1
neg_count = 0
neg_correct = 0
# neg_count = 0
# neg_correct = 0
file_negative = open("negative.txt","r")
file_negative_lines = file_negative.readlines()
for line in file_negative_lines:
sentiment = overall_sentiment(line)
if sentiment == "Negative":
neg_correct += 1
neg_count += 1
# file_negative = open("negative.txt","r")
# file_negative_lines = file_negative.readlines()
# for line in file_negative_lines:
# sentiment = overall_sentiment(line)
# if sentiment == "Negative":
# neg_correct += 1
# neg_count += 1
print("Positive accuracy using vader= {}% via {} samples".format(pos_correct/pos_count*100.0, pos_count))
print("Negative accuracy using vader= {}% via {} samples".format(neg_correct/neg_count*100.0, neg_count))
# print("Positive accuracy using vader= {}% via {} samples".format(pos_correct/pos_count*100.0, pos_count))
# print("Negative accuracy using vader= {}% via {} samples".format(neg_correct/neg_count*100.0, neg_count))
......@@ -7,9 +7,17 @@ import csv
import re
import string
import preprocessor as p
import analysis
import emoji
# Remove Emojis
def give_emoji_free_text(text):
allchars = [str for str in text]
emoji_list = [c for c in allchars if c in emoji.UNICODE_EMOJI]
clean_text = ' '.join([str for str in text.split() if not any(i in str for i in emoji_list)])
return clean_text
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
......@@ -19,8 +27,10 @@ api = tweepy.API(auth,wait_on_rate_limit=True)
search_words = "#wildfires" # enter your words
new_search = search_words + " -filter:retweets"
for tweets in api.search_tweets(q="iphone", lang="en", count=100, since_id=0):
print(tweets.text.encode('utf-8'))
for tweets in api.search_tweets(q=new_search, lang="en", count=100, since_id=0):
print(tweets.text)
text = give_emoji_free_text(text=tweets.text)
analysis.overall_sentiment(text)
# #for tweet in tweepy.Cursor(api.search_tweets,q=new_search,count=100,
# lang="en",
# since_id=0).items():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment