Skip to content

fix(transliterate): romanize royin words containing ฤ - #1473

Open
Sanjays2402 wants to merge 1 commit into
PyThaiNLP:mainfrom
Sanjays2402:fix/royin-ru-indexerror
Open

fix(transliterate): romanize royin words containing ฤ#1473
Sanjays2402 wants to merge 1 commit into
PyThaiNLP:mainfrom
Sanjays2402:fix/royin-ru-indexerror

Conversation

@Sanjays2402

Copy link
Copy Markdown

What do these changes do

Make romanize(..., engine="royin") handle words containing ฤ (U+0E24) instead of raising IndexError, and add a regression test for them.

What was wrong

_romanize() built its consonant list with _RE_CONSONANT, which is compiled from thai_consonants and therefore does not match ฤ. _replace_consonants(), however, treats every key of _CONSONANTS — which does include ฤ — as a consonant and advances its index for each one. On a word containing ฤ the index ran past the end of the list, so romanize("ฤดู", engine="royin") raised IndexError: string index out of range.

How this fixes it

The consonant list is now built with the same membership test the loop uses (c in _CONSONANTS), keeping the two in sync and letting ฤ romanize through its existing _CONSONANTS entry. ฤก→rueok, ฤดู→rueadu, ฤทธิ์→rueot; words without ฤ are byte-identical to before, including ฤ words that did not crash (พฤษภาคม, อังกฤษ, พฤหัสบดี, นฤมล, ทฤษฎี).

Fixes #1444

Your checklist for this pull request

  • Passed code styles and structures
  • Passed code linting checks and unit test

test_romanize_royin_ru was added to tests/core/test_transliterate.py beside the existing royin tests; it fails without the source fix (the reported IndexError) and passes with it. tests/core/test_transliterate.py passes in full, and ruff check is clean on both changed files.

This change was prepared with AI assistance; the regression test was run locally and fails without the fix.

romanize(..., engine="royin") raised IndexError on words containing ฤ
(U+0E24), e.g. ฤดู, ฤก, ฤทธิ์.

_romanize() built its consonant list with _RE_CONSONANT, which matches
only thai_consonants and so excludes ฤ, while _replace_consonants()
treats every key of _CONSONANTS - including ฤ - as a consonant and
advances its index for each one. The two went out of sync and the index
ran past the end of the list.

The consonant list is now built with the same membership test the loop
uses, so ฤ is romanized through its existing _CONSONANTS entry.

Adds RU_TESTS and test_romanize_royin_ru to
tests/core/test_transliterate.py.

Closes PyThaiNLP#1444
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexError on Thai words containing ฤ (U+0E24)

1 participant