Improve Korean understanding at every speech level and long talks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 07:36:03 +09:00
co-authored by Claude Opus 5.5
parent 284638a22d
commit 1411676269
13 changed files with 1006 additions and 71 deletions
+40 -2
View File
@@ -343,6 +343,36 @@ NOT_LATER = re.compile(r"[\s,;]*\b(?:and |but |so )?(?:not|no) (?:later(?! than)
# "go to the stage, right now, not later", "지금 가, 나중 말고": said to mean now; the later-time guards must not see it
POLITE_FRAME = re.compile( # a polite frame around a request: "wave, if you don't mind", "I'd love it if you could wave"
r"[\s,]*\bif you (?:don'?t|do not|wouldn'?t|would not) mind\b[\s,]*(?=[.!?]*$)|"
r"^\W*if you (?:don'?t|do not|wouldn'?t|would not) mind\b[\s,]*|[\s,]*\bif you please\b|"
r"\b(?:i'?d|i would|we'?d|we would) (?:really )?(?:love|like|appreciate) it if you(?: could| would| can|(?!\s+\w+ed\b))\b|"
r"\b(?:it'?d|it would|that would|that'?d|it'?ll|it will) be (?:really |so |very )?(?:great|nice|good|lovely|awesome|cool|"
r"helpful|wonderful|amazing|fantastic) if you(?: could| would| can|(?!\s+\w+ed\b))\b|"
r"\bit would help (?:me |us )?(?:a lot )?if you(?: could| would)?\b", re.I)
def _base_verb(w):
"""'waved' -> 'wave', 'stopped' -> 'stop', 'turned' -> 'turn'."""
if w.endswith("ed") and len(w) > 4:
if w[-3] == "e" or w[-3] in "cvsz" and w[-4] not in "aeiou" or w.endswith(("aved", "oved", "ived")):
return w[:-1]
return w[:-3] if w[-3] == w[-4] else w[:-2]
return w
def polite(t):
"""The words without an English polite frame (POLITE_FRAME): "wave, if you don't mind" -> "wave", "I'd love it
if you could wave" -> "please wave", "I'd love it if you waved at us" -> "please wave at us". Korean frames are
ko_plain's."""
t = re.sub(r"\b((?:love|like|appreciate) it|be (?:really |so |very )?(?:great|nice|good|lovely|awesome|cool|helpful|"
r"wonderful|amazing|fantastic)) if you (\w+ed)\b", lambda m: f"{m.group(1)} if you could {_base_verb(m.group(2))}",
t or "", flags=re.I)
out = POLITE_FRAME.sub(lambda m: " please " if re.search(r"\bif you(?: could| would| can)?$", m.group(0), re.I) and
not re.search(r"mind|please", m.group(0), re.I) else " ", t or "")
return re.sub(r"\s{2,}", " ", out).strip(" ,") or (t or "")
def now_not_later(t):
"""The words without "not later" / "나중 말고" (NOT_LATER)."""
return re.sub(r"\s{2,}", " ", NOT_LATER.sub(" ", t or "")).strip() or (t or "")
@@ -393,6 +423,11 @@ KO_PLAIN = [
(re.compile(r"(?<![가-힣])(\S*(?:돌아오|따라오|다가오|가져오|이리 오|일로 오))게" + _END), lambda m: aform(m.group(1))),
# 하게체: "돌아오게", "이리 오게"
(re.compile(r"(\S+) ?주셨으면 (?:해요|합니다|좋겠(?:어요|습니다|네요))" + _END), r"\1 줘"), # "내려가 주셨으면 해요"
(re.compile(r"(\S+) ?주(?:시|)(?:길|기를|기) (?:부탁(?: 좀)? ?(?:드립니다|드려요|드릴게요|합니다|해요|드리겠습니다)|바랍니다|바래요|바라요)"
+ _END), r"\1 줘"), # "가 주시길 부탁드립니다"
(re.compile(r"(?<=[가-힣]) (?:줍서|줍써|주십서|주십써|주게마씸|줍소)" + _END), " 줘"), # 제주 / 경상: "가 줍서"
(re.compile(r"(\d+(?:\.\d+)?\s*(?:도|미터|센티(?:미터)?|센치|cm|m)(?![가-힣a-z]))\s+(?:좀|쫌|한번|한 번)\s+(?=[가-힣])"), r"\1 "),
# "45도 좀 돌아 줘": the amount, then the verb
(re.compile(r"(?<= )조(?:잉)?(?=\s*(?:[,.!?~…]|$))"), "줘"), # "흔들어 조잉", "손 한번 조"
(re.compile(r"악수 ?(?:한 ?번)? ?(?:할까요?|하실래요?|합시다|하십시다|하자잉|허자잉?|하입시더)"), "악수하자"), # shake hands = wave
(re.compile(r"(?<=[가-힣](?:라|자)) 마(?=\s*(?:[,.!?~…]|$))"), ""), # 경상: "팔 접어 봐라 마"
@@ -414,9 +449,10 @@ KO_PLAIN = [
(re.compile(r"(?<![가-힣])(\S*?[가-힣])(?:으)?면 (?:돼요?|됩니다)" + _END_NOT_ASKED), "STEM"), # "날 따라오면 돼"
(re.compile(r"(?<![가-힣])(\S*[가-힣])\s?(?:줄래요?|줄 수 (?:있어요?|있니|있나요|있습니까)|주실 수 (?:있어요|있나요|있습니까|있으세요)|"
r"주시겠어요|주시겠습니까|주실래요)" + _END), r"\1 줘"),
(re.compile(r"(?<![가-힣])(\S*?[가-힣])(?:으)?" + _HON + _END), "STEM"), # 가세요, 따라오십시오, 보이소, 집으세요
(re.compile(r"(?<![가-힣])(\S*[가-힣])(?: 수 (?:있을까요?|있겠(?:어요|니|습니까)|있으실까요|있으시겠어요))\s*\??" + _END),
(re.compile(r"(?<![가-힣])(\S*[가-힣])(?: 수 (?:있을까요?|있겠(?:어요|니|습니까)|있으실까요|있으시겠어요|있으세요|있으신가요|"
r"있으십니까|있으시겠습니까))\s*\??" + _END),
"CAN_L"), # "갈 수 있을까요?": please go
(re.compile(r"(?<![가-힣])(\S*?[가-힣])(?:으)?" + _HON + _END), "STEM"), # 가세요, 따라오십시오, 보이소, 집으세요
(re.compile(r"(?<![가-힣])(\S*[가-힣]) 거 (?:돼요|되나요|될까요|가능해요|가능할까요|가능합니까|가능하세요)\s*\??" + _END),
"CAN_N"), # "가는 거 돼요?"
(re.compile(r"(?<![가-힣])(\S*(?:해|가|와|봐|줘|돌아|어|아|려|워|쳐|져|켜|꺼|둬|놔|펴|서|내))(?:요|라|유|부러|불어|뿌러|뿌라|삐라|잉|용)" + _END),
@@ -450,6 +486,8 @@ def _can_you(m, kind):
stem = {"도": "돌", "드": "들", "여": "열", "흔드": "흔들", "내미": "내밀"}.get(stem, stem)
if not stem or stem in KO_SOCIAL:
return m.group(0)
if stem in ("주", "주시"):
return "줘?" # "가 줄 수 있을까요?": the 줘 is said already
return aform(stem) + " 줘?"