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

59
LINES

< > BotCompany Repo | #1021498 // ai_ruleEngine2_rulesForInput_5 [with line types]

JavaX fragment (include)

// matches first condition, leaves rest in MatchedRule
static L<RuleEngine2_MatchedRule> ai_ruleEngine2_rulesForInput_5(RuleEngine2 engine, SS inputsByType, O... _) {
  bool debug = boolPar debug(_);
  new L<RuleEngine2_MatchedRule> l;
  
  for (RuleEngine2.Rule rule : engine.rules) {
    if (rule cast RuleEngine2.SimplifyWithRule) {
      if (rule.isSplitRule) continue;
      
      // run simplifier
  
      S in = inputsByType.get('standard);
      O f = rule.function();
      if (debug) print("Running simplifier " + rule.globalID + ": " + f);
      O arg = rule.callOnTree ? optPar tree(_) : in;
      if (arg == null) continue;
      O result = f instanceof S
        ? arg instanceof S ? callF(engine.callFunctionOnString, (S) f, arg)
          : callAndMake((S) f, arg)
        : callF(f, arg);
      if (result == null) continue;
      LS list = result instanceof Collection ? allToString((Collection) result) : ll(str(result));
      if (debug) print("Simplifier returned: " + list);
      theLoop: for (S x : list) {
        if (nempty(x) && neq(x, in)) {
          final new RuleEngine2_MatchedRule matched;
          matched.rule = rule;
          matched.out = x;
          matched.inputsByType = inputsByType;

          // call massagers in some dummy way
          // (e.g. for humanOnly test)
          
          for (O massager : unnull(matched.rule.mapMassagers))
            if (callF(massager, new HashMap, null, null, matched) == null) {
              if (debug) print("mapMassager returned null: " + massager);
              continue theLoop;
            }
          
          l.add(matched);
        }
      }
      continue;
    }
    
    // run normal rule
    
    final new RuleEngine2_MatchedRule matched;
    matched.rule = rule;
    matched.inputsByType = inputsByType;
    matched.map = ciMap();
    matched.tokenizationFunction = or(matchAny_firstGroup("tokenize with *", rule.comments), f javaTokNPunctuationWithBrackets);
    matched.outTokenizer = matchAny_firstGroup("tokenize out with *", rule.comments);
    
    if (!ai_ruleEngine2_matchStep(matched, inputsByType, true, _)) continue;
    l.add(matched);
  }
  ret l;
}

Author comment

Began life as a copy of #1021489

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1021498
Snippet name: ai_ruleEngine2_rulesForInput_5 [with line types]
Eternal ID of this version: #1021498/28
Text MD5: ca2e2491ecbf081840b1e12a0550f223
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-11 16:39:42
Source code size: 2226 bytes / 59 lines
Pitched / IR pitched: No / No
Views / Downloads: 422 / 479
Version history: 27 change(s)
Referenced in: [show references]