fix: apply เอ็ด rule for ones=1 in hundreds and above#1386
Merged
bact merged 3 commits intoPyThaiNLP:devfrom Mar 29, 2026
Merged
fix: apply เอ็ด rule for ones=1 in hundreds and above#1386bact merged 3 commits intoPyThaiNLP:devfrom
bact merged 3 commits intoPyThaiNLP:devfrom
Conversation
num_to_thaiword(101) returned "หนึ่งร้อยหนึ่ง" instead of "หนึ่งร้อยเอ็ด". The เอ็ด rule only triggered when tens > 0 (via "สิบหนึ่ง" → "สิบเอ็ด" replacement). Add post-processing to replace trailing หนึ่ง with เอ็ด when the number > 1.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Thai number-to-words conversion so that numbers ending in 1 use เอ็ด (instead of หนึ่ง) when the overall number is greater than 1, resolving the incorrect output for cases like num_to_thaiword(101).
Changes:
- Add a post-processing rule in
num_to_thaiword()to replace a trailingหนึ่งwithเอ็ดwhennumberis not±1. - Add regression tests covering hundreds/thousands/millions ending in 1 (e.g., 101, 1001, 1000001).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pythainlp/util/numtoword.py |
Implements the trailing-หนึ่ง → เอ็ด rule for numbers other than ±1. |
tests/core/test_util.py |
Adds regression tests validating the corrected เอ็ด behavior for trailing ones in larger numbers. |
bact
reviewed
Mar 29, 2026
|
|
||
| # เอ็ด rule: trailing หนึ่ง in ones place (after any place marker) | ||
| if number != 1 and number != -1 and output.endswith("หนึ่ง"): | ||
| output = output[: -len("หนึ่ง")] + "เอ็ด" |
bact
approved these changes
Mar 29, 2026
wannaphong
approved these changes
Mar 29, 2026
bact
reviewed
Mar 29, 2026
bact
reviewed
Mar 29, 2026
|
Member
|
Merged. Thanks @phoneee |
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
Fix
num_to_thaiword(101)returning หนึ่งร้อยหนึ่ง instead of หนึ่งร้อยเอ็ดFixes #1385