File tree Expand file tree Collapse file tree 3 files changed +9
-7
lines changed Expand file tree Collapse file tree 3 files changed +9
-7
lines changed Original file line number Diff line number Diff line change 3
3
from pythainlp .tokenize import word_tokenize
4
4
5
5
6
- # ถอดเสียงภาษาไทยเป็นอักษรละติน
7
6
def romanize (text : str , engine : str = "royin" ) -> str :
8
7
"""
8
+ ถอดเสียงภาษาไทยเป็นอักษรละติน
9
9
:param str text: Thai text to be romanized
10
10
:param str engine: 'royin' (default) or 'thai2rom'. 'royin' uses Thai Royal Institute standard. 'thai2rom' is deep learning Thai romanization (require keras).
11
11
: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:
21
21
else : # use default engine "royin"
22
22
from .royin import romanize
23
23
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
+
29
27
return "" .join (romanized_words )
30
28
31
29
Original file line number Diff line number Diff line change @@ -176,5 +176,5 @@ def romanize(word: str) -> str:
176
176
word2 = "" .join (word2 )
177
177
178
178
word2 = _replace_consonants (word2 , res )
179
-
179
+
180
180
return word2
Original file line number Diff line number Diff line change @@ -562,7 +562,10 @@ def test_normalize(self):
562
562
# ### pythainlp.util.thai
563
563
564
564
def test_countthai (self ):
565
+ self .assertEqual (countthai ("" ), 0 )
565
566
self .assertEqual (countthai ("ประเทศไทย" ), 100.0 )
567
+ self .assertEqual (countthai ("(กกต.)" , ".()" ), 100.0 )
568
+ self .assertEqual (countthai ("(กกต.)" , None ), 50.0 )
566
569
567
570
def test_isthaichar (self ):
568
571
self .assertEqual (isthaichar ("ก" ), True )
@@ -574,6 +577,7 @@ def test_isthai(self):
574
577
self .assertEqual (isthai ("ไทย0" ), False )
575
578
self .assertEqual (isthai ("ต.ค." ), True )
576
579
self .assertEqual (isthai ("(ต.ค.)" ), False )
580
+ self .assertEqual (isthai ("ต.ค." , ignore_chars = None ), False )
577
581
self .assertEqual (isthai ("(ต.ค.)" , ignore_chars = ".()" ), True )
578
582
579
583
def test_is_thaicheck (self ):
You can’t perform that action at this time.
0 commit comments