Skip to main content

Module query

Module query 

Source
Expand description

BFS reachability search and orphan/stub detection.

Structs§

Connectivity
One entity’s degree counts. total == incoming + outgoing; kept explicit so the JSON wire shape is self-describing and callers don’t re-derive it.

Functions§

cmp_by_dependency
Centrality ordering: dependency degree (typed_total) descending first, then raw total descending, then id lexicographic ascending as a stable deterministic tie-break. Ranking by typed_total keeps a co-mention-inflated hub from outranking a real dependency hub.
connectivity_for
Compute one entity’s raw and typed degree. incoming_counts decides which incoming edges contribute (e.g. source-in-mem scoping for a mem-filtered health view); every outgoing edge always counts. Typed degree excludes EdgeSource::BodyLink (auto-emitted mention) edges.
find_orphans
Find orphan entities — non-stub entities with no edges at all (completely isolated).
find_stubs
Find stub entities — entities created from unresolved references. Returns each stub with the list of entities that reference it.
most_connected
Find the most connected non-stub entities, ranked by dependency degree (typed edges) — see cmp_by_dependency. Returns up to limit entries.
reachable
Find all entities reachable from a starting entity within max_depth hops. Undirected traversal (follows both outgoing and incoming edges). Returns the set of reachable entity IDs including the start node.
reachable_distances
Like reachable but returns each reached entity’s hop-distance from from — the depth at which BFS first reaches it (from itself is 0). Undirected (outgoing + incoming), same membership as reachable. The distances drive proximity ranking of a related_to neighbourhood: nearer first.
reachable_via
Find all entities reachable from from by walking only edges whose rel_type is in edge_types, up to max_depth hops. Undirected traversal (outgoing + incoming). Returns one tuple per reached entity — never from itself — carrying the edge label used to first reach it and the depth of that first reach (1 = direct neighbour).
would_cycle
Would adding an edge from --rel_type--> to close a cycle in the subgraph restricted to edges of rel_type? Returns the back-path as [to, …, from] when a cycle exists, None otherwise.