diff --git a/meaningCloud/README.md b/meaningCloud/README.md new file mode 100644 index 0000000..84c8777 --- /dev/null +++ b/meaningCloud/README.md @@ -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 + ``` \ No newline at end of file diff --git a/meaningCloud/meaningCloud.py b/meaningCloud/meaningCloud.py new file mode 100644 index 0000000..c40d68a --- /dev/null +++ b/meaningCloud/meaningCloud.py @@ -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 diff --git a/meaningCloud/meaningCloud.senpy b/meaningCloud/meaningCloud.senpy new file mode 100644 index 0000000..e4ecbc0 --- /dev/null +++ b/meaningCloud/meaningCloud.senpy @@ -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": {}, +}