1
0
mirror of https://github.com/gsi-upm/senpy synced 2025-08-24 02:22:20 +00:00

Merged into monorepo

This commit is contained in:
J. Fernando Sánchez
2018-06-14 19:38:08 +02:00
parent e51b659030
commit c52a894017
29 changed files with 406 additions and 493 deletions

View File

@@ -1,10 +1,12 @@
# Sentimet-vader plugin
=========
Vader is a plugin developed at GSI UPM for sentiment analysis.
The response of this plugin uses [Marl ontology](https://www.gsi.dit.upm.es/ontologies/marl/) developed at GSI UPM for semantic web.
## Acknowledgements
This plugin uses the vaderSentiment module underneath, which is described in the paper:
For developing this plugin, it has been used the module vaderSentiment, which is described in the paper:
VADER: A Parsimonious Rule-based Model for Sentiment Analysis of Social Media Text
C.J. Hutto and Eric Gilbert
Eighth International Conference on Weblogs and Social Media (ICWSM-14). Ann Arbor, MI, June 2014.
@@ -15,16 +17,16 @@ For more information about the functionality, check the official repository
https://github.com/cjhutto/vaderSentiment
The response of this plugin uses [Marl ontology](https://www.gsi.dit.upm.es/ontologies/marl/) developed at GSI UPM for semantic web.
## Usage
Params accepted:
Parameters:
- Language: es (Spanish), en(English).
- Input: Text to analyse.
Example request:
```
http://senpy.cluster.gsi.dit.upm.es/api/?algo=sentiment-vader&language=en&input=I%20love%20Madrid
```

View File

@@ -1,16 +0,0 @@
==========
This README file describes the plugin vaderSentiment.
For developing this plugin, it has been used the module vaderSentiment, which is described in the paper:
VADER: A Parsimonious Rule-based Model for Sentiment Analysis of Social Media Text
C.J. Hutto and Eric Gilbert
Eighth International Conference on Weblogs and Social Media (ICWSM-14). Ann Arbor, MI, June 2014.
If you use this plugin in your research, please cite the above paper
For more information about the functionality, check the official repository
https://github.com/cjhutto/vaderSentiment
========

View File

@@ -1,25 +0,0 @@
{
"name": "sentiment-vader",
"module": "sentiment-vader",
"description": "Sentiment classifier using vaderSentiment module. Params accepted: Language: {en, es}. The output uses Marl ontology developed at GSI UPM for semantic web.",
"author": "@icorcuera",
"version": "0.1",
"extra_params": {
"language": {
"@id": "lang_rand",
"aliases": ["language", "l"],
"required": false,
"options": ["es", "en", "auto"]
},
"aggregate": {
"aliases": ["aggregate","agg"],
"options": ["true", "false"],
"required": false,
"default": false
}
},
"requirements": {}
}

View File

@@ -1,44 +0,0 @@
import os
import logging
logging.basicConfig()
try:
import unittest.mock as mock
except ImportError:
import mock
from senpy.extensions import Senpy
from flask import Flask
from flask.ext.testing import TestCase
import unittest
class vaderTest(unittest.TestCase):
def setUp(self):
self.app = Flask("test_plugin")
self.dir = os.path.join(os.path.dirname(__file__))
self.senpy = Senpy(plugin_folder=self.dir, default_plugins=False)
self.senpy.init_app(self.app)
def tearDown(self):
self.senpy.deactivate_plugin("vaderSentiment", sync=True)
def test_analyse(self):
plugin = self.senpy.plugins["vaderSentiment"]
plugin.activate()
texts = {'I am tired :(' : 'marl:Negative',
'I love pizza' : 'marl:Positive',
'I like going to the cinema :)' : 'marl:Positive',
'This cake is disgusting' : 'marl:Negative'}
for text in texts:
response = plugin.analyse(input=text)
expected = texts[text]
sentimentSet = response.entries[0].sentiments
max_sentiment = max(sentimentSet, key=lambda x: x['marl:polarityValue'])
assert max_sentiment['marl:hasPolarity'] == expected
plugin.deactivate()
if __name__ == '__main__':
unittest.main()

View File

@@ -5,15 +5,37 @@ from senpy.plugins import SentimentPlugin, SenpyPlugin
from senpy.models import Results, Sentiment, Entry
import logging
logger = logging.getLogger(__name__)
class vaderSentimentPlugin(SentimentPlugin):
class VaderSentimentPlugin(SentimentPlugin):
'''
Sentiment classifier using vaderSentiment module. Params accepted: Language: {en, es}. The output uses Marl ontology developed at GSI UPM for semantic web.
'''
name = "sentiment-vader"
module = "sentiment-vader"
author = "@icorcuera"
version = "0.1.1"
extra_params = {
"language": {
"@id": "lang_rand",
"aliases": ["language", "l"],
"default": "auto",
"options": ["es", "en", "auto"]
},
def analyse_entry(self,entry,params):
"aggregate": {
"aliases": ["aggregate","agg"],
"options": ["true", "false"],
"default": False
}
logger.debug("Analysing with params {}".format(params))
}
requirements = {}
text_input = entry.get("text", None)
def analyse_entry(self, entry, params):
self.log.debug("Analysing with params {}".format(params))
text_input = entry.text
aggregate = params['aggregate']
score = sentiment(text_input)
@@ -22,15 +44,18 @@ class vaderSentimentPlugin(SentimentPlugin):
marl__hasPolarity= "marl:Positive",
marl__algorithmConfidence= score['pos']
)
opinion0.prov(self)
opinion1 = Sentiment(id= "Opinion_negative",
marl__hasPolarity= "marl:Negative",
marl__algorithmConfidence= score['neg']
)
opinion1.prov(self)
opinion2 = Sentiment(id= "Opinion_neutral",
marl__hasPolarity = "marl:Neutral",
marl__algorithmConfidence = score['neu']
)
opinion2.prov(self)
if aggregate == 'true':
res = None
confident = max(score['neg'],score['neu'],score['pos'])
@@ -47,3 +72,25 @@ class vaderSentimentPlugin(SentimentPlugin):
entry.sentiments.append(opinion2)
yield entry
test_cases = []
test_cases = [
{
'input': 'I am tired :(',
'polarity': 'marl:Negative'
},
{
'input': 'I love pizza :(',
'polarity': 'marl:Positive'
},
{
'input': 'I enjoy going to the cinema :)',
'polarity': 'marl:Negative'
},
{
'input': 'This cake is disgusting',
'polarity': 'marl:Negative'
},
]