From 6177e5eef327000f8d2fd7a44c074c50285eeda4 Mon Sep 17 00:00:00 2001 From: Cutshion Date: Fri, 23 Oct 2026 16:45:29 +0900 Subject: [PATCH] =?UTF-8?q?Seeing:=20a=20question=20naming=20a=20hand=20(l?= =?UTF-8?q?eft=20/=20right=20/=20the=20other=20one=20/=20=EC=99=BC?= =?UTF-8?q?=EC=86=90=EC=9D=80=3F)=20is=20answered=20about=20that=20hand=20?= =?UTF-8?q?from=20a=20fresh=20look;=20raised=20empty=20hands=20said=20plai?= =?UTF-8?q?nly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- assistant/seeing.py | 53 +++++++++++++++++++++++++++++++++----- tests/test_seeing_fresh.py | 41 ++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 8 deletions(-) diff --git a/assistant/seeing.py b/assistant/seeing.py index c0a84eb..ca7c7e0 100644 --- a/assistant/seeing.py +++ b/assistant/seeing.py @@ -130,16 +130,16 @@ NOT_IN_VIEW = re.compile(r"\b(?:work|works|working|employ\w*|staff|company|compa r"live|lives|living|world|team|office|branch|developers?|engineers?|built|made|came|visited|talked|met)\b|" r"직원|회사|쿳션|일하|일해|근무|나라|국가|도시|살아|사는|인구|팀|지사|만든|만들|개발자|엔지니어|왔었|다녀갔|만났|얘기했|이야기했", re.I) # "how many people work at Cutshion?": the company, not the cameras -HOLDING = re.compile(r"\bwhat(?:'s| is| am| do)? (?:i|is in my hands?|in my hands?)\b.*?\b(?:holding|carrying|have)\b|" - r"\bwhat(?:'s| is)(?: it| this| that)? in my hands?\b|\bwhat(?:'s| is) my hands?\?|\bwhat (?:do )?i have in my hands?\b|\bam i holding\b|" - r"\bis there (?:something|anything) in my hand\b|\bwhat is this\b(?=.*\bhand\b)|\bwhat am i hold in\b|\banything in my hands?\b|" +HOLDING = re.compile(r"\bwhat(?:'s| is| am| do)? (?:i|is (?:in|on) my (?:left |right |other )?hands?|(?:in|on) my (?:left |right |other )?hands?)\b.*?\b(?:holding|carrying|have)\b|" + r"\bwhat(?:'s| is)(?: it| this| that)? (?:in|on) my (?:left |right |other )?hands?\b|\bwhat(?:'s| is) my (?:left |right |other )?hands?\?|\bwhat (?:do )?i have (?:in|on) my (?:left |right |other )?hands?\b|\bam i holding\b|" + r"\bis there (?:something|anything) in my hand\b|\bwhat is this\b(?=.*\bhand\b)|\bwhat am i hold in\b|\banything (?:in|on) my (?:left |right |other )?hands?\b|" r"\bwhat\b.{0,25}\b(?:i'?m|i am) (?:holding|carrying)\b|\bwhat(?:'ve| have| do) i (?:got|have)\b(?! to)|" r"\bwhat(?:'s| is) this(?: thing)?\W*$|\bwhat i(?:'ve| have) got\b|hold\s*했\S*\W+.*뭐|" r"(?\bnot (?:in )?(?:the |my |your )?|\bisn'?t (?:in )?(?:the |my |your )?)?\b(?Pleft|right)\b" r"(?=\s*(?:hand|one|side)(?![a-z])|\W*$)|(?P왼|오른)\s*(?:손|쪽|편)\S{0,3}(?P\s*아니)?", re.I) +HAND_ASKED = re.compile(r"\b(?:what|how) about\b|^\W*and\b|\bwhat\b.*\b(?:in|on)\b|\?\s*$|" + r"(?:손|쪽|거)\S{0,2}(?:은|는|엔)\s*\??\W*$|뭐|뭘|무엇|뭔", re.I) + # "what about the left hand?", "왼손은?": a question about that hand, not "it's my left hand" +OTHER_HAND = re.compile(r"\bother (?:hand|one)\b|\bthis (?:one|hand)\b|다른\s*(?:손|쪽)|반대\S{0,2}\s*손|이쪽\s*손|^\W*이\s*손|" + r"^\W*(?:그럼\s*)?이건\s*\?", re.I) # "and the other one?", "this one?" after a hand answer COLOUR_SAID = re.compile(r"(?P\bnot (?:\w+ ){0,2}|n't (?:\w+ ){0,2})?\b(?P" + "|".join(c for c in COLOURS if c.isascii()) + r")(?![a-z])|(?P" + "|".join(c for c in COLOURS if not c.isascii()) + r")\w*(?P\s*아니)?", re.I) _last = {"thing": None, # the thing seen last: "how far is it?" "name": None, # the kind of thing asked about last: "and the blue one?" "kind": None, # the kind of the question just answered: "what about my jeans?" after the shirt "asked": None, # (kind, words) of that question: "really?", "and now?" ask it again + "hand": None, # the hand the last "what's in my hand" answer was about: "and the other one?" "parts": [], # [(part, word, colour)] said in the clothes answer: "it's white" is about these "at": 0.0} # time.time() of the last seeing answer @@ -434,13 +440,17 @@ def _it_answer(t, frames, lang): if th['distance_m'] else f"{_j(_ko_name(name), '은', '는')} {_where_ko(th['where'])}에 있어요.", lang) -def _held_answer(frames, lang): +def _held_answer(frames, lang, side=None): + """What the person holds; side ("left" / "right", the person's own): only what is in that hand.""" p = scene.person_in_front(frames) if p is None: return _say("I can't see you well enough to tell. Could you step in front of me?", "잘 안 보여서 모르겠어요. 제 앞으로 와 주시겠어요?", lang) + if side: + return _hand_answer(p, side, lang) o = scene.object_in_hand(frames) if o: + _last["hand"] = o["hand"] hand = {"left": ("left", "왼"), "right": ("right", "오른")}[o["hand"]] return _say(f"You're holding {_a(o['name'], o['colour'])} in your {hand[0]} hand.", f"{hand[1]}손에 {COLOUR_KO[o['colour']] + ' ' if o['colour'] in COLOUR_KO else ''}" @@ -450,6 +460,30 @@ def _held_answer(frames, lang): return _say("I can't see your hands well enough to tell.", "손이 잘 안 보여서 모르겠어요.", lang) +def _hand_answer(p, side, lang): + """The one hand asked about ("what about my left hand?"), never the other hand's thing: what is in it, that it is + up with nothing seen in it, or that nothing known is in it.""" + _last["hand"] = side + h, k = p["hands"].get(side), {"left": "왼", "right": "오른"}[side] + o = h and h["object"] + if o: + return _say(f"In your {side} hand I see {_a(o['name'], o['colour'])}.", + f"{k}손에 {COLOUR_KO[o['colour']] + ' ' if o['colour'] in COLOUR_KO else ''}" + f"{_j(_ko_name(o['name']), '이', '가')} 보여요.", lang) + if side in p["raised"]: + return _say(f"Your {side} hand is up and I don't see anything in it.", + f"{k}손을 들고 계신데, 그 손에는 든 게 안 보여요.", lang) + if h is None: + return _say(f"I can't see your {side} hand well enough to tell.", f"{k}손이 잘 안 보여서 모르겠어요.", lang) + return _say(f"I don't see anything I can recognise in your {side} hand.", + f"{k}손에는 제가 알아볼 수 있는 게 안 보여요.", lang) + + +def _asked_hand(t): + """The hand a question is about: "what's in my left hand?", "왼손은?", "and the other one?" (not the one just told).""" + return _side(t) or (OTHER_HAND.search(t) and {"left": "right", "right": "left"}.get(_last["hand"])) or None + + def _empty_hands(lang, now=False): """Nothing the detector knows in the hands: said plainly, with what it can't see (a watch has no class).""" return _say(EMPTY_HANDS[0].format(" now" if now else ""), EMPTY_HANDS[1].format("지금은 " if now else ""), lang) @@ -653,6 +687,11 @@ def _check(t, lang, frames, since, slow_line): short = len(t.split()) <= CLAIM_WORDS and \ not ((ORDER.search(re.sub(r"\W+look\W*$", "", t)) or HEAD.search(t)) and not again) # "put it in my right hand"; "..., look" hand = _side(t) if short and kind in ("holding", "hand", "raised") else None + side = _asked_hand(t) if short and kind in ("holding", "hand") and HAND_ASKED.search(t) else None + if side: # "what about the left hand?": that hand, from a new look + _last["kind"], _last["asked"] = "holding", ("holding", f"what is in my {side} hand?") + frames = _look(frames, since) + return _held_answer(frames, lang, side) if frames else _say(*NO_CAMERA, lang) said, denied = _colours(t) if short and kind in ("shirt", "holding", "hand") else (None, set()) named = _said_thing(t) if short and kind in ("holding", "hand") and not hand else None count = _said_count(t) if short and kind == "how_many" else None @@ -762,7 +801,7 @@ def _reply(kind, t, frames, lang, slow_line=None): return _say("I can't measure how far it is.", "거리는 잴 수 없어요.", lang) return _say(f"The {name} is about {_metres(d)} from me.", f"{_j(_ko_name(name), '은', '는')} 저한테서 {_d(d)}미터쯤 떨어져 있어요.", lang) if kind == "holding": - return _held_answer(frames, lang) + return _held_answer(frames, lang, _asked_hand(t)) p = scene.person_in_front(frames) if kind == "friend": # "do you still see my friend?": anyone besides them n = len(scene.people(frames)) - (p is not None) diff --git a/tests/test_seeing_fresh.py b/tests/test_seeing_fresh.py index 0a213e1..a0df5da 100644 --- a/tests/test_seeing_fresh.py +++ b/tests/test_seeing_fresh.py @@ -40,7 +40,7 @@ def person_in_front(frames=None): hands[w["hand"]]["object"] = {"name": w["thing"], "colour": w["colour"], "position_mm": None, "distance_m": 0.8, "width_mm": None} return {"distance_m": 1.0, "bearing_deg": 0.0, "where": "in front of me", "position_mm": None, "camera": "head", - "facing": True, "gesture": None, "raised": [], "pointing": None, "hands": hands, + "facing": True, "gesture": None, "raised": w.get("raised", []), "pointing": None, "hands": hands, "clothes": {"upper": w.get("upper"), "lower": w.get("lower"), "feet": None}} @@ -140,6 +140,30 @@ dialogue([("Can you see me?", {"person": False}, r"can't see you"), ("What about now?", {"person": True}, r"looked again.*yes, i can see you"), ("Lumi, look at the left side.", None, "llm")]) # a head turn, not a seeing follow-up +# a question naming a hand is about that hand only, the person's own left / right (live 2026-10-23 15:34: "what about +# left hand?" with a laptop in the right and the left raised empty -> "I see a black laptop in your right hand" thrice) +LEFT_UP = r"^Your left hand is up and I don't see anything in it\.$" +world.update(START, hand="right", thing="laptop", colour="black", raised=["left"]) +dialogue([("What is my hand?", None, r"black laptop in your right hand"), + ("What about left hand?", None, LEFT_UP), + ("What is it in my left hand?", None, LEFT_UP), + ("What about the left one?", None, LEFT_UP), + ("and the other hand?", None, r"^In your right hand I see a black laptop"), + ("and this one?", None, LEFT_UP), + ("really?", None, r"looked again.*left hand is up"), + ("What about Inna's left hand?", {"raised": []}, r"^I don't see anything I can recognise in your left hand"), + ("What's in my right hand?", None, r"^In your right hand I see a black laptop"), + ("No, it's my left hand.", None, r"laptop in your right hand, but I may be wrong")]) # a claim stays a claim +world.update(raised=["left"]) +dialogue([("내 손에 뭐 있어?", None, r"오른손에 .*노트북"), + ("왼손은?", None, r"^왼손을 들고 계신데"), + ("다른 손은?", None, r"^오른손에 .*노트북"), + ("그럼 왼손에는 뭐 있어?", None, r"^왼손을 들고 계신데"), + ("What about 왼손?", None, r"^왼손을 들고 계신데"), # mixed + ("what about the other one?", None, r"^In your right hand I see a black laptop"), + ("그럼 left hand는?", None, r"^왼손을 들고 계신데")]) +world.update(raised=[]) + # nothing in the hand any more, or nobody there world.update(START) dialogue([("what am I holding?", None, r"left hand"), @@ -195,4 +219,19 @@ assert len(real_snapshot(("head",))) == 1 # without `sin (tmp / "det_head.json").write_text(json.dumps({"time": time.time(), "people": [], "objects": []})) assert len(real_snapshot(("head",), since=asked)) == 1 +# "what's in my hand" in every wording goes to the cameras (2026-10-23: "What is in my right hand?" went to the LLM) +for said in ("What is in my right hand?", "What's in my left hand?", "what is in my hand", "what's in my hand?", + "What is my hand?", "what am I holding", "What do I have in my hand?", "what is on my hand", + "Lumi, what's in my hand?", "내 손에 뭐 있어?", "내 오른손에 뭐 있어?", "제 왼손에 뭐 있어요?", "내가 뭐 들고 있어?", + "내 손에 든 거 뭐야?"): + assert next((k for k, rx in seeing.KINDS if rx.search(said)), None) == "holding", said + +# a barge-in that is the echo of Lumi's own answer (sound match ~0.5, bent words) is not a new question +from audio import mouth +mouth.recent_speech = lambda s=30.0: "Let me check. It is overcast in Seoul today with temperatures between 7 and 19 degrees." +assert lumi.Lumi.own_echo("So today, with temperature, it's been", share=lumi.ECHO_LIKELY_SHARE) +assert lumi.Lumi.own_echo("The school is over.", share=lumi.ECHO_LIKELY_SHARE) +assert not lumi.Lumi.own_echo("What about Busan?", share=lumi.ECHO_LIKELY_SHARE) +assert not lumi.Lumi.own_echo("Look it up.", share=lumi.ECHO_LIKELY_SHARE) + print("seeing fresh ok")