Skip to content

Commit 9b04a77

Browse files
Update AICategorizer provides rule-based task categorization using keyword matching
1 parent c0b0a53 commit 9b04a77

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed

src/main/java/AICategorizer.java

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
import java.util.Arrays;
2+
import java.util.List;
3+
4+
/**
5+
* AICategorizer provides rule-based task categorization using keyword matching
6+
* This simulates AI categorization without requiring external APIs
7+
*/
8+
public class AICategorizer {
9+
10+
// Work-related keywords
11+
private static final List<String> WORK_KEYWORDS = Arrays.asList(
12+
"office", "project", "client", "meeting", "presentation", "report", "deadline",
13+
"email", "call", "conference", "proposal", "budget", "team", "manager",
14+
"work", "job", "business", "professional", "corporate", "company",
15+
"task", "assignment", "review", "analysis", "development", "coding",
16+
"programming", "software", "application", "system", "database", "server",
17+
"sprint", "jira", "standup", "merge", "deploy", "deployment", "release",
18+
"pull request", "code review", "pr", "git", "repository", "ticket",
19+
"stakeholder", "spec", "requirement", "roadmap", "scrum", "agile",
20+
"invoice", "timesheet", "payroll", "hr", "hrms", "onboarding", "recruitment",
21+
"zoom", "meet", "teams", "slack", "okr", "kpi"
22+
);
23+
24+
// Personal-related keywords
25+
private static final List<String> PERSONAL_KEYWORDS = Arrays.asList(
26+
"birthday", "family", "shopping", "grocery", "home", "house", "personal",
27+
"friend", "vacation", "holiday", "doctor", "appointment", "health",
28+
"exercise", "gym", "hobby", "book", "movie", "restaurant", "dinner",
29+
"lunch", "breakfast", "party", "celebration", "gift", "anniversary",
30+
"wedding", "travel", "trip", "visit", "clean", "organize", "repair",
31+
"maintenance", "garden", "pet", "car", "insurance", "bank", "finance",
32+
"rent", "electricity", "water bill", "gas bill", "emi", "loan", "bill",
33+
"milk", "vegetables", "fruits", "medicines", "tuition", "school",
34+
"college", "exam", "fees", "passport", "aadhaar", "pan", "license",
35+
"parents", "kids", "spouse", "relatives", "festival", "diwali", "holi"
36+
);
37+
38+
// Urgent-related keywords
39+
private static final List<String> URGENT_KEYWORDS = Arrays.asList(
40+
"urgent", "asap", "immediately", "now", "today", "emergency", "critical",
41+
"important", "priority", "rush", "quick", "fast", "soon", "deadline",
42+
"overdue", "late", "must", "need", "required", "essential", "crucial",
43+
"vital", "pressing", "time-sensitive", "hurry", "instant", "immediate",
44+
"blocker", "p0", "p1", "hotfix", "sev1", "sev2", "outage", "downtime",
45+
"escalation", "last date", "last day", "final", "final call"
46+
);
47+
48+
/**
49+
* Categorizes a task based on its title using keyword matching
50+
* Priority: Urgent > Work > Personal > General
51+
*
52+
* @param taskTitle The title of the task to categorize
53+
* @return The category ("Urgent", "Work", "Personal", or "General")
54+
*/
55+
public static String categorizeTask(String taskTitle) {
56+
if (taskTitle == null || taskTitle.trim().isEmpty()) {
57+
return "General";
58+
}
59+
60+
String lowerTitle = taskTitle.toLowerCase();
61+
62+
// Check for urgent keywords first (highest priority)
63+
for (String keyword : URGENT_KEYWORDS) {
64+
if (lowerTitle.contains(keyword)) {
65+
return "Urgent";
66+
}
67+
}
68+
69+
// Check for work keywords
70+
for (String keyword : WORK_KEYWORDS) {
71+
if (lowerTitle.contains(keyword)) {
72+
return "Work";
73+
}
74+
}
75+
76+
// Check for personal keywords
77+
for (String keyword : PERSONAL_KEYWORDS) {
78+
if (lowerTitle.contains(keyword)) {
79+
return "Personal";
80+
}
81+
}
82+
83+
// Default category if no keywords match
84+
return "General";
85+
}
86+
87+
/**
88+
* Gets a confidence score for the categorization (0.0 to 1.0)
89+
* Higher score means more confident in the categorization
90+
*
91+
* @param taskTitle The title of the task
92+
* @param category The assigned category
93+
* @return Confidence score between 0.0 and 1.0
94+
*/
95+
public static double getConfidenceScore(String taskTitle, String category) {
96+
if (taskTitle == null || taskTitle.trim().isEmpty()) {
97+
return 0.1;
98+
}
99+
100+
String lowerTitle = taskTitle.toLowerCase();
101+
int matchCount = 0;
102+
List<String> relevantKeywords;
103+
104+
switch (category.toLowerCase()) {
105+
case "urgent":
106+
relevantKeywords = URGENT_KEYWORDS;
107+
break;
108+
case "work":
109+
relevantKeywords = WORK_KEYWORDS;
110+
break;
111+
case "personal":
112+
relevantKeywords = PERSONAL_KEYWORDS;
113+
break;
114+
default:
115+
return 0.3; // Low confidence for general category
116+
}
117+
118+
// Count matching keywords
119+
for (String keyword : relevantKeywords) {
120+
if (lowerTitle.contains(keyword)) {
121+
matchCount++;
122+
}
123+
}
124+
125+
// Calculate confidence based on matches
126+
if (matchCount == 0) {
127+
return 0.3;
128+
} else if (matchCount == 1) {
129+
return 0.7;
130+
} else if (matchCount == 2) {
131+
return 0.85;
132+
} else {
133+
return 0.95;
134+
}
135+
}
136+
137+
/**
138+
* Provides suggestions for improving task categorization
139+
*
140+
* @param taskTitle The title of the task
141+
* @return Suggestion string
142+
*/
143+
public static String getSuggestion(String taskTitle) {
144+
String category = categorizeTask(taskTitle);
145+
double confidence = getConfidenceScore(taskTitle, category);
146+
147+
if (confidence < 0.5) {
148+
return "💡 Tip: Add keywords like 'urgent', 'work', or 'personal' to improve auto-categorization!";
149+
} else if (confidence < 0.8) {
150+
return "👍 Good categorization! Consider adding more specific keywords for better accuracy.";
151+
} else {
152+
return "🎯 Excellent! Task categorized with high confidence.";
153+
}
154+
}
155+
156+
/**
157+
* Gets all available categories
158+
*
159+
* @return Array of category names
160+
*/
161+
public static String[] getAvailableCategories() {
162+
return new String[]{"Work", "Personal", "Urgent", "General"};
163+
}
164+
}

0 commit comments

Comments
 (0)