|
|
@@ -7,6 +7,7 @@ import json
|
|
|
import csv
|
|
|
import logging
|
|
|
import ast
|
|
|
+import time
|
|
|
from pathlib import Path
|
|
|
from typing import Dict, List, Any
|
|
|
import sys
|
|
|
@@ -439,6 +440,113 @@ def remove_common_elements_between_dataframes(
|
|
|
return miss_outline_df, redis_data
|
|
|
|
|
|
|
|
|
+def process_catalog_review_list(catogues_df: pd.DataFrame) -> List[Dict[str, Any]]:
|
|
|
+ """
|
|
|
+ 处理目录审查列表,从DataFrame中提取missing_items和miss_outline并生成审查项
|
|
|
+
|
|
|
+ Args:
|
|
|
+ catogues_df: 包含目录审查数据的DataFrame,需要包含以下列:
|
|
|
+ - title: 标题
|
|
|
+ - chapter_label: 章节标签
|
|
|
+ - chapter_classification: 章节分类
|
|
|
+ - missing_items: 目录缺失项(列表或字符串)
|
|
|
+ - miss_outline: 大纲缺失项(列表或字符串)
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ List[Dict[str, Any]]: 审查项列表,每个项包含:
|
|
|
+ - issue_point: 问题点
|
|
|
+ - location: 位置
|
|
|
+ - suggestion: 建议
|
|
|
+ - reason: 原因
|
|
|
+ - risk_level: 风险等级
|
|
|
+ - reference_source: 参考来源
|
|
|
+ """
|
|
|
+ start_time = time.time()
|
|
|
+ catogues_reciew_list = []
|
|
|
+
|
|
|
+ for index, row in catogues_df.iterrows():
|
|
|
+ title = row.get('title', '')
|
|
|
+ chapter_label = row.get('chapter_label', '')
|
|
|
+ chapter_classification = row.get('chapter_classification', '')
|
|
|
+
|
|
|
+ # 解析 missing_items 列(目录缺失)
|
|
|
+ missing_items_str = row.get('missing_items', '')
|
|
|
+ try:
|
|
|
+ if pd.isna(missing_items_str) or missing_items_str == '':
|
|
|
+ missing_items_list = []
|
|
|
+ elif isinstance(missing_items_str, list):
|
|
|
+ missing_items_list = missing_items_str
|
|
|
+ else:
|
|
|
+ # 尝试使用 ast.literal_eval 解析
|
|
|
+ missing_items_list = ast.literal_eval(missing_items_str)
|
|
|
+ except (ValueError, SyntaxError):
|
|
|
+ try:
|
|
|
+ # 尝试使用 json.loads 解析
|
|
|
+ missing_items_list = json.loads(missing_items_str)
|
|
|
+ except (json.JSONDecodeError, TypeError):
|
|
|
+ logger.warning(f"第 {index} 行无法解析missing_items: {missing_items_str}")
|
|
|
+ missing_items_list = []
|
|
|
+
|
|
|
+ # 解析 miss_outline 列(大纲缺失)
|
|
|
+ miss_outline_str = row.get('miss_outline', '')
|
|
|
+ try:
|
|
|
+ if pd.isna(miss_outline_str) or miss_outline_str == '':
|
|
|
+ miss_outline_list = []
|
|
|
+ elif isinstance(miss_outline_str, list):
|
|
|
+ miss_outline_list = miss_outline_str
|
|
|
+ else:
|
|
|
+ # 尝试使用 ast.literal_eval 解析
|
|
|
+ miss_outline_list = ast.literal_eval(miss_outline_str)
|
|
|
+ except (ValueError, SyntaxError):
|
|
|
+ try:
|
|
|
+ # 尝试使用 json.loads 解析
|
|
|
+ miss_outline_list = json.loads(miss_outline_str)
|
|
|
+ except (json.JSONDecodeError, TypeError):
|
|
|
+ logger.warning(f"第 {index} 行无法解析miss_outline: {miss_outline_str}")
|
|
|
+ miss_outline_list = []
|
|
|
+
|
|
|
+ # 处理 missing_items(目录缺失)
|
|
|
+ if isinstance(missing_items_list, list) and len(missing_items_list) > 0:
|
|
|
+ for missing_item in missing_items_list:
|
|
|
+ catalog_item = {
|
|
|
+ "issue_point": f"{missing_item}缺失",
|
|
|
+ "location": title if title else chapter_label,
|
|
|
+ "suggestion": f"目录缺失(missing_items):在待审查目录中未找到与'{missing_item}'对应的章节;当前章节仅涉及'{title if title else chapter_label}',未涵盖'{missing_item}'相关内容;整改建议:建议在本章或前序章节中增设'{missing_item}'相关内容,确保与审查规范要求一致。",
|
|
|
+ "reason": "",
|
|
|
+ "risk_level": "高风险",
|
|
|
+ "reference_source": '《桥梁公司危险性较大工程管理实施细则(2025版)》',
|
|
|
+ }
|
|
|
+ catogues_reciew_list.append(catalog_item)
|
|
|
+
|
|
|
+ # 处理 miss_outline(大纲缺失)
|
|
|
+ if isinstance(miss_outline_list, list) and len(miss_outline_list) > 0:
|
|
|
+ for miss_outline in miss_outline_list:
|
|
|
+ outline_item = {
|
|
|
+ "issue_point": f"{miss_outline}缺失",
|
|
|
+ "location": title if title else chapter_label,
|
|
|
+ "suggestion": f"大纲缺失(miss_outline):在待审查大纲中未找到与'{miss_outline}'对应的章节;当前章节仅涉及'{title if title else chapter_label}',未涵盖'{miss_outline}'相关内容;整改建议:建议在本章或前序章节中增设'{miss_outline}'相关内容,确保与审查规范要求一致。",
|
|
|
+ "reason": "",
|
|
|
+ "risk_level": "高风险",
|
|
|
+ "reference_source": '《桥梁公司危险性较大工程管理实施细则(2025版)》',
|
|
|
+ }
|
|
|
+ catogues_reciew_list.append(outline_item)
|
|
|
+
|
|
|
+ execution_time = time.time() - start_time
|
|
|
+ logger.info(f"目录审查完成,共发现 {len(catogues_reciew_list)} 个缺失项,耗时 {execution_time:.2f} 秒")
|
|
|
+
|
|
|
+ return {
|
|
|
+ "details": {
|
|
|
+ "name": "completeness_check",
|
|
|
+ "response": catogues_reciew_list,
|
|
|
+ "review_location_label": "",
|
|
|
+ "chapter_code": "catalogue",
|
|
|
+ "original_content": ""
|
|
|
+ },
|
|
|
+ "success": False,
|
|
|
+ "execution_time": execution_time
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
async def catalogues_check(catalog_file = None):
|
|
|
"""主函数"""
|
|
|
# 获取当前文件所在目录
|