fix: 偏旁替换改为偏旁丢弃 + 英文配置乱码过滤
- 偏旁过滤逻辑:从'替换为补充字符'改为'包含偏旁字符就丢弃' 修复'法'被OCR拆成'氵去'后替换为'河去'的问题 - 新增英文配置格式+乱码过滤:拦截 key=value 后跟乱码的模式 如 'invite referral bonus=5a激<5' - OCR级和Poll级同步更新偏旁过滤和乱码过滤规则
This commit is contained in:
+39
-20
@@ -1997,6 +1997,21 @@ class MessageMonitor:
|
|||||||
logger.debug(f"[{platform}] OCR 过滤: 生僻字/罕见字 line={line!r}")
|
logger.debug(f"[{platform}] OCR 过滤: 生僻字/罕见字 line={line!r}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# —— 英文配置格式+乱码过滤:key=value 或 key: value 后跟乱码 ——
|
||||||
|
# 如 "invite referral bonus=5a激<5"、"config=file.txt乱码"
|
||||||
|
if re.search(r'[a-zA-Z_]{2,}\s*[=:]\s*\S+', line):
|
||||||
|
# 检查是否包含乱码特征:特殊字符、数字字母混合、非正常英文单词
|
||||||
|
乱码特征 = False
|
||||||
|
# 特征1:等号或冒号后包含特殊字符(<>!@#$%^&*等)
|
||||||
|
if re.search(r'[=:]\s*[a-zA-Z0-9]*[<>!@#$%^&*()\[\]{}|\\/:;\'",.?~`]+', line):
|
||||||
|
乱码特征 = True
|
||||||
|
# 特征2:等号或冒号后包含数字字母混合但无空格(如"5a激<5")
|
||||||
|
if re.search(r'[=:]\s*[a-zA-Z0-9]{3,}[^\s,.;:!?。,;:!?\u4e00-\u9fff]', line):
|
||||||
|
乱码特征 = True
|
||||||
|
if 乱码特征:
|
||||||
|
logger.debug(f"[{platform}] OCR 过滤: 英文配置+乱码 line={line!r}")
|
||||||
|
continue
|
||||||
|
|
||||||
# —— 系统配置内容过滤:Wiki/文档页面内容 ——
|
# —— 系统配置内容过滤:Wiki/文档页面内容 ——
|
||||||
if re.search(r'概览|数据看板|在线玩家|注册用户|活跃玩家|玩家数据', line):
|
if re.search(r'概览|数据看板|在线玩家|注册用户|活跃玩家|玩家数据', line):
|
||||||
logger.debug(f"[{platform}] OCR 过滤: 系统配置内容(Wiki) line={line!r}")
|
logger.debug(f"[{platform}] OCR 过滤: 系统配置内容(Wiki) line={line!r}")
|
||||||
@@ -2069,17 +2084,12 @@ class MessageMonitor:
|
|||||||
logger.debug(f"[{platform}] OCR 过滤: 结构化面板 line={line!r}")
|
logger.debug(f"[{platform}] OCR 过滤: 结构化面板 line={line!r}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# —— OCR 偏旁碎片过滤:替换偏旁为正确汉字 ——
|
# —— OCR 偏旁碎片过滤:包含偏旁字符就丢弃 ——
|
||||||
# 如果偏旁有补充字符(非空)→ 替换为补充字符,继续处理
|
# 偏旁字符(U+2E80-U+2FDF)在正常中文聊天中不会出现
|
||||||
# 如果偏旁无补充字符(空)→ 整段丢弃
|
# OCR 拆字碎片如"亻牛""彡"只要出现就是碎片
|
||||||
line_replaced, discard = _replace_radicals(line)
|
if any(ch in _RADICAL_MAP for ch in line):
|
||||||
if discard:
|
logger.debug(f"[{platform}] OCR 过滤: 包含偏旁字符(丢弃) line={line!r}")
|
||||||
logger.debug(f"[{platform}] OCR 过滤: 偏旁无补充字符(丢弃) line={line!r}")
|
|
||||||
continue
|
continue
|
||||||
if line_replaced != line:
|
|
||||||
# 有偏旁被替换,使用替换后的文本继续处理
|
|
||||||
logger.debug(f"[{platform}] OCR 偏旁替换: {line!r} → {line_replaced!r}")
|
|
||||||
line = line_replaced
|
|
||||||
# —— 系统配置内容过滤:SMTP/邮件地址/代码片段不是用户消息 ——
|
# —— 系统配置内容过滤:SMTP/邮件地址/代码片段不是用户消息 ——
|
||||||
if re.search(r'@example|smtp|\.py\b|\.bat\b|\.sh\b|//.*\.\w{2,4}\b', line, re.IGNORECASE):
|
if re.search(r'@example|smtp|\.py\b|\.bat\b|\.sh\b|//.*\.\w{2,4}\b', line, re.IGNORECASE):
|
||||||
logger.debug(f"[{platform}] OCR 过滤: 系统配置内容 line={line!r}")
|
logger.debug(f"[{platform}] OCR 过滤: 系统配置内容 line={line!r}")
|
||||||
@@ -3748,6 +3758,20 @@ class MessageMonitor:
|
|||||||
if cjk > 0 and cjk / max(len(ts), 1) < 0.15:
|
if cjk > 0 and cjk / max(len(ts), 1) < 0.15:
|
||||||
logger.debug(f"[{platform}] Poll过滤: CJK比例过低乱码 ts={ts!r}")
|
logger.debug(f"[{platform}] Poll过滤: CJK比例过低乱码 ts={ts!r}")
|
||||||
continue
|
continue
|
||||||
|
# === 英文配置格式+乱码过滤:key=value 或 key: value 后跟乱码 ===
|
||||||
|
# 如 "invite referral bonus=5a激<5"、"config=file.txt乱码"
|
||||||
|
if re.search(r'[a-zA-Z_]{2,}\s*[=:]\s*\S+', ts):
|
||||||
|
# 检查是否包含乱码特征:特殊字符、数字字母混合、非正常英文单词
|
||||||
|
乱码特征 = False
|
||||||
|
# 特征1:等号或冒号后包含特殊字符(<>!@#$%^&*等)
|
||||||
|
if re.search(r'[=:]\s*[a-zA-Z0-9]*[<>!@#$%^&*()\[\]{}|\\/:;\'",.?~`]+', ts):
|
||||||
|
乱码特征 = True
|
||||||
|
# 特征2:等号或冒号后包含数字字母混合但无空格(如"5a激<5")
|
||||||
|
if re.search(r'[=:]\s*[a-zA-Z0-9]{3,}[^\s,.;:!?。,;:!?\u4e00-\u9fff]', ts):
|
||||||
|
乱码特征 = True
|
||||||
|
if 乱码特征:
|
||||||
|
logger.debug(f"[{platform}] Poll过滤: 英文配置+乱码 ts={ts!r}")
|
||||||
|
continue
|
||||||
# === 斜线英文命令碎片:"/sdfl undo撤销导入" 命令帮助碎片 ===
|
# === 斜线英文命令碎片:"/sdfl undo撤销导入" 命令帮助碎片 ===
|
||||||
if re.match(r'^/[A-Za-z]', ts):
|
if re.match(r'^/[A-Za-z]', ts):
|
||||||
logger.debug(f"[{platform}] Poll过滤: 斜线英文命令 ts={ts!r}")
|
logger.debug(f"[{platform}] Poll过滤: 斜线英文命令 ts={ts!r}")
|
||||||
@@ -3779,17 +3803,12 @@ class MessageMonitor:
|
|||||||
if len(colon_kv) >= 3:
|
if len(colon_kv) >= 3:
|
||||||
logger.debug(f"[{platform}] Poll过滤: 结构化面板 ts={ts!r}")
|
logger.debug(f"[{platform}] Poll过滤: 结构化面板 ts={ts!r}")
|
||||||
continue
|
continue
|
||||||
# === 偏旁碎片过滤:替换偏旁为正确汉字 ===
|
# === 偏旁碎片过滤:包含偏旁字符就丢弃 ===
|
||||||
# 如果偏旁有补充字符(非空)→ 替换为补充字符,继续处理
|
# 偏旁字符(U+2E80-U+2FDF)在正常中文聊天中不会出现
|
||||||
# 如果偏旁无补充字符(空)→ 整段丢弃
|
# OCR 拆字碎片如"亻牛""彡"只要出现就是碎片
|
||||||
ts_replaced, discard = _replace_radicals(ts)
|
if any(ch in _RADICAL_MAP for ch in ts):
|
||||||
if discard:
|
logger.debug(f"[{platform}] Poll过滤: 包含偏旁字符(丢弃) ts={ts!r}")
|
||||||
logger.debug(f"[{platform}] Poll过滤: 偏旁无补充字符(丢弃) ts={ts!r}")
|
|
||||||
continue
|
continue
|
||||||
if ts_replaced != ts:
|
|
||||||
# 有偏旁被替换,使用替换后的文本继续处理
|
|
||||||
logger.debug(f"[{platform}] Poll偏旁替换: {ts!r} → {ts_replaced!r}")
|
|
||||||
ts = ts_replaced
|
|
||||||
# === 系统配置内容过滤:SMTP/邮件地址/代码片段不是用户消息 ===
|
# === 系统配置内容过滤:SMTP/邮件地址/代码片段不是用户消息 ===
|
||||||
if re.search(r'@example|smtp|\.py\b|\.bat\b|\.sh\b|//.*\.\w{2,4}\b', ts, re.IGNORECASE):
|
if re.search(r'@example|smtp|\.py\b|\.bat\b|\.sh\b|//.*\.\w{2,4}\b', ts, re.IGNORECASE):
|
||||||
logger.debug(f"[{platform}] Poll过滤: 系统配置内容 ts={ts!r}")
|
logger.debug(f"[{platform}] Poll过滤: 系统配置内容 ts={ts!r}")
|
||||||
|
|||||||
Reference in New Issue
Block a user