11# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
22# SPDX-FileType: SOURCE
33# SPDX-License-Identifier: Apache-2.0
4- """Check if it is Thai text
5- """
4+ """Check if it is Thai text"""
65
76from __future__ import annotations
87
98import string
109from collections import defaultdict
10+ from typing import Optional
1111
1212from pythainlp import (
1313 thai_above_vowels ,
@@ -215,16 +215,17 @@ def display_thai_char(ch: str) -> str:
215215 return ch
216216
217217
218- def thai_word_tone_detector (word : str ) -> list [tuple [str , str ]]:
218+ def thai_word_tone_detector (word : Optional [ str ] ) -> list [tuple [str , str ]]:
219219 """Thai tone detector for word.
220220
221221 It uses pythainlp.transliterate.pronunciate for converting word to\
222222 pronunciation.
223223
224- :param str word: Thai word.
225- :return: Thai pronunciation with tones in each syllable.\
226- (l, m, h, r, f or empty if it cannot be detected)
227- :rtype: Tuple[str, str]
224+ :param Optional[str] word: Thai word, or None
225+ :return: List of tuples containing Thai pronunciation with tones in each syllable.\
226+ Tone values: l (low), m (mid), h (high), r (rising), f (falling), or empty if it cannot be detected.\
227+ Returns [] if word is None or empty.
228+ :rtype: list[tuple[str, str]]
228229
229230 :Example:
230231 ::
@@ -236,7 +237,13 @@ def thai_word_tone_detector(word: str) -> list[tuple[str, str]]:
236237
237238 print(thai_word_tone_detector("มือถือ"))
238239 # output: [('มือ', 'm'), ('ถือ', 'r')]
240+
241+ print(thai_word_tone_detector(None))
242+ # output: []
239243 """
244+ if not word :
245+ return []
246+
240247 from ..transliterate import pronunciate
241248 from ..util .syllable import tone_detector
242249
0 commit comments