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

36
LINES

< > BotCompany Repo | #1004712 // Word Index Predictor [Lua]

Lua code

-- a, b are the last 2 words
pairs = {}
text = {}
ntext = 0
word = {}
wordIdx = {}
function p(m, s)
  if s ~= nil then
    for i = 1, s:len() do
      local c = s:sub(i, i)
      ntext = ntext+1
      text[ntext] = c
      if c >= "a" and c <= "z" or c >= "A" and c <= "Z" then
        nword = nword+1
        word[nword] = c
      else
        if nword ~= 0 then
          newWord(table.concat(word))
          word = {}
          nword = 0
        end
      end
    end
  end

  local x = wordIdx[b]
  if x ~= nil then return table.concat(text, "", x,
    math.min(ntext, x+math.min(100, m)-1)) end
    
end

function newWord(w)
  a = b
  b = w
  wordIdx[b] = ntext+1
end

Author comment

Began life as a copy of #1004711

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

No comments. add comment

Snippet ID: #1004712
Snippet name: Word Index Predictor [Lua]
Eternal ID of this version: #1004712/1
Text MD5: fa44581e4842512ea3a1d6adefbdef43
Author: stefan
Category: javax / a.i.
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-27 17:01:34
Source code size: 708 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 623 / 178
Referenced in: [show references]