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)

1  
static void ai_tg_collectRuleFeedback(Map<S, Int> ruleScores, Collection<S> out_facts) {
2  
  replace Msg with TelegramMsg. // We're lazy!
3  
  
4  
  LPair<Msg, LS> l = serverTelegramLog_plusFiredRules();
5  
  for i over l: {
6  
    LS rules = l.get(i).b;
7  
    if (empty(rules)) continue;
8  
    Msg msg = l.get(i).a;
9  
    int j = i+1;
10  
    while (j < l(l) && l.get(j).a.sent) ++j; // Find next user msg
11  
    L<Msg> nextMsgs = pairsA(subList(l, i+1, j+1));
12  
    Msg userMsg = null;
13  
    if (nempty(nextMsgs)) {
14  
      for (Msg m : nextMsgs)
15  
        if (userMsg == null && !m.sent) userMsg = m;
16  
    }
17  
    if (userMsg == null) continue;
18  
    int score = 0, ruleNr = 0;
19  
    S s = userMsg.text;
20  
    
21  
    new Matches m;
22  
    if "* to number *" {
23  
      s = $1; ruleNr = parseInt($2);
24  
    }
25  
    
26  
    if (matchAny(mL("Yes Feedback Words"), s))
27  
      ++score;
28  
    if (matchAny(mL("No Feedback Words"), s))
29  
      --score;
30  
31  
    // Rules seem to be in the right order w/respect to output lines
32  
    for (S rule : ruleNr == 0 ? rules : ll(rules.get(ruleNr-1))) {
33  
      if (score != 0 && ruleScores != null)
34  
        ruleScores.put(rule, toInt(ruleScores.get(rule))+score);
35  
      if (out_facts != null)
36  
        out_facts.add("rule " + format_arg(rule) + " had "
37  
          + (score > 0 ? "positive" : score < 0 ? "negative" : "possible") + " feedback (" + quote(userMsg.text) + ") when fired on msg " + msg.globalID + " at " + msg.date);
38  
    }
39  
  }
40  
  
41  
  if (out_facts != null)
42  
    addToMechList("Rule Feedback", out_facts);
43  
}

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