Improve place names in typed commands, give wording and approaches that are blocked

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 19:03:25 +09:00
co-authored by Claude Opus 5.5
parent 27182df965
commit 1b3f4568e1
8 changed files with 47 additions and 11 deletions
+8 -4
View File
@@ -1749,7 +1749,7 @@ def _as_place(name):
_OBJ_ADJ = rf"(?:(?:{_COL}|작은|큰|왼쪽|오른쪽|가까운|먼|제일|가장)\s*)*+" # possessive: no backtracking
_AT_OBJ_EN = rf"\b(?:{_OBJ})s?,? (?:that'?s |that is |which is |sitting |lying |standing |left )?(?:on|at|by|near) (?:the )?$"
_AT_OBJ_KO = (rf"\s*(?:(?:위|쪽)\s*)?(?:에|의)\s*(?:(?:있는|있던|놓인|놓여\s*있는|둔|올려\s*둔|올려진|올라간|올라가\s*있는)\s*)?"
_AT_OBJ_KO = (rf"\s*(?:(?:테이블|탁자|책상|table)\s*)?(?:(?:위|쪽)\s*)?(?:에|의)\s*(?:(?:있는|있던|놓인|놓여\s*있는|둔|올려\s*둔|올려진|올라간|올라가\s*있는)\s*)?"
rf"{_OBJ_ADJ}(?:{_OBJ})|\s*(?:(?:에|의)\s*)?(?:있는|있던|놓인|놓여\s*있는|둔)\s*(?:거|것|걸)")
# ^ where the thing is ("the cup on p2", "p2에 있는 빨간 컵", "피원 컵", "p1의 컵"): the source, not where it goes
@@ -1768,14 +1768,18 @@ def _mentions(text, markers):
for m in re.finditer(_place_re(markers), t):
before, after, place = t[:m.start()], t[m.end():], _resolve(m, markers)
if re.search(r"\bfrom (the )?$", before) or re.match(r"\s*에서", after) \
or (re.search(r"\b(go|drive|head|come) (over )?to (the )?$", before) # "go to p1 and get the cup"
or (re.search(r"\b(go|drive|head|come) (over )?(to )?(the )?$", before) # "go (to) p1 and get the cup"
and re.match(r"\s*(,|and|then)\s*(get|fetch|take|pick|grab|bring)", after)) \
or (re.match(r"\s+(?:까지\s*)?가서", after) and objs and m.start() < objs[-1].start()) \
or re.search(_AT_OBJ_EN, before) or re.match(_AT_OBJ_KO, after) \
or (re.match(rf"\s+{_OBJ_ADJ}(?:{_OBJ})", after) and not re.search(r"\b(to|into|onto) (the )?$", before)):
# ^ "the cup on p2", "p2에 있는 컵", "피원 컵을", "p1 red cup bring me"
out["source"] = _as_place(place)
elif re.search(r"\b(to|into) (the )?$|\b(bring|fetch|give|get)( it| that| this)? $", before) \
or re.match(r"\s*(으로|로|에다|에|한테)(?!서)", after) or place == "here":
or re.search(r"\b(go|drive|head|walk|carry it|take it|bring it)( over)? (the )?$", before) \
or re.match(r"\s*(?:(?:포인트|point|지점|테이블|탁자|책상)\s*(?:위\s*)?)?(으로|로|에다|에|한테)(?!서)", after) or place == "here" \
or re.match(r"\s+(?:까지\s*)?(?:가(?:서|요|\s*줘|\s*주세요)?|이동)(?![가-힣])", after):
# ^ "and go exit point", "exit 가서", "exit 까지 가 줘": a drive there, said without "to" / 로
out["dest"] = _as_place(place)
for m in re.finditer(r"\bfrom (?:the )?([a-z]+)", t): # "from the kitchen": a place not on the map
if not re.match(_place_re(markers), t[m.start(1):]) and "source" not in out:
@@ -1787,7 +1791,7 @@ def _mentions(text, markers):
if m.start() > after_obj and "dest" not in out and not re.match(rf"{_TABLE}|{_place_re(markers)}", t[m.start(1):]) \
and m.group(1) not in ("put", "place", "hold", "give", "keep", "bring", "leave"):
out["dest"] = None
if "dest" not in out and re.search(r"\b(bring|get|fetch|give) (it |that |this )?(to )?me\b|\bto me\b|가져와|가지고 ?와|갖다 ?줘|가져다 ?(?:줘|주세요|줄래)", t):
if "dest" not in out and re.search(r"\b(bring|get|fetch|give) (it |that |this )?(to )?me\b|\bto me\b|가져와|가지고 ?와|갖고 ?와|갖다 ?줘|가져다 ?(?:줘|주세요|줄래)", t):
out["dest"] = "here"
if "dest" not in out and (re.search(r"\b(?:bring|fetch)(?:ing)?\b", t) and isinstance(out.get("source"), dict)
and not re.search(r"\b(?:to|for) (?!me\b|us\b)\w", t)
+8 -2
View File
@@ -1412,7 +1412,8 @@ def _en(s, last=False):
if d == "place":
return "put it down" if not s["on"] else f"put it on {_on_words(s['on'])}"
if d == "give":
return f"hand it to {s['person']}" if s.get("person") else "hand it over"
return f"hand it to {s['person']}" if s.get("person") else "give it to the person there" if s.get("_away") \
else "give it to you"
if d == "hold":
return "hold it"
return {"reach": "reach out my arm", "fold": "fold my arm", "open": "open my hand", "close": "close my hand"}[s["pose"]]
@@ -1455,7 +1456,7 @@ def _ko(s, last=False):
if d == "give":
if s.get("person"):
return f"{s['person']}께 건네드리고" if s["person"].endswith("님") else f"{s['person']}에게 건네주고"
return "건네주고"
return "거기 있는 분께 건네주고" if s.get("_away") else "건네주고"
if d == "hold":
return "들고 있고"
return {"reach": "팔을 뻗고", "fold": "팔을 접고", "open": "손을 펴고", "close": "손을 쥐고"}[s["pose"]]
@@ -1476,6 +1477,11 @@ def describe(steps, lang="en"):
"""'Take the cup, drive 0.5 m forward, turn right and drive 1 m, then put it on the table.'"""
if not steps:
return ""
away, marked = False, []
for s in steps: # a give after a drive away is to the person there, else to the one asking
away = s["to"] != "here" if s["do"] == "go" else away or s["do"] == "move"
marked.append({**s, "_away": away} if s["do"] == "give" else s)
steps = marked
if lang == "ko":
parts = [_ko(s, i == len(steps) - 1) for i, s in enumerate(steps)]
return " ".join(parts[:-1] + [_will(parts[-1][:-1]) + "."])