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() -> KnowledgeGraph

Source

pub fn directed(self) -> KnowledgeGraph

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

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<KnowledgeGraph, GraphError>

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

Trait Implementations§

Source§

impl Clone for KnowledgeGraph

Source§

fn clone(&self) -> KnowledgeGraph

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<(), Error>

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

impl Default for KnowledgeGraph

Source§

fn default() -> KnowledgeGraph

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

The type of the none-equivalent value that NoneValue::null_value produces.
Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more