mirror of
https://github.com/gsi-upm/senpy
synced 2025-08-24 02:22:20 +00:00
Plugins names updated
This commit is contained in:
32
sentiment-meaningCloud/README.md
Normal file
32
sentiment-meaningCloud/README.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# 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"
|
52
sentiment-meaningCloud/meaningCloud.py
Normal file
52
sentiment-meaningCloud/meaningCloud.py
Normal file
@@ -0,0 +1,52 @@
|
||||
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,Error
|
||||
|
||||
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 = params["apiKey"]
|
||||
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)
|
||||
if not value:
|
||||
raise Error(r.json())
|
||||
|
||||
#Senpy Response
|
||||
response = Results()
|
||||
polarityValue = 0
|
||||
polarity = 'marl:Neutral'
|
||||
if 'N' in value:
|
||||
polarity = 'marl:Negative'
|
||||
polarityValue = -1
|
||||
elif 'P' in value:
|
||||
polarity = 'marl:Positive'
|
||||
polarityValue = 1
|
||||
entry = Entry(id="Entry0",nif_isString=txt)
|
||||
opinion = Sentiment(id="Opinion0",marl__hasPolarity=polarity,marl__polarityValue = polarityValue)
|
||||
opinion["prov:wasGeneratedBy"] = self.id
|
||||
entry.sentiments = []
|
||||
entry.sentiments.append(opinion)
|
||||
response.entries.append(entry)
|
||||
return response
|
27
sentiment-meaningCloud/meaningCloud.senpy
Normal file
27
sentiment-meaningCloud/meaningCloud.senpy
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "meaningCloud",
|
||||
"module": "sentiment-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"
|
||||
},
|
||||
"apiKey":{
|
||||
"aliases":["meaningCloud-key","apiKey"],
|
||||
"required":true
|
||||
}
|
||||
|
||||
},
|
||||
"requirements": {},
|
||||
}
|
Reference in New Issue
Block a user