fast-fuzzy
Advanced tools
Comparing version 1.8.6 to 1.8.7
@@ -165,2 +165,17 @@ "use strict"; | ||
return rows; | ||
} // the content of the innermost loop of levenshtein | ||
function levCore(term, candidate, rows, i, j) { | ||
var rowA = rows[i]; | ||
var rowB = rows[i + 1]; | ||
var cost = term[i] === candidate[j] ? 0 : 1; | ||
var m; | ||
var min = rowB[j] + 1; // insertion | ||
if ((m = rowA[j + 1] + 1) < min) min = m; // deletion | ||
if ((m = rowA[j] + cost) < min) min = m; // substitution | ||
rowB[j + 1] = min; | ||
} // the fuzzy scoring algorithm: a modification of levenshtein proposed by Peter H. Sellers | ||
@@ -174,13 +189,3 @@ // this essentially finds the substring of "candidate" with the minimum levenshtein distance from "term" | ||
for (var i = 0; i < term.length; i++) { | ||
var rowA = rows[i]; | ||
var rowB = rows[i + 1]; | ||
var cost = term[i] === candidate[j] ? 0 : 1; | ||
var m = void 0; | ||
var min = rowB[j] + 1; // insertion | ||
if ((m = rowA[j + 1] + 1) < min) min = m; // deletion | ||
if ((m = rowA[j] + cost) < min) min = m; // substitution | ||
rowB[j + 1] = min; | ||
levCore(term, candidate, rows, i, j); | ||
} | ||
@@ -194,3 +199,16 @@ } // an implementation of the sellers algorithm using damerau-levenshtein as a base | ||
function damerauLevenshteinSellers(term, candidate, rows, j) { | ||
for (var i = 0; i < term.length; i++) { | ||
// if j === 0, we can't check for transpositions, | ||
// so use normal levenshtein instead | ||
if (j === 0) { | ||
levenshteinSellers(term, candidate, rows, j); | ||
return; | ||
} // for i === 0, we also can't check for transpositions, so calculate | ||
// the first row using normal levenshtein as well | ||
if (term.length > 0) { | ||
levCore(term, candidate, rows, 0, j); | ||
} | ||
for (var i = 1; i < term.length; i++) { | ||
var rowA = rows[i - 1]; | ||
@@ -200,10 +218,11 @@ var rowB = rows[i]; | ||
var cost = term[i] === candidate[j] ? 0 : 1; | ||
var m = void 0; | ||
var min = rowC[j] + 1; // insertion | ||
var m = void 0; // insertion | ||
if ((m = rowB[j + 1] + 1) < min) min = m; // deletion | ||
var min = rowC[j] + 1; // deletion | ||
if ((m = rowB[j] + cost) < min) min = m; // substitution | ||
if ((m = rowB[j + 1] + 1) < min) min = m; // substitution | ||
if (i > 0 && j > 0 && term[i] === candidate[j - 1] && term[i - 1] === candidate[j] && (m = rowA[j - 1] + cost) < min) min = m; | ||
if ((m = rowB[j] + cost) < min) min = m; // transposition | ||
if (term[i] === candidate[j - 1] && term[i - 1] === candidate[j] && (m = rowA[j - 1] + cost) < min) min = m; | ||
rowC[j + 1] = min; | ||
@@ -210,0 +229,0 @@ } |
{ | ||
"name": "fast-fuzzy", | ||
"version": "1.8.6", | ||
"version": "1.8.7", | ||
"description": "Fast and tiny fuzzy-search utility", | ||
@@ -5,0 +5,0 @@ "main": "lib/fuzzy.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24643
465