pub struct KnowledgeCache {
pub entities: Vec<Entity>,
pub relations: Vec<Relation>,
pub alias_strings: Vec<String>,
pub alias_entity_ids: Vec<i64>,
/* private fields */
}Expand description
In-memory cache for the /knowledge_graph group.
Fields§
§entities: Vec<Entity>§relations: Vec<Relation>§alias_strings: Vec<String>§alias_entity_ids: Vec<i64>Implementations§
Source§impl KnowledgeCache
impl KnowledgeCache
pub fn new() -> Self
pub fn new_with_next_id(next_id: u64) -> Self
Sourcepub fn add_entity(
&mut self,
name: &str,
entity_type: &str,
embedding_idx: i64,
) -> u64
pub fn add_entity( &mut self, name: &str, entity_type: &str, embedding_idx: i64, ) -> u64
Add an entity, returns its assigned ID.
Sourcepub fn add_relation(&mut self, src: u64, tgt: u64, relation: &str, weight: f32)
pub fn add_relation(&mut self, src: u64, tgt: u64, relation: &str, weight: f32)
Add a relation between two entities.
Sourcepub fn get_entity(&self, id: u64) -> Option<&Entity>
pub fn get_entity(&self, id: u64) -> Option<&Entity>
Find an entity by ID.
Sourcepub fn get_relations_from(&self, src_id: u64) -> Vec<&Relation>
pub fn get_relations_from(&self, src_id: u64) -> Vec<&Relation>
Find all relations where the given entity is the source.
Sourcepub fn get_relations_to(&self, tgt_id: u64) -> Vec<&Relation>
pub fn get_relations_to(&self, tgt_id: u64) -> Vec<&Relation>
Find all relations where the given entity is the target.
Sourcepub fn add_alias(&mut self, alias: &str, entity_id: i64)
pub fn add_alias(&mut self, alias: &str, entity_id: i64)
Register an alias for an entity. Case-insensitive storage.
Sourcepub fn get_aliases(&self, entity_id: i64) -> Vec<&str>
pub fn get_aliases(&self, entity_id: i64) -> Vec<&str>
Get all aliases for a given entity.
Sourcepub fn get_entity_name(&self, entity_id: i64) -> Option<&str>
pub fn get_entity_name(&self, entity_id: i64) -> Option<&str>
Get entity name by ID.
Sourcepub fn resolve_aliases(&self, query: &str) -> String
pub fn resolve_aliases(&self, query: &str) -> String
Resolve aliases in free text — greedy longest-match replacement.
Trait Implementations§
Source§impl Clone for KnowledgeCache
impl Clone for KnowledgeCache
Source§fn clone(&self) -> KnowledgeCache
fn clone(&self) -> KnowledgeCache
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for KnowledgeCache
impl Debug for KnowledgeCache
Auto Trait Implementations§
impl Freeze for KnowledgeCache
impl RefUnwindSafe for KnowledgeCache
impl Send for KnowledgeCache
impl Sync for KnowledgeCache
impl Unpin for KnowledgeCache
impl UnsafeUnpin for KnowledgeCache
impl UnwindSafe for KnowledgeCache
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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