修复KB搜索质量差+增加OCR病句过滤
1. 改进内容相关性检查:高匹配度(≥10.0)但无共同词时拒绝匹配 - 用户问PVP击杀播报,KB返回json格式说明(匹配度9.53)→ 拒绝 - 增加body内容检查,防止TF-IDF误匹配 2. 增加OCR病句过滤: - 病句1:句子以动词结尾但缺少宾语(如'将其修正后重三') - 病句2:句子以'三'结尾(OCR误读'试'为'三') - 病句3:句子缺少主语且无标点 - 病句直接过滤,不触发查库
This commit is contained in:
@@ -80,15 +80,18 @@ class AutoReply:
|
||||
"""查询词与匹配文档至少有一个共同2字+词,防偶然匹配。
|
||||
短查询(≤2个2字+词)直接放行,不做严格检查。
|
||||
检查顺序:heading → title → content/body。
|
||||
高匹配度(≥10.0):如果heading+title+body都无共同词,直接拒绝。
|
||||
"""
|
||||
q_tokens = set(t for t in jieba.cut(query) if len(t) >= 2)
|
||||
if len(q_tokens) <= 2:
|
||||
return True # 短查询不拦截
|
||||
|
||||
# 1. 检查 heading + title
|
||||
doc_text = doc.get("heading", "") + " " + doc.get("title", "")
|
||||
d_tokens = set(t for t in jieba.cut(doc_text) if len(t) >= 2)
|
||||
if q_tokens & d_tokens:
|
||||
return True
|
||||
|
||||
# 2. 检查 content/body(TF-IDF匹配的段落正文)
|
||||
body = doc.get("content", "") or doc.get("body", "")
|
||||
if body:
|
||||
@@ -96,6 +99,12 @@ class AutoReply:
|
||||
b_tokens = set(t for t in jieba.cut(body[:500]) if len(t) >= 2)
|
||||
if q_tokens & b_tokens:
|
||||
return True
|
||||
|
||||
# 3. 高匹配度但无共同词:可能是TF-IDF误匹配,拒绝
|
||||
# 用户问"PVP击杀播报",KB返回"json格式说明"(匹配度9.53)→ 应拒绝
|
||||
if score >= 10.0 and not (q_tokens & d_tokens) and not (q_tokens & (b_tokens if body else set())):
|
||||
return False
|
||||
|
||||
return False
|
||||
|
||||
def _get_answer(self, platform: str, msg: str, doc: dict, score: float) -> str or None:
|
||||
|
||||
+16
@@ -1815,6 +1815,22 @@ class MessageMonitor:
|
||||
logger.debug(f"[{platform}] OCR 过滤: 结构化面板 line={line!r}")
|
||||
continue
|
||||
|
||||
# —— OCR 病句检测:OCR 把消息"嚼碎"生成病句 ——
|
||||
# 特征:句子不完整、语义不通、缺少标点、片段化
|
||||
if len(line) > 5 and len(line) < 50:
|
||||
# 病句1:句子以动词结尾但缺少宾语(如"将其修正后重三")
|
||||
if re.search(r'[后以了]+.{0,3}$', line) and not re.search(r'[。!?,,;;::?]$', line):
|
||||
logger.debug(f"[{platform}] OCR 过滤: 病句(动词结尾) line={line!r}")
|
||||
continue
|
||||
# 病句2:句子以"三"结尾(OCR误读"试"为"三")
|
||||
if re.search(r'重三$', line):
|
||||
logger.debug(f"[{platform}] OCR 过滤: 病句(重三) line={line!r}")
|
||||
continue
|
||||
# 病句3:句子缺少主语且无标点(如"将其修正后重三")
|
||||
if re.match(r'^[其将把被]', line) and not re.search(r'[。!?,,;;::?]$', line):
|
||||
logger.debug(f"[{platform}] OCR 过滤: 病句(缺主语) line={line!r}")
|
||||
continue
|
||||
|
||||
texts.append(line)
|
||||
logger.debug(f"[{platform}] OCR -> {len(ocr_lines)} raw, {len(texts)} filtered, "
|
||||
f"last=\"{texts[-1][:50] if texts else ''}\"")
|
||||
|
||||
Reference in New Issue
Block a user