aboutsummaryrefslogtreecommitdiff
path: root/src/fuzzel.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/fuzzel.lua')
-rw-r--r--src/fuzzel.lua20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/fuzzel.lua b/src/fuzzel.lua
index 5a65514..f258acf 100644
--- a/src/fuzzel.lua
+++ b/src/fuzzel.lua
@@ -106,7 +106,7 @@ local function genericDistance( stringa, stringb, addcost, subcost, delcost, ...
end
--- The current version (1.4).
-fuzzel.VERSION = "1.4"
+fuzzel._VERSION = "1.4"
--- Finds edit distance between two strings with custom costs.
-- The levenshtein distance is the minimum number of additions, deletions, and substitutions that are needed to turn one string into another. This methods allows custom costs for addition, deletion, and substitution.
@@ -117,6 +117,7 @@ fuzzel.VERSION = "1.4"
-- @number subcost the custom cost to subtitute one character for another
-- @number delcost the custom cost to delete one character
-- @return the distance from the first string to the second (which will always be the same as the distance from the second string to the first)
+-- @usage fuzzel.LevenshteinDistance_extended("juice","moose",1,2,3)
fuzzel[LevenshteinDistance_extended] = function(stringa, stringb, addcost, subcost, delcost)
return genericDistance(stringa, stringb, addcost, subcost, delcost)
end
@@ -128,6 +129,7 @@ fuzzel.ld_e = fuzzel[LevenshteinDistance_extended]
-- @string str1 the first string
-- @string str2 the second string
-- @return the distance between the two input strings
+-- @usage fuzzel.LevenshteinDistance("Flag","Brag")
fuzzel[LevenshteinDistance] = function(stringa,stringb)
return fuzzel.ld_e(stringa,stringb,1,1,1)
end
@@ -138,6 +140,7 @@ fuzzel.ld = fuzzel[LevenshteinDistance]
-- @string str1 the first string, and the string to use for the ratio
-- @string str2 the second string
-- @return the distance between the two strings divided by the length of the first string
+-- @usage fuzzel.LevenshteinRatio("bling","bring")
fuzzel[LevenshteinRatio] = function(stringa,stringb)
return fuzzel.ld(stringa,stringb) / strlen(stringa)
end
@@ -153,6 +156,7 @@ fuzzel.lr = fuzzel[LevenshteinRatio]
-- @number delcost the cost of removeing a character
-- @number trncost the cost of transposeing two adjacent characters.
-- @return the edit distance between the two strings
+-- @usage DamerauLevenshteinDistance_extended("berry","bury",0,1,1,2,1)
fuzzel[DamerauLevenshteinDistance_extended] = function(stringa, stringb, addcost, subcost, delcost, trncost)
return genericDistance(stringa,stringb,addcost,subcost,delcost,tru,trncost)
end
@@ -163,6 +167,7 @@ fuzzel.dld_e = fuzzel[DamerauLevenshteinDistance_extended]
-- @string str1 the fist string
-- @string str2 the second string
-- @return the minimum number of additions, deletions, substitutions, or transpositions to turn str1 into str2
+-- @usage fuzzel.DamerauLevenshteinDistance("tree","trap")
fuzzel[DamerauLevenshteinDistance] = function(stringa,stringb)
return fuzzel.dld_e(stringa,stringb,1,1,1,1)
end
@@ -173,6 +178,7 @@ fuzzel.dld = fuzzel[DamerauLevenshteinDistance]
-- @string str1 the fist string, and number to use for ratio
-- @string str2 the second string
-- @return the Damerau-Levenshtein distance divided by the length of the first string.
+-- @usage fuzzel.DamerauLevenshteinRatio("pants","hands")
fuzzel[DamerauLevenshteinRatio] = function(stringa,stringb)
return fuzzel.dld(stringa,stringb) / strlen(stringa)
end
@@ -184,8 +190,8 @@ fuzzel.dlr = fuzzel[DamerauLevenshteinRatio]
-- @string str1 the first string
-- @string str2 the second string
-- @return the edit distance between str1 and str2
--- @useage fuzzel.HammingDistance("one","two")
--- @useage fuzzel.HammingDistance("two","three") --Will throw an error, since "two" is 3 characters long while "three" is 5 characters long!
+-- @usage fuzzel.HammingDistance("one","two")
+-- @usage fuzzel.HammingDistance("two","three") --Will throw an error, since "two" is 3 characters long while "three" is 5 characters long!
fuzzel[HammingDistance] = function(stringa,stringb)
local len,dist = strlen(stringa),0
asrt(len == strlen(stringb), ha.." "..di.." cannot be calculated on two strings of different lengths:\"" .. stringa .. "\" \"" .. stringb .. "\"")
@@ -201,8 +207,8 @@ fuzzel.hd = fuzzel[HammingDistance]
-- @string str1 the first string, and string to use for the ratio
-- @string str2 the second string
-- @return the edit distance between the two strings
--- @useage fuzzel.HammingRatio("four","five")
--- @useage fuzzel.HammingRatio("seven","ten") -- Will throw an error, since "seven" is 5 characters long while "ten" is 3 characters long
+-- @usage fuzzel.HammingRatio("four","five")
+-- @usage fuzzel.HammingRatio("seven","ten") -- Will throw an error, since "seven" is 5 characters long while "ten" is 3 characters long
fuzzel[HammingRatio] = function(stringa,stringb)
return fuzzel.hd(stringa,stringb) / strlen(stringa)
end
@@ -242,8 +248,8 @@ fuzzel.ffd = fuzzel[FuzzyFindDistance]
-- @function FuzzyFindRatio
-- @string str the string to compare to
-- @param ... A 1-indexed array of strings, or a list of strings to campare str against
--- @useage fuzzel.FuzzyFindRatio("light",{"lit","lot","lightbulb"})
--- @useage fuzzel.FuzzyFindRatio("light","lit","lot","lightbulb")
+-- @usage fuzzel.FuzzyFindRatio("light",{"lit","lot","lightbulb"})
+-- @usage fuzzel.FuzzyFindRatio("light","lit","lot","lightbulb")
fuzzel[FuzzyFindRatio] = function(str,...)
return upack{FuzzySearch(str,fuzzel.dlr,...)}
end