Canonicalizing Text Labels
A canonicalization rule maps equivalent labels to one representation so records can be compared and grouped consistently.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 2 min
In this article4 chapters
Choose the equivalence
A tag editor may decide that leading whitespace and capitalization carry no meaning. The display label " History" can map to a comparison key "history". Preserve the display form if people expect capitalization to be visible. Parsing and formatting separates these two purposes.
Avoid accidental collisions
Case folding can cause two input labels to share a key. Plan how insertion, merging, and lookup behave when that happens. An identifier whose punctuation or case is significant needs a different rule. Typed input records can preserve an exact identifier beside a normalized search field.[1][2]
Trace matching and display separately
A tag editor can preserve the user-facing spelling “Data Science” while indexing it under a normalized comparison key. A proposed spelling with leading spaces and a different case can resolve to the same key. First choose which differences should count as equivalent. Then use the same transformation before storage and before lookup. The visible label keeps its original spelling according to the display policy. Unicode normalization addresses canonically equivalent sequences that can look the same.
Define what happens when several labels have one key
When two inputs normalize to the same key, a map can reject the second, update a known label, or associate several originals with one search concept. The choice depends on whether the key means unique identity or retrieval by a flexible spelling. Make that decision before writing insertion tests. See stable record identifiers for keeping identity separate from mutable labels.
Test a variation that should match and two similar identifiers that should remain distinct. For a source with punctuation significant to the domain, a broad cleanup can unexpectedly merge valid values. Keep an independently expected match count in the fixture.