Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

79
LINES

< > BotCompany Repo | #1027422 // AI Package Tester v2 [shortened/generalized, latest version]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (18691L/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  
    // 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  
    pb_enableAutoPatterns(bot);
46  
47  
    // add facts to bot, calculate
48  
    
49  
    S program = joinWithEmptyLines(facts);
50  
    printWithIndent("PROGRAM> ", program);
51  
    bot.loadProgram(program);
52  
    bot.run();
53  
54  
    // Check answer
55  
    Set<S> wantedAnswers = mapToCISet dropPunctuation(testPairs.get("A"));
56  
    Set<S> unwantedAnswers = mapToCISet dropPunctuation(testPairs.get("Not an answer"));
57  
    pnl(+wantedAnswers);
58  
    pnl(+unwantedAnswers);
59  
60  
    bool good = listAndSetIntersect(bot.deducedFacts(), wantedAnswers);
61  
    bool bad = listAndSetIntersect(bot.deducedFacts(), unwantedAnswers);
62  
    if (bad)
63  
      ret false with print("BAD answer!");
64  
    if (good)
65  
      ret true with print("OK!");
66  
    ret false with print("No answer...");
67  
  }
68  
69  
  void saveIt enter {
70  
    dm_call(dm_aiPackagesCRUD(), 'storeAIPackage, getText(), verificationResult);
71  
    infoBox("Stored. Total number of AI packages: " + dm_rcall conceptCount(dm_aiPackagesCRUD()));
72  
  }
73  
74  
  visual
75  
    withMargin(withCenteredButtons(
76  
      jvsplit(super, dm_printLogComponent()),
77  
      "Compute", rThread compute,
78  
      "Save", rThread saveIt));
79  
}

Author comment

Began life as a copy of #1027406

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: #1027422
Snippet name: AI Package Tester v2 [shortened/generalized, latest version]
Eternal ID of this version: #1027422/8
Text MD5: 3483fab6b8cf6c665f79a56a75dde261
Transpilation MD5: 79c8bde85f44c01d05992ea76c438057
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-03-19 15:33:09
Source code size: 2508 bytes / 79 lines
Pitched / IR pitched: No / No
Views / Downloads: 187 / 596
Version history: 7 change(s)
Referenced in: [show references]