|
@@ -259,6 +259,43 @@ class StandardTimelinessReviewer:
|
|
|
final_result=match_result.final_result
|
|
final_result=match_result.final_result
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ def _normalize_text(self, text: str) -> str:
|
|
|
|
|
+ """
|
|
|
|
|
+ 规范化文本用于比较(与 StandardRepository._normalize_for_matching 保持一致)
|
|
|
|
|
+ 去除所有空白、标点符号、书名号、括号等
|
|
|
|
|
+ 从 config.ini 读取需要去除的符号
|
|
|
|
|
+ """
|
|
|
|
|
+ if not text:
|
|
|
|
|
+ return ""
|
|
|
|
|
+ import re
|
|
|
|
|
+
|
|
|
|
|
+ # 基础规范化(与 StandardRepository 一致)
|
|
|
|
|
+ # 去除 HTML 标签
|
|
|
|
|
+ text = re.sub(r'<[^>]+>', '', text)
|
|
|
|
|
+ # 去除所有 Unicode 空白字符
|
|
|
|
|
+ text = re.sub(r'\s+', '', text)
|
|
|
|
|
+ # 去除书名号和括号(第一轮)
|
|
|
|
|
+ text = text.replace('《', '').replace('》', '').replace('(', '').replace(')', '').replace('(', '').replace(')', '')
|
|
|
|
|
+
|
|
|
|
|
+ # 第二轮:从 config.ini 读取并去除指定符号
|
|
|
|
|
+ default_symbols = '),-,.,/,,:,[,],【,】,〔,〕,(,),-,—'
|
|
|
|
|
+
|
|
|
|
|
+ # 尝试从配置读取
|
|
|
|
|
+ symbols_str = default_symbols
|
|
|
|
|
+ try:
|
|
|
|
|
+ from foundation.infrastructure.config.config import config_handler
|
|
|
|
|
+ symbols_str = config_handler.get('timeliness_review', 'REMOVE_SYMBOLS', default_symbols)
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ pass # 使用默认符号
|
|
|
|
|
+
|
|
|
|
|
+ # 解析并去除符号
|
|
|
|
|
+ if symbols_str:
|
|
|
|
|
+ symbols_to_remove = [s.strip() for s in symbols_str.split(',') if s.strip()]
|
|
|
|
|
+ for symbol in symbols_to_remove:
|
|
|
|
|
+ text = text.replace(symbol, '')
|
|
|
|
|
+
|
|
|
|
|
+ return text
|
|
|
|
|
+
|
|
|
def convert_to_standardized_format(
|
|
def convert_to_standardized_format(
|
|
|
self,
|
|
self,
|
|
|
review_results: List[TimelinessReviewResult],
|
|
review_results: List[TimelinessReviewResult],
|
|
@@ -284,25 +321,36 @@ class StandardTimelinessReviewer:
|
|
|
# 标准库不存在或无问题的结果直接过滤,不返回
|
|
# 标准库不存在或无问题的结果直接过滤,不返回
|
|
|
if result.status_code == MatchResultCode.NOT_FOUND.value or not result.has_issue:
|
|
if result.status_code == MatchResultCode.NOT_FOUND.value or not result.has_issue:
|
|
|
continue
|
|
continue
|
|
|
- else:
|
|
|
|
|
- # 有问题
|
|
|
|
|
- standardized_results.append({
|
|
|
|
|
- "check_item": check_item,
|
|
|
|
|
- "chapter_code": chapter_code,
|
|
|
|
|
- "check_item_code": check_item_code,
|
|
|
|
|
- "check_result": {
|
|
|
|
|
- "location": f"《{result.standard_name}》({result.standard_number})",
|
|
|
|
|
- "description": result.reason or result.final_result,
|
|
|
|
|
- "suggestion": result.suggestion,
|
|
|
|
|
- "issue_type": result.issue_type,
|
|
|
|
|
- "standard_name": result.standard_name,
|
|
|
|
|
- "standard_number": result.standard_number,
|
|
|
|
|
- "replacement_name": result.replacement_name,
|
|
|
|
|
- "replacement_number": result.replacement_number,
|
|
|
|
|
- },
|
|
|
|
|
- "exist_issue": True,
|
|
|
|
|
- "risk_info": {"risk_level": result.risk_level}
|
|
|
|
|
- })
|
|
|
|
|
|
|
+
|
|
|
|
|
+ # 【兜底逻辑】检查替代标准是否和原始标准实质相同(规范化后比较)
|
|
|
|
|
+ if result.replacement_name and result.replacement_number:
|
|
|
|
|
+ original_combined = self._normalize_text(f"{result.standard_name}{result.standard_number}")
|
|
|
|
|
+ replacement_combined = self._normalize_text(f"{result.replacement_name}{result.replacement_number}")
|
|
|
|
|
+
|
|
|
|
|
+ if original_combined == replacement_combined:
|
|
|
|
|
+ logger.info(f"[兜底过滤] 替代标准与原始标准实质相同,跳过: "
|
|
|
|
|
+ f"{result.standard_name}({result.standard_number}) ~ "
|
|
|
|
|
+ f"{result.replacement_name}({result.replacement_number})")
|
|
|
|
|
+ continue # 跳过这条问题,视为无风险
|
|
|
|
|
+
|
|
|
|
|
+ # 有问题
|
|
|
|
|
+ standardized_results.append({
|
|
|
|
|
+ "check_item": check_item,
|
|
|
|
|
+ "chapter_code": chapter_code,
|
|
|
|
|
+ "check_item_code": check_item_code,
|
|
|
|
|
+ "check_result": {
|
|
|
|
|
+ "location": f"《{result.standard_name}》({result.standard_number})",
|
|
|
|
|
+ "description": result.reason or result.final_result,
|
|
|
|
|
+ "suggestion": result.suggestion,
|
|
|
|
|
+ "issue_type": result.issue_type,
|
|
|
|
|
+ "standard_name": result.standard_name,
|
|
|
|
|
+ "standard_number": result.standard_number,
|
|
|
|
|
+ "replacement_name": result.replacement_name,
|
|
|
|
|
+ "replacement_number": result.replacement_number,
|
|
|
|
|
+ },
|
|
|
|
|
+ "exist_issue": True,
|
|
|
|
|
+ "risk_info": {"risk_level": result.risk_level}
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
return standardized_results
|
|
return standardized_results
|
|
|
|
|
|