Skip to content

Commit 243f73e

Browse files
authored
add dead_syllable_as_aek support
for the check_aek_too function, we can now use dead_syllable as aek which is allowed for Thai poem such as klong
1 parent d68199e commit 243f73e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pythainlp/khavee/core.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,12 @@ def check_klon(self, text: str,k_type: int=8) -> Union[List[str], str]:
412412

413413
else:
414414
return 'Something went wrong Make sure you enter it in correct form.'
415-
416-
def check_aek_too(self, text: Union[List[str], str]) -> Union[List[bool], List[str], bool, str]:
415+
416+
def check_aek_too(self, text: Union[List[str], str], dead_syllable_as_aek:bool = False) -> Union[List[bool], List[str], bool, str]:
417417
"""
418418
Thai tonal word checker
419419
420-
:param str or list[str] text: Thai word or list of Thai words
420+
:param str or list[str] text: Thai word or list of Thai words, bool dead_syllable_as_aek: if True, dead syllable will be considered as aek
421421
:return: the check if the word is aek or too or False(not both) or list of the check if input is list
422422
:rtype: Union[List[bool], List[str], bool, str]
423423
@@ -433,9 +433,11 @@ def check_aek_too(self, text: Union[List[str], str]) -> Union[List[bool], List[s
433433
## -> False, aek, too
434434
print(kv.check_aek_too(['เอง', 'เอ่ง', 'เอ้ง'])) # ใช้ List ได้เหมือนกัน
435435
## -> [False, 'aek', 'too']
436+
437+
436438
"""
437439
if isinstance(text, list):
438-
return [self.check_aek_too(t) for t in text]
440+
return [self.check_aek_too(t, dead_syllable_as_aek) for t in text]
439441

440442
if not isinstance(text, str):
441443
raise TypeError('text must be str or iterable list[str]')
@@ -445,5 +447,7 @@ def check_aek_too(self, text: Union[List[str], str]) -> Union[List[bool], List[s
445447
return 'aek'
446448
elif '้' in word_characters and not '่' in word_characters:
447449
return 'too'
450+
if dead_syllable_as_aek and sound_syllable(text) == 'dead':
451+
return 'aek'
448452
else:
449453
return False

0 commit comments

Comments
 (0)