Last active
January 1, 2016 19:58
-
-
Save minacle/8193431 to your computer and use it in GitHub Desktop.
phiori용 한국어 조사 처리 모듈.
This file contains hidden or 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
| #korean.py | |
| # 한국어 조사 처리 모듈. | |
| # 사용을 위해 구성해야 할 것은 없습니다. | |
| # 값을 산출하는 OnTranslate 핸들러가 이미 있을 경우, 의도와는 다르게 동작할 수 있습니다. | |
| # | |
| # 사용 예시: | |
| # 나\=[은,는] 자연\=[을,를] 배운다. | |
| # 손\=[으]로 만지고, 발\=[으]로 밟는다. | |
| # | |
| # 결과: | |
| # 나는 자연을 배운다. | |
| # 손으로 만지고, 발로 밟는다. | |
| # | |
| # -- Minacle (http://minacle.it/) | |
| _hangul_base = 0xac00 | |
| _hangul_length = 0x2ba4 | |
| _hangul_initials_count = 19 | |
| _hangul_medials_count = 21 | |
| _hangul_finals_count = 28 | |
| @handle("OnTranslate") | |
| def _korean_postposition(**_): | |
| o = _["Reference0"] | |
| while True: | |
| l, f, x, y, a = "", "", "", "", "" | |
| i, e = -1, 0 | |
| t = 0 | |
| r = "" | |
| for p, c in enumerate(o): | |
| if not t: | |
| if c == "\\": | |
| i = p | |
| t = 1 | |
| else: | |
| l = c | |
| elif t == 1: | |
| if c == "=": | |
| t = 2 | |
| else: | |
| l = c | |
| t = 0 | |
| elif t == 2: | |
| if c == "[": | |
| t = 3 | |
| x = "" | |
| else: | |
| l = c | |
| t = 0 | |
| elif t == 3: | |
| if c == ",": | |
| t = 4 | |
| y = "" | |
| elif c == "]": | |
| t = 6 | |
| e = p | |
| else: | |
| x += c | |
| elif t == 4: | |
| if c == "]": | |
| t = 6 | |
| e = p | |
| elif c == ",": | |
| t = 5 | |
| else: | |
| y += c | |
| elif t == 5: | |
| if c == "]": | |
| t = 6 | |
| e = p | |
| elif t == 6: | |
| a = c | |
| break | |
| if t == 6: | |
| if not l: | |
| o = o[:i] + r + o[e:] | |
| continue | |
| if ord(l) >= _hangul_base and ord(l) <= _hangul_base + _hangul_length: | |
| f = (ord(l) - _hangul_base) % _hangul_finals_count | |
| if not f: | |
| f = 0 | |
| if x.startswith("으"): | |
| if (x == "으로" and y == "로") or (x == "으" and y == "" and a == "로"): | |
| if f == 8 or f == 0: | |
| r = y | |
| else: | |
| r = x | |
| else: | |
| if f > 0: | |
| r = x | |
| else: | |
| r = y | |
| o = o[:i] + r + o[e + 1:] | |
| else: | |
| break | |
| return o |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment