pub struct MultilingualNormalizer {
pub options: NormalizationOptions,
pub tokenization: TokenizationStrategy,
/* private fields */
}Expand description
Production-grade multilingual text normalizer.
MultilingualNormalizer executes a configurable normalization pipeline on
arbitrary Unicode text and tokenizes the result according to the chosen
TokenizationStrategy. It is internally thread-safe via atomic counters
wrapped in an Arc, so a single instance may be shared across threads.
§Example
use ipfrs_semantic::multilingual_normalizer::{
MultilingualNormalizer, NormalizationOptions, TokenizationStrategy,
};
let opts = NormalizationOptions { lowercase: true, ..Default::default() };
let norm = MultilingualNormalizer::new(opts, TokenizationStrategy::Whitespace);
let result = norm.normalize("Hello World");
assert_eq!(result.normalized, "hello world");
assert_eq!(result.token_count, 2);Fields§
§options: NormalizationOptionsActive normalization options.
tokenization: TokenizationStrategyActive tokenization strategy.
Implementations§
Source§impl MultilingualNormalizer
impl MultilingualNormalizer
Sourcepub fn new(
options: NormalizationOptions,
tokenization: TokenizationStrategy,
) -> Self
pub fn new( options: NormalizationOptions, tokenization: TokenizationStrategy, ) -> Self
Create a new normalizer with the given options and tokenization strategy.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a normalizer with default options and Whitespace tokenization.
Sourcepub fn normalize(&self, text: &str) -> NormalizedText
pub fn normalize(&self, text: &str) -> NormalizedText
Normalize a single text string and tokenize it.
The pipeline is:
- Detect dominant script.
- Derive a language hint from the script.
- Apply all enabled normalization options in order.
- Tokenize according to the configured strategy.
- Update internal statistics.
Sourcepub fn normalize_batch(&self, texts: &[&str]) -> Vec<NormalizedText>
pub fn normalize_batch(&self, texts: &[&str]) -> Vec<NormalizedText>
Normalize a batch of text strings.
Sourcepub fn detect_script(&self, text: &str) -> Script
pub fn detect_script(&self, text: &str) -> Script
Detect the dominant script in text by counting characters per script.
Returns Script::Unknown when the text is empty or when two scripts
tie for the highest count.
Sourcepub fn detect_language(&self, text: &str) -> LanguageHint
pub fn detect_language(&self, text: &str) -> LanguageHint
Derive a language hint from the dominant script in text.
Sourcepub fn apply_options(&self, text: &str) -> String
pub fn apply_options(&self, text: &str) -> String
Apply all enabled normalization options to text and return the result.
Options are applied in this fixed order:
lowercasestrip_accentsnormalize_whitespaceremove_punctuationmax_lengthscript_filter
Sourcepub fn tokenize(&self, text: &str) -> Vec<String>
pub fn tokenize(&self, text: &str) -> Vec<String>
Tokenize text according to the configured TokenizationStrategy.
Sourcepub fn strip_combining_chars(&self, text: &str) -> String
pub fn strip_combining_chars(&self, text: &str) -> String
Remove Unicode combining diacritical marks (U+0300-U+036F) from text.
Sourcepub fn stats(&self) -> NormalizerStats
pub fn stats(&self) -> NormalizerStats
Return a point-in-time snapshot of accumulated statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MultilingualNormalizer
impl RefUnwindSafe for MultilingualNormalizer
impl Send for MultilingualNormalizer
impl Sync for MultilingualNormalizer
impl Unpin for MultilingualNormalizer
impl UnsafeUnpin for MultilingualNormalizer
impl UnwindSafe for MultilingualNormalizer
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.