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:
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import sys
|
||||
import string
|
||||
import nltk
|
||||
import pickle
|
||||
@@ -14,6 +15,9 @@ from os import path
|
||||
from senpy.plugins import SentimentPlugin, SenpyPlugin
|
||||
from senpy.models import Results, Entry, Sentiment
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
unicode = str
|
||||
|
||||
|
||||
class SentimentBasic(SentimentPlugin):
|
||||
'''
|
||||
@@ -43,7 +47,7 @@ class SentimentBasic(SentimentPlugin):
|
||||
|
||||
def _load_pos_tagger(self):
|
||||
self.pos_path = self.find_file(self.pos_path)
|
||||
with open(self.pos_path, 'r') as f:
|
||||
with open(self.pos_path, 'rb') as f:
|
||||
tagger = pickle.load(f)
|
||||
return tagger
|
||||
|
||||
|
@@ -62,7 +62,7 @@ class SentiWordNet(object):
|
||||
senti_scores = []
|
||||
synsets = wordnet.synsets(word,pos)
|
||||
for synset in synsets:
|
||||
if self.pos_synset.has_key((synset.pos(), synset.offset())):
|
||||
if (synset.pos(), synset.offset()) in self.pos_synset:
|
||||
pos_val, neg_val = self.pos_synset[(synset.pos(), synset.offset())]
|
||||
senti_scores.append({"pos":pos_val,"neg":neg_val,\
|
||||
"obj": 1.0 - (pos_val - neg_val),'synset':synset})
|
||||
|
Reference in New Issue
Block a user