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

1  
!7
2  
3  
sclass ConstructChecker extends NLLogicChecker_v3 {
4  
  S construct;
5  
  
6  
  bool checkExpression_impl(Exp e, Matching m) {
7  
    if (e cast Func)
8  
      if (eq(e.name, 'construct)) {
9  
        S pat = e.arg.text();
10  
        ret matcher.match(pat, construct, m.matches);
11  
      }
12  
        
13  
    ret super.checkExpression_impl(e, m);
14  
  }
15  
}
16  
17  
static L<IfThen> preprocessRules(L<IfThen> rules) {
18  
  final L<IfThen> metaRules = nlLogic_filterByRHSConstructs(rules, 'construct);
19  
  
20  
  new L<IfThen> newRules;
21  
  for (IfThen rule : rules)
22  
    newRules.add(nlLogic_transformShallow(rule, func(Exp e) -> Exp {
23  
      if (!e instanceof Sentence2) ret e;
24  
      final new ConstructChecker c;
25  
      c.construct = e.text();
26  
      applyNLLogicFacts_v3(c, voidfunc(Exp e) {
27  
        if (e cast Func)
28  
          if (eq(e.name, 'construct))
29  
            c.construct = e.arg.text();
30  
      }, metaRules);
31  
      ret nlLogic_parseExpression(c.construct);
32  
    }));
33  
  ret newRules;   
34  
}
35  
36  
p-exp {
37  
  L<IfThen> rules = ai_parseRulesWithMacros(mL_raw("Rules BB"));
38  
  
39  
  // Meta
40  
  rules = preprocessRules(rules);
41  
  pnl(rules);
42  
  
43  
  // Concrete
44  
  S input = "was kostet der eintritt yo";
45  
  nlLogic_evalExp_verbose = false;
46  
  temp tempSetTL(nlLogic_processInputOrFact_allowUnsafeEvals, true);
47  
  L<ExecutedRule> results = nlLogic_processInputOrFact(input, false, pair(rules, (L<S>) null));
48  
  pnl(nlLogic_outputFromExecutedRules(new LinkedHashSet, results));
49  
}

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: 351 / 717
Version history: 11 change(s)
Referenced in: [show references]