File size: 1,209 Bytes
1ae81d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import Literal

ActionCategory = Literal["move", "clean", "fetch", "light", "info", "other"]

KEYWORDS = {
    "move": ["đi ", "tới ", "tiến", "lùi", "rẽ", "theo sau", "quay lại"],
    "clean": ["hút bụi", "quét", "lau", "dọn", "làm sạch"],
    "fetch": ["lấy", "mang", "đưa", "đem"],
    "light": ["bật đèn", "tắt đèn", "đèn", "sáng", "tối"],
    "info": ["mấy giờ", "ngày mấy", "thời tiết", "pin", "bao nhiêu phần trăm"],
    "other": [],
}

def classify_command(text: str) -> ActionCategory:
    """Classify a Vietnamese home-robot command into an action category."""
    t = text.lower()

    for category, words in KEYWORDS.items():
        for w in words:
            if w in t:
                return category  # type: ignore[return-value]

    # fallback rules
    if "?" in t:
        return "info"
    return "other"

if __name__ == "__main__":
    examples = [
        "Đi tới phòng khách",
        "Hút bụi phòng ngủ",
        "Lấy cho tôi chai nước",
        "Bật đèn nhà bếp",
        "Pin của bạn còn bao nhiêu phần trăm?",
    ]
    for e in examples:
        print(e, "->", classify_command(e))