pythainlp.khavee
The pythainlp.khavee
module is a powerful toolkit designed for working with Thai poetry. The term “khavee” corresponds to “กวี” in the Thai language, which translates to “Poetry” in English. This toolkit equips users with the tools and utilities necessary for the creation, analysis, and verification of Thai poetry.
Modules
KhaveeVerifier
- class pythainlp.khavee.KhaveeVerifier[source]
-
- check_sara(word: str) str [source]
Check the vowels in the Thai word.
from pythainlp.khavee import KhaveeVerifier kv = KhaveeVerifier() print(kv.check_sara("เริง")) # output: 'เออ'
- check_marttra(word: str) str [source]
Check the Thai spelling Section in the Thai word.
- Parameters:
word (str) – Thai word
- Returns:
name of spelling Section of the word.
- Return type:
- Example:
from pythainlp.khavee import KhaveeVerifier kv = KhaveeVerifier() print(kv.check_marttra('สาว')) # output: 'เกอว'
- is_sumpus(word1: str, word2: str) bool [source]
Check the rhyme between two words.
- Parameters:
- Returns:
boolean
- Return type:
- Example:
from pythainlp.khavee import KhaveeVerifier kv = KhaveeVerifier() print(kv.is_sumpus('สรร', 'อัน')) # output: True print(kv.is_sumpus('สรร', 'แมว')) # output: False
- check_klon(text: str, k_type: int = 8) List[str] | str [source]
Check the suitability of the poem according to Thai principles.
- Parameters:
- Returns:
the check results of the suitability of the poem according to Thai principles.
- Return type:
- Example:
from pythainlp.khavee import KhaveeVerifier kv = KhaveeVerifier() print(kv.check_klon( 'ฉันชื่อหมูกรอบ ฉันชอบกินไก่ แล้วก็วิ่งไล่ หมาชื่อนํ้าทอง ลคคนเก่ง เอ๋งเอ๋งคะนอง มีคนจับจอง เขาชื่อน้องเธียร', k_type=4 )) # output: The poem is correct according to the principle. print(kv.check_klon( 'ฉันชื่อหมูกรอบ ฉันชอบกินไก่ แล้วก็วิ่งไล่ หมาชื่อนํ้าทอง ลคคนเก่ง เอ๋งเอ๋งเสียงหมา มีคนจับจอง เขาชื่อน้องเธียร', k_type=4 )) # output: [ "Can't find rhyme between paragraphs ('หมา', 'จอง') in paragraph 2", "Can't find rhyme between paragraphs ('หมา', 'ทอง') in paragraph 2" ]
- check_aek_too(text: List[str] | str, dead_syllable_as_aek: bool = False) List[bool] | List[str] | bool | str [source]
Checker of Thai tonal words
- Parameters:
- Returns:
the check result if the word is aek or too or False (not both) or list of check results if input is list
- Return type:
- Example:
from pythainlp.khavee import KhaveeVerifier kv = KhaveeVerifier() # การเช็คคำเอกโท print(kv.check_aek_too('เอง'), kv.check_aek_too('เอ่ง'), kv.check_aek_too('เอ้ง')) # -> False, aek, too print(kv.check_aek_too(['เอง', 'เอ่ง', 'เอ้ง'])) # ใช้ List ได้เหมือนกัน # -> [False, 'aek', 'too']
- handle_karun_sound_silence(word: str) str [source]
Handle silent sounds in Thai words using ‘์’ character (Karun) by stripping all characters before the ‘Karun’ character that should be silenced
- __dict__ = mappingproxy({'__module__': 'pythainlp.khavee.core', '__init__': <function KhaveeVerifier.__init__>, 'check_sara': <function KhaveeVerifier.check_sara>, 'check_marttra': <function KhaveeVerifier.check_marttra>, 'is_sumpus': <function KhaveeVerifier.is_sumpus>, 'check_karu_lahu': <function KhaveeVerifier.check_karu_lahu>, 'check_klon': <function KhaveeVerifier.check_klon>, 'check_aek_too': <function KhaveeVerifier.check_aek_too>, 'handle_karun_sound_silence': <function KhaveeVerifier.handle_karun_sound_silence>, '__dict__': <attribute '__dict__' of 'KhaveeVerifier' objects>, '__weakref__': <attribute '__weakref__' of 'KhaveeVerifier' objects>, '__doc__': None, '__annotations__': {}})
- __module__ = 'pythainlp.khavee.core'
The KhaveeVerifier
class is the primary component of the pythainlp.khavee module, dedicated to the verification of Thai poetry. It offers a range of functions and methods for analyzing and validating Thai poetry, ensuring its adherence to the rules and structure of classical Thai poetic forms.
Example
Here’s a basic example of how to use the KhaveeVerifier class to verify Thai poetry:
- ::
from pythainlp.khavee import KhaveeVerifier
# Initialize a KhaveeVerifier instance verifier = KhaveeVerifier()
# Text to verify poem_text = “ดอกไม้สวยงาม แสนสดใส”
# Verify if the text is Thai poetry is_poetry = verifier.is_khavee(poem_text)
print(f”The provided text is Thai poetry: {is_poetry}”)