1
0
mirror of https://github.com/gsi-upm/senpy synced 2025-08-23 18:12:20 +00:00

PEP8 compliance

This commit is contained in:
J. Fernando Sánchez
2014-11-20 19:29:49 +01:00
parent eaf65f0c6b
commit 2b68838514
14 changed files with 117 additions and 130 deletions

View File

@@ -1,11 +1,10 @@
import requests
import json
import sys
from senpy.plugins import SentimentPlugin
from senpy.models import Response, Opinion, Entry
class Sentiment140Plugin(SentimentPlugin):
EXTRA_PARAMS = {
"language": {"aliases": ["language", "l"],
@@ -13,6 +12,7 @@ class Sentiment140Plugin(SentimentPlugin):
"options": ["es", "en", "auto"],
}
}
def __init__(self, **kwargs):
super(Sentiment140Plugin, self).__init__(name="sentiment140",
version="2.0",
@@ -22,23 +22,21 @@ class Sentiment140Plugin(SentimentPlugin):
def analyse(self, **params):
lang = params.get("language", "auto")
res = requests.post("http://www.sentiment140.com/api/bulkClassifyJson",
json.dumps({
"language": lang,
"data": [{"text": params["input"]}]}
))
json.dumps({"language": lang,
"data": [{"text": params["input"]}]
}
)
)
response = Response()
polarityValue = int(res.json()["data"][0]["polarity"]) * 25
polarity_value = int(res.json()["data"][0]["polarity"]) * 25
polarity = "marl:Neutral"
if polarityValue > 50:
if polarity_value > 50:
polarity = "marl:Positive"
elif polarityValue < 50:
elif polarity_value < 50:
polarity = "marl:Negative"
entry = Entry(text=params["input"])
opinion = Opinion(polarity=polarity, polarityValue=polarityValue)
opinion = Opinion(polarity=polarity, polarity_value=polarity_value)
entry.opinions.append(opinion)
entry.language = lang
response.entries.append(entry)