static L 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 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 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 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; }