mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-13 04:02:29 +00:00
affect plugin added
This commit is contained in:
parent
ac5ac2d06b
commit
864ca75b8f
10
affect/README.md
Normal file
10
affect/README.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Senpy Plugin for Sentiment and Emotion
|
||||
|
||||
This plugin allows to choose sentiment and emotion plugins to retrieve a response with the total sentiment and emotion analysis.
|
||||
|
||||
You can adjust the parameters of the plugin as follows:
|
||||
|
||||
- Sentiments plugins: EmoTextANEW, EmoTextWAF(only english)
|
||||
- Emotions plugins: sentiText, vaderSentiment,meaningCloud(requires API KEY)
|
||||
- Endpoint: the endpoint where the used plugins are. (default: http://senpy.cluster.gsi.dit.upm.es/api/)
|
||||
- Language: english(en) or spanish(es)
|
48
affect/sentiEmotions.py
Normal file
48
affect/sentiEmotions.py
Normal file
@ -0,0 +1,48 @@
|
||||
import time
|
||||
import requests
|
||||
import json
|
||||
import string
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
from os import path
|
||||
import time
|
||||
from senpy.plugins import SentimentPlugin, SenpyPlugin
|
||||
from senpy.models import Results, Entry, Sentiment
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class unifiedPlugin(SentimentPlugin):
|
||||
|
||||
def activate(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
def deactivate(self, *args, **kwargs):
|
||||
self.close()
|
||||
|
||||
|
||||
def analyse(self, **params):
|
||||
|
||||
txt = params["input"]
|
||||
endpoint = params["endpoint"]
|
||||
lang = params.get("language")
|
||||
|
||||
if params["emotions-plugin"] == 'EmoTextWAF':
|
||||
lang = 'en'
|
||||
sentiplug = params["sentiments-plugin"]
|
||||
s_params = {'algo':sentiplug,'language':lang,'i':txt.encode('utf-8')}
|
||||
senti_response = Results(requests.get(endpoint, params=s_params).json())
|
||||
emoplug = params["emotions-plugin"]
|
||||
e_params = {'algo':emoplug,'language':lang,'i':txt.encode('utf-8')}
|
||||
emo_response = Results(requests.get(endpoint, params=e_params).json())
|
||||
|
||||
|
||||
#Senpy Response
|
||||
response = Results()
|
||||
response.analysis = [senti_response.analysis, emo_response.analysis]
|
||||
unified = senti_response.entries[0]
|
||||
unified["emotions"] = emo_response.entries[0]["emotions"]
|
||||
response.entries.append(unified)
|
||||
|
||||
return response
|
36
affect/sentiEmotions.senpy
Normal file
36
affect/sentiEmotions.senpy
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "affect",
|
||||
"module": "sentiEmotions",
|
||||
"description": "Sentiment Analysis and Emotion Recognition",
|
||||
"author": "GSI UPM",
|
||||
"version": "0.1",
|
||||
"extra_params": {
|
||||
"language": {
|
||||
"aliases": ["language", "l"],
|
||||
"required": true,
|
||||
"options": ["en","es"],
|
||||
"default": "en"
|
||||
},
|
||||
"sentiments-plugin": {
|
||||
"aliases": ["sentiplug"],
|
||||
"required": true,
|
||||
"options": ["meaningCloud","sentiText","vaderSentiment"],
|
||||
"default": "sentiText"
|
||||
},
|
||||
"emotions-plugin": {
|
||||
"aliases": ["emoplug"],
|
||||
"required": true,
|
||||
"options": ["EmoTextWAF","EmoTextANEW"],
|
||||
"default": "EmoTextANEW"
|
||||
},
|
||||
"endpoint": {
|
||||
"aliases": ["endpoint"],
|
||||
"required": true,
|
||||
"options": ["http://senpy.cluster.gsi.dit.upm.es/api/"],
|
||||
"default": "http://senpy.cluster.gsi.dit.upm.es/api/"
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
"requirements": {},
|
||||
}
|
Loading…
Reference in New Issue
Block a user