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

47
LINES

< > BotCompany Repo | #1021688 // gazelle_addHelperTablesToRules

JavaX fragment (include)

1  
scope gazelle_addHelperTablesToRules.
2  
3  
sclass #Massager {
4  
  LL<S> helperTable;
5  
  Map<S, Pair<Int>> helperIndex;
6  
 
7  
  *() {}
8  
  *(LL<S> *helperTable, Map<S, Pair<Int>> *helperIndex) {}
9  
  
10  
  SS get(SS map, LS tokC, LS tokI, RuleEngine2_MatchedRule matched) {
11  
    if (map == null) null;
12  
    //print("Massaging: " + map + " " + sfu(tokC) + " / " + sfu(tokI));
13  
    for (S t : codeTokens(matched.tokenize(matched.rule.out))) {
14  
      //print("Checking: " + t);
15  
      if (map.containsKey(t)) continue;
16  
      Pair<Int> idx = helperIndex.get(t);
17  
      if (idx == null) continue;
18  
      //print("Found: " + t);
19  
      for (S key, val : cloneMap(map)) {
20  
        int idx2 = indexOfIC(helperTable.get(idx.a), key);
21  
        if (idx2 < 0) continue;
22  
        Pair<Int> idxVal = helperIndex.get(val);
23  
        if (idxVal == null) continue;
24  
        S out = _get(_get(helperTable, idxVal.a), idx.b);
25  
        print("Massaged: " + t + " <-> " + key + " => " + out);
26  
        mapPut(map, t, out);
27  
      }
28  
    }
29  
    ret map;
30  
  }
31  
}
32  
33  
svoid gazelle_addHelperTablesToRules(RuleEngine2 engine) {
34  
  new Matches m;
35  
  for (final RuleEngine2.Rule r : engine.rules) {
36  
    continue unless matchAny("use helper table mech list *", r.comments, m);
37  
    LS entries = mL($1);
38  
    continue if empty(entries);
39  
    
40  
    final LL<S> helperTable = map tok_splitAtCommaOrDoubleArrow(entries);
41  
    final Map<S, Pair<Int>> helperIndex = indexTwoDArrayIC(helperTable);
42  
  
43  
    r.addMapMassager(new Massager(helperTable, helperIndex));
44  
  }
45  
}
46  
47  
end scope

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: #1021688
Snippet name: gazelle_addHelperTablesToRules
Eternal ID of this version: #1021688/12
Text MD5: b4cfb9cc9c91451aeed9f60592ca5030
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-02 18:48:00
Source code size: 1540 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 296 / 338
Version history: 11 change(s)
Referenced in: [show references]