mirror of
https://github.com/gsi-upm/senpy
synced 2025-08-24 02:22:20 +00:00
Add plugins as submodules
This commit is contained in:
1
sentiment-meaningCloud
Submodule
1
sentiment-meaningCloud
Submodule
Submodule sentiment-meaningCloud added at 56d21c3525
@@ -1,32 +0,0 @@
|
||||
# Senpy Plugin MeaningCloud
|
||||
|
||||
MeaningCloud plugin uses API from Meaning Cloud to perform sentiment analysis.
|
||||
|
||||
For more information about Meaning Cloud and its services, please visit: https://www.meaningcloud.com/developer/apis
|
||||
|
||||
## Usage
|
||||
|
||||
To use this plugin, you need to obtain an API key from meaningCloud signing up here: https://www.meaningcloud.com/developer/login
|
||||
|
||||
When you had obtained the meaningCloud API Key, you have to provide it to the plugin, using the param **apiKey**.
|
||||
|
||||
To use this plugin, you should use a GET Requests with the following possible params:
|
||||
Params:
|
||||
- Language: English (en) and Spanish (es). (default: en)
|
||||
- API Key: the API key from Meaning Cloud. Aliases: ["apiKey","meaningCloud-key"]. (required)
|
||||
- Input: text to analyse.(required)
|
||||
- Model: model provided to Meaning Cloud API (for general domain). (default: general)
|
||||
|
||||
## Example of Usage
|
||||
|
||||
Example request:
|
||||
```
|
||||
http://senpy.cluster.gsi.dit.upm.es/api/?algo=meaningCloud&language=en&apiKey=<put here your API key>&input=I%20love%20Madrid
|
||||
```
|
||||
|
||||
|
||||
Example respond: This plugin follows the standard for the senpy plugin response. For more information, please visit [senpy documentation](http://senpy.readthedocs.io). Specifically, NIF API section.
|
||||
|
||||
![alt GSI Logo][logoGSI]
|
||||
|
||||
[logoGSI]: http://www.gsi.dit.upm.es/images/stories/logos/gsi.png "GSI Logo"
|
@@ -1,76 +0,0 @@
|
||||
import time
|
||||
import logging
|
||||
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,Error
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class DaedalusPlugin(SentimentPlugin):
|
||||
|
||||
|
||||
def _polarity(self, value):
|
||||
|
||||
if 'NONE' in value:
|
||||
polarity = 'marl:Neutral'
|
||||
polarityValue = 0
|
||||
elif 'N' in value:
|
||||
polarity = 'marl:Negative'
|
||||
polarityValue = -1
|
||||
elif 'P' in value:
|
||||
polarity = 'marl:Positive'
|
||||
polarityValue = 1
|
||||
return polarity, polarityValue
|
||||
|
||||
def analyse_entry(self, entry, params):
|
||||
|
||||
txt = entry.get("text",None)
|
||||
model = "general" # general_es / general_es / general_fr
|
||||
api = 'http://api.meaningcloud.com/sentiment-2.1'
|
||||
lang = params.get("language")
|
||||
key = params["apiKey"]
|
||||
parameters = {'key': key,
|
||||
'model': model,
|
||||
'lang': lang,
|
||||
'of': 'json',
|
||||
'txt': txt,
|
||||
'src': 'its-not-a-real-python-sdk'
|
||||
}
|
||||
try:
|
||||
r = requests.post(api, params=parameters, timeout=3)
|
||||
except requests.exceptions.Timeout:
|
||||
raise Error("Meaning Cloud API does not response")
|
||||
api_response = r.json()
|
||||
if not api_response.get('score_tag'):
|
||||
raise Error(r.json())
|
||||
logger.info(api_response)
|
||||
response = Results()
|
||||
agg_polarity, agg_polarityValue = self._polarity(api_response.get('score_tag', None))
|
||||
agg_opinion = Sentiment(id="Opinion0",
|
||||
marl__hasPolarity=agg_polarity,
|
||||
marl__polarityValue = agg_polarityValue,
|
||||
marl__opinionCount = len(api_response['sentence_list']))
|
||||
entry.sentiments.append(agg_opinion)
|
||||
logger.info(api_response['sentence_list'])
|
||||
count = 1
|
||||
for sentence in api_response['sentence_list']:
|
||||
for nopinion in sentence['segment_list']:
|
||||
logger.info(nopinion)
|
||||
polarity, polarityValue = self._polarity(nopinion.get('score_tag', None))
|
||||
opinion = Sentiment(id="Opinion{}".format(count),
|
||||
marl__hasPolarity=polarity,
|
||||
marl__polarityValue=polarityValue,
|
||||
marl__aggregatesOpinion=agg_opinion.get('id'),
|
||||
nif__anchorOf=nopinion.get('text', None),
|
||||
nif__beginIndex=nopinion.get('inip', None),
|
||||
nif__endIndex=nopinion.get('endp', None)
|
||||
)
|
||||
|
||||
count += 1
|
||||
entry.sentiments.append(opinion)
|
||||
yield entry
|
@@ -1,24 +0,0 @@
|
||||
{
|
||||
"name": "sentiment-meaningCloud",
|
||||
"module": "sentiment-meaningCloud",
|
||||
"description": "Sentiment analysis with meaningCloud service. To use this plugin, you need to obtain an API key from meaningCloud signing up here: https://www.meaningcloud.com/developer/login. When you had obtained the meaningCloud API Key, you have to provide it to the plugin, using param apiKey. Example request: http://senpy.cluster.gsi.dit.upm.es/api/?algo=meaningCloud&language=en&apiKey=<put here your API key>&input=I%20love%20Madrid.",
|
||||
"author": "GSI UPM",
|
||||
"version": "1.0",
|
||||
"extra_params": {
|
||||
"language": {
|
||||
"aliases": ["language", "l"],
|
||||
"required": true,
|
||||
"options": ["en","es"],
|
||||
"default": "en"
|
||||
},
|
||||
"apiKey":{
|
||||
"aliases":["meaningCloud-key","apiKey"],
|
||||
"required":true
|
||||
}
|
||||
|
||||
},
|
||||
"requirements": {},
|
||||
"maxPolarityValue": "1",
|
||||
"minPolarityValue": "-1"
|
||||
|
||||
}
|
Reference in New Issue
Block a user