!7 p-exp { if (contains(args, "bake")) bakeTheBot(); test1(); test2(); test3(); test4(); test5(); test4b(); test6(); test7(); test7b(); test7c(); test7d(); test7e(); test8(); test8b(); print("test8c"); test8c(); test8d(); test9(); consoleStatus(print("BASE TESTS DONE. DOING ADVANCED TESTS.")); test10(); consoleStatus(print("BASE & ADVANCED TESTS OK")); } svoid test1 { BakedBot bot = bakedBotWithRules([[ inputContainsTokens("=>") && !inputStartsWith("!rule ") => output(Should I store this rule?) ]]); bot.setAuthorized(true); bot.check("bla => blubb", "Should I store this rule?"); assertEqualsVerbose("", unnull(callAnswerMethod(bot, "bla <= blubb"))); bot.check("!rule bla => bla", "Rule saved as *. Have 2 rules."); } svoid test2 { BakedBot bot = bakedBotWithRules([[ input(what is $chicken $wire?) => output(a $wire made from $chicken) ]]); bot.check("what is pork sausage?", "a sausage made from pork"); } svoid test3 { BakedBot bot = bakedBotWithRules([[ input(What is $gertrude $afraid_of?) && fact($gertrude is $afraid_of $wolves) => output($wolves) ]]); bot.setList("Fact-to-fact rules", [[ fact($gertrude is a $sheep) && fact($sheep are $afraid_of_wolves) => fact($gertrude is $afraid_of_wolves) ]]); bot.setList("Random Facts", [[ sheep are afraid of wolves Cats are afraid of dogs. Mice are afraid of cats. klaus is a sheep ]]); setOptAll(bot.bot, ai_deriveFacts_debug := true, ai_applyFactToFactRules_debug := true); bot.answerAuthed("!deriveFacts"); assertEqualsVerbose_match("Klaus is afraid of wolves", bot.getList("Derived facts")); pnl((L) call(bot.bot, 'mL_facts)); call(bot.bot, 'setDebug, true); bot.check("What is Klaus afraid of", "Wolves"); } svoid test4 { BakedBot bot = bakedBotWithRules([[ i(what are the features) && allFacts($x is a feature|$x are a feature) => o($x1, $x2 [...] and $x_n) ]]); bot.setList("Random Facts", [[ fun is a feature love is a feature drinks are a feature music is a feature ]]); bot.check("what are the features", "fun, love, drinks and music"); } svoid test4b { BakedBot bot = bakedBotWithRules([[ i(what is that one $feature again) && allFacts($x is a $feature|$x are a $feature) => o(do you mean $x1, $x2 [...] or $x_n?) ]]); bot.setList("Random Facts", [[ fun is a feature love is a feature drinks are a feature music is a feature ]]); bot.check("what is that one feature again", "Do you mean fun, love, drinks or music?"); } svoid test5 { S rule = [[ [id: qohpbitnzaqfexmz] i(what is rule $x) => evalOutput(trim(getString(call(ai_context(), 'getRule, $x), 'originalText))) ]]; BakedBot bot = bakedBotWithRules(rule); bot.check("what is rule qohpbitnzaqfexmz", trim(rule)); } svoid test6 { BakedBot bot = bakedBotWithRules([[i($John is $in_the_playground) && $John != what => o(yo)]]); bot.check("bla is bla", "yo"); bot.check("what is bla", null); } svoid test7 { bakedBotWithRules([[i(bla) && $a, $b = eval(joinWithComma(pair("x", "y"))) => o($b and $a)]]).check("bla", "y and x"); } svoid test7b { bakedBotWithRules([[i(bla) && $a, $b = eval(joinWithComma(pair("bla bla", "this and that"))) => o($b and $a)]]).check("bla", "this and that and bla bla"); } svoid test7c { bakedBotWithRules([[i(bla) && $a, $b = eval(pair("bla bla", "this and that")) => o($b and $a)]]).check("bla", "this and that and bla bla"); } svoid test7d { bakedBotWithRules([[i(bla) && $a, $b, $c = eval(ll("let's", "do", "it")) => o($c $b $a)]]).check("bla", "it do let's"); } svoid test7e { bakedBotWithRules([[i(bla) && $a, $b, $c = eval(litorderedset("let's", "do", "it")) => o($c $b $a)]]).check("bla", "it do let's"); } sS mineralsRule = [[ [id: zrpcdxxfqzgdkzof] fact(I saw $a_man $lick $minerals) && fact($_q_licked is past tense for $_q_lick) => newID($the_man) && fact($the_man was $a_man) && fact(I saw $the_man) && fact($the_man $licked $minerals) ]]; svoid test8 { bakedBotWithRules(mineralsRule).check("!factsFrom i saw a girl eat frogs", "No new facts found"); // no result because there is no past tense for "eat" } svoid test8b { bakedBotWithRulesAndFacts(mineralsRule, [["licked" is past tense for "lick"]]) .check("!factsFrom i saw a girl eat frogs", "No new facts found"); // still no result because there is no past tense for "eat" } svoid test8c { BakedBot bot = bakedBotWithRulesAndFacts(mineralsRule, [["licked" is past tense for "lick"]]); setOptAll(bot.bot, ai_deriveFacts_debug := true, ai_applyFactToFactRules_debug := true); S s = bot.answer_verbose("!factsFrom [debug] i saw a girl lick walls"); print("l(s)= " + l(s)); assertNotNull(printStruct(jmatchDollarVars([[ $x was a girl I saw $x $x $licked walls ]], s)); } svoid test8d { bakedBotWithRulesAndFacts(joinWithEmptyLines(mineralsRule, [[ [id: xxrmapvwhesonlyo] unresolvedFact($x is past tense for $_q_y) && eval(ai_isVar($x) && !ai_isVar($y)) => output(What is the past tense of $_q_y?) ]]), [["licked" is past tense for "lick"]]) .check("!askBackAboutFact i saw a girl eat frogs", [[What is the past tense of "eat"?]]); } // !deriveFacts with rules containing eval svoid test9 { new BakedBot bot; bot.setList("Fact-to-fact rules", [[ eval(1==1) => fact(ok) ]]); setOptAll(bot.bot, ai_deriveFacts_debug := true, ai_applyFactToFactRules_debug := true); bot.answerAuthed("!deriveFacts"); assertEqualsVerbose_match("ok", bot.getList("Derived facts")); } svoid test10 { BakedBot bot = bakedBotWithRulesAndFacts([[ i(is $love $nice) && eval(ai_isTrue($love + " is " + $nice)) => o(yo) ]], [[love is nice]]); bot.check("is love nice", "yo"); bot.check("is love green", ""); }