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)

static S ctxFindRuleForInput() {
  CtxContext ctx = ctxContext();
  WoodyRule activeRule = woodyBot().getRule(ctx.activeRule);
  WoodyBot bot = woodyBot();
  
  print("ctxFindRuleForInput analyzer: " + ctx.activeAnalyzer);
  if (ctx.activeAnalyzer != null) {
    bool x = ctxProcessRule(ctx.activeAnalyzer);
    print("  -> " + (x ? ctx.nextRule : "no match"));
    if (x)
     ret ctx.nextRule;
  }
  
  if (activeRule != null) {
    print("Active rule: " + activeRule.fullName);
    /*WoodyRule analyzer = bot.getRule(activeRule.properties.get("ANALYZER"));
    print("Analyzer: " + getOpt(analyzer, "fullName"));
    if (analyzer != null) {
      // TODO
    }*/ 
    try answer ctxFindRuleForInput_default();
    ret activeRule.fullName;
  }
  
  ret ctxFindRuleForInput_default();
}
  
sS ctxFindRuleForInput_default() {
  new L<WoodyRule> matchingRules;
  
  for (WoodyRule rule : woodyOnRules(woodyBot()))
    if (rule.parsedCondition != null && rule.parsedCondition.get()) {
      //print("Matching: " + rule.fullName);
      matchingRules.add(rule);
    }
  
  if (empty(matchingRules)) null;
  
  matchingRules = sortByCalculatedFieldDesc(matchingRules, func(WoodyRule rule) { toInt(or(rule.properties.get("PRIORITY"), "100")) });
  
  if (l(matchingRules) > 1)
    print("Have multiple matching rules, picking " + first(matchingRules).fullName + " over " + collect('fullName, dropFirst(matchingRules)));
    
  ret first(matchingRules).fullName;
}

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: 409 / 457
Version history: 18 change(s)
Referenced in: [show references]