fix(transliterate): romanize royin words containing ฤ - #1473
Open
Sanjays2402 wants to merge 1 commit into
Open
Conversation
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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What do these changes do
Make
romanize(..., engine="royin")handle words containing ฤ (U+0E24) instead of raisingIndexError, and add a regression test for them.What was wrong
_romanize()built its consonant list with_RE_CONSONANT, which is compiled fromthai_consonantsand 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, soromanize("ฤดู", engine="royin")raisedIndexError: 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_CONSONANTSentry. ฤก→rueok, ฤดู→rueadu, ฤทธิ์→rueot; words without ฤ are byte-identical to before, including ฤ words that did not crash (พฤษภาคม, อังกฤษ, พฤหัสบดี, นฤมล, ทฤษฎี).Fixes #1444
Your checklist for this pull request
test_romanize_royin_ruwas added totests/core/test_transliterate.pybeside the existing royin tests; it fails without the source fix (the reportedIndexError) and passes with it.tests/core/test_transliterate.pypasses in full, andruff checkis clean on both changed files.This change was prepared with AI assistance; the regression test was run locally and fails without the fix.