Пример #1
0
        public void Test_Tell_SameBelief_DifferentPerspective()
        {
            var kb = new KB(Name.BuildName("Mark"));

            kb.Tell(Name.BuildName("Likes(Bread)"), Name.BuildName(true), Name.BuildName("Self"));

            kb.Tell(Name.BuildName("Likes(Bread)"), Name.BuildName(false), Name.BuildName("Jose"));

            var bs = kb.GetAllBeliefs();

            var count = bs.Count();

            Assert.AreEqual(2, count);
        }
        /// <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);
            }
        }
Пример #3
0
        public void Test_KB_RemoveBelief(string toAdd, string toRemove, int total)
        {
            var kb = new KB((Name)"John");

            var tell = toAdd.Split(',');

            foreach (var b in tell)
            {
                var value = b.Split('=');
                kb.Tell((Name)value[0], (Name)value[1]);
            }

            var rem = toRemove.Split(',');

            foreach (var r in rem)
            {
                kb.removeBelief((Name)r);
            }

            Assert.AreEqual(kb.GetAllBeliefs().Count(), total);
        }