1
0
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:
J. Fernando Sánchez 2014-12-01 09:38:23 +01:00
parent 4351f76b60
commit 10f4782ad7
6 changed files with 20 additions and 16 deletions

View File

@ -35,8 +35,12 @@ class Sentiment140Plugin(SentimentPlugin):
polarity = "marl:Positive" polarity = "marl:Positive"
elif polarity_value < 50: elif polarity_value < 50:
polarity = "marl:Negative" polarity = "marl:Negative"
entry = Entry(text=params["input"]) entry = Entry(text=params["input"],
opinion = Opinion(hasPolarity=polarity, polarityValue=polarity_value) 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.opinions.append(opinion)
entry.language = lang entry.language = lang
response.entries.append(entry) response.entries.append(entry)

View File

@ -48,7 +48,7 @@ def get_params(req, params=BASIC_PARAMS):
if alias in indict: if alias in indict:
outdict[param] = indict[alias] outdict[param] = indict[alias]
if param not in outdict: 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] wrong_params[param] = params[param]
else: else:
if "default" in options: if "default" in options:

View File

@ -34,6 +34,7 @@
"@id": "dc:date", "@id": "dc:date",
"@type": "xsd:dateTime" "@type": "xsd:dateTime"
}, },
"text": { "@id": "nif:isString" },
"wnaffect": "http://www.gsi.dit.upm.es/ontologies/wnaffect#", "wnaffect": "http://www.gsi.dit.upm.es/ontologies/wnaffect#",
"xsd": "http://www.w3.org/2001/XMLSchema#" "xsd": "http://www.w3.org/2001/XMLSchema#"
} }

View File

@ -9,11 +9,6 @@ logger = logging.getLogger(__name__)
from .plugins import SentimentPlugin, EmotionPlugin 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 .blueprints import nif_blueprint
from git import Repo, InvalidGitRepositoryError from git import Repo, InvalidGitRepositoryError
@ -145,11 +140,9 @@ class Senpy(object):
@property @property
def plugins(self): def plugins(self):
""" Return the plugins registered for a given application. """ """ Return the plugins registered for a given application. """
ctx = stack.top if not hasattr(self, 'senpy_plugins') or self._outdated:
if ctx is not None: self.senpy_plugins = self._load_plugins()
if not hasattr(ctx, 'senpy_plugins') or self._outdated: return self.senpy_plugins
ctx.senpy_plugins = self._load_plugins()
return ctx.senpy_plugins
def filter_plugins(self, **kwargs): def filter_plugins(self, **kwargs):
""" Filter plugins by different criteria """ """ Filter plugins by different criteria """

View File

@ -80,7 +80,6 @@ class Opinion(Leaf):
opinionContext = {} opinionContext = {}
def __init__(self, polarityValue=None, hasPolarity=None, *args, **kwargs): def __init__(self, polarityValue=None, hasPolarity=None, *args, **kwargs):
super(Opinion, self).__init__(context=self.opinionContext, super(Opinion, self).__init__(context=self.opinionContext,
prefix="marl",
*args, *args,
**kwargs) **kwargs)
if polarityValue is not None: if polarityValue is not None:
@ -95,7 +94,6 @@ class EmotionSet(Leaf):
if not emotions: if not emotions:
emotions = [] emotions = []
super(EmotionSet, self).__init__(context=self.emotionContext, super(EmotionSet, self).__init__(context=self.emotionContext,
prefix="onyx",
*args, *args,
**kwargs) **kwargs)
self.emotions = emotions or [] self.emotions = emotions or []

View File

@ -25,6 +25,10 @@ PARAMS = {"input": {"aliases": ["i", "input"],
"required": False, "required": False,
"options": ["es", "en"], "options": ["es", "en"],
}, },
"prefix": {"aliases": ["prefix", "p"],
"required": True,
"default": "",
},
"urischeme": {"aliases": ["urischeme", "u"], "urischeme": {"aliases": ["urischeme", "u"],
"required": False, "required": False,
"default": "RFC5147String", "default": "RFC5147String",
@ -56,9 +60,13 @@ class SenpyPlugin(object):
def disable(self): def disable(self):
self.enabled = False self.enabled = False
@property
def id(self):
return "{}_{}".format(self.name, self.version)
def jsonable(self, parameters=False): def jsonable(self, parameters=False):
resp = { resp = {
"@id": "{}_{}".format(self.name, self.version), "@id": self.id,
"enabled": self.enabled, "enabled": self.enabled,
} }
if hasattr(self, "repo") and self.repo: if hasattr(self, "repo") and self.repo: