fix: 优化合同比对误判的问题
This commit is contained in:
1 parent
2e8405e2f0
commit
04e6254096
6 files changed
+191
-19
No files matched your search
@@ -4,7 +4,7 @@ backend/app/services/procurement_contract/analyze.py
|
||||
用途:采购合同改稿比对与卖方合同五问检查(文本抽取、清洗、Diff、采购五灯)。
|
||||
依赖:stdlib difflib/re/zipfile;可选 python-docx / pdfplumber / pypdf。
|
||||
逻辑:review_service 清洗后调用 analyze_compare(红线 Diff + 五灯)或 analyze_solo(五问);
|
||||
比对模式以实质变更为主,不再向结果卡堆 OCR 待确认项。
|
||||
比对模式以实质变更为主,不再向结果卡堆 OCR 待确认项。日历日「N天」与「N日」视为同义。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -389,12 +389,31 @@ def _normalized_number_tokens(text: str) -> list[str]:
|
||||
抽取可明确读取的金额、比例和期限数字,供区分真实数值变化与 OCR 噪声。
|
||||
|
||||
核心逻辑:先把「千分之五 / 百分之零点五」等中文比例归一成 ‰/% 数字,再抽 token,
|
||||
否则母本常见中文违约金改写会被误判为无数字变化的 OCR 噪声。
|
||||
否则母本常见中文违约金改写会被误判为无数字变化的 OCR 噪声。数字后的「天」收成「日」,
|
||||
使「60天」与「60日」视为同一日历日;「3个工作日」的「日」被「个」隔开,不会并入 token。
|
||||
"""
|
||||
normalized, _ = _normalize_ocr_numeric_text(text)
|
||||
normalized = re.sub(r"(?<=\d)[Oo](?=[\d,.;:%‰])|(?<=[¥¥\d,])[Oo](?=\d)", "0", normalized)
|
||||
normalized = re.sub(r"(?<=\d)[Il|](?=[\d,.;:%‰])|(?<=[¥¥\d,])[Il|](?=\d)", "1", normalized)
|
||||
return [re.sub(r"\s+", "", item) for item in _NUMBER_TOKEN_PATTERN.findall(normalized)]
|
||||
tokens = [re.sub(r"\s+", "", item) for item in _NUMBER_TOKEN_PATTERN.findall(normalized)]
|
||||
# [STEP] 印章遮挡常把「天」读成「日」。只折叠紧跟数字的日历日,工作日仍保持独立。
|
||||
return [re.sub(r"(?<=\d)天$", "日", token) for token in tokens]
|
||||
|
||||
|
||||
def _calendar_day_alias_key(text: str) -> str:
|
||||
"""
|
||||
生成日历日同义比较键,供 OCR 噪声判断,不改写合同原文。
|
||||
|
||||
核心逻辑:在 OCR 比较键上把数字后的「天」收成「日」。短句「30天支付」与「30日支付」
|
||||
相似度会低于噪声阈值,但同义键相等即可忽略。工作日前面不是数字,键保持不同。
|
||||
|
||||
Args:
|
||||
text: 去掉列表序号后的单侧差异正文。
|
||||
|
||||
Returns:
|
||||
仅含中英文与数字的比较键。
|
||||
"""
|
||||
return re.sub(r"(?<=\d)天", "日", _ocr_comparison_key(text))
|
||||
|
||||
|
||||
def _material_terms(text: str) -> set[str]:
|
||||
@@ -430,6 +449,7 @@ def _diff_reliability(old_text: str, new_text: str) -> tuple[str, float]:
|
||||
|
||||
明确可读的数字或权利义务用语变化始终视为 substantive;高相似且关键字段一致的差异
|
||||
视为 ocr_noise;高相似但一侧含可疑字符、数字又无法对齐时标为 uncertain。
|
||||
数字后的「天/日」先按同一日历日比较,天数变化和工作日与自然日的差别仍是实质变化。
|
||||
"""
|
||||
if not old_text or not new_text:
|
||||
return "substantive", 1.0
|
||||
@@ -456,6 +476,9 @@ def _diff_reliability(old_text: str, new_text: str) -> tuple[str, float]:
|
||||
return "substantive", similarity
|
||||
if material_changed:
|
||||
return "substantive", similarity
|
||||
# [STEP] 账期只差「天/日」时,长短句都按噪声忽略;天数本身变化已在上面返回。
|
||||
if old_body and new_body and _calendar_day_alias_key(old_body) == _calendar_day_alias_key(new_body):
|
||||
return "ocr_noise", similarity
|
||||
if similarity >= 0.985 and old_numbers == new_numbers:
|
||||
return "ocr_noise", similarity
|
||||
if similarity >= 0.94 and old_numbers == new_numbers:
|
||||
|
||||
Reference in new issue
Block a user