Warning: session_start(): open(/var/lib/php/sessions/sess_v6q91p59ua3uvgulflkhki5b0u, 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
!include once #1027167 // Compact Module Include 2 v2
set flag AllPublic.
module WinogradSolver1 > DynSingleFunctionWithPrintLog {
transient PhilosophyBot1 engine;
transient O multiStage; // unused
S prelude = "import bool";
S input = "Bob paid for Charlie's college education. He is very [generous/grateful]. Who is [generous/grateful]?";
Map answers = syncMap();
void doIt {
clear(answers); change();
if (empty(input)) ret;
// Stage 1: take one option out of square brackets
for (S variant : winograd_variants(input)) {
print(variant);
SS _answers = ciMap();
dm_call(multiStage, 'addStage, "Variant", variant);
// Stage 1b: Split off 's
S input2b = ai_splitOffApostropheS(variant);
dm_call(multiStage, 'addStage, "Split off 's", input2b);
// Stage 1c: Split into sentences
LS sentences = map dropQuestionMark(sentences(input2b));
dm_call(multiStage, 'addStage, "Split into sentences", sentences);
// Stage 2: Parser
S parser = dm_makeModule("#1027108/TopDownParsing");
//L parsed = map(sentences, s -> dm_call(parser, 'parse, s));
L> parsed = map(sentences, s -> (Cl) dm_call(parser, 'parseToGroupings, s));
pnl(parsed);
Set allGroupings = concatListsToCISet(parsed);
print("Have " + n2(allGroupings, "grouping"));
dm_call(multiStage, 'addStage, "Parser", parsed);
// Stage 3a: Select the right rules for the task
Cl allRules = dm_getUnclearList("Rules"); // take all for now
// Stage 3b: Run logic engine
S program = joinWithEmptyLines(concatLists(ll(prelude), allGroupings, allRules));
engine = PhilosophyBot1(program);
engine.standardImports();
engine.enableTrails();
for (S s : allGroupings) {
//print("Setting trail for " + quote(s));
engine.setTrail(s, "grouped original input");
}
engine.setTrailForAllLogicRules("initial rule");
engine.printFactsAfterThinking = false;
engine.think();
engine.printDeducedFactsWithTrails();
// gather simplified versions of questions so we find their answers too
LPairS simplifications = philosophyBot1_allSimplifications_gen(engine);
for (PairS p : simplifications)
if (allGroupings.contains(p.a)) allGroupings.add(p.b);
for (SS map : engine.matchFacts("the answer to $x is $y"))
if (allGroupings.contains($x(map))) {
printAfterNewLine("ANSWER>> " + $x(map) + ": " + $y(map));
_answers.put($x(map), $y(map));
}
answers.put(variant, _answers); change();
print();
}
}
visual northCenterAndSouthWithMargins(
jCenteredSection("Input", dm_centeredTextField input()),
super,
jCenteredSection("Answers",
//dm_calculatedTextArea(() -> pnlToString(answers)))
dm_calculatedCenteredLabel(() -> joinWithSlash(
map(values(answers), map -> joinWithComma(values(map)))))
));
start {
dm_registerAs winogradSolver();
}
// API
O getTrailForFact(S fact) {
ret engine == null ? null : engine.getTrail(fact);
}
}