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
453b9f32
Commit
453b9f32
authored
Feb 28, 2017
by
J. Fernando Sánchez
Browse files
Fixed bugs in Ekman2VAD
parent
5fb858f5
Changes
6
Hide whitespace changes
Inline
Side-by-side
senpy/extensions.py
View file @
453b9f32
...
@@ -13,6 +13,7 @@ from .api import API_PARAMS, NIF_PARAMS, parse_params
...
@@ -13,6 +13,7 @@ from .api import API_PARAMS, NIF_PARAMS, parse_params
from
threading
import
Thread
from
threading
import
Thread
import
os
import
os
import
copy
import
fnmatch
import
fnmatch
import
inspect
import
inspect
import
sys
import
sys
...
@@ -180,7 +181,7 @@ class Senpy(object):
...
@@ -180,7 +181,7 @@ class Senpy(object):
newentries
=
[]
newentries
=
[]
for
i
in
resp
.
entries
:
for
i
in
resp
.
entries
:
if
output
==
"full"
:
if
output
==
"full"
:
newemotions
=
i
.
emotions
.
copy
(
)
newemotions
=
copy
.
copy
(
i
.
emotions
)
else
:
else
:
newemotions
=
[]
newemotions
=
[]
for
j
in
i
.
emotions
:
for
j
in
i
.
emotions
:
...
...
senpy/plugins/conversion/emotion/ekman2vad.py
View file @
453b9f32
...
@@ -10,24 +10,26 @@ import math
...
@@ -10,24 +10,26 @@ import math
class
WNA2VAD
(
EmotionConversionPlugin
):
class
WNA2VAD
(
EmotionConversionPlugin
):
def
_ekman_to_vad
(
self
,
ekmanSet
):
def
_ekman_to_vad
(
self
,
ekmanSet
):
potency
=
0
"""Sum the VAD value of all categories found."""
valence
=
0
arousal
=
0
arousal
=
0
dominance
=
0
dominance
=
0
for
e
in
ekmanSet
.
onyx__hasEmotion
:
for
e
in
ekmanSet
.
onyx__hasEmotion
:
category
=
e
.
onyx__hasEmotionCategory
category
=
e
.
onyx__hasEmotionCategory
centroid
=
self
.
centroids
[
category
]
centroid
=
self
.
centroids
[
category
]
pot
enc
y
+=
centroid
[
'V'
]
val
enc
e
+=
centroid
[
'V'
]
arousal
+=
centroid
[
'A'
]
arousal
+=
centroid
[
'A'
]
dominance
+=
centroid
[
'D'
]
dominance
+=
centroid
[
'D'
]
e
=
Emotion
({
'emoml:
pot
enc
y
'
:
pot
enc
y
,
e
=
Emotion
({
'emoml:
val
enc
e
'
:
val
enc
e
,
'emoml:arousal'
:
arousal
,
'emoml:arousal'
:
arousal
,
'emoml:
domina
nc
e
'
:
dominance
})
'emoml:
pote
nc
y
'
:
dominance
})
return
e
return
e
def
_vad_to_ekman
(
self
,
VADEmotion
):
def
_vad_to_ekman
(
self
,
VADEmotion
):
"""Find the closest category"""
V
=
VADEmotion
[
'emoml:valence'
]
V
=
VADEmotion
[
'emoml:valence'
]
A
=
VADEmotion
[
'emoml:
potency
'
]
A
=
VADEmotion
[
'emoml:
arousal
'
]
D
=
VADEmotion
[
'emoml:
domina
nc
e
'
]
D
=
VADEmotion
[
'emoml:
pote
nc
y
'
]
emotion
=
''
emotion
=
''
value
=
10000000000000000000000.0
value
=
10000000000000000000000.0
for
state
in
self
.
centroids
:
for
state
in
self
.
centroids
:
...
@@ -50,7 +52,7 @@ class WNA2VAD(EmotionConversionPlugin):
...
@@ -50,7 +52,7 @@ class WNA2VAD(EmotionConversionPlugin):
e
.
onyx__hasEmotion
.
append
(
self
.
_ekman_to_vad
(
emotionSet
))
e
.
onyx__hasEmotion
.
append
(
self
.
_ekman_to_vad
(
emotionSet
))
elif
fromModel
==
'emoml:fsre-dimensions'
:
elif
fromModel
==
'emoml:fsre-dimensions'
:
for
i
in
emotionSet
.
onyx__hasEmotion
:
for
i
in
emotionSet
.
onyx__hasEmotion
:
e
.
onyx__hasEmotion
.
append
(
self
.
_vad_to_ekman
(
e
))
e
.
onyx__hasEmotion
.
append
(
self
.
_vad_to_ekman
(
i
))
else
:
else
:
raise
Error
(
'EMOTION MODEL NOT KNOWN'
)
raise
Error
(
'EMOTION MODEL NOT KNOWN'
)
yield
e
yield
e
senpy/plugins/conversion/emotion/ekman2vad.senpy
View file @
453b9f32
...
@@ -7,7 +7,7 @@ onyx:doesConversion:
...
@@ -7,7 +7,7 @@ onyx:doesConversion:
- onyx:conversionFrom: emoml:big6
- onyx:conversionFrom: emoml:big6
onyx:conversionTo: emoml:fsre-dimensions
onyx:conversionTo: emoml:fsre-dimensions
- onyx:conversionFrom: emoml:fsre-dimensions
- onyx:conversionFrom: emoml:fsre-dimensions
onyx:conversionTo:
wna:WNAModel
onyx:conversionTo:
emoml:big6
centroids:
centroids:
emoml:big6anger:
emoml:big6anger:
A: 6.95
A: 6.95
...
@@ -31,5 +31,5 @@ centroids:
...
@@ -31,5 +31,5 @@ centroids:
V: 2.21
V: 2.21
aliases:
aliases:
A: emoml:arousal
A: emoml:arousal
V: emoml:
pot
enc
y
V: emoml:
val
enc
e
D: emoml:dominance
D: emoml:dominance
\ No newline at end of file
setup.cfg
View file @
453b9f32
...
@@ -9,4 +9,6 @@ test=pytest
...
@@ -9,4 +9,6 @@ test=pytest
ignore = E402
ignore = E402
max-line-length = 100
max-line-length = 100
[bdist_wheel]
[bdist_wheel]
universal=1
universal=1
\ No newline at end of file
[tool:pytest]
addopts = --cov=senpy --cov-report term-missing
\ No newline at end of file
tests/test_extensions.py
View file @
453b9f32
from
__future__
import
print_function
from
__future__
import
print_function
import
os
import
os
from
copy
import
deepcopy
import
logging
import
logging
try
:
try
:
...
@@ -9,7 +10,7 @@ except ImportError:
...
@@ -9,7 +10,7 @@ except ImportError:
from
functools
import
partial
from
functools
import
partial
from
senpy.extensions
import
Senpy
from
senpy.extensions
import
Senpy
from
senpy.models
import
Error
from
senpy.models
import
Error
,
Results
,
Entry
,
EmotionSet
,
Emotion
from
flask
import
Flask
from
flask
import
Flask
from
unittest
import
TestCase
from
unittest
import
TestCase
...
@@ -52,6 +53,7 @@ class ExtensionsTest(TestCase):
...
@@ -52,6 +53,7 @@ class ExtensionsTest(TestCase):
assert
module
assert
module
import
noop
import
noop
dir
(
noop
)
dir
(
noop
)
self
.
senpy
.
install_deps
()
def
test_installing
(
self
):
def
test_installing
(
self
):
""" Enabling a plugin """
""" Enabling a plugin """
...
@@ -120,3 +122,42 @@ class ExtensionsTest(TestCase):
...
@@ -120,3 +122,42 @@ class ExtensionsTest(TestCase):
def
test_load_default_plugins
(
self
):
def
test_load_default_plugins
(
self
):
senpy
=
Senpy
(
plugin_folder
=
self
.
dir
,
default_plugins
=
True
)
senpy
=
Senpy
(
plugin_folder
=
self
.
dir
,
default_plugins
=
True
)
assert
len
(
senpy
.
plugins
)
>
1
assert
len
(
senpy
.
plugins
)
>
1
def
test_convert_emotions
(
self
):
self
.
senpy
.
activate_all
()
plugin
=
{
'id'
:
'imaginary'
,
'onyx:usesEmotionModel'
:
'emoml:fsre-dimensions'
}
eSet1
=
EmotionSet
()
eSet1
[
'onyx:hasEmotion'
].
append
(
Emotion
({
'emoml:arousal'
:
1
,
'emoml:potency'
:
0
,
'emoml:valence'
:
0
}))
response
=
Results
({
'entries'
:
[
Entry
({
'text'
:
'much ado about nothing'
,
'emotions'
:
[
eSet1
]
})]
})
params
=
{
'emotionModel'
:
'emoml:big6'
,
'conversion'
:
'full'
}
r1
=
deepcopy
(
response
)
self
.
senpy
.
convert_emotions
(
r1
,
plugin
,
params
)
assert
len
(
r1
.
entries
[
0
].
emotions
)
==
2
params
[
'conversion'
]
=
'nested'
r2
=
deepcopy
(
response
)
self
.
senpy
.
convert_emotions
(
r2
,
plugin
,
params
)
assert
len
(
r2
.
entries
[
0
].
emotions
)
==
1
assert
r2
.
entries
[
0
].
emotions
[
0
][
'prov:wasDerivedFrom'
]
==
eSet1
params
[
'conversion'
]
=
'filtered'
r3
=
deepcopy
(
response
)
self
.
senpy
.
convert_emotions
(
r3
,
plugin
,
params
)
assert
len
(
r3
.
entries
[
0
].
emotions
)
==
1
tests/test_models.py
View file @
453b9f32
...
@@ -143,7 +143,3 @@ class ModelsTest(TestCase):
...
@@ -143,7 +143,3 @@ class ModelsTest(TestCase):
print
(
t
)
print
(
t
)
g
=
rdflib
.
Graph
().
parse
(
data
=
t
,
format
=
'turtle'
)
g
=
rdflib
.
Graph
().
parse
(
data
=
t
,
format
=
'turtle'
)
assert
len
(
g
)
==
len
(
triples
)
assert
len
(
g
)
==
len
(
triples
)
def
test_convert_emotions
(
self
):
"""It should be possible to convert between different emotion models"""
pass
Write
Preview
Markdown
is supported
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