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

49
LINES

< > BotCompany Repo | #1021410 // ai_ruleEngine2_rulesForInput_3b [abandoned]

JavaX fragment (include)

sclass RuleEngine2_MatchedRule {
  RuleEngine2.Rule rule;
  Map<TokenAndRange, S> map;
  new Map<S, Int> mappingQuality; // key in map to -1, 0 or 1
  new LPair<LS> matchedLines;
  O tokenizationFunction;
  
  int qualitySum() {
    ret intSum(values(mappingQuality))-l(map);
  }
  
  RuleEngine2.Rule applyMapping() {
    new RuleEngine2.Rule r;
    r.in = map(rule.in, f<S, S> applyMappingTo);
    r.out = applyMappingTo(rule.out);
    ret r;
  }
  
  S applyMappingTo(S s) {
    ret s == null ? null : join(ai_mapCodeTokensWithMap(tokenize(s), map));
  }
  
  LS tokenize(S s) {
    ret (LS) callF(assertNotNull(tokenizationFunction), s);
  }
}

static L<RuleEngine2_MatchedRule> ai_ruleEngine2_rulesForInput_3b(RuleEngine2 engine, S q) {
  S tokenize = f javaTokNPunctuationWithBrackets;
  LS tokI = (LS) callF(tokenize, q);
  new L<RuleEngine2_MatchedRule> l;
  for (RuleEngine2.Rule rule : engine.rules) {
    S cond = first(rule.in);
    LS tokC = (LS) callF(tokenize, cond);
    Map<TokenAndRange, S> map = ai_matchTwoTokenizations(tokC, tokI);
    if (map == null) continue;
    new RuleEngine2_MatchedRule matched;
    matched.rule = rule;
    matched.map = map;
    matched.matchedLines.add(pair(tokC, tokI));
    matched.tokenizationFunction = tokenize;
    Map<PairS, Int> qualities = ai_ruleEngine2_mappingQualities(rule);
    for (S a, b : map) {
      mapPut(matched.mappingQuality, a, qualities.get(pair(a, b)));
    }
    l.add(matched);
  }
  ret l;
}

Author comment

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: 265 / 299
Version history: 4 change(s)
Referenced in: [show references]