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

48
LINES

< > BotCompany Repo | #1009446 // Word Collector [dev.]

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

Uses 3874K of libraries. Click here for Pure Java version (8776L/57K/202K).

1  
!7
2  
3  
static int maxWords = 100000;
4  
static int maxWordLength = 10;
5  
static int topTenTargetLength = 10;
6  
7  
static Map<S, Long> map;
8  
static L<S> topTen;
9  
10  
p-subst {
11  
  tt();
12  
  centerHigherConsole();
13  
  map = l_persistentTreeMap("Words + count");
14  
  topTen = l_persistentList("Top Ten");
15  
  printTopTen();
16  
  botIfMain();
17  
}
18  
19  
svoid addWordHits(Collection<S> words) {
20  
  for (S word : words) {
21  
    word = shorten(word, maxWordLength);
22  
    long count = longMultiSet_add(map, word);
23  
    insertToTopTen(word, count);
24  
  }
25  
}
26  
27  
svoid insertToTopTen(S word, long count) {
28  
  int originalIndex = indexOf(topTen, word);
29  
  int i = originalIndex < 0 ? l(topTen) : originalIndex;
30  
  while (i > 0 && count >= toLong(map.get(topTen.get(i-1))))
31  
    --i;
32  
  if (i >= topTenTargetLength || i == originalIndex) ret;
33  
  if (originalIndex >= 0) topTen.remove(originalIndex);
34  
  topTen.add(i, word);
35  
  truncateList(topTen, topTenTargetLength);
36  
}
37  
38  
svoid printTopTen {
39  
  printAsciiHeading("TOP TEN");
40  
  pnl(map(topTen, func(S s) { s + " - " + map.get(s) }));
41  
}
42  
43  
answer {
44  
  if "clear top ten" { topTen.clear(); ret "OK"; }
45  
  addWordHits(words2(s));
46  
  printTopTen();
47  
  try answer "OK";
48  
}

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: #1009446
Snippet name: Word Collector [dev.]
Eternal ID of this version: #1009446/11
Text MD5: 0cac6d447dae1639cd2808c5528f3bc9
Transpilation MD5: 48a03185531cc8435480f4dceff14269
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-01 20:51:03
Source code size: 1187 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 569 / 711
Version history: 10 change(s)
Referenced in: [show references]