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)); } } } }
/// <summary> /// Appraises a set of event strings. /// /// Durring appraisal, the events will be recorded in the asset's autobiographical memory, /// and Property Change Events will update the asset's knowledge about the world, allowing /// the asset to use the new information derived from the events to appraise the correspondent /// emotions. /// </summary> /// <param name="eventNames">A set of string representation of the events to appraise</param> public void AppraiseEvents(IEnumerable <Name> eventNames, Name perspective, IEmotionalState emotionalState, AM am, KB kb) { var appraisalFrame = new InternalAppraisalFrame(); appraisalFrame.Perspective = kb.Perspective; foreach (var n in eventNames) { var evt = am.RecordEvent(n, am.Tick); var propEvt = evt as IPropertyChangedEvent; if (propEvt != null) { var fact = propEvt.Property; var value = Name.BuildName("-"); if (propEvt.NewValue.IsPrimitive) { value = propEvt.NewValue; if (value.ToString() == "-") { var remove = kb.GetAllBeliefs().Where(x => x.Name == fact); kb.removeBelief(fact); } else { kb.Tell(fact, value, perspective); } } else // new value is not grounded { var values = kb.AskPossibleProperties(propEvt.NewValue, perspective, new List <SubstitutionSet>()); if (values.Count() == 1) { kb.Tell(fact, values.FirstOrDefault().Item1.Value, perspective); } else { throw new Exception("Multiple possible values for " + propEvt.NewValue); } } } appraisalFrame.Reset(evt); var componentFrame = appraisalFrame.RequestComponentFrame(m_appraisalDerivator, m_appraisalDerivator.AppraisalWeight); m_appraisalDerivator.Appraisal(kb, evt, componentFrame); UpdateEmotions(appraisalFrame, emotionalState, am); } }
private void UpdateEmotions(IAppraisalFrame frame, IEmotionalState emotionalState, AM am) { if (_lastFrameAppraisal > frame.LastChange) { return; } var emotions = m_occAffectDerivator.AffectDerivation(this, frame); foreach (var emotion in emotions) { var activeEmotion = emotionalState.AddEmotion(emotion, am, GetEmotionDisposition(emotion.EmotionType), am.Tick); if (activeEmotion == null) { continue; } } _lastFrameAppraisal = frame.LastChange; }
public void AppraiseEvents(IEnumerable <Name> eventNames, IEmotionalState emotionalState, AM am, KB kb) { AppraiseEvents(eventNames, Name.SELF_SYMBOL, emotionalState, am, kb); }
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)); } } } }
private void UpdateEmotions(IAppraisalFrame frame, Dictionary <string, Goal> goals, IEmotionalState emotionalState, AM am) { var emotions = m_occAffectDerivator.AffectDerivation(this, goals, frame); foreach (var emotion in emotions) { var activeEmotion = emotionalState.AddEmotion(emotion, am, GetEmotionDisposition(emotion.EmotionType), am.Tick); if (activeEmotion == null) { continue; } } }
public void AppraiseEvents(IEnumerable <Name> eventNames, IEmotionalState emotionalState, AM am, KB kb, Dictionary <string, Goal> goals) { AppraiseEvents(eventNames, Name.SELF_SYMBOL, emotionalState, am, kb, goals); }