!7 cmodule AIPackagesSpike > DynPrintLog { S input = [[ Test ---- Fact: A gazelle is fast Q: Is a gazelle slow? A: No A: No, it is fast A: No, it's fast A: No, a gazelle is fast A: No, fast A: No, it's fast, not slow Not an answer: Yes Example solution ---------------- Fact: Fast is not slow Rule: Y is not Z => Z is not Y Rule: a X is Y & Y is not Z => a X is not Z Rule: is X Y? & X is not Y => no ]]; transient PhilosophyBot1 bot; start-thread { dm_reloadOnFieldChange input(); SS sections = asCIMap(underlinedHeadingSections(input)); S testText = sections.get("test"); S solutionText = sections.get("Example solution"); MultiMap testPairs = parseColonPropertyCIMultiMap(testText); MultiMap solutionPairs = parseColonPropertyCIMultiMap(solutionText); // ungrouped facts Cl facts = concatLists( testPairs.get("Fact"), testPairs.get("Q"), solutionPairs.get("Fact")); // get patterns from rules Cl rules = solutionPairs.get("Rule"); pnl("RULES> ", rules); bot = new PhilosophyBot1(joinWithEmptyLines(rules)); // make bot group all facts bot.parseProgram(); Cl patterns = philosophyBot_allLHSAsStarPatterns(bot); pnl("PATTERN> ", patterns); bot.addCodeOnFact(s -> bot.addFacts(dm_topDownParseToGroupings(s, patterns))); // add grouped facts to bot, calculate S program = joinWithEmptyLines(facts); printWithIndent("PROGRAM> ", program); bot.loadProgram(program); bot.run(); // Check answer Set wantedAnswers = mapToCISet dropPunctuation(testPairs.get("A")); Set unwantedAnswers = mapToCISet dropPunctuation(testPairs.get("Not an answer")); pnl(+wantedAnswers); pnl(+unwantedAnswers); bool good = listAndSetIntersect(bot.deducedFacts(), wantedAnswers); bool bad = listAndSetIntersect(bot.deducedFacts(), unwantedAnswers); if (bad) print("BAD answer!"); else if (good) print("OK!"); else print("No answer..."); } }