#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, sys
import re
import time
from hanguldict import hangul2jamos
clusters = u"ㄳㄵㄶㄺㄻㄼㄽㄾㄿㅀㅄ"
diphtongues = u"ㅘㅙㅚㅝㅞㅟㅢ"
diphtongues_merge = {
u"ㅗㅏ": u"ㅘ",
u"ㅗㅐ": u"ㅙ",
u"ㅗㅣ": u"ㅚ",
u"ㅜㅓ": u"ㅝ",
u"ㅜㅔ": u"ㅞ",
u"ㅜㅣ": u"ㅟ",
u"ㅡㅣ": u"ㅢ"}
clusters_merge = {
u"ㄱㅅ": u"ㄳ",
u"ㄴㅈ": u"ㄵ",
u"ㄴㅎ": u"ㄶ",
u"ㄹㄱ": u"ㄺ",
u"ㄹㅁ": u"ㄻ",
u"ㄹㅂ": u"ㄼ",
u"ㄹㅅ": u"ㄽ",
u"ㄹㅌ": u"ㄾ",
u"ㄹㅍ": u"ㄿ",
u"ㄹㅎ": u"ㅀ",
u"ㅂㅅ": u"ㅄ"
}
consonnes = u"ㄱㄴㄷㄹㅁㅂㅅㅇㅈㅊㅋㅌㅍㅎ"
voyelles = u"ㅏㅑㅓㅕㅗㅛㅜㅠㅡㅣㅐㅒㅔㅖ"
def mk_jamos (caractere):
tuple = hangul2jamos
if len (tuple) < 3:
return tuple + ("",)*(3-len(tuple))
tuple = list (tuple)
tuple.reverse ()
ini = u""
voy = u""
fin = u""
ini += tuple.pop ()
voy += tuple.pop ()
j = tuple.pop ()
if j in voyelles: voy += j
else: fin += j
if len (tuple):
j = tuple.pop ()
if j in voyelles: voy += j
else: fin += j
if len (tuple):
j = tuple.pop ()
if j in voyelles: voy += j
else: fin += j
if len (voy) > 1:
voy = diphtongues_merge
if len (fin) > 1:
fin = clusters_merge
return (ini, voy, fin)
if __name__ == "__main__":
for i in hangul2jamos:
try:
a = "".join (mk_jamos (i))
print u"%s → %s"% (i, a)
except: print "ERROR: ", i