Spaces:
Running
Running
Delete text/thai.py
Browse files- text/thai.py +0 -44
text/thai.py
DELETED
|
@@ -1,44 +0,0 @@
|
|
| 1 |
-
import re
|
| 2 |
-
from num_thai.thainumbers import NumThai
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
num = NumThai()
|
| 6 |
-
|
| 7 |
-
# List of (Latin alphabet, Thai) pairs:
|
| 8 |
-
_latin_to_thai = [(re.compile('%s' % x[0], re.IGNORECASE), x[1]) for x in [
|
| 9 |
-
('a', 'เอ'),
|
| 10 |
-
('b','บี'),
|
| 11 |
-
('c','ซี'),
|
| 12 |
-
('d','ดี'),
|
| 13 |
-
('e','อี'),
|
| 14 |
-
('f','เอฟ'),
|
| 15 |
-
('g','จี'),
|
| 16 |
-
('h','เอช'),
|
| 17 |
-
('i','ไอ'),
|
| 18 |
-
('j','เจ'),
|
| 19 |
-
('k','เค'),
|
| 20 |
-
('l','แอล'),
|
| 21 |
-
('m','เอ็ม'),
|
| 22 |
-
('n','เอ็น'),
|
| 23 |
-
('o','โอ'),
|
| 24 |
-
('p','พี'),
|
| 25 |
-
('q','คิว'),
|
| 26 |
-
('r','แอร์'),
|
| 27 |
-
('s','เอส'),
|
| 28 |
-
('t','ที'),
|
| 29 |
-
('u','ยู'),
|
| 30 |
-
('v','วี'),
|
| 31 |
-
('w','ดับเบิลยู'),
|
| 32 |
-
('x','เอ็กซ์'),
|
| 33 |
-
('y','วาย'),
|
| 34 |
-
('z','ซี')
|
| 35 |
-
]]
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
def num_to_thai(text):
|
| 39 |
-
return re.sub(r'(?:\d+(?:,?\d+)?)+(?:\.\d+(?:,?\d+)?)?', lambda x: ''.join(num.NumberToTextThai(float(x.group(0).replace(',', '')))), text)
|
| 40 |
-
|
| 41 |
-
def latin_to_thai(text):
|
| 42 |
-
for regex, replacement in _latin_to_thai:
|
| 43 |
-
text = re.sub(regex, replacement, text)
|
| 44 |
-
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|