mirror of https://github.com/gsi-upm/senpy
parent
37a098109f
commit
79c83e34a3
@ -0,0 +1,32 @@
|
||||
import json
|
||||
import random
|
||||
|
||||
from senpy.plugins import SentimentPlugin
|
||||
from senpy.models import Response, Opinion, Entry
|
||||
|
||||
|
||||
class Sentiment140Plugin(SentimentPlugin):
|
||||
def analyse(self, **params):
|
||||
lang = params.get("language", "auto")
|
||||
|
||||
p = params.get("prefix", None)
|
||||
response = Response(prefix=p)
|
||||
#polarity_value = self.maxPolarityValue*int(res.json()["data"][0]["polarity"]) * 0.25
|
||||
polarity_value = max(-1, min(1, random.gauss(0.2,0.2)))
|
||||
polarity = "marl:Neutral"
|
||||
if polarity_value > 0:
|
||||
polarity = "marl:Positive"
|
||||
elif polarity_value < 0:
|
||||
polarity = "marl:Negative"
|
||||
entry = Entry(id="Entry0",
|
||||
text=params["input"],
|
||||
prefix=p)
|
||||
opinion = Opinion(id="Opinion0",
|
||||
prefix=p,
|
||||
hasPolarity=polarity,
|
||||
polarityValue=polarity_value)
|
||||
opinion["prov:wasGeneratedBy"] = self.id
|
||||
entry.opinions.append(opinion)
|
||||
entry.language = lang
|
||||
response.entries.append(entry)
|
||||
return response
|
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "rand",
|
||||
"module": "rand",
|
||||
"description": "What my plugin broadly does",
|
||||
"author": "@balkian",
|
||||
"version": "0.1",
|
||||
"extra_params": {
|
||||
"language": {
|
||||
"aliases": ["language", "l"],
|
||||
"required": false,
|
||||
"options": ["es", "en", "auto"]
|
||||
}
|
||||
},
|
||||
"requirements": {},
|
||||
"marl:maxPolarityValue": "1",
|
||||
"marl:minPolarityValue": "-1"
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
{
|
||||
"dc": "http://purl.org/dc/terms/",
|
||||
"dc:subject": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
||||
"marl": "http://www.gsi.dit.upm.es/ontologies/marl/ns#",
|
||||
"nif": "http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#",
|
||||
"onyx": "http://www.gsi.dit.upm.es/ontologies/onyx/ns#",
|
||||
"emotions": {
|
||||
"@container": "@set",
|
||||
"@id": "onyx:hasEmotionSet"
|
||||
},
|
||||
"opinions": {
|
||||
"@container": "@set",
|
||||
"@id": "marl:hasOpinion"
|
||||
},
|
||||
"prov": "http://www.w3.org/ns/prov#",
|
||||
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
|
||||
"analysis": {
|
||||
"@container": "@set",
|
||||
"@id": "prov:wasInformedBy"
|
||||
},
|
||||
"entries": {
|
||||
"@container": "@set",
|
||||
"@id": "prov:generated"
|
||||
},
|
||||
"strings": {
|
||||
"@container": "@set",
|
||||
"@reverse": "nif:hasContext"
|
||||
},
|
||||
"date":
|
||||
{
|
||||
"@id": "dc:date",
|
||||
"@type": "xsd:dateTime"
|
||||
},
|
||||
"text": { "@id": "nif:isString" },
|
||||
"wnaffect": "http://www.gsi.dit.upm.es/ontologies/wnaffect#",
|
||||
"xsd": "http://www.w3.org/2001/XMLSchema#"
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
try:
|
||||
import unittest.mock as mock
|
||||
except ImportError:
|
||||
import mock
|
||||
import json
|
||||
import os
|
||||
from unittest import TestCase
|
||||
from senpy.models import Response
|
||||
from senpy.plugins import SenpyPlugin
|
||||
|
||||
class ModelsTest(TestCase):
|
||||
def test_response(self):
|
||||
r = Response(context=os.path.normpath(os.path.join(__file__, "..", "..", "context.jsonld")))
|
||||
assert("@context" in r)
|
||||
assert("marl" in r.context)
|
||||
r2 = Response(context=json.loads('{"test": "roger"}'))
|
||||
assert("test" in r2.context)
|
||||
r3 = Response(context=None)
|
||||
del r3.context
|
||||
assert("@context" not in r3)
|
||||
assert("entries" in r3)
|
||||
assert("analysis" in r3)
|
||||
|
||||
def test_opinions(self):
|
||||
pass
|
||||
|
||||
def test_frame_plugin(self):
|
||||
p = SenpyPlugin({"name": "dummy", "version": 0})
|
||||
c = p.frame()
|
||||
assert "info" not in c
|
||||
|
||||
def test_frame_response(self):
|
||||
pass
|
Loading…
Reference in New Issue