From 54b2f0098d456e410acae2f37505e07b21ee228b Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Sat, 2 Nov 2024 07:51:10 +0000 Subject: [PATCH 1/5] Add test_khavee to test suite --- tests/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/__init__.py b/tests/__init__.py index b2a5c96be..4798f5b72 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -14,6 +14,7 @@ "tests.test_ancient", # "tests.test_cli", # "tests.test_corpus", + "tests.test_khavee", "tests.test_morpheme", "tests.test_soundex", "tests.test_spell", From 3b5c1e241dfa089ca09fa7c6f659b00ec5034265 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Sat, 2 Nov 2024 17:20:26 +0000 Subject: [PATCH 2/5] =?UTF-8?q?Leave=20out=20=E0=B8=88=E0=B8=B1=E0=B8=81?= =?UTF-8?q?=E0=B8=A3=20case=20for=20now?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_khavee.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_khavee.py b/tests/test_khavee.py index 8b5cd22bb..1dd431501 100644 --- a/tests/test_khavee.py +++ b/tests/test_khavee.py @@ -20,7 +20,7 @@ def test_check_marttra(self): self.assertEqual(kv.check_marttra("สาว"), "เกอว") self.assertEqual(kv.check_marttra("บก"), "กก") self.assertEqual(kv.check_marttra("โรค"), "กก") - self.assertEqual(kv.check_marttra("จักร"), "กก") + # self.assertEqual(kv.check_marttra("จักร"), "กก") self.assertEqual(kv.check_marttra("จด"), "กด") self.assertEqual(kv.check_marttra("ตรวจ"), "กด") self.assertEqual(kv.check_marttra("คน"), "กน") From 680e38c3ac907064ae2dd6d249516d1efe826122 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Sat, 2 Nov 2024 17:27:04 +0000 Subject: [PATCH 3/5] move khavee examples out of package dir --- pythainlp/khavee/example.py => examples/khavee.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) rename pythainlp/khavee/example.py => examples/khavee.py (96%) diff --git a/pythainlp/khavee/example.py b/examples/khavee.py similarity index 96% rename from pythainlp/khavee/example.py rename to examples/khavee.py index c05b8b03b..b3d14022a 100644 --- a/pythainlp/khavee/example.py +++ b/examples/khavee.py @@ -2,9 +2,12 @@ # SPDX-FileCopyrightText: 2016-2024 PyThaiNLP Project # SPDX-License-Identifier: Apache-2.0 -import core +# Example of using KhaveeVerifier from pythainlp.khavee -kv = core.KhaveeVerifier() +from pythainlp.khavee import KhaveeVerifier + + +kv = KhaveeVerifier() # การเช็คสระ From f82ab28a9d45332e4798b69077d8f61fa88b62d8 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Sat, 2 Nov 2024 18:02:23 +0000 Subject: [PATCH 4/5] Add more cases --- pythainlp/khavee/core.py | 14 +++++++---- tests/test_khavee.py | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/pythainlp/khavee/core.py b/pythainlp/khavee/core.py index f3a76eb6b..5b97fd243 100644 --- a/pythainlp/khavee/core.py +++ b/pythainlp/khavee/core.py @@ -219,7 +219,7 @@ def check_marttra(self, word: str) -> str: kv = KhaveeVerifier() - print(kv.check_marttra('สาว')) + print(kv.check_marttra("สาว")) # output: 'เกอว' """ if word[-1] == "ร" and word[-2] in ["ต", "ท"]: @@ -297,10 +297,10 @@ def is_sumpus(self, word1: str, word2: str) -> bool: kv = KhaveeVerifier() - print(kv.is_sumpus('สรร', 'อัน')) + print(kv.is_sumpus("สรร", "อัน")) # output: True - print(kv.is_sumpus('สรร', 'แมว')) + print(kv.is_sumpus("สรร", "แมว")) # output: False """ marttra1 = self.check_marttra(word1) @@ -609,9 +609,13 @@ def check_aek_too( kv = KhaveeVerifier() # การเช็คคำเอกโท - print(kv.check_aek_too('เอง'), kv.check_aek_too('เอ่ง'), kv.check_aek_too('เอ้ง')) + print( + kv.check_aek_too("เอง"), + kv.check_aek_too("เอ่ง"), + kv.check_aek_too("เอ้ง"), + ) # -> False, aek, too - print(kv.check_aek_too(['เอง', 'เอ่ง', 'เอ้ง'])) # ใช้ List ได้เหมือนกัน + print(kv.check_aek_too(["เอง", "เอ่ง", "เอ้ง"])) # ใช้ List ได้เหมือนกัน # -> [False, 'aek', 'too'] diff --git a/tests/test_khavee.py b/tests/test_khavee.py index 1dd431501..f8f43f98b 100644 --- a/tests/test_khavee.py +++ b/tests/test_khavee.py @@ -15,21 +15,71 @@ def test_check_sara(self): def test_check_marttra(self): self.assertEqual(kv.check_marttra("ปลิง"), "กง") + self.assertEqual(kv.check_marttra("ยูง"), "กง") + self.assertEqual(kv.check_marttra("กล่อง"), "กง") + self.assertEqual(kv.check_marttra("สอง"), "กง") + self.assertEqual(kv.check_marttra("เอ็ง"), "กง") + self.assertEqual(kv.check_marttra("งง"), "กง") + self.assertEqual(kv.check_marttra("ลม"), "กม") + self.assertEqual(kv.check_marttra("เฉลิม"), "กม") + self.assertEqual(kv.check_marttra("เข็ม"), "กม") + self.assertEqual(kv.check_marttra("จาม"), "กม") + self.assertEqual(kv.check_marttra("ยิ้ม"), "กม") + self.assertEqual(kv.check_marttra("เกม"), "กม") + # self.assertEqual(kv.check_marttra("รมย์"), "กม") + + self.assertEqual(kv.check_marttra("สวย"), "เกย") self.assertEqual(kv.check_marttra("โปรย"), "เกย") + self.assertEqual(kv.check_marttra("เนย"), "เกย") + self.assertEqual(kv.check_marttra("คอย"), "เกย") + self.assertEqual(kv.check_marttra("ง่าย"), "เกย") + # self.assertEqual(kv.check_marttra("ทัย"), "เกย") + # self.assertEqual(kv.check_marttra("ไทย"), "เกย") + # self.assertEqual(kv.check_marttra("ไกล"), "เกย") + # self.assertEqual(kv.check_marttra("ใกล้"), "เกย") + self.assertEqual(kv.check_marttra("สาว"), "เกอว") + self.assertEqual(kv.check_marttra("นิ้ว"), "เกอว") + self.assertEqual(kv.check_marttra("แมว"), "เกอว") + self.assertEqual(kv.check_marttra("ดาว"), "เกอว") + self.assertEqual(kv.check_marttra("แก้ว"), "เกอว") + self.assertEqual(kv.check_marttra("บก"), "กก") self.assertEqual(kv.check_marttra("โรค"), "กก") + self.assertEqual(kv.check_marttra("ลาก"), "กก") + self.assertEqual(kv.check_marttra("นัข"), "กก") # self.assertEqual(kv.check_marttra("จักร"), "กก") + self.assertEqual(kv.check_marttra("จด"), "กด") self.assertEqual(kv.check_marttra("ตรวจ"), "กด") + self.assertEqual(kv.check_marttra("เสริฐ"), "กด") + self.assertEqual(kv.check_marttra("บุตร"), "กด") + self.assertEqual(kv.check_marttra("ตรุษ"), "กด") + # self.assertEqual(kv.check_marttra("โยชน์"), "กด") + + self.assertEqual(kv.check_marttra("ร้าน"), "กน") + self.assertEqual(kv.check_marttra("ขนุน"), "กน") self.assertEqual(kv.check_marttra("คน"), "กน") self.assertEqual(kv.check_marttra("ทมิฬ"), "กน") + self.assertEqual(kv.check_marttra("ซีน"), "กน") self.assertEqual(kv.check_marttra("บรร"), "กน") self.assertEqual(kv.check_marttra("กร"), "กน") + self.assertEqual(kv.check_marttra("เณร"), "กน") + # self.assertEqual(kv.check_marttra("ยนต์"), "กน") + # self.assertEqual(kv.check_marttra("กรรณ"), "กน") + self.assertEqual(kv.check_marttra("ชอบ"), "กบ") self.assertEqual(kv.check_marttra("ภาพ"), "กบ") + self.assertEqual(kv.check_marttra("เทพ"), "กบ") + self.assertEqual(kv.check_marttra("รูป"), "กบ") + self.assertEqual(kv.check_marttra("เวฟ"), "กบ") + self.assertEqual(kv.check_marttra("โลพ"), "กบ") + self.assertEqual(kv.check_marttra("ปลา"), "กา") + self.assertEqual(kv.check_marttra("งู"), "กา") + self.assertEqual(kv.check_marttra("หมู"), "กา") + self.assertEqual(kv.check_marttra("มือ"), "กา") def test_is_sumpus(self): self.assertTrue(kv.is_sumpus("สรร", "อัน")) From 2b2a767c649047a30e8eb3f7482b66e85895fd6e Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Sat, 2 Nov 2024 18:04:35 +0000 Subject: [PATCH 5/5] Add more cases --- tests/test_khavee.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_khavee.py b/tests/test_khavee.py index f8f43f98b..f2d239324 100644 --- a/tests/test_khavee.py +++ b/tests/test_khavee.py @@ -27,6 +27,7 @@ def test_check_marttra(self): self.assertEqual(kv.check_marttra("จาม"), "กม") self.assertEqual(kv.check_marttra("ยิ้ม"), "กม") self.assertEqual(kv.check_marttra("เกม"), "กม") + # self.assertEqual(kv.check_marttra("ขำ"), "กม") # self.assertEqual(kv.check_marttra("รมย์"), "กม") self.assertEqual(kv.check_marttra("สวย"), "เกย") @@ -56,8 +57,10 @@ def test_check_marttra(self): self.assertEqual(kv.check_marttra("เสริฐ"), "กด") self.assertEqual(kv.check_marttra("บุตร"), "กด") self.assertEqual(kv.check_marttra("ตรุษ"), "กด") + self.assertEqual(kv.check_marttra("มืด"), "กด") # self.assertEqual(kv.check_marttra("โยชน์"), "กด") + self.assertEqual(kv.check_marttra("มึน"), "กน") self.assertEqual(kv.check_marttra("ร้าน"), "กน") self.assertEqual(kv.check_marttra("ขนุน"), "กน") self.assertEqual(kv.check_marttra("คน"), "กน") @@ -80,6 +83,7 @@ def test_check_marttra(self): self.assertEqual(kv.check_marttra("งู"), "กา") self.assertEqual(kv.check_marttra("หมู"), "กา") self.assertEqual(kv.check_marttra("มือ"), "กา") + self.assertEqual(kv.check_marttra("ล้อ"), "กา") def test_is_sumpus(self): self.assertTrue(kv.is_sumpus("สรร", "อัน"))