Sentiment 1 Assign
Sentiment 1 Assign
word = word.strip(ch)
word = word.replace('.','')
return word
!!!!!!!!!!!!!!!!!!!
punctuation_chars = ["'", '"', ",", ".", "!", ":", ";", '#', '@']
def strip_punctuation(word):
for ch in punctuation_chars:
if ch in word:
word = word.strip(ch)
word = word.replace('.','')
return word
def get_pos(strng):
strng = strng.split(" ")
#print(strng)
positive = 0
for wod in strng:
if strip_punctuation(wod) in positive_words:
positive+=1
return positive
punctuation_chars = ["'", '"', ",", ".", "!", ":", ";", '#', '@']
def strip_punctuation(word):
for ch in punctuation_chars:
if ch in word:
word = word.strip(ch)
word = word.replace('.','')
return word
def get_neg(nstr):
nstr = nstr.split(" ")
print(nstr)
negative = 0
for wrd in nstr:
if strip_punctuation(wrd) in negative_words:
negative +=1
return negative
negative_words = []
with open("negative_words.txt") as pos_f:
for lin in pos_f:
if lin[0] != ';' and lin[0] != '\n':
negative_words.append(lin.strip())
!!!!!!!!!!!!!!!!!!!!!
punctuation_chars = ["'", '"', ",", ".", "!", ":", ";", '#', '@']
def strip_punctuation(word):
for ch in punctuation_chars:
if ch in word:
word = word.strip(ch)
word = word.replace('.','')
return word
def get_neg(nstr):
nstr = nstr.split(" ")
print(nstr)
negative = 0
for wrd in nstr:
if strip_punctuation(wrd) in negative_words:
negative +=1
return negative
def get_pos(strng):
strng = strng.split(" ")
#print(strng)
positive = 0
for wod in strng:
if strip_punctuation(wod) in positive_words:
positive+=1
return positive
negative_words = []
with open("negative_words.txt") as pos_f:
for lin in pos_f:
if lin[0] != ';' and lin[0] != '\n':
negative_words.append(lin.strip())
outfile = open("resulting_data.csv","w")
outfile.write("Number of Retweets, Number of Replies, Positive Score, Negative
Score, Net Score")
outfile.write('\n')
lines = fileconnection.readlines()
print(lines)
header = lines[0]
field_names = header.strip().split(',')
print(field_names)
for row in lines[1:]:
vals = row.strip().split(',')
row_string = '{},{},{},{},
{}'.format(vals[1],vals[2],get_pos(vals[0]),get_neg(vals[0]),get_pos(vals[0])-
get_neg(vals[0]))
outfile.write(row_string)
outfile.write('\n')
outfile.close()
!!!!!!!!!!!!!!!!!!!!!!!!