修复OCR残片过滤:新增表格单元格残片检测

This commit is contained in:
youpaishidifu
2026-08-20 09:38:27 +08:00
parent cf9f269eca
commit 4d14fe0bc0
+21
View File
@@ -6990,6 +6990,27 @@ class MessageMonitor:
if len(text) < 10 and text.endswith((',', '、', ',', '.')):
logger.debug(f"[ocr] 过滤器2结果: 检测到短截断片段,返回True")
return True
# ⭐ OCR残片检测:表格单元格/孤立名词短语(无主语无谓语)
# 如"端口(基岩版)"、"等级"、"评判规则"等——这些是bot回复表格内容的残片
# 特征:
# 1. 长度≤10字符(太短无法构成完整问句)
# 2. 无疑问词(用户真问句会含"吗呢多少怎么"等)
# 3. 无问号
# 4. 无动词(判断是否为名词短语)
# 5. 无主语(无人称代词)
# 放行条件:含疑问词或有问号→可能是用户真问句,不拦截
if len(text) <= 10:
_has_question_word = any(w in text for w in ('吗', '呢', '多少', '怎么', '如何', '哪', '什么', '几', '?', '?'))
_has_verb = any(v in text for v in ('怎么', '如何', '进行', '设置', '配置', '操作', '使用', '打开', '下载', '安装', '登录', '进入', '查看', '查询', '问', '找', '要', '可以', '能', '会', '请', '帮', '给', '有'))
_has_subject = any(s in text for s in ('我', '你', '他', '我们', '你们', '他们', '玩家', '用户', '管理员'))
# 无疑问词 + 无动词 或 无疑问词 + 无主语 → 可能是残片
if not _has_question_word and (not _has_verb or not _has_subject):
# 额外防御:检查是否是常见用户问句模式
_common_query = any(text.startswith(q) for q in ('怎么', '如何', '什么', '哪里', '哪个', '几', '多少', '为什么', '在哪', '如何'))
_ends_with_question = text.rstrip().endswith(('?', '?', '!', '!'))
if not _common_query and not _ends_with_question:
logger.debug(f"[ocr] 过滤器2结果: 检测到OCR残片(无疑问词+无动词/主语),返回True: {text!r}")
return True
# 括号不匹配(可能OCR截断)
# 清理末尾的不完整括号(OCR噪声),如"消息内容['"
text_clean = re.sub(r'[\[((]+$', '', text)