Skip to main content

KnowledgeGraph

Struct KnowledgeGraph 

Source
pub struct KnowledgeGraph {
    pub directed: bool,
    /* private fields */
}
Expand description

知识图谱。有向 / 无向在图级别声明(布局与邻接口径一致)。

Fields§

§directed: bool

是否有向;无向图的邻接查询双向对称。

Implementations§

Source§

impl KnowledgeGraph

Source

pub fn new() -> Self

Source

pub fn directed(self) -> Self

有向图构造器(导入与测试用)。

Source

pub fn alloc_node_id(&mut self) -> NodeId

分配并占用一个新节点 ID(导入预扫用,避免逐条 add 的开销)。

Source

pub fn alloc_edge_id(&mut self) -> EdgeId

Source

pub fn alloc_kind_id(&mut self) -> KindId

Source

pub fn add_kind(&mut self, name: impl Into<String>) -> KindId

Source

pub fn upsert_kind(&mut self, id: KindId, name: impl Into<String>)

插入指定 ID 的类型;已存在时只更新名称(CSV 按名引用的场景)。

Source

pub fn kind(&self, id: KindId) -> Option<&NodeKind>

Source

pub fn kinds(&self) -> impl Iterator<Item = &NodeKind>

类型列表,按 ID 有序(保证遍历与序列化可复现)。

Source

pub fn add_node( &mut self, label: impl Into<String>, kind: Option<KindId>, ) -> NodeId

Source

pub fn insert_node(&mut self, node: Node) -> Result<(), GraphError>

插入完整节点(导入路径)。ID 已存在返回错误且不产生半写入。

Source

pub fn update_node(&mut self, node: Node) -> Result<(), GraphError>

直接更新节点(保留原位置语义在布局层,这里只是存储替换)。

Source

pub fn node(&self, id: NodeId) -> Option<&Node>

Source

pub fn remove_node(&mut self, id: NodeId) -> Result<(), GraphError>

删除节点,级联删除全部关联边。

Source

pub fn add_edge( &mut self, source: NodeId, target: NodeId, weight: f32, label: Option<String>, ) -> Result<EdgeId, GraphError>

Source

pub fn edge(&self, id: EdgeId) -> Option<&Edge>

Source

pub fn remove_edge(&mut self, id: EdgeId) -> Result<(), GraphError>

Source

pub fn node_count(&self) -> usize

Source

pub fn edge_count(&self) -> usize

Source

pub fn nodes(&self) -> impl Iterator<Item = &Node>

Source

pub fn edges(&self) -> impl Iterator<Item = &Edge>

Source

pub fn adjacency(&self) -> &AdjacencyIndex

邻接索引(一度邻居 / 入射边 / 度数)。

Source

pub fn to_json(&self) -> String

导出为 JSON 文档字符串。

Source

pub fn from_json(json: &str) -> Result<Self, GraphError>

从 JSON 文档导入。坏 JSON 返回 GraphError::Format,不 panic。

Trait Implementations§

Source§

impl Clone for KnowledgeGraph

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KnowledgeGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for KnowledgeGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Forget for KnowledgeGraph

§

impl Freeze for KnowledgeGraph
where *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 KnowledgeGraph
where 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 KnowledgeGraph
where 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 KnowledgeGraph
where *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 KnowledgeGraph
where *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 KnowledgeGraph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.