!7 cmodule AIPackagesSpike > DynTextArea implements Runnable { transient PhilosophyBot1 bot; start { dm_onFieldChangeAndNow text(this); // doesn't work? } public void run() enter { S input = getText(); SS sections = asCIMap(underlinedHeadingSections(input)); S testText = getAny(sections, "", "test"); //valuesForKeysStartingWith S solutionText = sections.get("Example solution"); testSolution(testText, solutionText); } bool testSolution(S testText, S solutionText) { 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) ret false with print("BAD answer!"); if (good) ret true with print("OK!"); ret false with print("No answer..."); } visual withMargin(withCenteredButtons( jvsplit(super, dm_printLogComponent()), "Compute", module())); }