1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-11-25 01:22:28 +00:00

Fixed sentiment-basic plugin that only retrieved Neutral sentiment. This closes senpy/senpy-plugins-community#6. Also added nltk download for some plugins.

This commit is contained in:
militarpancho 2017-04-17 13:57:27 +02:00
parent 85db4db01d
commit e341cc82fa
3 changed files with 6 additions and 19 deletions

View File

@ -1,15 +1,9 @@
from gsiupm/senpy:0.6.1-python2.7
from gsiupm/senpy:0.8.7-python2.7
RUN mkdir -p /senpy-plugins
RUN pip install nltk
RUN python -m nltk.downloader stopwords
RUN python -m nltk.downloader punkt
RUN python -m nltk.downloader maxent_treebank_pos_tagger
RUN python -m nltk.downloader wordnet
RUN pip install pytest
RUN pip install mock
ADD . /senpy-plugins
RUN senpy -f /senpy-plugins --only-install
WORKDIR /senpy-plugins/

View File

@ -9,7 +9,6 @@ import string
import xml.etree.ElementTree as ET
from nltk.corpus import stopwords
from nltk.corpus import WordNetCorpusReader
from emotion import Emotion as Emo
from pattern.en import parse
from senpy.plugins import EmotionPlugin, SenpyPlugin, ShelfMixin
@ -51,6 +50,8 @@ class EmotionTextPlugin(EmotionPlugin, ShelfMixin):
Emo.emotions[name] = Emo(name, elem.get("isa"))
def activate(self, *args, **kwargs):
nltk.download('stopwords')
self._stopwords = stopwords.words('english')
#local_path=os.path.dirname(os.path.abspath(__file__))
self._categories = {'anger': ['general-dislike',],
@ -81,8 +82,6 @@ class EmotionTextPlugin(EmotionPlugin, ShelfMixin):
self._wn16 = self.sh['wn16']
def deactivate(self, *args, **kwargs):
self.save()

View File

@ -30,6 +30,7 @@ class SentiTextPlugin(SentimentPlugin):
return tagger
def activate(self, *args, **kwargs):
nltk.download(['punkt','wordnet'])
self._swn = self._load_swn()
self._pos_tagger = self._load_pos_tagger()
@ -69,7 +70,6 @@ class SentiTextPlugin(SentimentPlugin):
def analyse_entry(self, entry, params):
language = params.get("language")
text = entry.get("text", None)
tokens = self._tokenize(text)
@ -82,7 +82,6 @@ class SentiTextPlugin(SentimentPlugin):
if len(lemmas) == 0:
continue
tokens[i]['lemmas'][w[0]] = lemmas
if language == "en":
trans = TextBlob(unicode(text))
else:
@ -96,11 +95,10 @@ class SentiTextPlugin(SentimentPlugin):
continue
eq_synset = self._compare_synsets(synsets, tokens, s_i)
useful_synsets[s_i][t_w] = eq_synset
scores = {}
for i in tokens:
scores[i] = {}
if useful_synsets is None:
if useful_synsets != None:
for word in useful_synsets[i]:
if useful_synsets[i][word] is None:
continue
@ -116,9 +114,7 @@ class SentiTextPlugin(SentimentPlugin):
score['score'] = f_score
scores[i][word] = score
break
p = params.get("prefix", None)
for i in scores:
n_pos = 0.0
n_neg = 0.0
@ -127,7 +123,6 @@ class SentiTextPlugin(SentimentPlugin):
n_pos += 1.0
elif scores[i][w]['score'] == 'neg':
n_neg += 1.0
inter = interp1d([-1.0, 1.0], [0.0, 1.0])
try:
g_score = (n_pos - n_neg) / (n_pos + n_neg)
@ -135,7 +130,6 @@ class SentiTextPlugin(SentimentPlugin):
except:
if n_pos == 0 and n_neg == 0:
g_score = 0.5
polarity = 'marl:Neutral'
if g_score > 0.5:
polarity = 'marl:Positive'