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

85
LINES

< > BotCompany Repo | #1027406 // AI Package Tester [OK, v1] - see #1027422

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

Uses 911K of libraries. Click here for Pure Java version (18632L/103K).

!7

cmodule AIPackagesSpike > DynTextArea {
  transient PhilosophyBot1 bot;
  transient Scorer scorer;
  S verificationResult;

  start {
    grabInterval = 1.0;
    dm_onFieldChangeAndNow text(r compute);
  }

  void compute q {
    S input = getText();
    TreeMap<S> sections = asCIMap(underlinedHeadingSections(input));
    LS tests = nempties(itemPlusList(getAny(sections, "", "test"),
      valuesForKeysStartingWith(sections, "test ")));
    print("Have " + nTests(tests));
    S solutionText = sections.get("Example solution");
    scorer = new Scorer;
    for (S testText : tests)
      scorer.add(testSolution(testText, solutionText));
    setField(verificationResult := str(scorer));
    print(scorer);
  }

  bool testSolution(S testText, S solutionText) {
    MultiMap<S> testPairs = parseColonPropertyCIMultiMap(testText);
    MultiMap<S> solutionPairs = parseColonPropertyCIMultiMap_honorBrackets(solutionText);

    // ungrouped facts
    LS qs = testPairs.get("Q");
    Cl<S> facts = concatLists(
      testPairs.get("Fact"),
      qs,
      solutionPairs.get("Fact"),
      map(qs, q -> format_quoteAll("input is *", q)));

    // get patterns from rules

    Cl<S> rules = solutionPairs.get("Rule");
    pnl("RULES> ", rules);
    bot = new PhilosophyBot1(joinWithEmptyLines(rules));
    philosophyBot_autoJava(bot);

    // make bot group all facts
    
    bot.parseProgram();
    Cl<S> patterns = philosophyBot_allLHSAsStarPatterns(bot);
    pnl("PATTERN> ", patterns);
    bot.addCodeOnFact(s -> bot.addFacts(dm_topDownParseToGroupings(s, patterns)));

    // add grouped facts to bot, calculate
    
    S program = joinWithEmptyLines(facts);
    printWithIndent("PROGRAM> ", program);
    bot.loadProgram(program);
    bot.run();

    // Check answer
    Set<S> wantedAnswers = mapToCISet dropPunctuation(testPairs.get("A"));
    Set<S> unwantedAnswers = mapToCISet dropPunctuation(testPairs.get("Not an answer"));
    pnl(+wantedAnswers);
    pnl(+unwantedAnswers);

    bool good = listAndSetIntersect(bot.deducedFacts(), wantedAnswers);
    bool bad = listAndSetIntersect(bot.deducedFacts(), unwantedAnswers);
    if (bad)
      ret false with print("BAD answer!");
    if (good)
      ret true with print("OK!");
    ret false with print("No answer...");
  }

  void saveIt enter {
    dm_call(dm_aiPackagesCRUD(), 'storeAIPackage, getText(), verificationResult);
    infoBox("Stored. Total number of AI packages: " + dm_rcall conceptCount(dm_aiPackagesCRUD()));
  }

  visual
    withMargin(withCenteredButtons(
      jvsplit(super, dm_printLogComponent()),
      "Compute", rThread compute,
      "Save", rThread saveIt));
}

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: 180 / 631
Version history: 27 change(s)
Referenced in: [show references]