Skip to content

fix: apply เอ็ด rule for ones=1 in hundreds and above#1386

Merged
bact merged 3 commits intoPyThaiNLP:devfrom
phoneee:fix/numtoword-et-rule
Mar 29, 2026
Merged

fix: apply เอ็ด rule for ones=1 in hundreds and above#1386
bact merged 3 commits intoPyThaiNLP:devfrom
phoneee:fix/numtoword-et-rule

Conversation

@phoneee
Copy link
Copy Markdown
Contributor

@phoneee phoneee commented Mar 29, 2026

What do these changes do

Fix num_to_thaiword(101) returning หนึ่งร้อยหนึ่ง instead of หนึ่งร้อยเอ็ด

Fixes #1385

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

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.
@bact bact added the bug bugs in the library label Mar 29, 2026
@bact bact added this to PyThaiNLP Mar 29, 2026
@bact bact requested a review from Copilot March 29, 2026 16:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 เอ็ด when number is 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.


# เอ็ด rule: trailing หนึ่ง in ones place (after any place marker)
if number != 1 and number != -1 and output.endswith("หนึ่ง"):
output = output[: -len("หนึ่ง")] + "เอ็ด"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hacky but works.

@sonarqubecloud
Copy link
Copy Markdown

@bact bact merged commit b113e0b into PyThaiNLP:dev Mar 29, 2026
27 checks passed
@bact
Copy link
Copy Markdown
Member

bact commented Mar 29, 2026

Merged. Thanks @phoneee

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

Labels

bug bugs in the library

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: num_to_thaiword เอ็ด rule wrong for hundreds+; thaiword_to_time allows invalid hours/minutes; count_thai_chars double-counts

4 participants