Prep stage: host words stored raw, mapped centrally in app/prep after every pull
upsert_role stores the host's own words (roles.*_host), the place texts unresolved when they change, and the company key unresolved on insert, and marks the role prep_due. app.prep maps seniority, employment, remote and country through the host tables in app/prep/hosts, resolves places and company aliases, lists unknown words in `unmapped`, remaps every open role when the tables' fingerprint changes, and runs rebuild_dupes, which moves out of the pull's settle. Migration 22 adds the columns and the table and fills the host words from raw. Cascade: pull, prep, embed, score, enrich, prep, embed, score, extract, score, summarise. `app prep [unmapped] [--remap]`, /api/prep/unmapped and a fold on the Sources page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a66aac95cf
commit
d04ceae7e0
31 files changed
+1468
-330
No files matched your search
@@ -0,0 +1,55 @@
|
||||
"""A role's country, from its places, else from the one its host states."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
|
||||
from app import places
|
||||
|
||||
|
||||
def of_host(gaz: places.Gazetteer, stated: str) -> str | None:
|
||||
"""The ISO code a host's country names, in the host's spelling: a code
|
||||
("DK", "dk"), or a name the gazetteer has as an alias of a country
|
||||
("Denmark", "Danmark"), `EU` or Europe by name, or a text that resolves to places of one
|
||||
country. '' for nothing stated, None for a text naming no country."""
|
||||
text = (stated or "").strip()
|
||||
if not text:
|
||||
return ""
|
||||
if ("country", text.upper()) in gaz.by_key or text.upper() == "EU":
|
||||
return text.upper()
|
||||
named = {"EU" if gaz.places[p].key == "europe" else gaz.places[p].key
|
||||
for p in gaz.aliases.get(places.fold(text), ())
|
||||
if gaz.places[p].kind == "country"
|
||||
or (gaz.places[p].kind, gaz.places[p].key) == ("continent", "europe")}
|
||||
if len(named) == 1:
|
||||
return named.pop()
|
||||
found = {gaz.country(p) for p in gaz.resolve(text)} - {""}
|
||||
return found.pop() if len(found) == 1 else None
|
||||
|
||||
|
||||
def _in_europe(gaz: places.Gazetteer, code: str) -> bool:
|
||||
if code == "EU":
|
||||
return True
|
||||
europe = gaz.by_key.get(("continent", "europe"))
|
||||
place_id = gaz.by_key.get(("country", code))
|
||||
return europe is not None and place_id is not None and europe in gaz.ancestors(place_id)
|
||||
|
||||
|
||||
def country(gaz: places.Gazetteer, place_ids: Iterable[int], host_country: str = "") -> str:
|
||||
"""The one country the role's resolved places lie in, continents aside;
|
||||
Europe alone is `EU`; else, when they
|
||||
lie in several all in Europe, `EU` (what `country_of` wrote for "Dublin,
|
||||
London" and the country gate reads as Europe); else the host's stated
|
||||
country (`of_host`); else ''."""
|
||||
ids = list(place_ids)
|
||||
# A continent beside a country is the wider unit a line adds ("Home
|
||||
# based - EMEA; London" is GB), as `country_of` had it; alone, Europe
|
||||
# is `EU`.
|
||||
found = {gaz.country(p) for p in ids} - {""}
|
||||
if not found and any(gaz.places[p].key == "europe" for p in ids if p in gaz.places):
|
||||
found = {"EU"}
|
||||
if len(found) == 1:
|
||||
return found.pop()
|
||||
if len(found) > 1 and all(_in_europe(gaz, code) for code in found):
|
||||
return "EU"
|
||||
return of_host(gaz, host_country) or ""
|
||||
Reference in new issue
Block a user