yotext
Orthographic normalization and diacritic handling for Yorùbá text. Zero runtime dependencies. Requires Python 3.9 or newer.
Why this exists
Yorùbá text in circulation is encoded inconsistently. The underdot that marks ẹ, ọ, and ṣ shows up as U+0323, U+0329, U+0331, or U+032D depending on the keyboard and the era it was typed on. Combining marks often arrive out of canonical order too. The same word ends up as several different byte sequences that look identical on screen and compare unequal in code. standardize() folds all of that into one canonical form.
Tone marks and underdots are different things
This is the part that matters most. The underdot in ẹ, ọ, and ṣ is segmental. ẹ and e are separate phonemes, and removing the underdot turns one word into a different word. Tone marks, the acute in á and the grave in à, are suprasegmental. They mark pitch on top of a vowel, and they do not change which phoneme the vowel is.
Most text preprocessing code lumps both of these under the single label "diacritics" and strips them together. That conflates two different linguistic categories, and it produces wrong output for any task that depends on the ẹ/e or ọ/o distinction.
strip_tones() removes tone marks and keeps the underdot. strip_diacritics() removes both. I kept both functions because they answer different questions, and code that only offers one of them is answering the wrong question at least some of the time.
Install
pip install yotext
Usage
from yotext import standardize, strip_tones, strip_diacritics, tone_pattern
# Messy input: wrong underdot codepoint (U+0329 instead of U+0323)
# and a tone mark placed before the underdot instead of after.
messy = "e\u0300\u0329ko\u0301\u0331"
standardize(messy)
# 'ẹ̀kọ́'
strip_tones("ẹ̀kọ́")
# 'ẹkọ' tone dropped, underdot kept, ẹ and e stay different words
strip_diacritics("ẹ̀kọ́")
# 'eko' fully undiacritized, the baseline used in ablation experiments
tone_pattern("bàbá")
# 'LH' useful for checking tone distribution across a corpus
Two strings can look identical and still compare unequal, if one uses a precomposed vowel and the other uses a decomposed one with a non-canonical underdot codepoint.
s1 = "\u1eb9" # precomposed ẹ
s2 = "e\u0329" # decomposed, non-canonical underdot
s1 == s2 # False
standardize(s1) == standardize(s2) # True
Running standardize() on a corpus before deduplicating or indexing it collapses these variants so equal words compare equal.
What it guarantees
standardize() is idempotent. Running it twice gives the same result as running it once.
strip_diacritics(s) equals strip_diacritics(strip_tones(s)) for any input. Removing tone first and then removing what remains lands on the same undiacritized form as removing everything at once.
Combining marks always come out in canonical order, combining class 220 before combining class 230.
What it does not do
Version 0.1 does normalization only. It does not restore diacritics. Predicting bẹ̀rẹ̀ from bere, meaning guessing which vowels carry an underdot or a tone mark from plain ASCII input, is not implemented. That is planned for a later release.
License
MIT.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yotext-0.1.0.tar.gz.
File metadata
- Download URL: yotext-0.1.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3428cc51c638a40eea9fe72a1232690c73ecb55de54ce04255b5f19eaa7d1428
|
|
| MD5 |
82cc563f30bb0504cb41d73def903aa2
|
|
| BLAKE2b-256 |
9098764e3cec91ed76b9e4875876b4be8752f6dc475e759d7541707417c981b3
|
File details
Details for the file yotext-0.1.0-py3-none-any.whl.
File metadata
- Download URL: yotext-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f72ec172acabde55e23669722035d6be386c5a34cec7ee5eaee0def60a4ac5f
|
|
| MD5 |
8fbf0e8ae83a3ef65f611d7130d55cd5
|
|
| BLAKE2b-256 |
2551283e640de1e7cad7e31c5494bdfc0b127a23149fb127d8f3166a4d7c4b58
|