0 Members and 1 Guest are viewing this topic.
a b c {m} [abécédaire] primer {n} [ABC] a latere [REL‚ loc adj] a latere [adj phr] a latere [REL‚ loc adv] a latere [adv phr] a priori [loc adj] a priori [adj] a priori [loc adv] a priori [adv], guess; at a ~ [adv phr] a priori {m inv} apriorism {n}, preconception {n} A {m} [alphabet latin] A {n} [Roman alphabet] A {n} [ÉLEC‚ ampère] amp {n} [ELEC‚ an ampere] abaissement {m} abatement {n}, decay {n}, lowering {n} abaisser [v tr] lower [v tr‚ make lower] abaisser [v tr‚ raccourcir] cut up [v tr] abaisser [v tr‚ réduire] bring down [vt‚ lower a price] abaisser; s'~ [v pr] off; to get ~, demean; to ~ oneself abaisser; s'~ vivement [v pr] duck down [v intr] abaisser; s'~ à faire stoop; to ~ to doing
i meant that semicolon thing for your encoding of the library.if you do for example lib = "can;pie;cake;board;door" etc you can easely split them up to find the words, and you don't need that endlessly long table to store your entries..
function editDictionary(dictionary, old_dict) local data = old_dict or {} for _, word in ipairs(dictionary) do local curchar = data for i = 1, #word do local char = word:sub(i, i) if not curchar[char] then curchar[char] = {endof = i == #word and true or nil} elseif not curchar[char].endof then curchar[char].endof = i == #word and true or nil end curchar = curchar[char] end end data.lookup = function(tbl, str) local function lookup(str) local curchar = data for i = 1, #str do curchar = curchar[str:sub(i, i)] end return curchar.endof end err, ret = pcall(lookup, str) return err and ret or nil end return dataend
list={"carbon","cars","car","cat","cats"}
dictionary = { c={ a={ r={ b={ o={ n={endof = true} } } s={endof = true} endof = true } t = { s={endof = true} endof = true } } } lookup = function(tbl, str) --blah blah blah end}
dict = {"cat", "cats", "dog", "mouse"}dictionary = editDictionary(dict)print("d:", dictionary:lookup("d"))print("do:", dictionary:lookup("do"))print("dog:", dictionary:lookup("dog"))print("dogs:", dictionary:lookup("dogs"))print("dogz:", dictionary:lookup("dogz"))amendment = {"dogs"}dictionary = editDictionary(amendment, dictionary)print("\nAmendment: dogs added!\n")print("d:", dictionary:lookup("d"))print("do:", dictionary:lookup("do"))print("dog:", dictionary:lookup("dog"))print("dogs:", dictionary:lookup("dogs"))print("dogz:", dictionary:lookup("dogz"))
d: nildo: nildog: truedogs: nildogz: nilAmendment: dogs added!d: nildo: nildog: truedogs: truedogz: nil
function checkWord(word) local letterkeys = {1,72,129,241,310,360,402,437,479,533,541,551,582,647,679,720,822,827,895,1019,1076,1112,1130,1152,1153,1155} jstart = letterkeys[string.byte(word) - string.byte('a') + 1] for i = jstart,1158 do loadstring("abc = words"..i) if string.find(abc,word) then return true end end return falseend
abc = words12
abc = words13
A warning: don't paste tables like this into programs with syntax highlighting. I pasted a table into the student software, walked away for an hour, came back and it was still trying to highlight everything. I eventually gave up and used the old scripting tools to test out the method.