axes.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. """Shared axes for formal creation-query families."""
  2. from __future__ import annotations
  3. import json
  4. from pathlib import Path
  5. ROOT = Path(__file__).resolve().parents[2]
  6. TREES = ROOT / "scope_trees" / "trees_index.json"
  7. ACTIONS = ["构思", "策划", "组织", "撰写", "改编", "润色"]
  8. STAGES = ["灵感", "选题", "脚本"]
  9. KTYPE_SUFFIX = {"what": "有哪些", "why": "为什么", "how": "怎么做"}
  10. def _nonleaf_d4(
  11. source_type: str,
  12. limit: int,
  13. under: str | None = None,
  14. *,
  15. tree_path: Path = TREES,
  16. ) -> list[str]:
  17. """Return level-4 non-leaf node names, preserving the legacy axis order."""
  18. idx = json.loads(tree_path.read_text("utf-8"))
  19. paths = {
  20. n.get("path") or ""
  21. for n in idx
  22. if n.get("source_type") == source_type
  23. and (not under or under in (n.get("path") or "").split("/"))
  24. }
  25. d4 = [p for p in paths if len([x for x in p.split("/") if x]) == 4]
  26. nonleaf = sorted(p for p in d4 if any(o != p and o.startswith(p + "/") for o in paths))
  27. return [p.split("/")[-1] for p in nonleaf][:limit]