// 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); 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 iCond=" + matched.iCond + ", insWithType: " + rule.insWithType); if (debug) print("matchStep tokI/tokC: " + codeTokens(tokI) + " / " + codeTokens(tokC)); if (contains(cond, "{}")) tokI = ai_applyWordSplitPattern1(tokC, tokI); map = zipTwoListsToCIMap_strict_withoutEquals(tokC, tokI); } if (debug) print("matchStep map: " + map); if (containsAny(map, rule.dontChangeWords)) false; if (rule.massageMap != null) map = (SS) callF(rule.massageMap, map, tokC, tokI, matched); if (map == null) false; if (!addMapToMapWithoutOverwritingIC(matched.map, map)) { if (debug) print("Adding map failed"); false; } matched.flush(); //print(map + " | " + cond + " | " + rule.vars); 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 qualities = ai_ruleEngine2_mappingQualities(rule); for (S a, b : map) { mapPut(matched.mappingQuality, a, qualities.get(pair(a, b))); } matched.iCond++; true; }