pub struct KnowledgeGraph { /* private fields */ }Expand description
A simple in-memory knowledge graph for context extraction.
Stores triples and supports N-hop traversal.
Implementations§
Source§impl KnowledgeGraph
impl KnowledgeGraph
Sourcepub fn from_triples(triples: &[ContextTriple]) -> Self
pub fn from_triples(triples: &[ContextTriple]) -> Self
Build a knowledge graph from a slice of triples.
Sourcepub fn add_triple(&mut self, triple: ContextTriple)
pub fn add_triple(&mut self, triple: ContextTriple)
Add a single triple.
Sourcepub fn neighbors(&self, entity: &str) -> Vec<&ContextTriple>
pub fn neighbors(&self, entity: &str) -> Vec<&ContextTriple>
Get all triples where entity appears as subject or object.
Sourcepub fn triples_by_predicate(&self, predicate: &str) -> Vec<&ContextTriple>
pub fn triples_by_predicate(&self, predicate: &str) -> Vec<&ContextTriple>
Get all triples with a specific predicate.
Sourcepub fn all_triples(&self) -> &[ContextTriple]
pub fn all_triples(&self) -> &[ContextTriple]
Get all triples.
Trait Implementations§
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
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>
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 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>
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