fix: Task #1595 修复UI时间戳误检导致消息误丢弃

问题:OCR抓取配置面板+用户消息+UI时间戳时,_is_noise_text因检测到多条key:value而丢弃整段文本,包括其中的用户消息

修复:在噪声检测中添加用户消息特征豁免
- 包含@提及(如@利)→ 不丢弃
- 包含疑问词(吗呢多少怎么如何哪什么几)→ 不丢弃
- 包含明确查询意图(查/问/看+插件/功能/命令等)→ 不丢弃

应用场景:
- 配置面板显示+用户提问混排
- UI时间戳被OCR抓取粘连到文本末尾
- 避免误杀真实用户消息
This commit is contained in:
youpaishidifu
2026-08-24 18:03:09 +08:00
parent ab598087ad
commit 1b36d92909
+46 -9
View File
@@ -7536,15 +7536,40 @@ class MessageMonitor:
_json_content = _json_match.group(0)
_kv_pattern = re.search(r'["\']?\w+["\']?\s*[::]\s*["\']?[^"\']+["\']?', _json_content)
if _kv_pattern:
logger.debug(f"[ocr] 过滤器2结果: 检测到JSON配置文件格式,返回True: {text!r}")
return True
# ⭐ Task #1595: 检查用户消息特征
_has_user_msg_feature = '@' in text and re.search(r'@\w+', text)
_has_user_msg_feature |= any(q in text for q in ['?', '?', '吗', '呢', '多少', '怎么', '如何', '哪', '什么', '几'])
if _has_user_msg_feature:
logger.debug(f"[ocr] 过滤器2结果: 检测到JSON但含用户消息特征,继续检查: {text[:80]!r}")
else:
logger.debug(f"[ocr] 过滤器2结果: 检测到JSON配置文件格式,返回True: {text!r}")
return True
# 2. 检测key:value对格式:至少两个冒号分隔的键值对
_colon_pattern = r'[\u4e00-\u9fff]{2,10}\s*[::]\s*\S+'
_colon_matches = re.findall(_colon_pattern, text)
if len(_colon_matches) >= 2:
# 多条key:value拼接(如"图标: potato 标题:自杀")
logger.debug(f"[ocr] 过滤器2结果: 检测到多条配置文件格式({len(_colon_matches)}条key:value),返回True: {text!r}")
return True
# ⭐ Task #1595 修复:配置面板+用户消息混排场景
# OCR可能把"配置面板 + 用户消息 + UI时间戳"拼成一行
# 例:"图标:potato标题:自杀...近期公告游戏专用<>有人@利17:36:25"
# 如果直接丢弃整段,会误杀其中的用户消息
# 检查是否有用户消息特征(@提及、疑问词、明确提问)
_has_user_msg_feature = False
# 特征1: @提及(用户@他人或@机器人)
if '@' in text and re.search(r'@\w+', text):
_has_user_msg_feature = True
# 特征2: 疑问词(吗呢多少怎么如何哪什么几)
if any(q in text for q in ['?', '?', '吗', '呢', '多少', '怎么', '如何', '哪', '什么', '几']):
_has_user_msg_feature = True
# 特征3: 明确的查询意图词(查/问/看/有/在哪/如何/怎么)
if re.search(r'[查问看].*(?:插件|功能|命令|模式|系统|公告|信息)', text):
_has_user_msg_feature = True
if _has_user_msg_feature:
# 包含用户消息特征,不丢弃,继续后续检查
logger.debug(f"[ocr] 过滤器2结果: 检测到多条key:value但含用户消息特征(@提及/疑问词),继续检查: {text[:80]!r}")
else:
# 纯配置文本,丢弃
logger.debug(f"[ocr] 过滤器2结果: 检测到多条配置文件格式({len(_colon_matches)}条key:value),返回True: {text!r}")
return True
elif len(_colon_matches) == 1:
# 单条key:value,检查是否为完整的一条(无多余字符)
_colon_match = re.match(r'^[\u4e00-\u9fff]{2,10}\s*[::]\s*\S+$', text)
@@ -7555,14 +7580,26 @@ class MessageMonitor:
_eq_pattern = r'[\u4e00-\u9fff]{2,10}\s*=\s*\S+'
_eq_matches = re.findall(_eq_pattern, text)
if len(_eq_matches) >= 2:
logger.debug(f"[ocr] 过滤器2结果: 检测到等号分隔的配置文件格式({len(_eq_matches)}条key=value),返回True: {text!r}")
return True
# ⭐ Task #1595: 检查用户消息特征
_has_user_msg_feature = '@' in text and re.search(r'@\w+', text)
_has_user_msg_feature |= any(q in text for q in ['?', '?', '吗', '呢', '多少', '怎么', '如何', '哪', '什么', '几'])
if _has_user_msg_feature:
logger.debug(f"[ocr] 过滤器2结果: 检测到等号配置但含用户消息特征,继续检查: {text[:80]!r}")
else:
logger.debug(f"[ocr] 过滤器2结果: 检测到等号分隔的配置文件格式({len(_eq_matches)}条key=value),返回True: {text!r}")
return True
# 4. 检测YAML/INI格式:行首为key,后跟冒号或等号
_yaml_ini_pattern = r'^[\u4e00-\u9fff]{2,10}\s*[:=]\s*\S+'
_yaml_ini_matches = re.findall(_yaml_ini_pattern, text, re.MULTILINE)
if len(_yaml_ini_matches) >= 2:
logger.debug(f"[ocr] 过滤器2结果: 检测到YAML/INI配置文件格式({len(_yaml_ini_matches)}行),返回True: {text!r}")
return True
# ⭐ Task #1595: 检查用户消息特征
_has_user_msg_feature = '@' in text and re.search(r'@\w+', text)
_has_user_msg_feature |= any(q in text for q in ['?', '?', '吗', '呢', '多少', '怎么', '如何', '哪', '什么', '几'])
if _has_user_msg_feature:
logger.debug(f"[ocr] 过滤器2结果: 检测到YAML/INI但含用户消息特征,继续检查: {text[:80]!r}")
else:
logger.debug(f"[ocr] 过滤器2结果: 检测到YAML/INI配置文件格式({len(_yaml_ini_matches)}行),返回True: {text!r}")
return True
# ⭐ 闲聊消息检测(2026-08-22 新增)
# 特征:短文本 + 疑问词 + 无具体查询主题