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
86f45f81
Commit
86f45f81
authored
Nov 27, 2014
by
J. Fernando Sánchez
Browse files
JSON-LD contexts and prefixes
parent
28349670
Changes
2
Hide whitespace changes
Inline
Side-by-side
app.py
View file @
86f45f81
...
...
@@ -23,12 +23,13 @@ import config
from
flask
import
Flask
from
senpy.extensions
import
Senpy
import
logging
import
os
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
app
=
Flask
(
__name__
)
sp
=
Senpy
()
sp
.
init_app
(
app
)
mypath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
sp
=
Senpy
(
app
,
os
.
path
.
join
(
mypath
,
"plugins"
))
if
__name__
==
'__main__'
:
app
.
debug
=
config
.
DEBUG
...
...
senpy/models.py
View file @
86f45f81
...
...
@@ -4,22 +4,39 @@ from collections import defaultdict
class
Leaf
(
defaultdict
):
def
__init__
(
self
,
context
=
None
,
ofclass
=
list
):
_prefix
=
None
def
__init__
(
self
,
context
=
None
,
prefix
=
None
,
ofclass
=
list
):
super
(
Leaf
,
self
).
__init__
(
ofclass
)
if
context
:
self
.
context
=
context
self
.
_prefix
=
prefix
def
__getattr__
(
self
,
key
):
return
super
(
Leaf
,
self
).
__getitem__
(
self
.
_get_key
(
key
))
def
__getattr__
(
self
,
name
):
if
name
is
not
"context"
:
return
super
(
Leaf
,
self
).
__getitem__
(
name
)
return
self
[
"@context"
]
def
__setattr__
(
self
,
key
,
value
):
try
:
object
.
__getattr__
(
self
,
key
)
object
.
__setattr__
(
self
,
key
,
value
)
except
AttributeError
:
key
=
self
.
_get_key
(
key
)
value
=
self
.
get_context
(
value
)
if
key
==
"@context"
else
value
if
key
[
0
]
==
"_"
:
object
.
__setattr__
(
self
,
key
,
value
)
else
:
super
(
Leaf
,
self
).
__setitem__
(
key
,
value
)
def
__setattr__
(
self
,
name
,
value
):
name
=
"@context"
if
name
is
"context"
else
name
self
[
name
]
=
self
.
get_context
(
value
)
def
__delattr__
(
self
,
key
):
return
super
(
Leaf
,
self
).
__delitem__
(
self
.
_get_key
(
key
))
def
__delattr__
(
self
,
name
):
return
super
(
Leaf
,
self
).
__delitem__
(
name
)
def
_get_key
(
self
,
key
):
if
key
is
"context"
:
return
"@context"
elif
self
.
_prefix
:
return
"{}:{}"
.
format
(
self
.
_prefix
,
key
)
else
:
return
key
@
staticmethod
def
get_context
(
context
):
...
...
@@ -65,6 +82,7 @@ class Opinion(Leaf):
}
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
:
...
...
@@ -74,13 +92,12 @@ class Opinion(Leaf):
class
EmotionSet
(
Leaf
):
emotionContext
=
{
"@vocab"
:
"http://www.gsi.dit.upm.es/ontologies/onyx/ns#"
}
emotionContext
=
{}
def
__init__
(
self
,
emotions
=
None
,
*
args
,
**
kwargs
):
if
not
emotions
:
emotions
=
[]
super
(
EmotionSet
,
self
).
__init__
(
context
=
self
.
emotionContext
,
prefix
=
"onyx"
,
*
args
,
**
kwargs
)
self
.
emotions
=
emotions
or
[]
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