feat(regulatory): 按实际处理数量更新节点进度
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import re
|
||||
from collections import defaultdict
|
||||
from collections.abc import Callable
|
||||
|
||||
from review_agent.regulatory_review.schemas import Finding
|
||||
|
||||
@@ -17,27 +18,40 @@ FIELDS = {
|
||||
}
|
||||
|
||||
|
||||
def run_consistency_check(document_texts: dict[str, str]) -> list[Finding]:
|
||||
def run_consistency_check(
|
||||
document_texts: dict[str, str],
|
||||
progress_callback: Callable[[dict[str, object]], None] | None = None,
|
||||
) -> list[Finding]:
|
||||
findings: list[Finding] = []
|
||||
for label, pattern in FIELDS.items():
|
||||
fields = list(FIELDS.items())
|
||||
total = len(fields)
|
||||
for index, (label, pattern) in enumerate(fields, start=1):
|
||||
values: dict[str, list[str]] = defaultdict(list)
|
||||
for file_name, text in document_texts.items():
|
||||
match = re.search(pattern, text)
|
||||
if match:
|
||||
values[_normalize(match.group(1))].append(file_name)
|
||||
if len(values) <= 1:
|
||||
continue
|
||||
findings.append(
|
||||
Finding(
|
||||
rule_code=f"consistency:{label}",
|
||||
category="consistency",
|
||||
severity="high",
|
||||
title=f"{label}在不同文件中不一致",
|
||||
detail=f"发现 {len(values)} 个不同的{label}取值。",
|
||||
suggestion=f"请统一各注册资料中的{label}。",
|
||||
evidence={"field": label, "values": dict(values)},
|
||||
if len(values) > 1:
|
||||
findings.append(
|
||||
Finding(
|
||||
rule_code=f"consistency:{label}",
|
||||
category="consistency",
|
||||
severity="high",
|
||||
title=f"{label}在不同文件中不一致",
|
||||
detail=f"发现 {len(values)} 个不同的{label}取值。",
|
||||
suggestion=f"请统一各注册资料中的{label}。",
|
||||
evidence={"field": label, "values": dict(values)},
|
||||
)
|
||||
)
|
||||
if progress_callback:
|
||||
progress_callback(
|
||||
{
|
||||
"processed": index,
|
||||
"total": total,
|
||||
"label": label,
|
||||
"finding_count": len(findings),
|
||||
}
|
||||
)
|
||||
)
|
||||
return findings
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user