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
Show 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
from
threading
import
Thread
import
os
import
copy
import
fnmatch
import
inspect
import
sys
...
...
@@ -180,7 +181,7 @@ class Senpy(object):
newentries
=
[]
for
i
in
resp
.
entries
:
if
output
==
"full"
:
newemotions
=
i
.
emotions
.
copy
(
)
newemotions
=
copy
.
copy
(
i
.
emotions
)
else
:
newemotions
=
[]
for
j
in
i
.
emotions
:
...
...
senpy/plugins/conversion/emotion/ekman2vad.py
View file @
453b9f32
...
...
@@ -10,24 +10,26 @@ import math
class
WNA2VAD
(
EmotionConversionPlugin
):
def
_ekman_to_vad
(
self
,
ekmanSet
):
potency
=
0
"""Sum the VAD value of all categories found."""
valence
=
0
arousal
=
0
dominance
=
0
for
e
in
ekmanSet
.
onyx__hasEmotion
:
category
=
e
.
onyx__hasEmotionCategory
centroid
=
self
.
centroids
[
category
]
pot
enc
y
+=
centroid
[
'V'
]
val
enc
e
+=
centroid
[
'V'
]
arousal
+=
centroid
[
'A'
]
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:
domina
nc
e
'
:
dominance
})
'emoml:
pote
nc
y
'
:
dominance
})
return
e
def
_vad_to_ekman
(
self
,
VADEmotion
):
"""Find the closest category"""
V
=
VADEmotion
[
'emoml:valence'
]
A
=
VADEmotion
[
'emoml:
potency
'
]
D
=
VADEmotion
[
'emoml:
domina
nc
e
'
]
A
=
VADEmotion
[
'emoml:
arousal
'
]
D
=
VADEmotion
[
'emoml:
pote
nc
y
'
]
emotion
=
''
value
=
10000000000000000000000.0
for
state
in
self
.
centroids
:
...
...
@@ -50,7 +52,7 @@ class WNA2VAD(EmotionConversionPlugin):
e
.
onyx__hasEmotion
.
append
(
self
.
_ekman_to_vad
(
emotionSet
))
elif
fromModel
==
'emoml:fsre-dimensions'
:
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
:
raise
Error
(
'EMOTION MODEL NOT KNOWN'
)
yield
e
senpy/plugins/conversion/emotion/ekman2vad.senpy
View file @
453b9f32
...
...
@@ -7,7 +7,7 @@ onyx:doesConversion:
- onyx:conversionFrom: emoml:big6
onyx:conversionTo: emoml:fsre-dimensions
- onyx:conversionFrom: emoml:fsre-dimensions
onyx:conversionTo:
wna:WNAModel
onyx:conversionTo:
emoml:big6
centroids:
emoml:big6anger:
A: 6.95
...
...
@@ -31,5 +31,5 @@ centroids:
V: 2.21
aliases:
A: emoml:arousal
V: emoml:
pot
enc
y
V: emoml:
val
enc
e
D: emoml:dominance
\ No newline at end of file
setup.cfg
View file @
453b9f32
...
...
@@ -10,3 +10,5 @@ ignore = E402
max-line-length = 100
[bdist_wheel]
universal=1
[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
import
os
from
copy
import
deepcopy
import
logging
try
:
...
...
@@ -9,7 +10,7 @@ except ImportError:
from
functools
import
partial
from
senpy.extensions
import
Senpy
from
senpy.models
import
Error
from
senpy.models
import
Error
,
Results
,
Entry
,
EmotionSet
,
Emotion
from
flask
import
Flask
from
unittest
import
TestCase
...
...
@@ -52,6 +53,7 @@ class ExtensionsTest(TestCase):
assert
module
import
noop
dir
(
noop
)
self
.
senpy
.
install_deps
()
def
test_installing
(
self
):
""" Enabling a plugin """
...
...
@@ -120,3 +122,42 @@ class ExtensionsTest(TestCase):
def
test_load_default_plugins
(
self
):
senpy
=
Senpy
(
plugin_folder
=
self
.
dir
,
default_plugins
=
True
)
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):
print
(
t
)
g
=
rdflib
.
Graph
().
parse
(
data
=
t
,
format
=
'turtle'
)
assert
len
(
g
)
==
len
(
triples
)
def
test_convert_emotions
(
self
):
"""It should be possible to convert between different emotion models"""
pass
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