!7 cmodule AIPackagesSpike > DynTextArea implements Runnable { transient PhilosophyBot1 bot; public void run() enter { S input = getText(); SS sections = asCIMap(underlinedHeadingSections(input)); S testText = getAny(sections, "", "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..."); } visual withCenteredButtons( jvsplit(super, dm_printLogComponent()), "Compute", module()); }