Warning: session_start(): open(/var/lib/php/sessions/sess_hs4apjjnqd41n52dp8981hrddo, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
cmodule AIPackagesSpike > DynTextArea implements Runnable {
transient PhilosophyBot1 bot;
transient Scorer scorer;
start {
dm_onFieldChangeAndNow text(this); // doesn't work?
}
public void run() enter {
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));
print(scorer);
}
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));
philosophyBot_autoJava(bot);
// 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()));
}