hoangs commited on
Commit
1ae81d2
·
verified ·
1 Parent(s): 7d48258

Upload model.py

Browse files
Files changed (1) hide show
  1. model.py +37 -0
model.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Literal
2
+
3
+ ActionCategory = Literal["move", "clean", "fetch", "light", "info", "other"]
4
+
5
+ KEYWORDS = {
6
+ "move": ["đi ", "tới ", "tiến", "lùi", "rẽ", "theo sau", "quay lại"],
7
+ "clean": ["hút bụi", "quét", "lau", "dọn", "làm sạch"],
8
+ "fetch": ["lấy", "mang", "đưa", "đem"],
9
+ "light": ["bật đèn", "tắt đèn", "đèn", "sáng", "tối"],
10
+ "info": ["mấy giờ", "ngày mấy", "thời tiết", "pin", "bao nhiêu phần trăm"],
11
+ "other": [],
12
+ }
13
+
14
+ def classify_command(text: str) -> ActionCategory:
15
+ """Classify a Vietnamese home-robot command into an action category."""
16
+ t = text.lower()
17
+
18
+ for category, words in KEYWORDS.items():
19
+ for w in words:
20
+ if w in t:
21
+ return category # type: ignore[return-value]
22
+
23
+ # fallback rules
24
+ if "?" in t:
25
+ return "info"
26
+ return "other"
27
+
28
+ if __name__ == "__main__":
29
+ examples = [
30
+ "Đi tới phòng khách",
31
+ "Hút bụi phòng ngủ",
32
+ "Lấy cho tôi chai nước",
33
+ "Bật đèn nhà bếp",
34
+ "Pin của bạn còn bao nhiêu phần trăm?",
35
+ ]
36
+ for e in examples:
37
+ print(e, "->", classify_command(e))