forked from mkottman/luaspell
/
test.lua
50 lines (39 loc) · 1.29 KB
/
test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local spell = require 'spell'
assert(spell, 'spell not loaded')
assert(type(spell) == "function", 'spell is not a function')
s = spell('/usr/share/hunspell/en_US.aff', '/usr/share/hunspell/en_US.dic')
assert(s, 'dict not loaded')
local okword = 'friendliness'
local badword = 'friendlines'
assert(s.spell, 'spell function does not exist')
assert(s:spell(okword), 'spell("'..okword..'") should return true')
assert(not s:spell(badword), 'spell("'..badword..'") should return false')
assert(s.suggest, 'suggest function does not exist')
local t = s:suggest(badword)
local found = false
for _,v in ipairs(t) do
if v == okword then
found = true
break
end
end
assert(found, badword .. ' -> '..okword..' suggestion not found')
assert(s.analyze, 'analyze function does not exist')
local t = s:analyze(okword)
assert(type(t) == "table", 'analyze() does not return a table: '..type(t))
print('Analysis of '..okword)
for _,v in ipairs(t) do
print('>', v)
end
local root = s:stem(okword)
assert(type(root) == "table", 'stem() does not return a table: '..type(root))
print('Roots of '..okword)
for _,v in ipairs(root) do
print('>', v)
end
print(unpack(s:analyze('cars')))
local gen = s:generate('word', 'cars')
print(#gen, unpack(gen))
local gen2 = s:generate('word', {'fl:S'})
print(#gen2, unpack(gen2))
print('OK')