Skip to content

Commit 9072664

Browse files
committed
more test cases
1 parent 86d4b74 commit 9072664

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

pythainlp/transliterate/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from pythainlp.tokenize import word_tokenize
44

55

6-
# ถอดเสียงภาษาไทยเป็นอักษรละติน
76
def romanize(text: str, engine: str = "royin") -> str:
87
"""
8+
ถอดเสียงภาษาไทยเป็นอักษรละติน
99
:param str text: Thai text to be romanized
1010
:param str engine: 'royin' (default) or 'thai2rom'. 'royin' uses Thai Royal Institute standard. 'thai2rom' is deep learning Thai romanization (require keras).
1111
:return: English (more or less) text that spells out how the Thai text should read.
@@ -21,11 +21,9 @@ def romanize(text: str, engine: str = "royin") -> str:
2121
else: # use default engine "royin"
2222
from .royin import romanize
2323

24-
try:
25-
words = word_tokenize(text)
26-
romanized_words = [romanize(word) for word in words]
27-
except:
28-
romanized_words = [romanize(text)]
24+
words = word_tokenize(text)
25+
romanized_words = [romanize(word) for word in words]
26+
2927
return "".join(romanized_words)
3028

3129

pythainlp/transliterate/royin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,5 @@ def romanize(word: str) -> str:
176176
word2 = "".join(word2)
177177

178178
word2 = _replace_consonants(word2, res)
179-
179+
180180
return word2

tests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,10 @@ def test_normalize(self):
562562
# ### pythainlp.util.thai
563563

564564
def test_countthai(self):
565+
self.assertEqual(countthai(""), 0)
565566
self.assertEqual(countthai("ประเทศไทย"), 100.0)
567+
self.assertEqual(countthai("(กกต.)", ".()"), 100.0)
568+
self.assertEqual(countthai("(กกต.)", None), 50.0)
566569

567570
def test_isthaichar(self):
568571
self.assertEqual(isthaichar("ก"), True)
@@ -574,6 +577,7 @@ def test_isthai(self):
574577
self.assertEqual(isthai("ไทย0"), False)
575578
self.assertEqual(isthai("ต.ค."), True)
576579
self.assertEqual(isthai("(ต.ค.)"), False)
580+
self.assertEqual(isthai("ต.ค.", ignore_chars=None), False)
577581
self.assertEqual(isthai("(ต.ค.)", ignore_chars=".()"), True)
578582

579583
def test_is_thaicheck(self):

0 commit comments

Comments
 (0)