From 33984faaa4442f8e99fe1f69785462213d143aac Mon Sep 17 00:00:00 2001 From: phoneee Date: Sun, 29 Mar 2026 16:38:05 +0700 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20apply=20=E0=B9=80=E0=B8=AD=E0=B9=87?= =?UTF-8?q?=E0=B8=94=20rule=20for=20ones=3D1=20in=20hundreds=20and=20above?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- pythainlp/util/numtoword.py | 4 ++++ tests/core/test_util.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pythainlp/util/numtoword.py b/pythainlp/util/numtoword.py index 95d098c3e..1982b09e7 100644 --- a/pythainlp/util/numtoword.py +++ b/pythainlp/util/numtoword.py @@ -121,6 +121,10 @@ def num_to_thaiword(number: Optional[int]) -> str: for search, replac in _EXCEPTIONS.items(): output = output.replace(search, replac) + # เอ็ด rule: trailing หนึ่ง in ones place (after any place marker) + if number != 1 and number != -1 and output.endswith("หนึ่ง"): + output = output[: -len("หนึ่ง")] + "เอ็ด" + if number_temp < 0: output = "ลบ" + output diff --git a/tests/core/test_util.py b/tests/core/test_util.py index bbba08521..4db1e56fb 100644 --- a/tests/core/test_util.py +++ b/tests/core/test_util.py @@ -141,6 +141,10 @@ def test_number(self): self.assertEqual(num_to_thaiword(0), "ศูนย์") self.assertEqual(num_to_thaiword(112), "หนึ่งร้อยสิบสอง") self.assertEqual(num_to_thaiword(-273), "ลบสองร้อยเจ็ดสิบสาม") + # เอ็ด rule: ones=1 must use เอ็ด when number > 1 + self.assertEqual(num_to_thaiword(101), "หนึ่งร้อยเอ็ด") + self.assertEqual(num_to_thaiword(1001), "หนึ่งพันเอ็ด") + self.assertEqual(num_to_thaiword(1000001), "หนึ่งล้านเอ็ด") self.assertEqual(thaiword_to_num("ศูนย์"), 0) self.assertEqual(thaiword_to_num("แปด"), 8) From 51a6feb2d9459d56ae5ce03cc7f2a47e4cece116 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Sun, 29 Mar 2026 21:21:20 +0100 Subject: [PATCH 2/3] Update tests/core/test_util.py --- tests/core/test_util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/core/test_util.py b/tests/core/test_util.py index 4db1e56fb..461c4af69 100644 --- a/tests/core/test_util.py +++ b/tests/core/test_util.py @@ -142,6 +142,7 @@ def test_number(self): self.assertEqual(num_to_thaiword(112), "หนึ่งร้อยสิบสอง") self.assertEqual(num_to_thaiword(-273), "ลบสองร้อยเจ็ดสิบสาม") # เอ็ด rule: ones=1 must use เอ็ด when number > 1 + self.assertEqual(num_to_thaiword(1), "หนึ่ง") self.assertEqual(num_to_thaiword(101), "หนึ่งร้อยเอ็ด") self.assertEqual(num_to_thaiword(1001), "หนึ่งพันเอ็ด") self.assertEqual(num_to_thaiword(1000001), "หนึ่งล้านเอ็ด") From 7aa7c5ca965e3b53d42ca4c9a9ca2fd2c910bede Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Sun, 29 Mar 2026 21:28:22 +0100 Subject: [PATCH 3/3] Update tests/core/test_util.py --- tests/core/test_util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/core/test_util.py b/tests/core/test_util.py index 461c4af69..6aaa4c98a 100644 --- a/tests/core/test_util.py +++ b/tests/core/test_util.py @@ -143,6 +143,7 @@ def test_number(self): self.assertEqual(num_to_thaiword(-273), "ลบสองร้อยเจ็ดสิบสาม") # เอ็ด rule: ones=1 must use เอ็ด when number > 1 self.assertEqual(num_to_thaiword(1), "หนึ่ง") + self.assertEqual(num_to_thaiword(-1), "ลบหนึ่ง") self.assertEqual(num_to_thaiword(101), "หนึ่งร้อยเอ็ด") self.assertEqual(num_to_thaiword(1001), "หนึ่งพันเอ็ด") self.assertEqual(num_to_thaiword(1000001), "หนึ่งล้านเอ็ด")