""" Default junior-high math knowledge catalog(与 frontend/src/data/knowledgeCatalog.ts 保持一致,用于一键同步到 Neo4j)。 结构: { 年级: { 类别: [ { code, name }, ... ] } } """ from __future__ import annotations from typing import TypedDict class TopicItem(TypedDict): code: str name: str DEFAULT_KNOWLEDGE_CATALOG: dict[str, dict[str, list[TopicItem]]] = { "七年级": { "代数与方程": [ {"code": "J7-EQ-001", "name": "一元一次方程"}, {"code": "J7-EQ-002", "name": "二元一次方程组"}, ], "几何基础": [ {"code": "J7-GEO-001", "name": "线段与角"}, {"code": "J7-GEO-002", "name": "相交线与平行线"}, ], }, "八年级": { "代数与函数": [ {"code": "J8-FUNC-001", "name": "一次函数"}, {"code": "J8-ROOT-001", "name": "二次根式"}, ], "几何证明": [ {"code": "J8-GEO-001", "name": "全等三角形"}, {"code": "J8-GEO-002", "name": "轴对称"}, ], }, "九年级": { "代数进阶": [ {"code": "J9-EQ-001", "name": "一元二次方程"}, {"code": "J9-FUNC-001", "name": "二次函数"}, ], "圆与统计": [ {"code": "J9-CIRCLE-001", "name": "圆的基本性质"}, {"code": "J9-STAT-001", "name": "概率初步"}, ], }, } def iter_catalog_topics() -> list[tuple[str, str, str, str]]: """遍历目录,返回 (年级, 类别, 编码, 名称) 列表。""" out: list[tuple[str, str, str, str]] = [] for grade, categories in DEFAULT_KNOWLEDGE_CATALOG.items(): for category, topics in categories.items(): for t in topics: out.append((grade, category, t["code"], t["name"])) return out