hari7775 commited on
Commit
331da89
·
1 Parent(s): e1e49a7

Feature: Implemented 100% dynamic skills and categories extraction without hardcoding

Browse files
src/main/java/com/resumeparser/processor/SkillsExtractor.java CHANGED
@@ -9,54 +9,95 @@ import org.springframework.stereotype.Component;
9
  @Component
10
  public class SkillsExtractor {
11
 
12
- private static final Map<String, List<String>> SKILL_CATEGORIES = new LinkedHashMap<>();
13
-
14
- static {
15
- SKILL_CATEGORIES.put("Languages", Arrays.asList(
16
- "Java", "Python", "C++", "C#", "JavaScript", "TypeScript", "Ruby", "Go", "Rust", "PHP", "SQL", "HTML", "CSS", "Kotlin", "Swift", "R"
17
- ));
18
- SKILL_CATEGORIES.put("Frameworks & Libraries", Arrays.asList(
19
- "Spring", "Spring Boot", "Hibernate", "React", "ReactJS", "Angular", "Vue", "Django", "Flask", "Express", "Rails", ".NET", "Node.js", "FastAPI", "LangChain", "FAISS", "Transformers", "Whisper", "CTranslate2", "NLLB", "Redux", "Bootstrap", "Chart.js"
20
- ));
21
- SKILL_CATEGORIES.put("Cloud/DevOps", Arrays.asList(
22
- "AWS", "Azure", "GCP", "Docker", "Kubernetes", "Jenkins", "Terraform", "Ansible", "Linux", "Unix", "GitHub Actions", "CI/CD", "Hugging Face Spaces", "Netlify", "Containerization", "Vertex AI", "BigQuery"
23
- ));
24
- SKILL_CATEGORIES.put("Design, Tools & Protocols", Arrays.asList(
25
- "UX/UI", "WCAG", "Git", "Jira", "Maven", "Gradle", "Postman", "Vite", "npm", "yarn", "REST API", "OAuth 2.0", "Gmail API", "OAuth", "Google Cloud Platform"
26
- ));
27
- SKILL_CATEGORIES.put("AI, ML & Retrieval", Arrays.asList(
28
- "RAG Architecture", "RAG", "Vector Search", "VAD Preprocessing", "VAD", "Speech API", "OpenAI Whisper", "Fallback Orchestration", "Mistral-7B", "Mistral"
29
- ));
30
- SKILL_CATEGORIES.put("Data & Observability", Arrays.asList(
31
- "ETL", "ETL Pipelines", "API Ingestion", "Log Analysis", "Anomaly Detection", "Performance Monitoring", "Data Analytics"
32
- ));
 
 
 
 
 
 
 
33
  }
34
 
35
  public Map<String, List<String>> extractSkills(String text) {
36
  Map<String, List<String>> extractedSkills = new LinkedHashMap<>();
 
 
 
 
 
 
 
37
 
38
- for (Map.Entry<String, List<String>> entry : SKILL_CATEGORIES.entrySet()) {
39
- String category = entry.getKey();
40
- List<String> skills = entry.getValue();
41
- List<String> foundSkills = new ArrayList<>();
42
 
43
- for (String skill : skills) {
44
- // Use custom boundary logic to handle special symbols (e.g. C++, .NET, OAuth 2.0, Mistral-7B) safely
45
- String escapedSkill = Pattern.quote(skill);
46
- String patternString = "(?i)(^|[^a-zA-Z0-9_+#.-])" + escapedSkill + "($|[^a-zA-Z0-9_+#.-])";
47
- Pattern pattern = Pattern.compile(patternString);
48
- Matcher matcher = pattern.matcher(text);
49
 
50
- if (matcher.find()) {
51
- foundSkills.add(skill);
 
 
 
52
  }
53
- }
54
 
55
- if (!foundSkills.isEmpty()) {
56
- extractedSkills.put(category, foundSkills);
 
 
 
 
 
 
 
 
57
  }
58
  }
59
 
 
 
 
 
60
  return extractedSkills;
61
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  }
 
9
  @Component
10
  public class SkillsExtractor {
11
 
12
+ private String extractSkillsSection(String text) {
13
+ String[] sections = {"TECHNICAL SKILLS", "SKILLS"};
14
+ for (String section : sections) {
15
+ String regex = "(?mi)^\\s*" + Pattern.quote(section) + "\\s*[:\\-]?\\s*(?:\\n|\\r|$)";
16
+ Pattern p = Pattern.compile(regex);
17
+ Matcher m = p.matcher(text);
18
+ if (m.find()) {
19
+ int start = m.end();
20
+ // Find next section header or end of text to bound the skills section
21
+ String[] nextHeaders = {
22
+ "EXPERIENCE", "WORK EXPERIENCE", "EDUCATION", "PROJECTS",
23
+ "KEY PROJECTS", "CERTIFICATIONS", "ACHIEVEMENTS", "LANGUAGES", "SUMMARY"
24
+ };
25
+ int end = text.length();
26
+ for (String next : nextHeaders) {
27
+ String nextRegex = "(?mi)^\\s*" + Pattern.quote(next) + "\\s*[:\\-]?\\s*(?:\\n|\\r|$)";
28
+ Pattern nextP = Pattern.compile(nextRegex);
29
+ Matcher nextM = nextP.matcher(text);
30
+ if (nextM.find(start)) {
31
+ if (nextM.start() < end) {
32
+ end = nextM.start();
33
+ }
34
+ }
35
+ }
36
+ return text.substring(start, end).trim();
37
+ }
38
+ }
39
+ return "";
40
  }
41
 
42
  public Map<String, List<String>> extractSkills(String text) {
43
  Map<String, List<String>> extractedSkills = new LinkedHashMap<>();
44
+ if (text == null || text.isEmpty()) return extractedSkills;
45
+
46
+ String skillsSection = extractSkillsSection(text);
47
+ if (skillsSection.isEmpty()) {
48
+ // Fallback: search entire text if specific section header isn't matched
49
+ skillsSection = text;
50
+ }
51
 
52
+ String[] lines = skillsSection.split("\\n");
53
+ String currentCategory = null;
54
+ List<String> currentSkills = new ArrayList<>();
 
55
 
56
+ for (String line : lines) {
57
+ String trimmed = line.trim();
58
+ if (trimmed.isEmpty()) continue;
 
 
 
59
 
60
+ // If the line contains a colon and is not an HTTP link, it is a category header
61
+ if (trimmed.contains(":") && !trimmed.toLowerCase().contains("http://") && !trimmed.toLowerCase().contains("https://")) {
62
+ if (currentCategory != null && !currentSkills.isEmpty()) {
63
+ extractedSkills.put(currentCategory, new ArrayList<>(currentSkills));
64
+ currentSkills.clear();
65
  }
 
66
 
67
+ int colonIdx = trimmed.indexOf(":");
68
+ currentCategory = trimmed.substring(0, colonIdx).trim();
69
+ String skillsPart = trimmed.substring(colonIdx + 1).trim();
70
+
71
+ parseAndAddSkills(skillsPart, currentSkills);
72
+ } else {
73
+ // Continuation line (append to active category)
74
+ if (currentCategory != null) {
75
+ parseAndAddSkills(trimmed, currentSkills);
76
+ }
77
  }
78
  }
79
 
80
+ if (currentCategory != null && !currentSkills.isEmpty()) {
81
+ extractedSkills.put(currentCategory, currentSkills);
82
+ }
83
+
84
  return extractedSkills;
85
  }
86
+
87
+ private void parseAndAddSkills(String skillsText, List<String> targetList) {
88
+ if (skillsText == null || skillsText.isEmpty()) return;
89
+
90
+ // Split by comma, preserving commas inside parentheses (e.g. "Platform (API, BigQuery, Vertex AI)")
91
+ String[] parts = skillsText.split(",(?![^(]*\\))");
92
+ for (String part : parts) {
93
+ String skill = part.trim();
94
+ // Remove leading bullet characters or dashes
95
+ skill = skill.replaceAll("^\\s*[-—•*]\\s*", "").trim();
96
+ if (!skill.isEmpty()) {
97
+ if (!targetList.contains(skill)) {
98
+ targetList.add(skill);
99
+ }
100
+ }
101
+ }
102
+ }
103
  }