pub struct SemanticEntityLinker {
pub entities: HashMap<u64, KbEntity>,
pub name_index: HashMap<String, u64>,
pub alias_index: HashMap<String, u64>,
pub config: LinkerConfig,
pub stats: LinkerStats,
}Expand description
A linker that resolves mention texts to canonical knowledge-base entities.
Resolution is attempted in priority order:
- Exact name match (lowercase comparison against canonical names)
- Alias match (lowercase comparison against known aliases)
- Embedding similarity (cosine similarity above configured threshold)
Fields§
§entities: HashMap<u64, KbEntity>All registered entities, keyed by entity_id.
name_index: HashMap<String, u64>Lowercase canonical name → entity_id.
alias_index: HashMap<String, u64>Lowercase alias → entity_id.
config: LinkerConfigConfiguration parameters.
stats: LinkerStatsRunning statistics.
Implementations§
Source§impl SemanticEntityLinker
impl SemanticEntityLinker
Sourcepub fn new(config: LinkerConfig) -> Self
pub fn new(config: LinkerConfig) -> Self
Create a new, empty linker with the given configuration.
Sourcepub fn register(&mut self, entity: KbEntity)
pub fn register(&mut self, entity: KbEntity)
Register an entity in the knowledge base.
Indexes the entity’s canonical name and all aliases (lowercased).
If an entity with the same entity_id was already registered, it is replaced.
Sourcepub fn link(
&mut self,
mention_text: &str,
mention_embedding: Option<&[f32]>,
) -> Option<LinkedMention>
pub fn link( &mut self, mention_text: &str, mention_embedding: Option<&[f32]>, ) -> Option<LinkedMention>
Attempt to link a single mention text to an entity.
Resolution priority:
- ExactMatch — lowercase mention in
name_index - Alias — lowercase mention in
alias_index - EmbeddingMatch — highest cosine similarity ≥
embedding_threshold
Returns None and increments unlinked_count if no match is found.
Sourcepub fn link_batch(
&mut self,
mentions: Vec<(String, Option<Vec<f32>>)>,
) -> Vec<Option<LinkedMention>>
pub fn link_batch( &mut self, mentions: Vec<(String, Option<Vec<f32>>)>, ) -> Vec<Option<LinkedMention>>
Link a batch of mentions, each paired with an optional embedding.
Returns one Option<LinkedMention> per input mention, in the same order.
Sourcepub fn entity(&self, entity_id: u64) -> Option<&KbEntity>
pub fn entity(&self, entity_id: u64) -> Option<&KbEntity>
Look up a registered entity by its entity_id.
Sourcepub fn stats(&self) -> &LinkerStats
pub fn stats(&self) -> &LinkerStats
Return a reference to the current linker statistics.
Auto Trait Implementations§
impl Freeze for SemanticEntityLinker
impl RefUnwindSafe for SemanticEntityLinker
impl Send for SemanticEntityLinker
impl Sync for SemanticEntityLinker
impl Unpin for SemanticEntityLinker
impl UnsafeUnpin for SemanticEntityLinker
impl UnwindSafe for SemanticEntityLinker
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.