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

-- build a word tree (character occurrence tree) and walk it
pairs = {}
wordTree = {}
wordTreeP = wordTree
function p(m, s)
  if s ~= nil then
    for i = 1, s:len() do
      local c = s:sub(i, i)
      if c >= "a" and c <= "z" or c >= "A" and c <= "Z" then
        local n = wordTreeP[c]
        if n == nil then n = {} wordTreeP[c] = n end
        wordTreeP = n
      else
        wordTreeP = wordTree
      end
    end
  end
  local c, n = next(wordTreeP)
  return c
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

1 comment(s) hidden. show

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: 1023 / 195
Referenced in: [show references]