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

50
LINES

< > BotCompany Repo | #1018082 // nlLogic_evalExp

JavaX fragment (include)

1  
sbool nlLogic_evalExp_verbose = true;
2  
3  
static O nlLogic_evalExp(final NLLogicChecker_v2 c, Exp e, NLLogicChecker_v2.Matching m) {
4  
  ret nlLogic_evalExp(c, e.text(), m);
5  
}
6  
7  
static O nlLogic_evalExp(final NLLogicChecker_v2 c, S code, NLLogicChecker_v2.Matching m) {
8  
  // prepare context
9  
  final SS vars = m.matches;
10  
  temp tempSetTL(ai_context_tl(), new O {
11  
    LS getList(S var) {
12  
      int i = 1;
13  
      S s;
14  
      new LS l;
15  
      while ((s = vars.get(var + i++)) != null)
16  
        l.add(s);
17  
      ret l;
18  
    }
19  
    
20  
    IfThen getRule(S id) {
21  
      ret findByField(c.rules, globalID := id);
22  
    }
23  
  });
24  
25  
  if (nlLogic_evalExp_verbose) print("Eval'ing: " + code);
26  
  temp tempAdd(hotwire_copyOver_after, voidfunc(Class c) {
27  
    copyFields(mc(), c, ai_staticVars())
28  
  });
29  
  O result = null;
30  
  pcall {
31  
    temp tempSetTL(evalJava_prep2_useCacheInThread, true);
32  
    temp tempSetTL(evalJava_prep_voidMagic, false);
33  
    Pair<LS, O> p = prepareEvalWithDollarVars_assertAllVarsSet(code, m.matches);
34  
    
35  
    // Accomodate ai_isTrue
36  
    if (hasField(p.b, 'ai_isTrue_f))
37  
      set(p.b, 'ai_isTrue_f := func(S s) -> bool { nlLogic_matchAnyFact(c, s, new NLLogicChecker_v2.Matching()) });
38  
      
39  
    // Accomodate ai_input
40  
    if (c.input != null) {
41  
      ThreadLocal tl_vars = cast getOpt(p.b, 'ai_getVar_map);
42  
      if (tl_vars != null)
43  
        tl_vars.set(litmap("#input" := c.input));
44  
    }
45  
      
46  
    result = evalWithDollarVars_step2(p, m.matches);
47  
  }
48  
  if (nlLogic_evalExp_verbose) print("  eval => " + shorten(str(result), 100));
49  
  ret result;
50  
}

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: #1018082
Snippet name: nlLogic_evalExp
Eternal ID of this version: #1018082/17
Text MD5: 21be5c0506a8a447f0fb8782d9691b39
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-19 22:00:15
Source code size: 1588 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 295 / 358
Version history: 16 change(s)
Referenced in: [show references]