diff --git a/senpy/plugins/conversion/centroids.py b/senpy/plugins/conversion/centroids.py index 427e111..ef08976 100644 --- a/senpy/plugins/conversion/centroids.py +++ b/senpy/plugins/conversion/centroids.py @@ -44,16 +44,32 @@ class CentroidConversion(EmotionConversionPlugin): self.neutralPoints[i] = self.get("neutralValue", 0) def _forward_conversion(self, original): - """Sum the VAD value of all categories found.""" + """Sum the VAD value of all categories found weighted by intensity. + Intensities are scaled by onyx:maxIntensityValue if it is present, else maxIntensityValue is assumed to be one. + Emotion entries that do not have onxy:hasEmotionIntensity specified are assumed to have maxIntensityValue. + Emotion entries that do not have onyx:hasEmotionCategory specified are ignored.""" res = Emotion() + maxIntensity = float(original.get("onyx__maxIntensityValue",1)) + neutralPoint = self.get("origin",None) for e in original.onyx__hasEmotion: - category = e.onyx__hasEmotionCategory - if category in self.centroids: - for dim, value in self.centroids[category].items(): + category = e.get("onyx__hasEmotionCategory", None) + if category is None: + continue + intensity = e.get("onyx__hasEmotionIntensity",maxIntensity)/maxIntensity + if intensity == 0: + continue + centoid = self.centroids.get(category,None) + if centroid: + for dim, value in centroid.items(): + if neutralPoint: + value -= neutralPoint[dim] try: - res[dim] += value - except Exception: - res[dim] = value + res[dim] += value * intensity + except KeyError: + res[dim] = value * intensity + if neutralPoint: + for dim in res: + res[dim] += neutralPoint[dim] return res def _backwards_conversion(self, original): diff --git a/senpy/plugins/conversion/emotion/ekman2vad.senpy b/senpy/plugins/conversion/emotion/ekman2vad.senpy index a1f21f0..e9eac74 100644 --- a/senpy/plugins/conversion/emotion/ekman2vad.senpy +++ b/senpy/plugins/conversion/emotion/ekman2vad.senpy @@ -4,6 +4,11 @@ module: senpy.plugins.conversion.centroids description: Plugin to convert emotion sets from Ekman to VAD version: 0.1 # No need to specify onyx:doesConversion because centroids.py adds it automatically from centroids_direction +origin: + # Point in VAD space with no emotion (aka Neutral) + A: 5.0 + D: 5.0 + V: 5.0 centroids: anger: A: 6.95 @@ -36,4 +41,4 @@ aliases: # These are aliases for any key in the centroid, to avoid repeating a l disgust: emoml:big6disgust fear: emoml:big6fear happiness: emoml:big6happiness - sadness: emoml:big6sadness \ No newline at end of file + sadness: emoml:big6sadness