Text cleaning and normalization utilities.
Provides preprocessing functions to clean and normalize text before tokenization and vectorization.
Classes
Comprehensive text cleaning transformer.
Applies multiple cleaning operations in sequence.
Constructor
__init__( self, lowercase: bool = True, remove_punctuation: bool = False, remove_numbers: bool = False, remove_whitespace: bool = True, remove_html: bool = True, remove_urls: bool = True, remove_emails: bool = True, remove_special_chars: bool = False, strip_accents: bool = False, min_word_length: int = 1, )
Parameters
lowercase
bool
= True
Convert to lowercase.
remove_punctuation
bool
= False
Remove all punctuation.
remove_numbers
bool
= False
Remove all numbers.
remove_whitespace
bool
= True
Normalize whitespace (multiple spaces to single).
remove_html
bool
= True
Remove HTML tags.
remove_urls
bool
= True
Remove URLs.
remove_emails
bool
= True
Remove email addresses.
remove_special_chars
bool
= False
Remove special characters.
strip_accents
bool
= False
Remove accent marks from characters.
min_word_length
int
= 1
Remove words shorter than this.
python
>>> from tuiml.preprocessing.text import TextCleaner
>>>
>>> cleaner = TextCleaner(
... lowercase=True,
... remove_html=True,
... remove_urls=True
... )
>>> clean_text = cleaner.transform(["<p>Visit https://example.com!</p>"])
>>> print(clean_text[0]) # 'visit'
Methods
__repr__
(self) -> str
Remove stop words from text.
Constructor
__init__( self, stop_words: str | List[str] = 'english', case_sensitive: bool = False, )
Parameters
stop_words
list of str or 'english'
= 'english'
Stop words to remove.
case_sensitive
bool
= False
Whether matching is case-sensitive.
python
>>> from tuiml.preprocessing.text import StopWordRemover
>>> remover = StopWordRemover(stop_words='english')
>>> remover.transform(["the cat sat on the mat"])
['cat sat mat']
Apply stemming to reduce words to their root form.
Implements Porter Stemmer algorithm.
Constructor
__init__( self, lowercase: bool = True, )
Parameters
lowercase
bool
= True
Convert to lowercase before stemming.
python
>>> from tuiml.preprocessing.text import Stemmer
>>> stemmer = Stemmer()
>>> stemmer.transform(["running cats are playing"])
['run cat are play']
Normalize text with multiple operations.
Constructor
__init__( self, form: str = 'NFKC', lowercase: bool = True, strip: bool = True, collapse_whitespace: bool = True, )
Parameters
form
str
= 'NFKC'
Unicode normalization form ('NFC', 'NFD', 'NFKC', 'NFKD').
lowercase
bool
= True
Convert to lowercase.
strip
bool
= True
Strip leading/trailing whitespace.
collapse_whitespace
bool
= True
Replace multiple whitespace with single space.
python
>>> from tuiml.preprocessing.text import TextNormalizer
>>> normalizer = TextNormalizer()
>>> normalizer.transform([" Hello World "])
['hello world']