File size: 1,387 Bytes
e07d48f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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))