fix: QQ消息末尾O~/C~/0~状态标记清理更宽松正则
旧正则 \s*O~O~\s*$ 只匹配 O~O~,漏掉 O~、C~、0~ 等变体。 新正则 \s*(?:[A-Za-z0-9]~)+\s*$ 覆盖所有单/多字符+波浪线组合。 三处同步更新归一化函数: 1. _normalize_ocr_text (全局字符清理) 2. OCR原始行分割前 (split前整行清理) 3. 剪贴板行过滤 (clipboard路径清理) 4. 时间戳分割后逐片段清理 (关键修复:之前只清了分割前行,分割后片段漏了)
This commit is contained in:
+12
-8
@@ -573,8 +573,8 @@ class MessageMonitor:
|
||||
# .→ . 全角点→半角数字小数点 (0.45 → 0.45)
|
||||
text = re.sub(r'(\d)[.](\d)', r'\1.\2', text)
|
||||
|
||||
# 清理 QQ 消息末尾的状态标记(如 "0~O~"),避免污染 KB 匹配
|
||||
text = re.sub(r'\s*O~O~\s*$', '', text)
|
||||
# 清理消息末尾的状态标记(如 "0~" "O~" "C~" "0~O~"),避免污染 KB 匹配
|
||||
text = re.sub(r'\s*(?:[A-Za-z0-9]~)+\s*$', '', text)
|
||||
|
||||
return text.strip()
|
||||
|
||||
@@ -846,10 +846,10 @@ class MessageMonitor:
|
||||
return []
|
||||
self._ocr_garbage_count = 0
|
||||
self._ocr_last_text["qq"] = raw_text
|
||||
# 清理 QQ 消息末尾的状态标记(如 "0~O~"),避免污染 KB 匹配
|
||||
# 清理 QQ 消息末尾的状态标记(如 "O~" "C~" "0~O~"),避免污染 KB 匹配
|
||||
ocr_lines = []
|
||||
for l in raw_text.split('\n'):
|
||||
l = re.sub(r'\s*O~O~\s*$', '', l).strip()
|
||||
l = re.sub(r'\s*(?:[A-Za-z0-9]~)+\s*$', '', l).strip()
|
||||
if l:
|
||||
ocr_lines.append(l)
|
||||
# ⭐ debug: 记录 OCR 原始行内容,定位过滤导致空白的原因
|
||||
@@ -883,7 +883,9 @@ class MessageMonitor:
|
||||
if self._is_markdown_document(buf.strip()):
|
||||
logger.debug(f"[ocr] stage[{i}] markdown fragment skipped: {buf.strip()[:80]!r}")
|
||||
else:
|
||||
expanded.append(buf.strip())
|
||||
msg = re.sub(r'\s*(?:[A-Za-z0-9]~)+\s*$', '', buf.strip())
|
||||
if msg:
|
||||
expanded.append(msg)
|
||||
buf = ''
|
||||
else:
|
||||
buf += part
|
||||
@@ -891,7 +893,9 @@ class MessageMonitor:
|
||||
if self._is_markdown_document(buf.strip()):
|
||||
logger.debug(f"[ocr] stage[{i}] markdown fragment skipped: {buf.strip()[:80]!r}")
|
||||
else:
|
||||
expanded.append(buf.strip())
|
||||
msg = re.sub(r'\s*(?:[A-Za-z0-9]~)+\s*$', '', buf.strip())
|
||||
if msg:
|
||||
expanded.append(msg)
|
||||
ocr_lines = expanded
|
||||
texts = []
|
||||
for line in ocr_lines:
|
||||
@@ -1051,8 +1055,8 @@ class MessageMonitor:
|
||||
# ── 过滤:只返回"像用户消息"的行 ──
|
||||
sender_pattern = re.compile(r'^[\u4e00-\u9fff·A-Za-z0-9_\-]{1,10}$')
|
||||
for line in raw_lines:
|
||||
# 清理 QQ 消息末尾的状态标记(如 "0~O~"),避免污染 KB 匹配
|
||||
line = re.sub(r'\s*O~O~\s*$', '', line).strip()
|
||||
# 清理 QQ 消息末尾的状态标记(如 "O~" "C~" "0~O~"),避免污染 KB 匹配
|
||||
line = re.sub(r'\s*(?:[A-Za-z0-9]~)+\s*$', '', line).strip()
|
||||
if not line:
|
||||
continue
|
||||
# 跳过:系统消息、纯时间、纯数字、无意义短行
|
||||
|
||||
Reference in New Issue
Block a user