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

49
LINES

< > BotCompany Repo | #1018285 // Process Rules BB Spike [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (16513L/123K).

!7

sclass ConstructChecker extends NLLogicChecker_v3 {
  S construct;
  
  bool checkExpression_impl(Exp e, Matching m) {
    if (e cast Func)
      if (eq(e.name, 'construct)) {
        S pat = e.arg.text();
        ret matcher.match(pat, construct, m.matches);
      }
        
    ret super.checkExpression_impl(e, m);
  }
}

static L<IfThen> preprocessRules(L<IfThen> rules) {
  final L<IfThen> metaRules = nlLogic_filterByRHSConstructs(rules, 'construct);
  
  new L<IfThen> newRules;
  for (IfThen rule : rules)
    newRules.add(nlLogic_transformShallow(rule, func(Exp e) -> Exp {
      if (!e instanceof Sentence2) ret e;
      final new ConstructChecker c;
      c.construct = e.text();
      applyNLLogicFacts_v3(c, voidfunc(Exp e) {
        if (e cast Func)
          if (eq(e.name, 'construct))
            c.construct = e.arg.text();
      }, metaRules);
      ret nlLogic_parseExpression(c.construct);
    }));
  ret newRules;   
}

p-exp {
  L<IfThen> rules = ai_parseRulesWithMacros(mL_raw("Rules BB"));
  
  // Meta
  rules = preprocessRules(rules);
  pnl(rules);
  
  // Concrete
  S input = "was kostet der eintritt yo";
  nlLogic_evalExp_verbose = false;
  temp tempSetTL(nlLogic_processInputOrFact_allowUnsafeEvals, true);
  L<ExecutedRule> results = nlLogic_processInputOrFact(input, false, pair(rules, (L<S>) null));
  pnl(nlLogic_outputFromExecutedRules(new LinkedHashSet, results));
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1018285
Snippet name: Process Rules BB Spike [OK]
Eternal ID of this version: #1018285/12
Text MD5: a468f0b09e5bd42777d3db70546f9a93
Transpilation MD5: dd68152de46f7e69c444c979c3741ba4
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-09-15 23:32:05
Source code size: 1457 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 339 / 699
Version history: 11 change(s)
Referenced in: [show references]