pub struct ConceptExtractor { /* private fields */ }Expand description
Extracts concepts and keywords from text using TF-IDF and frequency analysis.
The extractor maintains corpus-level document-frequency statistics so that IDF weights improve as more documents are processed.
§Example
use ipfrs_semantic::concept_extractor::{ConceptExtractor, ExtractorConfig};
let config = ExtractorConfig::default();
let mut extractor = ConceptExtractor::new(config);
let concepts = extractor.extract("The quick brown fox jumps over the lazy dog.");
for c in &concepts {
println!("{:?}: score={:.4}", c.term, c.score);
}Implementations§
Source§impl ConceptExtractor
impl ConceptExtractor
Sourcepub fn new(config: ExtractorConfig) -> Self
pub fn new(config: ExtractorConfig) -> Self
Creates a new extractor with the given configuration.
Sourcepub fn extract(&mut self, text: &str) -> Vec<Concept>
pub fn extract(&mut self, text: &str) -> Vec<Concept>
Extracts and returns the top concepts from text, updating internal
corpus statistics so subsequent calls benefit from improved IDF weights.
Sourcepub fn tokenize(text: &str) -> Vec<String>
pub fn tokenize(text: &str) -> Vec<String>
Tokenizes text into lower-cased tokens, splitting on whitespace and
ASCII punctuation, dropping tokens shorter than min_term_length.
This is the public lower-cased variant used for TF/IDF computation.
Sourcepub fn compute_tf(tokens: &[String]) -> HashMap<String, u32>
pub fn compute_tf(tokens: &[String]) -> HashMap<String, u32>
Computes term frequency (raw count) for each token in tokens.
Sourcepub fn compute_tfidf(&self, term: &str, tf: u32, doc_len: usize) -> f64
pub fn compute_tfidf(&self, term: &str, tf: u32, doc_len: usize) -> f64
Returns the TF-IDF score for a term given its raw frequency tf and
the document length doc_len.
Uses augmented TF (0.5 + 0.5 × tf / max_tf) to prevent bias towards long documents, combined with smoothed IDF.
Sourcepub fn extract_ngrams(tokens: &[String], n: usize) -> Vec<String>
pub fn extract_ngrams(tokens: &[String], n: usize) -> Vec<String>
Extracts all n-grams of size n from tokens, joining tokens with a
single space to form the phrase string.
Sourcepub fn detect_concept_type(term: &str) -> ConceptType
pub fn detect_concept_type(term: &str) -> ConceptType
Classifies a term into its ConceptType.
- Entity — starts with an ASCII upper-case letter or every ASCII letter in the term is upper-case (acronym).
- Technical — contains
_(snake_case) or an interior upper-case letter (camelCase). - Phrase — contains a space (multi-word).
- Keyword — everything else.
Sourcepub fn is_stop_word(&self, word: &str) -> bool
pub fn is_stop_word(&self, word: &str) -> bool
Returns true if word appears in the configured stop-word list
(case-insensitive comparison).
Sourcepub fn update_corpus(&mut self, tokens: &[String])
pub fn update_corpus(&mut self, tokens: &[String])
Updates corpus document-frequency statistics for the unique terms found
in tokens. Each unique term in the token slice counts as appearing
in one additional document.
Sourcepub fn top_concepts(concepts: &mut Vec<Concept>, n: usize) -> Vec<Concept>
pub fn top_concepts(concepts: &mut Vec<Concept>, n: usize) -> Vec<Concept>
Returns the top n concepts from concepts sorted by descending score.
Deduplicates by term (keeps the highest-scoring entry).
Sourcepub fn stats(&self) -> &ExtractorStats
pub fn stats(&self) -> &ExtractorStats
Returns a reference to the cumulative extraction statistics.
Auto Trait Implementations§
impl Freeze for ConceptExtractor
impl RefUnwindSafe for ConceptExtractor
impl Send for ConceptExtractor
impl Sync for ConceptExtractor
impl Unpin for ConceptExtractor
impl UnsafeUnpin for ConceptExtractor
impl UnwindSafe for ConceptExtractor
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.