From 88f89adfc551f05220c75a59e192e5f771aa3f82 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Mon, 27 Jun 2016 19:12:53 -0400 Subject: Finished useage examples for documentation --- doc/config.ld | 4 ++-- doc/index.html | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- src/fuzzel.lua | 20 ++++++++++------ 3 files changed, 84 insertions(+), 14 deletions(-) diff --git a/doc/config.ld b/doc/config.ld index e6121b8..eed8621 100644 --- a/doc/config.ld +++ b/doc/config.ld @@ -1,8 +1,8 @@ project = 'Fuzzel' description = 'String matching library' full_description = 'A few functions to do fuzzy string matching' -title = 'Penlight Documentation' +title = 'Fuzzel Documentation' dir = 'doc' use_markdown_titles = true -format = 'markdown' +format = 'discount' file = '../src/fuzzel.lua' diff --git a/doc/index.html b/doc/index.html index d2fab8f..55fde7d 100644 --- a/doc/index.html +++ b/doc/index.html @@ -3,7 +3,7 @@ - Penlight Documentation + Fuzzel Documentation @@ -112,7 +112,7 @@

Fields

- +
VERSION_VERSION The current version (1.4).
@@ -165,6 +165,10 @@ +

Usage:

+
@@ -196,6 +200,10 @@ +

Usage:

+
@@ -226,6 +234,10 @@ +

Usage:

+
@@ -273,6 +285,10 @@ +

Usage:

+
@@ -303,6 +319,10 @@ +

Usage:

+
@@ -333,6 +353,10 @@ +

Usage:

+
@@ -364,6 +388,11 @@ +

Usage:

+
@@ -394,6 +423,11 @@ +

Usage:

+
@@ -419,6 +453,11 @@ +

Usage:

+
@@ -444,6 +483,11 @@ +

Usage:

+
@@ -474,6 +518,11 @@ +

Usage:

+
@@ -504,6 +553,11 @@ +

Usage:

+
@@ -534,6 +588,11 @@ +

Usage:

+
@@ -564,6 +623,11 @@ +

Usage:

+ @@ -571,8 +635,8 @@
- - VERSION + + _VERSION
The current version (1.4). @@ -591,7 +655,7 @@
generated by LDoc 1.4.3 -Last updated 2016-06-27 18:24:14 +Last updated 2016-06-27 19:11:33
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 -- cgit v1.2.3-70-g09d2