From 52942dce4933671ccbee085c8f91f938d418a8f4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 10 Jan 2026 16:27:41 +0000 Subject: [PATCH 1/2] Initial plan From 621e15d165d41db75121cd4cc7a9916e6cc00ceb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 10 Jan 2026 16:32:38 +0000 Subject: [PATCH 2/2] =?UTF-8?q?Fix:=20Replace=20=E0=B8=85=20with=20?= =?UTF-8?q?=E0=B8=84=20in=20tltk=20transliterate=20functions=20to=20avoid?= =?UTF-8?q?=20KeyError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: wannaphong <8536487+wannaphong@users.noreply.github.com> --- pythainlp/transliterate/tltk.py | 6 ++++++ tests/extra/testx_transliterate.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/pythainlp/transliterate/tltk.py b/pythainlp/transliterate/tltk.py index 12da6c25c..16581b800 100644 --- a/pythainlp/transliterate/tltk.py +++ b/pythainlp/transliterate/tltk.py @@ -16,15 +16,21 @@ def romanize(text: str) -> str: :return: A string of Thai words rendered in the Latin alphabet. :rtype: str """ + # Replace ฅ with ค to avoid KeyError in tltk (out-of-vocabulary issue) + text = text.replace("ฅ", "ค") _temp = th2roman(text) return _temp[: _temp.rfind(" ")].replace("", "") def tltk_g2p(text: str) -> str: + # Replace ฅ with ค to avoid KeyError in tltk (out-of-vocabulary issue) + text = text.replace("ฅ", "ค") _temp = g2p(text).split("")[1].replace("|", "").replace("|", " ") return _temp.replace("", "") def tltk_ipa(text: str) -> str: + # Replace ฅ with ค to avoid KeyError in tltk (out-of-vocabulary issue) + text = text.replace("ฅ", "ค") _temp = th2ipa(text) return _temp[: _temp.rfind(" ")].replace("", "") diff --git a/tests/extra/testx_transliterate.py b/tests/extra/testx_transliterate.py index 231f3b510..43683f8ce 100644 --- a/tests/extra/testx_transliterate.py +++ b/tests/extra/testx_transliterate.py @@ -18,6 +18,8 @@ class TransliterateTestCaseX(unittest.TestCase): def test_romanize(self): self.assertEqual(romanize("แมว", engine="tltk"), "maeo") + # Test for character ฅ (issue: Transliterator cannot handle ฅ) + self.assertIsNotNone(romanize("ภาษาไวคาลีฅ", engine="tltk")) def test_romanize_thai2rom(self): self.assertEqual(romanize("แมว", engine="thai2rom"), "maeo") @@ -146,6 +148,9 @@ def test_transliterate(self): self.assertIsNotNone(transliterate("แมว", engine="tltk_g2p")) self.assertIsNotNone(transliterate("คน", engine="tltk_ipa")) self.assertIsNotNone(transliterate("แมว", engine="tltk_ipa")) + # Test for character ฅ (issue: Transliterator cannot handle ฅ) + self.assertIsNotNone(transliterate("ภาษาไวคาลีฅ", engine="tltk_g2p")) + self.assertIsNotNone(transliterate("ภาษาไวคาลีฅ", engine="tltk_ipa")) self.assertIsNotNone(trans_list("คน")) self.assertIsNotNone(xsampa_list("คน"))