pub struct SemanticTermWeighter { /* private fields */ }Expand description
TF-IDF / BM25 term weighter for a corpus of documents.
Maintains document profiles and document-frequency counts so that term weights can be computed incrementally as documents are added or removed.
Implementations§
Source§impl SemanticTermWeighter
impl SemanticTermWeighter
Sourcepub fn new(config: WeighterConfig) -> Self
pub fn new(config: WeighterConfig) -> Self
Create a new weighter with the given configuration.
Sourcepub fn add_document(&mut self, doc_id: &str, terms: &[&str])
pub fn add_document(&mut self, doc_id: &str, terms: &[&str])
Register a document by its id and a slice of terms.
Counts each term occurrence and updates corpus-level statistics (document frequencies, average document length).
If a document with the same doc_id already exists it is replaced.
Sourcepub fn remove_document(&mut self, doc_id: &str) -> bool
pub fn remove_document(&mut self, doc_id: &str) -> bool
Remove a document from the corpus. Returns true if it existed.
Sourcepub fn weight_terms(&self, doc_id: &str) -> Result<Vec<TermWeight>, String>
pub fn weight_terms(&self, doc_id: &str) -> Result<Vec<TermWeight>, String>
Compute weights for every term in the specified document.
Sourcepub fn tf(&self, term: &str, doc_id: &str) -> Option<f64>
pub fn tf(&self, term: &str, doc_id: &str) -> Option<f64>
Raw term frequency: count / total_terms.
Sourcepub fn bm25_score(&self, term: &str, doc_id: &str) -> Option<f64>
pub fn bm25_score(&self, term: &str, doc_id: &str) -> Option<f64>
BM25 score for a single term in a document.
Sourcepub fn similarity(&self, doc_a: &str, doc_b: &str) -> Result<f64, String>
pub fn similarity(&self, doc_a: &str, doc_b: &str) -> Result<f64, String>
Cosine similarity between the TF-IDF vectors of two documents.
Sourcepub fn vocab_size(&self) -> usize
pub fn vocab_size(&self) -> usize
Number of unique terms across all documents.
Sourcepub fn stats(&self) -> TermWeighterStats
pub fn stats(&self) -> TermWeighterStats
Aggregate statistics snapshot.
Auto Trait Implementations§
impl Freeze for SemanticTermWeighter
impl RefUnwindSafe for SemanticTermWeighter
impl Send for SemanticTermWeighter
impl Sync for SemanticTermWeighter
impl Unpin for SemanticTermWeighter
impl UnsafeUnpin for SemanticTermWeighter
impl UnwindSafe for SemanticTermWeighter
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.