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.

1  
// true if successful
2  
// only call if there are more conditions
3  
sbool ai_ruleEngine2_matchStep(final RuleEngine2_MatchedRule matched, SS inputsByType, bool fillRemainingConditions, O... _) {
4  
  bool debug = boolPar debug(_);
5  
  RuleEngine2.Rule rule = matched.rule;
6  
  TextAndType in = rule.insWithType.get(matched.iCond);
7  
  S input = inputsByType.get(in.type);
8  
  if (input == null) false;
9  
  O inputMassager = get(rule.inputMassagers, matched.iCond);
10  
  O checkerFunction = get(rule.checkerFunctions, matched.iCond);
11  
  O matcher = get(rule.matchers, matched.iCond);
12  
  LS tokC = null, tokI = null;
13  
  SS map;
14  
  
15  
  if (inputMassager != null) {
16  
    input = (S) callF(inputMassager, input);
17  
    if (debug) print("Massaged input to: " + input);
18  
    if (input == null) false;
19  
  }
20  
  
21  
  if (checkerFunction != null)
22  
    map = (SS) callF(checkerFunction, input);
23  
  else {
24  
    S cond = in.text;
25  
    S tokenize = matched.tokenizationFunction;
26  
    tokC = (LS) callAndMake(tokenize, cond);
27  
    tokI = (LS) callAndMake(tokenize, input);
28  
    if (debug) print("matchStep inputsByType=" + sfu(asTreeMap(inputsByType)));
29  
    if (debug) print("matchStep in=" + in + ", iCond=" + matched.iCond + ", insWithType: " + rule.insWithType);
30  
    if (debug) print("matchStep tokI/tokC: " + codeTokens(tokI) + " / " + codeTokens(tokC));
31  
    if (contains(cond, "{}")) tokI = ai_applyWordSplitPattern1(tokC, tokI);
32  
    if (matcher != null)
33  
      map = (SS) callF(matcher, tokC, tokI, matched);
34  
    else
35  
      map = zipCodeTokensToCIMap_strict_withoutEquals(tokC, tokI);
36  
  }
37  
  
38  
  if (debug) print("matchStep for rule " + rule.globalID + " map: " + map);
39  
  if (!gazelle_addMatch(matched, map, tokC, tokI, _)) {
40  
    if (debug) print("addMatch failed - " + strWithIdentityHashCode(matched));
41  
    false;
42  
  }
43  
44  
  matched.iCond++; // XXX - used to be at end of method
45  
  if (debug) print("matchStep succeeded. " + matched);
46  
  
47  
  matched.matchedLines.add(pair(tokC, tokI));
48  
  if (fillRemainingConditions) {
49  
    matched.remainingConditions = nullIfEmpty(map(dropFirst(matched.iCond, rule.in), func(S s) -> S { matched.applyMappingTo(s) }));
50  
    matched.remainingConditionsWithType = nullIfEmpty(map(dropFirst(matched.iCond, rule.insWithType), func(TextAndType in) -> TextAndType { TextAndType(matched.applyMappingTo(in.text), in.type) }));
51  
  }
52  
  Map<PairS, Int> qualities = ai_ruleEngine2_mappingQualities(rule);
53  
  for (S a, b : map) {
54  
    mapPut(matched.mappingQuality, a, qualities.get(pair(a, b)));
55  
  }
56  
  if (debug) print("iCond now=" + matched.iCond + ", next input: " + get(matched.rule.insWithType, matched.iCond));
57  
  true;
58  
}

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: 380 / 479
Version history: 38 change(s)
Referenced in: [show references]