List unlinked places and unmapped words under Sources, fix them in code with the unmapped skill
Settings > Sources > Unmapped shows the place texts no place resolves, with their roles' countries and companies, and the host words no table maps, and copies both as text. Prep fingerprints places.seed(), so a town or spelling added to the code is seeded and every open role is mapped again at the next prep. app prep unlinked lists the places on the command line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ae978594b4
commit
06ff9f549b
13 files changed
+313
-43
No files matched your search
@@ -10,6 +10,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sqlite3
|
||||
from collections import Counter
|
||||
from collections.abc import Callable, Iterable, Iterator, MutableMapping, Sequence
|
||||
from contextlib import closing, contextmanager
|
||||
from datetime import UTC, datetime, timedelta
|
||||
@@ -601,6 +602,35 @@ class Store:
|
||||
gazetteer.relink(conn, gaz, folded)
|
||||
return place_id
|
||||
|
||||
def unlinked_places(self, limit: int | None = None) -> list[dict[str, Any]]:
|
||||
"""`unresolved_places` with what places each text: `countries`, the
|
||||
`[code, roles]` prep gave its roles ('' for none), and `companies`,
|
||||
the three that write it most, both most roles first. What the Sources
|
||||
page's Unmapped section and `app prep unlinked` list."""
|
||||
found = self.unresolved_places(limit=limit)
|
||||
countries: dict[str, Counter[str]] = {fold: Counter() for fold, _, _ in found}
|
||||
companies: dict[str, Counter[str]] = {fold: Counter() for fold, _, _ in found}
|
||||
for r in self._rows(
|
||||
"""SELECT rp.fold, r.country, r.company, COUNT(DISTINCT r.uid) AS n
|
||||
FROM role_places rp JOIN roles r ON r.uid = rp.uid
|
||||
WHERE rp.place_id IS NULL AND r.closed_at IS NULL AND r.dup_of IS NULL
|
||||
GROUP BY rp.fold, r.country, r.company"""):
|
||||
if (fold := str(r["fold"])) in countries:
|
||||
countries[fold][str(r["country"])] += int(r["n"])
|
||||
companies[fold][str(r["company"])] += int(r["n"])
|
||||
return [{"fold": fold, "text": text, "roles": n,
|
||||
"countries": [list(c) for c in countries[fold].most_common()],
|
||||
"companies": [c for c, _ in companies[fold].most_common(3) if c]}
|
||||
for fold, text, n in found]
|
||||
|
||||
def seed_places(self) -> int:
|
||||
"""Add what `places.seed` describes and the database lacks, a place
|
||||
or a spelling written into the code since the file was made. Prep
|
||||
calls it when the code changed and resolves the open roles again.
|
||||
Returns how many places were added."""
|
||||
with self.transaction() as conn:
|
||||
return gazetteer.seed(conn)
|
||||
|
||||
def relink_places(self) -> int:
|
||||
"""Resolve every role's own places again, after the gazetteer was
|
||||
seeded anew. Returns how many roles now resolve differently."""
|
||||
|
||||
Reference in new issue
Block a user