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))