fix: 添加平台名碎片过滤规则,拦截GitHub/gitee/gitcode+稳定版的OCR残片
问题:OCR把bot回复中的列表项(如"[√] GitHub(稳定版)")误认成用户消息 特征:含平台名+版本标识,无实质提问内容 修复:在OCR预处理阶段添加专门过滤规则 - 多checkbox+仅1个中文词 → 列表碎片 - 多平台名+无问号+中文词≤2 → 平台名堆砌 - 单checkbox+单平台名+无问号+仅1个中文词 → 单条列表项碎片 - 有问号但无实质内容 → 纯平台名碎片 测试:14个用例全部通过,不会误杀真实用户提问
This commit is contained in:
+30
@@ -3601,6 +3601,36 @@ class MessageMonitor:
|
||||
if re.search(r'\](', line):
|
||||
logger.debug(f"[{platform}] OCR 过滤: 全角括号碎片 line={line!r}")
|
||||
continue
|
||||
# ⭐ 平台名碎片:纯GitHub/gitee/gitcode+稳定版字样,无真实用户提问
|
||||
# OCR把bot回复中的列表项(如"[√] GitHub(稳定版)")误认成用户消息
|
||||
# 特征:含平台名 + "(稳定版)" / "(最新版)" / 等版本标识,无实质问句
|
||||
_platform_frag_pattern = r'\b(?:github|gitee|gitcode|gitlab)\b.*(?:稳定版|最新版|release|version)'
|
||||
if re.search(_platform_frag_pattern, line, re.IGNORECASE):
|
||||
# 进一步检查:是否只有平台碎片,没有真实用户提问
|
||||
# 提取不重复的中文词(避免"稳定版稳定版稳定版"重复计数)
|
||||
_content_words = list(set(re.findall(r'[\u4e00-\u9fff]{2,}', line)))
|
||||
_question_marks = '?' in line or '?' in line
|
||||
# 统计checkbox模式数量(如[ ]、[√])
|
||||
_checkbox_count = len(re.findall(r'\[\s*[√✗XvV ]?\s*\]', line))
|
||||
# 统计平台名出现次数
|
||||
_platform_count = len(re.findall(r'\b(?:github|gitee|gitcode)\b', line, re.I))
|
||||
# 判定规则:
|
||||
# 1. 多个checkbox + 仅1个唯一中文词 → 列表碎片
|
||||
# 2. 多个平台名 + 无问号 + 中文词≤2 → 平台名堆砌
|
||||
# 3. 单checkbox + 单平台名 + 无问号 + 仅1个中文词 → 单条列表项碎片
|
||||
if _checkbox_count >= 2 and len(_content_words) <= 1:
|
||||
logger.debug(f"[{platform}] OCR 过滤: 平台名碎片(list)+checkbox(line={line!r})")
|
||||
continue
|
||||
if _platform_count >= 2 and len(_content_words) <= 2 and not _question_marks:
|
||||
logger.debug(f"[{platform}] OCR 过滤: 平台名碎片(multi)+无问句(line={line!r})")
|
||||
continue
|
||||
if _checkbox_count >= 1 and _platform_count == 1 and not _question_marks and len(_content_words) <= 1:
|
||||
logger.debug(f"[{platform}] OCR 过滤: 平台名碎片(single)+checkbox(line={line!r})")
|
||||
continue
|
||||
# 若有问号但无实质提问内容(如"GitHub(稳定版)?"),也是残片
|
||||
if _question_marks and len(_content_words) == 0:
|
||||
logger.debug(f"[{platform}] OCR 过滤: 平台名碎片带问号(line={line!r})")
|
||||
continue
|
||||
if re.match(r'^\d{1,2}[::\s]\d{1,2}', line):
|
||||
continue
|
||||
if re.match(r'^\d{4}[/-]\d{1,2}', line):
|
||||
|
||||
Reference in New Issue
Block a user