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).

1  
static L<GazelleTree> dm_gazelle_reasonAboutChatInput_v2(S userName, S content, O... _) {
2  
  // GATHER PARAMETERS & CONTEXT
3  
  
4  
  bool debug = boolPar debug(_);
5  
  bool debugRules = boolPar debugRules(_) || debug;
6  
  LS preContext = cast optPar preContext(_);
7  
  GazelleEvalContext ctx = cast optPar ctx(_);
8  
  F0<GazelleEvalContext> contextMaker = cast optPar contextMaker(_);
9  
  if (debugRules) print("Have ctx: " + (ctx != null) + ", contextMaker: " + (contextMaker != null));
10  
  if (ctx == null && contextMaker != null) {
11  
    ctx = contextMaker!;
12  
    if (debugRules) print("Called contextMaker, got " + nRules(ctx.engine.rules));
13  
  }
14  
  if (ctx == null) ctx = dm_gazelle_stdEvalContext(dm_gazelle_allRulesWithComment(optPar requiredComment(_, "discord")));
15  
  Set<S> acceptablePurposes = cast optPar acceptablePurposes(_);
16  
17  
  if (debug)
18  
    print(" == PROCESSING INPUT: " + content);
19  
    
20  
  // PREPARE RULES
21  
    
22  
  // Need input as first condition
23  
  gazelle_dropRulesNotOnInput(ctx);
24  
  
25  
  if (acceptablePurposes != null) {
26  
    if (debugRules) {
27  
      print("Purposes: " + acceptablePurposes);
28  
      print("Have purposes: " + collectUnique purpose(ctx.engine.rules));
29  
    }
30  
    int nBefore = l(ctx.engine.rules);
31  
    ctx.engine.dropRulesWhere(r -> !acceptablePurposes.contains(unnull(r.purpose)));
32  
    if (debugRules) print("Retaining " + n2(ctx.engine.rules, "rule") + " of " + nBefore);
33  
  }
34  
    
35  
  if (debugRules) print("Have rules: " + collect globalID(ctx.engine.rules));
36  
  
37  
  gazelle_addHelpers(ctx, _);
38  
  
39  
  // MAKE PARAMETERS
40  
  
41  
  O[] params = paramsPlus(paramsMinus(_, 'ctx),
42  
    firstConditionOnly := true,
43  
    dialogHistory := preContext);
44  
    
45  
  // TREE1 (just input)
46  
  
47  
  GazelleTree tree1 = cast optPar tree(_);
48  
  if (tree1 == null) tree1 = GazelleTree(ctx, content);
49  
  L<GazelleTree> l = gazelle_getChildren_withContinuations(tree1, params);
50  
  
51  
  // TREE2 (user says: ...)
52  
  
53  
  if (nempty(userName) && !boolPar skipUserName(_)) {
54  
    GazelleTree tree2 = new(ctx, optCurly(userName) + " says: " + content);
55  
    if (debug) print("Tree2: " + tree2);
56  
    l.addAll(gazelle_getChildren_withContinuations(tree2, paramsPlus(_, tree2 := true)));
57  
  }
58  
  
59  
  // TREE3 (user with id x says: ...)
60  
  
61  
  Long userID = cast optPar userID(_);
62  
  
63  
  if (userID != null && userID != 0 && !boolPar skipUserID(_)) {
64  
    GazelleTree tree3 = new(ctx, "user with id " + userID + " says: " + content);
65  
    l.addAll(gazelle_getChildren_withContinuations(tree3, paramsPlus(_, tree3 := true));
66  
  }
67  
  
68  
  // DROP BAD ENTRIES, SORT
69  
  
70  
  if (boolPar skipBad(_, true)) l = [GazelleTree t : l | neq(t.prediction, 'bad)];
71  
  gazelle_sortChildren(l);
72  
  
73  
  // MATCH ADDITIONAL CONDITIONS
74  
  
75  
  SS inputMap = gazelle_inputMapFromLineAndHistory(content, 
76  
    listPlus(preContext, content));
77  
  if (debug) print("reasonAbout inputMap=" + sfu(asTreeMap(inputMap)));
78  
  
79  
  for (GazelleTree t : l) {
80  
    if (t.mr == null) continue;
81  
    int iCond;
82  
    do {
83  
      iCond = t.mr.iCond;
84  
      dm_gazelle_matchStep_statement(t,
85  
        passParams(_, 'debug, 'dm_gazelle_matchStatementsDebug));
86  
      dm_gazelle_matchStep_additionalInput(t, inputMap, _);
87  
      dm_gazelle_matchStep_condition(t, _);
88  
    } while (t.mr.iCond > iCond);
89  
  }
90  
  
91  
  for (GazelleTree t : l) t.flush();
92  
  
93  
  // DROP UNSATISFIED ENTRIES
94  
    
95  
  int n = l(l);
96  
  l = gazelle_dropUnsatisfiedEntries(l);
97  
  if (debug) print("Filtered out " + (n-l(l)) + " unsatisfied entries (keeping " + l(l) + ")");
98  
  
99  
  // DROP DEFAULTS
100  
  
101  
  if (!boolPar keepDefaults(_))
102  
    gazelle_dropMatchedDefaultRules(l, _);
103  
104  
  ret l;
105  
}

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: 438 / 670
Version history: 69 change(s)
Referenced in: [show references]