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

20
LINES

< > BotCompany Repo | #1004710 // Word Tree Predictor [Lua]

Lua code

1  
-- build a word tree (character occurrence tree) and walk it
2  
pairs = {}
3  
wordTree = {}
4  
wordTreeP = wordTree
5  
function p(m, s)
6  
  if s ~= nil then
7  
    for i = 1, s:len() do
8  
      local c = s:sub(i, i)
9  
      if c >= "a" and c <= "z" or c >= "A" and c <= "Z" then
10  
        local n = wordTreeP[c]
11  
        if n == nil then n = {} wordTreeP[c] = n end
12  
        wordTreeP = n
13  
      else
14  
        wordTreeP = wordTree
15  
      end
16  
    end
17  
  end
18  
  local c, n = next(wordTreeP)
19  
  return c
20  
end

Author comment

Began life as a copy of #1004708

test run  test run with input  download  show line numbers   

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

Comments [hide]

ID Author/Program Comment Date
1297 stefan Scores 31.4% in the Maude test 2016-08-27 16:23:13

add comment

Snippet ID: #1004710
Snippet name: Word Tree Predictor [Lua]
Eternal ID of this version: #1004710/1
Text MD5: f04cf7cb3d77e1b1ac34773b8d60099b
Author: stefan
Category: javax / a.i.
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-28 14:44:44
Source code size: 492 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 1021 / 194
Referenced in: [show references]