#!/usr/bin/env python3 """Query the non-verbatim book -> rule -> technique lineage map.""" from __future__ import annotations import argparse, json from pathlib import Path ROOT = Path(__file__).resolve().parents[1] DEFAULT_PARASHARI_BASELINE = ( "d1_rashi", "d9_navamsa", "d2_hora", "d10_dasamsa", "d11_labhamsha", "varga_dignity", "vargottama", "vimshottari_dasha", "dasha_sandhi", "transit_trigger", "shadbala", "bhava_bala", "ashtakavarga", "raj_yoga", "dhana_yoga", "neechabhanga", "solar_lunar_yogas", "moolatrikona", "combustion", "graha_yuddha", "dispositor_chain", "functional_benefic_malefic", "nakshatra_advanced", "shodasavarga", ) def load(path: str | None = None) -> dict: p = Path(path) if path else ROOT / "references/book_rule_technique_lineage.json" return json.loads(p.read_text(encoding="utf-8")) def query(data: dict, *, technique: str | None = None, profile: str | None = None) -> list[dict]: rows = data.get("rows", []) return [r for r in rows if (not technique or technique in r.get("techniques", [])) and (not profile or r.get("tradition_profile") == profile)] def audit_baseline(data: dict) -> list[dict]: rows = data.get("rows", []) result = [] for technique in DEFAULT_PARASHARI_BASELINE: matches = [r for r in rows if technique in r.get("techniques", []) and r.get("tradition_profile") == "parashari_core"] kinds = {"web_reference" if str(r.get("source_id", "")).startswith("web:") else "local_book" for r in matches} result.append({ "technique": technique, "source_status": ("web_reference" if kinds == {"web_reference"} else "mapped") if matches else "unmapped", "source_count": len(matches), "runtime_statuses": sorted({str(r.get("runtime_status")) for r in matches}), "next_action": ("review_rule_packet_and_runtime_receipt" if matches else "locate_book_chapter_or_add_candidate_packet"), }) return result def main() -> None: ap = argparse.ArgumentParser() ap.add_argument("--technique") ap.add_argument("--tradition-profile") ap.add_argument("--format", choices=["json", "count"], default="json") ap.add_argument("--audit-baseline", action="store_true") args = ap.parse_args() data = load() if args.audit_baseline: rows = audit_baseline(data) else: rows = query(data, technique=args.technique, profile=args.tradition_profile) print(len(rows) if args.format == "count" else json.dumps(rows, ensure_ascii=False, indent=2)) if __name__ == "__main__": main()