dknowc-dsh 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -3
- package/package.json +2 -2
- package/skills/dk-trace-report/SKILL.md +288 -0
- package/skills/dk-trace-report/config/examples/doc.json +56 -0
- package/skills/dk-trace-report/config/examples/legal.json +51 -0
- package/skills/dk-trace-report/config/examples/ppt.json +47 -0
- package/skills/dk-trace-report/config/examples/tax.json +46 -0
- package/skills/dk-trace-report/config/examples/trusted.json +122 -0
- package/skills/dk-trace-report/reference/sample_input.json +60 -0
- package/skills/dk-trace-report/resources/ECHARTS-NOTICE.txt +10 -0
- package/skills/dk-trace-report/resources/echarts.custom.min.js +48 -0
- package/skills/dk-trace-report/scripts/build_report_input.py +333 -0
- package/skills/{dknowc-trusted-search → dk-trace-report}/scripts/chart_embed.py +4 -1
- package/skills/{dknowc-trusted-search → dk-trace-report}/scripts/render_trace_html.py +1071 -536
- package/skills/dk-trace-report/scripts/run_paths.py +95 -0
- package/skills/dk-trace-report/scripts/trust_digest.py +77 -0
- package/skills/dknowc-legal-assistant/README.md +95 -0
- package/skills/dknowc-legal-assistant/SKILL.md +122 -0
- package/skills/dknowc-legal-assistant/attribution.json +5 -0
- package/skills/dknowc-legal-assistant/reference/answer-and-report.md +221 -0
- package/skills/dknowc-legal-assistant/reference/capability-layer.md +143 -0
- package/skills/dknowc-legal-assistant/reference/legal_claims.example.json +96 -0
- package/skills/dknowc-legal-assistant/reference/onboarding_scripts.md +198 -0
- package/skills/dknowc-legal-assistant/reference/policy_tags.json +2002 -0
- package/skills/dknowc-legal-assistant/reference/retrieval-statute.md +81 -0
- package/skills/dknowc-legal-assistant/reference/retrieval-v2.md +133 -0
- package/skills/dknowc-legal-assistant/reference/sample_search_result.md +33 -0
- package/skills/dknowc-legal-assistant/reference/sample_trace_report.html +940 -0
- package/skills/dknowc-legal-assistant/reference/tags.md +53 -0
- package/skills/dknowc-legal-assistant/reference/troubleshooting.md +50 -0
- package/skills/dknowc-legal-assistant/reference/verification-pass.md +59 -0
- package/skills/dknowc-legal-assistant/resources/echarts.custom.min.js +48 -0
- package/skills/dknowc-legal-assistant/scripts/api_key.py +68 -0
- package/skills/dknowc-legal-assistant/scripts/attribution.py +61 -0
- package/skills/dknowc-legal-assistant/scripts/calc_legal.py +375 -0
- package/skills/dknowc-legal-assistant/scripts/calc_period.py +155 -0
- package/skills/dknowc-legal-assistant/scripts/check_answer.py +664 -0
- package/skills/dknowc-legal-assistant/scripts/initialize.py +188 -0
- package/skills/dknowc-legal-assistant/scripts/legal_client.py +208 -0
- package/skills/dknowc-legal-assistant/scripts/legal_search.py +1059 -0
- package/skills/dknowc-legal-assistant/scripts/merge_search_results.py +630 -0
- package/skills/dknowc-legal-assistant/scripts/path_guard.py +92 -0
- package/skills/dknowc-legal-assistant/scripts/question_profile.py +215 -0
- package/skills/dknowc-legal-assistant/scripts/register_key.mjs +1152 -0
- package/skills/dknowc-legal-assistant/scripts/run_eval.py +109 -0
- package/skills/dknowc-legal-assistant/scripts/source_cards.py +321 -0
- package/skills/dknowc-legal-assistant/scripts/tag_catalog.py +162 -0
- package/skills/dknowc-legal-assistant/scripts/trace_report.config.json +66 -0
- package/skills/dknowc-legal-assistant/scripts/verify_claims.py +448 -0
- package/skills/dknowc-legal-assistant/scripts/websearch_convert.py +396 -0
- package/skills/dknowc-official-doc-writer/README.md +32 -21
- package/skills/dknowc-official-doc-writer/SKILL.md +28 -15
- package/skills/dknowc-official-doc-writer/config/trace_report.config.json +56 -0
- package/skills/dknowc-official-doc-writer/official-docs/input//345/274/225/347/224/250/345/257/271/347/205/247_/351/252/214/346/224/266_materials.json +628 -0
- package/skills/dknowc-official-doc-writer/official-docs/search-results/baseline_1555.json +345 -0
- package/skills/dknowc-official-doc-writer/official-docs/search-results/baseline_my.json +728 -0
- package/skills/dknowc-official-doc-writer/official-docs/search-results/baseline_wp.json +159 -0
- package/skills/dknowc-official-doc-writer/official-docs/search-results/baseline_wp2.json +1006 -0
- package/skills/dknowc-official-doc-writer/official-docs/search-results/test_tz.json +28 -0
- package/skills/dknowc-official-doc-writer/official-docs/search-results/tmp_q.json +1419 -0
- package/skills/dknowc-official-doc-writer/reference/anti_ai_patterns.md +14 -2
- package/skills/dknowc-official-doc-writer/reference/fact_discipline.md +4 -0
- package/skills/dknowc-official-doc-writer/reference/genre_writing_notes.md +4 -0
- package/skills/dknowc-official-doc-writer/reference/initialization.md +13 -8
- package/skills/dknowc-official-doc-writer/reference/local_memory_guide.md +7 -7
- package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +21 -0
- package/skills/dknowc-official-doc-writer/reference/materials_pipeline.md +64 -7
- package/skills/dknowc-official-doc-writer/reference/onboarding_scripts.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/outline_rules.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/output_guide.md +13 -13
- package/skills/dknowc-official-doc-writer/reference/research_notes.md +5 -3
- package/skills/dknowc-official-doc-writer/reference/review_checklist.md +6 -2
- package/skills/dknowc-official-doc-writer/reference/search_guide.md +44 -32
- package/skills/dknowc-official-doc-writer/reference/search_policy.md +63 -36
- package/skills/dknowc-official-doc-writer/reference/standards/01_report.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/standards/02_qingshi.md +6 -3
- package/skills/dknowc-official-doc-writer/reference/standards/03_pifu.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/04_tongzhi.md +12 -3
- package/skills/dknowc-official-doc-writer/reference/standards/05_yijian.md +8 -2
- package/skills/dknowc-official-doc-writer/reference/standards/06_han.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/08_tongbao.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/09_tonggao.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/10_gonggao.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/11_fuhan_approve.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/12_fuhan_objection.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/13_reminder.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/standards/14_generic.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/16_decision.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/18_order.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/19_gazette.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/20_motion.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/22_application.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/23_publicity.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/25_plan.md +2 -1
- package/skills/dknowc-official-doc-writer/reference/standards/26_summary.md +7 -1
- package/skills/dknowc-official-doc-writer/reference/standards/27_speech.md +4 -1
- package/skills/dknowc-official-doc-writer/reference/standards/99_expressions.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/task_router.md +4 -4
- package/skills/dknowc-official-doc-writer/reference/working_principles.md +4 -4
- package/skills/dknowc-official-doc-writer/reference/writing_method.md +166 -0
- package/skills/dknowc-official-doc-writer/reference/writing_rules.md +10 -4
- package/skills/dknowc-official-doc-writer/scripts/api_key.py +22 -2
- package/skills/dknowc-official-doc-writer/scripts/attribution.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/build_trace_json.py +205 -13
- package/skills/dknowc-official-doc-writer/scripts/check_materials.py +367 -22
- package/skills/dknowc-official-doc-writer/scripts/deep_convert.py +5 -0
- package/skills/dknowc-official-doc-writer/scripts/deep_query.py +2 -1
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +20 -7
- package/skills/dknowc-official-doc-writer/scripts/extract_reference.py +1 -0
- package/skills/dknowc-official-doc-writer/scripts/format_document.py +88 -30
- package/skills/dknowc-official-doc-writer/scripts/initialize.py +232 -6
- package/skills/dknowc-official-doc-writer/scripts/local_memory.py +2 -6
- package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +100 -7
- package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +2 -1
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +265 -32
- package/skills/dknowc-official-doc-writer/scripts/review_document.py +1 -0
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +117 -10
- package/skills/dknowc-official-doc-writer/scripts/template_generator.py +1 -0
- package/skills/dknowc-official-doc-writer/scripts/update_skill.py +339 -0
- package/skills/dknowc-official-doc-writer/scripts/websearch_convert.py +326 -0
- package/skills/dknowc-ppt-assistant/README.md +7 -9
- package/skills/dknowc-ppt-assistant/SKILL.md +28 -19
- package/skills/dknowc-ppt-assistant/config/trace_report.config.json +65 -0
- package/skills/dknowc-ppt-assistant/references/initialization.md +20 -8
- package/skills/dknowc-ppt-assistant/references/material_usage.md +46 -9
- package/skills/dknowc-ppt-assistant/references/onboarding_scripts.md +7 -5
- package/skills/dknowc-ppt-assistant/references/sample_trace_report.html +372 -920
- package/skills/dknowc-ppt-assistant/references/search_intro.md +2 -2
- package/skills/dknowc-ppt-assistant/references/svg-authoring.md +2 -2
- package/skills/dknowc-ppt-assistant/scripts/api_key.py +5 -28
- package/skills/dknowc-ppt-assistant/scripts/build_trace_input.py +188 -0
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +238 -3
- package/skills/dknowc-ppt-assistant/scripts/mcp_convert.py +1 -10
- package/skills/dknowc-ppt-assistant/scripts/merge_search_results.py +604 -0
- package/skills/dknowc-ppt-assistant/scripts/preview_slide_html.py +4 -11
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +224 -63
- package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +29 -12
- package/skills/dknowc-ppt-assistant/scripts/update_skill.py +314 -0
- package/skills/dknowc-ppt-assistant/scripts/websearch_convert.py +326 -0
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +92 -29
- package/skills/dknowc-ppt-assistant/workflows/routing.md +1 -1
- package/skills/dknowc-tax-assistant/README.md +54 -0
- package/skills/dknowc-tax-assistant/SKILL.md +99 -0
- package/skills/dknowc-tax-assistant/attribution.json +5 -0
- package/skills/dknowc-tax-assistant/reference/answer-and-report.md +100 -0
- package/skills/dknowc-tax-assistant/reference/capability-layer.md +205 -0
- package/skills/dknowc-tax-assistant/reference/onboarding_scripts.md +68 -0
- package/skills/dknowc-tax-assistant/reference/policy_tags.json +2002 -0
- package/skills/dknowc-tax-assistant/reference/retrieval-policy.md +43 -0
- package/skills/dknowc-tax-assistant/reference/retrieval-v2.md +58 -0
- package/skills/dknowc-tax-assistant/reference/tags.md +53 -0
- package/skills/dknowc-tax-assistant/reference/tax_claims.example.json +76 -0
- package/skills/dknowc-tax-assistant/reference/trace_report.config.json +46 -0
- package/skills/dknowc-tax-assistant/reference/troubleshooting.md +70 -0
- package/skills/dknowc-tax-assistant/reference/websearch-fallback.md +59 -0
- package/skills/dknowc-tax-assistant/resources/THIRD_PARTY_NOTICES.md +9 -0
- package/skills/dknowc-tax-assistant/resources/echarts.custom.min.js +48 -0
- package/skills/dknowc-tax-assistant/scripts/api_key.py +60 -0
- package/skills/dknowc-tax-assistant/scripts/attribution.py +61 -0
- package/skills/dknowc-tax-assistant/scripts/calc_period.py +156 -0
- package/skills/dknowc-tax-assistant/scripts/calc_tax.py +179 -0
- package/skills/dknowc-tax-assistant/scripts/check_answer.py +210 -0
- package/skills/dknowc-tax-assistant/scripts/initialize.py +208 -0
- package/skills/dknowc-tax-assistant/scripts/merge_search_results.py +631 -0
- package/skills/dknowc-tax-assistant/scripts/path_guard.py +23 -0
- package/skills/dknowc-tax-assistant/scripts/question_profile.py +444 -0
- package/skills/dknowc-tax-assistant/scripts/register_key.mjs +1173 -0
- package/skills/dknowc-tax-assistant/scripts/run_dir.py +149 -0
- package/skills/dknowc-tax-assistant/scripts/source_cards.py +372 -0
- package/skills/dknowc-tax-assistant/scripts/tag_catalog.py +164 -0
- package/skills/dknowc-tax-assistant/scripts/tax_client.py +218 -0
- package/skills/dknowc-tax-assistant/scripts/tax_search.py +403 -0
- package/skills/dknowc-tax-assistant/scripts/verify_claims.py +587 -0
- package/skills/dknowc-tax-assistant/scripts/websearch_convert.py +352 -0
- package/skills/dknowc-trusted-search/README.md +25 -19
- package/skills/dknowc-trusted-search/SKILL.md +205 -73
- package/skills/dknowc-trusted-search/config/trace_report.config.json +119 -0
- package/skills/dknowc-trusted-search/reference/onboarding_scripts.md +3 -3
- package/skills/dknowc-trusted-search/reference/sample_trace_report.html +286 -191
- package/skills/dknowc-trusted-search/resources/ECHARTS-NOTICE.txt +10 -0
- package/skills/dknowc-trusted-search/scripts/api_key.py +0 -1
- package/skills/dknowc-trusted-search/scripts/attribution.py +1 -1
- package/skills/dknowc-trusted-search/scripts/build_trace_input.py +173 -0
- package/skills/dknowc-trusted-search/scripts/deep_convert.py +79 -30
- package/skills/dknowc-trusted-search/scripts/deep_query.py +22 -33
- package/skills/dknowc-trusted-search/scripts/initialize.py +343 -2
- package/skills/dknowc-trusted-search/scripts/merge_search_results.py +222 -35
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +241 -29
- package/skills/dknowc-trusted-search/scripts/source_display.py +59 -0
- package/skills/dknowc-trusted-search/scripts/trusted_search.py +67 -34
- package/skills/dknowc-trusted-search/scripts/update_skill.py +300 -0
- package/skills/dknowc-trusted-search/scripts/websearch_convert.py +328 -0
- package/src/index.js +15 -0
- package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +0 -2574
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +0 -2642
- package/skills/dknowc-trusted-search/official-docs/output/.gitkeep +0 -0
- package/skills/dknowc-trusted-search/official-docs/search-results/.gitkeep +0 -0
|
@@ -33,6 +33,10 @@ import json
|
|
|
33
33
|
import re
|
|
34
34
|
import sys
|
|
35
35
|
from pathlib import Path
|
|
36
|
+
from typing import Optional
|
|
37
|
+
|
|
38
|
+
# 同一角标多次出现时的句子绑定与事后校验共用一套归一化,避免两处口径不一致
|
|
39
|
+
from check_materials import check_mark_occurrence_binding, cmp_norm, mark_occurrences
|
|
36
40
|
|
|
37
41
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
38
42
|
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
@@ -44,6 +48,7 @@ if not _ws:
|
|
|
44
48
|
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
45
49
|
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
46
50
|
WS_ROOT = Path(_ws).resolve()
|
|
51
|
+
|
|
47
52
|
INPUT_DIR = WS_ROOT / "official-docs" / "input"
|
|
48
53
|
|
|
49
54
|
# 合并产物文章字段(--clean 同构,deep_convert / merge 产物均含)
|
|
@@ -123,9 +128,12 @@ def map_article_fields(art: dict) -> dict:
|
|
|
123
128
|
"search_key": (first_value(art, ("搜索目的", "purpose"))
|
|
124
129
|
or first_value(art, SEL_SEARCH_KEY_FIELDS)
|
|
125
130
|
or "其他检索"),
|
|
126
|
-
# 检索通道(深知深度搜索 /
|
|
127
|
-
#
|
|
131
|
+
# 检索通道(深知深度搜索 / 深知可信搜索 / 联网检索):由 deep_convert / dkag_search /
|
|
132
|
+
# websearch_convert 打标,溯源报告据此区分接口来源与各自检索路数
|
|
128
133
|
"检索通道": first_value(art, ("检索通道",)),
|
|
134
|
+
# 外部联网材料标记:溯源报告据此打「非官方来源」徽标(联网检索/宿主 WebSearch 路)
|
|
135
|
+
"非官方来源": True if art.get("非官方来源") else "",
|
|
136
|
+
"数据权威性": first_value(art, ("数据权威性", "authority")),
|
|
129
137
|
}
|
|
130
138
|
|
|
131
139
|
|
|
@@ -140,6 +148,158 @@ def extract_citations(content: str) -> list[int]:
|
|
|
140
148
|
return out
|
|
141
149
|
|
|
142
150
|
|
|
151
|
+
def count_marks(content: str) -> dict[int, int]:
|
|
152
|
+
"""统计每个角标在正文中出现的次数(引用实例必须逐处对应)。"""
|
|
153
|
+
counts: dict[int, int] = {}
|
|
154
|
+
for m in re.finditer(r"[\[【]\s*(\d+)\s*[\]】]", content):
|
|
155
|
+
n = int(m.group(1))
|
|
156
|
+
counts[n] = counts.get(n, 0) + 1
|
|
157
|
+
return counts
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def flat(text: str) -> str:
|
|
161
|
+
return re.sub(r"\s+", "", str(text or ""))
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
CIT_USAGE_VALUES = ("依据", "借鉴")
|
|
165
|
+
CIT_STATUS_VALUES = ("现行", "历史", "参考")
|
|
166
|
+
CIT_REGION_VALUES = ("本地", "上级", "外省", "全国")
|
|
167
|
+
# 引文片段下限(去空白后的字符数):过短的片段容易在原文中偶然命中,撑不起该句
|
|
168
|
+
CIT_QUOTE_MIN = 10
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def find_citation_file(args, materials_path: Path) -> Optional[Path]:
|
|
172
|
+
"""定位引用对照文件:显式 --citations 优先;否则按素材清单同名规则查找。"""
|
|
173
|
+
if args.citations:
|
|
174
|
+
p = Path(args.citations).expanduser()
|
|
175
|
+
if not p.is_absolute():
|
|
176
|
+
p = (INPUT_DIR / p.name).resolve()
|
|
177
|
+
return p if p.is_file() else None
|
|
178
|
+
stem = materials_path.stem
|
|
179
|
+
task = stem[len("materials_"):] if stem.startswith("materials_") else stem
|
|
180
|
+
for cand in (materials_path.parent / f"引用对照_{task}.json",
|
|
181
|
+
materials_path.parent / "引用对照.json",
|
|
182
|
+
INPUT_DIR / f"引用对照_{task}.json",
|
|
183
|
+
INPUT_DIR / "引用对照.json"):
|
|
184
|
+
if cand.is_file():
|
|
185
|
+
return cand
|
|
186
|
+
return None
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def load_citation_records(path: Optional[Path], body: str, material_count: int) -> list:
|
|
190
|
+
"""读取并初校验引用对照;返回按正文出现顺序排列的引用实例列表。
|
|
191
|
+
|
|
192
|
+
硬约束:正文出现的每个角标,都要有等量的引用实例(同一角标用几处,就交几条 quote)。
|
|
193
|
+
这是"引用从篇级降到片段级"的落点——没有 quote 就无法逐字核验,直接阻断。
|
|
194
|
+
"""
|
|
195
|
+
counts = count_marks(body)
|
|
196
|
+
if not counts:
|
|
197
|
+
return []
|
|
198
|
+
if path is None:
|
|
199
|
+
raise SystemExit(
|
|
200
|
+
"错误:正文含 [n] 角标,但未找到引用对照文件。\n"
|
|
201
|
+
"请先按 reference/materials_pipeline.md 生成 official-docs/input/引用对照_<任务>.json:\n"
|
|
202
|
+
' {"task": "...", "citations": [{"mark": 1, "material": 1, '
|
|
203
|
+
'"sentence": "正文中的原句", "quote": "该句依据的原文片段", "用法": "依据"}]}\n'
|
|
204
|
+
"正文每出现一次 [n],就要交一条对应实例(同一角标多处引用=多条)。"
|
|
205
|
+
)
|
|
206
|
+
data = load_json(path)
|
|
207
|
+
records = data.get("citations") if isinstance(data, dict) else None
|
|
208
|
+
if not isinstance(records, list) or not records:
|
|
209
|
+
raise SystemExit(f"错误:{path.name} 的 citations 为空或不是数组")
|
|
210
|
+
|
|
211
|
+
errors: list[str] = []
|
|
212
|
+
per_mark: dict[int, int] = {}
|
|
213
|
+
cleaned: list = []
|
|
214
|
+
flat_body = flat(body)
|
|
215
|
+
for i, rec in enumerate(records, 1):
|
|
216
|
+
if not isinstance(rec, dict):
|
|
217
|
+
errors.append(f"引用[{i}] 不是对象")
|
|
218
|
+
continue
|
|
219
|
+
try:
|
|
220
|
+
mark = int(rec.get("mark"))
|
|
221
|
+
except (TypeError, ValueError):
|
|
222
|
+
errors.append(f"引用[{i}] 缺 mark(正整数,对应正文角标)")
|
|
223
|
+
continue
|
|
224
|
+
material = rec.get("material", mark)
|
|
225
|
+
try:
|
|
226
|
+
material = int(material)
|
|
227
|
+
except (TypeError, ValueError):
|
|
228
|
+
errors.append(f"引用[{i}] 的 material 不是整数")
|
|
229
|
+
continue
|
|
230
|
+
if mark not in counts:
|
|
231
|
+
errors.append(f"引用[{i}] 的 mark={mark} 在正文中不存在")
|
|
232
|
+
continue
|
|
233
|
+
if material < 1 or material > material_count:
|
|
234
|
+
errors.append(f"引用[{i}] 的 material={material} 超出素材清单范围(1..{material_count})")
|
|
235
|
+
continue
|
|
236
|
+
if material != mark:
|
|
237
|
+
errors.append(
|
|
238
|
+
f"引用[{i}] 的 material={material} 与 mark={mark} 不一致——"
|
|
239
|
+
f"角标号即素材清单序号,两者必须相同,否则正文 [{mark}] 可以拿第 {material} 篇的原文通过校验")
|
|
240
|
+
continue
|
|
241
|
+
quote = str(rec.get("quote") or "").strip()
|
|
242
|
+
sentence = str(rec.get("sentence") or "").strip()
|
|
243
|
+
usage = str(rec.get("用法") or rec.get("usage") or "").strip()
|
|
244
|
+
if len(flat(quote)) < CIT_QUOTE_MIN:
|
|
245
|
+
errors.append(
|
|
246
|
+
f"引用[{i}](mark={mark})quote 为空或过短(须≥{CIT_QUOTE_MIN}字原文片段,"
|
|
247
|
+
f"当前 {len(flat(quote))} 字)")
|
|
248
|
+
if not sentence:
|
|
249
|
+
errors.append(f"引用[{i}](mark={mark})缺 sentence(正文中该角标所在的原句)")
|
|
250
|
+
elif not re.search(rf"[\[【]\s*{mark}\s*[\]】]", sentence):
|
|
251
|
+
errors.append(
|
|
252
|
+
f"引用[{i}](mark={mark})的 sentence 必须包含角标 [{mark}] 本身"
|
|
253
|
+
f"(照抄正文原句,含角标):{sentence[:30]}")
|
|
254
|
+
elif flat(sentence) not in flat_body:
|
|
255
|
+
errors.append(f"引用[{i}](mark={mark})的 sentence 在正文中找不到:{sentence[:30]}")
|
|
256
|
+
if usage not in CIT_USAGE_VALUES:
|
|
257
|
+
errors.append(f"引用[{i}](mark={mark})的用法须为「依据」或「借鉴」,当前:{usage or '空'}")
|
|
258
|
+
per_mark[mark] = per_mark.get(mark, 0) + 1
|
|
259
|
+
cleaned.append({"mark": mark, "material": material, "quote": quote,
|
|
260
|
+
"sentence": sentence, "usage": usage})
|
|
261
|
+
|
|
262
|
+
for mark, need in counts.items():
|
|
263
|
+
got = per_mark.get(mark, 0)
|
|
264
|
+
if got != need:
|
|
265
|
+
errors.append(
|
|
266
|
+
f"角标 [{mark}] 在正文出现 {need} 处,但引用对照只有 {got} 条——"
|
|
267
|
+
f"每处引用都要交一条对应原文片段(不能一篇材料只交一段、多处复用)")
|
|
268
|
+
# 同一角标多次出现时,每条 sentence 必须对上各自的第 k 处(不能多句套同一处)
|
|
269
|
+
errors.extend(check_mark_occurrence_binding(body, cleaned))
|
|
270
|
+
if errors:
|
|
271
|
+
raise SystemExit("错误:引用对照校验未通过:\n- " + "\n- ".join(errors))
|
|
272
|
+
|
|
273
|
+
# 按正文出现次序装配:按句子内容逐处认领,认领不到即报错(杜绝靠条数糊弄)
|
|
274
|
+
pool = list(cleaned)
|
|
275
|
+
ordered = []
|
|
276
|
+
for mark, seg in mark_occurrences(body):
|
|
277
|
+
hit = next((r for r in pool if r["mark"] == mark and cmp_norm(r["sentence"]) == seg), None)
|
|
278
|
+
if hit is None:
|
|
279
|
+
raise SystemExit(
|
|
280
|
+
f"错误:引用对照与正文错位——角标 [{mark}] 的正文原句「{seg[:26]}」没有对应的引用记录,"
|
|
281
|
+
"请按出现次序逐处补齐 sentence"
|
|
282
|
+
)
|
|
283
|
+
pool.remove(hit)
|
|
284
|
+
ordered.append(hit)
|
|
285
|
+
return ordered
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def require_inside(path_value: str, label: str) -> Path:
|
|
289
|
+
"""输入路径必须落在本技能目录内(official-docs 之下),否则拒绝读取。
|
|
290
|
+
|
|
291
|
+
关标统一由脚本自身定位,不接受目录外的绝对路径,避免把任意文件读进产物。
|
|
292
|
+
"""
|
|
293
|
+
path = Path(path_value).expanduser().resolve()
|
|
294
|
+
allowed = [(WS_ROOT / "official-docs").resolve()]
|
|
295
|
+
if not any(path.is_relative_to(base) for base in allowed):
|
|
296
|
+
raise SystemExit(
|
|
297
|
+
f"错误:{label} 必须位于 {WS_ROOT / 'official-docs'} 之内,当前为 {path}。"
|
|
298
|
+
)
|
|
299
|
+
if path.suffix.lower() != ".json" and label != "问题文件":
|
|
300
|
+
raise SystemExit(f"错误:{label} 必须是 JSON 文件:{path}")
|
|
301
|
+
return path
|
|
302
|
+
|
|
143
303
|
def resolve_selected_index(selected: list, by_title: dict, by_url: dict) -> list:
|
|
144
304
|
"""为清单每条定位合并产物文章;返回 (条目, 文章或None)。"""
|
|
145
305
|
resolved = []
|
|
@@ -176,6 +336,8 @@ def main() -> int:
|
|
|
176
336
|
"溯源报告顶部展示完整原问题,供报告独立使用)")
|
|
177
337
|
parser.add_argument("--question-file", help="用户原始问题全文文件(多行/长 prompt 优先用此参数,"
|
|
178
338
|
"避免只传首行导致溯源报告原问题被截断)")
|
|
339
|
+
parser.add_argument("--citations", help="引用对照 JSON(official-docs/input/引用对照_<任务>.json);"
|
|
340
|
+
"缺省按素材清单同名自动查找")
|
|
179
341
|
parser.add_argument("--output", "-o", help="输出溯源 JSON 文件名(写入 official-docs/input/)")
|
|
180
342
|
parser.add_argument("--sample", action="store_true", help="打印素材清单示例结构")
|
|
181
343
|
args = parser.parse_args()
|
|
@@ -184,19 +346,28 @@ def main() -> int:
|
|
|
184
346
|
print(json.dumps({
|
|
185
347
|
"task": "任务名",
|
|
186
348
|
"selected": [
|
|
187
|
-
{"type": "政策依据型", "标题": "国务院关于印发新一代人工智能发展规划的通知", "源网址": "https://..."
|
|
188
|
-
|
|
349
|
+
{"type": "政策依据型", "标题": "国务院关于印发新一代人工智能发展规划的通知", "源网址": "https://...",
|
|
350
|
+
"发布机关": "国务院", "status": "现行", "region": "全国"},
|
|
351
|
+
{"type": "数据支撑型", "标题": "北京市人工智能产业发展报告", "源网址": "https://...",
|
|
352
|
+
"发布机关": "北京市经济和信息化局", "status": "现行", "region": "外省"},
|
|
189
353
|
],
|
|
354
|
+
"引用对照示例": {
|
|
355
|
+
"task": "任务名",
|
|
356
|
+
"citations": [
|
|
357
|
+
{"mark": 1, "material": 1, "sentence": "正文中该角标所在的原句",
|
|
358
|
+
"quote": "该句依据的原文片段(须在材料中逐字存在)", "用法": "依据"},
|
|
359
|
+
],
|
|
360
|
+
},
|
|
190
361
|
}, ensure_ascii=False, indent=2))
|
|
191
362
|
return 0
|
|
192
363
|
|
|
193
364
|
if not (args.materials_list and args.body_file and args.merged_json):
|
|
194
365
|
raise SystemExit("用法:python3 scripts/build_trace_json.py <素材清单> <正文文件> <合并产物JSON> --title <标题> --output <溯源JSON>")
|
|
195
366
|
|
|
196
|
-
materials_list = load_json(
|
|
367
|
+
materials_list = load_json(require_inside(args.materials_list, "素材清单"))
|
|
197
368
|
question_text = (args.question or "").strip()
|
|
198
369
|
if args.question_file:
|
|
199
|
-
question_path =
|
|
370
|
+
question_path = require_inside(args.question_file, "问题文件")
|
|
200
371
|
try:
|
|
201
372
|
question_text = question_path.read_text(encoding="utf-8").strip()
|
|
202
373
|
except OSError as exc:
|
|
@@ -211,7 +382,7 @@ def main() -> int:
|
|
|
211
382
|
"请先保存到 official-docs/input/ 后再装配溯源 JSON。"
|
|
212
383
|
)
|
|
213
384
|
body = body_path.read_text(encoding="utf-8")
|
|
214
|
-
merged = load_json(
|
|
385
|
+
merged = load_json(require_inside(args.merged_json, "合并产物"))
|
|
215
386
|
|
|
216
387
|
selected = materials_list.get("selected") or []
|
|
217
388
|
if not selected:
|
|
@@ -222,6 +393,8 @@ def main() -> int:
|
|
|
222
393
|
|
|
223
394
|
# ① materials:按正文角标序取清单对应篇
|
|
224
395
|
citations = extract_citations(body)
|
|
396
|
+
citation_file = find_citation_file(args, Path(args.materials_list).expanduser())
|
|
397
|
+
citation_records = load_citation_records(citation_file, body, len(resolved))
|
|
225
398
|
by_pos = {n: item for n, item in enumerate(resolved, 1)}
|
|
226
399
|
materials = []
|
|
227
400
|
for n in citations:
|
|
@@ -242,6 +415,12 @@ def main() -> int:
|
|
|
242
415
|
mat["excerpt"] = excerpt[:400]
|
|
243
416
|
mat["excerpts"] = [excerpt[:400]] if excerpt else []
|
|
244
417
|
mat["search_key"] = first_value(item, SEL_SEARCH_KEY_FIELDS) or mat.get("search_key", "")
|
|
418
|
+
# 版本与地域元数据(素材清单必填):供报告展示与 check_materials 拦截"引用历史版本/外省依据"
|
|
419
|
+
mat["status"] = first_value(item, ("status", "效力状态", "版本状态"))
|
|
420
|
+
mat["region"] = first_value(item, ("region", "地域属性", "地域"))
|
|
421
|
+
mat["issue_org"] = first_value(item, ("发布机关", "发文机关", "发布或实施机构"))
|
|
422
|
+
# 引用实例:本篇在正文中被引用的每一处,各带自己的原文片段
|
|
423
|
+
mat["citations"] = [c for c in citation_records if c["material"] == n]
|
|
245
424
|
materials.append(mat)
|
|
246
425
|
|
|
247
426
|
if not materials:
|
|
@@ -268,6 +447,11 @@ def main() -> int:
|
|
|
268
447
|
seen_keys.add(key)
|
|
269
448
|
rm = map_article_fields(art)
|
|
270
449
|
rm["type"] = first_value(item, SEL_TYPE_FIELDS) or "材料"
|
|
450
|
+
# 来自素材清单的条目:版本/地域/发布机关与 selected 一样必须齐备(check_materials 校验)
|
|
451
|
+
rm["from_selected"] = True
|
|
452
|
+
rm["status"] = first_value(item, ("status", "效力状态", "版本状态"))
|
|
453
|
+
rm["region"] = first_value(item, ("region", "地域属性", "地域"))
|
|
454
|
+
rm["issue_org"] = first_value(item, ("发布机关", "发文机关", "发布或实施机构"))
|
|
271
455
|
recalled.append(rm)
|
|
272
456
|
# 合并产物中未被清单覆盖的剩余材料
|
|
273
457
|
for art in merged.get("articles") or []:
|
|
@@ -279,13 +463,15 @@ def main() -> int:
|
|
|
279
463
|
seen_keys.add(key)
|
|
280
464
|
rm = map_article_fields(art)
|
|
281
465
|
rm["type"] = "材料"
|
|
466
|
+
# 合并产物里未被清单选中的召回材料:不受"三字段必填"约束
|
|
467
|
+
rm["from_selected"] = False
|
|
282
468
|
recalled.append(rm)
|
|
283
469
|
|
|
284
|
-
# ③ self_check
|
|
285
|
-
#
|
|
286
|
-
#
|
|
287
|
-
#
|
|
288
|
-
#
|
|
470
|
+
# ③ self_check 骨架(五项待模型填写,两轨验收的 Agent 轨)
|
|
471
|
+
# 每项填结构化对象:{"verdict": "pass|fail|pending", "basis": "结论依据", "evidence": ["可回查证据", …]}。
|
|
472
|
+
# 硬约束:verdict=pass 时 evidence 必须含可回查要素(材料角标 [n]/条款号/文号/日期/
|
|
473
|
+
# 文件名/GB 标准号任一),裸写「通过」或证据无要素会被渲染器按 evidence_missing 拦截;
|
|
474
|
+
# fail 否决、pending 只表示待人工复核。骨架用空字符串占位(如实显示"未记录")。
|
|
289
475
|
self_check = {k: "" for k in SELF_CHECK_ITEMS}
|
|
290
476
|
|
|
291
477
|
trace = {
|
|
@@ -299,6 +485,12 @@ def main() -> int:
|
|
|
299
485
|
"document_content": body,
|
|
300
486
|
"materials": materials,
|
|
301
487
|
"recalled_materials": recalled,
|
|
488
|
+
# 引用实例全量(逐处 quote):check_materials 据此做"角标↔原句↔原文片段"三方校验
|
|
489
|
+
"citations": citation_records,
|
|
490
|
+
# 装配所用的合并产物:渲染前的引用门禁据此比对 quote 是否真在该材料原文中
|
|
491
|
+
"merged_json": (str(Path(args.merged_json).expanduser().resolve().relative_to(WS_ROOT))
|
|
492
|
+
if Path(args.merged_json).expanduser().resolve().is_relative_to(WS_ROOT)
|
|
493
|
+
else str(Path(args.merged_json).expanduser().resolve())),
|
|
302
494
|
"self_check": self_check,
|
|
303
495
|
# 用户明确字数要求时由素材清单传入(如 {"min": 4000, "max": 5000});
|
|
304
496
|
# 未提字数时为空,check_materials 不做篇幅校验。
|
|
@@ -324,7 +516,7 @@ def main() -> int:
|
|
|
324
516
|
"materials": len(materials),
|
|
325
517
|
"recalled_materials": len(recalled),
|
|
326
518
|
"citations": citations,
|
|
327
|
-
"note": "溯源 JSON
|
|
519
|
+
"note": "溯源 JSON 已装配。请把 self_check 五项填成结构化结果(verdict/basis/evidence,pass 必须带可回查证据),再运行 check_materials.py 校验、source_note_html.py 渲染。",
|
|
328
520
|
}, ensure_ascii=False, indent=2))
|
|
329
521
|
return 0
|
|
330
522
|
|