Skip to content

Commit f4ffbbd

Browse files
committed
Handle empty text
1 parent a090448 commit f4ffbbd

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pythainlp/soundex/lk82.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
Thai soundex - lk82 system
3+
Thai soundex - LK82 system
44
55
Python implementation: Korakot Chaovavanich
66
https://gist.github.com/korakot/0b772e09340cac2f493868da035597e8
@@ -23,20 +23,23 @@
2323

2424
def lk82(text):
2525
"""
26-
LK82 - It's a thai soundex rule.
26+
LK82 - It's a Thai soundex rule.
2727
2828
:param str text: Thai word
2929
:return: LK82 soundex
3030
"""
3131
if not text:
3232
return ""
3333

34-
res = []
3534
text = _RE_1.sub("", text) # 4.ลบวรรณยุกต์
3635
text = _RE_2.sub("", text) # 4.ลบตัวการันต์
3736
text = _RE_3.sub("", text) # 5.ทิ้งไม้ไต่คู่ ฯลฯ
3837

38+
if not text:
39+
return ""
40+
3941
# 6.เข้ารหัสตัวแรก
42+
res = []
4043
if "ก" <= text[0] <= "ฮ":
4144
res.append(text[0].translate(_TRANS1))
4245
text = text[1:]

pythainlp/soundex/udom83.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def udom83(text):
5252
text = _RE_10.sub("", text)
5353
text = _RE_11.sub("", text)
5454

55+
if not text:
56+
return ""
57+
5558
sd = text[0].translate(_TRANS1)
5659
sd += text[1:].translate(_TRANS2)
5760

0 commit comments

Comments
 (0)