diff --git a/plugins/sentiment140/__init__.py b/plugins/sentiment140/__init__.py index 123bc73..caf38f1 100644 --- a/plugins/sentiment140/__init__.py +++ b/plugins/sentiment140/__init__.py @@ -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) diff --git a/senpy/blueprints.py b/senpy/blueprints.py index cafc91d..0b781cb 100644 --- a/senpy/blueprints.py +++ b/senpy/blueprints.py @@ -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: diff --git a/senpy/context.jsonld b/senpy/context.jsonld index 36a3cd8..936db98 100644 --- a/senpy/context.jsonld +++ b/senpy/context.jsonld @@ -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#" } diff --git a/senpy/extensions.py b/senpy/extensions.py index 5ee9ac0..14f3fb3 100644 --- a/senpy/extensions.py +++ b/senpy/extensions.py @@ -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 """ diff --git a/senpy/models.py b/senpy/models.py index 0d18290..dce3cbd 100644 --- a/senpy/models.py +++ b/senpy/models.py @@ -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 [] diff --git a/senpy/plugins.py b/senpy/plugins.py index 31e80e2..6c3b73d 100644 --- a/senpy/plugins.py +++ b/senpy/plugins.py @@ -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: