summaryrefslogtreecommitdiff
path: root/spellfix.fnl
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-10-15 14:49:46 +0600
committerunwox <me@unwox.com>2024-10-15 14:59:04 +0600
commit92d95b978bfb10fd29024d0adda7b28f125e08b8 (patch)
tree189fd3c9cf9bc08712d795e8119c8df61fd7ce6b /spellfix.fnl
parent1204496efa2fcd495bd74ba8ca249b7f082f3ba5 (diff)
adapt to the new convention for calling luna module methods
Diffstat (limited to 'spellfix.fnl')
-rw-r--r--spellfix.fnl7
1 files changed, 4 insertions, 3 deletions
diff --git a/spellfix.fnl b/spellfix.fnl
index 3478782..24d381c 100644
--- a/spellfix.fnl
+++ b/spellfix.fnl
@@ -1,6 +1,7 @@
(import-macros {: map : filter} :lib.macro)
(local array (require :lib.array))
(local str (require :lib.string))
+(local {: must} (require :lib.utils))
(local vocabulary ["абрикосовый" "агар" "агарвуд" "агат" "агатис" "алая" "али"
"алишань" "алтарь" "альба" "амазонка" "аметист" "амино"
@@ -278,8 +279,8 @@
"ясный" "яшма"])
(fn levenshtein [str1 str2]
- (let [len1 (luna.utf.len str1)
- len2 (luna.utf.len str2)
+ (let [len1 (must (luna.utf.len str1))
+ len2 (must (luna.utf.len str2))
matrix {}]
(var cost 0)
(if (= len1 0) (lua "return len2")
@@ -289,7 +290,7 @@
(for [j 0 len2] (tset (. matrix 0) j j))
(for [i 1 len1]
(for [j 1 len2]
- (if (= (luna.utf.sub str1 i 1) (luna.utf.sub str2 j 1))
+ (if (= (must (luna.utf.sub str1 i 1)) (must (luna.utf.sub str2 j 1)))
(set cost 0) (set cost 1))
(tset (. matrix i) j
(math.min (+ (. matrix (- i 1) j) 1) (+ (. matrix i (- j 1)) 1)