Repository navigation
Expand file tree
/
Copy pathqa_description_extractor.py
More file actions
105 lines (80 loc) · 2.17 KB
/
Copy pathqa_description_extractor.py
File metadata and controls
105 lines (80 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""Conservative extraction of QA role evidence from listing text."""
import re
ROLE_HEADINGS = {
"responsibilities",
"key responsibilities",
"requirements",
"job requirements",
"qualifications",
"job duties",
"what you will do",
}
STOP_HEADINGS = {
"about us",
"about the company",
"company overview",
"company background",
"benefits",
"compensation",
"equal opportunity",
"how to apply",
"job overview",
"job summary",
"who we are",
"our mission",
"our culture",
"why join us",
"company information",
}
def clean_heading(line):
return re.sub(
r"^[#*\s-]+|[:\s*]+$",
"",
line.strip().lower(),
)
def is_unknown_heading(line):
stripped = line.strip()
if not stripped:
return False
if re.match(r"^#{1,6}\s+\S+", stripped):
return True
if stripped.endswith(":") and len(stripped) <= 60:
return True
return False
def extract_role_evidence(card_text):
"""Extract explicitly labeled role duties or requirements.
Returns an empty string when reliable evidence is unavailable.
Does not classify jobs or access external resources.
"""
if not isinstance(card_text, str):
return ""
selected = []
collecting = False
for raw_line in card_text.splitlines():
line = raw_line.strip()
if not line:
continue
heading = clean_heading(line)
if heading in ROLE_HEADINGS:
collecting = True
continue
if heading in STOP_HEADINGS:
collecting = False
continue
inline = re.match(
r"^(responsibilities|key responsibilities|"
r"requirements|job requirements|qualifications|"
r"job duties|what you will do)\s*:\s*(.+)$",
line,
re.IGNORECASE,
)
if inline:
collecting = True
selected.append(inline.group(2).strip())
continue
if is_unknown_heading(line):
collecting = False
continue
if collecting:
selected.append(line)
return "\n".join(selected).strip()