fix(msgbot): 强化OCR逗号断行合并——前一行以逗号结尾时忽略下一行短句/问号特征强制合并
- EasyOCR常在中文逗号处拆行,导致"兑换码插件导入错误,怎么处置?"被分成两段 - 修复1:前一行以逗号结尾时,即使下一行含问号,也合并(逗号是停顿,不是消息边界) - 修复2:前一行以逗号结尾时,忽略下一行短句/名字特征强制合并 - 原因:逗号是用户日常发言的停顿或语句分割,不应作为消息边界 EOF )
This commit is contained in:
+7
-2
@@ -3584,7 +3584,11 @@ class MessageMonitor:
|
||||
for i, rl in enumerate(ocr_lines):
|
||||
# 当前行含疑问特征(裸@末尾或问号)→ 不合并,防止用户问句被黏进bot回复
|
||||
if rl.endswith('@') or re.search(r'[??]', rl):
|
||||
merged_lines.append(rl)
|
||||
# ⭐ 2026-08-29: 如果前一行以逗号结尾,合并——逗号是停顿,不是消息边界
|
||||
if merged_lines and merged_lines[-1].rstrip().endswith((',', ',')):
|
||||
merged_lines[-1] = merged_lines[-1] + ',' + rl
|
||||
else:
|
||||
merged_lines.append(rl)
|
||||
continue
|
||||
# ⭐ Task #1555: 若当前行是已知bot回复内容,不合并到下一行
|
||||
# 防止 "用户问句 + bot回复" 合并后污染消息
|
||||
@@ -3615,10 +3619,11 @@ class MessageMonitor:
|
||||
or re.match(r'^[\u4e00-\u9fff]{2,8}[@,,]', _next_line) \
|
||||
or re.match(r'^[/@((]', _next_line):
|
||||
_next_is_short_or_name = True
|
||||
_prev_ends_with_comma = merged_lines[-1].rstrip().endswith((',', ','))
|
||||
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:
|
||||
and not _at_noise_line and (not _next_is_short_or_name or _prev_ends_with_comma):
|
||||
merged_lines[-1] = merged_lines[-1] + ',' + rl
|
||||
else:
|
||||
merged_lines.append(rl)
|
||||
|
||||
Reference in New Issue
Block a user