Read a seniority level from the title
from_title folds the title and matches whole words in English, Danish, Swedish, German, French, Dutch and Spanish, highest level first, with intern tried before the rest. Individual-contributor managers (Account, Product, Project ...) stay unknown; a manager is a level only where the word means a team, a site or a shop. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
64f367cc18
commit
d7fa9527b4
2 files changed
+486
No files matched your search
@@ -0,0 +1,236 @@
|
||||
"""`from_title`: the level a job title names, as one of `SENIORITIES`, or `''`.
|
||||
|
||||
What fills `roles.seniority` at ingest, before `extract` has read the posting
|
||||
(which overwrites it). `''` and not `"mid"` when the title does not say:
|
||||
most titles name no level, and a filter that treats "does not say" as a level
|
||||
loses every role it could not read. So every rule here is written for
|
||||
precision, and a title that matches nothing stays unknown.
|
||||
|
||||
The approach is `plugins/ats.classify`'s, after its substring matches went
|
||||
wrong (" it" inside "Italy"): the title is folded with `title_key` (case,
|
||||
accents and the `(m/w/d)` marker gone, punctuation to spaces) and every
|
||||
pattern is a word-bounded regex against that. Patterns are therefore written
|
||||
folded: `direktör` is `direktor`, `chef d'équipe` is `chef d equipe`; `ø` and
|
||||
`æ` stay as they are, since NFKD does not decompose them.
|
||||
|
||||
The highest level named wins, checked from `exec` down: "Senior Director" is
|
||||
a director, "Managing Director" an exec, "Lead Project Manager" a lead. The
|
||||
one exception is `intern`, tried first: a title that says internship or
|
||||
thesis is one whatever it names after ("Praktikum ... Assistenz des Senior
|
||||
Vice Presidents"). A C-level or head named as the boss of the person hired
|
||||
("Executive Assistant to the CEO", "Office of the Head of ...") is cut out
|
||||
before matching (`_NOISE`). Rules that decide the doubtful cases:
|
||||
|
||||
- **manager** is a level only where the word means someone who runs a team:
|
||||
a bare "Manager", "Senior Manager", "Manager, Data Science" (the word
|
||||
first, as a level), an "Assistant Store Manager" as a lead, and the compounds whose department or place is what is
|
||||
managed (`_PEOPLE_MANAGER`: engineering, team, store, general ...). Every
|
||||
other "X Manager" is an individual contributor by function (Account,
|
||||
Product, Project, Customer Success, Office, Marketing, Sales ...) and says
|
||||
nothing, so "Senior Product Manager" is senior. An unlisted compound stays
|
||||
unknown, which costs a recall the filter's "and no level" makes up.
|
||||
- **director** is the word in English, Danish, Swedish, German, French, Spanish
|
||||
and Italian, "Head of" and a title's own first word "Head", and the German
|
||||
"Leiter" alone or of a whole department (Bereichsleiter, Abteilungsleiter).
|
||||
"Associate Director" and "Executive Director" are directors. **manager** is
|
||||
also the Danish, Swedish, German and Dutch head of a shop, site or office
|
||||
(-chef, -leder, Filialleiter, Kontorchef), French "responsable" and "gérant",
|
||||
Spanish "jefe" and "gerente". **exec** is C-level ("Chief ... Officer", CTO), "VP" and above
|
||||
(a bank's VP is mid-level, but a tech company's is not, and the filter is
|
||||
the reader's: exec), "Managing Director", Geschäftsführer, Vorstand and VD.
|
||||
A bank's "Assistant Vice President" is a director.
|
||||
- **lead** is "Lead" as a noun at either end ("Tech Lead", "Lead Engineer";
|
||||
not "Lead Generation"), "Leader", "Supervisor", and the team-sized German,
|
||||
Danish, Dutch and French forms (Teamleiter, Teamleider, chef d'équipe).
|
||||
- **staff** is "Staff" and "Principal". "Staff Nurse", "Staff Accountant"
|
||||
and their kind are left out; "Principal Investigator" and a
|
||||
"Staff Scientist" at a lab are taken as staff and are not.
|
||||
- **project managers stay unknown** in every language (Projektleiter,
|
||||
Bauleiter, chef de projet, projektleder, prosjektleder): they are Project
|
||||
Managers. Halbleiter and the other -leiter words for things are cut out too.
|
||||
- **intern** is anything that says the person is still studying or training:
|
||||
intern, Werkstudent, Praktikant, stagiaire, Ausbildung, apprentice,
|
||||
elev, studentermedhjælper, a thesis. **junior** is "Junior", "Graduate",
|
||||
"Trainee" and "entry level". **mid** only when the title says so:
|
||||
"Mid-level", "Intermediate", "II", "Medior".
|
||||
|
||||
Known wrong, and left so: "Senior Care Assistant" and other "senior" that
|
||||
means elderly; "Level II" outside a role level; "Principal Investigator";
|
||||
"Staff" on a title with an unlisted staff noun; "Field CTO" taken as unknown;
|
||||
"Chief of Staff" as unknown; "Assistant Manager" as unknown; French "responsable" is
|
||||
taken as a manager wherever it stands, and "Directeur" of a small firm as a
|
||||
director; "VP" as exec at a bank.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
|
||||
from app.models import title_key
|
||||
|
||||
#: A C-level title or abbreviation, for `_NOISE`.
|
||||
_C_LEVEL = (r"(?:ceo|cto|cfo|coo|cio|ciso|cpo|cdo|chro|caio"
|
||||
r"|chief(?: \w+){0,3} officer|managing director|(?<!vice )president"
|
||||
r"|geschaftsfuhr\w*|geschaftsfuhrung|vorstand)")
|
||||
|
||||
#: A vice president, which the phrases below take as a boss only after "to the",
|
||||
#: not after "assistant" ("Assistant Vice President" is a director).
|
||||
_VP = r"(?:vice president|[se]?vp)"
|
||||
|
||||
#: Phrases that carry a level word without naming a level, cut out of the
|
||||
#: folded title before anything is matched: "Chief of Staff" is not "Staff",
|
||||
#: "Executive Assistant to the CEO" is not a CEO, "Lead Generation" is not a
|
||||
#: Lead. What a title says after "reporting to" is about someone else.
|
||||
_NOISE = re.compile(
|
||||
r"\b(?:chief of staff|member of technical staff|technical staff"
|
||||
r"|(?:support|kitchen|wait|nursing|field|floor|retail|store|clinical|medical"
|
||||
r"|teaching|academic|administrative|hospital|bar|service|office|warehouse"
|
||||
r"|hotel|catering|cabin|restaurant|casual|agency|temporary|volunteer|library"
|
||||
r"|hourly|seasonal|healthcare|sales|customer) staff"
|
||||
r"|staff (?:accountant|nurse|attorney|pharmacist|auditor|writer|reporter"
|
||||
r"|assistant|augmentation|admin|augment|nurses)"
|
||||
r"|lead (?:gen(?:eration)?|development rep\w*|qualification|nurturing"
|
||||
r"|scoring|capture|to (?:cash|revenue))"
|
||||
rf"|(?:to|for|of|des|der) (?:the |dem |den )?(?:{_C_LEVEL}|{_VP})"
|
||||
rf"|(?:assistant|assistenz|assistent|secretary|sekretar\w*|business partner|coordinator"
|
||||
rf"|office|support|referent\w*|advisor|adviser) (?:\w+ ){{0,3}}?{_C_LEVEL}"
|
||||
rf"|{_C_LEVEL} (?:assistant|assistenz|office|team|support|founder associate)"
|
||||
r"|field (?:cto|cio|ciso)"
|
||||
r"|\w*(?:halb|nicht|supra|strom|blitzab)leiter"
|
||||
r"|\w*(?:projekt|prosjekt|project|bau|bygge|produkt)(?:leiter|leitung|leder|ledare|leider)(?:in)?"
|
||||
r"|zugchef\w*)\b"
|
||||
r"|\breport(?:s|ing)? to\b.*",
|
||||
)
|
||||
|
||||
#: "X Manager" where the manager runs a team, a site or a shop; see the
|
||||
#: docstring. Only the word directly before "manager" counts.
|
||||
_PEOPLE_MANAGER = (
|
||||
r"(?:engineering|software development|science|research|hardware|team|department"
|
||||
r"|group|store|branch|restaurant|shift|warehouse|site|plant|area|district"
|
||||
r"|regional|country|general)")
|
||||
|
||||
#: The stems of the -leiter/-leder words that are a team lead, not a manager.
|
||||
_TEAM_SIZED = r"(?:team|gruppen?|grupp|schicht|hold|vagt)"
|
||||
|
||||
#: Words after a title-initial "Head" that make it a job of its own (Head
|
||||
#: Chef), not the head of a function.
|
||||
_HEAD_JOBS = (r"(?:chef|cook|barista|nurse|coach|waiter|bartender|mechanic|gardener"
|
||||
r"|teacher|cashier|housekeeper|receptionist|technician|butcher|baker"
|
||||
r"|stylist|of)")
|
||||
|
||||
#: `(level, patterns)`, in the order they are tried: `intern` first, since a
|
||||
#: title that says internship is one whatever it names after ("Internship, Office
|
||||
#: of the Head of Product"); then the rest from `exec` down. A title takes the
|
||||
#: first level with a match, so a rule need not exclude what a later rule claims.
|
||||
_RULES: tuple[tuple[str, tuple[str, ...]], ...] = (
|
||||
("intern", (
|
||||
r"\binterns?\b", r"\binternship\w*", r"\bwerkstudent\w*", r"\bworking students?\b",
|
||||
r"\bstudent (?:assistant|worker|helper|aide|job|position|trainee|employee)s?\b",
|
||||
r"\bstudentische\w*", r"\bstudent(?:er)?med(?:hj|arb)\w*",
|
||||
r"\bstudent\w*job\w*", r"\bjobstudent\b",
|
||||
r"\w*praktik(?:um|ant\w*|a|ophold|plads)?\b", r"\bpraxissemester\b", r"\bduales? studium\b",
|
||||
r"\bstagiaires?\b", r"\bstagiair\w*", r"\bstagista\b", r"\btirocin\w*",
|
||||
r"\bestagiari[oa]s?\b", r"\bbecari[oa]s?\b", r"\bpracticas\b", r"\bpracticante\b",
|
||||
r"\baprendiz\b", r"\balternan\w*", r"\bapprenti(?:e|es|s)?\b", r"\bapprentice\w*",
|
||||
r"\bazubi\b", r"\bauszubildende\w*", r"\bausbildung\b", r"\blehr(?:ling|ausbildung|stelle)\b",
|
||||
r"\w*lærling\w*", r"\b\w*elev\b",
|
||||
r"\b\w+student\b", r"(?<!phd )(?<!doctoral )(?<!graduate )(?<!masters )\bstudent$",
|
||||
r"\bvolontar\w*",
|
||||
r"\b(?:master|bachelor|abschluss)arbeit\b", r"\bthesis\b",
|
||||
r"\bmasterproef\b", r"\beindwerk\b", r"\bafstudeer\w*",
|
||||
# French and Dutch "stage": a title that starts or ends with it, or
|
||||
# says how many months, and not the English stage (Stage Manager, early stage).
|
||||
r"^stage\b(?! (?:manager|management|hand|crew|technician|director|lighting|door))",
|
||||
r"(?<!early )(?<!late )(?<!growth )(?<!seed )(?<!mid )(?<!next )(?<!final )"
|
||||
r"(?<!pre )(?<!first )(?<!phase )\bstage$",
|
||||
r"\bstage (?:\d+ )?(?:mois|mesi|maanden|months)\b",
|
||||
)),
|
||||
("exec", (
|
||||
r"\b(?:ceo|cto|cfo|coo|cio|ciso|cpo|cdo|chro|caio)\b",
|
||||
r"\bchief(?: \w+){0,4}? officer\b", r"\bchief executive\b",
|
||||
r"(?<!assistant )(?<!associate )(?<!assoc )\b(?:vice president|[se]?vp)\b",
|
||||
r"(?<!vice )\bpresident\b",
|
||||
r"\bmanaging director\b", r"\b(?:administrerende|verkstallande) direktor\b",
|
||||
r"\badministrerende direktør\b", r"\bvd\b", r"\bpdg\b",
|
||||
r"\bdirecteur general\b", r"\bdirector general\b",
|
||||
r"\bgeschaftsfuhr\w*", r"\bgeschaftsleit\w*", r"\bvorstand\b",
|
||||
)),
|
||||
("director", (
|
||||
r"\b(?:director(?:a|s|es|in)?|directeur|directrice|direktor(?:in|er)?"
|
||||
r"|direktør(?:er)?|direttore|direttrice)\b",
|
||||
r"\bavp\b", r"\b(?:assistant|associate|assoc) (?:vice president|vp)\b",
|
||||
r"\bhead of\b", r"\b(?:department|division|unit|practice|group|team|country|regional) head\b",
|
||||
rf"^head (?!{_HEAD_JOBS}\b)", r"\bhead$",
|
||||
# Leiter(in) alone or of a whole unit (Bereichsleiter), and a title that
|
||||
# starts with Leitung; "mit technischer Leitung" is a job with a duty.
|
||||
r"\bleiter(?:in)?\b", r"^leitung\b",
|
||||
r"\b(?:bereichs|abteilungs|hauptabteilungs|geschaftsbereichs|vertriebs"
|
||||
r"|entwicklungs|werks)leit(?:er|erin|ung)\b",
|
||||
r"\bhoofd\b",
|
||||
)),
|
||||
("manager", (
|
||||
r"^(?:(?:senior|sr|global|regional|group|executive) )*manager\b",
|
||||
r"\b(?:senior|sr) manager\b",
|
||||
rf"(?<!assistant )(?<!deputy )(?<!asst )\b{_PEOPLE_MANAGER} manager\b",
|
||||
# -leiter / -leder / -leider of a shop, site or department: Filialleiter,
|
||||
# Afdelingsleder. The team-sized ones are lead (below), and project ones
|
||||
# are cut out by _NOISE. A -leitung is only these, since "Rohrleitung"
|
||||
# is a pipe.
|
||||
rf"\b(?!{_TEAM_SIZED}\w*leit)\w+leit(?:er|erin)\b",
|
||||
r"\b(?:filial|standort|betriebs|service|niederlassungs|markt|geschafts)leitung\b",
|
||||
rf"\b(?!{_TEAM_SIZED}\w*led)\w+leder\b", r"\bleder\b",
|
||||
rf"\b(?!{_TEAM_SIZED}\w*leid)\w+leider\b", r"\bleidinggevende\b",
|
||||
# Danish and Swedish compounds (kontorchef, avdelningschef); a bare
|
||||
# "chef" is a cook or French and says nothing.
|
||||
r"\b\w{3,}chef(?:er|en)?\b",
|
||||
r"\b(?:drift|avdelnings|enhets|verksamhets|butiks|lager|produktions)ledare\b",
|
||||
r"\bchef (?:for|fur|i|til|inom|over|pa|av)\b",
|
||||
r"\bchef d(?:e|u)? (?:service|departement|secteur|magasin|rayon|agence|site"
|
||||
r"|pole|atelier|production)\b",
|
||||
r"\bresponsable\b(?! adjoint| d(?:e|u|es)? projets?\b)", r"(?<!assistant )\bgerant\w*", r"\bgerente\b",
|
||||
r"\bjef[ea]\b(?! d(?:e|el) (?:equipo|proyecto|obra)\b)",
|
||||
r"\bresponsabile\b",
|
||||
)),
|
||||
("lead", (
|
||||
r"\b(?:team|tech|squad)?lead\b", r"\b(?:team|shift)?leader\b",
|
||||
r"\bsupervisor\b", r"\bsuperviseur\b",
|
||||
rf"\b(?:assistant|deputy|asst) {_PEOPLE_MANAGER} manager\b",
|
||||
r"\b(?:team|gruppen?|schicht|hold|vagt)(?:leit(?:er|erin|ung)|leder|leider)\b",
|
||||
r"\b(?:team|grupp)?ledare\b", r"\bchef(?: fe)? d equipe\b", r"\blider\b",
|
||||
r"\bjef[ea] de equipo\b",
|
||||
)),
|
||||
("staff", (
|
||||
r"\bstaff\b", r"\bprincipal\b", r"\bdistinguished\b",
|
||||
# SAP's top individual-contributor grade.
|
||||
r"\bchief expert\b",
|
||||
)),
|
||||
("senior", (
|
||||
r"\b(?:senior|sr|snr|iii)\b",
|
||||
)),
|
||||
("mid", (
|
||||
r"\bmid ?level\b", r"\bintermediate\b", r"\bii\b", r"\bmedior\b",
|
||||
r"\bconfirme\b",
|
||||
)),
|
||||
("junior", (
|
||||
r"\b(?:junior|jr|entry level|graduates?|grad|new grad|early careers?"
|
||||
r"|young professional|absolvent\w*|berufseinsteiger\w*|debutant\w*)\b",
|
||||
r"\btrainee\w*",
|
||||
)),
|
||||
)
|
||||
|
||||
#: `_RULES`, compiled once, in the same order.
|
||||
_COMPILED: tuple[tuple[str, tuple[re.Pattern[str], ...]], ...] = tuple(
|
||||
(level, tuple(re.compile(pattern) for pattern in patterns))
|
||||
for level, patterns in _RULES)
|
||||
|
||||
|
||||
def from_title(title: str) -> str:
|
||||
"""The highest level `title` names, one of `SENIORITIES`, or `''` when it
|
||||
names none. See the module docstring for what counts."""
|
||||
folded = " ".join(_NOISE.sub(" ", title_key(title)).split())
|
||||
if not folded:
|
||||
return ""
|
||||
for level, patterns in _COMPILED:
|
||||
if any(pattern.search(folded) for pattern in patterns):
|
||||
return level
|
||||
return ""
|
||||
Reference in new issue
Block a user