Skip to content

Commit b113e0b

Browse files
authored
Merge pull request #1386 from phoneee/fix/numtoword-et-rule
fix: apply เอ็ด rule for ones=1 in hundreds and above
2 parents 01b0a86 + 7aa7c5c commit b113e0b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pythainlp/util/numtoword.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ def num_to_thaiword(number: Optional[int]) -> str:
121121
for search, replac in _EXCEPTIONS.items():
122122
output = output.replace(search, replac)
123123

124+
# เอ็ด rule: trailing หนึ่ง in ones place (after any place marker)
125+
if number != 1 and number != -1 and output.endswith("หนึ่ง"):
126+
output = output[: -len("หนึ่ง")] + "เอ็ด"
127+
124128
if number_temp < 0:
125129
output = "ลบ" + output
126130

tests/core/test_util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ def test_number(self):
141141
self.assertEqual(num_to_thaiword(0), "ศูนย์")
142142
self.assertEqual(num_to_thaiword(112), "หนึ่งร้อยสิบสอง")
143143
self.assertEqual(num_to_thaiword(-273), "ลบสองร้อยเจ็ดสิบสาม")
144+
# เอ็ด rule: ones=1 must use เอ็ด when number > 1
145+
self.assertEqual(num_to_thaiword(1), "หนึ่ง")
146+
self.assertEqual(num_to_thaiword(-1), "ลบหนึ่ง")
147+
self.assertEqual(num_to_thaiword(101), "หนึ่งร้อยเอ็ด")
148+
self.assertEqual(num_to_thaiword(1001), "หนึ่งพันเอ็ด")
149+
self.assertEqual(num_to_thaiword(1000001), "หนึ่งล้านเอ็ด")
144150

145151
self.assertEqual(thaiword_to_num("ศูนย์"), 0)
146152
self.assertEqual(thaiword_to_num("แปด"), 8)

0 commit comments

Comments
 (0)