Skip to content
Open
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
5 changes: 4 additions & 1 deletion pythainlp/transliterate/royin.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ def _romanize(word: str) -> str:
return ""

word = _replace_vowels(_normalize(word))
consonants = _RE_CONSONANT.findall(word)
# Use the same membership test as _replace_consonants(), which treats
# every key of _CONSONANTS as a consonant. _RE_CONSONANT only matches
# thai_consonants, so it misses ฤ and the two lists fall out of sync.
consonants = [c for c in word if c in _CONSONANTS]

# 2-character word, all consonants
if len(word) == 2 and len(consonants) == 2:
Expand Down
13 changes: 13 additions & 0 deletions tests/core/test_transliterate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
"ชารินทร์": "charin",
}

# words containing ฤ (U+0E24 THAI CHARACTER RU), see issue #1444
RU_TESTS = {
"ฤก": "rueok",
"ฤดู": "rueadu",
"ฤทธิ์": "rueot",
}

# these are set of two-syllable words,
# to test if the transliteration/romanization is consistent, say
# romanize(1+2) = romanize(1) + romanize(2)
Expand All @@ -60,6 +67,12 @@ def test_romanize_royin_basic(self):
for word, expect in BASIC_TESTS.items():
self.assertEqual(romanize(word, engine="royin"), expect) # type: ignore[arg-type]

def test_romanize_royin_ru(self):
# ฤ (U+0E24) is a key of _CONSONANTS but is not in thai_consonants,
# so it used to desynchronise the consonant list and raise IndexError.
for word, expect in RU_TESTS.items():
self.assertEqual(romanize(word, engine="royin"), expect) # type: ignore[arg-type]

def test_romanize_royin_consistency(self):
for word, part1, part2 in CONSISTENCY_TESTS:
self.assertEqual(
Expand Down