decord/alpha/source/modules/search/StringMatchUtils.tsx

161 lines
4.2 KiB
TypeScript
Raw Permalink Normal View History

2026-10-13 12:43:34 +00:00
// Module ID: 15298
// Function ID: 15299
// Name: StringMatchUtils
2026-07-23 10:11:24 +00:00
// Dependencies: [2]
2026-07-20 16:05:17 +00:00
// Exports: calculateJaroWinklerSimilarity
2026-10-13 12:43:34 +00:00
// Module 15298 (StringMatchUtils)
import size from "module_2" /* 2 */;
2026-08-24 06:08:38 +00:00
function calculateJaroWinklerDistance(formatted, item) {
const diff = Math.floor(Math.max(formatted.length, item.length) / 2) - 1;
2026-07-20 16:05:17 +00:00
const items = [];
let num = 0;
let num2 = 0;
let num3 = 0;
if (0 < formatted.length) {
do {
let _Math = Math;
2026-07-29 08:29:29 +00:00
let bound = Math.max(0, num - diff);
2026-07-20 16:05:17 +00:00
let _Math2 = Math;
2026-07-29 08:29:29 +00:00
let sum = num + diff;
let sum1 = num2;
if (bound <= Math.min(item.length, sum)) {
2026-07-20 16:05:17 +00:00
while (true) {
if (formatted[num] === item[bound]) {
2026-07-20 16:05:17 +00:00
if (!items[bound]) {
break;
}
}
bound = bound + 1;
let _Math3 = Math;
2026-07-29 08:29:29 +00:00
sum1 = num2;
2026-07-20 16:05:17 +00:00
}
items[bound] = true;
2026-07-29 08:29:29 +00:00
sum1 = num2 + 1;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
num = num + 1;
num2 = sum1;
num3 = sum1;
} while (num < formatted.length);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (0 < num3) {
2026-07-20 16:05:17 +00:00
const _Math4 = Math;
const _Math5 = Math;
const diff1 = Math.floor(Math.max(formatted.length, item.length) / 2) - 1;
2026-07-20 16:05:17 +00:00
const items1 = [];
2026-07-29 08:29:29 +00:00
let str2 = "";
let num4 = 0;
let str3 = "";
if (0 < formatted.length) {
do {
let _Math6 = Math;
let bound1 = Math.max(0, num4 - diff1);
let _Math7 = Math;
let sum2 = num4 + diff1;
let sum3 = str2;
if (bound1 <= Math.min(item.length, sum2)) {
2026-07-29 08:29:29 +00:00
while (true) {
if (formatted[num4] === item[bound1]) {
2026-07-29 08:29:29 +00:00
if (!items1[bound1]) {
break;
}
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
bound1 = bound1 + 1;
let _Math8 = Math;
sum3 = str2;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
sum3 = str2 + formatted[num4];
items1[bound1] = true;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
num4 = num4 + 1;
str2 = sum3;
str3 = sum3;
} while (num4 < formatted.length);
2026-07-20 16:05:17 +00:00
}
const items2 = [];
2026-07-29 08:29:29 +00:00
let str4 = "";
let num5 = 0;
let str5 = "";
if (0 < item.length) {
2026-07-29 08:29:29 +00:00
do {
let _Math9 = Math;
let bound2 = Math.max(0, num5 - diff1);
let _Math10 = Math;
let sum4 = num5 + diff1;
let sum5 = str4;
if (bound2 <= Math.min(formatted.length, sum4)) {
while (true) {
if (item[num5] === formatted[bound2]) {
2026-07-29 08:29:29 +00:00
if (!items2[bound2]) {
break;
}
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
bound2 = bound2 + 1;
let _Math11 = Math;
sum5 = str4;
2026-07-20 16:05:17 +00:00
}
sum5 = str4 + item[num5];
2026-07-29 08:29:29 +00:00
items2[bound2] = true;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
num5 = num5 + 1;
str4 = sum5;
str5 = sum5;
} while (num5 < item.length);
2026-07-20 16:05:17 +00:00
}
let num6 = 0;
let num7 = 0;
let num8 = 0;
2026-07-29 08:29:29 +00:00
if (0 < str3.length) {
2026-07-20 16:05:17 +00:00
do {
2026-07-29 08:29:29 +00:00
let sum6 = num7;
if (str3[num6] !== str5[num6]) {
sum6 = num7 + 1;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
num6 = num6 + 1;
num7 = sum6;
num8 = sum6;
} while (num6 < str3.length);
2026-07-20 16:05:17 +00:00
}
const _Math12 = Math;
const result = (num3 / formatted.length + num3 / item.length + (num3 - Math.floor(num8 / 2)) / num3) / 3;
2026-07-20 16:05:17 +00:00
let num12 = 0;
if (result < 0.7) {
return result;
} else {
2026-07-29 08:29:29 +00:00
let sum8 = num12;
while (formatted[num12] === item[num12]) {
2026-07-29 08:29:29 +00:00
let sum7 = num12 + 1;
num12 = sum7;
if (sum7 < 4) {
2026-07-20 16:05:17 +00:00
continue;
} else {
2026-07-29 08:29:29 +00:00
sum8 = sum7 + 1;
2026-07-23 10:11:24 +00:00
break;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return result + 0.1 * sum8 * (1 - result);
2026-07-20 16:05:17 +00:00
}
}
} else {
return 0;
}
}
let result = size.fileFinishedImporting("modules/search/StringMatchUtils.tsx");
2026-07-20 16:05:17 +00:00
export const calculateJaroWinklerSimilarity = function calculateJaroWinklerSimilarity(toLocaleLowerCaseResult, item, arg2) {
2026-07-20 16:05:17 +00:00
let obj = arg2;
2026-07-29 08:29:29 +00:00
if (arg2 == null) {
2026-07-20 16:05:17 +00:00
obj = {};
}
const caseSensitive = obj.caseSensitive;
if (undefined !== caseSensitive) {
2026-10-03 08:58:59 +00:00
let tmp2;
2026-07-20 16:05:17 +00:00
if (caseSensitive) {
2026-10-03 08:58:59 +00:00
tmp2 = calculateJaroWinklerDistance(toLocaleLowerCaseResult, item);
2026-07-20 16:05:17 +00:00
}
return tmp2;
}
const formatted = toLocaleLowerCaseResult.toLowerCase();
tmp2 = calculateJaroWinklerDistance(formatted, item.toLowerCase());
2026-07-20 16:05:17 +00:00
};