enrichment.py¶
clew/enrichment.py
Optional architecture-topics enrichment from a YAML curriculum file.
enrich_database
None clew.enrichment.enrich_database(Path db_path, Path yaml_path)
Populate architecture_topics table from a YAML curriculum file.
Called by _build_stages, _enrich
Tested by
Calls _create_topics_table, _insert_topics
Source · 31 lines
def enrich_database(db_path: Path, yaml_path: Path) -> None:
"""Populate architecture_topics table from a YAML curriculum file.
The YAML file should contain a list of topic entries with fields:
topic, title, summary, key_files, key_concepts, prerequisite_topics,
difficulty. Existing rows in architecture_topics are deleted before
insert so re-running the build idempotently overwrites the table.
@brief Add architecture_topics table from YAML enrichment file.
@version 2
"""
try:
import yaml
except ImportError:
logger.error("PyYAML required for enrichment: pip install pyyaml")
sys.exit(1)
topics = yaml.safe_load(yaml_path.read_text())
if not isinstance(topics, list):
logger.error("Expected a YAML list in %s", yaml_path)
sys.exit(1)
conn = sqlite3.connect(str(db_path))
_create_topics_table(conn)
_insert_topics(conn, topics)
conn.close()
logger.info(
"Enriched database with %d topics from %s",
len(topics),
yaml_path,
)1 more lines, not shown