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).

1  
!7
2  
3  
cmodule AIPackagesSpike > DynPrintLog {
4  
  S input = [[
5  
    Test
6  
    ----
7  
    
8  
    Fact: A gazelle is fast
9  
    Q: Is a gazelle slow?
10  
    
11  
    A: No
12  
    A: No, it is fast
13  
    A: No, it's fast
14  
    A: No, a gazelle is fast
15  
    A: No, fast
16  
    A: No, it's fast, not slow
17  
18  
    Not an answer: Yes
19  
    
20  
    Example solution
21  
    ----------------
22  
    
23  
    Fact: Fast is not slow
24  
    Rule: Y is not Z => Z is not Y
25  
    Rule: a X is Y & Y is not Z => a X is not Z
26  
    Rule: is X Y? & X is not Y => no
27  
  ]];
28  
29  
  transient PhilosophyBot1 bot;
30  
31  
  start-thread {
32  
    dm_reloadOnFieldChange input();
33  
    SS sections = asCIMap(underlinedHeadingSections(input));
34  
    S testText = sections.get("test");
35  
    S solutionText = sections.get("Example solution");
36  
    
37  
    MultiMap<S> testPairs = parseColonPropertyCIMultiMap(testText);
38  
    MultiMap<S> solutionPairs = parseColonPropertyCIMultiMap(solutionText);
39  
40  
    // ungrouped facts
41  
    Cl<S> facts = concatLists(
42  
      testPairs.get("Fact"),
43  
      testPairs.get("Q"),
44  
      solutionPairs.get("Fact"));
45  
46  
    // get patterns from rules
47  
48  
    Cl<S> rules = solutionPairs.get("Rule");
49  
    pnl("RULES> ", rules);
50  
    bot = new PhilosophyBot1(joinWithEmptyLines(rules));
51  
52  
    // make bot group all facts
53  
    
54  
    bot.parseProgram();
55  
    Cl<S> patterns = philosophyBot_allLHSAsStarPatterns(bot);
56  
    pnl("PATTERN> ", patterns);
57  
    bot.addCodeOnFact(s -> bot.addFacts(dm_topDownParseToGroupings(s, patterns)));
58  
59  
    // add grouped facts to bot, calculate
60  
    
61  
    S program = joinWithEmptyLines(facts);
62  
    printWithIndent("PROGRAM> ", program);
63  
    bot.loadProgram(program);
64  
    bot.run();
65  
66  
    // Check answer
67  
    Set<S> wantedAnswers = mapToCISet dropPunctuation(testPairs.get("A"));
68  
    Set<S> unwantedAnswers = mapToCISet dropPunctuation(testPairs.get("Not an answer"));
69  
    pnl(+wantedAnswers);
70  
    pnl(+unwantedAnswers);
71  
72  
    bool good = listAndSetIntersect(bot.deducedFacts(), wantedAnswers);
73  
    bool bad = listAndSetIntersect(bot.deducedFacts(), unwantedAnswers);
74  
    if (bad) print("BAD answer!"); else if (good) print("OK!"); else print("No answer...");
75  
  }
76  
}

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: 274 / 997
Version history: 25 change(s)
Referenced in: [show references]