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

50
LINES

< > BotCompany Repo | #1017761 // applyNLLogicFacts_v3

JavaX fragment (include)

static new ThreadLocal<Bool> applyNLLogicFacts_v3_verbose;
static ThreadLocal<VF2<IfThen, NLLogicChecker_v2.Matching>> applyNLLogicFacts_v3_onRuleFired = new ThreadLocal;

svoid applyNLLogicFacts_v3(S input, VF1<Exp> out) {
  applyNLLogicFacts_v3(input, out, mL_facts());
}

svoid applyNLLogicFacts_v3(S input, VF1<Exp> out, LS facts) {
  applyNLLogicFacts_v3(input, out, facts, ai_mL_parsedLogicExamples2());
}

svoid applyNLLogicFacts_v3(S input, VF1<Exp> out, LS facts, L<IfThen> rules) {
  new NLLogicChecker_v3 c;
  c.matcher = new NLStringMatcher_dollarVars;
  addAll(c.facts, facts);
  c.input = input;
  
  applyNLLogicFacts_v3(c, out, rules);
}

svoid applyNLLogicFacts_v3(NLLogicChecker_v2 c, VF1<Exp> vfOut, L<IfThen> rules) {
  VF2<IfThen, NLLogicChecker_v2.Matching> onRuleFired = optParam(applyNLLogicFacts_v3_onRuleFired);
  
  for (IfThen rule : rules) pcall {
    new NLLogicChecker_v2.Matching m;
    m.verbose = isTrue(applyNLLogicFacts_v3_verbose!);
    if (m.verbose)
      print("Checking rule: " + rule);
    if (c.checkRule(rule, m)) {
      if (m.verbose) {
        print("Matched " + quote(c.input) + " with rule " + quote(rule));
        printStruct(m.matches);
      }
      callF(onRuleFired, rule, m);
      
      new SS matches; // matches made in evaluating RHS of rule
      for (Exp out : m.output)
        for (Exp e : nlLogic_unrollAnd(out))
          if (e cast Func)
            callF(vfOut, c.apply(e, m));
          /*else if (e cast Eq) {
            Exp r = e.right;
            S var = nlLogic_text(e.left);
            if (r cast Func)
              if (isStandardFunction(r.name) && r.arg instanceof Sentence && noJavaTokens(nlLogic_text(r.arg)))
                matches.put(var, str(callAndMake(r.name)));
          }*/
    }
  }
}

Author comment

Began life as a copy of #1017652

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017761
Snippet name: applyNLLogicFacts_v3
Eternal ID of this version: #1017761/17
Text MD5: 86506ab54c7ad9aa21e7c75c01e28d53
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-09-16 13:58:16
Source code size: 1827 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 369 / 452
Version history: 16 change(s)
Referenced in: [show references]