Skip to content

Instantly share code, notes, and snippets.

@j-min

j-min/hangul.py

Forked from allieus/hangul.py
Created Dec 20, 2016
Embed
What would you like to do?
# -*- 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
You can’t perform that action at this time.