Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
senpy
senpy
Commits
10f4782a
Commit
10f4782a
authored
Dec 01, 2014
by
J. Fernando Sánchez
Browse files
Better NIF compliance
parent
4351f76b
Changes
6
Hide whitespace changes
Inline
Side-by-side
plugins/sentiment140/__init__.py
View file @
10f4782a
...
...
@@ -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
)
...
...
senpy/blueprints.py
View file @
10f4782a
...
...
@@ -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
:
...
...
senpy/context.jsonld
View file @
10f4782a
...
...
@@ -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#"
}
senpy/extensions.py
View file @
10f4782a
...
...
@@ -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 """
...
...
senpy/models.py
View file @
10f4782a
...
...
@@ -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
[]
senpy/plugins.py
View file @
10f4782a
...
...
@@ -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
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment