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

45
LINES

< > BotCompany Repo | #1008922 // ctxFindRuleForInput (according to context)

JavaX fragment (include)

1  
static S ctxFindRuleForInput() {
2  
  CtxContext ctx = ctxContext();
3  
  WoodyRule activeRule = woodyBot().getRule(ctx.activeRule);
4  
  WoodyBot bot = woodyBot();
5  
  
6  
  print("ctxFindRuleForInput analyzer: " + ctx.activeAnalyzer);
7  
  if (ctx.activeAnalyzer != null) {
8  
    bool x = ctxProcessRule(ctx.activeAnalyzer);
9  
    print("  -> " + (x ? ctx.nextRule : "no match"));
10  
    if (x)
11  
     ret ctx.nextRule;
12  
  }
13  
  
14  
  if (activeRule != null) {
15  
    print("Active rule: " + activeRule.fullName);
16  
    /*WoodyRule analyzer = bot.getRule(activeRule.properties.get("ANALYZER"));
17  
    print("Analyzer: " + getOpt(analyzer, "fullName"));
18  
    if (analyzer != null) {
19  
      // TODO
20  
    }*/ 
21  
    try answer ctxFindRuleForInput_default();
22  
    ret activeRule.fullName;
23  
  }
24  
  
25  
  ret ctxFindRuleForInput_default();
26  
}
27  
  
28  
sS ctxFindRuleForInput_default() {
29  
  new L<WoodyRule> matchingRules;
30  
  
31  
  for (WoodyRule rule : woodyOnRules(woodyBot()))
32  
    if (rule.parsedCondition != null && rule.parsedCondition.get()) {
33  
      //print("Matching: " + rule.fullName);
34  
      matchingRules.add(rule);
35  
    }
36  
  
37  
  if (empty(matchingRules)) null;
38  
  
39  
  matchingRules = sortByCalculatedFieldDesc(matchingRules, func(WoodyRule rule) { toInt(or(rule.properties.get("PRIORITY"), "100")) });
40  
  
41  
  if (l(matchingRules) > 1)
42  
    print("Have multiple matching rules, picking " + first(matchingRules).fullName + " over " + collect('fullName, dropFirst(matchingRules)));
43  
    
44  
  ret first(matchingRules).fullName;
45  
}

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: #1008922
Snippet name: ctxFindRuleForInput (according to context)
Eternal ID of this version: #1008922/19
Text MD5: 5e469e2dd1df88da19382dca2136f978
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-14 20:20:35
Source code size: 1502 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 414 / 462
Version history: 18 change(s)
Referenced in: [show references]