Skip to content

Commit

Permalink
Fixed #1004
Browse files Browse the repository at this point in the history
Fixed #1004
  • Loading branch information
wannaphong committed Dec 25, 2024
1 parent 188904f commit 6f1dc92
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
38 changes: 19 additions & 19 deletions pythainlp/util/syllable.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def syllable_length(syllable: str) -> str:
# output: short
"""
consonants = [i for i in syllable if i in list(thai_consonants)]
if len(consonants) < 3 and any((c in set(short)) for c in syllable):
if len(consonants) <= 3 and any((c in set(short)) for c in syllable):
return "short"
elif bool(re_short.search(syllable)):
return "short"
Expand Down Expand Up @@ -259,15 +259,15 @@ def tone_detector(syllable: str) -> str:
and tone_mark == "่"
):
r = "l"
elif initial_consonant == "อ" and consonant_ending and s == "dead":
r = "l"
elif (
initial_consonant == "ห"
and consonant_ending
and s == "live"
and tone_mark == "่"
):
r = "l"
elif initial_consonant == "อ" and consonant_ending and s == "dead":
r = "l"
elif (
initial_consonant == "ห"
and consonant_ending
Expand All @@ -279,6 +279,22 @@ def tone_detector(syllable: str) -> str:
r = "l"
elif initial_consonant == "ห" and consonant_ending and s == "live":
r = "r"
elif initial_consonant_type == "high" and s == "live" and tone_mark == "่":
r = "l"
elif initial_consonant_type == "mid" and s == "live" and tone_mark == "่":
r = "l"
elif initial_consonant_type == "low" and tone_mark == "้":
r = "h"
elif initial_consonant_type == "mid" and tone_mark == "๋":
r = "r"
elif initial_consonant_type == "mid" and tone_mark == "๊":
r = "h"
elif initial_consonant_type == "low" and tone_mark == "่":
r = "f"
elif initial_consonant_type == "mid" and tone_mark == "้":
r = "f"
elif initial_consonant_type == "high" and tone_mark == "้":
r = "f"
elif (
initial_consonant_type == "low"
and syllable_check_length == "short"
Expand All @@ -299,22 +315,6 @@ def tone_detector(syllable: str) -> str:
and syllable_check == "open"
):
r = "h"
elif initial_consonant_type == "high" and s == "live" and tone_mark == "่":
r = "l"
elif initial_consonant_type == "mid" and s == "live" and tone_mark == "่":
r = "l"
elif initial_consonant_type == "low" and tone_mark == "้":
r = "h"
elif initial_consonant_type == "mid" and tone_mark == "๋":
r = "r"
elif initial_consonant_type == "mid" and tone_mark == "๊":
r = "h"
elif initial_consonant_type == "low" and tone_mark == "่":
r = "f"
elif initial_consonant_type == "mid" and tone_mark == "้":
r = "f"
elif initial_consonant_type == "high" and tone_mark == "้":
r = "f"
elif initial_consonant_type == "mid" and s == "dead":
r = "l"
elif initial_consonant_type == "high" and s == "dead":
Expand Down
2 changes: 2 additions & 0 deletions tests/core/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,8 @@ def test_tone_detector(self):
("f", "ไหม้"),
("f", "ต้น"),
("f", "ผู้"),
("h", "ครับ"),
("f", "ค่ะ"),
]
for i, j in data:
self.assertEqual(tone_detector(j), i)
Expand Down

0 comments on commit 6f1dc92

Please sign in to comment.