-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
53 lines (46 loc) · 1.63 KB
/
init.lua
File metadata and controls
53 lines (46 loc) · 1.63 KB
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
51
52
53
------------------------------------------------------------
---
---@module strsim
---
--- String similarity library for Lua/LuaJIT
--- Provides various string distance and similarity algorithms
---
------------------------------------------------------------
local Algorithm = require("strsim.algorithm")
local strsim = {}
------------------------------------------------------------
---
--- Default algorithm for distance/similarity calculations
---
------------------------------------------------------------
local DEFAULT_ALGORITHM = Algorithm.LEVENSHTEIN
------------------------------------------------------------
---
---Calculate the edit distance between two strings
---@param a string First string
---@param b string Second string
---@param algorithm? StringDistanceAlgorithm Algorithm to use (default: LEVENSHTEIN)
---
---@return number distance The edit distance
------------------------------------------------------------
function strsim.distance(a, b, algorithm)
algorithm = algorithm or DEFAULT_ALGORITHM
return algorithm.distance(a, b)
end
------------------------------------------------------------
---
---Calculate the similarity between two strings (0.0 to 1.0)
---
---@param a string First string
---@param b string Second string
---@param algorithm? StringDistanceAlgorithm Algorithm to use (default: LEVENSHTEIN)
---
---@return number similarity Similarity score between 0.0 and 1.0
---
------------------------------------------------------------
function strsim.similarity(a, b, algorithm)
algorithm = algorithm or DEFAULT_ALGORITHM
return algorithm.similarity(a, b)
end
strsim.Algorithm = Algorithm
return strsim