MCPcopy Create free account
hub / github.com/Litishkumar/AnalyticaX / IntentClassifier

Class IntentClassifier

intent_classifier.py:14–192  ·  view source on GitHub ↗

Classifies user intent from natural language questions

Source from the content-addressed store, hash-verified

12
13
14class IntentClassifier:
15 """
16 Classifies user intent from natural language questions
17 """
18
19 # Intent patterns using keywords and phrases
20 INTENT_PATTERNS = {
21 'trend_analysis': [
22 r'\btrend\b', r'\bover time\b', r'\bincreas(ing|e|ed)\b',
23 r'\bdecreas(ing|e|ed)\b', r'\bgrow(th|ing)\b', r'\bdeclin(e|ing)\b',
24 r'\bchanging\b', r'\bevolution\b', r'\btrajectory\b'
25 ],
26 'comparison': [
27 r'\bcompare\b', r'\bvs\.?\b', r'\bversus\b', r'\bbetter\b',
28 r'\bworse\b', r'\bdifference\b', r'\bhigher\b', r'\blower\b',
29 r'\bbetween\b.*\band\b'
30 ],
31 'explanation': [
32 r'\bwhy\b', r'\bhow\b', r'\bexplain\b', r'\breason\b',
33 r'\bcause\b', r'\bwhat.*mean\b', r'\bwhat.*affect\b',
34 r'\broot cause\b', r'\bdriv(e|ing|en)\b'
35 ],
36 'recommendation': [
37 r'\brecommend\b', r'\bsugg(est|estion)\b', r'\bwhat should\b',
38 r'\badvice\b', r'\baction\b', r'\bimprove\b', r'\boptimiz\w+\b',
39 r'\benhance\b'
40 ],
41 'kpi_query': [
42 r'\bkpi\b', r'\bmetric\b', r'\bindicator\b', r'\bperformance\b',
43 r'\bscore\b', r'\brating\b', r'\bvalue of\b'
44 ],
45 'dashboard_summary': [
46 r'\bdashboard\b', r'\boverview\b', r'\bsummary\b', r'\bsummariz\w+\b',
47 r'\ball.*kpis\b', r'\bshow me everything\b'
48 ],
49 'anomaly_detection': [
50 r'\banomal(y|ies)\b', r'\boutlier\b', r'\bunusual\b',
51 r'\bstrange\b', r'\bodd\b', r'\bunexpected\b', r'\birregular\b'
52 ],
53 'general_query': [
54 r'\bwhat is\b', r'\btell me about\b', r'\bshow me\b',
55 r'\bgive me\b', r'\bfind\b', r'\blist\b'
56 ]
57 }
58
59 def classify_intent(self, query: str) -> Tuple[str, float]:
60 """
61 Classify the intent of a user query
62
63 Args:
64 query: User's natural language query
65
66 Returns:
67 Tuple of (intent, confidence_score)
68 """
69 query_lower = query.lower()
70
71 intent_scores = {}

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected