Group copies only when they all match, compare towns through places.towns, and record the rule in the plan
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fdb6264c98
commit
b09a2f6b33
4 files changed
+90
-134
No files matched your search
+14
-1
@@ -35,7 +35,7 @@ from functools import lru_cache
|
||||
from app.models import _CITIES, _COUNTRY_NAMES, _REGIONS, _place_fold
|
||||
|
||||
__all__ = ["REGIONS", "SQL_FUNCTION", "Region", "Suggestion", "Token", "fold", "known",
|
||||
"label", "match_sql", "matches", "parse", "register", "suggest"]
|
||||
"label", "match_sql", "matches", "parse", "register", "suggest", "towns"]
|
||||
|
||||
|
||||
def fold(text: str) -> str:
|
||||
@@ -578,6 +578,19 @@ def _towns_in(folded: str) -> list[str]:
|
||||
return list(dict.fromkeys(found))
|
||||
|
||||
|
||||
def towns(place: str) -> frozenset[str]:
|
||||
"""The towns a line names, each as its group's key, so `København K` and
|
||||
`Copenhagen, Denmark` are both `{"copenhagen"}`: the first comma part of each
|
||||
place, and every known town the line holds as whole words, so a list such as
|
||||
`Aalborg, Copenhagen, Kolding` gives all three. A state or province after
|
||||
the town is not a town, so `Mountain View, California` and `San Francisco,
|
||||
California` share none. Empty for a line that names only a country, a region
|
||||
or how the role is worked."""
|
||||
found = {_group(fold(town)) for town in _towns(place)}
|
||||
found.update(_towns_in(fold(place or "")))
|
||||
return frozenset(found)
|
||||
|
||||
|
||||
def _region_counts(keys: Iterable[str], places: list[tuple[str, int]]) -> dict[str, int]:
|
||||
"""Open roles per region, over folded lines. A line is cut into every run of
|
||||
words once, and each region asks whether it holds one of its phrases."""
|
||||
|
||||
Reference in new issue
Block a user