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

43
LINES

< > BotCompany Repo | #1017867 // ai_tg_collectRuleFeedback

JavaX fragment (include)

static void ai_tg_collectRuleFeedback(Map<S, Int> ruleScores, Collection<S> out_facts) {
  replace Msg with TelegramMsg. // We're lazy!
  
  LPair<Msg, LS> 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<Msg> 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);
}

Author comment

Began life as a copy of #1017865

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017867
Snippet name: ai_tg_collectRuleFeedback
Eternal ID of this version: #1017867/8
Text MD5: 9874c86ce31028b473070548fa07050d
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-08-18 23:36:22
Source code size: 1522 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 374 / 404
Version history: 7 change(s)
Referenced in: [show references]