pub struct EntityResolver { /* private fields */ }Expand description
Disambiguates and resolves entity mentions to canonical entities.
Resolution priority (highest to lowest):
- Exact match on normalized canonical name.
- Alias match on any normalized alias.
- Fuzzy (edit-distance) match if similarity ≥
fuzzy_threshold. - Embedding cosine similarity match if score ≥
embedding_threshold. - Unresolved.
Implementations§
Source§impl EntityResolver
impl EntityResolver
Sourcepub fn new(config: ResolverConfig) -> Self
pub fn new(config: ResolverConfig) -> Self
Create a new resolver with the given configuration.
Sourcepub fn register_entity(&mut self, entity: CanonicalEntity) -> bool
pub fn register_entity(&mut self, entity: CanonicalEntity) -> bool
Register a canonical entity. Returns true if the entity was inserted,
false if an entity with the same entity_id already exists (no update).
Sourcepub fn resolve(&mut self, mention: EntityMention) -> ResolutionResult
pub fn resolve(&mut self, mention: EntityMention) -> ResolutionResult
Resolve a single mention to a canonical entity.
Sourcepub fn resolve_with_embedding(
&mut self,
mention: EntityMention,
query_embedding: &[f64],
) -> ResolutionResult
pub fn resolve_with_embedding( &mut self, mention: EntityMention, query_embedding: &[f64], ) -> ResolutionResult
Resolve a mention when the caller also supplies a query embedding.
Falls through the same priority chain as resolve but adds an
embedding-cosine step before returning Unresolved.
Sourcepub fn resolve_batch(
&mut self,
mentions: Vec<EntityMention>,
) -> Vec<ResolutionResult>
pub fn resolve_batch( &mut self, mentions: Vec<EntityMention>, ) -> Vec<ResolutionResult>
Resolve a batch of mentions, returning one ResolutionResult per mention.
Sourcepub fn normalize(text: &str) -> String
pub fn normalize(text: &str) -> String
Normalize a string: trim, lowercase, collapse interior whitespace runs.
Sourcepub fn edit_distance(a: &str, b: &str) -> usize
pub fn edit_distance(a: &str, b: &str) -> usize
Classic Levenshtein edit distance between two strings.
Sourcepub fn string_similarity(a: &str, b: &str) -> f64
pub fn string_similarity(a: &str, b: &str) -> f64
String similarity in [0.0, 1.0]: 1.0 - edit_distance / max_len.
Returns 1.0 if both strings are empty.
Sourcepub fn cosine_similarity(a: &[f64], b: &[f64]) -> f64
pub fn cosine_similarity(a: &[f64], b: &[f64]) -> f64
Cosine similarity between two vectors; returns 0.0 for zero-norm inputs.
Sourcepub fn find_candidates<'a>(
&'a self,
mention: &str,
n: usize,
) -> Vec<&'a CanonicalEntity>
pub fn find_candidates<'a>( &'a self, mention: &str, n: usize, ) -> Vec<&'a CanonicalEntity>
Return up to n candidate entities ranked by string similarity to mention.
This is an O(|entities|) scan. For very large registries a dedicated inverted-index or BK-tree would be more efficient, but correctness is the priority here.
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Number of registered canonical entities.
Sourcepub fn get_entity(&self, entity_id: &str) -> Option<&CanonicalEntity>
pub fn get_entity(&self, entity_id: &str) -> Option<&CanonicalEntity>
Look up a canonical entity by its stable ID.
Sourcepub fn stats(&self) -> &ResolverStats
pub fn stats(&self) -> &ResolverStats
Current resolution statistics.
Auto Trait Implementations§
impl Freeze for EntityResolver
impl RefUnwindSafe for EntityResolver
impl Send for EntityResolver
impl Sync for EntityResolver
impl Unpin for EntityResolver
impl UnsafeUnpin for EntityResolver
impl UnwindSafe for EntityResolver
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.