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

!include once #1027630 // Msg

replace LogicRule with BasicLogicRule.

cmodule NewEngineSpike > DynPrintLog {
  L<Msg> msgs;
  bool verbose = true, printNonMatches = true;
  transient new Map facts; // facts to trail
  transient AllOnAllWithOperation<LogicRule, O> rulesAndFacts
    = new(lambda2 applyLogicRuleToFact);

  bool step() { ret rulesAndFacts.step(); }

  void addLogicRule(LogicRule rule) {
    if (verbose) print("New rule: " + rule);
    rulesAndFacts.newA(rule);
  }

  void addFact(O fact) { addFact(fact, "external"); }
  
  void addFact(O fact, O trail) {
    if (trail == null) trail = "unknown";
    if (facts.put(fact, trail) != null) ret;
    if (verbose) print("New fact: " + fact);
    rulesAndFacts.newB(fact);
  }
   
  L factsInOrderOfDefinition() { ret rulesAndFacts.cloneBList(); }  
  
  start-thread {
    if (empty(msgs))
      setField(msgs := mainCruddieLog());
    print("Have " + nMessages(msgs));
    pnlStruct(takeFirst(2, msgs));
    L<Msg> msgs2 = whereFieldIsTrue fromUser(msgs);
    for (Msg msg : takeFirst(5, msgs2))
      addFact(ll(msg, Fragment("was understood correctly")));
    addFact(ll(get(msgs2, 5), Fragment("is a wrong recognition")));

    addLogicRule(new LogicRule(
      ll("$x", Fragment("is a wrong recognition")),
      ll("$x", Fragment("should be corrected"))));
    addLogicRule(new LogicRule(
      ll("$x", Fragment("should be corrected")),
      ll("$x", Fragment("is a wrong recognition"))));

    stepAll(lambda0 step);
    print("done. " + nFacts(rulesAndFacts.bList) + ", " + nRules(rulesAndFacts.aList));
  }

  // define what a variable is
  bool isVar(O o) { ret o instanceof S && isDollarVar(o/S); }

  void applyLogicRuleToFact(LogicRule rule, O fact) {
    new LogicRuleApplier ap;
    ap.rule = rule;
    ap.fact = fact;
    ap.verbose = verbose;
    ap.printNonMatches = printNonMatches;
    ap.addRewrittenRHS = lambda2 addRewrittenRHS;
    ap.tools.isVar = lambda1 isVar;
    ap.run();
  }

  void addRewrittenRHS(O o, O trail) {
    if (o cast LogicRule) {
      o.trail = trail;
      addLogicRule(o);
    } else if o is And(O a, O b) {
      addRewrittenRHS(a, o);
      addRewrittenRHS(b, o);
    } else if (o != null)
      addFact(o, trail);
  }
}

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: 140 / 485
Version history: 15 change(s)
Referenced in: [show references]