Tell() public method

public Tell ( Name property, Name value ) : void
property Name
value Name
return void
コード例 #1
0
 public void Test_DynamicProperty_Regist_Fail_ConstantProperties()
 {
     var kb = new KB((Name)"Me");
     Assert.Throws<ArgumentException>(() =>
     {
         kb.Tell((Name)"Count(John)", Name.BuildName(3));
         kb.RegistDynamicProperty((Name)"Count", DummyCount);
     });
 }
コード例 #2
0
        public void ConditionEvaluatorSet_Test_Universal_Pass(params string[] beliefs)
        {
            var kb = new KB((Name)"Me");
            foreach (var s in beliefs.Select(b => b.Split(':')))
                kb.Tell((Name)s[0], (Name)s[1]);

            var set = new ConditionSet(LogicalQuantifier.Universal, TEST_CONDITIONS);
            Assert.True(set.Evaluate(kb, Name.SELF_SYMBOL, null));
        }
コード例 #3
0
 //public static int NumOfPersistentEntries()
 //{
 //    return MemoryData().Count(d =>
 //        d.Arguments.Length > 2 && (bool) d.Arguments[2]
 //        );
 //}
 public static KB PopulatedTestMemory()
 {
     KB kb = new KB((Name)"Me");
     foreach (var t in MemoryData())
     {
         Name property = (Name) t.Arguments[0];
         Name value = Name.BuildName(t.Arguments[1]);
         try
         {
             //if(t.Arguments.Length>2)
             //	kb.Tell((Name)t.Arguments[0], PrimitiveValue.Cast(t.Arguments[1]),(bool)t.Arguments[2]);
             //else
             kb.Tell(property, value);
         }
         catch (Exception e)
         {
             if (t.Arguments.Length > 2)
                 Assert.AreEqual(e.GetType(), t.Arguments[2]);
             else
                 Assert.Fail($"An exception was thrown unexpectedly while evaluating {property} = {value}: {e}");
         }
     }
     return kb;
 }
コード例 #4
0
 public void Test_Tell_Pass_Basic_Property_With_ToM()
 {
     const string property = "ToM(Mary,ToM(Self,Has(Ball)))";
     var kb = new KB((Name)"John");
     kb.Tell((Name) property, Name.BuildName(true));
 }
コード例 #5
0
        public void Test_Tell_Pass_Add_With_Perspective(string nativePerspective, string tellPerdicate, string tellPerspective, string queryPerdicate, string queryPerspective)
        {
            var kb = new KB(Name.BuildName(nativePerspective));
            kb.Tell(Name.BuildName(tellPerdicate), Name.BuildName(true), Name.BuildName(tellPerspective));

            using (var stream = new MemoryStream())
            {
                var formater = new JSONSerializer();
                formater.Serialize(stream, kb);
                stream.Seek(0, SeekOrigin.Begin);
                Console.WriteLine(new StreamReader(stream).ReadToEnd());
            }

            var r = kb.AskProperty(Name.BuildName(queryPerdicate), Name.BuildName(queryPerspective));
            bool b;
            if (!r.TryConvertToValue(out b))
                Assert.Fail();

            Assert.IsTrue(b);
        }
コード例 #6
0
        public void Test_Tell_Pass_Add_Self_Belief_and_Change_Perspective_02()
        {
            var kb = new KB(Name.BuildName("Mark"));
            kb.Tell(Name.BuildName("IsPerson(Self)"), Name.BuildName(true),Name.BuildName("John(Self)"));

            kb.SetPerspective(Name.BuildName("Mary"));

            Assert.Null(kb.AskProperty(Name.BuildName("IsPerson(Mark)"), Name.BuildName("John(Self)")));

            var n = kb.AskProperty(Name.BuildName("IsPerson(Mary)"), Name.BuildName("John(Self)"));
            bool b;
            if(!n.TryConvertToValue(out b))
                Assert.Fail();
            Assert.True(b);
        }
コード例 #7
0
 public void Test_Tell_Fail_Property_ToM_Transform(string property,string perspective)
 {
     var kb = new KB((Name)"John");
     Assert.Throws<ArgumentException>(() => kb.Tell((Name) property, Name.BuildName(true),(Name)perspective));
 }
コード例 #8
0
 public void Test_Tell_Fail_Primitive_Property(string primitiveName)
 {
     var kb = new KB((Name)"John");
     Assert.Throws<ArgumentException>(() => kb.Tell((Name)primitiveName, Name.BuildName(true)));
 }
コード例 #9
0
        public void Test_Tell_Fail_Assert_Perspective(string perspective,Type exceptionType)
        {
            var kb = new KB((Name)"John");

            Assert.Throws(exceptionType,() => kb.Tell((Name)"Likes(Mary)", Name.BuildName(true), (Name)perspective));
        }
コード例 #10
0
 public void Test_Tell_Fail_Add_Self_To_Universal_Context()
 {
     var kb = new KB((Name)"John");
     Assert.Throws<InvalidOperationException>(() => kb.Tell((Name)"Likes(Self)", Name.BuildName(true),Name.UNIVERSAL_SYMBOL));
 }
コード例 #11
0
 public void Test_Tell_Fail_Add_Self_To_Universal()
 {
     var kb = new KB(Name.BuildName("Matt"));
     Assert.Throws<InvalidOperationException>(() => { kb.Tell((Name)"IsPerson(Self)", Name.BuildName(true), Name.UNIVERSAL_SYMBOL); });
 }
コード例 #12
0
 public void Test_Simple_Tell_Valid(Name name, object value)
 {
     var kb = new KB((Name)"Me");
     kb.Tell(name, Name.BuildName(value));
 }
コード例 #13
0
 public void Test_Simple_Tell_Invalid(Name name, object value, Type expectedException)
 {
     var kb = new KB((Name)"Me");
     Assert.Throws(expectedException, () => kb.Tell(name, Name.BuildName(value)));
 }
コード例 #14
0
 public void Test_Fail_Tell_With_Nil_Perspective()
 {
     var kb = new KB(Name.BuildName("Mark"));
     Assert.Throws<ArgumentException>(() => kb.Tell(Name.BuildName("IsPerson(Self)"), Name.BuildName(true), Name.NIL_SYMBOL));
 }
コード例 #15
0
 public void Test_Tell_Fail_Complext_Property_With_ToM()
 {
     const string property = "ToM(Mary,ToM(Self,Has(ToM(Mary,Ball))))";
     var kb = new KB((Name)"John");
     Assert.Throws<ArgumentException>(() => kb.Tell((Name)property, Name.BuildName(true)));
 }
コード例 #16
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)));
        }
コード例 #17
0
        private static KB CreateKB()
        {
            var kb = new KB((Name)"Me");

            kb.Tell((Name)"Strength(John)",Name.BuildName(5));
            kb.Tell((Name)"Strength(Mary)", Name.BuildName(3));
            kb.Tell((Name)"Strength(Leonidas)", Name.BuildName(500));
            kb.Tell((Name)"Strength(Goku)", Name.BuildName(9001f));
            kb.Tell((Name)"Strength(SuperMan)", Name.BuildName(ulong.MaxValue));
            kb.Tell((Name)"Strength(Saitama)", Name.BuildName(float.MaxValue));
            kb.Tell((Name)"Race(Saitama)", Name.BuildName("human"));
            kb.Tell((Name)"Race(Superman)", Name.BuildName("kriptonian"));
            kb.Tell((Name)"Race(Goku)",Name.BuildName("sayian"));
            kb.Tell((Name)"Race(Leonidas)", Name.BuildName("human"));
            kb.Tell((Name)"Race(Mary)", Name.BuildName("human"));
            kb.Tell((Name)"Race(John)", Name.BuildName("human"));
            kb.Tell((Name)"Job(Saitama)", Name.BuildName("super-hero"));
            kb.Tell((Name)"Job(Superman)", Name.BuildName("super-hero"));
            kb.Tell((Name)"Job(Leonidas)", Name.BuildName("Spartan"));
            kb.Tell((Name)"AKA(Saitama)", Name.BuildName("One-Punch_Man"));
            kb.Tell((Name)"AKA(Superman)", Name.BuildName("Clark_Kent"));
            kb.Tell((Name)"AKA(Goku)", Name.BuildName("Kakarot"));
            kb.Tell((Name)"Hobby(Saitama)", Name.BuildName("super-hero"));
            kb.Tell((Name)"Hobby(Goku)", Name.BuildName("training"));
            kb.Tell((Name)"IsAlive(Leonidas)", Name.BuildName(false));
            kb.Tell((Name)"IsAlive(Saitama)", Name.BuildName(true));
            kb.Tell((Name)"IsAlive(Superman)", Name.BuildName(true));
            kb.Tell((Name)"IsAlive(John)", Name.BuildName(true));

            return kb;
        }