File tree Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Original file line number Diff line number Diff line change 1
1
import re
2
2
3
- from korean_romanizer .syllable import Syllable
3
+ from korean_romanizer .syllable import (
4
+ Syllable ,
5
+ unicode_compatible_consonants ,
6
+ unicode_initial ,
7
+ )
4
8
from korean_romanizer .pronouncer import Pronouncer
5
9
6
10
'''
96
100
97
101
None : '' ,
98
102
}
103
+
104
+ # Compatibility jamo (e.g. ㄱ, ㄴ) do not appear as part of a full syllable.
105
+ # Map them to their onset romanization so single jamo can be transliterated.
106
+ compat_onset = {
107
+ comp : onset [unicode_initial [i ]]
108
+ for i , comp in enumerate (unicode_compatible_consonants )
109
+ }
99
110
100
111
class Romanizer (object ):
101
112
def __init__ (self , text ):
@@ -111,13 +122,14 @@ def romanize(self):
111
122
112
123
if not s .medial and not s .final :
113
124
# s is NOT a full syllable (e.g. characters)
114
- # if onset.get(chr(s.initial)):
115
- # _romanized += onset[chr(s.initial)]
116
- # elif vowel.get(chr(s.initial)):
117
- # _romanized += vowel[chr(s.initial)]
118
- # else:
119
- # _romanized += char
120
- _romanized += char
125
+ if char in vowel :
126
+ _romanized += vowel [char ]
127
+ elif char in onset :
128
+ _romanized += onset [char ]
129
+ elif char in compat_onset :
130
+ _romanized += compat_onset [char ]
131
+ else :
132
+ _romanized += char
121
133
else :
122
134
# s is a full syllable
123
135
_romanized += onset [s .initial ] + vowel [s .medial ] + coda [s .final ]
Original file line number Diff line number Diff line change @@ -70,8 +70,8 @@ def test_double_consonant_final_without_next_syllable():
70
70
71
71
72
72
def test_non_syllables ():
73
- assert romanize ("ㅠㄴㅁㄱ" ) == "ㅠㄴㅁㄱ "
74
- assert romanize ("ㅠ동" ) == "ㅠdong "
73
+ assert romanize ("ㅠㄴㅁㄱ" ) == "yunmg "
74
+ assert romanize ("ㅠ동" ) == "yudong "
75
75
76
76
77
77
def test_coda_h ():
You can’t perform that action at this time.
0 commit comments