Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getBestSubstringList(str1, str2, words1, threshold = 1) {
const str1len = str1.length;
const str2len = str2.length;
const result = [];
if (str1len <= str2len) {
const levenshtein = similarity(str1, str2, true);
const accuracy = (str2len - levenshtein) / str2len;
if (accuracy >= threshold) {
result.push({
start: 0,
end: str1len - 1,
len: str1len,
levenshtein,
accuracy,
});
}
return result;
}
const maxLevenshtein = str2len * (1 - threshold);
const wordPositions = words1 || this.getWordPositions(str1);
const wordPositionsLen = wordPositions.length;
for (let i = 0; i < wordPositionsLen; i += 1) {
levenshtein,
accuracy,
});
}
return result;
}
const maxLevenshtein = str2len * (1 - threshold);
const wordPositions = words1 || this.getWordPositions(str1);
const wordPositionsLen = wordPositions.length;
for (let i = 0; i < wordPositionsLen; i += 1) {
for (let j = i; j < wordPositionsLen; j += 1) {
const str3 = str1.substring(
wordPositions[i].start,
wordPositions[j].end + 1
);
const levenshtein = similarity(str3, str2, true);
const accuracy = (str2len - levenshtein) / str2len;
if (accuracy >= threshold) {
result.push({
start: wordPositions[i].start,
end: wordPositions[j].end,
len: wordPositions[j].end - wordPositions[i].start + 1,
levenshtein,
accuracy,
});
}
if (
str3.length - wordPositions[0].len >=
str2.length + maxLevenshtein
) {
break;
}
getBestSubstring(str1, str2, words1) {
const str1len = str1.length;
const str2len = str2.length;
if (str1len <= str2len) {
const result = {
start: 0,
end: str1len - 1,
len: str1len,
levenshtein: similarity(str1, str2, true),
};
result.accuracy = (str2len - result.levenshtein) / str2len;
return result;
}
const wordPositions = words1 || this.getWordPositions(str1);
const wordPositionsLen = wordPositions.length;
const best = {
start: 0,
end: 0,
len: 0,
levenshtein: undefined,
accuracy: 0,
};
for (let i = 0; i < wordPositionsLen; i += 1) {
for (let j = i; j < wordPositionsLen; j += 1) {
const str3 = str1.substring(
const wordPositions = words1 || this.getWordPositions(str1);
const wordPositionsLen = wordPositions.length;
const best = {
start: 0,
end: 0,
len: 0,
levenshtein: undefined,
accuracy: 0,
};
for (let i = 0; i < wordPositionsLen; i += 1) {
for (let j = i; j < wordPositionsLen; j += 1) {
const str3 = str1.substring(
wordPositions[i].start,
wordPositions[j].end + 1
);
const levenshtein = similarity(str3, str2, true);
if (best.levenshtein === undefined || levenshtein < best.levenshtein) {
best.levenshtein = levenshtein;
best.start = wordPositions[i].start;
best.end = wordPositions[j].end;
best.len = best.end - best.start + 1;
}
}
}
best.accuracy = (str2len - best.levenshtein) / str2len;
return best;
}