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

1  
-- a, b are the last 2 words
2  
pairs = {}
3  
text = {}
4  
ntext = 0
5  
word = {}
6  
wordIdx = {}
7  
function p(m, s)
8  
  if s ~= nil then
9  
    for i = 1, s:len() do
10  
      local c = s:sub(i, i)
11  
      ntext = ntext+1
12  
      text[ntext] = c
13  
      if c >= "a" and c <= "z" or c >= "A" and c <= "Z" then
14  
        nword = nword+1
15  
        word[nword] = c
16  
      else
17  
        if nword ~= 0 then
18  
          newWord(table.concat(word))
19  
          word = {}
20  
          nword = 0
21  
        end
22  
      end
23  
    end
24  
  end
25  
26  
  local x = wordIdx[b]
27  
  if x ~= nil then return table.concat(text, "", x,
28  
    math.min(ntext, x+math.min(100, m)-1)) end
29  
    
30  
end
31  
32  
function newWord(w)
33  
  a = b
34  
  b = w
35  
  wordIdx[b] = ntext+1
36  
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: 624 / 179
Referenced in: [show references]