Text Normalization › Key Functions and Parameters
Language AI HandbookAll chapters Text Normalization › Key Functions and ParametersOne section · Sections in this chapter13 / 15 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
When working with text normalization in Python, these are the essential functions and their most important parameters:
-
unicodedata.normalize(form, text): Applies Unicode normalization to a string. Theformparameter specifies the normalization form:'NFC'(canonical composition, default for storage),'NFD'(canonical decomposition, useful for accent stripping),'NFKC'(compatibility composition, aggressive, for search), or'NFKD'(compatibility decomposition). -
unicodedata.category(char): Returns a two-letter category code for a Unicode character. Common categories include'Mn'(Mark, Nonspacing, for combining diacritics),'Cc'(control characters), and'Zs'(space separator). Useful for filtering specific character types during normalization. -
str.casefold(): Returns a casefolded copy of the string for case-insensitive comparison. More aggressive thanlower(), handles special cases like German "ß" to "ss". Preferred overlower()for Unicode-aware case-insensitive matching. -
str.lower()vsstr.casefold(): Uselower()for display (standard Unicode lowercasing) andcasefold()for comparison (full Unicode case folding that handles language-specific mappings). -
re.sub(pattern, replacement, text): Essential for whitespace normalization. Common patterns includer'[\u00A0\u2000-\u200A\u202F\u205F\u3000]'for various Unicode spaces,r'[\u200B-\u200D\uFEFF]'for zero-width characters, andr' +'for multiple consecutive spaces.