Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
senpy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
6
Issues
6
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
senpy
senpy
Commits
8e4578dc
Commit
8e4578dc
authored
Jun 16, 2017
by
J. Fernando Sánchez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes
#40
parent
312e7f7f
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
136 additions
and
5 deletions
+136
-5
senpy/models.py
senpy/models.py
+6
-3
senpy/plugins/__init__.py
senpy/plugins/__init__.py
+33
-0
senpy/plugins/conversion/emotion/centroids.py
senpy/plugins/conversion/emotion/centroids.py
+51
-0
senpy/plugins/example/emoRand/emoRand.py
senpy/plugins/example/emoRand/emoRand.py
+9
-1
senpy/plugins/example/rand/rand.py
senpy/plugins/example/rand/rand.py
+11
-1
senpy/plugins/sentiment/sentiment140/sentiment140.py
senpy/plugins/sentiment/sentiment140/sentiment140.py
+17
-0
tests/plugins/async_plugin/asyncplugin.py
tests/plugins/async_plugin/asyncplugin.py
+3
-0
tests/plugins/dummy_plugin/dummy.py
tests/plugins/dummy_plugin/dummy.py
+3
-0
tests/plugins/sleep_plugin/sleep.py
tests/plugins/sleep_plugin/sleep.py
+3
-0
No files found.
senpy/models.py
View file @
8e4578dc
...
...
@@ -218,11 +218,16 @@ class BaseModel(SenpyMixin, dict):
super
(
BaseModel
,
self
).
__init__
(
temp
)
def
_get_key
(
self
,
key
):
if
key
is
'id'
:
key
=
'@id'
key
=
key
.
replace
(
"__"
,
":"
,
1
)
return
key
def
__getitem__
(
self
,
key
):
return
dict
.
__getitem__
(
self
,
self
.
_get_key
(
key
))
def
__setitem__
(
self
,
key
,
value
):
dict
.
__setitem__
(
self
,
key
,
value
)
dict
.
__setitem__
(
self
,
self
.
_get_key
(
key
)
,
value
)
def
__delitem__
(
self
,
key
):
dict
.
__delitem__
(
self
,
key
)
...
...
@@ -244,8 +249,6 @@ class BaseModel(SenpyMixin, dict):
def
_plain_dict
(
self
):
d
=
{
k
:
v
for
(
k
,
v
)
in
self
.
items
()
if
k
[
0
]
!=
"_"
}
if
'id'
in
d
:
d
[
"@id"
]
=
d
.
pop
(
'id'
)
return
d
...
...
senpy/plugins/__init__.py
View file @
8e4578dc
...
...
@@ -14,6 +14,30 @@ from ..api import API_PARAMS
logger
=
logging
.
getLogger
(
__name__
)
def
check_template
(
indict
,
template
):
if
isinstance
(
template
,
dict
)
and
isinstance
(
indict
,
dict
):
for
k
,
v
in
template
.
items
():
if
k
not
in
indict
:
return
'{} not in {}'
.
format
(
k
,
indict
)
check_template
(
indict
[
k
],
v
)
elif
isinstance
(
template
,
list
)
and
isinstance
(
indict
,
list
):
if
len
(
indict
)
!=
len
(
template
):
raise
models
.
Error
(
'Different size for {} and {}'
.
format
(
indict
,
template
))
for
e
in
template
:
found
=
False
for
i
in
indict
:
try
:
check_template
(
i
,
e
)
found
=
True
except
models
.
Error
as
ex
:
continue
if
not
found
:
raise
models
.
Error
(
'{} not found in {}'
.
format
(
e
,
indict
))
else
:
if
indict
!=
template
:
raise
models
.
Error
(
'{} and {} are different'
.
format
(
indict
,
template
))
class
Plugin
(
models
.
Plugin
):
def
__init__
(
self
,
info
=
None
):
"""
...
...
@@ -37,6 +61,15 @@ class Plugin(models.Plugin):
def
deactivate
(
self
):
pass
def
test
(
self
):
for
case
in
self
.
test_cases
:
res
=
list
(
self
.
analyse_entry
(
models
.
Entry
(
case
[
'entry'
]),
case
[
'params'
]))
exp
=
case
[
'expected'
]
if
not
isinstance
(
exp
,
list
):
exp
=
[
exp
]
check_template
(
res
,
exp
)
SenpyPlugin
=
Plugin
...
...
senpy/plugins/conversion/emotion/centroids.py
View file @
8e4578dc
...
...
@@ -100,3 +100,54 @@ class CentroidConversion(EmotionConversionPlugin):
else
:
raise
Error
(
'EMOTION MODEL NOT KNOWN'
)
yield
e
def
test
(
self
,
info
=
None
):
if
not
info
:
info
=
{
"name"
:
"CentroidTest"
,
"description"
:
"Centroid test"
,
"version"
:
0
,
"centroids"
:
{
"c1"
:
{
"V1"
:
0.5
,
"V2"
:
0.5
},
"c2"
:
{
"V1"
:
-
0.5
,
"V2"
:
0.5
},
"c3"
:
{
"V1"
:
-
0.5
,
"V2"
:
-
0.5
},
"c4"
:
{
"V1"
:
0.5
,
"V2"
:
-
0.5
}},
"aliases"
:
{
"V1"
:
"X-dimension"
,
"V2"
:
"Y-dimension"
},
"centroids_direction"
:
[
"emoml:big6"
,
"emoml:fsre-dimensions"
]
}
c
=
CentroidConversion
(
info
)
es1
=
EmotionSet
()
e1
=
Emotion
()
e1
.
onyx__hasEmotionCategory
=
"c1"
es1
.
onyx__hasEmotion
.
append
(
e1
)
res
=
c
.
_forward_conversion
(
es1
)
assert
res
[
"X-dimension"
]
==
0.5
assert
res
[
"Y-dimension"
]
==
0.5
e2
=
Emotion
()
e2
.
onyx__hasEmotionCategory
=
"c2"
es1
.
onyx__hasEmotion
.
append
(
e2
)
res
=
c
.
_forward_conversion
(
es1
)
assert
res
[
"X-dimension"
]
==
0
assert
res
[
"Y-dimension"
]
==
1
e
=
Emotion
()
e
[
"X-dimension"
]
=
-
0.2
e
[
"Y-dimension"
]
=
-
0.3
res
=
c
.
_backwards_conversion
(
e
)
assert
res
[
"onyx:hasEmotionCategory"
]
==
"c3"
e
=
Emotion
()
e
[
"X-dimension"
]
=
-
0.2
e
[
"Y-dimension"
]
=
0.3
res
=
c
.
_backwards_conversion
(
e
)
assert
res
[
"onyx:hasEmotionCategory"
]
==
"c2"
senpy/plugins/example/emoRand/emoRand.py
View file @
8e4578dc
import
random
from
senpy.plugins
import
EmotionPlugin
from
senpy.models
import
EmotionSet
,
Emotion
from
senpy.models
import
EmotionSet
,
Emotion
,
Entry
class
RmoRandPlugin
(
EmotionPlugin
):
...
...
@@ -16,3 +16,11 @@ class RmoRandPlugin(EmotionPlugin):
emotionSet
.
prov__wasGeneratedBy
=
self
.
id
entry
.
emotions
.
append
(
emotionSet
)
yield
entry
def
test
(
self
):
params
=
dict
()
results
=
list
()
for
i
in
range
(
100
):
res
=
next
(
self
.
analyse_entry
(
Entry
(
text
=
"Hello"
),
params
))
res
.
validate
()
results
.
append
(
res
.
emotions
[
0
][
'onyx:hasEmotion'
][
0
][
'onyx:hasEmotionCategory'
])
senpy/plugins/example/rand/rand.py
View file @
8e4578dc
import
random
from
senpy.plugins
import
SentimentPlugin
from
senpy.models
import
Sentiment
from
senpy.models
import
Sentiment
,
Entry
class
RandPlugin
(
SentimentPlugin
):
...
...
@@ -22,3 +22,13 @@ class RandPlugin(SentimentPlugin):
entry
.
sentiments
.
append
(
sentiment
)
entry
.
language
=
lang
yield
entry
def
test
(
self
):
params
=
dict
()
results
=
list
()
for
i
in
range
(
100
):
res
=
next
(
self
.
analyse_entry
(
Entry
(
text
=
"Hello"
),
params
))
res
.
validate
()
results
.
append
(
res
.
sentiments
[
0
][
'marl:hasPolarity'
])
assert
'marl:Positive'
in
results
assert
'marl:Negative'
in
results
senpy/plugins/sentiment/sentiment140/sentiment140.py
View file @
8e4578dc
...
...
@@ -34,3 +34,20 @@ class Sentiment140Plugin(SentimentPlugin):
entry
.
sentiments
.
append
(
sentiment
)
entry
.
language
=
lang
yield
entry
test_cases
=
[
{
'entry'
:
{
'text'
:
'I love Titanic'
},
'params'
:
{},
'expected'
:
{
"text"
:
"I love Titanic"
,
'sentiments'
:
[
{
'marl:hasPolarity'
:
'marl:Positive'
,
}
]
}
}
]
tests/plugins/async_plugin/asyncplugin.py
View file @
8e4578dc
...
...
@@ -21,3 +21,6 @@ class AsyncPlugin(AnalysisPlugin):
values
=
self
.
_do_async
(
2
)
entry
.
async_values
=
values
yield
entry
def
test
(
self
):
pass
tests/plugins/dummy_plugin/dummy.py
View file @
8e4578dc
...
...
@@ -6,3 +6,6 @@ class DummyPlugin(SentimentPlugin):
entry
.
text
=
entry
.
text
[::
-
1
]
entry
.
reversed
=
entry
.
get
(
'reversed'
,
0
)
+
1
yield
entry
def
test
(
self
):
pass
tests/plugins/sleep_plugin/sleep.py
View file @
8e4578dc
...
...
@@ -9,3 +9,6 @@ class SleepPlugin(AnalysisPlugin):
def
analyse_entry
(
self
,
entry
,
params
):
sleep
(
float
(
params
.
get
(
"timeout"
,
self
.
timeout
)))
yield
entry
def
test
(
self
):
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