static void ai_tg_collectRuleFeedback(Map ruleScores, Collection out_facts) { replace Msg with TelegramMsg. // We're lazy! LPair l = serverTelegramLog_plusFiredRules(); for i over l: { LS rules = l.get(i).b; if (empty(rules)) continue; Msg msg = l.get(i).a; int j = i+1; while (j < l(l) && l.get(j).a.sent) ++j; // Find next user msg L nextMsgs = pairsA(subList(l, i+1, j+1)); Msg userMsg = null; if (nempty(nextMsgs)) { for (Msg m : nextMsgs) if (userMsg == null && !m.sent) userMsg = m; } if (userMsg == null) continue; int score = 0, ruleNr = 0; S s = userMsg.text; new Matches m; if "* to number *" { s = $1; ruleNr = parseInt($2); } if (matchAny(mL("Yes Feedback Words"), s)) ++score; if (matchAny(mL("No Feedback Words"), s)) --score; // Rules seem to be in the right order w/respect to output lines for (S rule : ruleNr == 0 ? rules : ll(rules.get(ruleNr-1))) { if (score != 0 && ruleScores != null) ruleScores.put(rule, toInt(ruleScores.get(rule))+score); if (out_facts != null) out_facts.add("rule " + format_arg(rule) + " had " + (score > 0 ? "positive" : score < 0 ? "negative" : "possible") + " feedback (" + quote(userMsg.text) + ") when fired on msg " + msg.globalID + " at " + msg.date); } } if (out_facts != null) addToMechList("Rule Feedback", out_facts); }