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

71
LINES

< > BotCompany Repo | #1021751 // dm_gazelle_reasonAboutChatInput (OLD, use v2 instead)

JavaX fragment (include)

static L<GazelleTree> dm_gazelle_reasonAboutChatInput(S userName, S content, O... _) {
  bool debug = boolPar debug(_);
  bool selfVarsFix = boolPar selfVarsFix(_, true);
  GazelleEvalContext ctx = optPar ctx(_);
  if (ctx == null) ctx = dm_gazelle_stdEvalContext(dm_gazelle_allRulesWithComment(optPar requiredComment(_, "discord")));
  
  // Need input as first condition
  ctx.engine.dropRulesWhere(r -> cicOneOf(r.comments, "in 1 = statement", "in = statement"));
  if (debug) print("Have rules: " + collect globalID(ctx.engine.rules));
  
  gazelle_addHelperTablesToRules(ctx.engine);
  
  GazelleTree tree1 = new(ctx, content);
  L<GazelleTree> l = dm_gazelle_getChildren(tree1, firstConditionOnly := true);
  
  GazelleTree tree2 = new(ctx, optCurly(userName) + " says: " + content);
  l.addAll(dm_gazelle_getChildren(tree2, firstConditionOnly := true));
  
  if (boolPar skipBad(_, true)) l = [GazelleTree t : l | neq(t.prediction, 'bad)];
  gazelle_sortChildren(l);
  
  for (GazelleTree t : l)
    if (t.rule() != null) {
      RuleEngine2_MatchedRule mr = t.mr;
      LS in = t.rule().in;
      int iCond = t.mr.iCond;
      if (l(in) > iCond) {
        LS conditions = dropFirst(iCond, in);
        print("Remaining conditions for " + t.ruleID() + " with " + t.mr.map + ": " + conditions);
        new Matches m;
        if (!matchAny("in " + (iCond+1) + " = statement *", t.rule().comments, m))
          continue with print("Unwired condition");
        S subRuleID = $1;
        print("Found subrule: " + subRuleID);
        L fulfillments = dm_gazelle_fulfillmentsForRule(subRuleID);
        print("Have fulfillments:");
        for (O f : fulfillments) {
          SS varMap = asCIMap(safeUnstructMap(getString varMap(f)));
          printIndent(sfu(varMap));
          
          // self-vars hack to fix John Doe problem
          if (selfVarsFix) {
            S cond = first(conditions);
            for (S x : identifiersOnly(codeTokens(mr.tokenize(cond))))
              if (!varMap.containsKey(x)) {
                print("Self-linking " + x);
                varMap.put(x, x);
              }
          }
            
          SS newMap = mergeMapsStrictlyIC(asCIMap(t.mr.map), varMap);
          if (newMap == null)
            continue with printIndent("Can't merge maps");
          printIndent("Maps merged! => " + sfu(newMap));
          t.mr.map = newMap;
          t.mr.iCond++;
          t.mr.remainingConditions = dropFirst(t.mr.remainingConditions); // XX: also should rewrite with new vars
          t.mr.remainingConditionsWithType = dropFirst(t.mr.remainingConditionsWithType);
          t.mr.out = null;
          t.line = t.mr.outText();
          print("Rewrote " + t.mr.rule.out + " to: " + t.line);
          break;
        }
      }
    }
    
  // drop unsatisfied entries
  l = [GazelleTree t : l | t.mr == null || !t.mr.moreConditions()];
  
  ret l;
}

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: #1021751
Snippet name: dm_gazelle_reasonAboutChatInput (OLD, use v2 instead)
Eternal ID of this version: #1021751/36
Text MD5: bc023ab7301f18a24cd857324de8cfa7
Author: stefan
Category: javax / discord
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-05 16:39:01
Source code size: 2969 bytes / 71 lines
Pitched / IR pitched: No / No
Views / Downloads: 227 / 328
Version history: 35 change(s)
Referenced in: [show references]