Uses 911K of libraries. Click here for Pure Java version (18632L/103K).
1 | !7 |
2 | |
3 | cmodule AIPackagesSpike > DynTextArea { |
4 | transient PhilosophyBot1 bot; |
5 | transient Scorer scorer; |
6 | S verificationResult; |
7 | |
8 | start { |
9 | grabInterval = 1.0; |
10 | dm_onFieldChangeAndNow text(r compute); |
11 | } |
12 | |
13 | void compute q { |
14 | S input = getText(); |
15 | TreeMap<S> sections = asCIMap(underlinedHeadingSections(input)); |
16 | LS tests = nempties(itemPlusList(getAny(sections, "", "test"), |
17 | valuesForKeysStartingWith(sections, "test "))); |
18 | print("Have " + nTests(tests)); |
19 | S solutionText = sections.get("Example solution"); |
20 | scorer = new Scorer; |
21 | for (S testText : tests) |
22 | scorer.add(testSolution(testText, solutionText)); |
23 | setField(verificationResult := str(scorer)); |
24 | print(scorer); |
25 | } |
26 | |
27 | bool testSolution(S testText, S solutionText) { |
28 | MultiMap<S> testPairs = parseColonPropertyCIMultiMap(testText); |
29 | MultiMap<S> solutionPairs = parseColonPropertyCIMultiMap_honorBrackets(solutionText); |
30 | |
31 | // ungrouped facts |
32 | LS qs = testPairs.get("Q"); |
33 | Cl<S> facts = concatLists( |
34 | testPairs.get("Fact"), |
35 | qs, |
36 | solutionPairs.get("Fact"), |
37 | map(qs, q -> format_quoteAll("input is *", q))); |
38 | |
39 | // get patterns from rules |
40 | |
41 | Cl<S> rules = solutionPairs.get("Rule"); |
42 | pnl("RULES> ", rules); |
43 | bot = new PhilosophyBot1(joinWithEmptyLines(rules)); |
44 | philosophyBot_autoJava(bot); |
45 | |
46 | // make bot group all facts |
47 | |
48 | bot.parseProgram(); |
49 | Cl<S> patterns = philosophyBot_allLHSAsStarPatterns(bot); |
50 | pnl("PATTERN> ", patterns); |
51 | bot.addCodeOnFact(s -> bot.addFacts(dm_topDownParseToGroupings(s, patterns))); |
52 | |
53 | // add grouped facts to bot, calculate |
54 | |
55 | S program = joinWithEmptyLines(facts); |
56 | printWithIndent("PROGRAM> ", program); |
57 | bot.loadProgram(program); |
58 | bot.run(); |
59 | |
60 | // Check answer |
61 | Set<S> wantedAnswers = mapToCISet dropPunctuation(testPairs.get("A")); |
62 | Set<S> unwantedAnswers = mapToCISet dropPunctuation(testPairs.get("Not an answer")); |
63 | pnl(+wantedAnswers); |
64 | pnl(+unwantedAnswers); |
65 | |
66 | bool good = listAndSetIntersect(bot.deducedFacts(), wantedAnswers); |
67 | bool bad = listAndSetIntersect(bot.deducedFacts(), unwantedAnswers); |
68 | if (bad) |
69 | ret false with print("BAD answer!"); |
70 | if (good) |
71 | ret true with print("OK!"); |
72 | ret false with print("No answer..."); |
73 | } |
74 | |
75 | void saveIt enter { |
76 | dm_call(dm_aiPackagesCRUD(), 'storeAIPackage, getText(), verificationResult); |
77 | infoBox("Stored. Total number of AI packages: " + dm_rcall conceptCount(dm_aiPackagesCRUD())); |
78 | } |
79 | |
80 | visual |
81 | withMargin(withCenteredButtons( |
82 | jvsplit(super, dm_printLogComponent()), |
83 | "Compute", rThread compute, |
84 | "Save", rThread saveIt)); |
85 | } |
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: | #1027406 |
Snippet name: | AI Package Tester [OK, v1] - see #1027422 |
Eternal ID of this version: | #1027406/28 |
Text MD5: | f726ac373388c6499d349633d4775a79 |
Transpilation MD5: | 9c74d828496adc505cd9f8da2b22bcaf |
Author: | stefan |
Category: | |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-03-18 19:29:53 |
Source code size: | 2739 bytes / 85 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 181 / 634 |
Version history: | 27 change(s) |
Referenced in: | [show references] |