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

105
LINES

< > BotCompany Repo | #1021773 // dm_gazelle_reasonAboutChatInput_v2 - with multiple input lines (LIVE)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (18571L/107K).

static L<GazelleTree> dm_gazelle_reasonAboutChatInput_v2(S userName, S content, O... _) {
  // GATHER PARAMETERS & CONTEXT
  
  bool debug = boolPar debug(_);
  bool debugRules = boolPar debugRules(_) || debug;
  LS preContext = cast optPar preContext(_);
  GazelleEvalContext ctx = cast optPar ctx(_);
  F0<GazelleEvalContext> contextMaker = cast optPar contextMaker(_);
  if (debugRules) print("Have ctx: " + (ctx != null) + ", contextMaker: " + (contextMaker != null));
  if (ctx == null && contextMaker != null) {
    ctx = contextMaker!;
    if (debugRules) print("Called contextMaker, got " + nRules(ctx.engine.rules));
  }
  if (ctx == null) ctx = dm_gazelle_stdEvalContext(dm_gazelle_allRulesWithComment(optPar requiredComment(_, "discord")));
  Set<S> acceptablePurposes = cast optPar acceptablePurposes(_);

  if (debug)
    print(" == PROCESSING INPUT: " + content);
    
  // PREPARE RULES
    
  // Need input as first condition
  gazelle_dropRulesNotOnInput(ctx);
  
  if (acceptablePurposes != null) {
    if (debugRules) {
      print("Purposes: " + acceptablePurposes);
      print("Have purposes: " + collectUnique purpose(ctx.engine.rules));
    }
    int nBefore = l(ctx.engine.rules);
    ctx.engine.dropRulesWhere(r -> !acceptablePurposes.contains(unnull(r.purpose)));
    if (debugRules) print("Retaining " + n2(ctx.engine.rules, "rule") + " of " + nBefore);
  }
    
  if (debugRules) print("Have rules: " + collect globalID(ctx.engine.rules));
  
  gazelle_addHelpers(ctx, _);
  
  // MAKE PARAMETERS
  
  O[] params = paramsPlus(paramsMinus(_, 'ctx),
    firstConditionOnly := true,
    dialogHistory := preContext);
    
  // TREE1 (just input)
  
  GazelleTree tree1 = cast optPar tree(_);
  if (tree1 == null) tree1 = GazelleTree(ctx, content);
  L<GazelleTree> l = gazelle_getChildren_withContinuations(tree1, params);
  
  // TREE2 (user says: ...)
  
  if (nempty(userName) && !boolPar skipUserName(_)) {
    GazelleTree tree2 = new(ctx, optCurly(userName) + " says: " + content);
    if (debug) print("Tree2: " + tree2);
    l.addAll(gazelle_getChildren_withContinuations(tree2, paramsPlus(_, tree2 := true)));
  }
  
  // TREE3 (user with id x says: ...)
  
  Long userID = cast optPar userID(_);
  
  if (userID != null && userID != 0 && !boolPar skipUserID(_)) {
    GazelleTree tree3 = new(ctx, "user with id " + userID + " says: " + content);
    l.addAll(gazelle_getChildren_withContinuations(tree3, paramsPlus(_, tree3 := true));
  }
  
  // DROP BAD ENTRIES, SORT
  
  if (boolPar skipBad(_, true)) l = [GazelleTree t : l | neq(t.prediction, 'bad)];
  gazelle_sortChildren(l);
  
  // MATCH ADDITIONAL CONDITIONS
  
  SS inputMap = gazelle_inputMapFromLineAndHistory(content, 
    listPlus(preContext, content));
  if (debug) print("reasonAbout inputMap=" + sfu(asTreeMap(inputMap)));
  
  for (GazelleTree t : l) {
    if (t.mr == null) continue;
    int iCond;
    do {
      iCond = t.mr.iCond;
      dm_gazelle_matchStep_statement(t,
        passParams(_, 'debug, 'dm_gazelle_matchStatementsDebug));
      dm_gazelle_matchStep_additionalInput(t, inputMap, _);
      dm_gazelle_matchStep_condition(t, _);
    } while (t.mr.iCond > iCond);
  }
  
  for (GazelleTree t : l) t.flush();
  
  // DROP UNSATISFIED ENTRIES
    
  int n = l(l);
  l = gazelle_dropUnsatisfiedEntries(l);
  if (debug) print("Filtered out " + (n-l(l)) + " unsatisfied entries (keeping " + l(l) + ")");
  
  // DROP DEFAULTS
  
  if (!boolPar keepDefaults(_))
    gazelle_dropMatchedDefaultRules(l, _);

  ret l;
}

Author comment

Began life as a copy of #1021751

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: #1021773
Snippet name: dm_gazelle_reasonAboutChatInput_v2 - with multiple input lines (LIVE)
Eternal ID of this version: #1021773/70
Text MD5: 3bcc8521a2a70a78bd56c84729dde306
Transpilation MD5: e95894dd27c569234e4f2796402c4b0c
Author: stefan
Category: javax / discord
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-06-22 01:36:02
Source code size: 3633 bytes / 105 lines
Pitched / IR pitched: No / No
Views / Downloads: 431 / 660
Version history: 69 change(s)
Referenced in: [show references]