private IEnumerable <DynamicPropertyResult> GetEmotionsForEntity(IEmotionalState state, Name emotionName, IQueryable kb, Name perspective, IEnumerable <SubstitutionSet> constraints) { if (emotionName.IsVariable) { foreach (var emotion in state.GetAllEmotions()) { var sub = new Substitution(emotionName, new ComplexValue((Name)emotion.EmotionType)); foreach (var c in constraints) { if (c.Conflicts(sub)) { continue; } var newConstraints = new SubstitutionSet(c); newConstraints.AddSubstitution(sub); yield return(new DynamicPropertyResult(new ComplexValue(Name.BuildName(emotion.Intensity)), newConstraints)); } } } else { foreach (var resultPair in kb.AskPossibleProperties(emotionName, perspective, constraints)) { string emotionKey = resultPair.Item1.Value.ToString(); var emotion = state.GetEmotionsByType(emotionKey).OrderByDescending(e => e.Intensity).FirstOrDefault(); float value = emotion?.Intensity ?? 0; foreach (var c in resultPair.Item2) { yield return(new DynamicPropertyResult(new ComplexValue(Name.BuildName(value)), c)); } } } }
private IEnumerable <Pair <PrimitiveValue, SubstitutionSet> > GetEmotionsForEntity(IEmotionalState state, Name emotionName, KB kb, Name perspective, IEnumerable <SubstitutionSet> constraints) { if (emotionName.IsVariable) { foreach (var emotion in state.GetAllEmotions()) { var sub = new Substitution(emotionName, (Name)emotion.EmotionType); foreach (var c in constraints) { if (c.Conflicts(sub)) { continue; } var newConstraints = new SubstitutionSet(c); newConstraints.AddSubstitution(sub); yield return(Tuples.Create((PrimitiveValue)emotion.Intensity, newConstraints)); } } } else { foreach (var resultPair in kb.AskPossibleProperties(emotionName, perspective, constraints)) { string emotionKey = resultPair.Item1.ToString(); var emotion = state.GetEmotionsByType(emotionKey).OrderByDescending(e => e.Intensity).FirstOrDefault(); PrimitiveValue value = emotion == null ? 0 : emotion.Intensity; foreach (var c in resultPair.Item2) { yield return(Tuples.Create(value, c)); } } } }