pub struct KnowledgeGraph {
pub directed: bool,
/* private fields */
}Expand description
知识图谱。有向 / 无向在图级别声明(布局与邻接口径一致)。
Fields§
§directed: bool是否有向;无向图的邻接查询双向对称。
Implementations§
Source§impl KnowledgeGraph
impl KnowledgeGraph
pub fn new() -> Self
Sourcepub fn alloc_node_id(&mut self) -> NodeId
pub fn alloc_node_id(&mut self) -> NodeId
分配并占用一个新节点 ID(导入预扫用,避免逐条 add 的开销)。
pub fn alloc_edge_id(&mut self) -> EdgeId
pub fn alloc_kind_id(&mut self) -> KindId
pub fn add_kind(&mut self, name: impl Into<String>) -> KindId
Sourcepub fn upsert_kind(&mut self, id: KindId, name: impl Into<String>)
pub fn upsert_kind(&mut self, id: KindId, name: impl Into<String>)
插入指定 ID 的类型;已存在时只更新名称(CSV 按名引用的场景)。
pub fn kind(&self, id: KindId) -> Option<&NodeKind>
pub fn add_node( &mut self, label: impl Into<String>, kind: Option<KindId>, ) -> NodeId
Sourcepub fn insert_node(&mut self, node: Node) -> Result<(), GraphError>
pub fn insert_node(&mut self, node: Node) -> Result<(), GraphError>
插入完整节点(导入路径)。ID 已存在返回错误且不产生半写入。
Sourcepub fn update_node(&mut self, node: Node) -> Result<(), GraphError>
pub fn update_node(&mut self, node: Node) -> Result<(), GraphError>
直接更新节点(保留原位置语义在布局层,这里只是存储替换)。
pub fn node(&self, id: NodeId) -> Option<&Node>
Sourcepub fn remove_node(&mut self, id: NodeId) -> Result<(), GraphError>
pub fn remove_node(&mut self, id: NodeId) -> Result<(), GraphError>
删除节点,级联删除全部关联边。
pub fn add_edge( &mut self, source: NodeId, target: NodeId, weight: f32, label: Option<String>, ) -> Result<EdgeId, GraphError>
pub fn edge(&self, id: EdgeId) -> Option<&Edge>
pub fn remove_edge(&mut self, id: EdgeId) -> Result<(), GraphError>
pub fn node_count(&self) -> usize
pub fn edge_count(&self) -> usize
pub fn nodes(&self) -> impl Iterator<Item = &Node>
pub fn edges(&self) -> impl Iterator<Item = &Edge>
Sourcepub fn adjacency(&self) -> &AdjacencyIndex
pub fn adjacency(&self) -> &AdjacencyIndex
邻接索引(一度邻居 / 入射边 / 度数)。
Sourcepub fn from_json(json: &str) -> Result<Self, GraphError>
pub fn from_json(json: &str) -> Result<Self, GraphError>
从 JSON 文档导入。坏 JSON 返回 GraphError::Format,不 panic。
Trait Implementations§
Source§impl Clone for KnowledgeGraph
impl Clone for KnowledgeGraph
Source§impl Debug for KnowledgeGraph
impl Debug for KnowledgeGraph
Auto Trait Implementations§
impl Forget for KnowledgeGraph
impl Freeze for KnowledgeGraphwhere
*const LeafNode<KindId, NodeKind> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(KindId, NodeKind)>>: Freeze,
*const LeafNode<NodeId, Node> is !null: Freeze,
PhantomData<Box<(NodeId, Node)>>: Freeze,
*const LeafNode<EdgeId, Edge> is !null: Freeze,
PhantomData<Box<(EdgeId, Edge)>>: Freeze,
*const LeafNode<NodeId, Adjacency> is !null: Freeze,
PhantomData<Box<(NodeId, Adjacency)>>: Freeze,
impl Move for KnowledgeGraph
impl RefUnwindSafe for KnowledgeGraph
impl Send for KnowledgeGraphwhere
NodeRef<Owned, KindId, NodeKind, LeafOrInternal>: Send,
BoxRaw<(KindId, NodeKind)>: Send,
NodeRef<Owned, NodeId, Node, LeafOrInternal>: Send,
BoxRaw<(NodeId, Node)>: Send,
NodeRef<Owned, EdgeId, Edge, LeafOrInternal>: Send,
BoxRaw<(EdgeId, Edge)>: Send,
NodeRef<Owned, NodeId, Adjacency, LeafOrInternal>: Send,
BoxRaw<(NodeId, Adjacency)>: Send,
impl Sync for KnowledgeGraphwhere
NodeRef<Owned, KindId, NodeKind, LeafOrInternal>: Sync,
BoxRaw<(KindId, NodeKind)>: Sync,
NodeRef<Owned, NodeId, Node, LeafOrInternal>: Sync,
BoxRaw<(NodeId, Node)>: Sync,
NodeRef<Owned, EdgeId, Edge, LeafOrInternal>: Sync,
BoxRaw<(EdgeId, Edge)>: Sync,
NodeRef<Owned, NodeId, Adjacency, LeafOrInternal>: Sync,
BoxRaw<(NodeId, Adjacency)>: Sync,
impl Unpin for KnowledgeGraphwhere
*const LeafNode<KindId, NodeKind> is !null: Unpin,
Box<(KindId, NodeKind)>: Unpin,
*const LeafNode<NodeId, Node> is !null: Unpin,
Box<(NodeId, Node)>: Unpin,
*const LeafNode<EdgeId, Edge> is !null: Unpin,
Box<(EdgeId, Edge)>: Unpin,
*const LeafNode<NodeId, Adjacency> is !null: Unpin,
Box<(NodeId, Adjacency)>: Unpin,
impl UnsafeUnpin for KnowledgeGraphwhere
*const LeafNode<KindId, NodeKind> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(KindId, NodeKind)>>: UnsafeUnpin,
*const LeafNode<NodeId, Node> is !null: UnsafeUnpin,
PhantomData<Box<(NodeId, Node)>>: UnsafeUnpin,
*const LeafNode<EdgeId, Edge> is !null: UnsafeUnpin,
PhantomData<Box<(EdgeId, Edge)>>: UnsafeUnpin,
*const LeafNode<NodeId, Adjacency> is !null: UnsafeUnpin,
PhantomData<Box<(NodeId, Adjacency)>>: UnsafeUnpin,
impl UnwindSafe for KnowledgeGraphwhere
BTreeMap<KindId, NodeKind>: UnwindSafe,
BTreeMap<NodeId, Node>: UnwindSafe,
BTreeMap<EdgeId, Edge>: UnwindSafe,
BTreeMap<NodeId, Adjacency>: UnwindSafe,
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