Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CjangCjengh committed Sep 28, 2022
1 parent 02a915a commit 7f4dcbf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion text/korean.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def number_to_hangul(text):
def korean_to_lazy_ipa(text):
text = latin_to_hangul(text)
text = number_to_hangul(text)
text=re.sub('[\uac00-\ud7af]+',lambda x:ko_pron.romanise(x.group(0),'ipa'),text).split('] ~ [')[0]
text=re.sub('[\uac00-\ud7af]+',lambda x:ko_pron.romanise(x.group(0),'ipa').split('] ~ [')[0],text)
for regex, replacement in _ipa_to_lazy_ipa:
text = re.sub(regex, replacement, text)
return text
37 changes: 36 additions & 1 deletion text/thai.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,41 @@

num = NumThai()

# List of (Latin alphabet, Thai) pairs:
_latin_to_thai = [(re.compile('%s' % x[0], re.IGNORECASE), x[1]) for x in [
('a', 'เอ'),
('b','บี'),
('c','ซี'),
('d','ดี'),
('e','อี'),
('f','เอฟ'),
('g','จี'),
('h','เอช'),
('i','ไอ'),
('j','เจ'),
('k','เค'),
('l','แอล'),
('m','เอ็ม'),
('n','เอ็น'),
('o','โอ'),
('p','พี'),
('q','คิว'),
('r','แอร์'),
('s','เอส'),
('t','ที'),
('u','ยู'),
('v','วี'),
('w','ดับเบิลยู'),
('x','เอ็กซ์'),
('y','วาย'),
('z','ซี')
]]


def num_to_thai(text):
return re.sub(r'(?:\d+,?\d+)+(?:\.\d+,?\d+)?', lambda x: ''.join(num.NumberToTextThai(float(x.group(0).replace(',', '')))), text)
return re.sub(r'(?:\d+(?:,?\d+)?)+(?:\.\d+(?:,?\d+)?)?', lambda x: ''.join(num.NumberToTextThai(float(x.group(0).replace(',', '')))), text)

def latin_to_thai(text):
for regex, replacement in _latin_to_thai:
text = re.sub(regex, replacement, text)
return text

0 comments on commit 7f4dcbf

Please sign in to comment.