Skip to content

Commit f34b20a

Browse files
committed
fix: Correct Vietnamese time estimation pattern extraction
- Fixed logic order: check Vietnamese patterns first, then regex - Improved task description extraction for Vietnamese queries - Fixed initialization issue in pattern matching
1 parent 3cabe73 commit f34b20a

2 files changed

Lines changed: 26 additions & 22 deletions

File tree

backend/core/time_estimation_intent.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,9 @@ def detect_time_estimation_intent(query: str) -> Tuple[bool, Optional[str]]:
7070
if not has_time_keyword:
7171
return (False, None)
7272

73-
# Try to extract task description
74-
# Patterns like "how long to [task]" or "bao lâu để [task]"
75-
patterns = [
76-
r'how\s+long\s+(?:will\s+it\s+)?(?:take\s+)?(?:to\s+)?(.+?)(?:\?|$)',
77-
r'how\s+much\s+time\s+(?:will\s+it\s+)?(?:take\s+)?(?:to\s+)?(.+?)(?:\?|$)',
78-
r'bao\s+lâu\s+(?:để\s+)?(.+?)(?:\?|$)',
79-
r'mất\s+bao\s+lâu\s+(?:để\s+)?(.+?)(?:\?|$)',
80-
r'tốn\s+bao\s+lâu\s+(?:để\s+)?(.+?)(?:\?|$)',
81-
r'cần\s+bao\s+lâu\s+(?:để\s+)?(.+?)(?:\?|$)',
82-
r'ước\s+tính\s+(?:thời\s+gian\s+)?(?:cho\s+)?(.+?)(?:\?|$)',
83-
r'(.+?)\s+(?:mất|tốn|cần)\s+bao\s+lâu', # "[task] mất bao lâu"
84-
]
73+
task_description = None
8574

86-
# Also check for Vietnamese patterns without regex (more reliable)
75+
# First, try Vietnamese patterns (more reliable without regex)
8776
if "bao lâu" in query_lower:
8877
# Pattern: "bao lâu để [task]"
8978
if "để" in query_lower:
@@ -106,18 +95,29 @@ def detect_time_estimation_intent(query: str) -> Tuple[bool, Optional[str]]:
10695
if len(parts) > 0:
10796
task_description = parts[0].strip()
10897

109-
task_description = None
110-
for pattern in patterns:
111-
match = re.search(pattern, query_lower, re.IGNORECASE)
112-
if match:
113-
task_description = match.group(1).strip()
114-
# Clean up common trailing words
115-
task_description = re.sub(r'\s+(?:to|for|để|cho)\s*$', '', task_description)
116-
break
98+
# If Vietnamese pattern didn't match, try regex patterns
99+
if not task_description:
100+
patterns = [
101+
r'how\s+long\s+(?:will\s+it\s+)?(?:take\s+)?(?:to\s+)?(.+?)(?:\?|$)',
102+
r'how\s+much\s+time\s+(?:will\s+it\s+)?(?:take\s+)?(?:to\s+)?(.+?)(?:\?|$)',
103+
r'bao\s+lâu\s+(?:để\s+)?(.+?)(?:\?|$)',
104+
r'mất\s+bao\s+lâu\s+(?:để\s+)?(.+?)(?:\?|$)',
105+
r'tốn\s+bao\s+lâu\s+(?:để\s+)?(.+?)(?:\?|$)',
106+
r'cần\s+bao\s+lâu\s+(?:để\s+)?(.+?)(?:\?|$)',
107+
r'ước\s+tính\s+(?:thời\s+gian\s+)?(?:cho\s+)?(.+?)(?:\?|$)',
108+
r'(.+?)\s+(?:mất|tốn|cần)\s+bao\s+lâu', # "[task] mất bao lâu"
109+
]
110+
111+
for pattern in patterns:
112+
match = re.search(pattern, query_lower, re.IGNORECASE)
113+
if match:
114+
task_description = match.group(1).strip()
115+
# Clean up common trailing words
116+
task_description = re.sub(r'\s+(?:to|for|để|cho)\s*$', '', task_description)
117+
break
117118

118119
# If no specific task found, use query as task description
119120
if not task_description:
120121
task_description = query.strip()
121122

122123
return (True, task_description)
123-

stillme_core/monitoring/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
)
1919
from .task_tracker import TaskTracker, TaskRecord, get_task_tracker
2020
from .time_estimation import TimeEstimationEngine, TimeEstimate, get_estimation_engine
21+
from .self_tracking import track_task_execution, estimate_and_track, format_self_aware_response
2122

2223
__all__ = [
2324
"UnifiedMetricsCollector",
@@ -30,5 +31,8 @@
3031
"TimeEstimationEngine",
3132
"TimeEstimate",
3233
"get_estimation_engine",
34+
"track_task_execution",
35+
"estimate_and_track",
36+
"format_self_aware_response",
3337
]
3438

0 commit comments

Comments
 (0)