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

64
LINES

< > BotCompany Repo | #1021683 // Rule with helper table Spike [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (16910L/97K).

1  
!7
2  
3  
sS data = [[
4  
5  
  -- Rule
6  
  
7  
  What does a driver do? => He drives, dummie.
8  
  
9  
  -- Test
10  
  
11  
  What does a catcher do? => He catches, dummie.
12  
  
13  
  -- Helper Table
14  
  
15  
  driver, drive, drives, driving
16  
  sleeper, sleep, sleeps, sleeping
17  
  murderer, murder, murders, murdering
18  
  catcher, catch, catches, catching
19  
20  
]];
21  
22  
p-exp {
23  
  SS sections = minusSignSectionsCI(data);
24  
  pnlStruct(sections);
25  
  
26  
  LPair<S> rules = ai_findDoubleArrowRulesAsPairs(sections.get("Rule"));
27  
  GazelleEvalContext ctx = gazelle_stdEvalContext(map(rules, func(PairS inOut) -> T3<S> {
28  
    t3(joinPairWithDoubleArrow(inOut), "", aGlobalID())
29  
  }));
30  
  pnlStruct(ctx.engine.rules);
31  
  
32  
  final LL<S> helperTable = map tok_splitAtComma(tlft(sections.get("Helper Table")));
33  
  //pnlStruct(helperTable);
34  
  final Map<S, Pair<Int>> helperIndex = indexTwoDArrayIC(helperTable);
35  
  
36  
  final RuleEngine2.Rule rule = first(ctx.engine.rules);
37  
  rule.massageMap = func(SS map, LS tokC, LS tokI, RuleEngine2_MatchedRule matched) -> SS {
38  
    print("Massaging: " + map + " " + sfu(tokC) + " / " + sfu(tokI));
39  
    for (S t : codeTokens(matched.tokenize(rule.out))) {
40  
      //print("Checking: " + t);
41  
      if (map.containsKey(t)) continue;
42  
      Pair<Int> idx = helperIndex.get(t);
43  
      if (idx == null) continue;
44  
      //print("Found: " + t);
45  
      for (S key, val : cloneMap(map)) {
46  
        int idx2 = indexOfIC(helperTable.get(idx.a), key);
47  
        if (idx2 < 0) continue;
48  
        Pair<Int> idxVal = helperIndex.get(val);
49  
        print("Found: " + t + " <-> " + key);
50  
        mapPut(map, t, _get(_get(helperTable, idxVal.a), idx.b));
51  
      }
52  
    }
53  
    ret map;
54  
  };
55  
  
56  
  new LS out;
57  
  for (PairS inOut : ai_findDoubleArrowRulesAsPairs(sections.get("Test"))) {
58  
    nlPrintNL(inOut.a);
59  
    out.addAll(collect line(pnl(gazelle_getChildren(GazelleTree(ctx, inOut.a)))));
60  
  }
61  
  
62  
  assertContainsIC(out, "He catches, dummie.");
63  
  print("OK!");
64  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1021683
Snippet name: Rule with helper table Spike [OK]
Eternal ID of this version: #1021683/24
Text MD5: 8230d100a71f3c83d8eb6b352b488ef2
Transpilation MD5: 0f7901d6e20817f58d95b1b0b1ce8679
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-02-24 14:09:28
Source code size: 1958 bytes / 64 lines
Pitched / IR pitched: No / No
Views / Downloads: 383 / 1138
Version history: 23 change(s)
Referenced in: [show references]