all sms on 9/11 day
source :
../share/texts/messages_all.txt (50Mo)
script based on sentiments:
from pattern.en import sentiment
doc = open("/home/k/Documents/messages_all.txt",'r')
data = doc.read()
doc.close()
sentiments = sentiment(data).assessments
result = ""
tags = {}
for elements in sentiments:
word = elements[0][0]
if word in tags:
tags[word] += elements[1]
else:
tags[word] = elements[1]
#classement = []
index={}
for elements in sentiments:
word = elements[0][0]
if word in index:
continue
index[word] = elements
for id_name in tags.keys():
res1 = tags[id_name]
# print res1
res2 = index[id_name]
# print res2
# final = zip(list(res2), str(res1))
ds = [tags, index]
d = {}
for k in tags:
d[k] = tuple(d[k] for d in ds)
res_ok = sorted(d.values(), reverse=False)
for elements in res_ok:
result += "score:{0} word:{1}\n".format(elements[0],elements[1][0][0])
#print result
doc_save = open("/home/k/Documents/results2.txt",'w')
doc_save.write(result)
doc_save.close()