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

49
LINES

< > BotCompany Repo | #1012905 // je_checkRule

JavaX fragment (include)

1  
static new ThreadLocal<Bool> je_checkRule_debug;
2  
3  
static bool je_checkRule(L<JE_CascadeEntry> rule) {
4  
  try {
5  
    ret je_checkRule_impl(rule);
6  
  } catch e {
7  
    printShortOrLongException(e, isTrue(je_checkRule_debug!));
8  
  }
9  
  false;
10  
}
11  
12  
static bool je_checkRule_impl(L<JE_CascadeEntry> rule) {
13  
  bool debug = isTrue(je_checkRule_debug!);
14  
  for (JE_CascadeEntry e : rule) {
15  
    if (eqicOneOf(e.op, "if", "and")) {
16  
      if (e.java) {
17  
        // direct match on input with: if "bla"
18  
        if (l(e.tok) == 3 && isQuoted(get(e.tok, 1))) {
19  
          S input = (S) ai_getVar("#input");
20  
          S pat = unquote(get(e.tok, 1));
21  
          if (!eqic(input, pat)) {
22  
            debug print "Rule fail on input: " + pat + " / " + input;
23  
            false;
24  
          }
25  
        } else {
26  
          O result = safeInterpretedJavaEval(e.tok);
27  
          if (!isTrue_able(result))
28  
            fail("Weird result type of function " + join(e.tok) + ": " + (result instanceof S ? quote((S) result) : className(result)));
29  
          if (!isTrue(result)) {
30  
            debug print "Rule fail on Java: " + join(e.tok);
31  
            false;
32  
          }
33  
        }
34  
      } else {
35  
        L<S> tok = tok_withoutOuterBrackets(e.tok);
36  
        T3<S> t = ai_tripelizeOrParseTriple(join(tok));
37  
        if (!has(t)) {
38  
          debug print "Rule fail on triple: " + ai_renderTriple(t);
39  
          false;
40  
        }
41  
      }
42  
    } else if (eqic(e.op, "then"))
43  
      break;
44  
    else
45  
      fail("Unsupported operator: " + e.op);
46  
  }
47  
  debug print "Rule hit";
48  
  true;
49  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1012905
Snippet name: je_checkRule
Eternal ID of this version: #1012905/12
Text MD5: d26882b38ae85f3367ed45a3eb2d0058
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-12-18 19:08:13
Source code size: 1575 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 373 / 416
Version history: 11 change(s)
Referenced in: [show references]