-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathko.py
64 lines (54 loc) · 2.39 KB
/
ko.py
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
"""Naming set for Korean"""
import copy
import basepart
class ComposerElementKorean(basepart.ComposerElementBase):
"""Korean name composer - inspired by 이강성, 『파이썬 3 바이블』"""
character = ( \
tuple('ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ'), \
tuple('ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ'), \
tuple(' ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅅㅆㅇㅈㅊㅋㅌㅍㅎ') \
)
character_recommend = ( \
tuple('ㄱㄴㄷㅁㅂㅅㅇㅈㅎ'), \
tuple('ㅏㅓㅗㅜㅡㅣ'), \
tuple(' ㄴㅇ') \
)
num_character_all = \
len(character[0]) * \
len(character[1]) * \
len(character[2])
num_character_recommend = \
len(character_recommend[0]) * \
len(character_recommend[1]) * \
len(character_recommend[2])
initial = basepart.ListBase()
medial = basepart.ListBase()
final = basepart.ListBase()
def __init__(self, initial=None, medial=None, final=None):
pass # See the metaclass
def compose(self):
"""Compose the Korean name"""
character = self.character
list_original = [self.initial, self.medial, self.final]
list_process = [basepart.ListBase(), basepart.ListBase(), basepart.ListBase()]
ingredient = [basepart.ListBase(), basepart.ListBase(), basepart.ListBase()]
# Check type and init list_process
for (idx, elem) in enumerate(list_original):
if isinstance(elem, basepart.ListBase):
list_process[idx] = copy.deepcopy(elem)
elif elem is None:
list_process[idx] = basepart.IncludeList(character[idx])
else:
raise basepart.NamingLibException('Check composer input type')
for (elem, characterset) in zip(list_process, (character[0], character[1], character[2])):
# Change str to index
elem.digitize(characterset)
# Check index whether that is out of range
elem.check_element_index(characterset)
# Fill the ingredient
for (idx, elem) in enumerate(list_process):
ingredient[idx] = elem.choice(character[idx])
result_int = 0xac00 + ((ingredient[0] * 21) + ingredient[1]) * 28 + ingredient[2]
result_char = chr(result_int)
self.result = result_char
return result_char