fix(Task#1600): _is_noise_text新增Markdown表格管道残留检测

QQ渲染的md表格(|日期|内容|...)被OCR抓取后,管道符结构未被is_noise_text识别,
导致表格碎片通过预分割管道进入KB搜索触发误回复。

修复:在过滤器2中新增管道残留检测:
- 模式A: 以|开头 + 2+管道符 → 整行表格片段
- 模式B: 3+管道符 + 含CJK → 截断表格片段
- 豁免: 含疑问词(?) → 可能是用户讨论表格语法
This commit is contained in:
youpaishidifu
2026-08-24 22:54:59 +08:00
parent 5952b8672c
commit bdb4e5c168
+17
View File
@@ -7738,6 +7738,23 @@ class MessageMonitor:
if re.search(r'<\s*(?:br|p|div|span|a|img)\s*/?\s*>', text, re.IGNORECASE): if re.search(r'<\s*(?:br|p|div|span|a|img)\s*/?\s*>', text, re.IGNORECASE):
logger.debug(f"[ocr] 过滤器2结果: 检测到HTML标签,返回True") logger.debug(f"[ocr] 过滤器2结果: 检测到HTML标签,返回True")
return True return True
# ⭐ Task #1600: Markdown表格管道符残留(QQ渲染md表格被OCR抓取)
# 特征1:以 | 开头的表格行片段(| 日期 | 内容 | ...),含2+个管道符
# 特征2:含CJK的文本中有3+个管道符(表格被拆分/截断后可能不以|开头)
# 正常用户聊天从不以 | 开头,也不使用 | 作为文本分隔符
# 排除:含疑问词 → 可能是用户讨论表格/管道符语法
_pipe_count = text.count('|')
if _pipe_count >= 2:
_has_q = any(q in text for q in ('?', '?', '吗', '呢', '怎么', '如何'))
if not _has_q:
# 模式A:以 | 开头(完整表格行)
if re.match(r'^\s*\|', text):
logger.debug(f"[ocr] 过滤器2结果: 检测到Markdown表格管道残留(pipe={_pipe_count}),返回True: {text[:60]!r}")
return True
# 模式B:3+管道符 + 含CJK(截断表格片段)
if _pipe_count >= 3 and re.search(r'[\u4e00-\u9fff]', text):
logger.debug(f"[ocr] 过滤器2结果: 检测到Markdown表格管道残留(pipe={_pipe_count},CJK),返回True: {text[:60]!r}")
return True
# 图片路径引用:![](./img/...)、!0(Jimg/...)、![](...)=等 # 图片路径引用:![](./img/...)、!0(Jimg/...)、![](...)=等
if re.search(r'!\s*\[.*?\]\s*\(.*?\)', text): if re.search(r'!\s*\[.*?\]\s*\(.*?\)', text):
logger.debug(f"[ocr] 过滤器2结果: 检测到图片路径引用模式1,返回True") logger.debug(f"[ocr] 过滤器2结果: 检测到图片路径引用模式1,返回True")