Spaces:
Runtime error
Runtime error
File size: 2,046 Bytes
35b8bdf d9e50d0 35b8bdf d9e50d0 35b8bdf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
from text.cleaners import japanese_to_romaji_with_accent
from text.korean import (
join_jamos, j2hcj, h2j,
latin_to_hangul,
number_to_hangul,
g2pk,
)
import re
import jaconv
repl_lst = {
'γ²': 'γ
',
'γΈ': 'γ
',
'γ
': 'γ
',
'γ
': 'γ
',
'γ
': 'γ
',
'γ
': 'γ
/γ
',
'γ
': 'γ
/γ
£',
'γ
': 'γ
γ
',
'γ
': 'γ
/γ
',
'γ
': 'γ
/γ
',
'γ
': 'γ
γ
£',
'γ
’': 'γ
γ
£',
'γ
': 'γ
£γ
',
'γ
': 'γ
',
'γ
': 'γ
£γ
',
'γ
': 'γ
',
'γ
': 'γ
',
'γ
‘': 'γ
',
'||//γ
': 'γΉ',
}
def get_word_list(text):
text = g2pk(text)
text = latin_to_hangul(text)
text = number_to_hangul(text)
text = j2hcj(h2j(text))
text = re.sub(r'([\u3131-\u3163])$', r'\1.', text)
return list(join_jamos(text.replace(' ', ' ')[:-1]))
def korean2katakana(text):
word_lst = get_word_list(text)
text = '/' + text.replace('/', ' ').replace('|', ' ').replace('^', ' ').replace(' ', ' ').replace(' ', '^')
new_lst = []
for i, s in enumerate(word_lst):
dh = list(j2hcj(h2j(s)))
if len(dh) == 3:
if dh[-1] == 'γ΄':
dh[-1] = 'γ΄'
elif dh[-1] == 'γ
' or dh[-1] == 'γ
':
dh[-1] = 'γ΄|'
elif dh[-1] == 'γΉ':
dh[-1] = '||/'
else: # γ± γ· γ
dh[-1] = dh[-1]
dh.append('/')
new_lst.extend(dh)
kr = ''.join(new_lst)
for k, v in repl_lst.items():
kr = kr.replace(k, v)
kr2ro = japanese_to_romaji_with_accent(kr).replace('si', 'shi').replace('c', 'ts') \
.replace('ti', 'γγ£γΌ').replace('tu', 'γγ₯γΌ') \
.replace('di', 'γγ£γΌ').replace('du', 'γγ₯γΌ')
result = jaconv.alphabet2kata(kr2ro)
result = result.replace('/', '').replace('|', 'γΌ').replace('^', '')
print(result)
return result |