mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-22 08:12:27 +00:00
Fixed some code problems
This commit is contained in:
parent
38b478890b
commit
530982be62
@ -17,20 +17,23 @@ class maxSentiment(AnalysisPlugin):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def analyse_entry(self, entry, params):
|
def analyse_entry(self, entry, params):
|
||||||
if params["max"]==True:
|
if not params["max"]:
|
||||||
set_emotions= entry.emotions[0]['onyx:hasEmotion']
|
yield entry
|
||||||
max_emotion =set_emotions[0]
|
return
|
||||||
|
|
||||||
# Extract max emotion from the set emotions (emotion with highest intensity)
|
set_emotions= entry.emotions[0]['onyx:hasEmotion']
|
||||||
for tmp_emotion in set_emotions:
|
max_emotion =set_emotions[0]
|
||||||
if tmp_emotion['onyx:hasEmotionIntensity']>max_emotion['onyx:hasEmotionIntensity']:
|
|
||||||
max_emotion=tmp_emotion
|
|
||||||
|
|
||||||
if max_emotion['onyx:hasEmotionIntensity'] == 0:
|
# Extract max emotion from the set emotions (emotion with highest intensity)
|
||||||
max_emotion['onyx:hasEmotionCategory'] = "neutral"
|
for tmp_emotion in set_emotions:
|
||||||
max_emotion['onyx:hasEmotionIntensity'] = 1.0
|
if tmp_emotion['onyx:hasEmotionIntensity']>max_emotion['onyx:hasEmotionIntensity']:
|
||||||
|
max_emotion=tmp_emotion
|
||||||
|
|
||||||
entry.emotions[0]['onyx:hasEmotion'] = [max_emotion]
|
if max_emotion['onyx:hasEmotionIntensity'] == 0:
|
||||||
|
max_emotion['onyx:hasEmotionCategory'] = "neutral"
|
||||||
|
max_emotion['onyx:hasEmotionIntensity'] = 1.0
|
||||||
|
|
||||||
|
entry.emotions[0]['onyx:hasEmotion'] = [max_emotion]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -38,15 +41,11 @@ class maxSentiment(AnalysisPlugin):
|
|||||||
#print(entry)
|
#print(entry)
|
||||||
yield entry
|
yield entry
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Test Cases:
|
# Test Cases:
|
||||||
# 1º Normal Situation.
|
# 1 Normal Situation.
|
||||||
# 2º Case to return a Neutral Emotion.
|
# 2 Case to return a Neutral Emotion.
|
||||||
test_cases = [{
|
test_cases = [{
|
||||||
"entry": {
|
"entry": {
|
||||||
"@id": "#",
|
|
||||||
"@type": "entry",
|
"@type": "entry",
|
||||||
"emotions": [
|
"emotions": [
|
||||||
{
|
{
|
||||||
@ -83,23 +82,16 @@ class maxSentiment(AnalysisPlugin):
|
|||||||
"onyx:hasEmotionCategory": "disgust",
|
"onyx:hasEmotionCategory": "disgust",
|
||||||
"onyx:hasEmotionIntensity": 0
|
"onyx:hasEmotionIntensity": 0
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
'prov:wasGeneratedBy':"maxSentiment_plugin"
|
|
||||||
|
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
"entities": [],
|
"nif:isString": "This text makes me sad.\nwhilst this text makes me happy and surprised at the same time.\nI cannot believe it!"
|
||||||
"nif:isString": "This text makes me sad.\nwhilst this text makes me happy and surprised at the same time.\nI cannot believe it!",
|
|
||||||
"sentiments": [],
|
|
||||||
"suggestions": [],
|
|
||||||
"topics": []
|
|
||||||
|
|
||||||
},
|
},
|
||||||
'params': {
|
'params': {
|
||||||
'max': True
|
'max': True
|
||||||
},
|
},
|
||||||
'expected' : {
|
'expected' : {
|
||||||
"@id": "#",
|
|
||||||
"@type": "entry",
|
"@type": "entry",
|
||||||
"emotions": [
|
"emotions": [
|
||||||
{
|
{
|
||||||
@ -112,19 +104,15 @@ class maxSentiment(AnalysisPlugin):
|
|||||||
"onyx:hasEmotionCategory": "joy",
|
"onyx:hasEmotionCategory": "joy",
|
||||||
"onyx:hasEmotionIntensity": 0.3333333333333333
|
"onyx:hasEmotionIntensity": 0.3333333333333333
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"prov:wasGeneratedBy" : 'maxSentiment'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"entities": [],
|
"nif:isString": "This text makes me sad.\nwhilst this text makes me happy and surprised at the same time.\nI cannot believe it!"
|
||||||
"nif:isString": "This text makes me sad.\nwhilst this text makes me happy and surprised at the same time.\nI cannot believe it!",
|
|
||||||
"sentiments": [],
|
|
||||||
"suggestions": [],
|
|
||||||
"topics": []
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"entry": {
|
"entry": {
|
||||||
"@id": "#",
|
|
||||||
"@type": "entry",
|
"@type": "entry",
|
||||||
"emotions": [
|
"emotions": [
|
||||||
{
|
{
|
||||||
@ -161,23 +149,17 @@ class maxSentiment(AnalysisPlugin):
|
|||||||
"onyx:hasEmotionCategory": "disgust",
|
"onyx:hasEmotionCategory": "disgust",
|
||||||
"onyx:hasEmotionIntensity": 0
|
"onyx:hasEmotionIntensity": 0
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
'prov:wasGeneratedBy':"maxSentiment_plugin"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"entities": [],
|
"nif:isString": "This text makes me sad.\nwhilst this text makes me happy and surprised at the same time.\nI cannot believe it!"
|
||||||
"nif:isString": "This text makes me sad.\nwhilst this text makes me happy and surprised at the same time.\nI cannot believe it!",
|
|
||||||
"sentiments": [],
|
|
||||||
"suggestions": [],
|
|
||||||
"topics": []
|
|
||||||
|
|
||||||
},
|
},
|
||||||
'params': {
|
'params': {
|
||||||
'max': True
|
'max': True
|
||||||
},
|
},
|
||||||
'expected' : {
|
'expected' : {
|
||||||
"@id": "#",
|
|
||||||
"@type": "entry",
|
"@type": "entry",
|
||||||
"emotions": [
|
"emotions": [
|
||||||
{
|
{
|
||||||
@ -190,14 +172,11 @@ class maxSentiment(AnalysisPlugin):
|
|||||||
"onyx:hasEmotionCategory": "neutral",
|
"onyx:hasEmotionCategory": "neutral",
|
||||||
"onyx:hasEmotionIntensity": 1
|
"onyx:hasEmotionIntensity": 1
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"prov:wasGeneratedBy" : 'maxSentiment'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"entities": [],
|
"nif:isString": "This text makes me sad.\nwhilst this text makes me happy and surprised at the same time.\nI cannot believe it!"
|
||||||
"nif:isString": "This text makes me sad.\nwhilst this text makes me happy and surprised at the same time.\nI cannot believe it!",
|
|
||||||
"sentiments": [],
|
|
||||||
"suggestions": [],
|
|
||||||
"topics": []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}]
|
}]
|
||||||
|
Loading…
Reference in New Issue
Block a user