GetCause() public méthode

public GetCause ( AM am ) : IBaseEvent
am AutobiographicMemory.AM
Résultat IBaseEvent
Exemple #1
0
        public EmotionDTO AddActiveEmotion(EmotionDTO emotion, AM am)
        {
            var activeEmotion = new ActiveEmotion(emotion, am, 1, 1);

            if (emotionPool.ContainsKey(calculateHashString(activeEmotion)))
            {
                throw new ArgumentException("This given emotion is already related to given cause", nameof(emotion));
            }

            emotionPool.Add(calculateHashString(activeEmotion), activeEmotion);
            activeEmotion.GetCause(am).LinkEmotion(activeEmotion.EmotionType);
            return(activeEmotion.ToDto(am));
        }
            /// <summary>
            /// Creates and Adds to the emotional state a new ActiveEmotion based on
            /// a received BaseEmotion. However, the ActiveEmotion will be created
            /// and added to the emotional state only if the final intensity for
            /// the emotion surpasses the threshold for the emotion type.
            /// </summary>
            /// <param name="emotion">the BaseEmotion that creates the ActiveEmotion</param>
            /// <returns>the ActiveEmotion created if it was added to the EmotionalState.
            /// Otherwise, if the intensity of the emotion was not enough to be added to the EmotionalState, the method returns null</returns>
            public IActiveEmotion AddEmotion(IEmotion emotion)
            {
                if (emotion == null)
                {
                    return(null);
                }

                int           decay;
                ActiveEmotion auxEmotion  = null;
                bool          reappraisal = false;

                EmotionDisposition disposition = GetEmotionDisposition(emotion.EmotionType);

                decay = disposition.Decay;

                ActiveEmotion previousEmotion;
                string        hash = calculateHashString(emotion, m_parent.m_am);

                if (emotionPool.TryGetValue(hash, out previousEmotion))
                {
                    //if this test is true, it means that this is 100% a reappraisal of the same event
                    //if not true, it is not a reappraisal, but the appraisal of a new event of the same
                    //type
                    if (previousEmotion.CauseId == emotion.CauseId)
                    {
                        reappraisal = true;
                    }

                    //in both cases we need to remove the old emotion. In the case of reappraisal it is obvious.
                    //In the case of the appraisal of a similar event, we want to aggregate all the similar resulting
                    //emotions into only one emotion
                    emotionPool.Remove(hash);
                }

                float potential = DeterminePotential(emotion);

                if (potential > disposition.Threshold)
                {
                    auxEmotion = new ActiveEmotion(emotion, potential, disposition.Threshold, decay, m_parent.Tick);
                    emotionPool.Add(hash, auxEmotion);
                    if (!reappraisal)
                    {
                        this.mood.UpdateMood(auxEmotion, m_parent);
                    }

                    auxEmotion.GetCause(m_parent.m_am).LinkEmotion(auxEmotion.EmotionType);
                }

                return(auxEmotion);
            }
            public EmotionDTO AddActiveEmotion(EmotionDTO emotion)
            {
                EmotionDisposition disposition = GetEmotionDisposition(emotion.Type);
                var    activeEmotion           = new ActiveEmotion(emotion, disposition.Threshold, disposition.Decay);
                string hash = calculateHashString(activeEmotion, m_parent.m_am);

                if (emotionPool.ContainsKey(hash))
                {
                    throw new Exception("Emotion already exists");
                }

                emotionPool.Add(hash, activeEmotion);
                activeEmotion.GetCause(m_parent.m_am).LinkEmotion(activeEmotion.EmotionType);

                return(activeEmotion.ToDto(m_parent.m_am));
            }
            public EmotionDTO AddActiveEmotion(EmotionDTO emotion)
            {
                EmotionDisposition disposition = GetEmotionDisposition(emotion.Type);
                var activeEmotion = new ActiveEmotion(emotion, disposition.Threshold, disposition.Decay);
                string hash = calculateHashString(activeEmotion, m_parent.m_am);

                if (emotionPool.ContainsKey(hash))
                {
                    throw new ArgumentException("This given emotion is already related to given cause",nameof(emotion));
                }

                emotionPool.Add(hash, activeEmotion);
                activeEmotion.GetCause(m_parent.m_am).LinkEmotion(activeEmotion.EmotionType);

                return activeEmotion.ToDto(m_parent.m_am);
            }
            /// <summary>
            /// Creates and Adds to the emotional state a new ActiveEmotion based on 
            /// a received BaseEmotion. However, the ActiveEmotion will be created 
            /// and added to the emotional state only if the final intensity for 
            /// the emotion surpasses the threshold for the emotion type. 
            /// </summary>
            /// <param name="emotion">the BaseEmotion that creates the ActiveEmotion</param>
            /// <returns>the ActiveEmotion created if it was added to the EmotionalState.
            /// Otherwise, if the intensity of the emotion was not enough to be added to the EmotionalState, the method returns null</returns>
            public IActiveEmotion AddEmotion(IEmotion emotion)
            {
                if (emotion == null)
                    return null;

                int decay;
                ActiveEmotion auxEmotion = null;
                bool reappraisal = false;

                EmotionDisposition disposition = GetEmotionDisposition(emotion.EmotionType);
                decay = disposition.Decay;

                ActiveEmotion previousEmotion;
                string hash = calculateHashString(emotion, m_parent.m_am);
                if (emotionPool.TryGetValue(hash,out previousEmotion))
                {
                    //if this test is true, it means that this is 100% a reappraisal of the same event
                    //if not true, it is not a reappraisal, but the appraisal of a new event of the same
                    //type
                    if (previousEmotion.CauseId == emotion.CauseId)
                        reappraisal = true;

                    //in both cases we need to remove the old emotion. In the case of reappraisal it is obvious.
                    //In the case of the appraisal of a similar event, we want to aggregate all the similar resulting
                    //emotions into only one emotion
                    emotionPool.Remove(hash);
                }

                float potential = DeterminePotential(emotion);
                if (potential > disposition.Threshold)
                {
                    auxEmotion = new ActiveEmotion(emotion, potential, disposition.Threshold, decay, m_parent.Tick);
                    emotionPool.Add(hash, auxEmotion);
                    if (!reappraisal)
                        this.mood.UpdateMood(auxEmotion,m_parent);

                    auxEmotion.GetCause(m_parent.m_am).LinkEmotion(auxEmotion.EmotionType);
                }

                return auxEmotion;
            }