pub struct KnowledgeGraphTraverser {
pub graph: KnowledgeGraph,
}Expand description
Provides graph traversal, path-finding, and subgraph extraction over a
KnowledgeGraph.
All algorithms are iterative (no recursion) to avoid stack-overflow on large graphs and to give predictable performance for distributed workloads.
Fields§
§graph: KnowledgeGraphThe underlying knowledge graph.
Implementations§
Source§impl KnowledgeGraphTraverser
impl KnowledgeGraphTraverser
Sourcepub fn new(graph: KnowledgeGraph) -> Self
pub fn new(graph: KnowledgeGraph) -> Self
Wrap a KnowledgeGraph in a traverser.
Sourcepub fn bfs(&self, start: &str, max_depth: usize) -> Vec<String>
pub fn bfs(&self, start: &str, max_depth: usize) -> Vec<String>
Breadth-first search starting from start.
Returns the node IDs in BFS visit order. Nodes deeper than
max_depth hops from start are not visited. A visited-set
prevents cycles from causing duplicate visits.
Returns an empty Vec if start does not exist in the graph.
Sourcepub fn dfs(&self, start: &str, max_depth: usize) -> Vec<String>
pub fn dfs(&self, start: &str, max_depth: usize) -> Vec<String>
Depth-first search starting from start.
Returns node IDs in DFS visit order (pre-order). Nodes deeper than
max_depth hops from start are not visited. A visited-set
prevents revisiting nodes in cyclic graphs.
Returns an empty Vec if start does not exist in the graph.
Sourcepub fn find_path(&self, from: &str, to: &str) -> Option<Vec<String>>
pub fn find_path(&self, from: &str, to: &str) -> Option<Vec<String>>
Find the shortest path (fewest hops) from from to to using BFS.
Returns Some(path) where path is the sequence of node IDs from
from to to inclusive, or None if no path exists or either
endpoint is absent.
Sourcepub fn subgraph(&self, roots: &[String], depth: usize) -> KnowledgeGraph
pub fn subgraph(&self, roots: &[String], depth: usize) -> KnowledgeGraph
Extract the subgraph reachable from any of the roots within depth
hops (inclusive).
The returned KnowledgeGraph contains all reachable nodes together
with every edge whose both endpoints are in the reachable set.
Sourcepub fn connected_components(&self) -> Vec<Vec<String>>
pub fn connected_components(&self) -> Vec<Vec<String>>
Compute the connected components of the undirected version of the graph using union-find (path-compressed, union-by-rank).
Returns one Vec<String> per component. Each component’s node IDs
are sorted lexicographically. Components are themselves ordered by
their smallest member.
Auto Trait Implementations§
impl Freeze for KnowledgeGraphTraverser
impl RefUnwindSafe for KnowledgeGraphTraverser
impl Send for KnowledgeGraphTraverser
impl Sync for KnowledgeGraphTraverser
impl Unpin for KnowledgeGraphTraverser
impl UnsafeUnpin for KnowledgeGraphTraverser
impl UnwindSafe for KnowledgeGraphTraverser
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more