Skip to content

Commit 463dd23

Browse files
committed
Fixed #1055
1 parent 37f6ba8 commit 463dd23

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

pythainlp/util/syllable.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,20 @@ def sound_syllable(syllable: str) -> str:
8181
print(sound_syllable("เลข"))
8282
# output: dead
8383
"""
84+
# if len of syllable < 2
85+
if len(syllable) < 2:
86+
return "dead"
8487
# get consonants
8588
consonants = [i for i in syllable if i in list(thai_consonants_all)]
89+
if (len(consonants) == 0 and
90+
"อ" in syllable
91+
and any((c in set("เ")) for c in syllable)
92+
and len(syllable)== 2
93+
):
94+
return "live"
8695
# get spelling consonants
8796
spelling_consonant = consonants[-1]
88-
# if len of syllable < 2
89-
if len(syllable) < 2:
90-
return "dead"
91-
elif (spelling_consonant in _check_2) and (
97+
if (spelling_consonant in _check_2) and (
9298
any((c in set("าีืแูาเโ")) for c in syllable) is False
9399
and any((c in set("ำใไ")) for c in syllable) is False
94100
and bool(pattern.search(syllable)) is not True
@@ -122,6 +128,8 @@ def sound_syllable(syllable: str) -> str:
122128
or any((c in set(short)) for c in syllable)
123129
) and len(consonants) < 2:
124130
return "dead"
131+
elif syllable[-1] in set(short):
132+
return "dead"
125133
return "live"
126134
elif bool(
127135
re_short.search(syllable)

tests/core/test_util.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,14 @@ def test_sound_syllable(self):
680680
("เพราะ", "dead"),
681681
("เกาะ", "dead"),
682682
("แคะ", "dead"),
683+
("ประ", "dead"),
683684
]
684685
for i, j in test:
685-
self.assertEqual(sound_syllable(i), j)
686+
self.assertEqual(
687+
sound_syllable(i),
688+
j,
689+
f"{i} should be determined to be a '{j}' syllable."
690+
)
686691

687692
def test_tone_detector(self):
688693
data = [
@@ -710,9 +715,14 @@ def test_tone_detector(self):
710715
("f", "ผู้"),
711716
("h", "ครับ"),
712717
("f", "ค่ะ"),
718+
("m", "เอ"),
713719
]
714720
for i, j in data:
715-
self.assertEqual(tone_detector(j), i)
721+
self.assertEqual(
722+
tone_detector(j),
723+
i,
724+
f"{j} should be determined to be a '{i}' tone."
725+
)
716726

717727
def test_syllable_length(self):
718728
self.assertEqual(syllable_length("มาก"), "long")

0 commit comments

Comments
 (0)