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

60
LINES

< > BotCompany Repo | #1002988 // Log Analysis (#talkingbots)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1270L/9K/28K).

!752

answer {
  exceptionToUser {
    if (!tb()) null;
    
    if "how many lines"
      ret lstr(getLog());
      
    if "how many users"
      ret lstr(getUsers());
      
    if "how many different words" 
      ret lstr(getWords());
      
    if "some users"
      ret some(getUsers());
      
    if "some words"
      ret some(getWords());
      
    if "longest message"
      ret shorten(longest(getTexts()), 100);
  }
}

static L getLog() {
  ret getTBLog();
}

static Set<S> getUsers() {
  ret asTreeSet(collectField(getLog(), "userName"));
}

static L<S> getTexts() {
  ret collectField(getLog(), "text");
}

static Set<S> getWords() {
  L<S> lines = getTexts();
  new TreeSet<S> set;
  for (S text : lines) {
    for (S t : codeTokens(nlTok(text))) {
      if (isExtendedIdentifier(t))
        set.add(t.toLowerCase());
    }
  }
  ret set;
}

static S some(Collection<S> c) {
  ret join(" ", selectRandom(asList(c), 10));
}

static S longest(L<S> l) {
  new Map<S, Integer> map;
  for (S s : l)
    map.put(s, l(s));
  ret highest(map);
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002988
Snippet name: Log Analysis (#talkingbots)
Eternal ID of this version: #1002988/1
Text MD5: e633dcdd1937b89ff6e9bb76b902c8aa
Transpilation MD5: b1f858be37808703126a3b19204aa6f7
Author: stefan
Category: eleu / nl
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-04-17 22:02:05
Source code size: 1114 bytes / 60 lines
Pitched / IR pitched: No / No
Views / Downloads: 764 / 846
Referenced in: [show references]