mirror of https://github.com/gsi-upm/senpy
Switched to Yapsy
parent
2f7a8d7267
commit
dabf444607
@ -0,0 +1,45 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
from senpy.plugins import SentimentPlugin
|
||||
from senpy.models import Response, Opinion, Entry
|
||||
|
||||
|
||||
class Sentiment140Plugin(SentimentPlugin):
|
||||
EXTRA_PARAMS = {
|
||||
"language": {"aliases": ["language", "l"],
|
||||
"required": False,
|
||||
"options": ["es", "en", "auto"],
|
||||
}
|
||||
}
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(Sentiment140Plugin, self).__init__(name="sentiment140",
|
||||
version="2.0",
|
||||
extraparams=self.EXTRA_PARAMS,
|
||||
**kwargs)
|
||||
|
||||
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"]}]
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
response = Response()
|
||||
polarity_value = int(res.json()["data"][0]["polarity"]) * 25
|
||||
polarity = "marl:Neutral"
|
||||
if polarity_value > 50:
|
||||
polarity = "marl:Positive"
|
||||
elif polarity_value < 50:
|
||||
polarity = "marl:Negative"
|
||||
entry = Entry(text=params["input"])
|
||||
opinion = Opinion(polarity=polarity, polarity_value=polarity_value)
|
||||
entry.opinions.append(opinion)
|
||||
entry.language = lang
|
||||
response.entries.append(entry)
|
||||
return response
|
||||
|
||||
plugin = Sentiment140Plugin()
|
@ -0,0 +1,8 @@
|
||||
[Core]
|
||||
Name = Test plugin of Yapsy
|
||||
Module = prueba
|
||||
[Documentation]
|
||||
Description = What my plugin broadly does
|
||||
Author = My very own name
|
||||
Version = 0.1
|
||||
Website = My very own website
|
@ -1,3 +0,0 @@
|
||||
from senpy.plugins import SenpyPlugin
|
||||
|
||||
plugin = SenpyPlugin("dummy")
|
@ -0,0 +1,6 @@
|
||||
from senpy.plugins import SenpyPlugin
|
||||
|
||||
class DummyPlugin(SenpyPlugin):
|
||||
def __init__(self):
|
||||
super(DummyPlugin, self).__init__("dummy")
|
||||
|
@ -0,0 +1,8 @@
|
||||
[Core]
|
||||
Name = dummy
|
||||
Module = dummy
|
||||
[Documentation]
|
||||
Description = What my plugin broadly does
|
||||
Author = My very own name
|
||||
Version = 0.1
|
||||
Website = My very own website
|
Loading…
Reference in New Issue