mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-22 00:02:28 +00:00
Better NIF compliance
This commit is contained in:
parent
4351f76b60
commit
10f4782ad7
@ -35,8 +35,12 @@ class Sentiment140Plugin(SentimentPlugin):
|
||||
polarity = "marl:Positive"
|
||||
elif polarity_value < 50:
|
||||
polarity = "marl:Negative"
|
||||
entry = Entry(text=params["input"])
|
||||
opinion = Opinion(hasPolarity=polarity, polarityValue=polarity_value)
|
||||
entry = Entry(text=params["input"],
|
||||
prefix=params.get("prefix", ""))
|
||||
opinion = Opinion(hasPolarity=polarity,
|
||||
polarityValue=polarity_value,
|
||||
prefix=params.get("prefix", ""))
|
||||
opinion["prov:wasGeneratedBy"] = self.id
|
||||
entry.opinions.append(opinion)
|
||||
entry.language = lang
|
||||
response.entries.append(entry)
|
||||
|
@ -48,7 +48,7 @@ def get_params(req, params=BASIC_PARAMS):
|
||||
if alias in indict:
|
||||
outdict[param] = indict[alias]
|
||||
if param not in outdict:
|
||||
if options.get("required", False):
|
||||
if options.get("required", False) and "default" not in options:
|
||||
wrong_params[param] = params[param]
|
||||
else:
|
||||
if "default" in options:
|
||||
|
@ -34,6 +34,7 @@
|
||||
"@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#"
|
||||
}
|
||||
|
@ -9,11 +9,6 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
from .plugins import SentimentPlugin, EmotionPlugin
|
||||
|
||||
try:
|
||||
from flask import _app_ctx_stack as stack
|
||||
except ImportError:
|
||||
from flask import _request_ctx_stack as stack
|
||||
|
||||
from .blueprints import nif_blueprint
|
||||
from git import Repo, InvalidGitRepositoryError
|
||||
|
||||
@ -145,11 +140,9 @@ class Senpy(object):
|
||||
@property
|
||||
def plugins(self):
|
||||
""" Return the plugins registered for a given application. """
|
||||
ctx = stack.top
|
||||
if ctx is not None:
|
||||
if not hasattr(ctx, 'senpy_plugins') or self._outdated:
|
||||
ctx.senpy_plugins = self._load_plugins()
|
||||
return ctx.senpy_plugins
|
||||
if not hasattr(self, 'senpy_plugins') or self._outdated:
|
||||
self.senpy_plugins = self._load_plugins()
|
||||
return self.senpy_plugins
|
||||
|
||||
def filter_plugins(self, **kwargs):
|
||||
""" Filter plugins by different criteria """
|
||||
|
@ -80,7 +80,6 @@ class Opinion(Leaf):
|
||||
opinionContext = {}
|
||||
def __init__(self, polarityValue=None, hasPolarity=None, *args, **kwargs):
|
||||
super(Opinion, self).__init__(context=self.opinionContext,
|
||||
prefix="marl",
|
||||
*args,
|
||||
**kwargs)
|
||||
if polarityValue is not None:
|
||||
@ -95,7 +94,6 @@ class EmotionSet(Leaf):
|
||||
if not emotions:
|
||||
emotions = []
|
||||
super(EmotionSet, self).__init__(context=self.emotionContext,
|
||||
prefix="onyx",
|
||||
*args,
|
||||
**kwargs)
|
||||
self.emotions = emotions or []
|
||||
|
@ -25,6 +25,10 @@ PARAMS = {"input": {"aliases": ["i", "input"],
|
||||
"required": False,
|
||||
"options": ["es", "en"],
|
||||
},
|
||||
"prefix": {"aliases": ["prefix", "p"],
|
||||
"required": True,
|
||||
"default": "",
|
||||
},
|
||||
"urischeme": {"aliases": ["urischeme", "u"],
|
||||
"required": False,
|
||||
"default": "RFC5147String",
|
||||
@ -56,9 +60,13 @@ class SenpyPlugin(object):
|
||||
def disable(self):
|
||||
self.enabled = False
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return "{}_{}".format(self.name, self.version)
|
||||
|
||||
def jsonable(self, parameters=False):
|
||||
resp = {
|
||||
"@id": "{}_{}".format(self.name, self.version),
|
||||
"@id": self.id,
|
||||
"enabled": self.enabled,
|
||||
}
|
||||
if hasattr(self, "repo") and self.repo:
|
||||
|
Loading…
Reference in New Issue
Block a user