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

47
LINES

< > BotCompany Repo | #1004744 // Word Tree Predictor Strategy

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

Libraryless. Click here for Pure Java version (2145L/14K/47K).

1  
!752
2  
3  
static int sep = 0;
4  
5  
p {
6  
  load("sep");
7  
}
8  
9  
static S lua = [[
10  
  -- build a word tree (character occurrence tree) and walk it
11  
  pairs = {}
12  
  wordTree = {}
13  
  wordTreeP = wordTree
14  
  isSep = {}
15  
  seps = "SEPS"
16  
  for i = 1, seps:len() do isSep[seps:sub(i, i)] = true end
17  
  function p(m, s)
18  
    if s ~= nil then
19  
      for i = 1, s:len() do
20  
        local c = s:sub(i, i)
21  
        if isSep[c] then
22  
          wordTreeP = wordTree
23  
        else
24  
          local n = wordTreeP[c]
25  
          if n == nil then n = {} wordTreeP[c] = n end
26  
          wordTreeP = n
27  
        end
28  
      end
29  
    end
30  
    local c, n = next(wordTreeP)
31  
    return c
32  
  end
33  
]];
34  
35  
static S strategy(S text) {
36  
  if (sep >= 0x100) ret "done";
37  
  sep++;
38  
  save("sep");
39  
  S seps = str((char) sep);
40  
  print("Trying sep " + quote(seps));
41  
  ret lua.replace([["SEPS"]], luaQuote(seps));
42  
}
43  
44  
static void reset() {
45  
  sep = 0;
46  
  save("sep");
47  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1004744
Snippet name: Word Tree Predictor Strategy
Eternal ID of this version: #1004744/1
Text MD5: 204d919e2e809ba6854b1c01995ba6ee
Transpilation MD5: f89279ce397c64e944b6ae219c9c7e14
Author: stefan
Category: javax / a.i.
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-09-11 23:14:35
Source code size: 932 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 665 / 1007
Referenced in: [show references]