|
|
|
|
@ -21,15 +21,13 @@ function _distance(str1, str2) {
|
|
|
|
|
if (str1 === null && str2 === null) {
|
|
|
|
|
throw 'Trying to compare two null values';
|
|
|
|
|
}
|
|
|
|
|
if (str1 === null || str2 === null)
|
|
|
|
|
return 0;
|
|
|
|
|
if (str1 === null || str2 === null) return 0;
|
|
|
|
|
str1 = String(str1);
|
|
|
|
|
str2 = String(str2);
|
|
|
|
|
const distance = levenshtein(str1, str2);
|
|
|
|
|
if (str1.length > str2.length) {
|
|
|
|
|
return 1 - distance / str1.length;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
return 1 - distance / str2.length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -40,7 +38,6 @@ function _distance(str1, str2) {
|
|
|
|
|
* @param {string} str2
|
|
|
|
|
*/
|
|
|
|
|
function levenshtein(str1, str2) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {number[]}
|
|
|
|
|
*/
|
|
|
|
|
@ -52,12 +49,10 @@ function levenshtein(str1, str2) {
|
|
|
|
|
if (i && j) {
|
|
|
|
|
if (str1.charAt(j - 1) === str2.charAt(i - 1)) {
|
|
|
|
|
value = prev;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
value = Math.min(current[j], current[j - 1], prev) + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
value = i + j;
|
|
|
|
|
}
|
|
|
|
|
prev = current[j];
|
|
|
|
|
@ -99,8 +94,7 @@ function gram_counter(value, gram_size = 2) {
|
|
|
|
|
for (i; i < grams.length; ++i) {
|
|
|
|
|
if (grams[i] in result) {
|
|
|
|
|
result[grams[i]] += 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
result[grams[i]] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -116,7 +110,6 @@ function sort_descending(a, b) {
|
|
|
|
|
}
|
|
|
|
|
/** */
|
|
|
|
|
class FuzzySet {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @default {}
|
|
|
|
|
*/
|
|
|
|
|
@ -174,8 +167,7 @@ class FuzzySet {
|
|
|
|
|
sum_of_square_gram_counts += Math.pow(gram_count, 2);
|
|
|
|
|
if (gram in this.match_dict) {
|
|
|
|
|
this.match_dict[gram].push([index, gram_count]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
this.match_dict[gram] = [[index, gram_count]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -229,8 +221,7 @@ class FuzzySet {
|
|
|
|
|
other_gram_count = this.match_dict[gram][i][1];
|
|
|
|
|
if (index in matches) {
|
|
|
|
|
matches[index] += gram_count * other_gram_count;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
matches[index] = gram_count * other_gram_count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -262,7 +253,3 @@ class FuzzySet {
|
|
|
|
|
return new_results;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|