From 56fad284a63b91519b7e346243e6118650e71fc9 Mon Sep 17 00:00:00 2001 From: Wolf Date: Wed, 30 Sep 2026 11:23:34 +0200 Subject: [PATCH] Prep reads remote from a Danish or Swedish place line, and from a search role's title The search providers stop mapping remote_word themselves (R2), so prep reads the same words: in any role's place line after remote_of, and in the title of a role from a search. Co-Authored-By: Claude Opus 5.5 --- app/prep/stage.py | 5 +++-- app/prep/words.py | 27 ++++++++++++++++++++++++--- app/storage/store.py | 2 +- tests/test_prep.py | 20 ++++++++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/app/prep/stage.py b/app/prep/stage.py index 02aa499..5c9dc8c 100644 --- a/app/prep/stage.py +++ b/app/prep/stage.py @@ -85,8 +85,9 @@ def map_role(row: Mapping[str, Any], gaz: places.Gazetteer, folds: Mapping[str, "seniority_title": titled, "employment": words.employment(host, row["employment_host"], tables), "remote": words.remote(host, row["remote_host"] or None, (), "", tables), - "remote_places": words.remote(host, None, _places(row["raw_places"]), row["place"], - tables), + "remote_places": words.remote( + host, None, _places(row["raw_places"]), row["place"], tables, + title=row["title"] if row["source"] == "search" else ""), "country": country(gaz, place_ids, row["country_host"]), } diff --git a/app/prep/words.py b/app/prep/words.py index 4d71dc8..da1ee7b 100644 --- a/app/prep/words.py +++ b/app/prep/words.py @@ -44,6 +44,23 @@ def _match(rules: Mapping[str, Any], key: str) -> str | None: return None +#: Remote and hybrid in a line of Danish, Swedish or English that `remote_of` +#: does not read: "Nordhavn og mulighed for hjemmearbejde", "Arbete på distans". +#: Remote first, since "fuldt hjemmearbejde" is remote. +_REMOTE_LINE = re.compile( + r"\bremote\b|fjernarbejde|fuldt hjemmearbejde|distansarbete|på distans", re.IGNORECASE) +_HYBRID_LINE = re.compile(r"\bhybrid|hjemmearbejde", re.IGNORECASE) + + +def _line_word(text: str) -> str: + """`remote_of`'s reading of a line, else its Danish and Swedish words.""" + if found := remote_of(text): + return found + if _REMOTE_LINE.search(text): + return "remote" + return "hybrid" if _HYBRID_LINE.search(text) else "" + + def _squash(word: str) -> str: return "".join(c for c in word.lower() if c not in " -_") @@ -86,7 +103,7 @@ def _place_text(place: Any) -> str: def remote(host: str, value: Any, places: Iterable[Any] = (), line: str = "", - tables: Tables = TABLES) -> str: + tables: Tables = TABLES, title: str = "") -> str: """How the role is worked, one of `REMOTE` or ''. `value` is the host's own (a bool, or its word; `host_word`'s 'true' and @@ -95,7 +112,9 @@ def remote(host: str, value: Any, places: Iterable[Any] = (), line: str = "", every role that is not remote, hybrid ones included. A word goes through the host's table, else the shared map. When the value says nothing, the place line or the place texts are read for a word - (`remote_of`: "Hybrid, Berlin"), and last a place the reader marked + (`remote_of`: "Hybrid, Berlin", and the Danish and Swedish words), then + `title` when given, which the stage gives for a search provider's role + only ("Backend Developer - Remote"), and last a place the reader marked remote is remote.""" if value is True or value == "true": return "remote" @@ -103,7 +122,9 @@ def remote(host: str, value: Any, places: Iterable[Any] = (), line: str = "", if said and (found := lookup("remote", host, str(value), tables)): return found places = list(places) - if found := remote_of(line or "; ".join(map(_place_text, places))): + if found := _line_word(line or "; ".join(map(_place_text, places))): + return found + if title and (found := _line_word(title)): return found if any(isinstance(p, Mapping) and p.get("remote") is True for p in places): return "remote" diff --git a/app/storage/store.py b/app/storage/store.py index b5b9932..2959cb0 100644 --- a/app/storage/store.py +++ b/app/storage/store.py @@ -1273,7 +1273,7 @@ class Store: due (`prep_due` above 0), every open role, or every role.""" where = {"due": "prep_due > 0", "open": "closed_at IS NULL", "all": "1"}[scope] return self._rows( - f"""SELECT uid, prep_due, {_HOST} AS host, title, company, company_key, place, + f"""SELECT uid, prep_due, source, {_HOST} AS host, title, company, company_key, place, seniority_host, employment_host, remote_host, country_host, seniority_model, seniority_stated, seniority_title, seniority, employment, remote, country, diff --git a/tests/test_prep.py b/tests/test_prep.py index cfa6439..734683b 100644 --- a/tests/test_prep.py +++ b/tests/test_prep.py @@ -93,6 +93,26 @@ def test_remote_from_a_bool_a_word_the_place_line_then_a_place_marked_remote() - "", TABLES) == "remote" +def test_a_line_in_danish_or_swedish_and_a_search_title_are_read() -> None: + assert words.remote("jobindex", None, (), "Nordhavn og mulighed for hjemmearbejde") \ + == "hybrid" + assert words.remote("jobindex", None, (), "Aarhus, fuldt hjemmearbejde") == "remote" + assert words.remote("platsbanken", None, (), "Malmö, arbete på distans") == "remote" + assert words.remote("adzuna", None, (), "Berlin", title="Backend Developer - Remote") \ + == "remote" + assert words.remote("adzuna", None, (), "Berlin", title="Backend Developer") == "" + + +def test_a_search_roles_title_counts_and_a_boards_does_not(store: Store) -> None: + store.upsert_role(item("1", title="Engineer (remote)", place="Berlin")) + store.upsert_role(item("2", title="Engineer (remote)", place="Berlin", host="jobindex", + provider="jobindex")) + with store.transaction() as conn: + conn.execute("UPDATE roles SET source = 'search' WHERE source_id = 'jobindex:2'") + prep.run(store, tables=TABLES) + assert (row(store, "1")["remote"], row(store, "2", "jobindex")["remote"]) == ("", "remote") + + # ----------------------------------------------------------------- country @pytest.fixture