1
0
mirror of https://github.com/gsi-upm/senpy synced 2025-09-18 12:32:21 +00:00

Added plugin architecture

This commit is contained in:
J. Fernando Sánchez
2014-10-17 12:47:17 +02:00
parent d0aa889124
commit 8405e5deef
12 changed files with 261 additions and 46 deletions

View File

@@ -0,0 +1,48 @@
import requests
import json
import sys
print(sys.path)
from senpy.plugin import SentimentPlugin
class Sentiment140Plugin(SentimentPlugin):
def __init__(self, **kwargs):
super(Sentiment140Plugin, self).__init__(name="Sentiment140",
version="1.0",
**kwargs)
def analyse(self, **params):
res = requests.post("http://www.sentiment140.com/api/bulkClassifyJson",
json.dumps({
"language": "auto",
"data": [{"text": params["input"]}]}
))
response = {"analysis": [{}], "entries": []}
response["analysis"][0].update({ "marl:algorithm": "SimpleAlgorithm",
"marl:minPolarityValue": 0,
"marl:maxPolarityValue": 100})
polarityValue = int(res.json()["data"][0]["polarity"]) * 25
polarity = "marl:Neutral"
if polarityValue > 50:
polarity = "marl:Positive"
elif polarityValue < 50:
polarity = "marl:Negative"
response["entries"] = [
{
"isString": params["input"],
"opinions": [{
"marl:polarityValue": polarityValue,
"marl:hasPolarity": polarity
}]
}
]
return response
plugin = Sentiment140Plugin()