1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-12-22 13:08:13 +00:00

Added meaningCloud plugin

This commit is contained in:
militarpancho 2017-01-12 13:30:14 +01:00
parent aa628518ec
commit 90b55a4b27
3 changed files with 79 additions and 0 deletions

9
meaningCloud/README.md Normal file
View File

@ -0,0 +1,9 @@
# Senpy Plugin MeaningCloud
To use this plugin, you need to obtain an API_KEY from meaningCloud signing up here: https://www.meaningcloud.com/developer/login
Then run Senoy docker image with the path to this plugin as follows:
```
$ docker run -ti -p 5000:5000 -e DAEDALUS_KEY=02079c6e4e97d85f3fa483cd42180042 -v $PWD:/plugins gsiupm/senpy --host 0.0.0.0 -f /plugins
```

View File

@ -0,0 +1,47 @@
import time
import requests
import json
import string
import os
from os import path
import time
from senpy.plugins import SentimentPlugin, SenpyPlugin
from senpy.models import Results, Entry, Sentiment
class DaedalusPlugin(SentimentPlugin):
def activate(self, *args, **kwargs):
pass
def deactivate(self, *args, **kwargs):
self.close()
def analyse(self, **params):
txt = params["input"]
model = params["model"] # general_es / general_es / general_fr
api = 'http://api.meaningcloud.com/sentiment-2.1'
lang = params.get("language")
key = os.environ.get('DAEDALUS_KEY')
parameters = {'key': key,'model': model,'lang': lang,'of': 'json','txt': txt,'src': 'its-not-a-real-python-sdk'}
r = requests.post(api, params=parameters)
print(r.text)
value = r.json().get('score_tag', None)
#Senpy Response
response = Results()
polarity = 'marl:Neutral'
if 'N' in value:
polarity = 'marl:Negative'
elif 'P' in value:
polarity = 'marl:Positive'
entry = Entry(id="Entry0",nif_isString=txt)
opinion = Sentiment(id="Opinion0",marl__hasPolarity=polarity)
opinion["prov:wasGeneratedBy"] = self.id
entry.sentiments = []
entry.sentiments.append(opinion)
response.entries.append(entry)
return response

View File

@ -0,0 +1,23 @@
{
"name": "meaningCloud",
"module": "meaningCloud",
"description": "Sentiment analysis with meaningCloud service",
"author": "GSI UPM",
"version": "1.0",
"extra_params": {
"language": {
"aliases": ["language", "l"],
"required": true,
"options": ["en","es"],
"default": "en"
},
"model": {
"aliases": ["model"],
"required": true,
"options": ["general"],
"default": "general"
}
},
"requirements": {},
}