KnowledgeBase.KB.SetPerspective C# (CSharp) Method

SetPerspective() public method

public SetPerspective ( Name newPerspective ) : void
newPerspective Name
return void
        public void SetPerspective(Name newPerspective)
        {
            if(!newPerspective.IsPrimitive)
                throw new ArgumentException("Only primitive symbols are allowed to be perspectives.");

            if(newPerspective == Name.NIL_SYMBOL)
                throw new ArgumentException("NIL symbol cannot be used as a perspective.");

            if (newPerspective == Name.SELF_SYMBOL)
                throw new ArgumentException("SELF symbol cannot be set as a default a perspectives.");

            if (newPerspective==Perspective)
                return;

            if(GetAllPerspectives().Contains(newPerspective))
                throw new ArgumentException($"The is already beliefs containing perspectives for {newPerspective}. Changing to the requested perspective would result in belief conflicts.");

            //Modify believes to reflect perspective changes
            var newStorage = new NameSearchTree<KnowledgeEntry>();
            foreach (var entry in m_knowledgeStorage)
            {
                var newProperty = entry.Key.SwapTerms(Perspective, newPerspective);
                newStorage.Add(newProperty,entry.Value);
            }
            m_knowledgeStorage.Clear();
            m_knowledgeStorage = newStorage;
            Perspective = newPerspective;
        }

Usage Example

Example #1
0
        public void Test_Fail_Change_Perspective_To_Invalid_Perspective(string perspective)
        {
            var kb = new KB(Name.BuildName("Mark"));
            kb.Tell(Name.BuildName("IsPerson(Self)"), Name.BuildName(true), Name.BuildName("John(Self)"));

            Assert.Throws<ArgumentException>(() => kb.SetPerspective(Name.BuildName(perspective)));
        }
All Usage Examples Of KnowledgeBase.KB::SetPerspective