!7 cmodule AIPackagesSpike > DynTextArea { transient PhilosophyBot1 bot; transient Scorer scorer; S verificationResult; start { grabInterval = 1.0; dm_onFieldChangeAndNow text(r compute); } void compute q { S input = getText(); TreeMap sections = asCIMap(underlinedHeadingSections(input)); LS tests = nempties(itemPlusList(getAny(sections, "", "test"), valuesForKeysStartingWith(sections, "test "))); print("Have " + nTests(tests)); S solutionText = sections.get("Example solution"); scorer = new Scorer; for (S testText : tests) scorer.add(testSolution(testText, solutionText)); setField(verificationResult := str(scorer)); print(scorer); } bool testSolution(S testText, S solutionText) { MultiMap testPairs = parseColonPropertyCIMultiMap(testText); MultiMap solutionPairs = parseColonPropertyCIMultiMap_honorBrackets(solutionText); // facts LS qs = testPairs.get("Q"); Cl facts = concatLists( testPairs.get("Fact"), qs, solutionPairs.get("Fact"), map(qs, q -> format_quoteAll("input is *", q))); // get patterns from rules Cl rules = solutionPairs.get("Rule"); pnl("RULES> ", rules); bot = new PhilosophyBot1(joinWithEmptyLines(rules)); philosophyBot_autoJava(bot); pb_enableAutoPatterns(bot); // add 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..."); } void saveIt enter { dm_call(dm_aiPackagesCRUD(), 'storeAIPackage, getText(), verificationResult); infoBox("Stored. Total number of AI packages: " + dm_rcall conceptCount(dm_aiPackagesCRUD())); } visual withMargin(withCenteredButtons( jvsplit(super, dm_printLogComponent()), "Compute", rThread compute, "Save", rThread saveIt)); }