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)

1  
static L<GazelleTree> dm_gazelle_reasonAboutChatInput(S userName, S content, O... _) {
2  
  bool debug = boolPar debug(_);
3  
  bool selfVarsFix = boolPar selfVarsFix(_, true);
4  
  GazelleEvalContext ctx = optPar ctx(_);
5  
  if (ctx == null) ctx = dm_gazelle_stdEvalContext(dm_gazelle_allRulesWithComment(optPar requiredComment(_, "discord")));
6  
  
7  
  // Need input as first condition
8  
  ctx.engine.dropRulesWhere(r -> cicOneOf(r.comments, "in 1 = statement", "in = statement"));
9  
  if (debug) print("Have rules: " + collect globalID(ctx.engine.rules));
10  
  
11  
  gazelle_addHelperTablesToRules(ctx.engine);
12  
  
13  
  GazelleTree tree1 = new(ctx, content);
14  
  L<GazelleTree> l = dm_gazelle_getChildren(tree1, firstConditionOnly := true);
15  
  
16  
  GazelleTree tree2 = new(ctx, optCurly(userName) + " says: " + content);
17  
  l.addAll(dm_gazelle_getChildren(tree2, firstConditionOnly := true));
18  
  
19  
  if (boolPar skipBad(_, true)) l = [GazelleTree t : l | neq(t.prediction, 'bad)];
20  
  gazelle_sortChildren(l);
21  
  
22  
  for (GazelleTree t : l)
23  
    if (t.rule() != null) {
24  
      RuleEngine2_MatchedRule mr = t.mr;
25  
      LS in = t.rule().in;
26  
      int iCond = t.mr.iCond;
27  
      if (l(in) > iCond) {
28  
        LS conditions = dropFirst(iCond, in);
29  
        print("Remaining conditions for " + t.ruleID() + " with " + t.mr.map + ": " + conditions);
30  
        new Matches m;
31  
        if (!matchAny("in " + (iCond+1) + " = statement *", t.rule().comments, m))
32  
          continue with print("Unwired condition");
33  
        S subRuleID = $1;
34  
        print("Found subrule: " + subRuleID);
35  
        L fulfillments = dm_gazelle_fulfillmentsForRule(subRuleID);
36  
        print("Have fulfillments:");
37  
        for (O f : fulfillments) {
38  
          SS varMap = asCIMap(safeUnstructMap(getString varMap(f)));
39  
          printIndent(sfu(varMap));
40  
          
41  
          // self-vars hack to fix John Doe problem
42  
          if (selfVarsFix) {
43  
            S cond = first(conditions);
44  
            for (S x : identifiersOnly(codeTokens(mr.tokenize(cond))))
45  
              if (!varMap.containsKey(x)) {
46  
                print("Self-linking " + x);
47  
                varMap.put(x, x);
48  
              }
49  
          }
50  
            
51  
          SS newMap = mergeMapsStrictlyIC(asCIMap(t.mr.map), varMap);
52  
          if (newMap == null)
53  
            continue with printIndent("Can't merge maps");
54  
          printIndent("Maps merged! => " + sfu(newMap));
55  
          t.mr.map = newMap;
56  
          t.mr.iCond++;
57  
          t.mr.remainingConditions = dropFirst(t.mr.remainingConditions); // XX: also should rewrite with new vars
58  
          t.mr.remainingConditionsWithType = dropFirst(t.mr.remainingConditionsWithType);
59  
          t.mr.out = null;
60  
          t.line = t.mr.outText();
61  
          print("Rewrote " + t.mr.rule.out + " to: " + t.line);
62  
          break;
63  
        }
64  
      }
65  
    }
66  
    
67  
  // drop unsatisfied entries
68  
  l = [GazelleTree t : l | t.mr == null || !t.mr.moreConditions()];
69  
  
70  
  ret l;
71  
}

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: 230 / 330
Version history: 35 change(s)
Referenced in: [show references]