1 | sclass RuleEngine2_MatchedRule { |
2 | RuleEngine2.Rule rule; |
3 | Map<TokenAndRange, S> map; |
4 | new Map<S, Int> mappingQuality; // key in map to -1, 0 or 1 |
5 | new LPair<LS> matchedLines; |
6 | O tokenizationFunction; |
7 | |
8 | int qualitySum() { |
9 | ret intSum(values(mappingQuality))-l(map); |
10 | } |
11 | |
12 | RuleEngine2.Rule applyMapping() { |
13 | new RuleEngine2.Rule r; |
14 | r.in = map(rule.in, f<S, S> applyMappingTo); |
15 | r.out = applyMappingTo(rule.out); |
16 | ret r; |
17 | } |
18 | |
19 | S applyMappingTo(S s) { |
20 | ret s == null ? null : join(ai_mapCodeTokensWithMap(tokenize(s), map)); |
21 | } |
22 | |
23 | LS tokenize(S s) { |
24 | ret (LS) callF(assertNotNull(tokenizationFunction), s); |
25 | } |
26 | } |
27 | |
28 | static L<RuleEngine2_MatchedRule> ai_ruleEngine2_rulesForInput_3b(RuleEngine2 engine, S q) { |
29 | S tokenize = f javaTokNPunctuationWithBrackets; |
30 | LS tokI = (LS) callF(tokenize, q); |
31 | new L<RuleEngine2_MatchedRule> l; |
32 | for (RuleEngine2.Rule rule : engine.rules) { |
33 | S cond = first(rule.in); |
34 | LS tokC = (LS) callF(tokenize, cond); |
35 | Map<TokenAndRange, S> map = ai_matchTwoTokenizations(tokC, tokI); |
36 | if (map == null) continue; |
37 | new RuleEngine2_MatchedRule matched; |
38 | matched.rule = rule; |
39 | matched.map = map; |
40 | matched.matchedLines.add(pair(tokC, tokI)); |
41 | matched.tokenizationFunction = tokenize; |
42 | Map<PairS, Int> qualities = ai_ruleEngine2_mappingQualities(rule); |
43 | for (S a, b : map) { |
44 | mapPut(matched.mappingQuality, a, qualities.get(pair(a, b))); |
45 | } |
46 | l.add(matched); |
47 | } |
48 | ret l; |
49 | } |
Began life as a copy of #1021405
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: | #1021410 |
Snippet name: | ai_ruleEngine2_rulesForInput_3b [abandoned] |
Eternal ID of this version: | #1021410/5 |
Text MD5: | f66be6d89c0e7b5751ab70c6faa182c6 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-02-15 04:35:28 |
Source code size: | 1518 bytes / 49 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 267 / 302 |
Version history: | 4 change(s) |
Referenced in: | [show references] |