Exemplo n.º 1
0
        internal static void AdviceTests()
        {
            var mind = new MindSet();

            mind
            .AddPattern("$something", "can", "have", "$something2")
            .HowToEvaluate(c =>
                           c["something"].ExtendByAnswer("what does @ have?", c["something2"])
                           )

            .AddPattern("every", "$something")
            .HowToEvaluate(c =>
                           DbConstraint.Entity(null).ExtendByAnswer("what @ is?", c["something"])
                           )

            .AddPattern("blue", "$something")

            ;

            mind.AddFact("dog", "what color @ has?", "black");
            mind.AddFact("whale", "what color @ has?", "blue");
            mind.AddFact("whale", "where @ lives?", "sea");
            mind.AddFact("dog", "what @ is?", "mammal");
            mind.AddFact("whale", "what @ is?", "mammal");

            var evaluation = mind.Evaluator.Evaluate("every blue mammal", Evaluator.HowToEvaluateQ);

            wl(evaluation.ToString());

            foreach (var value in mind.Database.Query(evaluation.Constraint))
            {
                Console.WriteLine("Result: " + value.Substitution);
            }

            //what is sky?
            //the stuff above
            //what is a blue color?
            //its an example of a color

            wl("S: What is The Great Britain?");
            wl("U: It is a country.");

            wl("S: What is a country?");
            wl("U: Its a location with a culture, people and so on.");
            wl("U: USA is a country.");
            wl("U: Country is a word.");
            wl("....");
            //writes
            //  - how is defined? A location
            //  - which extra props. it has? culture
            //  - which extra props. it has? people

            wl("S: What culture a country has?");
            wl("U: It depends on a concrete country.");

            wl("S: So do you know some country?");
            wl("U: Sure, e.g. germany with their strict culture.");
        }
Exemplo n.º 2
0
        internal Body(MindSet mind)
        {
            Mind = mind;

            //common abilities
            AddNativeAction(Print, "say", "$what");
            AddNativeAction(FormulateTopicQuestion, "formulate", "a", "topic", "question");
            AddNativeAction(AddSensorAction, RawEvaluator, ValueEvaluator, "add", "$action", "to", "$sensor");

            //topic handling
            AddNativeAction(WriteTopic, "write", "topic", "$topic");
            AddNativeAction(SetPointerToEmptyEntity, "set", "topic", "pointer", "to", "a", "missing", "entity");

            //search handling
            AddNativeAction(Search, "search", "$something");

            mind
            .AddPattern("input", "from", "user")
            .HowToEvaluate(c => DbConstraint.Entity(_inputHistory.Last()))

            .AddPattern("topic")
            .HowToEvaluate(c => _currentTopic)

            .AddPattern("a", "database", "question")
            .HowToEvaluate(c => databaseQuestion())

            .AddPattern("yes")
            .IsTrue(c => DbConstraint.Entity("yes"))

            .AddPattern("no")
            .IsTrue(c => DbConstraint.Entity("no"))

            .AddPattern("first", "$action1", "second", "$action2", "third", "$action3")
            .HowToDo(c =>
            {
                var action1 = c.Evaluate("action1", Evaluator.HowToDoQ);
                var action2 = c.Evaluate("action2", Evaluator.HowToDoQ);
                var action3 = c.Evaluate("action3", Evaluator.HowToDoQ);

                return(DbConstraint.Entity(NativeMutliCallHandler).ExtendByAnswer("1?", action1).ExtendByAnswer("2?", action2).ExtendByAnswer("3?", action3));
            })

            .AddPattern("first", "$action1", "second", "$action2")
            .HowToDo(c =>
            {
                var action1 = c.Evaluate("action1", Evaluator.HowToDoQ);
                var action2 = c.Evaluate("action2", Evaluator.HowToDoQ);

                return(DbConstraint.Entity(NativeMutliCallHandler).ExtendByAnswer("1?", action1).ExtendByAnswer("2?", action2));
            })
            ;

            _nativeCallWrappers.Add(NativeMutliCallHandler, MultiCall);
        }
Exemplo n.º 3
0
        internal static void DbTests()
        {
            var mind = new MindSet();

            mind.AddFact("dog", "how @ is defined?", "animal with four legs");
            mind.AddFact("dog", "what does @ eat?", "meat");

            var constraint = new DbConstraint(
                ConstraintEntry.AnswerWhere("dog", "how @ is defined?")
                );

            foreach (var entity in mind.Database.Query(constraint))
            {
                Console.WriteLine(entity.Substitution);
            }
        }
Exemplo n.º 4
0
        internal static void ParsingTests()
        {
            var mind = new MindSet();

            mind
            .AddPattern("a", "$something")
            .HowToEvaluate(c => c["something"])

            .AddPattern("what", "is", "$what")
            .HowToEvaluate(c => c.AnswerWhere(c["something"], "how @ is defined?"))

            .AddPattern("$something1", "and", "$something2")
            .HowToEvaluate(c => c["something1"].Join(c["something2"]))
            ;

            var matches = mind.Matcher.Match("what is a pilot");

            foreach (var match in matches)
            {
                Console.WriteLine(match);
            }
        }