-
-
Save j-min/9c148f1dbb15f24a8e96fd2f93ad1459 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
class Hangul: | |
BASE_CODE = 44032 | |
CHOSUNG = 588 | |
JUNGSUNG = 28 | |
# 초성 리스트. 00 ~ 18 | |
CHOSUNG_LIST = [ | |
'ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ', | |
'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'] | |
# 중성 리스트. 00 ~ 20 | |
JUNGSUNG_LIST = [ | |
'ㅏ', 'ㅐ', 'ㅑ', 'ㅒ', 'ㅓ', 'ㅔ', 'ㅕ', 'ㅖ', 'ㅗ', 'ㅘ', 'ㅙ', | |
'ㅚ', 'ㅛ', 'ㅜ', 'ㅝ', 'ㅞ', 'ㅟ', 'ㅠ', 'ㅡ', 'ㅢ', 'ㅣ'] | |
# 종성 리스트. 00 ~ 27 + 1(1개 없음) | |
JONGSUNG_LIST = [ | |
None, 'ㄱ', 'ㄲ', 'ㄳ', 'ㄴ', 'ㄵ', 'ㄶ', 'ㄷ', 'ㄹ', 'ㄺ', 'ㄻ', 'ㄼ', | |
'ㄽ', 'ㄾ', 'ㄿ', 'ㅀ', 'ㅁ', 'ㅂ', 'ㅄ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅊ', | |
'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'] | |
def split(self, ch): | |
base_code = ord(ch) - self.BASE_CODE | |
c1 = base_code // self.CHOSUNG | |
c2 = (base_code - (self.CHOSUNG * c1)) // self.JUNGSUNG | |
c3 = (base_code - (self.CHOSUNG * c1) - (self.JUNGSUNG * c2)) | |
try: | |
return (self.CHOSUNG_LIST[c1], self.JUNGSUNG_LIST[c2], self.JONGSUNG_LIST[c3]) | |
except IndexError: | |
return (None, None, None) | |
hangul = Hangul() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment