//Testing whether true and false are handled as prolog queries private static void TestBoolConstant() { KnowledgeBase kb = new KnowledgeBase("Global", null); kb.Consult("PrologTest.prolog"); kb.IsTrueWrite("true."); kb.IsTrueWrite("false."); }
/* * Test that SolveFor() can be used to bind variables. * Findings: * If the variable is bound to a simple value it's a Symbol. * If the variable is bound to a composite value (like a functor) it's a Structure. * If the query doesn't succeed the returned variable is null. * If the query succeeds but the variable isn't bound in the query, the returned variable is a gensym. * If you need to return multiple values with a query, you can create a predicate on the prolog side which binds multiple values in a functor and unify that with the return variable. */ private static void TestVariableBinding() { KnowledgeBase kb = new KnowledgeBase("Global", null); kb.Consult("PrologTest.prolog"); var x = kb.SolveForParsed("X:test(X)."); Console.WriteLine("The value of x is " + x); Console.WriteLine("The type of x is " + x.GetType()); //Console.WriteLine("The type of x is " + ((Structure)x).Argument(1)); }
/* * fixme: Queries which involve chaining bindings generate an error. It looks like in the guts of SolveFor() there * are recursive calls which call GameObject.SolveFor(). So using this basic feature of prolog requires * the UnityProlog KB to be embeded in a game object. To debug this I should just develop a TextChoices unity * demo with the KB stored on a GameObject. */ private static void TestIncrement() { KnowledgeBase kb = new KnowledgeBase("Global", null); kb.Consult("PrologTestWithError.prolog"); kb.IsTrueWrite("triesGreaterThan(1)."); //kb.IsTrueWrite("tries(X), X > 1."); //kb.IsTrueWrite("assert(triedDoor)."); //kb.IsTrueWrite("incrementTries."); //kb.IsTrueWrite("tries(X), X > 1."); //kb.IsTrueWrite("assert(triedDoor)."); //kb.IsTrueWrite("tries(x), X > 1."); }
private static void CreatePrologKBAFromFileAndQuery() { // fixme: KnowledgeBase wants a reference to a game object. This is because GameObjects can form a tree of knowledge bases. // But I don't need this. Ideally we'd refactor prolog so that there is a lower abstract level that makes no reference to Unity classes. // Alternatively, a KB could be created on the Unity side and passed into the CSA. KnowledgeBase kb = new KnowledgeBase("Global", null); kb.Consult("PrologTest.prolog"); var query = ISOPrologReader.Read("mortal(socratese)."); if (kb.IsTrue(query)) { Console.WriteLine("Socratese is mortal."); } else { Console.WriteLine("Something is wrong with logic!"); } }
protected void Init(string kbPath, string kbName) { myKB = new KnowledgeBase(kbName, gameObject); myKB.Consult(kbPath); myKB.IsTrue(new ISOPrologReader("init.").ReadTerm(), this); }