Korean and Konglish amounts read exactly: sino and native numbers (사 십오, 마흔다섯), particles, decimals, 레프트 / 라이트; a number without a unit is asked; whisper's number and unit slips corrected

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 12:38:04 +09:00
co-authored by Claude Opus 5.5
parent 6d74a6ee39
commit 10bba17f4e
5 changed files with 267 additions and 7 deletions
+23 -2
View File
@@ -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"(?<![가-힣])(?:하나|둘|셋|넷|다섯|여섯|일곱|여덟|아홉|열|스물|서른|마흔|쉰)(?:만|쯤|정도)?(?![가-힣])")
# "앞으로 다섯만 가": a count with no unit, asked
KO_COUNT = re.compile(KO_NUM_WORD.pattern + r"|(?<![가-힣])[이삼사오육칠팔구]?[십백][일이삼사오육칠팔구]?(?:만|쯤|정도)?(?![가-힣])|"
r"(?<![\w.])\d+(?:\.\d+)?(?![\d.])(?!\s?(?:m|도|degrees?|°)(?![a-z]))") # a number with no unit
WRONG_UNIT = (re.compile(r"(?<![\w.])\d+(?:\.\d+)? ?(?:도|degrees?)(?:만|쯤|정도|가량)?(?![가-힣a-z])"), # degrees for a drive
re.compile(r"(?<![\w.])\d+(?:\.\d+)? m(?![a-z])")) # metres for a turn
TURN_WORD = re.compile(r"\b(?:turn|spin|rotate|pivot)\b|돌아|돌려|돌(?:까|래|면)|회전|도세요|도십시오")
NOT_BASE = re.compile(r"\b(?:look|head|face|lift|arm)\b|고개|머리|얼굴|봐|보세요|리프트|팔|손")
FASTER = re.compile(r"\b(?:faster|quicker|speed (?:it )?up|pick up (?:the )?(?:pace|speed)|step on it|hurry(?: up)?|"
r"get a move on|more speed|full speed|go quick(?:ly)?|too slow(?:ly)?|so slow(?:ly)?|"
@@ -107,7 +115,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"(?<![\w.])\d", t) or NUM_WORD.search(t):
if re.search(r"(?<![\w.])\d", t) or NUM_WORD.search(t) or KO_NUM_WORD.search(t):
return "?", False # "move back 20", "two feet", "a couple of metres"
if LITTLE.search(t):
return LITTLE_M, False
@@ -174,6 +182,15 @@ def read(t, last=None, talking=False):
n, exact = amount(t) # "just a few centimetres more", "10센티 더"
if n is not None:
return _checked(last[1].split()[0], n, exact)
d = direction(t)
if d and not (JOINED.search(t) or SAYER.search(t) or NOT_BASE.search(t)):
if WRONG_UNIT[0].search(t) and VERB.search(t) and not TURN_WORD.search(t):
return ("ask", d) # "앞으로 30도 가": degrees for a drive
if WRONG_UNIT[1].search(t) and TURN_WORD.search(t) and d in ("left", "right") and not VERB.search(TURN_WORD.sub(" ", t)):
return ("ask", f"turn {d}") # "왼쪽으로 1미터 돌아": metres for a turn
if TURN_WORD.search(t) and d in ("left", "right") and re.search(r"[가-힣]", t) and \
not WRONG_UNIT[0].search(t) and KO_COUNT.search(t):
return ("ask", f"turn {d}") # "왼쪽으로 서른만 돌아", "왼쪽으로 30 돌아": degrees?
got = move(t)
return _checked(*got) if got else None
@@ -237,6 +254,10 @@ def say_refused(d, n, lang="en"):
def say_ask(d, lang="en"):
if d.startswith("turn "):
d = d.split()[1]
return (f"How far should I turn {d}? Please say it in degrees, like 30 degrees." if lang == "en"
else f"{KO_DIR.get(d, '')} 몇 도 돌까요? 30도처럼 말씀해 주세요.")
if not d:
return ("More of what? Please tell me what to do." if lang == "en" else "무엇을 더 할까요? 다시 말씀해 주세요.")
return (f"How far should I go {d}? Please say it with a unit, like 20 centimetres." if lang == "en"
+71 -5
View File
@@ -25,6 +25,12 @@ NATIVE = {"한": 1, "두": 2, "세": 3, "네": 4, "다섯": 5, "여섯": 6, "일
SINO = {"일": 1, "이": 2, "삼": 3, "사": 4, "오": 5, "육": 6, "륙": 6, "칠": 7, "팔": 8, "구": 9}
_D = "[일이삼사오육륙칠팔구]"
_SINO = rf"(?:{_D}?천(?:{_D}?백)?(?:{_D}?십)?{_D}?|(?:{_D}?백)(?:{_D}?십)?{_D}?|{_D}?십{_D}?|{_D})" # 일 … 구천구백구십구
NATIVE_TENS = {"열": 10, "스물": 20, "스무": 20, "서른": 30, "마흔": 40, "쉰": 50, "예순": 60, "일흔": 70, "여든": 80, "아흔": 90}
NATIVE_ONES = {"하나": 1, "한": 1, "둘": 2, "두": 2, "셋": 3, "세": 3, "넷": 4, "네": 4, "다섯": 5, "여섯": 6, "일곱": 7,
"여덟": 8, "아홉": 9}
_NATIVE_NUM = (rf"(?:({'|'.join(NATIVE_TENS)})\s?({'|'.join(NATIVE_ONES)})?|(다섯|여섯|일곱|여덟|아홉))") # 한 / 두 / 세 /
# 네 alone: NUM_WORDS (before a unit only; "한 도" is no angle)
_ABOUT = r"(?:만|쯤|정도|가량|씩)?" # "45도만", "30도쯤": still that amount
TENS = {"twenty": 20, "thirty": 30, "forty": 40, "fifty": 50, "sixty": 60, "seventy": 70, "eighty": 80, "ninety": 90}
NUM_WORDS = {"one": "1", "two": "2", "three": "3", "four": "4", "five": "5", "six": "6", "seven": "7", "eight": "8",
"nine": "9", "ten": "10", "a": "1", "an": "1", "한": "1", "두": "2", "세": "3", "네": "4"}
@@ -121,6 +127,13 @@ def numbers(t):
lambda m: f"{_num(m.group(1))}.{_num(m.group(2))} ", t) # "one point five meters"
t = re.sub(rf"\b(?:zero |oh )?point ({'|'.join(list(EN_NUM)[:9])}|\d)\s*(?={UNIT}\b)",
lambda m: f"0.{_num(m.group(1))} ", t) # "point five meters"
t = re.sub(rf"(?<![가-힣\d])({_SINO}(?:\s{_SINO})+)(?=\s*(?:{UNIT}|도|걸음|점))", # "사 십오 도", "삼백 육십 도":
lambda m: m.group(1).replace(" ", "") if re.fullmatch(_SINO, m.group(1).replace(" ", "")) else m.group(1),
t) # one number said apart
t = re.sub(rf"(?<![가-힣]){_NATIVE_NUM}\s*(?={UNIT}|걸음|발짝|발자국|뼘|도{_ABOUT}(?![가-힣]))", # "마흔다섯 도", "스무 센티"
lambda m: f"{NATIVE_TENS.get(m.group(1), 0) + NATIVE_ONES.get(m.group(2) or m.group(3), 0)} ", t)
t = re.sub(rf"(?<![가-힣\d])({_SINO})\s*도(?={_ABOUT}(?![가-힣]))", # "사십오 도만", "백팔십 도"
lambda m: f"{sino(m.group(1))}도" if len(m.group(1)) > 1 or m.group(1) in "십백" else m.group(0), t)
t = re.sub(rf"(?<![가-힣])(?:({_SINO})|[영공])\s*점\s*({_D})\s*(?={UNIT})",
lambda m: f"{sino(m.group(1)) if m.group(1) else 0}.{SINO[m.group(2)]} ", t) # "영점오 미터", "일 점 오"
t = re.sub(rf"(?<![가-힣\d])({_SINO})\s*(?={UNIT}(?![a-z]))", lambda m: f"{sino(m.group(1))} ", t) # "오십 센치"
@@ -269,12 +282,65 @@ ASR_SLIPS = [ # how whisper writes Korean commands (tests/asr_check.py, 2026-1
]
def norm(text, names=()):
"""Lower case, whisper's slips (ASR_SLIPS), numbers first ("point five meters" is a distance), then marker names
(names: the map's)."""
t = " " + (text or "").lower().replace("’", "'") + " "
for slip, said in ASR_SLIPS:
_NO = r"(?<![가-힣a-z])"
KONGLISH = [ # English direction words said in Korean -> 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"(?<![\d.])(\d+)\.\s?m(?![a-z\d])", r"\1점 몇 m"), # "앞으로 1.m가"
(r"(?<![\d.])(\d+)\s?미가(?![가-힣])", r"\1미터 가"), # "1미가"
(r"(?<![\d.])(\d+)\s?m\s?(\d+)\s?cm\b", r"\1 m \2 cm"), # "1m50cm 뒤로 가"
(r"(?<![\d.])(\d+(?:\.\d+)?)\s*(?:센트|센터|세트|세기|cent(?:uries|ury|s|i)?(?: letters?)?)(?![a-z])",
r"\1 cm"), # "30 centuries", "40센터만", "60세기"
(r"\b(forward|backward|left|right)\.\s+(\d+(?:\.\d+)?)\s*(?=cm|m\b|meters?|미터|센티|도|degrees?)", r"\1 \2 "),
# a clause cut at the language change: "Left. 30cm가." (a period
# only: commas mark self-corrections, "forward, sorry, right, 150 cm")
(r"\b((?:go|move|drive|step) " + _DIR + " " + _AMOUNT + r")(?:years?|later)\b", r"\1meters"), # "go back two years"
(r"\b(forward|backward|left|right)[,.]? to me(?=\W*$)", r"\1 2 meters"), # "Go forward. Forward to me." (not back:
# "go back to me" may be meant)
(r"(\bto [\w.-]+)[,.]? weight[,.]? (?=\S)", r"\1, wait, "), # "Move to P3 weight P8"
]
MOVE_SAID = re.compile(rf"\b(?:go|move|drive|step|come|turn)\b|{_DIR}|가|와|이동|돌아")
NOT_MOVE = re.compile(r"\b(?:come|look|turn|wave|give|bring|hand|show)\b[^.!?]*\bto me\W*$")
def number_slips(t):
"""Whisper's slips of a distance in a move command (NUMBER_SLIPS); text without a move is left as it is."""
if not MOVE_SAID.search(t):
return t
for slip, said in NUMBER_SLIPS:
if "to me" in slip and NOT_MOVE.search(t):
continue
t = re.sub(slip, said, t)
return t
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("’", "'") + " "
for slip, said in ASR_SLIPS + KONGLISH:
t = re.sub(slip, said, t)
t = number_slips(t)
return re.sub(r"\s+", " ", markers(map_names(numbers(t), names))).strip() # the map's names first: "booth 3 point"
# is booth_3, not "booth p3"
+98
View File
@@ -0,0 +1,98 @@
"""Amounts and directions said in Korean, Konglish and mixed with English, as the readers must take them
(tests/test_korean_numbers.py). Written 2026-10-23 for the voice test of move / turn / look / lift.
ROUTE: said -> "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}],
}
+47
View File
@@ -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()
+28
View File
@@ -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")