Skip to content

Commit

Permalink
Merge pull request #967 from bact/add-khavee-tests
Browse files Browse the repository at this point in the history
Add test_khavee to test suite
  • Loading branch information
bact authored Nov 2, 2024
2 parents 78f1795 + 2b2a767 commit 0c970fd
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 8 deletions.
7 changes: 5 additions & 2 deletions pythainlp/khavee/example.py → examples/khavee.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


# การเช็คสระ
Expand Down
14 changes: 9 additions & 5 deletions pythainlp/khavee/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ["ต", "ท"]:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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']
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
56 changes: 55 additions & 1 deletion tests/test_khavee.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,75 @@ 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("โลพ"), "กบ")

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("สรร", "อัน"))
Expand Down

0 comments on commit 0c970fd

Please sign in to comment.