starfuzz/normalize
A module providing text normalization capabilities. Normalization is typically the first step before calculating text similarities, ensuring formatting differences (casing, spaces, punctuation) do not distort scores.
Types
An immutable normalizer configuration.
pub type Normalizer {
Normalizer(
lowercase: Bool,
trim: Bool,
collapse_whitespace: Bool,
remove_punctuation: Bool,
replace_punctuation_with_space: Bool,
)
}
Constructors
-
Normalizer( lowercase: Bool, trim: Bool, collapse_whitespace: Bool, remove_punctuation: Bool, replace_punctuation_with_space: Bool, )
Values
pub fn apply(normalizer: Normalizer, input: String) -> String
Applies the normalizer pipeline to the input string.
pub fn basic(input: String) -> String
A preset performing lowercase mapping, trimming, punctuation stripping, and collapsing spaces.
pub fn search_text(input: String) -> String
A preset performing lowercase mapping, trimming, replacing punctuation with spaces, and collapsing spaces.
pub fn with_collapsed_whitespace(
normalizer: Normalizer,
) -> Normalizer
Configures the normalizer to collapse multiple consecutive whitespaces into a single space.
pub fn with_lowercase(normalizer: Normalizer) -> Normalizer
Configures the normalizer to convert all text to lowercase.
pub fn with_punctuation_as_space(
normalizer: Normalizer,
) -> Normalizer
Configures the normalizer to replace punctuation marks with spaces.
pub fn with_trim(normalizer: Normalizer) -> Normalizer
Configures the normalizer to trim leading and trailing whitespaces.
pub fn without_punctuation(normalizer: Normalizer) -> Normalizer
Configures the normalizer to strip all punctuation marks from the text.