-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdudgks.py
executable file
Β·84 lines (68 loc) Β· 3.34 KB
/
dudgks.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
Reference
https://github.com/ChalkPE/gksdud
"""
import sys
import re
INITIAL = ['γ±', 'γ²', 'γ΄', 'γ·', 'γΈ', 'γΉ', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
']
MEDIAL = ['γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
‘', 'γ
’', 'γ
£']
FINAL = [None, 'γ±', 'γ²', 'γ³', 'γ΄', 'γ΅', 'γΆ', 'γ·', 'γΉ', 'γΊ', 'γ»', 'γΌ', 'γ½', 'γΎ', 'γΏ', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
']
ZI = ['γ±', 'γ²', 'γ³', 'γ΄', 'γ΅', 'γΆ', 'γ·', 'γΈ', 'γΉ', 'γΊ', 'γ»', 'γΌ', 'γ½', 'γΎ', 'γΏ', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
', 'γ
']
MU = MEDIAL
ALPHABETS = 'qQwWeErRtTyYuUiIoOpPaAsSdDfFgGhHjJkKlLzZxXcCvVbBnNmM'
HANGEUL_JAMOS = 'γ
γ
γ
γ
γ·γΈγ±γ²γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ΄γ΄γ
γ
γΉγΉγ
γ
γ
γ
γ
γ
γ
γ
γ
£γ
£γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
‘γ
‘'
KOR_REGEX = re.compile("([γ±γ²γ΄γ·-γΉγ
-γ
γ
-γ
])([γ
-γ
γ
γ
γ
£]|γ
[γ
γ
γ
£]?|γ
[γ
γ
γ
£]?|γ
‘γ
£?)(?:([γ²γ·γ
γ
-γ
γ
-γ
]|γ±γ
?|γ΄[γ
γ
]?|γΉ[γ±γ
γ
γ
γ
-γ
]?|γ
γ
?)(?![γ
-γ
£]))?")
COMPLEX = { 'γ
γ
': 'γ
', 'γ
γ
': 'γ
', 'γ
γ
£': 'γ
', 'γ
γ
': 'γ
', 'γ
γ
': 'γ
', 'γ
γ
£': 'γ
', 'γ
‘γ
£': 'γ
’', 'γ±γ
': 'γ³', 'γ΄γ
': 'γ΅', 'γ΄γ
': 'γΆ', 'γΉγ±': 'γΊ', 'γΉγ
': 'γ»', 'γΉγ
': 'γΌ', 'γΉγ
': 'γ½', 'γΉγ
': 'γΎ', 'γΉγ
': 'γΏ', 'γΉγ
': 'γ
', 'γ
γ
': 'γ
' }
def combine(chars):
"""
["γ
", "γ
", "γ΄"] => "ν"
["γ±", "γ
‘", "γΉ"] => "κΈ"
"""
if chars[1] in COMPLEX:
chars[1] = COMPLEX[chars[1]]
if chars[2] in COMPLEX:
chars[2] = COMPLEX[chars[2]]
return chr(INITIAL.index(chars[0]) * 588 + MEDIAL.index(chars[1]) * 28 + FINAL.index(chars[2]) + 44032)
def split_gks(gks):
"""
κ° -> ['γ±', 'γ
']
κΉ -> ['γ±', 'γ
£', 'γ
']
ν -> ['γ
', 'γ
', 'γ΄']
"""
if 'κ°' > gks or gks > 'ν£':
raise Exception("split_gks() got wrong parameter {}".format(gks))
## 588κ° λ§λ€ μ΄μ±μ΄ λ°λ.
ch1 = (ord(gks) - ord('κ°')) // 588
## μ€μ±μ μ΄ 28κ°μ§ μ’
λ₯
ch2 = ((ord(gks) - ord('κ°')) - (588 * ch1)) // 28
ch3 = (ord(gks) - ord('κ°')) - (588 * ch1) - 28 * ch2
return [INITIAL[ch1], MEDIAL[ch2], FINAL[ch3]]
def dudgks(dud):
"""
dudgks -> μν
"""
cracked_korean = ""
for _dud in dud:
# dudgks -> γ
γ
γ
γ
γ
γ΄
if _dud not in ALPHABETS:
continue
cracked_korean += HANGEUL_JAMOS[ALPHABETS.index(_dud)]
divided_koreans = KOR_REGEX.findall(cracked_korean)
ret = ""
for divided_korean in divided_koreans:
ret += combine([None if d == '' else d for d in divided_korean])
if ret == "":
return cracked_korean
return ret
if len(sys.argv) == 2:
ret = ""
param = sys.argv[1].strip()
if param[0] == "\"":
param = param[1:]
non_alphabetic_regex = re.compile("[^a-zA-Z]")
non_alphabetics = non_alphabetic_regex.findall(param)
non_alphabetics.append("")
alphabetic_groups = non_alphabetic_regex.split(param)
for idx in range(len(alphabetic_groups)):
ret += dudgks(alphabetic_groups[idx]) + non_alphabetics[idx]
print(ret)