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

75
LINES

< > BotCompany Repo | #1027758 // New Engine Spike with AllOnAll [OK]

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

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

1  
!include once #1027630 // Msg
2  
3  
replace LogicRule with BasicLogicRule.
4  
5  
cmodule NewEngineSpike > DynPrintLog {
6  
  L<Msg> msgs;
7  
  bool verbose = true, printNonMatches = true;
8  
  transient new Map facts; // facts to trail
9  
  transient AllOnAllWithOperation<LogicRule, O> rulesAndFacts
10  
    = new(lambda2 applyLogicRuleToFact);
11  
12  
  bool step() { ret rulesAndFacts.step(); }
13  
14  
  void addLogicRule(LogicRule rule) {
15  
    if (verbose) print("New rule: " + rule);
16  
    rulesAndFacts.newA(rule);
17  
  }
18  
19  
  void addFact(O fact) { addFact(fact, "external"); }
20  
  
21  
  void addFact(O fact, O trail) {
22  
    if (trail == null) trail = "unknown";
23  
    if (facts.put(fact, trail) != null) ret;
24  
    if (verbose) print("New fact: " + fact);
25  
    rulesAndFacts.newB(fact);
26  
  }
27  
   
28  
  L factsInOrderOfDefinition() { ret rulesAndFacts.cloneBList(); }  
29  
  
30  
  start-thread {
31  
    if (empty(msgs))
32  
      setField(msgs := mainCruddieLog());
33  
    print("Have " + nMessages(msgs));
34  
    pnlStruct(takeFirst(2, msgs));
35  
    L<Msg> msgs2 = whereFieldIsTrue fromUser(msgs);
36  
    for (Msg msg : takeFirst(5, msgs2))
37  
      addFact(ll(msg, Fragment("was understood correctly")));
38  
    addFact(ll(get(msgs2, 5), Fragment("is a wrong recognition")));
39  
40  
    addLogicRule(new LogicRule(
41  
      ll("$x", Fragment("is a wrong recognition")),
42  
      ll("$x", Fragment("should be corrected"))));
43  
    addLogicRule(new LogicRule(
44  
      ll("$x", Fragment("should be corrected")),
45  
      ll("$x", Fragment("is a wrong recognition"))));
46  
47  
    stepAll(lambda0 step);
48  
    print("done. " + nFacts(rulesAndFacts.bList) + ", " + nRules(rulesAndFacts.aList));
49  
  }
50  
51  
  // define what a variable is
52  
  bool isVar(O o) { ret o instanceof S && isDollarVar(o/S); }
53  
54  
  void applyLogicRuleToFact(LogicRule rule, O fact) {
55  
    new LogicRuleApplier ap;
56  
    ap.rule = rule;
57  
    ap.fact = fact;
58  
    ap.verbose = verbose;
59  
    ap.printNonMatches = printNonMatches;
60  
    ap.addRewrittenRHS = lambda2 addRewrittenRHS;
61  
    ap.tools.isVar = lambda1 isVar;
62  
    ap.run();
63  
  }
64  
65  
  void addRewrittenRHS(O o, O trail) {
66  
    if (o cast LogicRule) {
67  
      o.trail = trail;
68  
      addLogicRule(o);
69  
    } else if o is And(O a, O b) {
70  
      addRewrittenRHS(a, o);
71  
      addRewrittenRHS(b, o);
72  
    } else if (o != null)
73  
      addFact(o, trail);
74  
  }
75  
}

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: #1027758
Snippet name: New Engine Spike with AllOnAll [OK]
Eternal ID of this version: #1027758/16
Text MD5: 4760af4968098bb46aabd0fb8ab93dff
Transpilation MD5: 00505f491475079382db7528f070f21b
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-04-10 01:32:21
Source code size: 2310 bytes / 75 lines
Pitched / IR pitched: No / No
Views / Downloads: 143 / 489
Version history: 15 change(s)
Referenced in: [show references]