punctuation_chars = ["'", '"', ",", ".", "!
", ":", ";", '#', '@']
def strip_punctuation(word):
for ch in punctuation_chars:
if ch in word:
word = [Link](ch)
word = [Link]('.','')
return word
!!!!!!!!!!!!!!!!!!!
punctuation_chars = ["'", '"', ",", ".", "!", ":", ";", '#', '@']
def strip_punctuation(word):
for ch in punctuation_chars:
if ch in word:
word = [Link](ch)
word = [Link]('.','')
return word
def get_pos(strng):
strng = [Link](" ")
#print(strng)
positive = 0
for wod in strng:
if strip_punctuation(wod) in positive_words:
positive+=1
return positive
# list of positive words to use
positive_words = []
with open("positive_words.txt") as pos_f:
for lin in pos_f:
if lin[0] != ';' and lin[0] != '\n':
positive_words.append([Link]())
#print(positive_words)
!!!!!!!!!!!!!!!1
punctuation_chars = ["'", '"', ",", ".", "!", ":", ";", '#', '@']
def strip_punctuation(word):
for ch in punctuation_chars:
if ch in word:
word = [Link](ch)
word = [Link]('.','')
return word
def get_neg(nstr):
nstr = [Link](" ")
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([Link]())
!!!!!!!!!!!!!!!!!!!!!
punctuation_chars = ["'", '"', ",", ".", "!", ":", ";", '#', '@']
def strip_punctuation(word):
for ch in punctuation_chars:
if ch in word:
word = [Link](ch)
word = [Link]('.','')
return word
def get_neg(nstr):
nstr = [Link](" ")
print(nstr)
negative = 0
for wrd in nstr:
if strip_punctuation(wrd) in negative_words:
negative +=1
return negative
def get_pos(strng):
strng = [Link](" ")
#print(strng)
positive = 0
for wod in strng:
if strip_punctuation(wod) in positive_words:
positive+=1
return positive
# lists of words to use
positive_words = []
with open("positive_words.txt") as pos_f:
for lin in pos_f:
if lin[0] != ';' and lin[0] != '\n':
positive_words.append([Link]())
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([Link]())
outfile = open("resulting_data.csv","w")
[Link]("Number of Retweets, Number of Replies, Positive Score, Negative
Score, Net Score")
[Link]('\n')
fileconnection = open("project_twitter_data.csv", 'r')
lines = [Link]()
print(lines)
header = lines[0]
field_names = [Link]().split(',')
print(field_names)
for row in lines[1:]:
vals = [Link]().split(',')
row_string = '{},{},{},{},
{}'.format(vals[1],vals[2],get_pos(vals[0]),get_neg(vals[0]),get_pos(vals[0])-
get_neg(vals[0]))
[Link](row_string)
[Link]('\n')
[Link]()
!!!!!!!!!!!!!!!!!!!!!!!!