From 05348e5a79bcbde9b9e0410d9ed66498095ce955 Mon Sep 17 00:00:00 2001 From: Shay Date: Wed, 8 Jul 2026 07:21:17 -0700 Subject: [PATCH] =?UTF-8?q?refactor:=20consolidate=20duplicate=20depth=20e?= =?UTF-8?q?xtraction=20=E2=80=94=20graph=5Fplanner.get=5Fnode=5Fdepths=20n?= =?UTF-8?q?ow=20delegates=20to=20build=5Fnode=5Fdepths=20(single=20source)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses MEDIUM from code-review: eliminates duplication risk between GraphNode method and pure canonical func. Tests (graph_anti / node_depths) remain green. --- generate/graph_planner.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/generate/graph_planner.py b/generate/graph_planner.py index e97cfca9..ad435a5a 100644 --- a/generate/graph_planner.py +++ b/generate/graph_planner.py @@ -107,20 +107,13 @@ class PropositionGraph: def get_node_depths(self) -> dict[str, dict]: """Return nid -> {language, root, morphology_id} for nodes carrying 3-lang depth. - Pure extraction. Enables graph-level consumers (anti-unif, framing, realizer) + Delegates to the canonical pure extractor in recognition.depth_canonical + (single source of truth; avoids duplication with build_node_depths). + Enables graph-level consumers (anti-unif, framing, realizer) to operate on root forms for he/grc without string hacks. """ - return { - n.node_id: { - k: v for k, v in { - "language": n.language, - "root": n.root, - "morphology_id": n.morphology_id, - }.items() if v is not None - } - for n in self.nodes - if n.language or n.root or n.morphology_id - } + from recognition.depth_canonical import build_node_depths + return build_node_depths(self.nodes) def topo_order(self) -> tuple[str, ...]: """Kahn's topological sort over the graph's edges.