In: Computer Science
Perform a sentiment analysis of a big text file in python
Extract each word from the file, transform the words to lower case, and remove special characters from the words using code similar to the following line:w=w.replace(':','').replace('?','').replace(',','').replace('.','').replace('"','').replace('!','').replace('(','').replace(')','').replace('\'','').replace('\\','').replace('/','')
Utilize the lists of positive words, found in positive.txt to perform a sentiment analysis on the file (count how many positive words there are in a file)
positive.txt
crisp
crisper
cure
cure-all
cushy
cute
cuteness
danke
danken
daring
...
file.txt
...has a new campaign song. \nNot sure why they chose this one but, wow!\xf0\x9f\x98\x82 \xf0\x9f\xa4\xb7\xe2\x80\x8d\xe2\x99\x82\xef\xb8\x8f \xf0\x9f\xa4\xaf\n\nHey @JoeBob you may want to replac\xe2\x80\xa6\n'b"RT @EdZipperer: .@AriFlish is 100% correct about the debate....
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU
def fileContain(s,filename):
f = open(filename,'r')
for i in f:
if(i==s):
return True
return False
count = 0
f = open("file.txt", 'r')
for i in f:
s = i.split(" ")
for w in s:
w = w.replace(':', '').replace('?', '').replace(',', '').replace('.', '').replace('"', '').replace(
'!', '').replace('(', '').replace(')', '').replace('\'', '').replace('\\', '').replace('/', '')
if(fileContain(w,"positive.txt")):
count+=1
print(count)