|
|
@@ -0,0 +1,233 @@
|
|
|
+"""
|
|
|
+基础合规性审查器
|
|
|
+负责语法检查、语义逻辑检查、完整性检查等基础审查功能
|
|
|
+"""
|
|
|
+
|
|
|
+import json
|
|
|
+from typing import Dict, Any, Optional
|
|
|
+from .base_reviewer import BaseComplianceReviewer, ReviewResult
|
|
|
+
|
|
|
+
|
|
|
+class GrammarCheckReviewer(BaseComplianceReviewer):
|
|
|
+ """语法检查审查器"""
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ super().__init__("语法检查")
|
|
|
+
|
|
|
+ def get_system_prompt(self) -> str:
|
|
|
+ return """你是一个专业的中文语法检查专家,专门负责检查施工方案文档中的语法问题。
|
|
|
+
|
|
|
+你的任务是:
|
|
|
+1. 检查语法错误、标点符号使用
|
|
|
+2. 识别语句不通顺的地方
|
|
|
+3. 发现用词不当的问题
|
|
|
+4. 检查专业术语使用是否规范
|
|
|
+
|
|
|
+请对给定的施工方案内容进行语法检查,并以JSON格式返回结果:
|
|
|
+{
|
|
|
+ "score": 85.5,
|
|
|
+ "details": {
|
|
|
+ "grammar_errors": [{"text": "错误内容", "position": "位置", "suggestion": "修改建议"}],
|
|
|
+ "punctuation_errors": [{"text": "错误内容", "position": "位置", "suggestion": "修改建议"}],
|
|
|
+ "word_choice_issues": [{"text": "用词问题", "position": "位置", "suggestion": "修改建议"}],
|
|
|
+ "total_errors": 3
|
|
|
+ },
|
|
|
+ "suggestions": ["建议1", "建议2"]
|
|
|
+}
|
|
|
+
|
|
|
+评分标准:
|
|
|
+- 90-100分:语法优秀,基本无错误
|
|
|
+- 80-89分:语法良好,少量小错误
|
|
|
+- 70-79分:语法一般,有一些错误
|
|
|
+- 60-69分:语法较差,错误较多
|
|
|
+- 0-59分:语法很差,需要重写
|
|
|
+"""
|
|
|
+
|
|
|
+ def get_user_prompt_template(self) -> str:
|
|
|
+ return """请对以下施工方案内容进行语法检查:
|
|
|
+
|
|
|
+待检查内容:
|
|
|
+{content}
|
|
|
+
|
|
|
+请仔细检查上述内容的语法、标点符号和用词,并以JSON格式返回检查结果。"""
|
|
|
+
|
|
|
+
|
|
|
+class SemanticLogicReviewer(BaseComplianceReviewer):
|
|
|
+ """语义逻辑检查审查器"""
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ super().__init__("语义逻辑检查")
|
|
|
+
|
|
|
+ def get_system_prompt(self) -> str:
|
|
|
+ return """你是一个专业的施工方案语义逻辑检查专家,负责检查施工方案中的逻辑一致性和语义合理性。
|
|
|
+
|
|
|
+你的任务是:
|
|
|
+1. 检查前后内容是否矛盾
|
|
|
+2. 验证技术参数的逻辑一致性
|
|
|
+3. 检查施工流程的合理性
|
|
|
+4. 识别语义不清晰或歧义的表达
|
|
|
+5. 验证数据之间的逻辑关系
|
|
|
+
|
|
|
+请对给定的施工方案内容进行语义逻辑检查,并以JSON格式返回结果:
|
|
|
+{
|
|
|
+ "score": 88.0,
|
|
|
+ "details": {
|
|
|
+ "logic_conflicts": [{"issue": "逻辑冲突描述", "location": "位置", "suggestion": "修改建议"}],
|
|
|
+ "parameter_inconsistencies": [{"issue": "参数不一致描述", "location": "位置", "suggestion": "修改建议"}],
|
|
|
+ "semantic_ambiguities": [{"issue": "语义歧义描述", "location": "位置", "suggestion": "修改建议"}],
|
|
|
+ "data_logic_issues": [{"issue": "数据逻辑问题", "location": "位置", "suggestion": "修改建议"}],
|
|
|
+ "total_issues": 2
|
|
|
+ },
|
|
|
+ "suggestions": ["建议1", "建议2"]
|
|
|
+}
|
|
|
+
|
|
|
+评分标准:
|
|
|
+- 90-100分:逻辑清晰,无矛盾
|
|
|
+- 80-89分:逻辑基本清晰,轻微问题
|
|
|
+- 70-79分:逻辑一般,有一些问题
|
|
|
+- 60-69分:逻辑较差,问题较多
|
|
|
+- 0-59分:逻辑混乱,需要重写
|
|
|
+"""
|
|
|
+
|
|
|
+ def get_user_prompt_template(self) -> str:
|
|
|
+ return """请对以下施工方案内容进行语义逻辑检查:
|
|
|
+
|
|
|
+待检查内容:
|
|
|
+{content}
|
|
|
+
|
|
|
+请仔细检查上述内容的逻辑一致性、参数合理性和语义清晰度,并以JSON格式返回检查结果。"""
|
|
|
+
|
|
|
+
|
|
|
+class CompletenessReviewer(BaseComplianceReviewer):
|
|
|
+ """完整性检查审查器"""
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ super().__init__("完整性检查")
|
|
|
+
|
|
|
+ def get_system_prompt(self) -> str:
|
|
|
+ return """你是一个专业的施工方案完整性检查专家,负责检查施工方案的完整性和规范性。
|
|
|
+
|
|
|
+你的任务是:
|
|
|
+1. 检查必要的章节和内容是否齐全
|
|
|
+2. 验证技术参数是否完整
|
|
|
+3. 检查是否缺少关键信息
|
|
|
+4. 验证表格和图表的完整性
|
|
|
+5. 检查引用和参考文献是否完整
|
|
|
+
|
|
|
+请对给定的施工方案内容进行完整性检查,并以JSON格式返回结果:
|
|
|
+{
|
|
|
+ "score": 82.5,
|
|
|
+ "details": {
|
|
|
+ "missing_sections": [{"section": "缺失章节名称", "importance": "高/中/低", "suggestion": "补充建议"}],
|
|
|
+ "incomplete_parameters": [{"parameter": "参数名称", "location": "位置", "suggestion": "完善建议"}],
|
|
|
+ "missing_references": [{"reference": "缺失引用", "context": "上下文", "suggestion": "补充建议"}],
|
|
|
+ "incomplete_tables": [{"table": "表格标识", "missing_info": "缺失信息", "suggestion": "完善建议"}],
|
|
|
+ "total_missing_items": 4
|
|
|
+ },
|
|
|
+ "suggestions": ["建议1", "建议2"]
|
|
|
+}
|
|
|
+
|
|
|
+评分标准:
|
|
|
+- 90-100分:内容完整,基本无缺失
|
|
|
+- 80-89分:内容较完整,少量缺失
|
|
|
+- 70-79分:内容一般,有一些缺失
|
|
|
+- 60-69分:内容不完整,缺失较多
|
|
|
+- 0-59分:内容严重不完整,需要补充大量信息
|
|
|
+"""
|
|
|
+
|
|
|
+ def get_user_prompt_template(self) -> str:
|
|
|
+ return """请对以下施工方案内容进行完整性检查:
|
|
|
+
|
|
|
+待检查内容:
|
|
|
+{content}
|
|
|
+
|
|
|
+请仔细检查上述内容的完整性,包括章节、参数、引用等方面,并以JSON格式返回检查结果。"""
|
|
|
+
|
|
|
+
|
|
|
+class BasicComplianceReviewer(BaseComplianceReviewer):
|
|
|
+ """基础合规性综合审查器"""
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ super().__init__("基础合规性审查")
|
|
|
+
|
|
|
+ # 初始化各个子审查器
|
|
|
+ self.grammar_reviewer = GrammarCheckReviewer()
|
|
|
+ self.semantic_reviewer = SemanticLogicReviewer()
|
|
|
+ self.completeness_reviewer = CompletenessReviewer()
|
|
|
+
|
|
|
+ async def comprehensive_check(self, content: str, context: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
|
+ """
|
|
|
+ 综合基础合规性检查
|
|
|
+ """
|
|
|
+ results = {}
|
|
|
+
|
|
|
+ try:
|
|
|
+ # 并行执行各项检查
|
|
|
+ import asyncio
|
|
|
+
|
|
|
+ tasks = [
|
|
|
+ self.grammar_reviewer.review(content, context),
|
|
|
+ self.semantic_reviewer.review(content, context),
|
|
|
+ self.completeness_reviewer.review(content, context)
|
|
|
+ ]
|
|
|
+
|
|
|
+ grammar_result, semantic_result, completeness_result = await asyncio.gather(*tasks)
|
|
|
+
|
|
|
+ results = {
|
|
|
+ "grammar_check": {
|
|
|
+ "score": grammar_result.score,
|
|
|
+ "details": grammar_result.details,
|
|
|
+ "suggestions": grammar_result.suggestions,
|
|
|
+ "execution_time": grammar_result.execution_time
|
|
|
+ },
|
|
|
+ "semantic_check": {
|
|
|
+ "score": semantic_result.score,
|
|
|
+ "details": semantic_result.details,
|
|
|
+ "suggestions": semantic_result.suggestions,
|
|
|
+ "execution_time": semantic_result.execution_time
|
|
|
+ },
|
|
|
+ "completeness_check": {
|
|
|
+ "score": completeness_result.score,
|
|
|
+ "details": completeness_result.details,
|
|
|
+ "suggestions": completeness_result.suggestions,
|
|
|
+ "execution_time": completeness_result.execution_time
|
|
|
+ },
|
|
|
+ "overall_score": self._calculate_overall_score(
|
|
|
+ grammar_result.score,
|
|
|
+ semantic_result.score,
|
|
|
+ completeness_result.score
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ results = {
|
|
|
+ "error": str(e),
|
|
|
+ "overall_score": 0.0
|
|
|
+ }
|
|
|
+
|
|
|
+ return results
|
|
|
+
|
|
|
+ def _calculate_overall_score(self, grammar_score: float, semantic_score: float, completeness_score: float) -> float:
|
|
|
+ """计算综合得分"""
|
|
|
+ # 权重配置
|
|
|
+ weights = {
|
|
|
+ "grammar": 0.2, # 语法权重20%
|
|
|
+ "semantic": 0.4, # 语义逻辑权重40%(最重要)
|
|
|
+ "completeness": 0.4 # 完整性权重40%
|
|
|
+ }
|
|
|
+
|
|
|
+ overall_score = (
|
|
|
+ grammar_score * weights["grammar"] +
|
|
|
+ semantic_score * weights["semantic"] +
|
|
|
+ completeness_score * weights["completeness"]
|
|
|
+ )
|
|
|
+
|
|
|
+ return round(overall_score, 2)
|
|
|
+
|
|
|
+ def get_system_prompt(self) -> str:
|
|
|
+ """这个方法在综合审查器中不会被直接调用"""
|
|
|
+ return ""
|
|
|
+
|
|
|
+ def get_user_prompt_template(self) -> str:
|
|
|
+ """这个方法在综合审查器中不会被直接调用"""
|
|
|
+ return ""
|