Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pythainlp/transliterate/tltk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(" <s/>")].replace("<s/>", "")


def tltk_g2p(text: str) -> str:
# Replace ฅ with ค to avoid KeyError in tltk (out-of-vocabulary issue)
text = text.replace("ฅ", "ค")
_temp = g2p(text).split("<tr/>")[1].replace("|<s/>", "").replace("|", " ")
return _temp.replace("<s/>", "")


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(" <s/>")].replace("<s/>", "")
5 changes: 5 additions & 0 deletions tests/extra/testx_transliterate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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("คน"))
Expand Down
Loading