pub struct TemporalKnowledgeGraph { /* private fields */ }Expand description
A temporal knowledge graph that records how facts and relationships change.
All mutations are timestamped and appended to an internal timeline, enabling point-in-time queries and full history replay.
Implementations§
Source§impl TemporalKnowledgeGraph
impl TemporalKnowledgeGraph
Sourcepub fn add_node(&mut self, label: String, ts: u64) -> Result<NodeId, TkgError>
pub fn add_node(&mut self, label: String, ts: u64) -> Result<NodeId, TkgError>
Add a node with the given label at timestamp ts.
Returns the new NodeId on success.
Sourcepub fn delete_node(&mut self, id: NodeId, ts: u64) -> Result<(), TkgError>
pub fn delete_node(&mut self, id: NodeId, ts: u64) -> Result<(), TkgError>
Soft-delete node id at timestamp ts.
Sourcepub fn add_edge(
&mut self,
src: NodeId,
dst: NodeId,
relation: String,
weight: f64,
valid_from: u64,
) -> Result<EdgeId, TkgError>
pub fn add_edge( &mut self, src: NodeId, dst: NodeId, relation: String, weight: f64, valid_from: u64, ) -> Result<EdgeId, TkgError>
Add an edge from src to dst with the given relation, weight, and
start timestamp valid_from.
Both endpoint nodes must exist (not deleted) at valid_from.
Sourcepub fn delete_edge(&mut self, id: EdgeId, ts: u64) -> Result<(), TkgError>
pub fn delete_edge(&mut self, id: EdgeId, ts: u64) -> Result<(), TkgError>
Soft-delete edge id at timestamp ts.
Sourcepub fn set_property(
&mut self,
id: NodeId,
key: String,
value: String,
ts: u64,
) -> Result<(), TkgError>
pub fn set_property( &mut self, id: NodeId, key: String, value: String, ts: u64, ) -> Result<(), TkgError>
Set (or overwrite) a property on node id at timestamp ts.
Sourcepub fn query(&self, q: TkgQuery) -> TkgQueryResult
pub fn query(&self, q: TkgQuery) -> TkgQueryResult
Execute a TkgQuery and return a TkgQueryResult.
Sourcepub fn snapshot_at(&self, t: u64) -> TkgSnapshot
pub fn snapshot_at(&self, t: u64) -> TkgSnapshot
Return a point-in-time snapshot: all nodes and edges valid at t.
Sourcepub fn temporal_path(
&self,
src: NodeId,
dst: NodeId,
at_t: u64,
) -> Option<Vec<NodeId>>
pub fn temporal_path( &self, src: NodeId, dst: NodeId, at_t: u64, ) -> Option<Vec<NodeId>>
BFS to find a path from src to dst using only edges valid at at_t.
Returns None if no path exists or if either endpoint does not exist at at_t.
Sourcepub fn merge_graphs(&mut self, other: &Self, policy: TkgMergePolicy)
pub fn merge_graphs(&mut self, other: &Self, policy: TkgMergePolicy)
Merge other into self according to policy.
TkgMergePolicy::KeepMine— on ID collision keepself’s data.TkgMergePolicy::KeepOther— on ID collision keepother’s data.TkgMergePolicy::UnionAll— keep all data; on ID collision preferother.
Sourcepub fn stats(&self) -> TkgGraphStats
pub fn stats(&self) -> TkgGraphStats
Compute aggregate statistics for the graph.
Sourcepub fn get_node(&self, id: NodeId) -> Option<&TkgNode>
pub fn get_node(&self, id: NodeId) -> Option<&TkgNode>
Return a reference to the node with the given id, if it exists.
Sourcepub fn get_edge(&self, id: EdgeId) -> Option<&TkgEdge>
pub fn get_edge(&self, id: EdgeId) -> Option<&TkgEdge>
Return a reference to the edge with the given id, if it exists.
Sourcepub fn events_at(&self, ts: u64) -> &[TkgEvent]
pub fn events_at(&self, ts: u64) -> &[TkgEvent]
Return all events recorded at exactly timestamp ts.
Sourcepub fn timeline_iter(&self) -> impl Iterator<Item = (u64, &[TkgEvent])>
pub fn timeline_iter(&self) -> impl Iterator<Item = (u64, &[TkgEvent])>
Iterate over the timeline in chronological order.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes (including deleted).
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Number of edges (including expired).
Trait Implementations§
Source§impl Clone for TemporalKnowledgeGraph
impl Clone for TemporalKnowledgeGraph
Source§fn clone(&self) -> TemporalKnowledgeGraph
fn clone(&self) -> TemporalKnowledgeGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TemporalKnowledgeGraph
impl Debug for TemporalKnowledgeGraph
Auto Trait Implementations§
impl Freeze for TemporalKnowledgeGraph
impl RefUnwindSafe for TemporalKnowledgeGraph
impl Send for TemporalKnowledgeGraph
impl Sync for TemporalKnowledgeGraph
impl Unpin for TemporalKnowledgeGraph
impl UnsafeUnpin for TemporalKnowledgeGraph
impl UnwindSafe for TemporalKnowledgeGraph
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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