mirror of
https://github.com/Cp0204/quark-auto-save.git
synced 2026-01-17 09:50:42 +08:00
优化中文数字的识别逻辑
This commit is contained in:
parent
fea41e76fd
commit
f0a05d5572
@ -115,6 +115,66 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 添加中文数字转阿拉伯数字的函数
|
||||||
|
function chineseToArabic(chinese) {
|
||||||
|
if (!chinese) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数字映射
|
||||||
|
const digitMap = {
|
||||||
|
'零': 0, '一': 1, '二': 2, '三': 3, '四': 4,
|
||||||
|
'五': 5, '六': 6, '七': 7, '八': 8, '九': 9,
|
||||||
|
'两': 2
|
||||||
|
};
|
||||||
|
|
||||||
|
// 单位映射
|
||||||
|
const unitMap = {
|
||||||
|
'十': 10,
|
||||||
|
'百': 100,
|
||||||
|
'千': 1000,
|
||||||
|
'万': 10000
|
||||||
|
};
|
||||||
|
|
||||||
|
// 如果是单个字符,直接返回对应数字
|
||||||
|
if (chinese.length === 1) {
|
||||||
|
if (chinese === '十') return 10;
|
||||||
|
return digitMap[chinese];
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = 0;
|
||||||
|
let section = 0;
|
||||||
|
let number = 0;
|
||||||
|
|
||||||
|
// 从左向右处理
|
||||||
|
for (let i = 0; i < chinese.length; i++) {
|
||||||
|
const char = chinese[i];
|
||||||
|
|
||||||
|
if (char in digitMap) {
|
||||||
|
number = digitMap[char];
|
||||||
|
} else if (char in unitMap) {
|
||||||
|
const unit = unitMap[char];
|
||||||
|
// 如果前面没有数字,默认为1,例如"十"表示1*10=10
|
||||||
|
section += (number || 1) * unit;
|
||||||
|
number = 0;
|
||||||
|
|
||||||
|
// 如果是万级单位,累加到结果并重置section
|
||||||
|
if (unit === 10000) {
|
||||||
|
result += section;
|
||||||
|
section = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 非法字符
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加上最后的数字和小节
|
||||||
|
result += section + number;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@ -1790,13 +1850,10 @@
|
|||||||
if (match) {
|
if (match) {
|
||||||
separatorMatch = match;
|
separatorMatch = match;
|
||||||
// 根据不同的格式,确定季序号的位置
|
// 根据不同的格式,确定季序号的位置
|
||||||
if (match[3] && match[3].match(/[一二三四五六七八九十零]/)) {
|
if (match[3] && match[3].match(/[一二三四五六七八九十百千万零两]/)) {
|
||||||
// 将中文数字转换为阿拉伯数字
|
// 将中文数字转换为阿拉伯数字
|
||||||
const chineseToNumber = {
|
const arabicNumber = chineseToArabic(match[3]);
|
||||||
'零': '0', '一': '1', '二': '2', '三': '3', '四': '4',
|
seasonNumber = arabicNumber !== null ? String(arabicNumber) : '01';
|
||||||
'五': '5', '六': '6', '七': '7', '八': '8', '九': '9', '十': '10'
|
|
||||||
};
|
|
||||||
seasonNumber = chineseToNumber[match[3]] || '01';
|
|
||||||
} else {
|
} else {
|
||||||
seasonNumber = match[3] || '01';
|
seasonNumber = match[3] || '01';
|
||||||
}
|
}
|
||||||
@ -1893,18 +1950,15 @@
|
|||||||
if (pathParts.length > 0) {
|
if (pathParts.length > 0) {
|
||||||
const lastPart = pathParts[pathParts.length - 1];
|
const lastPart = pathParts[pathParts.length - 1];
|
||||||
// 匹配中文季序号格式
|
// 匹配中文季序号格式
|
||||||
const chineseSeasonMatch = lastPart.match(/^(.*?)([\s\.\-_]+)第([一二三四五六七八九十零]+)季$/);
|
const chineseSeasonMatch = lastPart.match(/^(.*?)([\s\.\-_]+)第([一二三四五六七八九十百千万零两]+)季$/);
|
||||||
if (chineseSeasonMatch) {
|
if (chineseSeasonMatch) {
|
||||||
const showName = chineseSeasonMatch[1].trim();
|
const showName = chineseSeasonMatch[1].trim();
|
||||||
const separator = chineseSeasonMatch[2];
|
const separator = chineseSeasonMatch[2];
|
||||||
const chineseSeason = chineseSeasonMatch[3];
|
const chineseSeason = chineseSeasonMatch[3];
|
||||||
|
|
||||||
// 将中文数字转换为阿拉伯数字
|
// 将中文数字转换为阿拉伯数字
|
||||||
const chineseToNumber = {
|
const arabicNumber = chineseToArabic(chineseSeason);
|
||||||
'零': '0', '一': '1', '二': '2', '三': '3', '四': '4',
|
const seasonNumber = arabicNumber !== null ? String(arabicNumber) : '1';
|
||||||
'五': '5', '六': '6', '七': '7', '八': '8', '九': '9', '十': '10'
|
|
||||||
};
|
|
||||||
const seasonNumber = chineseToNumber[chineseSeason] || '1';
|
|
||||||
|
|
||||||
// 更新最末级目录为标准格式
|
// 更新最末级目录为标准格式
|
||||||
pathParts[pathParts.length - 1] = showName + separator + 'S' + seasonNumber.padStart(2, '0');
|
pathParts[pathParts.length - 1] = showName + separator + 'S' + seasonNumber.padStart(2, '0');
|
||||||
|
|||||||
@ -454,7 +454,7 @@ def chinese_to_arabic(chinese):
|
|||||||
digit_map = {
|
digit_map = {
|
||||||
'零': 0, '一': 1, '二': 2, '三': 3, '四': 4,
|
'零': 0, '一': 1, '二': 2, '三': 3, '四': 4,
|
||||||
'五': 5, '六': 6, '七': 7, '八': 8, '九': 9,
|
'五': 5, '六': 6, '七': 7, '八': 8, '九': 9,
|
||||||
'两': 2, '十': 10
|
'两': 2
|
||||||
}
|
}
|
||||||
|
|
||||||
# 单位映射
|
# 单位映射
|
||||||
@ -467,38 +467,37 @@ def chinese_to_arabic(chinese):
|
|||||||
|
|
||||||
# 如果是单个字符,直接返回对应数字
|
# 如果是单个字符,直接返回对应数字
|
||||||
if len(chinese) == 1:
|
if len(chinese) == 1:
|
||||||
|
if chinese == '十':
|
||||||
|
return 10
|
||||||
return digit_map.get(chinese)
|
return digit_map.get(chinese)
|
||||||
|
|
||||||
# 如果只有"十"
|
|
||||||
if chinese == '十':
|
|
||||||
return 10
|
|
||||||
|
|
||||||
result = 0
|
result = 0
|
||||||
temp = 0
|
section = 0
|
||||||
unit = 1
|
number = 0
|
||||||
|
|
||||||
# 从右向左处理
|
# 从左向右处理
|
||||||
for i in range(len(chinese) - 1, -1, -1):
|
for i in range(len(chinese)):
|
||||||
char = chinese[i]
|
char = chinese[i]
|
||||||
|
|
||||||
# 处理数字
|
if char in digit_map:
|
||||||
if char in digit_map and char != '十':
|
number = digit_map[char]
|
||||||
temp = digit_map[char]
|
|
||||||
result += temp * unit
|
|
||||||
unit = 1 # 重置单位
|
|
||||||
# 处理单位
|
|
||||||
elif char in unit_map:
|
elif char in unit_map:
|
||||||
if char == '十' and i == 0: # 处理"十X"的情况
|
unit = unit_map[char]
|
||||||
result += 10 + digit_map.get(chinese[1], 0)
|
# 如果前面没有数字,默认为1,例如"十"表示1*10=10
|
||||||
break
|
section += (number or 1) * unit
|
||||||
else:
|
number = 0
|
||||||
unit = unit_map[char]
|
|
||||||
if i == 0: # 如果单位在最前面,如"十三",则前面默认为1
|
# 如果是万级单位,累加到结果并重置section
|
||||||
result += unit
|
if unit == 10000:
|
||||||
|
result += section
|
||||||
|
section = 0
|
||||||
else:
|
else:
|
||||||
# 非法字符
|
# 非法字符
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# 加上最后的数字和小节
|
||||||
|
result += section + number
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# 兼容青龙
|
# 兼容青龙
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user