Improve command, cup task and talk understanding in English and Korean

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 15:30:06 +09:00
co-authored by Claude Opus 5.5
parent e3a1c123c9
commit e3fcfd30ab
23 changed files with 1380 additions and 167 deletions
+26 -1
View File
@@ -211,6 +211,17 @@ _BANK = {
("What's the capital of Australia?", "none", "Canberra, not Sydney."),
("Who's the president of France right now?", "search", "Let me check."),
("What's the score of today's Dodgers game?", "search", "Let me check."),
("how fast can a cheetah run?", "none", "Up to about 110 km/h, in short sprints."),
("Why so fast?", "none", "A light body, a very bendy spine and long legs make each stride huge."),
("A giraffe neck, how many bones it has?", "none", "Seven, the same as ours; each bone is just very long."),
("How long does a baby kangaroo stay in the pouch?", "none", "About six to eight months, then it hops out."),
("how much does a sloth sleep, like per day?", "none", "About 15 hours a day in the wild."),
("Namsan tower height is how much?", "none", "N Seoul Tower is about 236 metres; on the mountain top about 480 metres above the sea."),
("How quickly does a sunflower grow?", "none", "In good sun up to a few centimetres a day; it reaches two to three metres in a summer."),
("Can elephants really not jump?", "none", "Yes, they can't: their legs are built to carry weight, and one foot always stays on the ground."),
("Oh right, what's a hanok?", "none", "A traditional Korean house, with a tiled or thatched roof and floor heating."),
("Wait, what's the coldest place on Earth?", "none", "Antarctica; near Vostok station it once fell to about minus 89 °C."),
("What's the newest iPhone?", "search", "Let me check."),
],
"ko": [
("사람이 달에 처음 간 게 언제야?", "none", "1969년 7월, 아폴로 11호 때예요."),
@@ -230,7 +241,21 @@ _BANK = {
("에펠탑은 언제 세워지셨는지 여쭤봐도 될까요?", "none", "1889년 파리 만국박람회 때 완공됐어요."),
("호주 수도가 어디게?", "none", "캔버라예요. 시드니가 아니에요."),
("지금 프랑스 대통령 누구야?", "search", "확인해 볼게요."),
("오늘 야구 결과 어떻게 됐어요?", "search", "확인해 볼게요."),
("오늘 야구 몇 대 몇으로 끝났어요?", "search", "확인해 볼게요."),
("된장은 어떻게 만듭니까?", "none", "삶은 콩으로 메주를 쑤어 띄운 뒤 소금물에 담가 숙성시키고, 건더기를 건져 만듭니다."),
("김치 맛을 시게 만드는 건 뭐임?", "none", "유산균이에요. 익으면서 젖산을 만들어서 신맛이 나요."),
("치타는 을매나 빨리 뛰노?", "none", "짧게는 시속 110킬로미터쯤까지 달려요."),
("기린 목뼈 그거 몇 개야?", "none", "일곱 개예요. 사람이랑 같은데 하나하나가 아주 길어요."),
("캥거루 새끼는 주머니에 얼마나 있습니까?", "none", "약 6개월에서 8개월 동안 주머니에서 지냅니다."),
("나무늘보는 하루에 얼마나 자요?", "none", "야생에서는 하루에 15시간쯤 자요."),
("남산타워 height 몇 m예요?", "none", "N서울타워는 약 236미터이고, 산 위라서 해발로는 480미터쯤이에요."),
("해바라기는 얼마나 빨리 커?", "none", "햇빛이 좋으면 하루에 몇 센티미터씩, 여름 한철에 2~3미터까지 자라요."),
("코끼리가 점프를 못 한다는 게 참말이가?", "none", "네, 맞아요. 다리가 무게를 받치게 생겨서 항상 한 발은 땅에 있어요."),
("고래는 숨을 얼마나 참으실 수 있는지 여쭤봐도 될까요?", "none", "향유고래는 한 시간 넘게도 참을 수 있어요."),
("아 맞다, 판소리가 뭐야?", "none", "북 장단에 맞춰 한 사람이 노래와 말로 긴 이야기를 들려주는 우리 전통 음악이에요."),
("잠깐, 세상에서 제일 긴 강은?", "none", "나일강이에요. 약 6,650킬로미터예요."),
("그건 그렇고 정확히 몇 킬로?", "none", "약 6,650킬로미터예요. 아마존강과 비슷해서 재는 방법에 따라 달라요."),
("요즘 나온 갤럭시 최신 모델 뭐야?", "search", "확인해 볼게요."),
],
},
}
+47
View File
@@ -0,0 +1,47 @@
"""Cup-task wordings for the intent bank (F1, night 4): fetch from a place said in every way ("the cup on p2",
"p2에 있는 컵", "피원 컵을", "move the cup from A to B", "옮겨"), at every Korean level; and "no": the same words
reported, asked about, put off or taken back (nothing moves). The words decide the fields (brain.parse_fetch)."""
_KO_FETCH = ["<place>에 있는 <obj> 가져와", "<place>에 있는 <obj> 좀 갖다 줘", "<place>에 놓인 <obj> 가져와",
"<place> <obj> 가져와", "<place>의 <obj> 가져다 줘", "<place> 위에 있는 <obj> 가져와",
"<place>에서 <obj> 집어서 가져와", "<place>에서 <obj> 들고 와", "<place>에 있는 <obj>을 여기로 가져와",
"<place>에서 <obj> 좀 챙겨 와", "<place>에 있는 <obj> 옮겨 와"]
_KO_END = [("가져와", ["가져와", "가져와요", "가져오세요", "가져오십시오", "가져와 주세요", "가져와 주시겠어요?",
"가져와 주시겠습니까?", "가져와 줄래?", "가져오게", "가져와 주게나", "가져온나", "가져와유",
"가져와 주이소", "가져와 주실 수 있으신가요?", "가져와 주시면 감사하겠습니다"]),
("갖다 줘", ["갖다 줘", "갖다 주세요", "갖다 주십시오", "갖다 주실래요?", "갖다 주게", "갖다 줘유",
"갖다 주이소", "갖다 주시겠어요?", "갖다 드려 주세요"]),
("가져다 줘", ["가져다 줘", "가져다 주세요", "가져다 주십시오", "가져다 주시겠습니까?", "가져다 주게나"]),
("들고 와", ["들고 와", "들고 와요", "들고 오세요", "들고 오십시오"]),
("챙겨 와", ["챙겨 와", "챙겨 와요", "챙겨 오세요"]),
("옮겨 와", ["옮겨 와", "옮겨 와 주세요", "옮겨 오십시오"])]
_EN_FETCH = ["bring me the <obj> on <place>", "get me the <obj> that's on <place>", "fetch the <obj> sitting at <place>",
"grab the <obj> at <place> and bring it here", "bring the <obj> over from <place>",
"<place> <obj>, bring it to me", "go to <place>, get the <obj> and bring it back to me",
"pick up the <obj> at <place> and bring it to me", "the <obj> on <place>, could you fetch it",
"move the <obj> from <place> over here", "carry the <obj> from <place> to me"]
_EN_FRAME = ["{}", "please {}", "could you {}", "would you mind, {}", "can you {} for me", "{} please", "lumi, {}",
"hey robot, {}", "excuse me, {}", "i need you to {}", "{} real quick", "do me a favour and {}"]
_NO = ["did you bring the <obj> from <place>?", "you brought the <obj> from <place> yesterday", "can you bring cups at all?",
"don't bring the <obj> from <place>", "i'll bring the <obj> from <place> myself", "tomorrow bring the <obj>",
"maybe later you can bring the <obj> from <place>", "my friend brought the <obj> from <place>",
"she asked whether you can fetch things", "bring me the <obj> from <place>, no wait, never mind",
"<place>에서 <obj> 가져왔어?", "어제 <obj> 가져왔지?", "<place>에서 <obj> 가져오지 마", "내가 <obj> 가져올게",
"나중에 <obj> 가져와 줘", "<obj> 가져올 수 있어?", "친구가 <place>에서 <obj> 가져왔대", "<obj> 가져오는 거 봤어",
"<place>에서 <obj> 가져와, 아 아니다 됐어", "<obj> 가져오시면 안 됩니다", "<obj> 가져다 주실 필요 없어요",
"할머니가 <obj> 가져오라고 하셨는데 괜찮아", "<obj> 가져오는 건 내일 해", "<place>에서 <obj> 가져다 줄 수 있나 궁금하네"]
def _ko():
"""Each wording with the endings of every level for its verb."""
out = []
for base in _KO_FETCH:
for verb, ends in _KO_END:
if base.endswith(verb):
out += [f"{base[:-len(verb)].rstrip()} {e}" for e in ends]
return out
INTENT = {"fetch": sorted(set(_ko() + [f.format(c) for c in _EN_FETCH for f in _EN_FRAME])), "no": _NO}
+24
View File
@@ -227,3 +227,27 @@ QUICK["no"] = QUICK.get("no", []) + [
"시간 괜찮아요", "시간 돼요", "give me a second", "give me a minute", "give me some time", "do you have time",
"이름 지어 줄까", "내 이름은 민수야", "제 이름 기억해요", "우리 애 몇 살 같아요", "제가 몇 살 같아요", "나 몇 살로 보여",
"누가 이겼어", "누가 더 빨라", "몇 시에 끝나요", "몇 시에 시작해요"]
# ---------- night 4: Konglish verbs and short dialect forms ko_plain does not turn into the plain verb ----------
INTENT["pick"] += _v(["<obj> 그랩 해", "<obj> 그랩", "<obj> 픽 해", "<obj> 픽업해", "<obj> 캐치 해", "<obj> 홀드 해",
"<obj> 잡아 봐라", "<obj> 집어 도", "<obj> 쫌 집어"], ("", " 줘"))
INTENT["fetch"] += _v(["<obj> 겟 해 와", "<obj> 겟해 와", "<obj> 브링 해", "<obj> 가져와 봐라", "<obj> 갖고 온나",
"<obj> 퍼뜩 가져와", "<obj> 쫌 갖다 도", "나한테 <obj> 브링"], ("", " 줘"))
INTENT["follow"] += _v(["팔로우 해", "나 팔로우", "날 팔로우", "come with 나", "나랑 같이 가", "같이 가자 루미",
"내 뒤로 붙어", "졸졸 따라 댕겨", "따라 온나"], ("", " 줘"))
INTENT["come"] += _v(["컴 히어", "컴온 히어", "이리로 컴", "여기로 컴", "가까이 컴", "이리 온나", "일로 온나", "이리 오이라"],
("", " 해", " 해 줘"))
INTENT["wave"] += _v(["웨이브 해", "하이 해", "바이바이 해", "빠이빠이 해", "손 인사 해", "손으로 인사 해", "핸드 웨이브 해",
"손 흔들어 봐라", "손 쫌 흔들어"], ("", " 줘", " 봐"))
INTENT["arm_reach"] += _v(["손 줘라", "핸드 줘", "암 내밀어", "핸드 아웃 해", "손 쭉 내밀어 봐라", "팔 뻗어 봐라",
"손 이리 도", "손 쫌 도"], ("", " 줘"))
INTENT["arm_fold"] += _v(["암 다운 해", "암 폴드 해", "arm fold 해", "팔 원위치 해", "팔 집어넣어", "손 거둬 들여",
"팔 접어 봐라"], ("", " 줘"))
INTENT["look"] += _v(["룩 업 해", "룩 다운 해", "업 봐", "다운 봐", "레프트 봐", "라이트 봐", "위로 룩", "아래로 룩",
"고개 쫌 들어", "고개 쫌 숙여", "고개 들어 봐라", "고개 숙여 봐라"], ("", " 줘"))
INTENT["lift"] += _v(["바디 업", "바디 다운", "키 업", "키 다운", "몸 업", "몸 다운", "몸 쫌 올려", "몸 쫌 내려",
"키 쫌 키워", "키 쫌 줄여"], ("", " 해", " 해 줘"))
INTENT["turn"] += _v(["턴 해", "레프트 턴", "라이트 턴", "라이트로 턴", "레프트로 턴", "백 턴", "유턴 쫌", "한 바퀴 턴",
"왼쪽으로 돌아 봐라", "오른쪽으로 돌아 봐라"], ("", " 해", " 해 줘"))
INTENT["move"] += _v(["무브 포워드", "고 백", "백 해", "앞으로 무브", "뒤로 무브", "레프트로 무브", "라이트로 무브",
"앞으로 쪼매 가 봐라", "뒤로 쫌 빠져"], ("", " 줘"))
+363 -82
View File
File diff suppressed because it is too large Load Diff
+39 -1
View File
@@ -29,13 +29,15 @@ FETCHING = re.compile(r"\b(?:bring|fetch|deliver|carry)\b|가져|갖다", re.I)
_FILL = re.compile(rf"(?:{steps._FILL}|루미야?|lumi|hey|do me a favou?r|부탁(?:해|해요|할게)?|dear|sir|ma'?am|madam|buddy|"
r"my friend|robot|로봇아?|선생님?|yo|bro|dude|okay lumi|ok lumi|robot please|루미 ?씨|로봇 양반|여보세요|"
r"go ahead|okay\?|ok\?|right\?|thanks|thank you|yes|yeah|yep|yes\?|네|응|그래|will ya|will you|won'?t you|"
r"can\?|can|do it|do it now|just do it|alright\?|please\?|혹시|아 뭐라 그래야 되지|뭐라 그래야 되지|뭐더라|"
r"can\?|can|do it|do it now|just do it|alright\?|please\?|over here\??|this way\??|어디 ?한번|어디 ?보자|얼마나 걸리나|(?:pls |please )?(?:eh|huh|da|see|ya|yah|innit)\??|혹시|아 뭐라 그래야 되지|뭐라 그래야 되지|뭐더라|"
r"(?:아\s*)?영어로 ?뭐더라|(?:아\s*)?뭐라고 ?하지|"
r"(?:거기서?\s*)?(?:서|가만히)\s*있(?:어|게|으세요|으십시오)\s*(?:줄래|줄 ?수 ?있어요?|주실래요|주세요|줘|줘잉|주라|"
r"주면 ?안 ?될까요?|주면 ?좋겠어요?|주실 ?수 ?있어요?|주십시오|주이소)?|"
r"(?:거기서?\s*)?기다려\s*(?:줄래|주세요|줘)?)", re.I) # tags, hesitations, "...가서 서 있어 줄래?"
RELATIVE = re.compile(r"^\W*(?:where|which|who|that|when)\s+(?:the|my|your|his|her|our|their|a|an|this|that|these|those|"
r"people|everyone|it|he|she|they|we|i)\b", re.I) # "look right, where the door is": no question
SPEED_Q = re.compile(r"속도|몇으로|얼마나 (?:빨리|빠르게|천천히)|\bhow (?:fast|quick(?:ly)?|slow(?:ly)?)\b|\bwhat speed\b", re.I)
GREET = re.compile(r"인사|작별|\b(?:hello|hi|goodbye|bye)\b", re.I) # a greeting made by waving
PAST = re.compile(r"\byou (?:got|went|were|did|turned|looked|moved|came|said|told)\b|\b(?:earlier|before|yesterday)\b", re.I)
BANK_KINDS = {"look", "lift", "turn", "move", "come", "come_back", "follow", "wave", "arm", "go_to"} # a part the
# keyword rules miss, read by the intent bank (same slot rules)
@@ -43,6 +45,22 @@ CHAIN_ONLY = {"look", "lift", "wave", "come", "come_back", "follow"} # a part
# a sentence the mission reader reads whole is still a chain
BACKGROUND = re.compile(r"[가-힣](?:는|은|인|던)(?:데|디)(?:요)?\W*$") # "…말하는데," a clause that only sets the scene
SELF_PROMISE = re.compile(r"(?:^|\W)(?:i'?ll|i will|let me|i'?m going to|i can) (?:hold|take|keep|get|catch|grab) (?:it|that|this|them)\W*$|"
r"(?:^|\W)(?:내가|제가) (?:들|받|잡)(?:게|을게|을게요|게요|을께)\W*$", re.I) # the speaker's part
def _restated(words, before):
"""A Korean part that says the order before it again in another level ("손 거둬!", "아 거두시겠어요?")."""
from assistant import wording
said = [w for w in re.findall(r"\w+", wording.ko_plain(words)) if not re.fullmatch(r"(?:줘|봐|주|좀|요)[가-힣]?|허허|하하|호호|헤헤|아|어", w)]
if not said or len(said) > 3 or not re.fullmatch(r"[가-힣]{2,}|[가와]", said[-1]):
return False
last = said[-1]
return any(last == w or len(w) > 1 and (w.startswith(last) or last.startswith(w))
for w in re.findall(r"\w+", wording.ko_plain(before)) if re.fullmatch(r"[가-힣]+", w))
def _rule(words, markers):
"""brain.intent of a part, also of a Korean -고 form ("나 보고" read as "나 봐")."""
rule = brain.intent(words, markers)
@@ -57,6 +75,8 @@ def _rule(words, markers):
from assistant import intent_bank # "glance to your right", "고개 숙이고": the bank, by meaning
got = intent_bank.read(ko, markers)
rule = got if got and got[0] in BANK_KINDS else None
if rule and rule[0] == "come_back" and re.fullmatch(r"\W*(?:루미야?\s*)?(?:원래 ?자리|제자리)(?:에|로)?\W*", words):
rule = None # "제자리에, 손 내밀어": "ready", no drive back
return rule
@@ -69,6 +89,9 @@ def parts(text):
for p in _SPLIT.split(cut):
out += [q for q in steps._SPLIT_KO.split(p) if q.strip()]
out = [re.sub(r"§(\d+)§", lambda m: f'"{says[int(m.group(1))]}"', p).strip(" ,.!") for p in out]
for i in range(len(out) - 1, 0, -1): # "뒤로 물러서 줘": 서 is the verb's, 줘 no part of its own
if re.fullmatch(r"(?:줘|줘요|주세요|주십시오|줄래요?\??|주실래요?\??|주라|주게|주이소|봐|봐요|보세요)\W*", out[i]):
out[i - 1] += " " + out.pop(i)
return [p for p in out if p and not re.fullmatch(rf"(?:{_FILL.pattern}|\W)+", p, re.I)]
@@ -90,6 +113,8 @@ def plan(text, markers=(), cant=None):
return None # "turn around and look": the head looks behind
out = []
for p in ps:
if SELF_PROMISE.search(p) or out and _restated(p, out[-1][1]) or brain.GREET_ONLY.match(p): # "hello robot, …"
continue # "흰색 머그컵 잡아!, 아 잡아 줄 수 있어요?": the order once
got, unread = steps.rules(p, markers)
rule = _rule(p, markers)
if got and not unread and not (rule and rule[0] in ("look", "lift", "wave", "come", "come_back", "follow")):
@@ -100,6 +125,13 @@ def plan(text, markers=(), cant=None):
out.append(["quick", p, rule])
elif RELATIVE.search(p):
return None # a part that tells more about the one before
elif BACKGROUND.search(p):
continue # "이장이 말하는디, 팔 제자리로 해", "I'll hold it, give it here"
elif out and out[-1][0] in ("quick", "steps") and _restated(p, out[-1][1]):
continue # "손 거둬!, 아 거두시겠어요?": the same order again, politely
elif out and out[-1][0] == "quick" and out[-1][2][0] == "wave" and re.search(r"(?:면서|며|서)\W*$", out[-1][1]) and \
GREET.search(p) and not rule:
continue # "손 흔들면서 인사하고 고개 숙여": the wave is the greeting
elif ASK.search(p) or rule and rule[0] in ("weather", "search") or cant is not None and cant.match(p):
out.append(["talk", p, None])
else:
@@ -112,6 +144,12 @@ def plan(text, markers=(), cant=None):
said[i] and said[i] == said[i - 1]))]
if len(out) < 2:
return None # "wave, wave, wave!": one wave, said with feeling
if any(k == "talk" and SPEED_Q.search(p) and i and re.search(r"고$|\b(?:holding|carrying|with)\b", out[i - 1][1], re.I)
for i, (k, p, _) in enumerate(out)):
return None # "컵 들고 몇으로 가?": how fast it goes so, no order
if any(k == "quick" and w[0] == "wave" and re.search(r"(?<!가)서$", p) and i + 1 < len(out) and
GREET.search(out[i + 1][1]) for i, (k, p, w) in enumerate(out)):
return None # "손 흔들어서 작별 인사 해 줘": the wave is the greeting
kinds = [k for k, _, _ in out]
if "talk" not in kinds and "quick" not in kinds or "steps" not in kinds and "quick" not in kinds:
return None # all steps: a mission (read back); all talk: the LLM
+4
View File
@@ -113,6 +113,10 @@ def read(text, markers=(), goal=None):
ends = [m.end() for r in (_BACK_UP_RE, _AROUND, _BACK, _RETRY) for m in r.finditer(t)]
if not ends or _NOT_ORDER.search(t):
return None
if brain.to_someone_else(text) or brain.held_back(re.sub(r"(?:포기하|멈추|그만두)지 ?마\w*|\bdon.?t (?:give up|stop)\b", " ", text)) or brain.ARM_TALK.search(text) or \
re.search(r"(?:라고|자고|하라고|가라고) ?(?:했|하더|그러)|(?:나|니|까|냐|어)\s+(?![루누]미|로봇)[가-힣]{2}(?:아|야)\s*\?\s*$|봤(?:냐|니|어요?|나요)\s*\?|(?<![가-힣])아까(?![가-힣])|\b(?:also|too)\W*$", text):
return None # "아까 저 아저씨가 다시 가라고 했어", "재시도해부러" said after "-믄", "Maria, you go back",
# "다른 길 있나 민수야?" (asked to Minsu), "여러분, 돌아와 보세요"
if _TAKEN_BACK.search(t, max(ends)) or _FIXED.search(t, max(ends)):
return None # "try again. never mind", "go around— no, not need"
fixed = list(_FIXED.finditer(t))
+10 -6
View File
@@ -24,13 +24,13 @@ SPAN_M = 0.2 # m; "한 뼘", one hand span; estimate
STEP_M = 0.5 # m; one step ("two steps", "한 걸음", "반 걸음"); estimate of a person's step
TURN_MORE_DEG = 15.0 # deg; "a bit more" right after a turn: this much further the same way
DIRS = (("back", r"\bback(?:wards?)?\b(?! down\b)|\bbackward\b|\breverse\b|^(?:let'?s )?(?:bake|big)\b(?= \d| half| a )|뒤로|뒤쪽|후진|"
DIRS = (("back", r"\bback(?:wards?)?\b(?! down\b)|\bbackward\b|\breverse\b|\bretreat\b|^(?:let'?s )?(?:bake|big)\b(?= \d| half| a )|뒤로|뒤쪽|후진|"
r"물러"), # whisper's "let's bake / big one meter"
("forward", r"\bforwards?\b|\bahead\b|앞으로|앞쪽|전진"),
("left", r"\b(?:to the |to your )?left\b|왼쪽|왼편|웬쪽|좌측"),
("right", r"(?<!all )\b(?:to the |to your )?right\b(?! now| away| here| there| back)|오른쪽|오른편|우측"))
("left", r"\b(?:to the |to your )?left\b|왼 ?쪽|왼편|웬쪽|좌측"),
("right", r"(?<!all )\b(?:to the |to your )?right\b(?! now| away| here| there| back)|오른 ?쪽|오른편|우측"))
VERB = re.compile(r"\b(?:move|go|come|drive|step|scoot|scooch|shift|inch|roll|back (?:up|off)|reverse|get)\b|"
r"가|와|이동|움직|물러|빠져|후진|전진|비켜")
r"(?<![신인는])가|와|이동|움직|물러|빠져|후진|전진|비켜") # not "…있으신가요?"
NEAR_THING = re.compile(r"(?:테이블|책상|탁자|의자|소파|문|벽|창문)\s*(?:앞|옆|뒤)|"
r"(?<![가-힣])(?!(?:루미야?|조금만?|살짝|다시|그냥|이제|저기요?|여기|거기|약간|천천히|빨리|얼른|어서|그럼|근데|"
r"그리고|좀|더|한|두|세|반|쭉|바로|똑바로|계속|한번|한 번|일단|먼저|자|아주|많이|쪼끔|쬐끔|요만큼|뼘|걸음|발짝|발자국|미터|센티|센치|밀리)만?(?:\s|$))(?:[가-힣][가-힣_]{0,9}|(?<![a-z0-9_.])(?!(?:m|cm|mm|lumi|loomi|rumi|hey|ok|okay|please)\b)[a-z][a-z0-9_]*)\s*"
@@ -52,12 +52,13 @@ SPANS = re.compile(rf"(?:(?<![\w.]){_COUNT}\s*)?뼘")
TINY = re.compile(r"\b(?:tiny|teeny|wee|hair|hairs?breadth|smidge|smidgen|tad|touch|nudge|slightly|little tiny)\b|"
r"\bfew (?:centimet(?:er|re)s|cm)\b|\binch (?:forward|back|left|right|ahead)|"
r"살짝|아주 조금|쪼끔|쬐끔|약간|요만큼|조금만 살짝")
LITTLE = re.compile(r"\b(?:a little|a bit|little bit|bit)\b|조금|쪼금") # "좀" is "please" as often as "a bit"
LITTLE = re.compile(r"\b(?:a little|a bit|little bit|bit)\b|조금|쪼금|쪼매|쫌만") # "좀" is "please" as often as "a bit"
VAGUE = re.compile(r"\b(?:more|less|longer|further|farther|bit more|bit less) than\b|(?:^|\s)몇\s*(?:미터|센티|m\b|걸음)|\bsome (?:meters?|metres?)\b|\bto (?:m|meters?|metres?)\b|"
r"\b(?:some|like|uh|um)\s*$|(?<![가-힣])[이삼사오육칠팔구]?[십백][일이삼사오육칠팔구]?\s*(?:만\s*)?"
r"(?:가|와|이동|움직|후진|전진)") # an amount half said: asked, never a guess
NUM_WORD = re.compile(r"\b(?:eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|"
r"thirty|forty|fifty|sixty|seventy|eighty|ninety|hundred|thousand|dozen|couple|several|few|half)\b")
UNIT_WORD = re.compile(r"미터|센티|센치|밀리|(?<![a-z])(?:cm|mm|meters?|metres?|centimet(?:er|re)s?|millimet(?:er|re)s?)(?![a-z])")
KO_NUM_WORD = re.compile(r"(?<![가-힣])(?:하나|둘|셋|넷|다섯|여섯|일곱|여덟|아홉|열|스물|서른|마흔|쉰)(?:만|쯤|정도)?(?![가-힣])")
# "앞으로 다섯만 가": a count with no unit, asked
KO_COUNT = re.compile(KO_NUM_WORD.pattern + r"|(?<![가-힣])[이삼사오육칠팔구]?[십백][일이삼사오육칠팔구]?(?:만|쯤|정도)?(?![가-힣])|"
@@ -122,6 +123,9 @@ def amount(t):
return 0.25, True # "a quarter of a meter"
if VAGUE.search(t):
return "?", False # "more than a meter", "to meters" (two?), "move back some"
m = re.search(r"(?<![\w.])(\d+) ?m ?([1-9]0)(?:만|쯤|정도)?(?![\d.]|\s*(?:m|cm|mm|센|밀|도|times|번)(?![a-z]))", t)
if m:
return int(m.group(1)) + int(m.group(2)) / 100, True # "1미터 50": 1.5 m
m = re.search(r"(?<![\w.])(\d+(?:\.\d+)?) m(?![a-z])", t)
if m:
return float(m.group(1)), True
@@ -135,7 +139,7 @@ def amount(t):
if m and not re.search(r"\b(?:few|couple|several|some)\b", t):
n = m.group(1)
return (float(n) if n and n[0].isdigit() else _NATIVE.get(n, 1)) * unit, False
if re.search(r"(?<![a-z\d.])\d", t) or NUM_WORD.search(t) or KO_NUM_WORD.search(t):
if re.search(r"(?<![a-z\d.])\d", t) or NUM_WORD.search(t) or KO_NUM_WORD.search(t) or UNIT_WORD.search(t):
return "?", False # "move back 20", "two feet", "a couple of metres",
# "오른쪽으로30가게"
if LITTLE.search(t):
+60 -13
View File
@@ -34,18 +34,18 @@ FILLS = 3 # place / object fills made of each template (the same e
# ---------- guards: words the bank never reads ----------
NEGATION = re.compile(r"\b(?:don'?t|do not|never|no need|not now|no more|stop \w+ing|quit \w+ing|without|forget it|"
r"never ?mind|scratch that|cancel that)\b|취소|아니다|됐다|"
r"[가-힣]지 ?마(?:세요|요|라|십시오)?(?![가-힣])|하지 ?말|말고|[가-힣]지 ?(?:말아|말라|마시|마셔|말게)|필요 ?없|안 ?(?:해|돼|가|와)(?:도)?\b|그만", re.I)
r"[가-힣]지 ?마(?:세요|요|라|십시오|쇼|소|이소|시오|셔)?(?:잉|요)?(?![가-힣])|하지 ?말|말고|[가-힣]지 ?(?:말아|말라|마시|마셔|말게)|필요 ?없|안 ?(?:해|돼|가|와)(?:도)?\b|그만", re.I)
LATER = re.compile(r"\b(?:when|whenever|if|unless|after|before|once|until|till|as soon as|later|tomorrow|tonight|"
r"next time|in (?:\w+ ){0,2}(?:minute|hour|second|min|sec)s?|in a (?:while|bit)|soon)\b|분 ?(?:뒤|후|있다)|"
r"next time|some ?day|one day|in (?:\w+ ){0,2}(?:minute|hour|second|min|sec)s?|in a (?:while|bit)|soon)\b|분 ?(?:뒤|후|있다)|"
r"[가-힣](?<![정화측반전표라장내외평단그러])면(?:\s|$)|(?:하|으|오|가|되|끝나|있으|오시)면|나중에|이따|내일|"
r"다음에|있다가|(?:^|\s)(?:후|뒤|전)에(?![서가-힣])|때(?:에)?\s|다음 ?(?:주|달|번|시간)에?|"
r"(?:^|\s)(?:\d{1,2}|한|두|세|네|다섯|여섯|일곱|여덟|아홉|열|열한|열두) ?시(?:에|쯤|까지)|"
r"\b(?:next (?:week|month|year|monday|tuesday|wednesday|thursday|friday|saturday|sunday)|"
r"at (?:\d{1,2}|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)(?::\d\d)? ?(?:o'?clock|pm|am|p\.m\.|a\.m\.))", re.I)
ABILITY = re.compile(r"\b(?:are you able|able to|know how to|how (?:do|can|could|would) you|is it possible|can you even|"
ABILITY = re.compile(r"\b(?:are you able|able to|know how|i heard you can|heard (?:that )?you can|how (?:do|can|could|would) you|is it possible|can you even|"
r"capable of|do you (?:know|have)|can robots?|could robots?)\b|"
r"\bcan you (?:\w+ )?(?:things|anything|objects|stuff|people|by yourself)\b|\b(?:can|could) you \w+(?: up)? (?:a|an|any)\b.*\?|"
r"\bshow me (?:you can|how)\b|기능|\bfunction\b|\bfeature\b|보여 ?(?:줄|주실|주세요|줘)|할 ?줄|줄 ?알|(?<!줄 )(?<!주실 )(?<!주 )(?<!줄)(?<!주실)수 ?있(?:어|어요|니|나요|습니까|을까)\s*\??$|가능해|가능한가|가능하", re.I)
r"\bshow me (?:you can|how)\b|기능|\bfunction\b|\bfeature\b|줄 ?(?:은|도)? ?(?:알|아|압|안)|보여 ?(?:줄|주실|주세요|줘)|할 ?줄|줄 ?알|(?<!줄 )(?<!주실 )(?<!주 )(?<!줄)(?<!주실)수 ?있(?:어|어요|니|나요|습니까|을까)\s*\??$|가능해|가능한가|가능하", re.I)
WONDER = re.compile(r"\bi wonder\b|\bwonder(?:ing)? (?:if|whether|how)\b|\bi bet\b|\b(?:i )?guess (?:it|the robot)\b|"
r"\b(?:can|could|does|did|will|would|is|was) (?:it|this|that|the robot|this robot|that robot|he|she|this thing)\b|"
r"\b(?:it|the robot|this robot|this thing) (?:can|could|does|will|is able)\b|\bcan it\b|"
@@ -56,7 +56,7 @@ WONDER = re.compile(r"\bi wonder\b|\bwonder(?:ing)? (?:if|whether|how)\b|\bi bet
# "can it wave? I wonder", "does it follow people?", "이거 손 흔들 수 있나?", "얘 따라오나 봐"
NOT_TO_LUMI = re.compile(
r"\bshall we\b|\bwe(?:'re| are) (?:heading|going|off|gonna)\b|\bwe (?:should|could|can|will|might|must|need to)\b|\bwe'll\b|"
r"\byou and (?:i|me)\b|\bmy plan\b|\bour plan\b|우리(?!.*악수).*(?:자|까|래|기로)\s*[??.!~]*$|" # plans between people
r"\byou and (?:i|me)\b|\bmy plan\b|\bour plan\b|우리끼리|우리(?!.*악수).*(?:자|까|래|기로)\s*[??.!~]*$|" # plans between people
r"\bimagine\b|\bsuppose\b|\bwhat if\b|\bwould you ever\b|\bif you were\b|\bpretend\b|\bhypothetical|"
r"만약|[가-힣](?:라면|다면)|어떨까|겠다\s*[!.~]*$|" # hypotheticals
r"\battention\b|\bladies and gentlemen\b|\b(?:visitors|guests|attendees|passengers)(?: are)? (?:please|should|must|may|"
@@ -70,6 +70,8 @@ QUESTION = re.compile(r"^\W*(?:(?:hey|so|um+|uh+|lumi|okay|ok)\W+)*(?:what|where
r"어디|뭐|무엇|왜|언제|누구|어떻게|몇|어느|무슨|어떤|얼마|[가-힣]까\s*[??]+\s*$|봤(?:어|니|나|냐|어요|습니까)|본 ?적|"
r"\bhave you (?:been|gone|ever)\b|(?:어|아|해|여)도 ?(?:돼|되|될까|괜찮)|"
r"알려 ?(?:줘|주|줄)|설명해|가르쳐|말해 ?(?:줘|봐|주)|\btell me\b|\bexplain\b|\bdescribe\b|"
r"상태(?:야|예요|에요|니|냐|입니까|인가요)?\s*\??\s*$|(?:open|오픈|열림|닫힘)(?:이야|이에요|이니|인가요|입니까)|"
r"\b(?:is|are) (?:your|the) (?:hand|gripper|fingers?|arm|head)s? (?:open|closed|up|down|out)\b|"
r"정확도|얼마나|을매나|속도|(?:열려|닫혀|켜져|꺼져|접혀|펴져) ?있(?:어|어요|니|나요|습니까)?\s*[??]", re.I)
# "그리퍼 열려 있어요?": a state asked, no motion # "팔 정확도 알려 줘": a question, no motion
OTHER_SENSE = re.compile(r"instagram|insta\b|\bsns\b|\baccount\b|\bsubscribe\b|인스타|계정|채널|구독|팔로우 ?해 ?주세요|"
@@ -81,7 +83,8 @@ REPEAT = re.compile(r"^\W*(?:(?:\w+\W+){0,2})?(?:again|one more time|once more|d
# "again", "한 번만 더 해 줘": what again is the history's (driving.read, the LLM)
SEVERAL = re.compile(r"\b(?<!hundred )and\b(?! a half\b)|\bwait\w*|\bcorrection\b|\binstead\b|"
r"\b(?:look|turn|go|move|wave|come|follow|pick|take|put|lift|raise|lower|reach|grab|bring)\b[^,]*,\s*(?:(?:\w+\W+){0,2})?(?:look|turn|go|move|wave|come|follow|pick|take|put|lift|raise|lower|reach|grab|bring|tell|say|sing|show|ask|answer|check)\b|\b(?:then|after that|also|plus|while|no|not|wait|stay|sleep|sorry|i mean|actually|rather)\b|;|"
r"(?!갖고|고고|에서)(?<!가)[가-힣](?:서|고)(?:[\s,.…]|$)|하고|셔서|면서|다가(?![와오])|갔다|다녀|아니|기다|대기|(?:가|와) ?있어|계세요|"
r"(?!갖고|고고|에서)(?<!가)[가-힣](?:서|고)(?:[\s,.…]|$)|(?:으로|로|에) ?가서|"
r"(?:흔들|흔드시|보시|돌|내리|올리|집어|내밀|숙이|들|봐 ?주시)고(?=[가-힣])|(?:쪽|나|날|위|아래|앞)보고(?=[가-힣])|(?:집어|와|가져와)서(?=[가-힣])|하고|셔서|면서|다가(?![와오])|갔다|다녀|아니|기다|대기|(?:가|와) ?있어|계세요|"
r"계십시오", re.I)
# several requests or a stay ("go to p3 and wait", "가서 기다려", "p3에 가 있어"): steps.read's
HAND_WORDS = re.compile(r"\byou(?:'re| are) holding\b|\b(?:in|from) my hand\b|\bhere'?s\b|\bhanding\b|\bi'?ll give\b|"
@@ -713,7 +716,7 @@ def _load():
POLITE = re.compile(r"\bif you don'?t mind\b|\b(?:it'?d|it would|that would|that'?d) be (?:great|nice|good|lovely|awesome|"
r"cool|helpful) if you(?: could)?\b|^\W*go ahead and\b|\bfor a (?:sec|second|moment|bit)\b|\bif you please\b", re.I)
SLANG = [(re.compile(rf"(?<![\w가-힣]){a}(?![\w가-힣])", re.I), b) for a, b in (
("wav", "wave"), ("reech", "reach"), ("ur", "your"), ("u", "you"), ("lemme", "let me"), ("luk", "look"),
("wav", "wave"), ("reech", "reach"), ("ur", "your"), ("u(?!-?turn)", "you"), ("lemme", "let me"), ("luk", "look"),
("pickup", "pick up"), ("plz|pls", "please"), ("mister robot|hey robot|yo robot|bro|buddy|lol|beep boop", ""),
("^\\W*robot", ""), (",?\\s*robot(?=\\s*[,.!?]|\\s*$)", ""),
("보이소|보시오|보시게|보십시오", "봐"), ("주이소|주시게", "주세요"), ("따라온나|따라오시게|따라오이소", "따라와"),
@@ -788,6 +791,7 @@ def core(text, markers=()):
"감사합니다") cut, and the one marker named written as CANON_PLACE ("go to the coffee corner" -> "go to p3")."""
from assistant import brain
t = TAIL.sub("", brain.CALLING.sub("", plain(text))).strip(" ,.!?~") or text
t = re.sub(r"(?<![가-힣])좀\s+(?=[가-힣])", "", t) # "뒤로 좀 돌아 줘": a softener, not a word to compare
named = [m for m in markers if brain.named_place(t, m, markers)]
if len(named) == 1:
low = brain._norm(t, markers)
@@ -852,8 +856,9 @@ DIR = {"forward": r"\b(?:forward|forwards|forword|ahead|straight)\b|\bto the fro
CARRY = (r"\b(?:bring(?! yourself)|fetch|deliver|carry)\b|\bget me\b|\b(?:to|for) me\b(?=.*\b(?:bring|get|fetch|hand|pass)\b)|"
r"\bget(?:ting)?\b.*\bfrom\b|\bgo get\b|가져|갖다|가지고 ?와|가져다|챙겨 ?(?:와|다)|갖고 ?와") # words that bring a thing to someone
COME_VERB = (r"\bcome\b|\bcum\b|\bkum\b|\bget over\b|\bapproach|\bcloser\b|\bhither\b|\bnear me\b|"
r"\bget closer\b|\broll over\b|\bdrive over\b|\bmy side\b|\bnext to me\b|\bto me\b|와|오세요|오십시오|오시|올래")
COME_SAID = (r"\bcome\b|\bcum\b|\bkum\b|\bget over\b|\bapproach|\bcloser\b|\bhither\b|\bnear me\b|"
r"\bget closer\b|\broll over\b|\bdrive over\b|\bmy side\b|\bnext to me\b|\bto me\b|와|오세요|오십시오|오시|올래|"
r"(?<![가-힣])컴(?= ?히어|(?![가-힣]))") # Konglish "컴 히어 해 줘", "이리 컴"
LIFT_SAID_MAX_M = 0.3 # m; a longer lift amount said is no lift request ("grow to three meters tall")
LIFT_BODY = (r"\b(?:yourself|your (?:body|torso|upper body)|body|make you|taller|shorter|smaller|small|tall|high|lift|rise|grow|"
r"shrink|come down|go up|go down|move up|move down|raise up|lower down|come up|sink down|elevate|squat|height|"
@@ -868,7 +873,7 @@ MOVE_VERB = (r"\b(?:move|go|step|back up|backup|scoot|slide|shift|drive|roll|rev
LOOK_DIR = {"left": r"\bleft|왼|레프트|(?:^|\s)좌로|좌측", "right": r"\bright|\brite\b|오른|라이트|(?:^|\s)우로|우측",
"up": r"\bup|\bupward|\bceiling|\bsky\b|\bhigher\b|천장|하늘|(?<!원)위", "down": r"\bdown|\bfloor|\bground|\bfeet\b|바닥|땅|아래|밑"}
LOOK_ME = (r"\b(?:at|on|to|toward|towards) (?:me|us|나)\b|\bthis way\b|\bover here\b|\bmy way\b|\bhere\b|\bwatch me\b|"
r"\bme in the eye|\bmy face\b|나한테|저한테|쳐다봐|(?:^|\s)(?:여기|이쪽|저|나|날)(?:를|을)?\s*(?:좀\s*)?(?:봐|보세요|look)")
r"\bme in the eye|\bmy face\b|나한테|저한테|쳐다봐|(?:^|\s)(?:여기|이쪽|저|나|날|절)(?:를|을)?\s*(?:(?:좀|한 ?번|잠깐|잠시|다시)\s*)*(?:바라|쳐다)?(?:봐|보세요|look)")
EN_NUM = {w: i for i, w in enumerate("zero one two three four five six seven eight nine ten eleven twelve thirteen "
@@ -1011,7 +1016,7 @@ def _slot(kind, text, markers, holding):
not re.search(rf"(?<![a-z0-9]){re.escape(named[0].lower())}(?![0-9])", said):
return None # "exit a" with only Exit_B, "booth 13" with Booth_12: asked
return ("go_to", named[0])
if kind == "come" and (re.search(CARRY + r"|따라", t) or not re.search(COME_VERB, t)):
if kind == "come" and (re.search(CARRY + r"|따라", t) or not re.search(COME_SAID, t)):
return None # "나한테 가져와", "이리 줘": not a trip to the person
if kind == "come" and re.search(r"\bwith (?:me|us)\b|함께|같이", t):
return ("follow", "") # "just come with me": walk along
@@ -1057,7 +1062,7 @@ def _slot(kind, text, markers, holding):
not re.search(r"\bface\b|\bother (?:side|way)\b|\d+\s*(?:degrees?|도)", t.replace("360", "")) and \
said_amount(text)[1] in (None, 360):
return ("turn", ("right" if re.search(r"\bright\b|오른쪽", t) else "left") + " 360")
if re.search(r"\baround\b|\bu-?turn\b|유턴|뒤로 돌|뒤돌|\bother way\b|\babout face\b|한 바퀴", t):
if re.search(r"\baround\b|\bu-?turn\b|유턴|뒤로 (?:(?:좀|한 ?번|얼른|빨리)\s*)?돌|뒤돌|\bother way\b|\babout face\b|한 바퀴", t):
return None if re.search(r"\bleft|\bright\b|왼|오른", t) else ("turn", "around 180")
d = [x for x in _dirs(t) if x in ("left", "right")]
if not d and said_amount(text)[1] == 180:
@@ -1159,12 +1164,54 @@ def read(text, markers=(), holding=False):
kind = kind_of(text, markers)
if isinstance(kind, tuple): # two motions close: only when the words fit one of them
kind, other = kind
if other not in ACTS or _slot(other, text, markers, holding) is not None:
if other == "put" and not holding and not PUT_VERB.search(text):
pass # "원래 자리로 가 줘": no put verb, nothing held: the trip back
elif other not in ACTS or _slot(other, text, markers, holding) is not None:
return None
if kind and _verb_conflict(kind, text, holding):
return None
got = _slot(kind, text, markers, holding) if kind else None
return ("fetch", said) if got and got[0] == "fetch" else got
PICK_VERB = re.compile(r"집|잡|들어|들고|가져|갖다|챙겨|\b(?:pick|grab|take|get|fetch|bring|hold)\b", re.I)
LOOK_VERB = re.compile(r"봐|보세|쳐다|바라|\b(?:look|see|watch)\b", re.I)
PUT_VERB = re.compile(r"놓|놔|둬|두|내려|\b(?:put|place|drop|set|leave)\b", re.I)
BACK_VERB = re.compile(r"돌아|복귀|컴백|리턴|가|와|\b(?:return|go|come|head|back)\b", re.I)
POINTED = re.compile(r"저기 ?저|저 ?자리|(?<!아까 )그 ?자리로|\bthat (?:spot|place|position)\b|\bover there\b", re.I)
def _verb_conflict(kind, text, holding):
"""The bank's kind against the verb said: "저 컵 봐" is no pick, "바닥에 있는 거 집어 줘" no look, "저기 저 자리로 가"
a pointed place, not back; holding a thing, the hand words are the hand reader's ("손 펴", "제자리 좀")."""
if kind in ("pick", "fetch") and LOOK_VERB.search(text) and not PICK_VERB.search(text):
return True
if kind == "look" and PICK_VERB.search(text) and not LOOK_VERB.search(text) and not HEAD_WORD.search(text):
return True
if kind == "come_back" and (POINTED.search(text) or not BACK_VERB.search(text)):
return True
if kind in ("turn", "move") and (HEAD_WORD.search(text) or re.search(r"돌아 ?보|허리|\bwaa*i*st\b|\btorso\b", text, re.I)):
return True # "머리 왼쪽으로 15도 돌려": the head
if kind == "look" and BODY_WORD.search(text) and not HEAD_WORD.search(text):
return True # "본체를 오른쪽으로 돌려", "torso 정면": the body
if kind == "look" and GO_VERB.search(text) and not HEAD_WORD.search(text) and not LOOK_VERB.search(text):
return True # "라이트로 살짝 가 줘": a drive
if kind == "arm_reach" and (HAND_SHAPE.search(text) or COME_VERB.search(text) and not ARM_WORD.search(text)):
return True # "손 펴 주시겠어요" (open), "할머니한테 와 줘" (come)
if kind == "wave" and not WAVE_VERB.search(text):
return True # "손 벌려 줘", "손 쥐어 빨리", "손 좀 주이소"
return holding and kind in ("arm_open", "arm_fold", "arm_reach", "arm_close")
HEAD_WORD = re.compile(r"머리|고개|얼굴|시선|\b(?:head|eyes|(?<!about )face|gaze)\b", re.I)
BODY_WORD = re.compile(r"본체|몸|허리|상체|몸통|\b(?:body|torso|waist|upper body|yourself)\b", re.I)
GO_VERB = re.compile(r"(?<![가-힣])가(?: ?줘| ?주|$|\s)|이동|움직|무브|\b(?:move|go|drive|roll|scoot)\b", re.I)
HAND_SHAPE = re.compile(r"펴|펼|쥐|주먹|넣|접|내려|오므|놔|놓|\b(?:open|close|fist|tuck|fold|lower)\b", re.I)
COME_VERB = re.compile(r"(?<![가-힣])와(?![가-힣])|와 ?(?:줘|주)|오세요|오십시오|\bcome\b", re.I)
ARM_WORD = re.compile(r"손|팔|\b(?:hand|arm)\b", re.I)
WAVE_VERB = re.compile(r"흔들|흔드|악수|인사|빠이|바이|웨이브|하이|\b(?:wave|waving|hello|hi|hey|shake|greet|bye)\b", re.I)
if __name__ == "__main__":
if sys.argv[1:] == ["build"]:
n = len(_load()[1])
+72 -22
View File
@@ -123,8 +123,14 @@ CLOSE_BOX = 0.85 # a person is really closer than TOO_CLOSE on
HEAD_SIGN = 1.0 # +image angle -> +head yaw (checked: + = robot's left)
LOOK = {"left": (40, None), "right": (-40, None), "center": (0, head.HEAD_REST_PITCH), "up": (None, 20), "down": (None, -5)}
# ^ yaw/pitch in degrees for "look" commands: +yaw = left, +pitch = up (checked on the dashboard 2026-10-12)
WAKE = re.compile(r"\b(hi|hey|hello|okay|ok|hai|high)?[\s,.!]*(lumi|lumia|loomi|loomy|lumie|lumee|lumy|lummy|lummi|looney|lu-mi|rumi|rumy|roomie)\b"
r"|루미|누미", re.I)
WAKE_UP_EN = r"wake up|wakey wakey|time to wake up"
WAKE_UP_KO = r"(?:일어나|깨어나)(?:요|세요|십시오|라|봐|봐요)?|기상"
WAKE = re.compile(rf"\b(hi|hey|hello|okay|ok|hai|high|{WAKE_UP_EN})?[\s,.!]*(lumi|lumia|loomi|loomy|lumie|lumee|lumy|lummy|lummi|looney|lu-mi|rumi|rumy|roomie)\b"
rf"(?:[\s,.!]*(?:{WAKE_UP_EN})\b)?"
rf"|(?:(?:{WAKE_UP_KO})[\s,.!~]*)?(?:헤이 ?|하이 ?)?(?:루미|누미)(?:야|아)?(?:[\s,.!~]*(?:{WAKE_UP_KO}))?"
rf"|^\W*(?:(?:hey|ok|okay|come on)\W+)?(?:{WAKE_UP_EN})\W*$|^\W*(?:(?:자|이제|얼른)\s+)?(?:{WAKE_UP_KO})[\s.!~]*$", re.I)
# ^ "Hey Lumi", "Lumi", "wake up (Lumi)", "Lumi, wake up", "루미야", "헤이 루미", "루미야 일어나", "일어나세요";
# a bare "wake up" / "일어나" only as the whole utterance ("I wake up at 7" is no call)
WAKE_REPLY = {"en": "Yes? How can I help?", "ko": "네? 무엇을 도와드릴까요?"}
NAME_ONLY = re.compile(r"^\s*(hi |hey |hello )?(lumi|loomi|rumi|루미)[\s,.!?]*$", re.I)
FETCH_STOP = re.compile(r"\b(sto+pp?|stob|halt|freeze|don'?t move)\b|^\W*(?:lumi\W+)?stopped\W*$|스탑|스텁|멈추(?:세요|십시오)|^\W*abort\W*$|\babort (?:the |this |your )?(?:mission|task|trip)\b|\bcancel (?:the |this |your )?(?:mission|task|trip)\b|"
@@ -313,7 +319,7 @@ HELLO_ONLY = re.compile(r"^(?=\W*\w)\s*(?:(?:hi|hey|hello|hiya|hai|hallo|helo|hi
r"(?:how are you(?: doing)?(?: today)?[\s,.!?]*)?$|" # "how are you?"
r"^\s*(?:안녕|안녕하세요|안녕하십니까|하이)[\s.!~?]*$", re.I) # "안녕하세요", "하이"
CALL_REST = re.compile(r"^(?:[\W_]|\b(?:hi|hey|hello|hiya|hai|ok|okay|there|how are you(?: doing)?(?: today)?)\b|"
r"안녕(?:하세요|하십니까)?|하이|야|아)*$", re.I) # what is left of a call without the name
r"안녕(?:하세요|하십니까)?|하이|헤이|야|아)*$", re.I) # what is left of a call without the name
CAMERA_HALF_FOV = 42.0 # deg; half the camera's view (+ the head's YAW_LIMIT for the head camera)
WAKE_MAX_S = 6.0 # s; longer utterances are not checked for the wake word
BARGE_IN_LOGPROB = -0.6 # an interruption must be heard more clearly than a normal answer (-1.0)
@@ -3255,35 +3261,53 @@ STOP_UNSAID = re.compile( # a stop that is taken back, for later, said about t
r"\bstop it,? (?-i:(?!Lumi\b|Robot\b)[A-Z][a-z]+)\b", re.I)
STOP_LATER = re.compile( # a stop for later ("내일 그만하시게", "행사가 끝난 후에 멈춰 주세요") or reported ("아까 직원분이
# 그만하라고 지시했습니다"); "내가 멈추라고 했지!" is said now
r"(?:^|\s)(?:나중에|이따가?|있다가|내일|모레|다음에|다음 ?번에)\s|(?:끝난|끝나고|마친|마치고|끝내고) ?(?:후|뒤|다음)?에?\s|"
r"[가-힣]고 ?나서\s|(?<!내가 )(?<!제가 )(?<!내가)(?:그만하|멈추|멈춰 ?달|정지하|서)라고\s*(?:\S+\s+)?"
r"(?:했|하셨|그랬|말했|말씀|지시|하더|하던|한다|하네)")
STOP_PAD = re.compile(r"^(?:\W*(?:hey|hi|yo|oh|okay|ok|so|um+|uh+|listen|right|alright|all right|excuse me|mister robot|"
r"robot|lumi|loomi|루미 ?씨|루미 ?선생|루미야?|로봇아?|로봇 양반|어+|아+|야|저기요?)\b)+|"
r"(?:\W*\b(?:please|plz|pls|bro|now|right now|real quick|thanks|thank you|okay|ok|would you|will you|"
r"right|already|빨리|좀|제발|당장|루미야?)\b)+\W*$", re.I)
r"right|already|lumi|robot|빨리|좀|제발|당장|루미야?)\b)+\W*$", re.I)
STOP_ONLY = re.compile( # a whole sentence that only says stop / enough / stay (after calls and fillers): stop at once
r"(?:(?:sto+p|stahp|stob|top it|enough|that'?s enough|that is enough|no more|quit it|cut it out|kill it|abort|"
r"(?:(?:sto+p|stahp|stob|top it|enough|that'?s enough|that is enough|no more|quit it|cut it out|knock it off|whoa,? there|whoa(?:,? whoa)+|kill it|abort|"
r"stop (?:everything|driving|moving|it|that|the robot|right there|right now)|enough (?:music|of that)|"
r"hold it|stop 해|그만|그만해|그만해요|그만하세요|그만하십시오|그만해 ?줄래요?|"
r"hold it(?: (?:right )?(?:there|here))?|stop 해|그만|그만해|그만해요|그만하세요|그만하십시오|그만해 ?줄래요?|"
r"그만해 ?주세요|그마내|그만둬|멈춰|멈쳐|멈처|멈추라고|멈춰 ?봐|거기까지|고마 ?(?:서라|해라|해|하이소)|서|don'?t go|가지 ?마|그마+안|"
r"얼음|cut it|노래 ?꺼|음악 ?꺼|stop the (?:music|song)|music off|stay|stay (?:here|there|put|right there)|"
r"(?:just )?wait there|stop following(?: me)?|finish follow|(?:여기|거기)(?:서)? ?(?:그대로 ?)?(?:있어|있어요|계세요|stay|서|서세요|"
r"기다려)|그대로 있어|가만히 있어|stay 해|wait 해)\W*){1,3}", re.I)
STOP_POLITE = re.compile( # a stop asked politely, after wording.ko_plain: "멈춰 주시겠어요?" -> "멈춰 줘?", "can you stop for me?"
r"\W*(?:(?:좀|지금|당장|잠깐|잠시|거기서?|이제)\s*)*(?:멈춰|멈춰 서|정지해|그만해|스톱해|스탑해|서)(?: ?줘)?\W*|"
r"\W*(?:(?:please|lumi|hey|okay|ok)\W+)*(?:can|could|would|will) (?:you|u) (?:please |just |kindly )?(?:stop|halt|freeze)"
r"(?: (?:right )?(?:now|here|there|please))?(?: for (?:me|us|a (?:second|sec|moment|bit|minute)))?(?:,? please)?\W*|"
r"\W*(?:would|do) you mind stopping(?: (?:now|here|there))?(?: for (?:me|us|a (?:second|moment)))?(?:,? please)?\W*", re.I)
def stop_order(text, markers):
""""stop", "freeze", "멈춰": stop everything at once. Not "stop talking" and not a question about the stop button;
"can you stop?", "멈출 수 있어?" and "stop, where are you going?" do stop. Not a negated stop ("don't stop", "계속
해"), talk about stopping ("he said stop", "bus stop", "my laptop freezes", "내 다리도 자주 멈춰"); a short bare
stop word always stops (also stretched: "stooop", "머엄춰")."""
if NOT_STOP.search(text) and not re.fullmatch(r"\W*(?:(?:no|ok|okay|lumi|루미야?|hey)\W+)*(?:sto+pp?|stob|stopped|halt|freeze|멈춰|머+엄*춰|"
if NOT_STOP.search(text) and not re.fullmatch(r"\W*(?:(?:lumi|robot|hey|okay|ok)\W+)*(?:would|do) you mind stopping"
r"(?:,? (?:now|here|there|please|for (?:me|us|a (?:second|moment))))*\W*", text, re.I) \
and not re.fullmatch(r"\W*(?:(?:no|ok|okay|lumi|루미야?|hey)\W+)*(?:sto+pp?|stob|stopped|halt|freeze|멈춰|머+엄*춰|"
r"그만|정지|스톱|스탑|stop it|stop now)\W*", text, re.I):
return False
if STOP_UNSAID.search(text):
return False
if STOP_UNSAID.search(text) or STOP_LATER.search(text):
return False # "이따가 멈춰 주세요": a stop for later
bare = STOP_PAD.sub("", text.strip()).strip(" ,.!?~")
if bare and STOP_ONLY.fullmatch(bare):
return True # "hi Lumi, stop, okay?", "enough already", "Lumi, wait"
# (watch out / 위험해 / "Lumi, wait" / hold on: on a mission these halt it (mission_talk), never end it)
asked = bool(brain_mod.STOP_ASK.match(brain_mod.CALLING.sub("", text)) or
from assistant import wording
plain = brain_mod.CALLING.sub("", wording.ko_plain(text)).strip()
asked = bool(brain_mod.STOP_ASK.match(brain_mod.CALLING.sub("", text)) or STOP_POLITE.fullmatch(plain) or
re.match(r"^\W*(?:stop|halt|freeze|멈춰|정지|스톱)\W*[,.!]", text, re.I))
return bool(FETCH_STOP.search(text) or asked) and (brain_mod.intent(text, markers) or ("",))[0] not in ("quiet", "look") \
and not brain_mod.STOP_TALK.search(text) and ("?" not in text or asked)
@@ -3299,14 +3323,16 @@ HAND_STATE_Q = re.compile( # how the hand is now (A1): "is your hand open?", "
r"\b(?:is|are|r|was) (?:your|ur|the) (?:hand|gripper|claw|fingers?|arm)s? (?:still |now |already )?(?:open|opened|closed|shut|out|"
r"extended|empty|folded|in|up|down|stretched)\b|\b(?:hand|gripper|arm) (?:open|closed?|out)\s*(?:이야|이에요|인가요?|이니|상태|\?)|"
r"^\W*(?:(?:right|um|basically|next|so|okay)\W+)*did (?:you|u) drop (?:it|that|something|the \w+)\W*$|"
r"(?:손|그리퍼|집게|손가락|팔)(?:이|은|는|가)? ?(?:지금 |아직 |다 )?(?:open|close|펴져|펴진|열려|열린|닫혀|닫힌|접혀|접힌|뻗어져|오므려져|"
r"(?:손|그리퍼|집게|손가락|팔)(?:이|은|는|가)? ?(?:지금 |아직 |다 )?(?:open|close|오픈|클로즈|펴져|펴진|열려|열린|닫혀|닫힌|접혀|접힌|뻗어져|오므려져|"
r"쥐어져)\s*(?:있|상태|이야|인가)", re.I)
def status_question(text):
""""What are you doing?", "where are you going?", "is your hand open?": answered from the task state ("들고 있는 거
줘" is a request)."""
return bool(HAND_STATE_Q.search(text)) or bool(STATUS_Q.search(text)) and not NOT_STATUS_NOW.search(text) and not EMPTY_HAND.search(text)
hand = HAND_STATE_Q.search(text) and not re.search(r"\b(?:stretch|stick|hold|put|reach|extend|get|move|bring)\b", text, re.I)
return bool(hand) or bool(STATUS_Q.search(text)) and not NOT_STATUS_NOW.search(text) and not EMPTY_HAND.search(text)
# hand: not "may I ask you to stretch your arm out?" (an order)
def says_goodbye(text):
@@ -3338,6 +3364,11 @@ NOT_A_STEP = re.compile(r"^\W*(?:(?:please|and|then|also)\s+)*(?:dance|jump|fly|
r"bring|take|give|hand|put|carry|deliver)\b|.*(?:춤|점프|날아|수영|박수)", re.I) # a part not read: asked
CAN_TOLD = re.compile(r"\b(?:you|u) (?:can|could|are able to|know how to)\b|(?<!줄 )(?<!주실 )(?<!줄)(?<!주실)수 ?(?:도 ?)?있(?:지|죠|잖|겠지|겠죠|을 ?걸)|"
r"줄 ?(?:도 ?)?알(?:지|죠|잖)", re.I) # with a tag: Lumi's ability said back, a question (TAG)
MYEOT_SLIP = re.compile(r"(?<![가-힣])멸(?=\s*(?:센티|센치|미터|밀리|키로|킬로|그램|개|번|도|시|분|초|명|살|층|cm|mm|kg|m\b))", re.I)
def route(text, markers, b, holding=False, seen=None, last="", chain_ok=True):
"""Which way a command goes, the same for voice (Lumi.answer), the dashboard's Command box (/tasks/parse) and
tests/command_check: (kind, data). Kinds in this order: "stop"; "detour" (data: assistant/detour.read's
@@ -3348,10 +3379,15 @@ def route(text, markers, b, holding=False, seen=None, last="", chain_ok=True):
reading: assistant/intent_bank.py); (None, None): the LLM reads
it. seen: seeing.answer or a stand-in; chain_ok: False on a mission or while a chain runs."""
from assistant import chain, intent_bank
text = MYEOT_SLIP.sub("몇", text or "") # whisper's 멸 for 몇: "멸 센티까지 잡아?" asks, orders nothing
text = re.sub(r"(?<=[가-힣])(?=[a-zA-Z]{2})", " ", text) # "원래 자리에put back": the English word apart
text = re.sub(r"\bcome on back\b", "come back", text, flags=re.I) # not 1 m back
text = re.sub(r"(?<![\d.])360(?= ?돌아)", "360도", text) # "루미 360 돌아 봐": a full turn, not "turn round"
if stop_order(text, markers):
return "stop", None
told = intent_bank.TAG.search(text) and (chain.PAST.search(text) or intent_bank.PAST_EN.search(text) or
intent_bank.past_ko(text)) # "you went to P5 earlier, right?": asked
intent_bank.past_ko(text) or CAN_TOLD.search(text))
# "you went to P5 earlier, right?", "you can lift your arm, right?", "너 팔 접을 수 있지?": asked, no order
text = brain_mod.strip_asides(text) # "hi Lumi, it's my birthday, put it down!": the command (A1)
if sing.picked(text, last): # after the list of songs: "the first one", "Fantastic Baby"
return "sing", None
@@ -3371,15 +3407,18 @@ def route(text, markers, b, holding=False, seen=None, last="", chain_ok=True):
plan = None # "그 cup 들고 wave 해" with a cup in the hand: no second pick; the LLM
if plan:
return "chain", plan
got = seen(text) if seen else None
held_order = (holding() if callable(holding) else holding) and not hold and \
(brain_mod.held_place(text, markers) or brain_mod.held_give(text, markers)) # "put it down ok?" with a cup:
got = seen(text) if seen and not held_order else None # the hand, not "I put it down, now?"
if got:
return "seeing", got
if status_question(text):
return "status", None
if (holding() if callable(holding) else holding) and brain_mod.held_put_back(text, markers):
if (holding() if callable(holding) else holding) and not brain_mod.held_back(text) and \
not brain_mod.ARM_TALK.search(text) and brain_mod.held_put_back(text, markers):
return "quick", ("put", "back") # "it's my birthday, put that back where you found it!"
song = sing.asked(text, last) # "Let it go 불러 줘": a song title, never the hand (A1)
if hold and not song: # a wave / arm rule may act on a question-form request ("악수 한번 할까요?",
if hold and not song and not told: # a wave / arm rule may act on a question-form request ("악수 한번 할까요?",
arm_rule = brain_mod.intent(text, markers) # "would it be possible to wave at me?"); intent() itself refuses
if arm_rule and arm_rule[0] in ("wave", "arm"): # negations, later times, remarks, ability questions (A1)
return arm_quick(arm_rule, holding)
@@ -3392,7 +3431,9 @@ def route(text, markers, b, holding=False, seen=None, last="", chain_ok=True):
cor = brain_mod.correction(text, b.history)
if cor:
return "correction", cor
if not song and (brain_mod.hand_request(text, False, b, markers) or brain_mod.hand_request(text, True, b, markers)):
if not song and not brain_mod.ARM_TALK.search(text) and not brain_mod.held_back(text) and \
(brain_mod.hand_request(text, False, b, markers) or brain_mod.hand_request(text, True, b, markers)):
# not "it'd be cool if you could hand it over someday", "I heard you can take things from people"
held = holding() if callable(holding) else holding
hand = brain_mod.hand_request(text, held, b, markers)
if hand:
@@ -3408,12 +3449,16 @@ def route(text, markers, b, holding=False, seen=None, last="", chain_ok=True):
if sing.asked(text, last):
return "sing", None
rule = brain_mod.intent(text, markers)
if rule and rule[0] in QUICK_RULES - {"come_back", "weather", "search"} and brain_mod.ARM_TALK.search(text):
return None, None # "자네 컵 잡는 거 제법이더군", "do you know how to drive right 30 cm?",
# "70센티 앞으로 움직일 리가 있나": a remark or an ability, no motion
if rule and rule[0] in QUICK_RULES:
return "quick", rule
if not rule:
from assistant import intent_bank
rule = intent_bank.read(text, markers, holding) # the same request in other words, by meaning
if rule and rule[0] in ("wave", "arm") and brain_mod.ARM_TALK.search(text):
rule = None if brain_mod.GREET_ONLY.match(text or "") else \
intent_bank.read(text, markers, holding) # the same request in other words, by meaning ("hello robot": no wave)
if rule and rule[0] not in ("come_back", "weather", "search") and brain_mod.ARM_TALK.search(text):
rule = None # "it'd be cool if you could take your hand back someday": talk (A1)
if rule:
return arm_quick(rule, holding)
@@ -3436,7 +3481,7 @@ ARM_AGAIN = re.compile(r"^\W*(?:(?:okay|ok|yes|yeah|lumi|please|robot|루미야?
FILLER_PART = re.compile(r"\W*(?:(?:hey|yo|hi|okay|ok|excuse me|um+|uh+|so|now|please|thanks|thank you|real quick|quick|"
r"right now|lumi|robot|buddy|mister robot|bro|dude|어이|야|저기요?|루미야?|로봇아?|당장|지금|빨리|"
r"right now|lumi|robot|buddy|mister robot|bro|dude|어이|야|저기요?|루미 ?씨|루미야?|로봇아?|당장|지금|빨리|"
r"얼른|어서|끝까지|이제|좀|제발)\W*)+", re.I) # a part of the words that is no step: a call, "now"
@@ -3445,7 +3490,10 @@ def read_mission(text, markers):
A single move / turn / arm / go, or words that are only partly a plain command, stay with the other paths."""
from assistant import steps
got, unread, by = steps.read(text, markers, llm=False)
unread = [u for u in unread if not FILLER_PART.fullmatch(u)] # "팔 접어, 당장", "hey robot, fold your arm"
from assistant import chain
unread = [u for u in unread if not FILLER_PART.fullmatch(u) and # "팔 접어, 당장", "hey robot, fold your arm"
not chain._restated(u, text.lower().replace(u, " "))] # "컵 잡아!, 아 잡아 줄 수 있어요?": said again
# (the parts come lower-cased: "부스 B로 가서" is the part itself, not said twice)
rule = brain_mod.intent(text, markers) or ("", "")
if unread and rule[0] == "look" and rule[1].endswith(f" {brain_mod.HEAD_YAW[1]:g}"):
return None # "turn around and look": the head looks behind (brain.BEHIND_WORDS)
@@ -3462,7 +3510,9 @@ def read_mission(text, markers):
return None
if len(got) > 1 and all(st == got[0] for st in got) and got[0]["do"] in ("arm", "wave", "look", "lift"):
got = got[:1] # "reach out, reach out to me": one reach, said twice
plain = not steps.is_mission(got) and (len(got) == 1 or (brain_mod.intent(text, markers) or ("",))[0] == "fetch")
one_part = len(steps._split(steps._norm(steps._cut_says(text)[0], markers), markers)) == 1
plain = not steps.is_mission(got) and (len(got) == 1 or one_part or (brain_mod.intent(text, markers) or ("",))[0] == "fetch")
# ^ "컵 가져와 주셨으면 해요": one part a plain fetch can do stays the fetch, not a mission
if not unread and (plain or (len(got) == 1 and got[0]["do"] in ("move", "turn", "arm"))): # "take the cup and put
return None # it on the chair": two steps, not a pick
return got, unread, by
+117 -17
View File
@@ -35,16 +35,21 @@ _SUP_KO = "|".join(k for k in brain.SUPPORTS if not k.isascii())
_NUM = r"(\d+(?:\.\d+)?)"
_DIR = r"(forward|ahead|straight|back(?:wards?)?|left|right)"
_DIR_KO = r"(앞으로|뒤로|왼쪽으로|오른쪽으로)"
_FILL = (r"(?:please|let'?s|lets|hey lumi|hi lumi|hey|hi|lumi|loomi|rumi|okay|ok|alright|all right|so|well|real quick|if you can|if you could|자|저기|저기요|혹시|instead|um+|uh+|er|hmm|thank you|thanks|now|then|and|also|first|next|"
r"finally|after that|there|for me|again|carefully|slowly|could you|can you|would you|will you|lumi야|루미야|루미|음|응|어|야 로봇|로봇아|로봇야|"
_FILL = (r"(?:(?:저기 |그 )?(?:이보게(?: 루미)?|어이(?: 로봇아?| 루미야?)?|아야(?: 루미)?|야야(?: 루미)?|우리 루미|보소|자네|"
r"루미 ?(?:님|씨|군|양)(?:께서|께)?|로봇 ?씨|여보세요|실례지만|실례합니다|죄송한데요?|죄송하지만|죄송합니다만|"
r"번거로우시겠지만)|" # calls of every level ("이보게 루미", "루미 님께서") before "루미" alone
r"please|let'?s|lets|hey lumi|hi lumi|hey|hi|lumi|loomi|rumi|okay|ok|alright|all right|so|well|real quick|if you can|if you could|자|저기|저기요|혹시|instead|um+|uh+|er|hmm|thank you|thanks|now|then|and|also|first|next|"
r"finally|after that|there|for me|for us|again|carefully|slowly|could you|can you|would you|will you|lumi야|루미야|루미|음|응|어|야 로봇|로봇아|로봇야|"
r"감사합니다|고마워요|고마워|고맙습니다|좀|먼저|우선|일단|그다음|그 다음|마지막으로|다시|lastly|first of all|"
r"(?:i'?d|i would) like you to|i want you to|i need you to|you should|kindly|go ahead and|maybe|possibly|"
r"do me a favou?r and|be a dear and|right away|quickly|if you don'?t mind)")
r"do me a favou?r and|be a dear and|right away|quickly|if you don'?t mind|excuse me|sorry|"
r"거시기|에구|에이그|아|얘|no|nope|actually|change of plans?|아니|아니야|아니요|아뇨|아니 아니|" # "no, bring it to p4 instead": the new order
r"ㅎㅎ+|ㅋㅋ+|응\??|한 ?번만|쪼까|쫌|퍼뜩|얼른|빨리|어서|우리|거기서|그|robot)")
_PEOPLE = r"(?:them|him|her|someone|somebody|the person(?: there)?|people|the people|everyone|everybody|the guests?)"
# where one step ends and the next starts
_SPLIT = re.compile(r"\s*(?:,|;|\.(?=\s|$)|\band then\b|\bthen\b|\band\b|\bafter that\b|\bafterwards\b|\bonce you'?re there\b|"
r"\bwhen you get there\b|그리고 나서|그러고 나서|그런 다음에?|그 후에?|그리고|그 ?다음에?|그담에|다음에)\s*")
_SPLIT_KO = re.compile(r"(?<=[가-힣](?:고|서))(?<!라고)(?<!다고)(?<!자고)(?<!냐고)(?<!에서)(?<!말고)\s+(?!있)|(?<=다가)\s+") # "들고 ", "가서 ": a verb
_SPLIT_KO = re.compile(r"(?<=[가-힣](?:고|서))(?<!라고)(?<!다고)(?<!자고)(?<!냐고)(?<!에서)(?<!말고)\s+(?!있)(?!(?<![가와해]서\s)(?:줘|줘요|주세요|주십시오|줄래|주실래|주라|주게|주이소|봐|봐요|보세요)(?![가-힣]))|(?<=다가)\s+") # "들고 ", "가서 ": a verb
# joining two steps, not a quote
def _norm(text, markers=()):
@@ -73,6 +78,11 @@ _SAME = [ # wordings read as the plain one (the blind mission sets, 2026-10-22
r"|\buntil you(?:'re| are) told to (?:go on|continue|move on)\b", "until i tell you to go on"),
(r"(?:누가\s*)?계속\s*(?:가라고|하라고|가도 된다고)\s*(?:할|하실|말할)\s*때까지\s*(?:거기서\s*)?", ""),
(r"(?<=\S)까지\s*(?=갔다 ?와|다녀와)", " "), # "p4까지 갔다 와요" = "p4 갔다 와요"
(r"컴백\s*(?:하|해)\S*|컴 ?백(?=[\s,.!?]|$)", "돌아와"), (r"오더(?:를)?\s*(?=받)", "지시 "), # Konglish
(r"원 ?서클\s*(?=돌)", "한 바퀴 "), (r"\bwait\s*(?:하고|해서)", "기다리고"),
(r"\b((?:give|hand|take|bring|send) (?:it|this|that) |go |head |come )too\b", r"\1to"), # whisper's "too"
(r"웨이트\s*(?:하고|해서|했다가)", "기다리고"), (r"웨이트\s*해\S*", "기다려"),
(r"(?<=[가-힣a-z0-9_])(에|로|으로)\s*고\s*해서", r"\1 가서"), (r"들렀다가|들렀다 ?(?=와)", "갔다가"),
(r"돌아오(?:세요|십시오)", "돌아와"), (r"(?:이리로|여기로|이쪽으로)\s*돌아와", "돌아와"),
]
_AFTER_KO = {"간": "가고", "온": "오고", "집은": "집고", "잡은": "잡고", "든": "들고", "받은": "받고", "준": "주고", "놓은": "놓고",
@@ -89,7 +99,7 @@ _HON_KO = [("가셔서", "가서"), ("가시고", "가고"), ("가셨다가", "
# ---------- one clause -> one step ----------
def _place(word, markers):
"""A place word in a go clause -> marker name, "here", or None (not on the map)."""
word = re.sub(r"(?<=\S) (?:point|marker)$|\s*(?:앞|옆|근처|쪽|포인트|지점)$", "", word.strip()) # "the final point", "p5 앞"
word = re.sub(r"(?<=\S) (?:point|marker)$|\s*(?:앞|옆|근처|쪽|포인트|지점|위치|포지션|자리)$", "", word.strip()) # "the final point", "p5 앞"
w = re.sub(r"^(?:either |the |your |my |point |marker |포인트 ?)", "", word)
exact = next((mk for mk in markers if wording._key(mk) == wording._key(w)), None) # "coffee_corner", "부스 3"
if exact:
@@ -294,12 +304,17 @@ def _give(c):
if re.fullmatch(rf"(?:give|hand) (?:it|that|this|the (?:(?:{COL}) )?(?:{OBJ})s?)?(?: over)?"
rf"(?: to (?:me|you|{_PEOPLE}|the person there|whoever is(?: there)?|anyone(?: there)?|anybody(?: there)?|"
rf"the (?:first )?(?:person|one) you (?:see|meet)))?(?: there)?"
r"|wait (?:there )?(?:until|till) (?:someone|somebody|anyone|they|he|she) takes? it(?: from you)?"
rf"|wait (?:there )?(?:until|till) (?:someone|somebody|anyone|they|he|she) (?:takes?|comes? (?:and|to) (?:take|get)s?) "
rf"(?:it|the (?:(?:{COL}) )?(?:{OBJ})s?)(?: from you)?"
r"|(?:누가|누군가|사람이|손님이|그 사람이|그분이)\s*(?:(?:그거|그걸|컵을?|이거)\s*)?(?:가져갈|받을|가지러 올|찾으러 올)\s*때까지\s*"
r"(?:기다려|기다리고|기다렸다가|대기해|있어)"
r"|hand it over|(?:give|hand) it", c) or \
re.fullmatch(rf"(?:그거|그것을?|(?:(?:{COL})\s*)?(?:{OBJ})(?:을|를)?)?\s*(?:줘|주고|주세요|건네 ?줘|건네주고|"
rf"건네 ?주세요|건네|전해 ?줘|전해 ?주고|전해 ?주세요|전해)", c):
return {"do": "give"}
if re.fullmatch(r"(?:거기 (?:있는|계신)\s*)?(?:나한테|저한테|나에게|저에게|그 사람한테|사람한테|그분께|분께|분한테)\s*"
if re.fullmatch(r"(?:나|저) (?:줘|주세요|주고)", c) or \
re.fullmatch(r"(?:(?:그거|그걸|이거|이걸)\s+)?(?:거기 (?:있는|계신)\s*)?(?:나한테|저한테|나에게|저에게|(?:그|저|이) ?사람(?:한테|에게)|사람한테|"
r"(?:그|저|이) ?분(?:께|한테)|분께|분한테)\s*"
rf"(?:(?:이거|그거|이것|그것|이걸|그걸|(?:(?:이|그)\s*)?(?:{OBJ})(?:을|를)?)\s*)?"
r"(?:줘|주고|주세요|건네|건네줘|건네주고|건네주세요|건네 ?줘|건네 ?주세요|드려|드리고|갖다 ?줘|갖다 ?주세요)", c) or \
re.fullmatch(r"(?:이|그|저|두|세|네) ?분(?:께|한테|에게)\s*(?:줘|주고|드려|드리고|건네|건네 ?줘|건네 ?드려)", c):
@@ -407,12 +422,12 @@ def _wait(c, markers, after):
m = re.fullmatch(rf"(?:(.+?)에서\s*)?(?:(\d+(?:\.\d+)?) s\s*(?:동안|정도|만)?\s*)?{_KO_GIVER}\s*(?:({COL})\s*)?({OBJ}|물건|뭔가|무언가|그거|뭐|무엇을|뭘|이거)?\s*"
r"(?:을|를)?\s*(?:주면|건네주면|건네면|갖다주면|가져다주면|가져다 주면|줄 때까지|건네줄 때까지|줄 거야|"
r"줄 거예요|가져올 거야)\s*(?:기다렸다가|기다려서|기다리고|기다려|기다려요)?\s*"
r"(받아서|받아|받고|받아와|받아 와|받아요)?", c)
r"(받아서|받아 ?가지고 ?와|받아 ?가지고|받아|받고|받아와|받아 와|받아요)?", c)
if m and (m.group(1) is None or _at_place(m.group(1), markers)):
obj = brain.OBJECTS.get(m.group(4) or "")
return ([{"do": "go", "to": _at_place(m.group(1), markers)}] if m.group(1) else []) + \
[{"do": "receive", "object": obj, "wait_s": float(m.group(2)) if m.group(2) else WAIT_GIVE_S}] + \
([{"do": "go", "to": "here"}] if m.group(5) in ("받아 와", "받아와") else [])
([{"do": "go", "to": "here"}] if re.fullmatch(r"받아 ?(?:가지고 ?)?와", m.group(5) or "") else [])
if after and re.fullmatch(r"(?:거기|여기)(?:서|에서)", c):
return [] # "p3로 가서 | 거기서 | 기다려": the place of the next step
if after and after["do"] == "receive" and after.get("wait_s") and re.fullmatch(r"받아서|받아|받고|받아 와|받아와|받아요", c):
@@ -461,10 +476,10 @@ def _wait(c, markers, after):
_POLITE = re.compile(r"(?<=[가-힣])\s*(?:주십시오|주시겠어요|주시겠습니까|주실 수 있나요|주실 수 있습니까|주실 수 있어요|"
r"줄 수 있어요|줄 수 있어|주실래요|줄래요?|줘 ?봐요?|줘요?|주세요|죠)\??$") # every speech level
r"줄 수 있어요|줄 수 있어|주실래요|줄래요?|줘 ?봐요?|줘요?|주세요|주라|죠)\??$") # every speech level
_HONORIFIC = [(r"(가|와|놔|돌아|집어|잡어|잡아|들어|줘) ?봐요?$", r"\1"), # "가봐", "놔 봐": try / do it
(r"(?<=[가-힣]) ?주시고$", "고"), (r"(?<=[가-힣]) ?주셔서$", "서"), # "가 주시고": 가고
(r"가(?:십시오|세요|시죠|요)$", "가"), (r"오(?:십시오|세요|시죠)$", "와"), (r"도(?:십시오|세요)$", "돌아"),
(r"가(?:십시오|세요|시죠|요)$", "가"), (r"((?:으로|로|에) )가게나?$", r"\1가"), (r"오(?:십시오|세요|시죠)$", "와"), (r"도(?:십시오|세요)$", "돌아"),
(r"드리(?:십시오|세요)$", "드려"), (r"(?:주|드리)십시오$", "줘"), (r"물러나(?:세요|십시오|요)?$", "가"),
(r"회전(?:해|하세요|하십시오|해요)$", "돌아"), (r"말씀(?:해|하세요|하십시오|해요|해 주세요)$", "말해"),
(r"놓으(?:십시오|세요)$", "놔"), (r"기다리(?:십시오|세요|시죠|셔요)$", "기다려"),
@@ -684,9 +699,10 @@ def _clause(c, markers, after=None):
def _clause_steps(c, markers, after=None):
c = re.sub(r"^(?:second(?:ly)?|third(?:ly)?|fourth|first(?:ly)?|last(?:ly)?|step \d)[\s,]+", "", c.strip(" .!?")) # "second, go to ..."
c = re.sub(rf"^(?:{_FILL}[\s,]+)+|(?:[\s,]+{_FILL})+$", "", c).strip(" .!?,")
c = re.sub(rf"^(?:{_FILL}(?:[\s,]+|$))+|(?:[\s,]+{_FILL})+$", "", c).strip(" .!?,")
if re.search(r"[가-힣]", c):
c = re.sub(r"\s+", " ", c)
c = re.sub(r"\s+", " ", wording.ko_plain(c)).strip(" .!?~") # every speech level / dialect as 반말: "돌아오게나",
c = re.sub(rf"^(?:{_FILL}(?:[\s,]+|$))+|(?:[\s,]+{_FILL})+$", "", c).strip(" .!?,~") # "가 주시겄슈" -> "돌아와", "가 줘"
c = re.sub(r"\s좀\s", " ", c)
c = re.sub(r"^(?:야\s+)?로봇(?:아|야)?[,\s]+|^야[,\s]+(?!로봇)", "", c) # "야 로봇", "로봇아", "야": calling it
c = c.replace("그리퍼를", "손을").replace("물러나", "뒤로 물러나") if "뒤로" not in c else c.replace("그리퍼를", "손을")
@@ -705,7 +721,7 @@ def _clause_steps(c, markers, after=None):
c = re.sub(r"^\S+ 말고\s+", "", c) # "미나 말고 사라한테": not Mina, Sara
c = re.sub(r"^\S+ (?:없으니까|없어서|없대서)\s+", "", c) # "현우 없으니까 ...": the reason, not a step
c = re.sub(r"\s+(?:거기로|내가) 갈게$", "", c)
c = re.sub(r"(?<=[a-z0-9가-힣]) (?:하고|해서|하고서|하고 나서|한 다음에?)$", "", c) # "turn left 하고 p2로 가",
c = re.sub(r"(?<=[a-z0-9가-힣])(?<!거)(?<!것)(?<!대로) (?:하고|해서|하고서|하고 나서|한 다음에?)$", "", c) # "turn left 하고 p2로 가",
# "go to 입구 하고"
raw, c = c, _sender(c)
if not c:
@@ -735,7 +751,8 @@ def _clause_steps(c, markers, after=None):
c = re.sub(r"\bstraight ahead\b", "forward", c)
c = re.sub(r"\bthe gripper\b", "your hand", c)
c = c.replace("그리퍼", "손")
m = re.fullmatch(r"(.+?)에 있는 (?:사람|분|손님)(?:한테|에게|께)\s*(?:갖다|가져다|건네) ?(?:줘|주고|주세요)?", c)
m = re.fullmatch(r"(.+?)에 (?:있는|계신) (?:사람|분|손님)(?:한테|에게|께)\s*(?:(?:갖다|가져다|건네) ?(?:줘|주고|주세요|드려|드리고)?|"
r"줘|주고|드려|드리고)", c)
if m:
to = _places(m.group(1), markers)
return to and len(to) == 1 and [{"do": "go", "to": to[0]}, {"do": "give"}] or None
@@ -743,6 +760,8 @@ def _clause_steps(c, markers, after=None):
if m and c != raw:
obj, col = _thing(m.group(1), m.group(2))
return [{"do": "pick", "object": obj, "colour": col}]
if after and after["do"] in ("pick", "receive") and re.fullmatch(r"(?:여기로\s*)?(?:(?:받아|집어) ?)?(?:가져와|가지고 ?와|갖고 ?와)", c):
return [{"do": "go", "to": "here"}] # "민수한테 컵 받아서 가져와": as "bring it here"
if c in ("bring it back to me", "bring it to me", "bring it back") or \
re.fullmatch(r"(?:나한테|저한테|나에게|저에게)\s*(?:가져와|가져다 ?줘|가져와서|가져다 ?주고|가져다|갖다 ?줘|갖다)"
r"(?:요| ?주세요)?", c):
@@ -769,10 +788,83 @@ def _clause_steps(c, markers, after=None):
if hand and hand[0] == "receive" and not (after and re.match(r"(?:just )?(?:hold|keep)\b|.*들고 ?있", c)) \
and not re.search(r"누가|누군가|someone|somebody|something|anything|things|주면|gives?\b", c):
return [{"do": "receive", "object": hand[1], "from_hand": True}] # "take this from me", "이거 받아": from the person's hand
m = re.fullmatch(rf"(?:find|look for|search for|locate|look around for) (?:the |a |an |my )?(?:({COL}) )?({OBJ})s?|"
rf"(?:(?:{COL})\s*)?(?:{OBJ})\s*(?:을|를)?\s*찾(?:아서|고|아 ?가지고)", c)
if m: # "find the red cup and bring it to me": the pick looks around
t = re.search(rf"(?:({COL})\s*)?({OBJ})", c)
obj, col = _thing(t.group(1), t.group(2))
return [{"do": "pick", "object": obj, "colour": col}]
m = re.fullmatch(r"(.+?)(?:으로|로|에) (?:가져가|가지고 가|갖고 가|들고 가)(?:서| 줘)?", c)
if m and (to := _places(m.group(1), markers)) and len(to) == 1:
return [{"do": "go", "to": to[0]}] # "피사로 가져가": as "take it to p4"
s = _place_at(c, markers) or _fetch_clause(c, markers)
if s:
return s
s = _place_step(c) or _say(c)
return [s] if s else None
_PUT_KO = r"(?:놔|놓아|놓고|내려놔|내려 ?놓고|둬|두고|놔두고|놔둬|올려 ?놔|올려 ?놓고)"
_GIVE_AT_KO = r"(?:갖다 ?주고|갖다 ?줘|가져다 ?주고|가져다 ?줘|갖다 ?드리고|갖다 ?드려|전해 ?주고|전해 ?줘|배달해 ?주고|배달해)"
def _place_at(c, markers):
""""put it on p3", "deliver the cup to p5", "컵을 p5에 갖다 놓고", "p3에 갖다 줘": (the named thing picked here,) a
drive there, then put down (put / leave / 놔) or handed over (deliver / 갖다 줘). None otherwise."""
m = re.fullmatch(rf"(put|place|set|leave|drop|deliver|drop off) (?:it|that|this|the ((?:(?:{COL}) )?(?:{OBJ}))s?)"
r"(?: down| off)? (?:on|at|in|to) (?:the )?(.+?)", c)
if m:
verb, thing, where = m.groups()
else:
m = re.fullmatch(rf"(?:(?:이거|그거|이걸|그걸|((?:(?:{COL})\s*)?(?:{OBJ}))(?:을|를)?)\s+)?(.+?)(?:에다가?|에|로|으로) "
rf"(?:(갖다|가져다|가져가서) ?)?({_PUT_KO}|{_GIVE_AT_KO})(?: 줘| 주고)?", c)
if not m or (m.group(4) in ("갖다 줘", "갖다줘", "가져다 줘", "가져다줘") and not m.group(1)):
return None # "p3에 갖다 줘" alone: a fetch / give, not this
thing, where = m.group(1), m.group(2)
verb = "put" if re.fullmatch(_PUT_KO, m.group(4)) else "deliver"
to = _places(where, markers)
if not to or len(to) != 1 or to == ["here"]:
return None
pick = []
if thing:
t = re.fullmatch(rf"(?:({COL})\s*)?({OBJ})", thing.strip())
obj, col = _thing(t.group(1), t.group(2))
pick = [{"do": "pick", "object": obj, "colour": col}]
return pick + [{"do": "go", "to": to[0]}, {"do": "give"} if verb == "deliver" else {"do": "place", "on": None}]
_FETCH_VERB = re.compile(r"\b(?:bring|fetch|get|carry|move)\b|가져|갖다|가지고|갖고|옮겨")
def _fetch_clause(c, markers):
"""A whole fetch said as one part of several ("bring me the cup from p2 and then go home", "p1에서 병 가져다 p2에
놔 주고 ..."): brain.parse_fetch's reading as steps, only when it names the object and every place it names."""
if not _FETCH_VERB.search(c) or brain.not_an_order(c, asked=True) or not (
re.match(r"(?:(?:please|just|go and|go) )?(?:bring|fetch|get|carry|move|take|grab)\b", c) or
re.search(r"(?:가져와|가져와서|가져다 ?(?:줘|주고|놔|놓고)?|가져다가|갖다 ?(?:줘|주고|놔|놓고)|갖다가|가지고 ?와(?:서)?|"
r"갖고 ?와(?:서)?|챙겨 ?와(?:서)?|옮겨(?: ?줘| ?주고| ?와| ?놔)?|들고 ?와(?:서)?|주시고|(?<!갖)(?<!가지)고)$", c)):
return None # an order said now, not "did you bring ...", "I'll bring ..."
c = re.sub(r"(?<=[가-힣]) ?고$", " 주고", c) if re.search(r"(?:갖다|가져다)고$", c) else c # "가져다 주시고" (_HONORIFIC)
task, problems = brain.parse_fetch(c, markers)
src, dest = task["source"], task["dest"]
if problems == ["dest"] and isinstance(src, dict) and re.search(r"(?:다가|서|고)$", c):
return [{"do": "go", "to": src["marker"]}, {"do": "pick", "object": task["object"], "colour": task["colour"],
**({"prefer": task["prefer"]} if task.get("prefer") else {})}] # "p1에서 컵 가져다가 | p3에 놔"
if problems or src == "here" and dest == "here":
return None
out = [{"do": "go", "to": src["marker"]}] if isinstance(src, dict) else []
out.append({"do": "pick", "object": task["object"], "colour": task["colour"],
**({"prefer": task["prefer"]} if task.get("prefer") else {})})
out.append({"do": "go", "to": dest["marker"] if isinstance(dest, dict) else "here"} |
({"implied": True} if dest == "here" and re.search(r"(?:와서|다가|가지고|갖고)$", c) else {})) # "가져와서 | p6로": no
# trip back first
if task["finish"] == "place":
out.append({"do": "place", "on": None})
elif dest == "here" and not re.search(r"(?:와서|다가|가지고|갖고)$", c): # "가져와서 | p3에 있는 사람한테 줘"
out.append({"do": "give", "fetch_give": True}) # handed over only when more follows (rules); the plain fetch
return out # holds it here
# ---------- whole commands ----------
_STEP_VERB = (r"(?:go|come|drive|head|return|give|hand|put|place|set|leave|take|pick|grab|get|bring|carry|turn|move|"
r"wait|hold|keep|open|close|reach|fold|receive|ask|find|look for)\b")
@@ -801,8 +893,9 @@ def _split(t, markers=()):
for part in _SPLIT.split(t):
pieces = []
for p in _SPLIT_KO.split(part):
if pieces and ends and re.search(rf"(?<![가-힣])(?:{'|'.join(ends)})$", pieces[-1]):
pieces[-1] += " " + p
if pieces and ends and re.search(rf"(?<![가-힣])(?:{'|'.join(ends)})$", pieces[-1]) or \
pieces and re.search(r"(?:갖고|가지고)$", pieces[-1]) and re.match(r"(?:와|오)", p):
pieces[-1] += " " + p # "갖고 와": one verb (bring), not "take it | come"
else:
pieces.append(p)
out += [p for p in pieces if p.strip()]
@@ -851,6 +944,11 @@ def _pieces(c, markers, after):
def rules(text, markers=()):
"""(steps, unread clauses). Steps are merged where two clauses mean one ("look for the table" + "put it there")."""
text = re.sub(r"(?<=[가-힣A-Za-z0-9])(으로|로|에)(가서|가고|가면)(?=[가-힣])", r"\1 \2 ", text or "") # written without
if re.search(r"[가-힣]{9,}", text): # Korean written without spaces: "피사에가서5분있다가다시오세요"
text = re.sub(r"(실례지만|죄송한데요|가서|와서|돌고|있다가|기다렸다가|기다리고|갔다가|하고|해서|집어서|잡아서|집고|잡고|들고|"
r"받아서|받고|다시)(?=[가-힣\d])|(?<=[가-힣\d]에)(?=있는|계신)|(?<=있는|계신)(?=[가-힣])", r"\1 ", text)
text = re.sub(r"(?<=[가-힣])(?=\d)|(?<=\d[초분])(?=[가-힣])|(?<=다시)(?=[와오])|(?<=[아어와여해])(?=주(?:세요|시|라|십|실|게))",
" ", text)
cut, says = _cut_says(text) # spaces: "부스A로가서저희"
t = _protect_lists(_norm(cut, markers), markers)
t = _INTERJECTION.sub("", t)
@@ -889,6 +987,8 @@ def rules(text, markers=()):
steps.append(s)
steps = [s for i, s in enumerate(steps) # "bring it" then a place to go: no trip back first
if not (s.pop("implied", False) and i + 1 < len(steps) and steps[i + 1]["do"] == "go")]
steps = [s for i, s in enumerate(steps) if not (s.pop("fetch_give", False) and
(i == len(steps) - 1 or steps[i + 1]["do"] in ("wait", "place")))]
steps, unread = _people(steps, unread, text)
if steps and not unread and all(s["do"] == "wait" for s in steps):
return [], [text.strip()] # "hold on a second", "wait here": talk to me, not a task
+4 -4
View File
@@ -29,11 +29,11 @@ LOUDER = re.compile(r"\blouder\b|\bspeak up\b|\b(?:can'?t|cannot|can not|couldn'
r"(?:소리|목소리)\S*\s*너무\s*작", re.I)
QUIETER = re.compile(r"\bquieter\b|\bsofter\b|\btoo loud\b|\bnot so loud\b|\bless loud\b|\bso loud\b|"
r"\b(?:lower|turn down|drop) (?:your |the )?(?:voice|volume|sound)\b|\b(?:volume|sound) down\b|"
r"\bturn (?:it |yourself )?down\b|\b(?:speak|talk) (?:more )?(?:quietly|softly)\b|"
r"작게|시끄러|(?:소리|볼륨|목소리)\s*(?:를|을|좀|\s)*(?:줄여|낮춰|내려)|(?:소리|목소리)\S*\s*너무\s*커", re.I)
r"\bturn (?:it |yourself )?down\b|\btone (?:it |yourself )?down\b|\b(?:speak|talk) (?:more )?(?:quietly|softly)\b|"
r"작게|조용조용|조곤조곤|소곤소곤|시끄러|(?:소리|볼륨|목소리)\s*(?:를|을|좀|\s)*(?:줄여|낮춰|내려)|(?:소리|목소리)\S*\s*너무\s*커", re.I)
VOICE = re.compile(r"\b(?:speak|speaking|talk|talking|say|saying|said|voice|speech|words)\b|말|얘기|이야기|목소리", re.I)
SLOW = re.compile(r"\b(?:slower|slowly|slow down)\b|천천히|느리게|느릿", re.I)
FAST = re.compile(r"\b(?:faster|quicker|quickly|speed up)\b|빨리|빠르게", re.I)
SLOW = re.compile(r"\b(?:slower|slowly|slow down)\b|천천히|느리게|느릿|슬로우하게|슬로우리", re.I)
FAST = re.compile(r"\b(?:faster|quicker|quickly|speed up)\b|빨리|빠르게|패스트하게|퀵하게", re.I)
TOO_FAST = re.compile(r"\b(?:too|so) fast\b|(?:너무|넘)\s*빨라|빠르네|빨라요", re.I)
TOO_SLOW = re.compile(r"\b(?:too|so) slow(?:ly)?\b|(?:너무|넘)\s*느려|느리네|느려요", re.I)
DRIVE = re.compile(r"\b(?:go|going|drive|driving|move|moving|walk|come|run|follow|forward)\b|"
+44 -9
View File
@@ -20,7 +20,10 @@ EN_NUM = {"one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven
"ten": 10, "eleven": 11, "twelve": 12}
KO_EN_NUM = {"원": 1, "투": 2, "쓰리": 3, "스리": 3, "뜨리": 3, "트리": 3, "포": 4, "파이브": 5, "화이브": 5,
"식스": 6, "씩스": 6, "세븐": 7, "쎄븐": 7, "에잇": 8, "에이트": 8, "나인": 9, "텐": 10, "일레븐": 11,
"트웰브": 12} # English numbers said in Korean ("피쓰리", "포인트 원")
"트웰브": 12, "써틴": 13, "서틴": 13, "포틴": 14, "피프틴": 15, "휘프틴": 15, "식스틴": 16, "세븐틴": 17,
"에이틴": 18, "나인틴": 19} # English numbers said in Korean ("피쓰리", "포인트 원")
KO_EN_TENS = {"트웬티": 20, "트웨니": 20, "써티": 30, "서티": 30, "포티": 40, "피프티": 50, "휘프티": 50, "식스티": 60,
"세븐티": 70, "에이티": 80, "나인티": 90} # before a unit only (numbers): "에이티 센티"
NATIVE = {"한": 1, "두": 2, "세": 3, "네": 4, "다섯": 5, "여섯": 6, "일곱": 7, "여덟": 8, "아홉": 9, "열": 10}
SINO = {"일": 1, "이": 2, "삼": 3, "사": 4, "오": 5, "육": 6, "륙": 6, "칠": 7, "팔": 8, "구": 9}
_D = "[일이삼사오육륙칠팔구]"
@@ -112,6 +115,12 @@ def markers(t):
def numbers(t):
"""Distances and angles in lower-case text -> digits and metres: "half a meter" -> "0.5 m", "오십 센치" -> "0.5 m",
"일 미터 반" -> "1.5 m", "구십 도" -> "90도"."""
t = re.sub(rf"(?<![가-힣])(?:({'|'.join(KO_EN_TENS)})\s?)?({'|'.join(sorted(KO_EN_NUM, key=len, reverse=True))})?"
rf"(?<=[가-힣])\s*(?=(?:{UNIT}|도|degrees?|디그리스?)(?![a-z가-힣]))",
lambda m: f"{KO_EN_TENS.get(m.group(1), 0) + KO_EN_NUM.get(m.group(2), 0)} "
if m.group(1) or m.group(2) else m.group(0), t)
# Konglish amounts: "텐 센치", "에이티 센티", "트웬티 파이브 도"
t = re.sub(r"(\d+)\s*디그리스?(?![가-힣])", r"\1도", t) # "피프틴 디그리"
t = re.sub(r"\bone and a half\b", "1.5", t)
t = re.sub(rf"\b({'|'.join(TENS)})(?:[ -]({'|'.join(list(EN_NUM)[:9])}))?\b",
lambda m: str(TENS[m.group(1)] + EN_NUM.get(m.group(2), 0)), t)
@@ -122,7 +131,7 @@ def numbers(t):
lambda m: str(1000 * _num(m.group(1)) if m.group(1) else 1000), t) # "a thousand", "five thousand"
t = re.sub(rf"\b([2-9]|{'|'.join(list(EN_NUM)[1:9])}) hundred(?: and)?(?: (\d+))?\b",
lambda m: str(100 * _num(m.group(1)) + int(m.group(2) or 0)), t) # "two hundred and fifty"
t = re.sub(rf"\b({'|'.join(TEEN)}|eleven|twelve)\b(?=\s*{UNIT}(?![a-z]))",
t = re.sub(rf"\b({'|'.join(TEEN)}|eleven|twelve)\b(?=\s*(?:{UNIT}(?![a-z])|degrees?\b|도(?![가-힣])))",
lambda m: str(TEEN.get(m.group(1)) or EN_NUM[m.group(1)]), t) # "fifteen centimetres"
t = re.sub(r"\b(?:a|one) hundred(?: and)? (\d+)\b", lambda m: str(100 + int(m.group(1))), t)
t = re.sub(r"\b(?:a|one) hundred\b", "100", t)
@@ -143,11 +152,16 @@ def numbers(t):
t = re.sub(rf"(?:(?<=으로)|(?<=로))\s*({_SINO})\s*도(?![가-힣])", lambda m: f" {sino(m.group(1))}도", t)
t = re.sub(rf"(?<![가-힣\d])({_SINO})\s*도(?=\s+(?:왼쪽|오른쪽|뒤로|돌))", lambda m: f"{sino(m.group(1))}도", t)
t = re.sub(r"(\d+)\s*degrees?(?=\s*[가-힣])", r"\1도", t) # "왼쪽으로 45 degrees 돌아"
t = re.sub(r"(?<![\d.])(\d+) 도(?=\s+(?:왼|오른|위|아래|밑|좌|우|뒤|돌|회전|틀|꺾))", r"\1도", t) # "고개를 90 도 오른쪽으로"
t = re.sub(rf"(?:^|(?<=으로)|(?<=[~,\s몸]))({_SINO})\s*도(?=\s*(?:왼|오른|좌|우|회전|돌|틀|꺾|만|쯤|정도|얼른|빨리|천천히|살짝|좀|퍼뜩|언능))",
lambda m: f"{sino(m.group(1))}도 ", t) # written together: "왼쪽으로십오도회전해"
t = re.sub(r"(?<![\d.])(\d+) ?(?:m|미터)\s?([1-9])0(?![\d.]|\s*(?:센|cm|밀|mm|미|m\b|도))(?=\s*(?:만|쯤|정도)?\s*(?:[가-힣]|$))",
lambda m: f"{m.group(1)}.{m.group(2)} m", t) # "1미터 50" is 1.5 m
t = re.sub(rf"\bhalf (?:a |an )?{UNIT}", "0.5 m", t)
t = re.sub(rf"반\s*{UNIT}", "0.5 m", t)
for w, d in NUM_WORDS.items():
if w.isascii():
t = re.sub(rf"\b{w}\b(?=\s*(?:{UNIT}(?![a-z])|degrees?|and a (?:half|0\.5)))", d, t) # "one meter", "a meter"
t = re.sub(rf"\b{w}\b(?=\s*(?:{UNIT}(?![a-z])|degrees?|도(?![가-힣])|and a (?:half|0\.5)))", d, t) # "one meter", "a meter"
else:
t = re.sub(rf"(?<![가-힣]){w}\s*(?={UNIT})", d + " ", t)
t = re.sub(rf"(?<![\d.])0(\d)\s*(?={UNIT}(?![a-z]))", r"0.\1 ", t) # whisper's "05 meters": 0.5 m
@@ -274,7 +288,7 @@ ASR_SLIPS = [ # how whisper writes Korean commands (tests/asr_check.py, 2026-1
(r"([a-z0-9])\.?\s+(으로|로)\s*(?=가|와|이동|돌아)", r"\1\2 "), # "P3. 로가줘", "final point. 로 가": one word
(r"(?<=로)\s*가죠(?![가-힣])", " 가 줘"), # "p3로 가 줘" written "p3로 가죠"
(r"\blook (?:last|lest|less)(?=[\s.!,]*$)", "look left"), (r"\bdoc t\b", "dock 2"), # said at the end
(r"고게(?=\s*(?:들|숙))", "고개"), (r"찝어", "집어"), (r"파이나(?=\s*(?:갔|가|로))", "파이널"),
(r"고게(?=\s*(?:들|숙)|[를는도가]?\s)", "고개"), (r"찝어", "집어"), (r"파이나(?=\s*(?:갔|가|로))", "파이널"),
# the owner's English as whisper wrote it live (logs/lumi.log 2026-10-21 / 22)
(r"\bcount to(?= p\s?\d)", "come to"), # "Let's count to p5."
# the head up / down, said or heard loosely (2026-10-23 15:08-15:16: "Look at the bellow.", "Look it up.")
@@ -296,6 +310,10 @@ ASR_SLIPS = [ # how whisper writes Korean commands (tests/asr_check.py, 2026-1
_NO = r"(?<![가-힣a-z])"
KONGLISH = [ # English direction words said in Korean -> the Korean word ("레프트로 반 미터 가 줘요", "라이트 턴 해")
(r"왼쭉|왼족", "왼쪽"), (r"멈처|멈쳐", "멈춰"), (r"슴니(?=다|까)", "습니"), (r"(?<![가-힣])야루미", "야 루미"),
(r"(?:쉐|셰)이크 ?핸즈?|핸드 ?쉐이크", "악수"), (r"(?<![가-힣])히어로(?= ?(?:와|오|가까이))", "이리로"),
(r"리프트 ?다운(?: ?(?:해|하(?:게나?|세요|십시오|시게|시오)?))?(?=\s|$|[?.!~,])", "몸 내려"),
(r"리프트 ?업(?: ?(?:해|하(?:게나?|세요|십시오|시게|시오)?))?(?=\s|$|[?.!~,])", "몸 올려"), # read by norm and ko_plain
(_NO + r"레프트\s*(?:쪽으로|으로|로|쪽)?", "왼쪽으로 "),
(_NO + r"라이트\s*(?:쪽으로|으로|로|쪽)(?![가-힣])|" + _NO + r"라이트(?=\s*(?:턴|turn|무브|move|\d|반\s*미터))",
"오른쪽으로 "), # "라이트 켜" is a light
@@ -311,6 +329,7 @@ KONGLISH = [ # English direction words said in Korean -> the Korean word ("레
(r"(고개|머리|헤드|얼굴)\s*(?:를|을)?\s*업(?![가-힣])", r"\1 들어"),
(r"(고개|머리|헤드|얼굴)\s*(?:를|을)?\s*다운(?![가-힣])", r"\1 숙여"),
(_NO + r"헤드(?=\s)", "고개"),
(_NO + r"웨이스트(?=\s|를|을|는|가)", "허리"),
]
@@ -415,8 +434,17 @@ _END_NOT_ASKED = r"(?=(?:\s+(?:빨리|얼른|어서|좀|제발|당장|지금|ple
_HON = r"(?:세요|세용|세여|십시오|시오|셔요|시죠|실래요|실래|시겠어요|시겠습니까|시겠어|시게|이소(?:마|예)?|거라|너라|렴|라고요?|랑께요?|래이|이라|쇼|시라|시지요|실래예|씨요|세예)"
_LOOK_AT = r"(왼쪽|오른쪽|위|위쪽|아래|아래쪽|뒤|뒤쪽|앞|하늘|천장|바닥|여기|이쪽|저쪽|나|날|저|정면|좌측|우측)"
KO_PLAIN = [
*((re.compile(a), b) for a, b in KONGLISH[:8]), # slips / Konglish above
(re.compile(r"(?<=[가-힣?!.~]) +(?:허허|하하|헤헤|호호|히히|ㅋ+|ㅎ+)[\s!.~]*$"), ""), # a laugh after it: "돌아 봐요 허허"
(re.compile(r"(?<![가-힣])(?:퍼뜩|퍼떡|언능|얼렁|싸게싸게)(?![가-힣])"), "빨리"), # dialect "quickly"
(re.compile(r"(?<=봐) 봐(?=\s*(?:[,.!?~…]|$))"), ""), # "돌아가 봐 봐": once
(re.compile(r"(?<=[려어아여]) (?:좀|한 ?번) (?=놔|놓|둬|두)"), " "), # "컵 내려 좀 놔 줘": a softener
(re.compile(r"(?<=[가-힣])게나(?=\s*(?:[,.!?~…]|$))"), "게"), # 하게체 "이동하게나", "주게나"
(re.compile(r"겄슈|겄어유|겠슈"), "겠어요"), (re.compile(r"(?<=[가-힣])세유(?=\s*(?:[,.!?~…]|$))"), "세요"), # 충청
(re.compile(r"(?<![가-힣])(\S*?[가-힣])(?:으)?(?:시겠어요|시겠습니까|시겠어|실래요|실래)\s*\?"), "STEMQ"),
# "회전하시겠어요?": please turn
(re.compile(r"(?<=아니 )(\S+?)(?:이요|요)(?=\s*(?:[,.!?~…]|$))"), r"\1"), # "아 아니 정면이요": the noun
(re.compile(r"오른쭉|오른족"), "오른쪽"), (re.compile(r"(?<![가-힣])외쪽"), "왼쪽"), (re.compile(r"고게(?= )"), "고개"),
(re.compile(r"오른쭉|오른족"), "오른쪽"), (re.compile(r"(?<![가-힣])외쪽"), "왼쪽"), (re.compile(r"고게(?=[를는도가]?\s)"), "고개"),
(re.compile(r"(루미야|루미씨|루미 씨)(?=[가-힣])"), r"\1 "), # "루미야오른쪽 봐"
(re.compile(r"(?<![가-힣])쫌(?![가-힣])"), "좀"), (re.compile(r"(?<![가-힣])놉여"), "높여"),
(re.compile(r"(?<= )주드라(?:고|구)|(?<= )주드랑께"), "줘"), # 전라: "와 주드라고"
@@ -429,7 +457,10 @@ KO_PLAIN = [
(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*\??"),
"악수하자"), # shake hands = wave; 하게체 "악수하세"
(re.compile(r"(?<=[어아여해줘봐와가라자워려춰켜꺼놔둬]) (?:응|엉|알았지|알겠지|알았죠|알겠죠|오케이)"
r"\s*[?!.~]*(?=\s*$)"), ""), # a tag after the order: "고개 들어 응?"
(re.compile(r"(?<=[가-힣](?:라|자)) 마(?=\s*(?:[,.!?~…]|$))"), ""), # 경상: "팔 접어 봐라 마"
(re.compile(_LOOK_AT + r" ?(?:한번 )?(?:바|보게)(?= 주|\s*(?:[,.!?~]|$))"), r"\1 봐"), # whisper "왼쪽바", 하게체 "하늘보게"
(re.compile(r"(\S+) ?주면 안 (?:돼|될까|되나|되겠니|되겠어|되겠습니까)(?:요)?\s*\??" + r"(?=\s*(?:[,.!~…]|$))"), r"\1 줘?"),
@@ -473,7 +504,9 @@ def _stem_l(word):
if not j or j[2] != 8:
return None
stem = word[:-1] + _syl(j[0], j[1])
return {"드": "들", "도": "돌", "여": "열", "미": "밀", "내미": "내밀", "흔드": "흔들"}.get(stem, stem)
if stem.endswith("시") and len(stem) > 1 and stem not in ("다시",):
stem = stem[:-1].removesuffix("으") or stem # honorific: "트실 수" -> 트, "도실 수" -> 도, "집으실" -> 집
return {"드": "들", "도": "돌", "트": "틀", "여": "열", "미": "밀", "내미": "내밀", "흔드": "흔들"}.get(stem, stem)
def _can_you(m, kind):
@@ -508,12 +541,14 @@ def ko_plain(t):
for rx, to in KO_PLAIN:
if to in ("CAN_L", "CAN_N"):
t = rx.sub(lambda m: _can_you(m, to), t)
elif to == "STEM":
elif to in ("STEM", "STEMQ"):
def stem(m):
w = m.group(1)
if KO_SOCIAL_BEFORE.search(m.string[:m.start()]):
return m.group(0)
got = _stem_aform(w[:-1] if w.endswith("으") and len(w) > 1 and _jamo(w[-2]) and _jamo(w[-2])[2] else w)
if to == "STEMQ" and got:
return got + ("?" if got == "줘" else " 줘?")
return got if got else m.group(0)
t = rx.sub(stem, t)
else:
@@ -536,7 +571,7 @@ def norm(text, names=()):
"""Lower case, whisper's slips (ASR_SLIPS), Konglish directions (KONGLISH), numbers first ("point five meters" is
a distance), then marker names (names: the map's)."""
t = " " + (text or "").lower().replace("’", "'") + " "
t = re.sub(r"(\S+)[—–-]+\s*(?=\1)", "", t) # a stutter: "육십 센— 센티", "go ah— ahead"
t = re.sub(r"(?<!\S)(\S+)[—–-]+\s*(?=\1)", "", t) # a stutter: "육십 센— 센티", "go ah— ahead"
t = re.sub(r"(?<=[가-힣])(?=\d+(?:\.\d+)?\s*(?:미터|센티|센치|cm|m\b|도))", " ", t) # "오른쪽으로80센티미터"
for slip, said in ASR_SLIPS + KONGLISH:
t = re.sub(slip, said, t)