Spaces:
Running
Running
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
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
}
|
| 34 |
|
| 35 |
public Map<String, List<String>> extractSkills(String text) {
|
| 36 |
Map<String, List<String>> extractedSkills = new LinkedHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
List<String> foundSkills = new ArrayList<>();
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 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 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
| 52 |
}
|
| 53 |
-
}
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
}
|