Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="perspective">The perspective to evaluate</param>
        /// <returns>The ToM sequenceList</returns>
        private List <Name> AssertPerspective(Name perspective, string argumentName)
        {
            if (perspective == Name.NIL_SYMBOL)
            {
                throw new ArgumentException("Perspectives cannot contain NIL symbol", argumentName);
            }

            perspective = perspective.ApplyPerspective(Perspective);

            List <Name> ToMList = new List <Name>();

            if (perspective.IsUniversal)
            {
                ToMList.Add(Name.UNIVERSAL_SYMBOL);
                return(ToMList);
            }

            ToMList.Add(Name.SELF_SYMBOL);
            if (perspective.IsPrimitive)
            {
                if (perspective != Name.SELF_SYMBOL)
                {
                    ToMList.Add(perspective);
                }

                return(ToMList);
            }

            if (!perspective.IsConstant)
            {
                throw new ArgumentException("The given Theory of the Mind perspective needs to be constant", argumentName);
            }

            //Validate ToM definition and ToM level
            var eval = perspective;

            while (eval.IsComposed)
            {
                if (eval.NumberOfTerms > 2)
                {
                    throw new ArgumentException($"Invalid perspective format {perspective}", argumentName);
                }

                var f = eval.GetNTerm(0);

                AssetToMList(ToMList, f, argumentName);

                eval = eval.GetNTerm(1);
            }
            AssetToMList(ToMList, eval, argumentName);

            return(ToMList);
        }
Example #2
0
        public void Tell(Name property, PrimitiveValue value, Name perspective)
        {
            if (property.IsPrimitive)
            {
                throw new ArgumentException("The given property name cannot be a primitive value.", nameof(property));
            }

            if (!property.IsConstant)
            {
                throw new ArgumentException("The given property name is not constant. Only constant names can be stored", nameof(property));
            }

            perspective = perspective.ApplyPerspective(Perspective);
            var ToMList = AssertPerspective(perspective, nameof(perspective));

            property = RemovePropertyPerspective(property, ToMList);

            //ToM property shift
            property = ExtractPropertyFromToM(property, ToMList, nameof(property));

            if (m_dynamicProperties.Unify(property).Any())
            {
                throw new ArgumentException("The given name will be objuscated by a dynamic property", nameof(property));
            }

            var fact = property.ApplyToTerms(p => SimplifyProperty(p, ToMList));

            KnowledgeEntry entry;

            if (!m_knowledgeStorage.TryGetValue(fact, out entry))
            {
                entry = new KnowledgeEntry();
                m_knowledgeStorage[fact] = entry;
            }

            var mind_key = ToMList2Key(ToMList);

            entry.TellValueFor(mind_key, value);
            if (entry.IsEmpty())
            {
                m_knowledgeStorage.Remove(fact);
            }
        }
Example #3
0
        public IEnumerable <BeliefPair> AskPossibleProperties(Name property, Name perspective, IEnumerable <SubstitutionSet> constraints)
        {
            if (constraints == null)
            {
                constraints = new[] { new SubstitutionSet() }
            }
            ;

            if (property.IsPrimitive)
            {
                if (property == Name.SELF_SYMBOL)
                {
                    property = Perspective;
                }

                return(new[] { Tuples.Create(property.GetPrimitiveValue(), constraints) });
            }

            perspective = perspective.ApplyPerspective(Perspective);
            var ToMList = AssertPerspective(perspective, nameof(perspective));

            return(internal_AskPossibleProperties(property, ToMList, constraints));
        }
Example #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="perspective">The perspective to evaluate</param>
        /// <returns>The ToM sequenceList</returns>
        private List<Name> AssertPerspective(Name perspective, string argumentName)
        {
            if(perspective == Name.NIL_SYMBOL)
                throw new ArgumentException("Perspectives cannot contain NIL symbol",argumentName);

            perspective = perspective.ApplyPerspective(Perspective);

            List<Name> ToMList = new List<Name>();
            if (perspective.IsUniversal)
            {
                ToMList.Add(Name.UNIVERSAL_SYMBOL);
                return ToMList;
            }

            ToMList.Add(Name.SELF_SYMBOL);
            if (perspective.IsPrimitive)
            {
                if(perspective != Name.SELF_SYMBOL)
                    ToMList.Add(perspective);

                return ToMList;
            }

            if (!perspective.IsConstant)
                throw new ArgumentException("The given Theory of the Mind perspective needs to be constant", argumentName);

            //Validate ToM definition and ToM level
            var eval = perspective;

            while (eval.IsComposed)
            {
                if (eval.NumberOfTerms > 2)
                    throw new ArgumentException($"Invalid perspective format {perspective}", argumentName);

                var f = eval.GetNTerm(0);

                AssetToMList(ToMList, f, argumentName);

                eval = eval.GetNTerm(1);
            }
            AssetToMList(ToMList, eval, argumentName);

            return ToMList;
        }