From 268301c60d4a0b4e3e96127fd2173163a5ecee97 Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Fri, 14 Aug 2026 10:26:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(monitor):=20=E8=BF=87=E6=BB=A4=E5=8D=95?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E6=98=A0=E5=B0=84=E9=81=BF=E5=85=8D=E8=AF=AF?= =?UTF-8?q?=E8=BF=98=E5=8E=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - '儿' → '凵' 单字符映射导致误还原 - 输入 '亻尔个事儿' 被错误还原成 '亻凵个事儿' 修复: - _restore_radical_text() 只匹配长度 ≥ 2 的偏旁组合 - 避免单字符误匹配导致的错误还原 效果: - '亻尔个事儿' → '你个事儿' ✅ - '儿' 不再被还原成 '凵' ✅ --- monitor.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/monitor.py b/monitor.py index 8ae6680..91a1511 100644 --- a/monitor.py +++ b/monitor.py @@ -160,12 +160,16 @@ def _restore_radical_text(text: str) -> str: 例如: - '讠吾' → '语' - '亻尔' → '你' - - '默讠人' → '默认人' (部分还原) + - '彳亍' → '行' - 策略:按长度降序匹配,避免短模式误匹配。 + 策略: + - 只匹配长度 ≥ 2 的偏旁组合(避免单字符误匹配) + - 按长度降序匹配,避免短模式误匹配长模式 """ restored = text - for ocr_form, correct in sorted(_RADICAL_RESTORE_MAP.items(), key=lambda x: -len(x[0])): + # ⭐ 过滤掉单字符映射,避免误还原(如 '儿' → '凵') + multi_char_map = {k: v for k, v in _RADICAL_RESTORE_MAP.items() if len(k) >= 2} + for ocr_form, correct in sorted(multi_char_map.items(), key=lambda x: -len(x[0])): restored = restored.replace(ocr_form, correct) return restored