pub struct EntityLinker {
pub min_mention_len: usize,
pub threshold: f64,
/* private fields */
}Expand description
String-to-entity linker backed by an in-memory knowledge base.
Fields§
§min_mention_len: usizeMinimum character length of a text span to be considered as a mention.
threshold: f64Minimum combined score for a candidate to be returned.
Implementations§
Source§impl EntityLinker
impl EntityLinker
Sourcepub fn new(threshold: f64) -> Self
pub fn new(threshold: f64) -> Self
Create an empty linker with the given minimum combined score threshold.
Sourcepub fn add_entity(&mut self, entity: Entity)
pub fn add_entity(&mut self, entity: Entity)
Add a single entity to the knowledge base and update the index.
Sourcepub fn add_entities(&mut self, entities: Vec<Entity>)
pub fn add_entities(&mut self, entities: Vec<Entity>)
Add multiple entities in bulk and rebuild the index.
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Total number of entities in the knowledge base.
Sourcepub fn detect_mentions(&self, text: &str) -> Vec<EntityMention>
pub fn detect_mentions(&self, text: &str) -> Vec<EntityMention>
Scan text for all known entity labels / aliases and return mentions.
Both exact (case-insensitive) and fuzzy (similarity ≥ 0.7) matches are considered. Overlapping spans from the same starting position are de-duplicated in favour of the longer match.
Sourcepub fn link(&self, text: &str) -> Result<Vec<LinkedEntity>, LinkerError>
pub fn link(&self, text: &str) -> Result<Vec<LinkedEntity>, LinkerError>
Link all mentions found in text to their best entity candidates.
§Errors
LinkerError::EmptyTextiftextis empty after trimming.LinkerError::EmptyKnowledgeBaseif no entities have been added.
Sourcepub fn link_mention(&self, mention: &str) -> Vec<LinkCandidate>
pub fn link_mention(&self, mention: &str) -> Vec<LinkCandidate>
Find all entity candidates for an arbitrary mention string.
Searches all entity labels and aliases using both exact (lowercase) and
fuzzy matching. Results are sorted by score descending.
Sourcepub fn find_by_iri(&self, iri: &str) -> Option<&Entity>
pub fn find_by_iri(&self, iri: &str) -> Option<&Entity>
Look up an entity by its exact IRI.
Sourcepub fn string_similarity(a: &str, b: &str) -> f64
pub fn string_similarity(a: &str, b: &str) -> f64
Normalised edit-distance similarity: 1 − edit_distance(a, b) / max(|a|, |b|).
Returns 1.0 for identical strings and 0.0 when the edit distance equals the length of the longer string.
Auto Trait Implementations§
impl Freeze for EntityLinker
impl RefUnwindSafe for EntityLinker
impl Send for EntityLinker
impl Sync for EntityLinker
impl Unpin for EntityLinker
impl UnsafeUnpin for EntityLinker
impl UnwindSafe for EntityLinker
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
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