detectEmotionalValence method
Computes a simple emotional valence from detected cues.
Implementation
EmotionalValence detectEmotionalValence(List<String> emotionalCues) {
if (emotionalCues.isEmpty) return EmotionalValence.neutral;
const positiveWords = {
'happy', 'joy', 'love', 'safe', 'excited', 'calm',
};
const negativeWords = {
'sad', 'angry', 'afraid', 'scared', 'pain', 'danger',
'hungry', 'tired', 'worried', 'frustrated', 'hate', 'fear',
};
var positiveCount = 0;
var negativeCount = 0;
for (final cue in emotionalCues) {
if (positiveWords.contains(cue)) positiveCount++;
if (negativeWords.contains(cue)) negativeCount++;
}
if (positiveCount == 0 && negativeCount == 0) {
return EmotionalValence.neutral;
}
final balance = (positiveCount - negativeCount).toDouble();
final total = (positiveCount + negativeCount).toDouble();
final ratio = balance / total;
if (ratio >= 0.6) return EmotionalValence.veryPositive;
if (ratio >= 0.2) return EmotionalValence.positive;
if (ratio <= -0.6) return EmotionalValence.veryNegative;
if (ratio <= -0.2) return EmotionalValence.negative;
return EmotionalValence.neutral;
}