pythainlp.transliterate.transliterate() sometimes throws a KeyError when the input contains the character ฅ. The stacktrace points to ReplaceSnd in nlp.py.
In the following output, the word ภาษาไวคาลีฅ is taken from the list of processed Wikipedia article titles in this repo.
>>> transliterate("ภาษาไวคาลีฅ", engine="tltk_g2p")
Traceback (most recent call last):
File "<python-input-7>", line 1, in <module>
transliterate("ภาษาไวคาลีฅ", engine="tltk_g2p")
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/<SNIP>/venv/lib/python3.13/site-packages/pythainlp/transliterate/core.py", line 185, in transliterate
return transliterate(text)
File "/<SNIP>/venv/lib/python3.13/site-packages/pythainlp/transliterate/tltk.py", line 24, in tltk_g2p
_temp = g2p(text).split("<tr/>")[1].replace("|<s/>", "").replace("|", " ")
~~~^^^^^^
File "/<SNIP>/venv/lib/python3.13/site-packages/tltk/nlp.py", line 1690, in g2p
y = sylparse(inp)
File "/<SNIP>/venv/lib/python3.13/site-packages/tltk/nlp.py", line 1767, in sylparse
phone = ReplaceSnd(PronF,codematch,charmatch)
File "/<SNIP>/venv/lib/python3.13/site-packages/tltk/nlp.py", line 1929, in ReplaceSnd
s = stable[x][tmp1Lst[i]]
~~~~~~~~~^^^^^^^^^^^^
KeyError: 'ฅ'
For now, this can be solved easily with this basic replacement: text.replace("ฅ", "ค"), which will not affect the transliteration.
pythainlp.transliterate.transliterate()sometimes throws aKeyErrorwhen the input contains the characterฅ. The stacktrace points toReplaceSndinnlp.py.In the following output, the word ภาษาไวคาลีฅ is taken from the list of processed Wikipedia article titles in this repo.
For now, this can be solved easily with this basic replacement:
text.replace("ฅ", "ค"), which will not affect the transliteration.