From 10bba17f4e2730ab6ddeb2ae9df4aa08acfb2421 Mon Sep 17 00:00:00 2001 From: Cutshion Date: Fri, 23 Oct 2026 12:38:04 +0900 Subject: [PATCH] =?UTF-8?q?Korean=20and=20Konglish=20amounts=20read=20exac?= =?UTF-8?q?tly:=20sino=20and=20native=20numbers=20(=EC=82=AC=20=EC=8B=AD?= =?UTF-8?q?=EC=98=A4,=20=EB=A7=88=ED=9D=94=EB=8B=A4=EC=84=AF),=20particles?= =?UTF-8?q?,=20decimals,=20=EB=A0=88=ED=94=84=ED=8A=B8=20/=20=EB=9D=BC?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8;=20a=20number=20without=20a=20unit=20is=20as?= =?UTF-8?q?ked;=20whisper's=20number=20and=20unit=20slips=20corrected?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- assistant/driving.py | 25 ++++++++- assistant/wording.py | 76 +++++++++++++++++++++++++-- tests/korean_numbers_cases.py | 98 +++++++++++++++++++++++++++++++++++ tests/test_korean_numbers.py | 47 +++++++++++++++++ tests/test_number_slips.py | 28 ++++++++++ 5 files changed, 267 insertions(+), 7 deletions(-) create mode 100644 tests/korean_numbers_cases.py create mode 100644 tests/test_korean_numbers.py create mode 100644 tests/test_number_slips.py diff --git a/assistant/driving.py b/assistant/driving.py index 747185b..5c4ab34 100644 --- a/assistant/driving.py +++ b/assistant/driving.py @@ -37,7 +37,7 @@ NEAR_THING = re.compile(r"(?:테이블|책상|탁자|의자|소파|문|벽|창 r"(?:앞|옆|뒤)(?:으?로|쪽|에)") # "테이블 앞으로", "무대 앞으로 가": to that thing or place, not forward OTHER = re.compile(r"\b(?:look|head|turn|spin|rotate|face|arm|hand|lift|raise|lower|it|this|that|them|those|these|here|there|" r"home|me|us)\b|\bthe (?!left\b|right\b)|\bgo (?:right )?ahead\b|\bback to (?![\d.])|\b[a-z]+\d+\b|\b[a-z]+(?:_[a-z0-9]+)+\b|고개|머리|팔|손|돌아|돌려|봐|보(?:세요|십시오|시오|실래요|자|라|아|여)|볼래|쳐다|들어|올려|내려|" - r"여기|저기|이리|집|\S(?:을|를)(?=\s)|도십시오|도세요|\d+(?:\.\d+)? ?도(?=\s|$)|" + NEAR_THING.pattern) + r"여기|저기|이리|집|\S(?:을|를)(?=\s)|도십시오|도세요|회전|\d+(?:\.\d+)? ?도(?:만|쯤|정도|가량)?(?=\s|$)|" + NEAR_THING.pattern) # the head, an object, a place # (p3, dock2, booth_9: a marker as written): not a short drive SAYER = re.compile(r"\b(?:i|i'm|im|i'll|i've|we|we're|he|she|they|there|it's|it is|my|our|his|her|their|was|were|" @@ -56,6 +56,14 @@ VAGUE = re.compile(r"\b(?:more|less|longer|further|farther|bit more|bit less) th 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") +KO_NUM_WORD = re.compile(r"(? 1 or m.group(1) in "십백" else m.group(0), t) t = re.sub(rf"(? the Korean word ("레프트로 반 미터 가 줘요", "라이트 턴 해") + (_NO + r"레프트\s*(?:쪽으로|으로|로|쪽)?", "왼쪽으로 "), + (_NO + r"라이트\s*(?:쪽으로|으로|로|쪽)(?![가-힣])|" + _NO + r"라이트(?=\s*(?:턴|turn|무브|move|\d|반\s*미터))", + "오른쪽으로 "), # "라이트 켜" is a light + (_NO + r"포워드\s*(?:쪽으로|으로|로|쪽)?", "앞으로 "), + (_NO + r"백\s*(?:쪽으로|으로|쪽)(?![가-힣])|" + _NO + r"백(?=\s+(?:\d|반\s*미터|무브|move|고(?![가-힣])|해(?![가-힣])))", + "뒤로 "), # "백 미터", "백팔십" stay numbers + (r"(?:" + _NO + r"턴|(?<=으로 )turn\b)(?:\s*(?:해|해요|해라|하세요|하십시오|해\s*줘|해\s*주세요|해\s*줄래요?))?(?![가-힣])", + "돌아"), # "왼쪽으로 턴 해", "왼쪽으로 turn 해" + (r"(?:" + _NO + r"무브|(?:(?<=미터 )|(?<=센티 )|(?<=센치 )|(?<=cm )|(?<=\dm )|(?<=으로 ))고|" + _NO + r"고\s*고)(?:\s*(?:해|해요|하세요|해\s*줘|해\s*주세요))?(?![가-힣])", + "이동해"), # "고" alone is a particle / a place's "go": after a way only + (r"(고개|머리|헤드|얼굴)\s*(?:를|을)?\s*업(?![가-힣])", r"\1 들어"), + (r"(고개|머리|헤드|얼굴)\s*(?:를|을)?\s*다운(?![가-힣])", r"\1 숙여"), + (_NO + r"헤드(?=\s)", "고개"), +] + + +_DIR = r"(?:forward|backwards?|back|left|right|앞으로|뒤로|왼쪽|오른쪽|옆으로)" +_AMOUNT = r"(?:(?:\d+(?:\.\d+)?|one|two|three|four|five|six|seven|eight|nine|ten|and|a|half)\s+)+" +# whisper's slips of amounts in a move (tests/asr_check.py set 5, blind train hearing; 2026-10-23). Each needs a move +# direction in the text (MOVE_SAID); none guesses a lost digit: "1.m" (1.5미터 with the 5 dropped) becomes "1점 몇 m", +# which is asked ("how far?") instead of driving 1 m. +NUMBER_SLIPS = [ + (r"(? "move left 0.5" | "turn right 45" | "look left 20" | "lift up" | "ask" (a number with no unit, or a +unit that doesn't fit: never a guess). NORM: said -> what wording.norm must write. SAID: intent_bank.said_amount. +""" +import itertools + +# ---------- spoken amounts ---------- +METRES = { # said -> metres + "일 미터": 1, "이 미터": 2, "1미터": 1, "1 미터": 1, "1.5미터": 1.5, "일 점 오 미터": 1.5, "영 점 오 미터": 0.5, + "1미터 반": 1.5, "일 미터 반": 1.5, "반 미터": 0.5, "1m 50cm": 1.5, "150센티": 1.5, "백오십 센티": 1.5, + "오십 센티": 0.5, "오십 센치": 0.5, "50cm": 0.5, "이십 센티": 0.2, "스무 센티": 0.2, "열 센티": 0.1, + "삼십 센치": 0.3, "서른 센티": 0.3, "사 십 센티": 0.4, "칠십오 센티": 0.75, "두 미터": 2, "1.5 meter": 1.5, + "30 cm": 0.3, "마흔 센티": 0.4, "열다섯 센티": 0.15, "이십오 센티미터": 0.25, "일 미터 오십 센티": 1.5, +} +DEGREES = { # said -> degrees + "십오 도": 15, "사십오 도": 45, "사 십오 도": 45, "마흔다섯 도": 45, "서른 도": 30, "스무 도": 20, "열 도": 10, + "삼십 도": 30, "육십 도": 60, "구십 도": 90, "45도": 45, "30 degrees": 30, "백이십 도": 120, "열다섯 도": 15, + "십 도": 10, "이십 도": 20, "예순 도": 60, "칠십 도": 70, "삼 십 도": 30, "60도": 60, +} +ABOUT = ["", "만", "쯤"] # "30센티만", "45도쯤": still that amount + +MOVE_DIRS = {"앞으로": "forward", "뒤로": "back", "왼쪽으로": "left", "오른쪽으로": "right", + "레프트로": "left", "라이트로": "right", "포워드로": "forward", "백으로": "back"} +MOVE_FORMS = ["{d} {a}{p} 가", "{d} {a}{p} 이동해 주세요"] +TURN_DIRS = {"왼쪽으로": "left", "오른쪽으로": "right", "레프트로": "left"} +TURN_FORMS = ["{d} {a}{p} 돌아", "{d} {a}{p} 돌아 줘", "{d} {a}{p} 회전해", "{d} {a}{p} 턴 해"] +LOOK_FORMS = ["고개 {d} {a}{p} 돌려", "고개를 {d} {a} 돌려 줘", "{d} {a}{p} 봐"] +LOOK_DIRS = {"왼쪽으로": "left", "오른쪽으로": "right"} + + +def _moves(): + out = {} + for (d, dw), (a, n), p, f in itertools.product(MOVE_DIRS.items(), METRES.items(), ["", "만"], MOVE_FORMS): + if n <= 3: + out[f.format(d=d, a=a, p=p)] = f"move {dw} {n:g}" + return out + + +def _turns(): + out = {} + for (d, dw), (a, n), p, f in itertools.product(TURN_DIRS.items(), DEGREES.items(), ABOUT, TURN_FORMS): + out[f.format(d=d, a=a, p=p)] = f"turn {dw} {n:g}" + return out + + +def _looks(): + out = {} + for (d, dw), (a, n), p, f in itertools.product(LOOK_DIRS.items(), DEGREES.items(), ["", "만"], LOOK_FORMS): + if n <= 90: + out[f.format(d=d, a=a, p=p)] = f"look {dw} {n:g}" + return out + + +ROUTE = {**_moves(), **_turns(), **_looks(), **{ + # Konglish and mixed + "레프트로 반 미터 가 줘요": "move left 0.5", "라이트 턴 해": "turn right 90", "레프트 턴": "turn left 90", + "라이트로 턴": "turn right 90", "레프트 턴 해 줘": "turn left 90", "라이트로 1미터 무브": "move right 1", + "포워드 1미터 고": "move forward 1", "백 1미터": "move back 1", "앞으로 1미터 고": "move forward 1", + "turn left 45도": "turn left 45", "왼쪽으로 30 degrees 돌아": "turn left 30", "앞으로 1.5 meter 가": "move forward 1.5", + "왼쪽으로 turn 해": "turn left 90", "라이트로 45도 턴": "turn right 45", "레프트로 마흔다섯 도 턴 해": "turn left 45", + "move left 반 미터": "move left 0.5", "go forward 일 미터": "move forward 1", "turn right 서른 도": "turn right 30", + "고개 업": "look up", "고개 다운": "look down", "머리 업": "look up", "헤드 다운": "look down", + "고개 레프트로 돌려": "look left", "레프트 봐": "look left", "리프트 업": "lift up", "리프트 다운": "lift down", + "백으로 50센티 가": "move back 0.5", "포워드로 1미터 가": "move forward 1", + # whole turns, English + "백팔십 도 돌아": "turn around 180", "turn right 90 degrees": "turn right 90", + "turn left forty five degrees": "turn left 45", "move forward 1.5 meters": "move forward 1.5", + "앞으로 다섯 걸음 가": "move forward 2.5", "뒤로 한 걸음": "move back 0.5", + # no unit, or a unit that doesn't fit: asked + "앞으로 다섯만 가": "ask", "앞으로 다섯 가": "ask", "뒤로 셋 가": "ask", "앞으로 30 가": "ask", + "왼쪽으로 서른만 가": "ask", "앞으로 삼십만 가": "ask", "앞으로 30도 가": "ask", "뒤로 45도만 가": "ask", + "왼쪽으로 1미터 돌아": "ask", "오른쪽으로 50센티 돌아": "ask", "왼쪽으로 서른만 돌아": "ask", + "왼쪽으로 30 돌아": "ask", "오른쪽으로 30만 돌아": "ask", "왼쪽으로 삼십만 돌아": "ask", "오른쪽으로 열만 돌아": "ask", + "레프트로 다섯 가": "ask", "라이트로 30만 턴": "ask", +}} + +NORM = { + "사 십오 도": "45도", "삼백 육십 도": "360도", "마흔다섯 도": "45 도", "스무 센티": "0.2 m", "일 점 오 미터": "1.5 m", + "1미터 반": "1.5 m", "1m 50cm": "1.5 m", "150센티": "1.5 m", "반 미터": "0.5 m", "열 센티": "0.1 m", + "레프트로 반 미터": "왼쪽으로 0.5 m", "라이트 턴 해": "오른쪽으로 돌아", "포워드 1미터 고": "앞으로 1 m 이동해", + "백 미터 달리기": "100 m 달리기", "백팔십 도": "180도", "라이트 켜 줘": "라이트 켜 줘", "고개 업": "고개 들어", + "백 1미터": "뒤로 1 m", "이번에": "이번에", "한 번 더": "한 번 더", +} + +SAID = { # intent_bank.said_amount: (metres, degrees) + "왼쪽으로 사 십오 도": (None, 45), "마흔다섯 도": (None, 45), "일 점 오 미터": (1.5, None), "1미터 반": (1.5, None), + "150센티": (1.5, None), "1m 50cm": (1.5, None), "반 미터": (0.5, None), "스무 센티": (0.2, None), + "a quarter of a meter": (0.25, None), "a hundred and eighty degrees": (None, 180), "삼십 도": (None, 30), +} + +STEPS = { # assistant/steps.rules: the steps read whole + "앞으로 사 십 센티 가고 왼쪽으로 마흔다섯 도 돌아": [{"do": "move", "dir": "forward", "m": 0.4}, {"do": "turn", "deg": 45.0}], + "레프트로 반 미터 가고 라이트로 서른 도 돌아": [{"do": "move", "dir": "left", "m": 0.5}, {"do": "turn", "deg": -30.0}], + "p3로 가서 오른쪽으로 사 십오 도 돌아": [{"do": "go", "to": "p3"}, {"do": "turn", "deg": -45.0}], + "뒤로 일 미터 반 가고 오른쪽으로 스무 도 돌아": [{"do": "move", "dir": "back", "m": 1.5}, {"do": "turn", "deg": -20.0}], +} diff --git a/tests/test_korean_numbers.py b/tests/test_korean_numbers.py new file mode 100644 index 0000000..2bb6251 --- /dev/null +++ b/tests/test_korean_numbers.py @@ -0,0 +1,47 @@ +"""Self-check: amounts and directions in Korean, Konglish and mixed (tests/korean_numbers_cases.py) read exactly by +wording.norm, the route lumi.answer() takes before the LLM and intent_bank.said_amount; a number +without a fitting unit is asked. No robot: python tests/test_korean_numbers.py""" +import math + +from assistant import brain, intent_bank, steps, wording +from tests import command_check +from tests.korean_numbers_cases import NORM, ROUTE, SAID, STEPS + +M = ["home", "p3", "dock2"] +B = brain.Brain() + + +def route(text): + """lumi.answer()'s route before the LLM (tests/command_check.rules): 'move left 0.5' | 'turn right 45' | + 'look left 20' | 'lift up' | 'ask' | None (left to the LLM).""" + got = command_check.rules(text, "idle", M, B) + return got[len("action:"):] if got and got.startswith("action:") else got + + +def main(): + bad = [] + for said, want in NORM.items(): + got = wording.norm(said) + if want not in got: + bad.append(f"norm {said!r}: {got!r}, want {want!r}") + for said, want in SAID.items(): + got = intent_bank.said_amount(said) + if not all(a == b or (a is not None and b is not None and math.isclose(a, b)) for a, b in zip(got, want)): + bad.append(f"said_amount {said!r}: {got}, want {want}") + for said, want in ROUTE.items(): + got = route(said) + if got != want: + bad.append(f"route {said!r}: {got}, want {want}") + for said, want in STEPS.items(): + got = steps.rules(said, M) + if got != (want, []): + bad.append(f"steps {said!r}: {got}, want {want}") + for b in bad: + print(b) + n = len(NORM) + len(SAID) + len(ROUTE) + len(STEPS) + print(f"{n - len(bad)}/{n} right") + assert not bad + + +if __name__ == "__main__": + main() diff --git a/tests/test_number_slips.py b/tests/test_number_slips.py new file mode 100644 index 0000000..6697065 --- /dev/null +++ b/tests/test_number_slips.py @@ -0,0 +1,28 @@ +"""Self-check of whisper's number / unit slips read right in a move (assistant/wording.py number_slips), and words +that must stay as they are. python tests/test_number_slips.py""" +from assistant import wording + +CASES = { + "앞으로 1.m가": "앞으로 1점 몇 m가", # 1.5미터 with the 5 lost: asked, never 1 m + "앞으로 1미가": "앞으로 1 m 가", + "1m50cm 뒤로 가.": "1.5 m 뒤로 가.", + "move back 30 centuries.": "move back 0.3 m.", + "왼쪽으로 30세트 가죠?": "왼쪽으로 0.3 m 가죠?", + "뒤로 40센터만 가주세요.": "뒤로 0.4 m만 가주세요.", + "you go forward 50 cent letter please.": "you go forward 0.5 m please.", + "left. 30cm가.": "left 0.3 m가.", + "go forward two years.": "go forward 2 m.", + "go back one and a half years.": "go back 1.5 m.", + "go forward. forward to me.": "go forward. forward 2 m.", + "move to p3 weight p8": "move to p3, wait, p8", + # not a move or not a slip: kept + "come forward to me.": "come forward to me.", + "go back to me.": "go back to me.", + "i gave 50 cents.": "i gave 50 cents.", + "the weight is 5 kg": "the weight is 5 kg", + "커피 바 센터": "커피 바 센터", + "move 1.5 m forward": "move 1.5 m forward", +} +wrong = {t: (wording.norm(t), want) for t, want in CASES.items() if wording.norm(t) != want} +assert not wrong, wrong +print("number slips ok")