pub struct KnowledgeGraph {
pub communities: Vec<CommunityInfo>,
pub hyperedges: Vec<Hyperedge>,
/* private fields */
}Expand description
A knowledge graph backed by petgraph::StableGraph.
Provides ID-based node lookup and serialization to/from the
NetworkX node_link_data JSON format for Python interoperability.
Fields§
§communities: Vec<CommunityInfo>§hyperedges: Vec<Hyperedge>Implementations§
Source§impl KnowledgeGraph
impl KnowledgeGraph
pub fn new() -> Self
Sourcepub fn add_node(&mut self, node: GraphNode) -> Result<NodeIndex>
pub fn add_node(&mut self, node: GraphNode) -> Result<NodeIndex>
Add a node. Returns an error if a node with the same id already exists.
Sourcepub fn add_edge(&mut self, edge: GraphEdge) -> Result<()>
pub fn add_edge(&mut self, edge: GraphEdge) -> Result<()>
Add an edge between two nodes identified by their string IDs.
pub fn get_node(&self, id: &str) -> Option<&GraphNode>
Sourcepub fn get_node_mut(&mut self, id: &str) -> Option<&mut GraphNode>
pub fn get_node_mut(&mut self, id: &str) -> Option<&mut GraphNode>
Get a mutable reference to a node by its string ID.
pub fn get_neighbors(&self, id: &str) -> Vec<&GraphNode>
pub fn node_count(&self) -> usize
pub fn edge_count(&self) -> usize
Sourcepub fn set_hyperedges(&mut self, h: Vec<Hyperedge>)
pub fn set_hyperedges(&mut self, h: Vec<Hyperedge>)
Replace the hyperedges list.
Sourcepub fn neighbor_ids(&self, id: &str) -> Vec<String>
pub fn neighbor_ids(&self, id: &str) -> Vec<String>
Get neighbor IDs as strings.
Sourcepub fn edges_with_endpoints(&self) -> Vec<(&str, &str, &GraphEdge)>
pub fn edges_with_endpoints(&self) -> Vec<(&str, &str, &GraphEdge)>
Iterate over all edges as (source_id, target_id, &GraphEdge).
Sourcepub fn to_node_link_json(&self) -> Value
pub fn to_node_link_json(&self) -> Value
Serialize to the NetworkX node_link_data JSON format.
Sourcepub fn write_node_link_json<W: Write>(&self, writer: W) -> Result<()>
pub fn write_node_link_json<W: Write>(&self, writer: W) -> Result<()>
Stream the graph as NetworkX node_link_data JSON directly to a writer.
Unlike to_node_link_json(), this avoids building the entire JSON tree
in memory. For a 50K-node graph this saves ~500 MB of intermediate
allocations.
Sourcepub fn from_node_link_json(value: &Value) -> Result<Self>
pub fn from_node_link_json(value: &Value) -> Result<Self>
Deserialize from the NetworkX node_link_data JSON format.