update CAT

This commit is contained in:
qist
2024-05-22 10:56:27 +08:00
parent 8a7360760f
commit ab6af24701
32 changed files with 1064 additions and 466 deletions
+65 -1
View File
@@ -273,8 +273,70 @@ function formatContent(content) {
.replaceAll('"', '\"')
.replaceAll(/<\/?[^>]+>/g, '');
}
/**
* 字符串相似度匹配
* @returns
*/
function lcs(str1, str2) {
if (!str1 || !str2) {
return {
length: 0,
sequence: '',
offset: 0,
};
}
var sequence = '';
var str1Length = str1.length;
var str2Length = str2.length;
var num = new Array(str1Length);
var maxlen = 0;
var lastSubsBegin = 0;
for (var i = 0; i < str1Length; i++) {
var subArray = new Array(str2Length);
for (var j = 0; j < str2Length; j++) {
subArray[j] = 0;
}
num[i] = subArray;
}
var thisSubsBegin = null;
for (i = 0; i < str1Length; i++) {
for (j = 0; j < str2Length; j++) {
if (str1[i] !== str2[j]) {
num[i][j] = 0;
} else {
if (i === 0 || j === 0) {
num[i][j] = 1;
} else {
num[i][j] = 1 + num[i - 1][j - 1];
}
if (num[i][j] > maxlen) {
maxlen = num[i][j];
thisSubsBegin = i - num[i][j] + 1;
if (lastSubsBegin === thisSubsBegin) {
// if the current LCS is the same as the last time this block ran
sequence += str1[i];
} else {
// this block resets the string builder if a different LCS is found
lastSubsBegin = thisSubsBegin;
sequence = ''; // clear it
sequence += str1.substr(lastSubsBegin, i + 1 - lastSubsBegin);
}
}
}
}
}
return {
length: maxlen,
sequence: sequence,
offset: thisSubsBegin,
};
}
let patternAli = /(https:\/\/www\.aliyundrive\.com\/s\/[^"]+|https:\/\/www\.alipan\.com\/s\/[^"]+)/
let patternQuark = /(https:\/\/pan\.quark\.cn\/s\/[^"]+)/
export {
isSub,
@@ -292,6 +354,7 @@ export {
base64Encode,
base64Decode,
patternAli,
patternQuark,
unescape,
decode,
MOBILEUA,
@@ -309,5 +372,6 @@ export {
randUUID,
formatContent,
formatUrl,
encode
encode,
lcs
};