MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / resolve_section_query

Function resolve_section_query

graphify/sections.py:179–204  ·  view source on GitHub ↗

Resolve a heading label, node id or ``path::Heading`` to one section node. An explicit node id takes precedence. For a name or path query, retry against the section nodes so a code symbol cannot hide a heading match.

(G, query: str)

Source from the content-addressed store, hash-verified

177
178
179def resolve_section_query(G, query: str) -> "tuple[str | None, str]":
180 """Resolve a heading label, node id or ``path::Heading`` to one section node.
181
182 An explicit node id takes precedence. For a name or path query, retry
183 against the section nodes so a code symbol cannot hide a heading match.
184 """
185 from graphify.serve import _is_ambiguity_refusal, _resolve_single_node
186
187 nid, err = _resolve_single_node(G, query)
188 if nid is not None and (query == nid or is_section_node(G.nodes[nid])):
189 return nid, ""
190 sections = G.subgraph([n for n, d in G.nodes(data=True) if is_section_node(d)])
191 # A subgraph view shares G.graph, so it would reuse the full graph's search
192 # caches (ids of nodes not in the view) or store its own over the full
193 # graph's. Keep public graph metadata and the logical direction flag, but
194 # discard other private state so future caches cannot leak into this view.
195 sections.graph = {
196 k: v for k, v in G.graph.items()
197 if not k.startswith("_") or k in _SECTION_VIEW_GRAPH_KEYS
198 }
199 sec_nid, sec_err = _resolve_single_node(sections, query)
200 if sec_nid is not None:
201 return sec_nid, ""
202 if sec_err and _is_ambiguity_refusal(sec_err):
203 return None, sec_err
204 return nid, err or ""

Calls 4

_resolve_single_nodeFunction · 0.90
_is_ambiguity_refusalFunction · 0.90
is_section_nodeFunction · 0.85
itemsMethod · 0.45