Spaces:
Running
Running
optimize cv extraction
Browse files- services/cv_chunker.py +30 -8
services/cv_chunker.py
CHANGED
|
@@ -164,6 +164,9 @@ def _detect_section(stripped_line: str, raw_line: str) -> Optional[str]:
|
|
| 164 |
line_norm = _normalize(_strip_md(_strip_html(stripped_line)))
|
| 165 |
if not line_norm:
|
| 166 |
return None
|
|
|
|
|
|
|
|
|
|
| 167 |
if re.match(r"^\d", line_norm):
|
| 168 |
return None
|
| 169 |
if _PERIOD_RE.search(stripped_line):
|
|
@@ -249,13 +252,26 @@ def _parse_experience(raw: str) -> List[Dict[str, Any]]:
|
|
| 249 |
current: Optional[Dict[str, Any]] = None
|
| 250 |
|
| 251 |
for raw_line in raw.splitlines():
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
if not line:
|
| 254 |
continue
|
| 255 |
if re.match(r"^[\w\s]+:\s*$", line) and len(line) < 40:
|
| 256 |
continue
|
| 257 |
|
| 258 |
-
period = _extract_period(line)
|
| 259 |
is_bullet = bool(_BULLET_RE.match(line))
|
| 260 |
clean = _strip_period(_BULLET_RE.sub("", line)).strip()
|
| 261 |
|
|
@@ -477,12 +493,18 @@ def _parse_contact(raw: str, cv_full: str) -> Dict[str, Any]:
|
|
| 477 |
if lbl_m:
|
| 478 |
location = lbl_m.group(1).strip()
|
| 479 |
else:
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
|
| 487 |
return {
|
| 488 |
"email": email_m.group(0).strip() if email_m else "",
|
|
|
|
| 164 |
line_norm = _normalize(_strip_md(_strip_html(stripped_line)))
|
| 165 |
if not line_norm:
|
| 166 |
return None
|
| 167 |
+
# If header contains separated single letters (e.g., "c a r e e r s u m m a r y"), collapse them
|
| 168 |
+
if re.match(r"^(?:[a-z]\s+)+[a-z]$", line_norm):
|
| 169 |
+
line_norm = line_norm.replace(" ", "")
|
| 170 |
if re.match(r"^\d", line_norm):
|
| 171 |
return None
|
| 172 |
if _PERIOD_RE.search(stripped_line):
|
|
|
|
| 252 |
current: Optional[Dict[str, Any]] = None
|
| 253 |
|
| 254 |
for raw_line in raw.splitlines():
|
| 255 |
+
stripped_raw = raw_line.strip()
|
| 256 |
+
if re.match(r"^\|[\s\-|:]+\|$", stripped_raw):
|
| 257 |
+
continue
|
| 258 |
+
if stripped_raw.startswith("|") and stripped_raw.count("|") >= 2:
|
| 259 |
+
cells = [_clean_line(c) for c in stripped_raw.strip("|").split("|")]
|
| 260 |
+
cells = [c for c in cells if c]
|
| 261 |
+
if not cells:
|
| 262 |
+
continue
|
| 263 |
+
line = cells[0]
|
| 264 |
+
extra_period = _extract_period(cells[-1]) if len(cells) > 1 else None
|
| 265 |
+
else:
|
| 266 |
+
line = _clean_line(raw_line)
|
| 267 |
+
extra_period = None
|
| 268 |
+
|
| 269 |
if not line:
|
| 270 |
continue
|
| 271 |
if re.match(r"^[\w\s]+:\s*$", line) and len(line) < 40:
|
| 272 |
continue
|
| 273 |
|
| 274 |
+
period = _extract_period(line) or extra_period
|
| 275 |
is_bullet = bool(_BULLET_RE.match(line))
|
| 276 |
clean = _strip_period(_BULLET_RE.sub("", line)).strip()
|
| 277 |
|
|
|
|
| 493 |
if lbl_m:
|
| 494 |
location = lbl_m.group(1).strip()
|
| 495 |
else:
|
| 496 |
+
# Require location text to be in close proximity to contact info or explicit header to prevent matching technical skills text
|
| 497 |
+
for line in loc_text.splitlines():
|
| 498 |
+
line_str = line.strip()
|
| 499 |
+
if not line_str or re.search(r"languages|frameworks|tools|databases|skills|developer|engineer|experience", line_str, re.IGNORECASE):
|
| 500 |
+
continue
|
| 501 |
+
loc_m = _LOCATION_RE.search(line_str)
|
| 502 |
+
if loc_m:
|
| 503 |
+
w1 = (loc_m.group(1) or "").lower()
|
| 504 |
+
w2 = (loc_m.group(2) or "").lower()
|
| 505 |
+
if w1 not in _TECH_LOC_BLACKLIST and w2 not in _TECH_LOC_BLACKLIST:
|
| 506 |
+
location = loc_m.group(0).strip()
|
| 507 |
+
break
|
| 508 |
|
| 509 |
return {
|
| 510 |
"email": email_m.group(0).strip() if email_m else "",
|