From ad91b70b633e3a63f7174211435e1be77f901110 Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Wed, 16 Sep 2026 11:57:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(Task=20#1727):=20OCR=E9=A1=BF=E5=8F=B7?= =?UTF-8?q?=E6=96=AD=E8=A1=8C=E4=BF=AE=E5=A4=8D=E2=80=94=E2=80=94=E3=80=81?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E5=BD=93=E5=88=86=E9=9A=94=E7=AC=A6=EF=BC=8C?= =?UTF-8?q?=E8=A1=8C=E5=90=88=E5=B9=B6=E6=94=AF=E6=8C=81=E9=A1=BF=E5=8F=B7?= =?UTF-8?q?=E6=8B=BC=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 两处修复: 1. 表情包碎片过滤:从_delim_count正则中移除顿号、 - 顿号是中文正常标点(如恶意交易、刷量违规),不应被当作表情包碎片标志 2. 连续行合并:顿号、与逗号,同为列举连接符 - OCR在、处断行时,前行以、结尾应触发合并 - 合并时保留原顿号,不额外插入逗号 - 修复:恶意交易、刷量违规 → 被拆为两行 → 未合并 → 知识库匹配失败 --- monitor.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/monitor.py b/monitor.py index c1dae30..50e6cf5 100644 --- a/monitor.py +++ b/monitor.py @@ -4124,7 +4124,9 @@ class MessageMonitor: # QQ 表情包图片上常有文字(如"点击"、"按钮"),OCR 识别后产出 # 短文本+大量分隔符混排(如 "点击, ~按钮; ,"),不是真实用户消息。 # 判定:中文字符≤6 且 分隔符(逗号/分号/波浪号/斜杠等)≥2 → 碎片。 - _delim_count = len(re.findall(r'[,;~!@#%^&,。;~、/\\|]', l)) + # ⭐ Task #1727: 移除中文顿号"、"作为分隔符 + # 顿号是中文正常标点(如"恶意交易、刷量违规"),不应被当作表情包碎片标志 + _delim_count = len(re.findall(r'[,;~!@#%^&,。;~/\\|]', l)) _cjk_in_l = sum(1 for c in l if '\u4e00' <= c <= '\u9fff') # ⭐ Task #1510: 纯时间戳行保护。EasyOCR 时间戳常用双分号分隔(15;35;38、 # 14;08;03),含两个分隔符会被误判为表情包碎片丢弃 → 新鲜时间戳丢失, @@ -4154,8 +4156,8 @@ class MessageMonitor: logger.debug(f"[{platform}] OCR: 剥离)昵称前缀: {l[:60]!r} (短句豁免)") ocr_lines.append(l) - # —— 连续行合并(修复 EasyOCR 逗号断行) —— - # EasyOCR 对长消息在中文逗号","处拆行,导致前半句无时间戳被丢弃。 + # —— 连续行合并(修复 EasyOCR 逗号/顿号断行) —— + # EasyOCR 对长消息在中文逗号","或顿号"、"处拆行,导致前半句无时间戳被丢弃。 # 合并规则:前一行不以句末标点结尾 且 后一行不以时间戳开头 → 合并 # ⚠ 修复漏消息:前一行若本身是"时间戳行"(如 16;28:40),绝不与其后的消息合并, # 否则时间戳被黏进消息文本、re.split 错位,导致该消息被误判为尾部落入旧时间戳、 @@ -4177,8 +4179,10 @@ class MessageMonitor: # 当前行含疑问特征(裸@末尾或问号)→ 不合并,防止用户问句被黏进bot回复 if rl.endswith('@') or re.search(r'[??]', rl): # ⭐ 2026-08-29: 如果前一行以逗号结尾,合并——逗号是停顿,不是消息边界 - if merged_lines and merged_lines[-1].rstrip().endswith((',', ',')): - merged_lines[-1] = merged_lines[-1] + ',' + rl + if merged_lines and merged_lines[-1].rstrip().endswith((',', ',', '、')): + # ⭐ 顿号结尾时直接拼接(保留原顿号),逗号结尾时插入逗号 + _sep = '' if merged_lines[-1].rstrip().endswith('、') else ',' + merged_lines[-1] = merged_lines[-1] + _sep + rl else: merged_lines.append(rl) continue @@ -4214,12 +4218,17 @@ class MessageMonitor: # ⭐ Task #1622: 必须先判断 merged_lines 非空,否则首行不以@结尾/不含问号/ # 非bot回复时 merged_lines[-1] 抛 IndexError → 被最外层 except 捕获成 # [qq] OCR失败: list index out of range - _prev_ends_with_comma = merged_lines[-1].rstrip().endswith((',', ',')) if merged_lines else False + # ⭐ Task #1727: 顿号"、"与逗号","同为列举连接符,OCR断行后也应触发合并 + # 例:OCR将"恶意交易、刷量违规"拆为"恶意交易"+"刷量违规", + # 前一行以"、"结尾时需合并回同一消息 + _prev_ends_with_comma = merged_lines[-1].rstrip().endswith((',', ',', '、')) if merged_lines else False if merged_lines and not _SENT_END.search(merged_lines[-1]) \ and not _TS_START.match(rl) and not _TS_START.match(merged_lines[-1]) \ and not _is_bot_reply_line and not _is_single_excl and not _prev_is_single_excl \ and not _at_noise_line and (not _next_is_short_or_name or _prev_ends_with_comma): - merged_lines[-1] = merged_lines[-1] + ',' + rl + # ⭐ 顿号结尾时直接拼接(保留原顿号),逗号结尾时插入逗号 + _sep = '' if merged_lines[-1].rstrip().endswith('、') else ',' + merged_lines[-1] = merged_lines[-1] + _sep + rl else: merged_lines.append(rl) if len(merged_lines) != len(ocr_lines):