Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 29 additions & 25 deletions cli/integrations/job_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,29 @@ class JobParser:
"remote available",
]

# Pre-compiled regex patterns for extraction
_SALARY_PATTERNS = [
re.compile(r"\$[\d,]+(?:\s*[-–to]+\s*\$[\d,]+)?", re.IGNORECASE), # $100k - $150k
re.compile(r"\$[\d,]+k(?:\s*[-–to]+\s*\$[\d,]+k)?", re.IGNORECASE), # $100k - $150k
re.compile(r"[\d,]+k(?:\s*[-–to]+\s*[\d,]+k)", re.IGNORECASE), # 100k - 150k
re.compile(r"(?:salary|pay|compensation)[:\s]*(\$[^<>\n]+)", re.IGNORECASE), # Salary: $X
re.compile(r"(?:per|/)\s*(?:year|annum)[:\s]*(\$[^<>\n]+)", re.IGNORECASE), # per year: $X
]

_JOB_TYPE_PATTERNS = [
re.compile(
r"\b(full[- ]?time|part[- ]?time|contract|freelance|intern|temporary)\b", re.IGNORECASE
),
re.compile(r"\b(permanent|fixed[- ]?term)\b", re.IGNORECASE),
]

_EXPERIENCE_LEVEL_PATTERNS = [
re.compile(
r"\b(entry[- ]?level|junior|mid[- ]?level|senior|staff|principal|lead)\b", re.IGNORECASE
),
re.compile(r"\b(associate|vice[- ]?president|director|executive)\b", re.IGNORECASE),
]

def __init__(self, cache_dir: Optional[Path] = None):
"""
Initialize job parser.
Expand Down Expand Up @@ -555,17 +578,8 @@ def _extract_salary_from_text(self, text: str) -> Optional[str]:
Returns:
Salary string or None
"""
# Common salary patterns
patterns = [
r"\$[\d,]+(?:\s*[-–to]+\s*\$[\d,]+)?", # $100k - $150k
r"\$[\d,]+k(?:\s*[-–to]+\s*\$[\d,]+k)?", # $100k - $150k
r"[\d,]+k(?:\s*[-–to]+\s*[\d,]+k)", # 100k - 150k
r"(?:salary|pay|compensation)[:\s]*(\$[^<>\n]+)", # Salary: $X
r"(?:per|/)\s*(?:year|annum)[:\s]*(\$[^<>\n]+)", # per year: $X
]

for pattern in patterns:
match = re.search(pattern, text, re.IGNORECASE)
for pattern in self._SALARY_PATTERNS:
match = pattern.search(text)
if match:
salary = match.group(0) if match.lastindex is None else match.group(1)
# Clean up the salary string
Expand Down Expand Up @@ -805,13 +819,8 @@ def _extract_job_type(self, html: str) -> Optional[str]:
Returns:
Job type string or None
"""
patterns = [
r"\b(full[- ]?time|part[- ]?time|contract|freelance|intern|temporary)\b",
r"\b(permanent|fixed[- ]?term)\b",
]

for pattern in patterns:
match = re.search(pattern, html, re.IGNORECASE)
for pattern in self._JOB_TYPE_PATTERNS:
match = pattern.search(html)
if match:
return match.group(1).lower().replace("-", "-")

Expand All @@ -827,13 +836,8 @@ def _extract_experience_level(self, html: str) -> Optional[str]:
Returns:
Experience level string or None
"""
patterns = [
r"\b(entry[- ]?level|junior|mid[- ]?level|senior|staff|principal|lead)\b",
r"\b(associate|vice[- ]?president|director|executive)\b",
]

for pattern in patterns:
match = re.search(pattern, html, re.IGNORECASE)
for pattern in self._EXPERIENCE_LEVEL_PATTERNS:
match = pattern.search(html)
if match:
return match.group(1).lower().replace("-", "-")

Expand Down
33 changes: 18 additions & 15 deletions cli/utils/keyword_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
from ..utils.config import Config
from ..utils.yaml_parser import ResumeYAML

# Pre-compiled regex patterns for extraction
_TITLE_PATTERNS = [
re.compile(r"(?:job title|position|title):\s*([^\n]+)", re.IGNORECASE | re.MULTILINE),
re.compile(r"^([^\n]+)\s*[-|]\s*[^|]+$", re.IGNORECASE | re.MULTILINE),
re.compile(
r"#\s*([^\n]+)", re.IGNORECASE | re.MULTILINE
), # Markdown headers often have job title
]

_COMPANY_PATTERNS = [
re.compile(r"(?:company|organization):\s*([^\n]+)", re.IGNORECASE),
re.compile(r"(?:at|from)\s+([A-Z][^\n]+?)(?:\s+[-\u2014]|\s+$)", re.IGNORECASE),
]

# Load environment variables from .env file if present
try:
from dotenv import load_dotenv
Expand Down Expand Up @@ -208,26 +222,15 @@ def _extract_job_details(self, job_description: str) -> Tuple[str, str]:
company = ""

# Try to extract job title (common patterns)
title_patterns = [
r"(?:job title|position|title):\s*([^\n]+)",
r"^([^\n]+)\s*[-|]\s*[^|]+$",
r"#\s*([^\n]+)", # Markdown headers often have job title
]

for pattern in title_patterns:
match = re.search(pattern, job_description, re.IGNORECASE | re.MULTILINE)
for pattern in _TITLE_PATTERNS:
match = pattern.search(job_description)
if match:
job_title = match.group(1).strip()
break

# Try to extract company name
company_patterns = [
r"(?:company|organization):\s*([^\n]+)",
r"(?:at|from)\s+([A-Z][^\n]+?)(?:\s+[-\u2014]|\s+$)",
]

for pattern in company_patterns:
match = re.search(pattern, job_description, re.IGNORECASE)
for pattern in _COMPANY_PATTERNS:
match = pattern.search(job_description)
if match:
company = match.group(1).strip()
break
Expand Down
Loading