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

58
LINES

< > BotCompany Repo | #1021499 // ai_ruleEngine2_matchStep

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (10640L) is out of date.

// true if successful
// only call if there are more conditions
sbool ai_ruleEngine2_matchStep(final RuleEngine2_MatchedRule matched, SS inputsByType, bool fillRemainingConditions, O... _) {
  bool debug = boolPar debug(_);
  RuleEngine2.Rule rule = matched.rule;
  TextAndType in = rule.insWithType.get(matched.iCond);
  S input = inputsByType.get(in.type);
  if (input == null) false;
  O inputMassager = get(rule.inputMassagers, matched.iCond);
  O checkerFunction = get(rule.checkerFunctions, matched.iCond);
  O matcher = get(rule.matchers, matched.iCond);
  LS tokC = null, tokI = null;
  SS map;
  
  if (inputMassager != null) {
    input = (S) callF(inputMassager, input);
    if (debug) print("Massaged input to: " + input);
    if (input == null) false;
  }
  
  if (checkerFunction != null)
    map = (SS) callF(checkerFunction, input);
  else {
    S cond = in.text;
    S tokenize = matched.tokenizationFunction;
    tokC = (LS) callAndMake(tokenize, cond);
    tokI = (LS) callAndMake(tokenize, input);
    if (debug) print("matchStep inputsByType=" + sfu(asTreeMap(inputsByType)));
    if (debug) print("matchStep in=" + in + ", iCond=" + matched.iCond + ", insWithType: " + rule.insWithType);
    if (debug) print("matchStep tokI/tokC: " + codeTokens(tokI) + " / " + codeTokens(tokC));
    if (contains(cond, "{}")) tokI = ai_applyWordSplitPattern1(tokC, tokI);
    if (matcher != null)
      map = (SS) callF(matcher, tokC, tokI, matched);
    else
      map = zipCodeTokensToCIMap_strict_withoutEquals(tokC, tokI);
  }
  
  if (debug) print("matchStep for rule " + rule.globalID + " map: " + map);
  if (!gazelle_addMatch(matched, map, tokC, tokI, _)) {
    if (debug) print("addMatch failed - " + strWithIdentityHashCode(matched));
    false;
  }

  matched.iCond++; // XXX - used to be at end of method
  if (debug) print("matchStep succeeded. " + matched);
  
  matched.matchedLines.add(pair(tokC, tokI));
  if (fillRemainingConditions) {
    matched.remainingConditions = nullIfEmpty(map(dropFirst(matched.iCond, rule.in), func(S s) -> S { matched.applyMappingTo(s) }));
    matched.remainingConditionsWithType = nullIfEmpty(map(dropFirst(matched.iCond, rule.insWithType), func(TextAndType in) -> TextAndType { TextAndType(matched.applyMappingTo(in.text), in.type) }));
  }
  Map<PairS, Int> qualities = ai_ruleEngine2_mappingQualities(rule);
  for (S a, b : map) {
    mapPut(matched.mappingQuality, a, qualities.get(pair(a, b)));
  }
  if (debug) print("iCond now=" + matched.iCond + ", next input: " + get(matched.rule.insWithType, matched.iCond));
  true;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1021499
Snippet name: ai_ruleEngine2_matchStep
Eternal ID of this version: #1021499/39
Text MD5: 44410d88c6de29f74766b4e2f4beb652
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-17 12:01:58
Source code size: 2641 bytes / 58 lines
Pitched / IR pitched: No / No
Views / Downloads: 468 / 583
Version history: 38 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)