File size: 1,152 Bytes
ddd5c13 | 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 | from typing import Literal
Priority = Literal["low", "normal", "high", "urgent"]
URGENT_WORDS = ["ngay lập tức", "ngay bây giờ", "lập tức", "khẩn cấp"]
HIGH_WORDS = ["càng sớm càng tốt", "sớm nhất", "ưu tiên", "rất quan trọng"]
LOW_WORDS = ["khi rảnh", "lúc rảnh", "khi nào tiện", "không gấp"]
def estimate_priority(command: str) -> Priority:
"""Estimate the priority of a Vietnamese task/command."""
t = command.lower()
for w in URGENT_WORDS:
if w in t:
return "urgent"
for w in HIGH_WORDS:
if w in t:
return "high"
for w in LOW_WORDS:
if w in t:
return "low"
# heuristic: if has words like 'ngay', 'bây giờ'
if "ngay" in t or "bây giờ" in t:
return "high"
return "normal"
if __name__ == "__main__":
tests = [
"Hút bụi phòng khách khi rảnh",
"Nhắc tôi thanh toán tiền điện càng sớm càng tốt",
"Dọn nhà bếp ngay lập tức",
"Kiểm tra cửa sổ tối nay",
]
for t in tests:
print(t, "->", estimate_priority(t))
|