Uses 911K of libraries. Click here for Pure Java version (10967L/73K).
1 | !7 |
2 | |
3 | !include once #1027167 // Compact Module Include 2 v2 |
4 | |
5 | module WinogradSolver1 > DynSingleFunctionWithPrintLog { |
6 | transient PhilosophyBot1 engine; |
7 | transient O multiStage; // unused |
8 | |
9 | S prelude = "import bool"; |
10 | |
11 | S input = "Bob paid for Charlie's college education. He is very [generous/grateful]. Who is [generous/grateful]?"; |
12 | |
13 | Map<S, SS> answers = syncMap(); |
14 | |
15 | void doIt { |
16 | clear(answers); change(); |
17 | if (empty(input)) ret; |
18 | // Stage 1: take one option out of square brackets |
19 | for (S variant : winograd_variants(input)) { |
20 | print(variant); |
21 | SS _answers = ciMap(); |
22 | dm_call(multiStage, 'addStage, "Variant", variant); |
23 | |
24 | // Stage 1b: Split off 's |
25 | S input2b = ai_splitOffApostropheS(variant); |
26 | dm_call(multiStage, 'addStage, "Split off 's", input2b); |
27 | |
28 | // Stage 1c: Split into sentences |
29 | LS sentences = map dropQuestionMark(sentences(input2b)); |
30 | dm_call(multiStage, 'addStage, "Split into sentences", sentences); |
31 | |
32 | // Stage 2: Parser |
33 | S parser = dm_makeModule("#1027108/TopDownParsing"); |
34 | //L<virtual TryPatterns> parsed = map(sentences, s -> dm_call(parser, 'parse, s)); |
35 | L<Cl<S>> parsed = map(sentences, s -> (Cl<S>) dm_call(parser, 'parseToGroupings, s)); |
36 | pnl(parsed); |
37 | Set<S> allGroupings = concatListsToCISet(parsed); |
38 | print("Have " + n2(allGroupings, "grouping")); |
39 | dm_call(multiStage, 'addStage, "Parser", parsed); |
40 | |
41 | // Stage 3a: Select the right rules for the task |
42 | Cl<S> allRules = dm_getUnclearList("Rules"); // take all for now |
43 | |
44 | // Stage 3b: Run logic engine |
45 | S program = joinWithEmptyLines(concatLists(ll(prelude), allGroupings, allRules)); |
46 | engine = PhilosophyBot1(program); |
47 | engine.standardImports(); |
48 | engine.enableTrails(); |
49 | engine.printFactsAfterThinking = false; |
50 | engine.think(); |
51 | engine.printDeducedFactsWithTrails(); |
52 | |
53 | for (SS map : engine.matchFacts("the answer to $x is $y")) |
54 | if (allGroupings.contains($x(map))) { |
55 | printAfterNewLine("ANSWER>> " + $x(map) + ": " + $y(map)); |
56 | _answers.put($x(map), $y(map)); |
57 | } |
58 | answers.put(variant, _answers); change(); |
59 | print(); |
60 | } |
61 | } |
62 | |
63 | visual northCenterAndSouthWithMargins( |
64 | jCenteredSection("Input", dm_centeredTextField input()), |
65 | super, |
66 | jCenteredSection("Answers", |
67 | //dm_calculatedTextArea(() -> pnlToString(answers))) |
68 | dm_calculatedCenteredLabel(() -> joinWithSlash( |
69 | map(values(answers), map -> joinWithComma(values(map))))) |
70 | ); |
71 | |
72 | } |
Began life as a copy of #1027165
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1027181 |
Snippet name: | Winograd Solver (backup before trails) |
Eternal ID of this version: | #1027181/1 |
Text MD5: | f23c3d25ecbafc3180093553e539f026 |
Transpilation MD5: | 0af4c881f3cc47b0db490b39a449f204 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-02-24 11:59:21 |
Source code size: | 2653 bytes / 72 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 228 / 307 |
Referenced in: | [show references] |