1
0
mirror of https://github.com/gsi-upm/senpy synced 2025-08-24 02:22:20 +00:00

tweaks for py2/py3 compatibility

This commit is contained in:
J. Fernando Sánchez
2019-01-09 19:29:24 +01:00
parent 80acb9307c
commit bb6f9ee367
7 changed files with 35 additions and 18 deletions

View File

@@ -17,10 +17,15 @@ For example:
'''
import os, math, re, sys, fnmatch, string
reload(sys)
import codecs
def make_lex_dict(f):
return dict(map(lambda (w, m): (w, float(m)), [wmsr.strip().split('\t')[0:2] for wmsr in open(f) ]))
maps = {}
with codecs.open(f, encoding='iso-8859-1') as f:
for wmsr in f:
w, m = wmsr.strip().split('\t')[:2]
maps[w] = m
return maps
f = 'vader_sentiment_lexicon.txt' # empirically derived valence ratings for words, emoticons, slang, swear words, acronyms/initialisms
try:
@@ -356,8 +361,8 @@ if __name__ == '__main__':
]
sentences.extend(tricky_sentences)
for sentence in sentences:
print sentence,
print(sentence)
ss = sentiment(sentence)
print "\t" + str(ss)
print("\t" + str(ss))
print "\n\n Done!"
print("\n\n Done!")