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

45
LINES

< > BotCompany Repo | #1027748 // New Engine Spike with logic rule [dev.]

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

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

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  
  
9  
  start-thread {
10  
    if (empty(msgs))
11  
      setField(msgs := mainCruddieLog());
12  
    print("Have " + nMessages(msgs));
13  
    pnlStruct(takeFirst(2, msgs));
14  
    L<Msg> msgs2 = whereFieldIsTrue fromUser(msgs);
15  
    new L props;
16  
    for (Msg msg : takeFirst(5, msgs2))
17  
      print(addAndReturn(props, ll(msg, "was understood correctly")));
18  
    props.add(print(ll(get(msgs2, 5), "is a wrong recognition")));
19  
20  
    LogicRule rule = new(
21  
      ll("$x", "is a wrong recognition"),
22  
      ll("$x", "should be corrected"));
23  
24  
    for (O prop : props)
25  
      applyLogicRuleToFact(rule, prop);
26  
  }
27  
28  
  // define what a variable is
29  
  bool isVar(O o) { ret o instanceof S && isDollarVar(o/S); }
30  
31  
  void applyLogicRuleToFact(LogicRule rule, O fact) {
32  
    new LogicRuleApplier ap;
33  
    ap.rule = rule;
34  
    ap.fact = fact;
35  
    ap.verbose = verbose;
36  
    ap.printNonMatches = printNonMatches;
37  
    ap.addRewrittenRHS = lambda2 addRewrittenRHS;
38  
    ap.tools.isVar = lambda1 isVar;
39  
    ap.run();
40  
  }
41  
42  
  void addRewrittenRHS(O rhs, O trail) {
43  
    print("Derived: " + rhs);
44  
  }
45  
}

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: #1027748
Snippet name: New Engine Spike with logic rule [dev.]
Eternal ID of this version: #1027748/14
Text MD5: 3a7c646bf43b67212e9aff13fe58064f
Transpilation MD5: e362c99b624fc193710c85695133d869
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 00:29:38
Source code size: 1221 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 111 / 491
Version history: 13 change(s)
Referenced in: [show references]