mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-14 04:32:29 +00:00
Added meaningCloud to affect
This commit is contained in:
parent
864ca75b8f
commit
82e3062a6b
@ -8,7 +8,7 @@ import logging
|
|||||||
from os import path
|
from os import path
|
||||||
import time
|
import time
|
||||||
from senpy.plugins import SentimentPlugin, SenpyPlugin
|
from senpy.plugins import SentimentPlugin, SenpyPlugin
|
||||||
from senpy.models import Results, Entry, Sentiment
|
from senpy.models import Results, Entry, Sentiment, Error
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -22,20 +22,34 @@ class unifiedPlugin(SentimentPlugin):
|
|||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
|
||||||
def analyse(self, **params):
|
def analyse(self, **kwargs):
|
||||||
|
params = dict(kwargs)
|
||||||
txt = params["input"]
|
txt = params["input"]
|
||||||
|
logger.info('TXT:%s' % txt)
|
||||||
endpoint = params["endpoint"]
|
endpoint = params["endpoint"]
|
||||||
lang = params.get("language")
|
lang = params.get("language")
|
||||||
|
|
||||||
if params["emotions-plugin"] == 'EmoTextWAF':
|
|
||||||
lang = 'en'
|
|
||||||
sentiplug = params["sentiments-plugin"]
|
sentiplug = params["sentiments-plugin"]
|
||||||
s_params = {'algo':sentiplug,'language':lang,'i':txt.encode('utf-8')}
|
s_params = params.copy()
|
||||||
senti_response = Results(requests.get(endpoint, params=s_params).json())
|
s_params.update({'algo':sentiplug,'language':lang})
|
||||||
|
senti_response = requests.get(endpoint, params=s_params).json()
|
||||||
|
logger.info('SENTIPARAMS: %s' % s_params)
|
||||||
|
if 'entries' not in senti_response:
|
||||||
|
raise Error(senti_response)
|
||||||
|
senti_response = Results(senti_response)
|
||||||
|
logger.info('SENTI: %s' % senti_response)
|
||||||
|
logger.info(senti_response)
|
||||||
emoplug = params["emotions-plugin"]
|
emoplug = params["emotions-plugin"]
|
||||||
e_params = {'algo':emoplug,'language':lang,'i':txt.encode('utf-8')}
|
e_params = params.copy()
|
||||||
emo_response = Results(requests.get(endpoint, params=e_params).json())
|
e_params.update({'algo':emoplug,'language':lang})
|
||||||
|
emo_response = requests.get(endpoint, params=e_params).json()
|
||||||
|
if 'entries' not in emo_response:
|
||||||
|
raise Error(emo_response)
|
||||||
|
emo_response = Results(emo_response)
|
||||||
|
logger.info('EMO: %s' % emo_response)
|
||||||
|
logger.info(emo_response)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Senpy Response
|
#Senpy Response
|
||||||
|
@ -28,6 +28,10 @@
|
|||||||
"required": true,
|
"required": true,
|
||||||
"options": ["http://senpy.cluster.gsi.dit.upm.es/api/"],
|
"options": ["http://senpy.cluster.gsi.dit.upm.es/api/"],
|
||||||
"default": "http://senpy.cluster.gsi.dit.upm.es/api/"
|
"default": "http://senpy.cluster.gsi.dit.upm.es/api/"
|
||||||
|
},
|
||||||
|
"apiKey": {
|
||||||
|
"aliases": ["apikey"],
|
||||||
|
"required": false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,7 +24,8 @@ class DaedalusPlugin(SentimentPlugin):
|
|||||||
model = params["model"] # general_es / general_es / general_fr
|
model = params["model"] # general_es / general_es / general_fr
|
||||||
api = 'http://api.meaningcloud.com/sentiment-2.1'
|
api = 'http://api.meaningcloud.com/sentiment-2.1'
|
||||||
lang = params.get("language")
|
lang = params.get("language")
|
||||||
key = os.environ.get('DAEDALUS_KEY')
|
#key = os.environ.get('DAEDALUS_KEY')
|
||||||
|
key = params["apiKey"]
|
||||||
parameters = {'key': key,'model': model,'lang': lang,'of': 'json','txt': txt,'src': 'its-not-a-real-python-sdk'}
|
parameters = {'key': key,'model': model,'lang': lang,'of': 'json','txt': txt,'src': 'its-not-a-real-python-sdk'}
|
||||||
r = requests.post(api, params=parameters)
|
r = requests.post(api, params=parameters)
|
||||||
print(r.text)
|
print(r.text)
|
||||||
|
@ -17,6 +17,10 @@
|
|||||||
"options": ["general"],
|
"options": ["general"],
|
||||||
"default": "general"
|
"default": "general"
|
||||||
}
|
}
|
||||||
|
"apiKey":{
|
||||||
|
"aliases":["meaningCloud-key"],
|
||||||
|
"required":true
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
"requirements": {},
|
"requirements": {},
|
||||||
|
Loading…
Reference in New Issue
Block a user