2018-01-03 08:39:30 +00:00
|
|
|
import random
|
|
|
|
|
|
|
|
from senpy.plugins import EmotionPlugin
|
|
|
|
from senpy.models import EmotionSet, Emotion, Entry
|
|
|
|
|
|
|
|
|
|
|
|
class EmoRand(EmotionPlugin):
|
|
|
|
'''A sample plugin that returns a random emotion annotation'''
|
2019-01-07 11:08:19 +00:00
|
|
|
name = 'emotion-random'
|
2018-01-03 08:39:30 +00:00
|
|
|
author = '@balkian'
|
|
|
|
version = '0.1'
|
|
|
|
url = "https://github.com/gsi-upm/senpy-plugins-community"
|
|
|
|
onyx__usesEmotionModel = "emoml:big6"
|
|
|
|
|
2019-01-07 11:08:19 +00:00
|
|
|
def analyse_entry(self, entry, activity):
|
2018-01-03 08:39:30 +00:00
|
|
|
category = "emoml:big6happiness"
|
|
|
|
number = max(-1, min(1, random.gauss(0, 0.5)))
|
|
|
|
if number > 0:
|
|
|
|
category = "emoml:big6anger"
|
|
|
|
emotionSet = EmotionSet()
|
|
|
|
emotion = Emotion({"onyx:hasEmotionCategory": category})
|
|
|
|
emotionSet.onyx__hasEmotion.append(emotion)
|
2019-01-07 11:08:19 +00:00
|
|
|
emotionSet.prov(activity)
|
2018-01-03 08:39:30 +00:00
|
|
|
entry.emotions.append(emotionSet)
|
|
|
|
yield entry
|
|
|
|
|
|
|
|
def test(self):
|
|
|
|
params = dict()
|
|
|
|
results = list()
|
|
|
|
for i in range(100):
|
2019-01-07 11:08:19 +00:00
|
|
|
res = next(self.analyse_entry(Entry(nif__isString="Hello"), self.activity(params)))
|
2018-01-03 08:39:30 +00:00
|
|
|
res.validate()
|
|
|
|
results.append(res.emotions[0]['onyx:hasEmotion'][0]['onyx:hasEmotionCategory'])
|