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>
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 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.
Trait Implementations§
Source§impl Debug for KnowledgeGraph
impl Debug for KnowledgeGraph
Auto Trait Implementations§
impl Freeze for KnowledgeGraph
impl RefUnwindSafe for KnowledgeGraph
impl Send for KnowledgeGraph
impl Sync for KnowledgeGraph
impl Unpin for KnowledgeGraph
impl UnsafeUnpin for KnowledgeGraph
impl UnwindSafe for KnowledgeGraph
Blanket Implementations§
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
Mutably borrows from an owned value. Read more