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

76
LINES

< > BotCompany Repo | #1027383 // "AI Packages" Spike [OK, see video]

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

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

!7

cmodule AIPackagesSpike > DynPrintLog {
  S input = [[
    Test
    ----
    
    Fact: A gazelle is fast
    Q: Is a gazelle slow?
    
    A: No
    A: No, it is fast
    A: No, it's fast
    A: No, a gazelle is fast
    A: No, fast
    A: No, it's fast, not slow

    Not an answer: Yes
    
    Example solution
    ----------------
    
    Fact: Fast is not slow
    Rule: Y is not Z => Z is not Y
    Rule: a X is Y & Y is not Z => a X is not Z
    Rule: is X Y? & X is not Y => no
  ]];

  transient PhilosophyBot1 bot;

  start-thread {
    dm_reloadOnFieldChange input();
    SS sections = asCIMap(underlinedHeadingSections(input));
    S testText = sections.get("test");
    S solutionText = sections.get("Example solution");
    
    MultiMap<S> testPairs = parseColonPropertyCIMultiMap(testText);
    MultiMap<S> solutionPairs = parseColonPropertyCIMultiMap(solutionText);

    // ungrouped facts
    Cl<S> facts = concatLists(
      testPairs.get("Fact"),
      testPairs.get("Q"),
      solutionPairs.get("Fact"));

    // get patterns from rules

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

    // 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) print("BAD answer!"); else if (good) print("OK!"); else print("No answer...");
  }
}

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: #1027383
Snippet name: "AI Packages" Spike [OK, see video]
Eternal ID of this version: #1027383/26
Text MD5: e4c2403f88d1a04a11a984d99b1aaacf
Transpilation MD5: 7d2d777a3ed822d152d19db8c7fe9525
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-17 00:41:46
Source code size: 2170 bytes / 76 lines
Pitched / IR pitched: No / No
Views / Downloads: 272 / 993
Version history: 25 change(s)
Referenced in: [show references]