"""`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|(? 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 ""