fix: 行合并把EasyOCR正确切分的消息错误合并\n\n根因:EasyOCR输出'没有个西瓜'+ '关于我们'是两条独立消息,\n但'没有个西瓜'不以_SENT_END结尾,被合并成'没有个西瓜,关于我们'。\n\n修复:新增'下一行保护'——若当前行后面是短消息(<12字)或包含\n昵称前缀(@/用户名开头),不合并,保留EasyOCR正确切分。\n\n场景: '没有个西瓜'(6字)→下一行'关于我们'(4字<12)→不合并\n场景: '@C418minecraft'→不合并(@开头)\n场景: '你好,'+'世界'→正常合并
This commit is contained in:
+12
-1
@@ -3400,10 +3400,21 @@ class MessageMonitor:
|
|||||||
# 它是OCR对@提及的误读残片,会被短句碎片拦截;并入会把上行用户消息污染。
|
# 它是OCR对@提及的误读残片,会被短句碎片拦截;并入会把上行用户消息污染。
|
||||||
_cjk_in_rl = sum(1 for c in rl if '\u4e00' <= c <= '\u9fff')
|
_cjk_in_rl = sum(1 for c in rl if '\u4e00' <= c <= '\u9fff')
|
||||||
_at_noise_line = ('@' in rl) and not re.search(r'[??]', rl) and _cjk_in_rl <= 4
|
_at_noise_line = ('@' in rl) and not re.search(r'[??]', rl) and _cjk_in_rl <= 4
|
||||||
|
# ⭐ 2026-08-19: 下一条是短消息/用户名前缀时不合并
|
||||||
|
# EasyOCR常把相邻用户消息切成多行(如"没有个西瓜"+"关于我们"),
|
||||||
|
# 若下一行是短句(<12字)或包含昵称前缀(/@/括号),不应并入上行。
|
||||||
|
_next_is_short_or_name = False
|
||||||
|
if i + 1 < len(ocr_lines):
|
||||||
|
_next_line = ocr_lines[i + 1].strip()
|
||||||
|
_next_cjk = sum(1 for c in _next_line if '\u4e00' <= c <= '\u9fff')
|
||||||
|
if len(_next_line) < 12 or '@' in _next_line \
|
||||||
|
or re.match(r'^[\u4e00-\u9fff]{2,8}[@,,]', _next_line) \
|
||||||
|
or re.match(r'^[/@((]', _next_line):
|
||||||
|
_next_is_short_or_name = True
|
||||||
if merged_lines and not _SENT_END.search(merged_lines[-1]) \
|
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 _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 _is_bot_reply_line and not _is_single_excl and not _prev_is_single_excl \
|
||||||
and not _at_noise_line:
|
and not _at_noise_line and not _next_is_short_or_name:
|
||||||
merged_lines[-1] = merged_lines[-1] + ',' + rl
|
merged_lines[-1] = merged_lines[-1] + ',' + rl
|
||||||
else:
|
else:
|
||||||
merged_lines.append(rl)
|
merged_lines.append(rl)
|
||||||
|
|||||||
Reference in New Issue
Block a user