fix: 增强偏旁碎片过滤 + 系统配置内容过滤
1. 偏旁碎片过滤增强: - 去掉长度限制(原≤20字),只要包含CJK偏旁(U+2E80-U+2FDF)且偏旁数>=CJK完整字数就过滤 - 覆盖OCR把'件'拆成'亻牛'等更长碎片的情况 2. 系统配置内容过滤(新增): - 检测包含@example、smtp、.py/.bat/.sh等特征的行,判定为系统配置内容 - 检测邮件地址格式(user@domain.tld),判定为SMTP配置片段 - 防止OCR截屏截到代码编辑器/终端内容被当用户消息处理 3. 同步更新OCR级和Poll级过滤逻辑
This commit is contained in:
+22
-6
@@ -1874,12 +1874,20 @@ class MessageMonitor:
|
||||
|
||||
# —— OCR 偏旁碎片过滤:氵、亻、讠、扌等 CJK 偏旁不是完整汉字 ——
|
||||
# CJK 偏旁部首 Unicode: U+2E80-U+2FDF (CJK Radicals Supplement + Kangxi Radicals)
|
||||
if len(line) <= 20:
|
||||
radical_cnt = sum(1 for c in line if '\u2e80' <= c <= '\u2fdf')
|
||||
# 正常用户消息几乎不含这些偏旁字符,只要出现就判定为OCR碎片
|
||||
radical_cnt = sum(1 for c in line if '\u2e80' <= c <= '\u2fdf')
|
||||
if radical_cnt > 0:
|
||||
cjk_cnt = sum(1 for c in line if '\u4e00' <= c <= '\u9fff')
|
||||
if radical_cnt > 0 and cjk_cnt <= radical_cnt:
|
||||
if cjk_cnt <= radical_cnt:
|
||||
logger.debug(f"[{platform}] OCR 过滤: 偏旁碎片(radical={radical_cnt},cjk={cjk_cnt}) line={line!r}")
|
||||
continue
|
||||
# —— 系统配置内容过滤:SMTP/邮件地址/代码片段不是用户消息 ——
|
||||
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}")
|
||||
continue
|
||||
if re.search(r'@\w+\.\w{2,4}[,.\s]', line) and re.search(r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}', line):
|
||||
logger.debug(f"[{platform}] OCR 过滤: 邮件地址格式 line={line!r}")
|
||||
continue
|
||||
|
||||
# —— OCR 短句/病句检测:OCR 把消息"嚼碎"生成碎片 ——
|
||||
# 通用疑问词(有这些词说明有查询意向,放行)
|
||||
@@ -3599,12 +3607,20 @@ class MessageMonitor:
|
||||
logger.debug(f"[{platform}] Poll过滤: 结构化面板 ts={ts!r}")
|
||||
continue
|
||||
# === 偏旁碎片过滤:氵、亻、讠、扌等 CJK 偏旁不是完整汉字 ===
|
||||
if len(ts) <= 20:
|
||||
radical_cnt = sum(1 for c in ts if '\u2e80' <= c <= '\u2fdf')
|
||||
# 正常用户消息几乎不含这些偏旁字符,只要出现就判定为OCR碎片
|
||||
radical_cnt = sum(1 for c in ts if '\u2e80' <= c <= '\u2fdf')
|
||||
if radical_cnt > 0:
|
||||
cjk_cnt = sum(1 for c in ts if '\u4e00' <= c <= '\u9fff')
|
||||
if radical_cnt > 0 and cjk_cnt <= radical_cnt:
|
||||
if cjk_cnt <= radical_cnt:
|
||||
logger.debug(f"[{platform}] Poll过滤: 偏旁碎片(radical={radical_cnt},cjk={cjk_cnt}) ts={ts!r}")
|
||||
continue
|
||||
# === 系统配置内容过滤:SMTP/邮件地址/代码片段不是用户消息 ===
|
||||
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}")
|
||||
continue
|
||||
if re.search(r'@\w+\.\w{2,4}[,.\s]', ts) and re.search(r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}', ts):
|
||||
logger.debug(f"[{platform}] Poll过滤: 邮件地址格式 ts={ts!r}")
|
||||
continue
|
||||
# === 游戏UI乱码:CJK+下划线英文、CJK+大写英文组合 → 非聊天文本 ===
|
||||
if re.search(r'[\u4e00-\u9fff]', ts) and re.search(r'[A-Za-z]', ts) and len(ts) > 10:
|
||||
if re.search(r'[a-zA-Z]+_[a-zA-Z]+', ts):
|
||||
|
||||
Reference in New Issue
Block a user