from typing import Literal Room = Literal[ "living_room", "kitchen", "bedroom", "bathroom", "hallway", "office", "storage", "any", "unknown", ] OBJECT_ROOM_RULES = { "remote": "living_room", "tivi": "living_room", "sofa": "living_room", "ghế sofa": "living_room", "bàn ăn": "kitchen", "cơm điện": "kitchen", "tủ lạnh": "kitchen", "bếp": "kitchen", "chăn": "bedroom", "gối": "bedroom", "giường": "bedroom", "khăn tắm": "bathroom", "phòng tắm": "bathroom", "bàn chải": "bathroom", "giày": "hallway", "chìa khóa": "hallway", "bàn làm việc": "office", "máy tính": "office", "laptop": "office", "máy hút bụi": "storage", } def map_object_to_room(text: str) -> Room: """Infer a typical room for a given Vietnamese object phrase.""" t = text.lower() for key, room in OBJECT_ROOM_RULES.items(): if key in t: return room # type: ignore[return-value] if "điện thoại" in t or "phone" in t: return "any" return "unknown" if __name__ == "__main__": tests = [ "điều khiển tivi", "chăn bông", "giày thể thao", "bàn làm việc", "điện thoại của tôi", ] for t in tests: print(t, "->", map_object_to_room(t))