!7 !include once #1027167 // Compact Module Include 2 v2 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(); engine.printFactsAfterThinking = false; engine.think(); engine.printDeducedFactsWithTrails(); 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))))) ); }