diff --git a/pythainlp/khavee/core.py b/pythainlp/khavee/core.py index f940e8922..dc426b322 100644 --- a/pythainlp/khavee/core.py +++ b/pythainlp/khavee/core.py @@ -54,6 +54,9 @@ def check_sara(self, word: str) -> str: sara = [] countoa = 0 + if not word: + return "" + # In case of การันย์ if "์" in word[-1]: word = word[:-2] @@ -253,6 +256,9 @@ def check_marttra(self, word: str) -> str: word = self.handle_karun_sound_silence(word) word = remove_tonemark(word) + if not word: + return "" + # Check for ำ at the end (represents "am" sound, ends with m) if word[-1] == "ำ": return "กม" diff --git a/pythainlp/morpheme/word_formation.py b/pythainlp/morpheme/word_formation.py index 63453a25e..45b161fe2 100644 --- a/pythainlp/morpheme/word_formation.py +++ b/pythainlp/morpheme/word_formation.py @@ -38,7 +38,12 @@ def nighit(w1: str, w2: str) -> str: newword = [] newword.append(list_w1[0]) newword.append("ั") - consonant_start = [i for i in list_w2 if i in set(thai_consonants)][0] + consonants_in_w2 = [i for i in list_w2 if i in set(thai_consonants)] + if not consonants_in_w2: + raise ValueError( + f"w2 {w2!r} contains no Thai consonants." + ) + consonant_start = consonants_in_w2[0] if consonant_start in ["ก", "ช", "ค", "ข", "ง"]: newword.append("ง") elif consonant_start in ["จ", "ฉ", "ช", "ฌ"]: