Spaces:
Sleeping
Sleeping
Fast deploy (index 51f60c37cb32)
Browse files- Dockerfile +1 -1
- backend/app.py +41 -4
- backend/atlas.py +244 -24
- backend/define.py +26 -7
- backend/game.py +240 -0
- backend/models.py +3 -0
- backend/wiktionary.py +22 -71
- frontend/dist/assets/index-CSxQdCV8.js +0 -0
- frontend/dist/assets/index-Dr1iPrLq.css +1 -0
- frontend/dist/index.html +2 -2
Dockerfile
CHANGED
|
@@ -27,7 +27,7 @@ COPY frontend/dist ./frontend/dist
|
|
| 27 |
|
| 28 |
# Pinned prebuilt index artifact (update when republishing the dataset).
|
| 29 |
ARG INDEX_URL=https://huggingface.co/datasets/Mongoosetross/reverse-etymology-index/resolve/main/index.tar.zst
|
| 30 |
-
ARG INDEX_SHA256=
|
| 31 |
RUN mkdir -p data/index \
|
| 32 |
&& curl -fsSL "$INDEX_URL" -o /tmp/index.tar.zst \
|
| 33 |
&& if [ -n "$INDEX_SHA256" ]; then echo "$INDEX_SHA256 /tmp/index.tar.zst" | sha256sum -c -; fi \
|
|
|
|
| 27 |
|
| 28 |
# Pinned prebuilt index artifact (update when republishing the dataset).
|
| 29 |
ARG INDEX_URL=https://huggingface.co/datasets/Mongoosetross/reverse-etymology-index/resolve/main/index.tar.zst
|
| 30 |
+
ARG INDEX_SHA256=51f60c37cb3219268f7852363860f7d17650cf2079888de75573f28412bb6d71
|
| 31 |
RUN mkdir -p data/index \
|
| 32 |
&& curl -fsSL "$INDEX_URL" -o /tmp/index.tar.zst \
|
| 33 |
&& if [ -n "$INDEX_SHA256" ]; then echo "$INDEX_SHA256 /tmp/index.tar.zst" | sha256sum -c -; fi \
|
backend/app.py
CHANGED
|
@@ -12,6 +12,7 @@ from fastapi.staticfiles import StaticFiles
|
|
| 12 |
|
| 13 |
from backend.atlas import Atlas
|
| 14 |
from backend.define import fetch_definitions
|
|
|
|
| 15 |
from backend.models import TreeQuery
|
| 16 |
|
| 17 |
ROOT = Path(__file__).resolve().parents[1]
|
|
@@ -77,17 +78,17 @@ def examples() -> dict:
|
|
| 77 |
|
| 78 |
|
| 79 |
@app.get("/api/node")
|
| 80 |
-
def node(term: str, lang: str) -> dict:
|
| 81 |
-
data = atlas.inspector(term, lang)
|
| 82 |
if data is None:
|
| 83 |
raise HTTPException(404, "Unknown word")
|
| 84 |
return data
|
| 85 |
|
| 86 |
|
| 87 |
@app.get("/api/define")
|
| 88 |
-
def define(term: str, lang: str = "", iso: str | None = None) -> dict:
|
| 89 |
"""Short glosses from the local Kaikki dump (baked into atlas.sqlite)."""
|
| 90 |
-
return fetch_definitions(term=term, lang=lang, iso_639_3=iso, atlas=atlas)
|
| 91 |
|
| 92 |
|
| 93 |
@app.post("/api/tree")
|
|
@@ -95,6 +96,42 @@ def tree(query: TreeQuery) -> dict:
|
|
| 95 |
return atlas.walk(query)
|
| 96 |
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
@app.post("/api/export")
|
| 99 |
def export_tree(query: TreeQuery, format: str = Query(default="csv")) -> Response:
|
| 100 |
result = atlas.walk(query)
|
|
|
|
| 12 |
|
| 13 |
from backend.atlas import Atlas
|
| 14 |
from backend.define import fetch_definitions
|
| 15 |
+
from backend.game import build_round, next_round, score_guess
|
| 16 |
from backend.models import TreeQuery
|
| 17 |
|
| 18 |
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
| 78 |
|
| 79 |
|
| 80 |
@app.get("/api/node")
|
| 81 |
+
def node(term: str, lang: str, ety: str | None = None) -> dict:
|
| 82 |
+
data = atlas.inspector(term, lang, ety)
|
| 83 |
if data is None:
|
| 84 |
raise HTTPException(404, "Unknown word")
|
| 85 |
return data
|
| 86 |
|
| 87 |
|
| 88 |
@app.get("/api/define")
|
| 89 |
+
def define(term: str, lang: str = "", ety: str | None = None, iso: str | None = None) -> dict:
|
| 90 |
"""Short glosses from the local Kaikki dump (baked into atlas.sqlite)."""
|
| 91 |
+
return fetch_definitions(term=term, lang=lang, ety=ety, iso_639_3=iso, atlas=atlas)
|
| 92 |
|
| 93 |
|
| 94 |
@app.post("/api/tree")
|
|
|
|
| 96 |
return atlas.walk(query)
|
| 97 |
|
| 98 |
|
| 99 |
+
@app.get("/api/relate")
|
| 100 |
+
def relate(
|
| 101 |
+
a: str = Query(..., description="First term"),
|
| 102 |
+
a_lang: str = Query(default="english"),
|
| 103 |
+
b: str = Query(..., description="Second term"),
|
| 104 |
+
b_lang: str = Query(default="spanish"),
|
| 105 |
+
max_depth: int = Query(default=12, ge=2, le=16),
|
| 106 |
+
) -> dict:
|
| 107 |
+
return atlas.relate(a, a_lang, b, b_lang, max_depth=max_depth)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
@app.get("/api/game/round")
|
| 111 |
+
def game_round(
|
| 112 |
+
en: str | None = None,
|
| 113 |
+
es: str | None = None,
|
| 114 |
+
avoid: str = Query(default="", description="Comma-separated round ids to skip"),
|
| 115 |
+
) -> dict:
|
| 116 |
+
if en and es:
|
| 117 |
+
rnd = build_round(atlas, en.strip(), es.strip(), source="custom")
|
| 118 |
+
else:
|
| 119 |
+
skip = {x.strip() for x in avoid.split(",") if x.strip()}
|
| 120 |
+
rnd = next_round(atlas, avoid=skip)
|
| 121 |
+
if not rnd.get("ok"):
|
| 122 |
+
raise HTTPException(404, rnd.get("error") or "No round available")
|
| 123 |
+
return rnd
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
@app.post("/api/game/score")
|
| 127 |
+
def game_score(body: dict) -> dict:
|
| 128 |
+
"""Score a guess. Body: {round, bridge?, chain?} — pass the round payload from /api/game/round."""
|
| 129 |
+
rnd = body.get("round") or {}
|
| 130 |
+
if not rnd.get("answer"):
|
| 131 |
+
raise HTTPException(400, "round.answer required")
|
| 132 |
+
return score_guess(rnd, body.get("bridge"), body.get("chain") or [])
|
| 133 |
+
|
| 134 |
+
|
| 135 |
@app.post("/api/export")
|
| 136 |
def export_tree(query: TreeQuery, format: str = Query(default="csv")) -> Response:
|
| 137 |
result = atlas.walk(query)
|
backend/atlas.py
CHANGED
|
@@ -46,7 +46,7 @@ class Atlas:
|
|
| 46 |
self.forward: CSR | None = None
|
| 47 |
self.n = 0
|
| 48 |
self.ctx: FilterContext | None = None
|
| 49 |
-
self._id_cache: dict[tuple[str, str], int | None] = {}
|
| 50 |
self.child_count: np.ndarray | None = None
|
| 51 |
self.lang_meta: dict[str, dict] = {}
|
| 52 |
self._arrays: dict[str, np.ndarray] = {}
|
|
@@ -171,27 +171,50 @@ class Atlas:
|
|
| 171 |
out[int(row["id"])] = row["term"]
|
| 172 |
return out
|
| 173 |
|
| 174 |
-
def node_id(self, term: str, lang: str) -> int | None:
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
if key in self._id_cache:
|
| 177 |
return self._id_cache[key]
|
| 178 |
assert self.conn is not None
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
alias = self.conn.execute(
|
| 186 |
"SELECT canon_term FROM term_aliases WHERE alias_term = ? AND lang = ?",
|
| 187 |
(term, lang),
|
| 188 |
).fetchone()
|
| 189 |
if alias is not None:
|
| 190 |
-
|
| 191 |
-
"SELECT id FROM nodes WHERE term = ? AND lang = ?",
|
| 192 |
-
(alias["canon_term"], lang),
|
| 193 |
-
).fetchone()
|
| 194 |
-
nid = int(row["id"]) if row else None
|
| 195 |
self._id_cache[key] = nid
|
| 196 |
return nid
|
| 197 |
|
|
@@ -231,7 +254,7 @@ class Atlas:
|
|
| 231 |
if self.has_aliases:
|
| 232 |
for r in self.conn.execute(
|
| 233 |
"""
|
| 234 |
-
SELECT a.alias_term, n.id, n.term, n.lang, n.child_count
|
| 235 |
FROM term_aliases a
|
| 236 |
JOIN nodes n ON n.term = a.canon_term AND n.lang = a.lang
|
| 237 |
WHERE a.alias_norm = ?
|
|
@@ -245,7 +268,7 @@ class Atlas:
|
|
| 245 |
if len(norm) == 1:
|
| 246 |
for r in self.conn.execute(
|
| 247 |
"""
|
| 248 |
-
SELECT id, term, lang, child_count
|
| 249 |
FROM nodes
|
| 250 |
WHERE term_norm LIKE ? || '%'
|
| 251 |
ORDER BY child_count DESC, term_norm
|
|
@@ -257,7 +280,7 @@ class Atlas:
|
|
| 257 |
else:
|
| 258 |
for r in self.conn.execute(
|
| 259 |
"""
|
| 260 |
-
SELECT id, term, lang, child_count
|
| 261 |
FROM nodes
|
| 262 |
WHERE term_norm = ? OR term_norm LIKE ? || '%'
|
| 263 |
ORDER BY (term_norm = ?) DESC, child_count DESC, term_norm
|
|
@@ -270,7 +293,7 @@ class Atlas:
|
|
| 270 |
if self.has_aliases and len(rows) < limit:
|
| 271 |
for r in self.conn.execute(
|
| 272 |
"""
|
| 273 |
-
SELECT a.alias_term, n.id, n.term, n.lang, n.child_count
|
| 274 |
FROM term_aliases a
|
| 275 |
JOIN nodes n ON n.term = a.canon_term AND n.lang = a.lang
|
| 276 |
WHERE a.alias_norm LIKE ? || '%'
|
|
@@ -287,7 +310,7 @@ class Atlas:
|
|
| 287 |
fts_q = '"' + norm.replace('"', "") + '"*'
|
| 288 |
for r in self.conn.execute(
|
| 289 |
"""
|
| 290 |
-
SELECT n.id, n.term, n.lang, n.child_count
|
| 291 |
FROM nodes_fts
|
| 292 |
JOIN nodes n ON n.id = nodes_fts.rowid
|
| 293 |
WHERE nodes_fts MATCH ?
|
|
@@ -308,6 +331,7 @@ class Atlas:
|
|
| 308 |
"id": nid,
|
| 309 |
"term": r["term"],
|
| 310 |
"lang": r["lang"],
|
|
|
|
| 311 |
"lang_display": info["lang_display"],
|
| 312 |
"family_name": info["family_name"],
|
| 313 |
"child_count": int(r["child_count"]),
|
|
@@ -328,7 +352,7 @@ class Atlas:
|
|
| 328 |
part = ids[i : i + chunk]
|
| 329 |
qmarks = ",".join("?" * len(part))
|
| 330 |
for row in self.conn.execute(
|
| 331 |
-
f"SELECT id, term, lang, child_count FROM nodes WHERE id IN ({qmarks})",
|
| 332 |
part,
|
| 333 |
):
|
| 334 |
nid = int(row["id"])
|
|
@@ -337,13 +361,15 @@ class Atlas:
|
|
| 337 |
"id": nid,
|
| 338 |
"term": row["term"],
|
| 339 |
"lang": row["lang"],
|
|
|
|
| 340 |
"child_count": int(row["child_count"]),
|
|
|
|
| 341 |
**info,
|
| 342 |
}
|
| 343 |
return out
|
| 344 |
|
| 345 |
-
def inspector(self, term: str, lang: str) -> dict | None:
|
| 346 |
-
nid = self.node_id(term, lang)
|
| 347 |
if nid is None:
|
| 348 |
return None
|
| 349 |
nodes = self.hydrate([nid])
|
|
@@ -368,10 +394,12 @@ class Atlas:
|
|
| 368 |
"id": tid,
|
| 369 |
"term": info.get("term", ""),
|
| 370 |
"lang": info.get("lang", ""),
|
|
|
|
| 371 |
"lang_display": info.get("lang_display"),
|
| 372 |
"family_name": info.get("family_name"),
|
| 373 |
"relation": RELATIONS[int(fwd.rel[e])],
|
| 374 |
"confidence": int(fwd.conf[e]) / 100.0,
|
|
|
|
| 375 |
}
|
| 376 |
)
|
| 377 |
|
|
@@ -403,6 +431,7 @@ class Atlas:
|
|
| 403 |
"id": int(pid),
|
| 404 |
"term": info.get("term", ""),
|
| 405 |
"lang": info.get("lang", ""),
|
|
|
|
| 406 |
"lang_display": info.get("lang_display"),
|
| 407 |
"family_name": info.get("family_name"),
|
| 408 |
"part_index": pi,
|
|
@@ -469,7 +498,11 @@ class Atlas:
|
|
| 469 |
"cognate_sets": cognates,
|
| 470 |
"wals": wals[:80],
|
| 471 |
"phonemes": phoneme_list,
|
| 472 |
-
"wiktionary": wiktionary_url(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
}
|
| 474 |
if self.ctx.freq_zipf is not None:
|
| 475 |
z = float(self.ctx.freq_zipf[nid])
|
|
@@ -481,7 +514,7 @@ class Atlas:
|
|
| 481 |
def walk(self, query: TreeQuery) -> dict:
|
| 482 |
t0 = time.perf_counter()
|
| 483 |
assert self.reverse is not None and self.ctx is not None
|
| 484 |
-
nid = self.node_id(query.term, query.lang)
|
| 485 |
if nid is None:
|
| 486 |
return {
|
| 487 |
"root": None,
|
|
@@ -491,6 +524,189 @@ class Atlas:
|
|
| 491 |
}
|
| 492 |
return walk_tree(self, query, nid, t0)
|
| 493 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 494 |
|
| 495 |
def _allowed_rel_mask(edges: EdgeFilter) -> np.ndarray:
|
| 496 |
names = edges.relations or DEFAULT_RELATIONS
|
|
@@ -797,6 +1013,7 @@ def walk_tree(atlas: Atlas, query: TreeQuery, root: int, t0: float) -> dict:
|
|
| 797 |
"branch": "root" if nid == root else "down",
|
| 798 |
"term": terms.get(nid, ""),
|
| 799 |
"lang": ctx.lang_key(nid),
|
|
|
|
| 800 |
"depth": int(depth_of[nid]),
|
| 801 |
"relation": relation_of(nid) if nid != root else None,
|
| 802 |
"confidence": conf_of(nid) if nid != root else None,
|
|
@@ -923,6 +1140,7 @@ def walk_tree(atlas: Atlas, query: TreeQuery, root: int, t0: float) -> dict:
|
|
| 923 |
"branch": "up",
|
| 924 |
"term": terms.get(nid, ""),
|
| 925 |
"lang": ctx.lang_key(nid),
|
|
|
|
| 926 |
"depth": int(anc_depth[nid]),
|
| 927 |
"relation": RELATIONS[int(rc)] if rc >= 0 else None,
|
| 928 |
"confidence": int(anc_conf_code.get(nid, 100)) / 100.0,
|
|
@@ -1011,6 +1229,7 @@ def walk_tree(atlas: Atlas, query: TreeQuery, root: int, t0: float) -> dict:
|
|
| 1011 |
raw_id = node["id"]
|
| 1012 |
nid = int(str(raw_id)[2:]) if isinstance(raw_id, str) and str(raw_id).startswith("a:") else int(raw_id)
|
| 1013 |
info = extra.get(nid, {})
|
|
|
|
| 1014 |
node["lang_display"] = info.get("lang_display")
|
| 1015 |
node["family_name"] = info.get("family_name")
|
| 1016 |
node["macroarea"] = info.get("macroarea")
|
|
@@ -1043,6 +1262,7 @@ def walk_tree(atlas: Atlas, query: TreeQuery, root: int, t0: float) -> dict:
|
|
| 1043 |
"id": root,
|
| 1044 |
"term": terms.get(root) or root_info.get("term") or query.term,
|
| 1045 |
"lang": ctx.lang_key(root),
|
|
|
|
| 1046 |
**{k: root_info.get(k) for k in ("lang_display", "family_name", "macroarea", "latitude", "longitude")},
|
| 1047 |
},
|
| 1048 |
"nodes": payload_nodes,
|
|
|
|
| 46 |
self.forward: CSR | None = None
|
| 47 |
self.n = 0
|
| 48 |
self.ctx: FilterContext | None = None
|
| 49 |
+
self._id_cache: dict[tuple[str, str, str | None], int | None] = {}
|
| 50 |
self.child_count: np.ndarray | None = None
|
| 51 |
self.lang_meta: dict[str, dict] = {}
|
| 52 |
self._arrays: dict[str, np.ndarray] = {}
|
|
|
|
| 171 |
out[int(row["id"])] = row["term"]
|
| 172 |
return out
|
| 173 |
|
| 174 |
+
def node_id(self, term: str, lang: str, ety: str | None = None) -> int | None:
|
| 175 |
+
"""Resolve a graph node.
|
| 176 |
+
|
| 177 |
+
When ``ety`` is provided (including empty string), require an exact match.
|
| 178 |
+
When omitted, prefer the sole ``(term, lang)`` node, then the ``""`` bucket,
|
| 179 |
+
then the highest ``child_count`` among matches.
|
| 180 |
+
"""
|
| 181 |
+
key = (term, lang, ety)
|
| 182 |
if key in self._id_cache:
|
| 183 |
return self._id_cache[key]
|
| 184 |
assert self.conn is not None
|
| 185 |
+
|
| 186 |
+
def lookup(canon: str, want_ety: str | None) -> int | None:
|
| 187 |
+
if want_ety is not None:
|
| 188 |
+
row = self.conn.execute(
|
| 189 |
+
"SELECT id FROM nodes WHERE term = ? AND lang = ? AND ety = ?",
|
| 190 |
+
(canon, lang, want_ety),
|
| 191 |
+
).fetchone()
|
| 192 |
+
return int(row["id"]) if row else None
|
| 193 |
+
rows = self.conn.execute(
|
| 194 |
+
"""
|
| 195 |
+
SELECT id, ety, child_count FROM nodes
|
| 196 |
+
WHERE term = ? AND lang = ?
|
| 197 |
+
ORDER BY (ety = '') DESC, child_count DESC
|
| 198 |
+
""",
|
| 199 |
+
(canon, lang),
|
| 200 |
+
).fetchall()
|
| 201 |
+
if not rows:
|
| 202 |
+
return None
|
| 203 |
+
if len(rows) == 1:
|
| 204 |
+
return int(rows[0]["id"])
|
| 205 |
+
for r in rows:
|
| 206 |
+
if r["ety"] == "":
|
| 207 |
+
return int(r["id"])
|
| 208 |
+
return int(rows[0]["id"])
|
| 209 |
+
|
| 210 |
+
nid = lookup(term, ety)
|
| 211 |
+
if nid is None and self.has_aliases:
|
| 212 |
alias = self.conn.execute(
|
| 213 |
"SELECT canon_term FROM term_aliases WHERE alias_term = ? AND lang = ?",
|
| 214 |
(term, lang),
|
| 215 |
).fetchone()
|
| 216 |
if alias is not None:
|
| 217 |
+
nid = lookup(alias["canon_term"], ety)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
self._id_cache[key] = nid
|
| 219 |
return nid
|
| 220 |
|
|
|
|
| 254 |
if self.has_aliases:
|
| 255 |
for r in self.conn.execute(
|
| 256 |
"""
|
| 257 |
+
SELECT a.alias_term, n.id, n.term, n.lang, n.ety, n.child_count
|
| 258 |
FROM term_aliases a
|
| 259 |
JOIN nodes n ON n.term = a.canon_term AND n.lang = a.lang
|
| 260 |
WHERE a.alias_norm = ?
|
|
|
|
| 268 |
if len(norm) == 1:
|
| 269 |
for r in self.conn.execute(
|
| 270 |
"""
|
| 271 |
+
SELECT id, term, lang, ety, child_count
|
| 272 |
FROM nodes
|
| 273 |
WHERE term_norm LIKE ? || '%'
|
| 274 |
ORDER BY child_count DESC, term_norm
|
|
|
|
| 280 |
else:
|
| 281 |
for r in self.conn.execute(
|
| 282 |
"""
|
| 283 |
+
SELECT id, term, lang, ety, child_count
|
| 284 |
FROM nodes
|
| 285 |
WHERE term_norm = ? OR term_norm LIKE ? || '%'
|
| 286 |
ORDER BY (term_norm = ?) DESC, child_count DESC, term_norm
|
|
|
|
| 293 |
if self.has_aliases and len(rows) < limit:
|
| 294 |
for r in self.conn.execute(
|
| 295 |
"""
|
| 296 |
+
SELECT a.alias_term, n.id, n.term, n.lang, n.ety, n.child_count
|
| 297 |
FROM term_aliases a
|
| 298 |
JOIN nodes n ON n.term = a.canon_term AND n.lang = a.lang
|
| 299 |
WHERE a.alias_norm LIKE ? || '%'
|
|
|
|
| 310 |
fts_q = '"' + norm.replace('"', "") + '"*'
|
| 311 |
for r in self.conn.execute(
|
| 312 |
"""
|
| 313 |
+
SELECT n.id, n.term, n.lang, n.ety, n.child_count
|
| 314 |
FROM nodes_fts
|
| 315 |
JOIN nodes n ON n.id = nodes_fts.rowid
|
| 316 |
WHERE nodes_fts MATCH ?
|
|
|
|
| 331 |
"id": nid,
|
| 332 |
"term": r["term"],
|
| 333 |
"lang": r["lang"],
|
| 334 |
+
"ety": r["ety"] if "ety" in r.keys() else "",
|
| 335 |
"lang_display": info["lang_display"],
|
| 336 |
"family_name": info["family_name"],
|
| 337 |
"child_count": int(r["child_count"]),
|
|
|
|
| 352 |
part = ids[i : i + chunk]
|
| 353 |
qmarks = ",".join("?" * len(part))
|
| 354 |
for row in self.conn.execute(
|
| 355 |
+
f"SELECT id, term, lang, ety, child_count, wiki_title FROM nodes WHERE id IN ({qmarks})",
|
| 356 |
part,
|
| 357 |
):
|
| 358 |
nid = int(row["id"])
|
|
|
|
| 361 |
"id": nid,
|
| 362 |
"term": row["term"],
|
| 363 |
"lang": row["lang"],
|
| 364 |
+
"ety": row["ety"] if "ety" in row.keys() else "",
|
| 365 |
"child_count": int(row["child_count"]),
|
| 366 |
+
"wiki_title": row["wiki_title"],
|
| 367 |
**info,
|
| 368 |
}
|
| 369 |
return out
|
| 370 |
|
| 371 |
+
def inspector(self, term: str, lang: str, ety: str | None = None) -> dict | None:
|
| 372 |
+
nid = self.node_id(term, lang, ety)
|
| 373 |
if nid is None:
|
| 374 |
return None
|
| 375 |
nodes = self.hydrate([nid])
|
|
|
|
| 394 |
"id": tid,
|
| 395 |
"term": info.get("term", ""),
|
| 396 |
"lang": info.get("lang", ""),
|
| 397 |
+
"ety": info.get("ety", ""),
|
| 398 |
"lang_display": info.get("lang_display"),
|
| 399 |
"family_name": info.get("family_name"),
|
| 400 |
"relation": RELATIONS[int(fwd.rel[e])],
|
| 401 |
"confidence": int(fwd.conf[e]) / 100.0,
|
| 402 |
+
"child_count": info.get("child_count", 0),
|
| 403 |
}
|
| 404 |
)
|
| 405 |
|
|
|
|
| 431 |
"id": int(pid),
|
| 432 |
"term": info.get("term", ""),
|
| 433 |
"lang": info.get("lang", ""),
|
| 434 |
+
"ety": info.get("ety", ""),
|
| 435 |
"lang_display": info.get("lang_display"),
|
| 436 |
"family_name": info.get("family_name"),
|
| 437 |
"part_index": pi,
|
|
|
|
| 498 |
"cognate_sets": cognates,
|
| 499 |
"wals": wals[:80],
|
| 500 |
"phonemes": phoneme_list,
|
| 501 |
+
"wiktionary": wiktionary_url(
|
| 502 |
+
node.get("wiki_title"),
|
| 503 |
+
lang=lang,
|
| 504 |
+
lang_display=node.get("lang_display"),
|
| 505 |
+
),
|
| 506 |
}
|
| 507 |
if self.ctx.freq_zipf is not None:
|
| 508 |
z = float(self.ctx.freq_zipf[nid])
|
|
|
|
| 514 |
def walk(self, query: TreeQuery) -> dict:
|
| 515 |
t0 = time.perf_counter()
|
| 516 |
assert self.reverse is not None and self.ctx is not None
|
| 517 |
+
nid = self.node_id(query.term, query.lang, getattr(query, "ety", None))
|
| 518 |
if nid is None:
|
| 519 |
return {
|
| 520 |
"root": None,
|
|
|
|
| 524 |
}
|
| 525 |
return walk_tree(self, query, nid, t0)
|
| 526 |
|
| 527 |
+
def ancestor_map(self, nid: int, max_depth: int = 12) -> tuple[dict[int, int], dict[int, int], dict[int, int]]:
|
| 528 |
+
"""Forward BFS: parent[node], depth[node], rel_code into parent.
|
| 529 |
+
|
| 530 |
+
``parent[nid] = -1``. Depth is hops from ``nid`` toward etymons.
|
| 531 |
+
"""
|
| 532 |
+
fwd = self.forward
|
| 533 |
+
assert fwd is not None
|
| 534 |
+
parent: dict[int, int] = {nid: -1}
|
| 535 |
+
depth: dict[int, int] = {nid: 0}
|
| 536 |
+
rel_into: dict[int, int] = {nid: -1}
|
| 537 |
+
q: deque[int] = deque([nid])
|
| 538 |
+
while q:
|
| 539 |
+
cur = q.popleft()
|
| 540 |
+
d = depth[cur]
|
| 541 |
+
if d >= max_depth:
|
| 542 |
+
continue
|
| 543 |
+
for e in fwd.edge_range(cur):
|
| 544 |
+
tgt = int(fwd.targets[e])
|
| 545 |
+
if tgt in parent:
|
| 546 |
+
continue
|
| 547 |
+
parent[tgt] = cur
|
| 548 |
+
depth[tgt] = d + 1
|
| 549 |
+
rel_into[tgt] = int(fwd.rel[e])
|
| 550 |
+
q.append(tgt)
|
| 551 |
+
return parent, depth, rel_into
|
| 552 |
+
|
| 553 |
+
def relate(
|
| 554 |
+
self,
|
| 555 |
+
term_a: str,
|
| 556 |
+
lang_a: str,
|
| 557 |
+
term_b: str,
|
| 558 |
+
lang_b: str,
|
| 559 |
+
*,
|
| 560 |
+
ety_a: str | None = None,
|
| 561 |
+
ety_b: str | None = None,
|
| 562 |
+
max_depth: int = 12,
|
| 563 |
+
) -> dict:
|
| 564 |
+
"""Closest shared etymon (DAG meet) and reconstructed paths a→lca and b→lca."""
|
| 565 |
+
id_a = self.node_id(term_a, lang_a, ety_a)
|
| 566 |
+
id_b = self.node_id(term_b, lang_b, ety_b)
|
| 567 |
+
if id_a is None or id_b is None:
|
| 568 |
+
return {
|
| 569 |
+
"ok": False,
|
| 570 |
+
"error": "not_found",
|
| 571 |
+
"a": {"term": term_a, "lang": lang_a, "id": id_a},
|
| 572 |
+
"b": {"term": term_b, "lang": lang_b, "id": id_b},
|
| 573 |
+
}
|
| 574 |
+
if id_a == id_b:
|
| 575 |
+
nodes = self.hydrate([id_a])
|
| 576 |
+
node = nodes[id_a]
|
| 577 |
+
return {
|
| 578 |
+
"ok": True,
|
| 579 |
+
"a": node,
|
| 580 |
+
"b": node,
|
| 581 |
+
"shared_count": 1,
|
| 582 |
+
"lca": {**node, "depth_a": 0, "depth_b": 0, "bridge": _bridge_label(node["lang"])},
|
| 583 |
+
"path_a": [node],
|
| 584 |
+
"path_b": [node],
|
| 585 |
+
"bridge": _bridge_label(node["lang"]),
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
par_a, dep_a, _rel_a = self.ancestor_map(id_a, max_depth)
|
| 589 |
+
par_b, dep_b, _rel_b = self.ancestor_map(id_b, max_depth)
|
| 590 |
+
shared = set(par_a) & set(par_b)
|
| 591 |
+
shared.discard(id_a)
|
| 592 |
+
shared.discard(id_b)
|
| 593 |
+
if not shared:
|
| 594 |
+
# One word may be an ancestor of the other.
|
| 595 |
+
if id_a in par_b:
|
| 596 |
+
shared = {id_a}
|
| 597 |
+
elif id_b in par_a:
|
| 598 |
+
shared = {id_b}
|
| 599 |
+
if not shared:
|
| 600 |
+
ha = self.hydrate([id_a, id_b])
|
| 601 |
+
return {
|
| 602 |
+
"ok": False,
|
| 603 |
+
"error": "no_shared_ancestor",
|
| 604 |
+
"a": ha[id_a],
|
| 605 |
+
"b": ha[id_b],
|
| 606 |
+
"shared_count": 0,
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
hydrated = self.hydrate(list(shared) + [id_a, id_b])
|
| 610 |
+
|
| 611 |
+
def score(cid: int) -> tuple:
|
| 612 |
+
node = hydrated.get(cid) or {}
|
| 613 |
+
term = (node.get("term") or "").strip()
|
| 614 |
+
junk = 1 if (not term or set(term) <= {">", "*", "-"}) else 0
|
| 615 |
+
bridge = _bridge_label(node.get("lang") or "")
|
| 616 |
+
# Prefer concrete historical stages over deep PIE when equally close.
|
| 617 |
+
bridge_rank = {
|
| 618 |
+
"Latin": 0,
|
| 619 |
+
"Old / Middle French": 1,
|
| 620 |
+
"Old English": 2,
|
| 621 |
+
"Proto-Germanic": 3,
|
| 622 |
+
"Proto-Italic": 4,
|
| 623 |
+
"Ancient Greek": 5,
|
| 624 |
+
"Proto-Slavic": 6,
|
| 625 |
+
"Sanskrit": 7,
|
| 626 |
+
"Proto-Indo-European": 8,
|
| 627 |
+
"Other": 9,
|
| 628 |
+
}.get(bridge, 9)
|
| 629 |
+
da, db = dep_a.get(cid, 99), dep_b.get(cid, 99)
|
| 630 |
+
return (junk, da + db, max(da, db), bridge_rank, -int(node.get("child_count") or 0))
|
| 631 |
+
|
| 632 |
+
lca_id = min(shared, key=score)
|
| 633 |
+
lca_node = hydrated[lca_id]
|
| 634 |
+
bridge = _bridge_label(lca_node["lang"])
|
| 635 |
+
|
| 636 |
+
def climb_to_lca(start: int, parents: dict[int, int]) -> list[int]:
|
| 637 |
+
# ancestor_map: parent[etymon] = node closer to the modern word (child → etymon).
|
| 638 |
+
fwd_map: dict[int, list[int]] = {}
|
| 639 |
+
for ety_n, child in parents.items():
|
| 640 |
+
if child != -1:
|
| 641 |
+
fwd_map.setdefault(child, []).append(ety_n)
|
| 642 |
+
came: dict[int, int] = {start: -1}
|
| 643 |
+
dq: deque[int] = deque([start])
|
| 644 |
+
found = False
|
| 645 |
+
while dq:
|
| 646 |
+
cur = dq.popleft()
|
| 647 |
+
if cur == lca_id:
|
| 648 |
+
found = True
|
| 649 |
+
break
|
| 650 |
+
for n in fwd_map.get(cur, ()):
|
| 651 |
+
if n not in came:
|
| 652 |
+
came[n] = cur
|
| 653 |
+
dq.append(n)
|
| 654 |
+
if not found:
|
| 655 |
+
return [start, lca_id] if start != lca_id else [start]
|
| 656 |
+
path = [lca_id]
|
| 657 |
+
cur = lca_id
|
| 658 |
+
while cur != start:
|
| 659 |
+
cur = came[cur]
|
| 660 |
+
path.append(cur)
|
| 661 |
+
path.reverse()
|
| 662 |
+
return path
|
| 663 |
+
|
| 664 |
+
ids_a = climb_to_lca(id_a, par_a)
|
| 665 |
+
ids_b = climb_to_lca(id_b, par_b)
|
| 666 |
+
need = list(dict.fromkeys(ids_a + ids_b))
|
| 667 |
+
nodes = self.hydrate(need)
|
| 668 |
+
|
| 669 |
+
def pack(ids: list[int]) -> list[dict]:
|
| 670 |
+
return [nodes[i] for i in ids if i in nodes]
|
| 671 |
+
|
| 672 |
+
return {
|
| 673 |
+
"ok": True,
|
| 674 |
+
"a": nodes[id_a],
|
| 675 |
+
"b": nodes[id_b],
|
| 676 |
+
"shared_count": len(shared),
|
| 677 |
+
"lca": {
|
| 678 |
+
**lca_node,
|
| 679 |
+
"depth_a": int(dep_a.get(lca_id, 0)),
|
| 680 |
+
"depth_b": int(dep_b.get(lca_id, 0)),
|
| 681 |
+
"bridge": bridge,
|
| 682 |
+
},
|
| 683 |
+
"path_a": pack(ids_a),
|
| 684 |
+
"path_b": pack(ids_b),
|
| 685 |
+
"bridge": bridge,
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
|
| 689 |
+
def _bridge_label(lang: str) -> str:
|
| 690 |
+
lk = (lang or "").casefold()
|
| 691 |
+
buckets = {
|
| 692 |
+
"Latin": {"latin", "classical latin", "medieval latin", "late latin", "vulgate latin"},
|
| 693 |
+
"Old / Middle French": {"old french", "middle french"},
|
| 694 |
+
"Old English": {"old english"},
|
| 695 |
+
"Proto-Germanic": {"proto-germanic"},
|
| 696 |
+
"Proto-Italic": {"proto-italic"},
|
| 697 |
+
"Ancient Greek": {"ancient greek", "classical greek"},
|
| 698 |
+
"Proto-Slavic": {"proto-slavic", "common slavic"},
|
| 699 |
+
"Sanskrit": {"sanskrit", "vedic sanskrit"},
|
| 700 |
+
"Proto-Indo-European": {"proto-indo-european"},
|
| 701 |
+
}
|
| 702 |
+
for label, langs in buckets.items():
|
| 703 |
+
if lk in langs:
|
| 704 |
+
return label
|
| 705 |
+
if not lk:
|
| 706 |
+
return "Other"
|
| 707 |
+
# Title-ish display for other stages (Middle English, etc.)
|
| 708 |
+
return lang.replace("-", " ").title() if lang else "Other"
|
| 709 |
+
|
| 710 |
|
| 711 |
def _allowed_rel_mask(edges: EdgeFilter) -> np.ndarray:
|
| 712 |
names = edges.relations or DEFAULT_RELATIONS
|
|
|
|
| 1013 |
"branch": "root" if nid == root else "down",
|
| 1014 |
"term": terms.get(nid, ""),
|
| 1015 |
"lang": ctx.lang_key(nid),
|
| 1016 |
+
"ety": "",
|
| 1017 |
"depth": int(depth_of[nid]),
|
| 1018 |
"relation": relation_of(nid) if nid != root else None,
|
| 1019 |
"confidence": conf_of(nid) if nid != root else None,
|
|
|
|
| 1140 |
"branch": "up",
|
| 1141 |
"term": terms.get(nid, ""),
|
| 1142 |
"lang": ctx.lang_key(nid),
|
| 1143 |
+
"ety": "",
|
| 1144 |
"depth": int(anc_depth[nid]),
|
| 1145 |
"relation": RELATIONS[int(rc)] if rc >= 0 else None,
|
| 1146 |
"confidence": int(anc_conf_code.get(nid, 100)) / 100.0,
|
|
|
|
| 1229 |
raw_id = node["id"]
|
| 1230 |
nid = int(str(raw_id)[2:]) if isinstance(raw_id, str) and str(raw_id).startswith("a:") else int(raw_id)
|
| 1231 |
info = extra.get(nid, {})
|
| 1232 |
+
node["ety"] = info.get("ety", "")
|
| 1233 |
node["lang_display"] = info.get("lang_display")
|
| 1234 |
node["family_name"] = info.get("family_name")
|
| 1235 |
node["macroarea"] = info.get("macroarea")
|
|
|
|
| 1262 |
"id": root,
|
| 1263 |
"term": terms.get(root) or root_info.get("term") or query.term,
|
| 1264 |
"lang": ctx.lang_key(root),
|
| 1265 |
+
"ety": root_info.get("ety", ""),
|
| 1266 |
**{k: root_info.get(k) for k in ("lang_display", "family_name", "macroarea", "latitude", "longitude")},
|
| 1267 |
},
|
| 1268 |
"nodes": payload_nodes,
|
backend/define.py
CHANGED
|
@@ -64,6 +64,7 @@ def lookup_definitions(
|
|
| 64 |
conn: sqlite3.Connection,
|
| 65 |
term: str,
|
| 66 |
lang: str = "",
|
|
|
|
| 67 |
iso_639_3: str | None = None,
|
| 68 |
lang_meta: dict[str, dict] | None = None,
|
| 69 |
) -> dict:
|
|
@@ -75,20 +76,32 @@ def lookup_definitions(
|
|
| 75 |
|
| 76 |
row = None
|
| 77 |
matched_lang = None
|
|
|
|
| 78 |
for cand in candidates:
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
if row is not None:
|
| 84 |
matched_lang = row["lang"] if isinstance(row, sqlite3.Row) else row[0]
|
|
|
|
| 85 |
break
|
| 86 |
|
| 87 |
fallback = False
|
| 88 |
if row is None:
|
| 89 |
-
# Any language for this spelling (last resort for mismatched atlas keys).
|
| 90 |
rows = conn.execute(
|
| 91 |
-
"SELECT lang, senses_json FROM definitions WHERE term = ? ORDER BY lang LIMIT 8",
|
| 92 |
(term,),
|
| 93 |
).fetchall()
|
| 94 |
if rows:
|
|
@@ -101,12 +114,14 @@ def lookup_definitions(
|
|
| 101 |
break
|
| 102 |
row = chosen or rows[0]
|
| 103 |
matched_lang = row["lang"] if isinstance(row, sqlite3.Row) else row[0]
|
|
|
|
| 104 |
fallback = bool(candidates) and matched_lang not in candidates
|
| 105 |
|
| 106 |
if row is None:
|
| 107 |
return {
|
| 108 |
"term": term,
|
| 109 |
"lang": lang,
|
|
|
|
| 110 |
"matched_code": None,
|
| 111 |
"senses": [],
|
| 112 |
"fallback": False,
|
|
@@ -114,11 +129,12 @@ def lookup_definitions(
|
|
| 114 |
"error": "not_found",
|
| 115 |
}
|
| 116 |
|
| 117 |
-
senses_json = row["senses_json"] if isinstance(row, sqlite3.Row) else row[
|
| 118 |
senses = _trim_senses(senses_json)
|
| 119 |
return {
|
| 120 |
"term": term,
|
| 121 |
"lang": lang,
|
|
|
|
| 122 |
"matched_code": matched_lang,
|
| 123 |
"senses": senses,
|
| 124 |
"fallback": fallback,
|
|
@@ -130,6 +146,7 @@ def lookup_definitions(
|
|
| 130 |
def fetch_definitions(
|
| 131 |
term: str,
|
| 132 |
lang: str = "",
|
|
|
|
| 133 |
iso_639_3: str | None = None,
|
| 134 |
*,
|
| 135 |
atlas=None,
|
|
@@ -139,6 +156,7 @@ def fetch_definitions(
|
|
| 139 |
return {
|
| 140 |
"term": term,
|
| 141 |
"lang": lang,
|
|
|
|
| 142 |
"matched_code": None,
|
| 143 |
"senses": [],
|
| 144 |
"fallback": False,
|
|
@@ -149,6 +167,7 @@ def fetch_definitions(
|
|
| 149 |
atlas.conn,
|
| 150 |
term=term,
|
| 151 |
lang=lang,
|
|
|
|
| 152 |
iso_639_3=iso_639_3,
|
| 153 |
lang_meta=getattr(atlas, "lang_meta", None),
|
| 154 |
)
|
|
|
|
| 64 |
conn: sqlite3.Connection,
|
| 65 |
term: str,
|
| 66 |
lang: str = "",
|
| 67 |
+
ety: str | None = None,
|
| 68 |
iso_639_3: str | None = None,
|
| 69 |
lang_meta: dict[str, dict] | None = None,
|
| 70 |
) -> dict:
|
|
|
|
| 76 |
|
| 77 |
row = None
|
| 78 |
matched_lang = None
|
| 79 |
+
matched_ety = None
|
| 80 |
for cand in candidates:
|
| 81 |
+
if ety is not None:
|
| 82 |
+
row = conn.execute(
|
| 83 |
+
"SELECT lang, ety, senses_json FROM definitions WHERE term = ? AND lang = ? AND ety = ?",
|
| 84 |
+
(term, cand, ety),
|
| 85 |
+
).fetchone()
|
| 86 |
+
else:
|
| 87 |
+
row = conn.execute(
|
| 88 |
+
"""
|
| 89 |
+
SELECT lang, ety, senses_json FROM definitions
|
| 90 |
+
WHERE term = ? AND lang = ?
|
| 91 |
+
ORDER BY (ety = '') DESC, ety
|
| 92 |
+
LIMIT 1
|
| 93 |
+
""",
|
| 94 |
+
(term, cand),
|
| 95 |
+
).fetchone()
|
| 96 |
if row is not None:
|
| 97 |
matched_lang = row["lang"] if isinstance(row, sqlite3.Row) else row[0]
|
| 98 |
+
matched_ety = row["ety"] if isinstance(row, sqlite3.Row) else row[1]
|
| 99 |
break
|
| 100 |
|
| 101 |
fallback = False
|
| 102 |
if row is None:
|
|
|
|
| 103 |
rows = conn.execute(
|
| 104 |
+
"SELECT lang, ety, senses_json FROM definitions WHERE term = ? ORDER BY lang, ety LIMIT 8",
|
| 105 |
(term,),
|
| 106 |
).fetchall()
|
| 107 |
if rows:
|
|
|
|
| 114 |
break
|
| 115 |
row = chosen or rows[0]
|
| 116 |
matched_lang = row["lang"] if isinstance(row, sqlite3.Row) else row[0]
|
| 117 |
+
matched_ety = row["ety"] if isinstance(row, sqlite3.Row) else row[1]
|
| 118 |
fallback = bool(candidates) and matched_lang not in candidates
|
| 119 |
|
| 120 |
if row is None:
|
| 121 |
return {
|
| 122 |
"term": term,
|
| 123 |
"lang": lang,
|
| 124 |
+
"ety": ety or "",
|
| 125 |
"matched_code": None,
|
| 126 |
"senses": [],
|
| 127 |
"fallback": False,
|
|
|
|
| 129 |
"error": "not_found",
|
| 130 |
}
|
| 131 |
|
| 132 |
+
senses_json = row["senses_json"] if isinstance(row, sqlite3.Row) else row[2]
|
| 133 |
senses = _trim_senses(senses_json)
|
| 134 |
return {
|
| 135 |
"term": term,
|
| 136 |
"lang": lang,
|
| 137 |
+
"ety": matched_ety or "",
|
| 138 |
"matched_code": matched_lang,
|
| 139 |
"senses": senses,
|
| 140 |
"fallback": fallback,
|
|
|
|
| 146 |
def fetch_definitions(
|
| 147 |
term: str,
|
| 148 |
lang: str = "",
|
| 149 |
+
ety: str | None = None,
|
| 150 |
iso_639_3: str | None = None,
|
| 151 |
*,
|
| 152 |
atlas=None,
|
|
|
|
| 156 |
return {
|
| 157 |
"term": term,
|
| 158 |
"lang": lang,
|
| 159 |
+
"ety": ety or "",
|
| 160 |
"matched_code": None,
|
| 161 |
"senses": [],
|
| 162 |
"fallback": False,
|
|
|
|
| 167 |
atlas.conn,
|
| 168 |
term=term,
|
| 169 |
lang=lang,
|
| 170 |
+
ety=ety,
|
| 171 |
iso_639_3=iso_639_3,
|
| 172 |
lang_meta=getattr(atlas, "lang_meta", None),
|
| 173 |
)
|
backend/game.py
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Etymology link game: guess how two related words meet in the graph."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import hashlib
|
| 6 |
+
import json
|
| 7 |
+
import random
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
from backend.atlas import Atlas, _bridge_label
|
| 11 |
+
from backend.define import lookup_definitions
|
| 12 |
+
|
| 13 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 14 |
+
DECK_PATH = ROOT / "data" / "game" / "en_es_pairs.json"
|
| 15 |
+
|
| 16 |
+
BRIDGE_CHOICES = [
|
| 17 |
+
"Latin",
|
| 18 |
+
"Old / Middle French",
|
| 19 |
+
"Proto-Germanic",
|
| 20 |
+
"Proto-Indo-European",
|
| 21 |
+
"Ancient Greek",
|
| 22 |
+
"Old English",
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
SEED_PAIRS: list[dict] = [
|
| 26 |
+
{"en": "family", "es": "familia", "source": "seed"},
|
| 27 |
+
{"en": "nation", "es": "nación", "source": "seed"},
|
| 28 |
+
{"en": "name", "es": "nombre", "source": "seed"},
|
| 29 |
+
{"en": "five", "es": "cinco", "source": "seed"},
|
| 30 |
+
{"en": "four", "es": "cuatro", "source": "seed"},
|
| 31 |
+
{"en": "star", "es": "estrella", "source": "seed"},
|
| 32 |
+
{"en": "night", "es": "noche", "source": "seed"},
|
| 33 |
+
{"en": "sun", "es": "sol", "source": "seed"},
|
| 34 |
+
{"en": "tooth", "es": "diente", "source": "seed"},
|
| 35 |
+
{"en": "heart", "es": "corazón", "source": "seed"},
|
| 36 |
+
{"en": "foot", "es": "pie", "source": "seed"},
|
| 37 |
+
{"en": "eye", "es": "ojo", "source": "seed"},
|
| 38 |
+
{"en": "fish", "es": "pez", "source": "seed"},
|
| 39 |
+
{"en": "new", "es": "nuevo", "source": "seed"},
|
| 40 |
+
{"en": "full", "es": "lleno", "source": "seed"},
|
| 41 |
+
{"en": "come", "es": "venir", "source": "seed"},
|
| 42 |
+
{"en": "mother", "es": "madre", "source": "seed"},
|
| 43 |
+
{"en": "father", "es": "padre", "source": "seed"},
|
| 44 |
+
{"en": "three", "es": "tres", "source": "seed"},
|
| 45 |
+
{"en": "two", "es": "dos", "source": "seed"},
|
| 46 |
+
{"en": "one", "es": "uno", "source": "seed"},
|
| 47 |
+
{"en": "wind", "es": "viento", "source": "seed"},
|
| 48 |
+
{"en": "red", "es": "rojo", "source": "seed"},
|
| 49 |
+
{"en": "school", "es": "escuela", "source": "seed"},
|
| 50 |
+
{"en": "music", "es": "música", "source": "seed"},
|
| 51 |
+
{"en": "animal", "es": "animal", "source": "seed"},
|
| 52 |
+
{"en": "hospital", "es": "hospital", "source": "seed"},
|
| 53 |
+
{"en": "nature", "es": "naturaleza", "source": "seed"},
|
| 54 |
+
{"en": "important", "es": "importante", "source": "seed"},
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def _load_deck() -> list[dict]:
|
| 59 |
+
pairs = list(SEED_PAIRS)
|
| 60 |
+
if DECK_PATH.exists():
|
| 61 |
+
try:
|
| 62 |
+
data = json.loads(DECK_PATH.read_text())
|
| 63 |
+
for row in data.get("pairs") or []:
|
| 64 |
+
en = (row.get("en") or "").strip()
|
| 65 |
+
es = (row.get("es") or "").strip()
|
| 66 |
+
if en and es:
|
| 67 |
+
pairs.append({"en": en, "es": es, "source": row.get("source") or "deck"})
|
| 68 |
+
except (json.JSONDecodeError, OSError):
|
| 69 |
+
pass
|
| 70 |
+
seen: set[tuple[str, str]] = set()
|
| 71 |
+
out: list[dict] = []
|
| 72 |
+
for p in pairs:
|
| 73 |
+
key = (p["en"].casefold(), p["es"].casefold())
|
| 74 |
+
if key in seen:
|
| 75 |
+
continue
|
| 76 |
+
seen.add(key)
|
| 77 |
+
out.append(p)
|
| 78 |
+
return out
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def _gloss(atlas: Atlas, term: str, lang: str) -> str:
|
| 82 |
+
assert atlas.conn is not None
|
| 83 |
+
payload = lookup_definitions(atlas.conn, term=term, lang=lang, lang_meta=atlas.lang_meta)
|
| 84 |
+
senses = payload.get("senses") or []
|
| 85 |
+
if not senses:
|
| 86 |
+
return ""
|
| 87 |
+
glosses = senses[0].get("glosses") or []
|
| 88 |
+
return glosses[0] if glosses else ""
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def _display_lang(atlas: Atlas, lang: str) -> str:
|
| 92 |
+
meta = atlas.lang_meta.get(lang) or {}
|
| 93 |
+
return meta.get("display") or (lang or "").replace("-", " ").title()
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def _pack_node(atlas: Atlas, n: dict) -> dict:
|
| 97 |
+
return {
|
| 98 |
+
"term": n["term"],
|
| 99 |
+
"lang": n["lang"],
|
| 100 |
+
"lang_display": n.get("lang_display") or _display_lang(atlas, n["lang"]),
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def _round_id(en: str, es: str) -> str:
|
| 105 |
+
return hashlib.sha1(f"{en}\0{es}".encode()).hexdigest()[:12]
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def build_round(atlas: Atlas, en: str, es: str, *, source: str = "custom") -> dict:
|
| 109 |
+
related = atlas.relate(en, "english", es, "spanish", max_depth=12)
|
| 110 |
+
if not related.get("ok"):
|
| 111 |
+
return {"ok": False, "error": related.get("error") or "unrelated", "en": en, "es": es}
|
| 112 |
+
|
| 113 |
+
path_a = related["path_a"]
|
| 114 |
+
path_b = related["path_b"]
|
| 115 |
+
lca = related["lca"]
|
| 116 |
+
bridge = _bridge_label(lca["lang"])
|
| 117 |
+
|
| 118 |
+
# Language hops after the modern word, including the shared ancestor language once.
|
| 119 |
+
langs_a = [_display_lang(atlas, n["lang"]) for n in path_a[1:]]
|
| 120 |
+
langs_b = [_display_lang(atlas, n["lang"]) for n in path_b[1:]]
|
| 121 |
+
a_only = langs_a[:-1] if langs_a else []
|
| 122 |
+
b_only = langs_b[:-1] if langs_b else []
|
| 123 |
+
answer_chain = a_only + [bridge] + list(reversed(b_only))
|
| 124 |
+
|
| 125 |
+
distractors = [
|
| 126 |
+
"Proto-Germanic",
|
| 127 |
+
"Latin",
|
| 128 |
+
"Old French",
|
| 129 |
+
"Middle English",
|
| 130 |
+
"Old English",
|
| 131 |
+
"Old Spanish",
|
| 132 |
+
"Proto-Italic",
|
| 133 |
+
"Ancient Greek",
|
| 134 |
+
"Proto-Indo-European",
|
| 135 |
+
"Middle French",
|
| 136 |
+
"Proto-West Germanic",
|
| 137 |
+
"Old / Middle French",
|
| 138 |
+
]
|
| 139 |
+
needed = list(dict.fromkeys(answer_chain))
|
| 140 |
+
pool = list(dict.fromkeys([*needed, *distractors]))
|
| 141 |
+
rng = random.Random(_round_id(en, es))
|
| 142 |
+
# Keep all needed + a few distractors
|
| 143 |
+
extras = [p for p in pool if p not in needed]
|
| 144 |
+
rng.shuffle(extras)
|
| 145 |
+
pool = needed + extras[:4]
|
| 146 |
+
rng.shuffle(pool)
|
| 147 |
+
|
| 148 |
+
opts = [bridge]
|
| 149 |
+
for c in BRIDGE_CHOICES:
|
| 150 |
+
if c not in opts:
|
| 151 |
+
opts.append(c)
|
| 152 |
+
if len(opts) >= 4:
|
| 153 |
+
break
|
| 154 |
+
rng.shuffle(opts)
|
| 155 |
+
|
| 156 |
+
a = related["a"]
|
| 157 |
+
b = related["b"]
|
| 158 |
+
return {
|
| 159 |
+
"ok": True,
|
| 160 |
+
"id": _round_id(en, es),
|
| 161 |
+
"source": source,
|
| 162 |
+
"a": {
|
| 163 |
+
"term": a["term"],
|
| 164 |
+
"lang": a["lang"],
|
| 165 |
+
"lang_display": a.get("lang_display") or "English",
|
| 166 |
+
"gloss": _gloss(atlas, a["term"], a["lang"]),
|
| 167 |
+
},
|
| 168 |
+
"b": {
|
| 169 |
+
"term": b["term"],
|
| 170 |
+
"lang": b["lang"],
|
| 171 |
+
"lang_display": b.get("lang_display") or "Spanish",
|
| 172 |
+
"gloss": _gloss(atlas, b["term"], b["lang"]),
|
| 173 |
+
},
|
| 174 |
+
"bridge_choices": opts,
|
| 175 |
+
"slot_count": len(answer_chain),
|
| 176 |
+
"chip_pool": pool,
|
| 177 |
+
"answer": {
|
| 178 |
+
"bridge": bridge,
|
| 179 |
+
"chain": answer_chain,
|
| 180 |
+
"lca": {**_pack_node(atlas, lca), "bridge": bridge},
|
| 181 |
+
"path_a": [_pack_node(atlas, n) for n in path_a],
|
| 182 |
+
"path_b": [_pack_node(atlas, n) for n in path_b],
|
| 183 |
+
},
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def next_round(atlas: Atlas, *, avoid: set[str] | None = None) -> dict:
|
| 188 |
+
deck = _load_deck()
|
| 189 |
+
avoid = avoid or set()
|
| 190 |
+
# Prefer pedagogical pairs (seed / IE-CoR) over opportunistic Latin-root samples.
|
| 191 |
+
def priority(p: dict) -> int:
|
| 192 |
+
src = p.get("source") or ""
|
| 193 |
+
if src == "seed":
|
| 194 |
+
return 0
|
| 195 |
+
if src == "iecor":
|
| 196 |
+
return 1
|
| 197 |
+
return 2
|
| 198 |
+
|
| 199 |
+
ranked = sorted(deck, key=priority)
|
| 200 |
+
buckets = {0: [], 1: [], 2: []}
|
| 201 |
+
for p in ranked:
|
| 202 |
+
rid = _round_id(p["en"], p["es"])
|
| 203 |
+
if rid in avoid:
|
| 204 |
+
continue
|
| 205 |
+
buckets[priority(p)].append(p)
|
| 206 |
+
# Weighted draw: mostly seed/iecor
|
| 207 |
+
pool: list[dict] = []
|
| 208 |
+
pool.extend(buckets[0] * 3)
|
| 209 |
+
pool.extend(buckets[1] * 2)
|
| 210 |
+
pool.extend(buckets[2])
|
| 211 |
+
if not pool:
|
| 212 |
+
pool = list(deck)
|
| 213 |
+
random.shuffle(pool)
|
| 214 |
+
last_err = "empty_deck"
|
| 215 |
+
for p in pool[:60]:
|
| 216 |
+
rnd = build_round(atlas, p["en"], p["es"], source=p.get("source") or "deck")
|
| 217 |
+
if rnd.get("ok"):
|
| 218 |
+
return rnd
|
| 219 |
+
last_err = rnd.get("error") or last_err
|
| 220 |
+
return {"ok": False, "error": last_err}
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def score_guess(round_payload: dict, bridge_guess: str | None, chain_guess: list[str] | None) -> dict:
|
| 224 |
+
ans = round_payload.get("answer") or {}
|
| 225 |
+
true_bridge = ans.get("bridge") or ""
|
| 226 |
+
true_chain = ans.get("chain") or []
|
| 227 |
+
bridge_ok = (bridge_guess or "").strip() == true_bridge
|
| 228 |
+
chain = list(chain_guess or [])
|
| 229 |
+
n = len(true_chain)
|
| 230 |
+
correct_slots = sum(1 for i in range(n) if i < len(chain) and chain[i] == true_chain[i])
|
| 231 |
+
chain_ok = chain[:n] == true_chain and len(chain) >= n
|
| 232 |
+
return {
|
| 233 |
+
"bridge_ok": bridge_ok,
|
| 234 |
+
"chain_ok": chain_ok,
|
| 235 |
+
"correct_slots": correct_slots,
|
| 236 |
+
"slot_count": n,
|
| 237 |
+
"score": int(bridge_ok) + correct_slots,
|
| 238 |
+
"max_score": 1 + n,
|
| 239 |
+
"answer": ans,
|
| 240 |
+
}
|
backend/models.py
CHANGED
|
@@ -61,6 +61,8 @@ class PathFilter(BaseModel):
|
|
| 61 |
class TreeQuery(BaseModel):
|
| 62 |
term: str
|
| 63 |
lang: str
|
|
|
|
|
|
|
| 64 |
edges: EdgeFilter = Field(default_factory=EdgeFilter)
|
| 65 |
leaf: NodePredicate = Field(default_factory=NodePredicate)
|
| 66 |
path: PathFilter = Field(default_factory=PathFilter)
|
|
@@ -74,6 +76,7 @@ class TreeQuery(BaseModel):
|
|
| 74 |
class SuggestHit(BaseModel):
|
| 75 |
term: str
|
| 76 |
lang: str
|
|
|
|
| 77 |
lang_display: str | None = None
|
| 78 |
family_name: str | None = None
|
| 79 |
child_count: int = 0
|
|
|
|
| 61 |
class TreeQuery(BaseModel):
|
| 62 |
term: str
|
| 63 |
lang: str
|
| 64 |
+
# Editorial etymology id / etymology_number key; omit to auto-resolve.
|
| 65 |
+
ety: str | None = None
|
| 66 |
edges: EdgeFilter = Field(default_factory=EdgeFilter)
|
| 67 |
leaf: NodePredicate = Field(default_factory=NodePredicate)
|
| 68 |
path: PathFilter = Field(default_factory=PathFilter)
|
|
|
|
| 76 |
class SuggestHit(BaseModel):
|
| 77 |
term: str
|
| 78 |
lang: str
|
| 79 |
+
ety: str = ""
|
| 80 |
lang_display: str | None = None
|
| 81 |
family_name: str | None = None
|
| 82 |
child_count: int = 0
|
backend/wiktionary.py
CHANGED
|
@@ -1,39 +1,10 @@
|
|
| 1 |
-
"""Build en.wiktionary.org links
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
from urllib.parse import quote
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
_MACRON_FOLD = str.maketrans({
|
| 9 |
-
"ā": "a", "ē": "e", "ī": "i", "ō": "o", "ū": "u", "ȳ": "y",
|
| 10 |
-
"Ā": "A", "Ē": "E", "Ī": "I", "Ō": "O", "Ū": "U", "Ȳ": "Y",
|
| 11 |
-
"ă": "a", "ĕ": "e", "ĭ": "i", "ŏ": "o", "ŭ": "u",
|
| 12 |
-
})
|
| 13 |
-
|
| 14 |
-
# Reconstruction: namespace language titles (Wiktionary English names).
|
| 15 |
-
# Stages of Latin share Reconstruction:Latin/… on Wiktionary.
|
| 16 |
-
_RECON_LANG_TITLE: dict[str, str] = {
|
| 17 |
-
"latin": "Latin",
|
| 18 |
-
"vulgar latin": "Latin",
|
| 19 |
-
"late latin": "Latin",
|
| 20 |
-
"medieval latin": "Latin",
|
| 21 |
-
"new latin": "Latin",
|
| 22 |
-
"old latin": "Old Latin",
|
| 23 |
-
"proto-indo-european": "Proto-Indo-European",
|
| 24 |
-
"proto-germanic": "Proto-Germanic",
|
| 25 |
-
"proto-west germanic": "Proto-West Germanic",
|
| 26 |
-
"proto-italic": "Proto-Italic",
|
| 27 |
-
"proto-celtic": "Proto-Celtic",
|
| 28 |
-
"proto-slavic": "Proto-Slavic",
|
| 29 |
-
"proto-balto-slavic": "Proto-Balto-Slavic",
|
| 30 |
-
"proto-indo-iranian": "Proto-Indo-Iranian",
|
| 31 |
-
"proto-iranian": "Proto-Iranian",
|
| 32 |
-
"proto-semitic": "Proto-Semitic",
|
| 33 |
-
"proto-romance": "Proto-Romance",
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
# Fragment / heading language names when display metadata is missing or poorly cased.
|
| 37 |
_SECTION_LANG_TITLE: dict[str, str] = {
|
| 38 |
"old french": "Old French",
|
| 39 |
"middle french": "Middle French",
|
|
@@ -45,70 +16,50 @@ _SECTION_LANG_TITLE: dict[str, str] = {
|
|
| 45 |
"vulgar latin": "Vulgar Latin",
|
| 46 |
"late latin": "Late Latin",
|
| 47 |
"medieval latin": "Medieval Latin",
|
|
|
|
|
|
|
|
|
|
| 48 |
}
|
| 49 |
|
| 50 |
|
| 51 |
-
def fold_length_marks(term: str) -> str:
|
| 52 |
-
return term.translate(_MACRON_FOLD)
|
| 53 |
-
|
| 54 |
-
|
| 55 |
def wiki_section_title(lang: str, lang_display: str | None = None) -> str:
|
| 56 |
-
"""Language heading as used in `#Old_French` fragments."""
|
| 57 |
key = (lang or "").strip().casefold()
|
| 58 |
if key in _SECTION_LANG_TITLE:
|
| 59 |
return _SECTION_LANG_TITLE[key]
|
| 60 |
-
if key in _RECON_LANG_TITLE and key != "vulgar latin":
|
| 61 |
-
# Prefer canonical WT casing for proto-* etc.
|
| 62 |
-
return _RECON_LANG_TITLE[key]
|
| 63 |
name = (lang_display or lang or "").strip().replace("_", " ")
|
| 64 |
if not name:
|
| 65 |
return ""
|
| 66 |
-
# Title-case hyphenated segments: proto-indo-european → Proto-Indo-European
|
| 67 |
return "-".join(
|
| 68 |
" ".join(w[:1].upper() + w[1:] if w else w for w in part.split())
|
| 69 |
for part in name.split("-")
|
| 70 |
)
|
| 71 |
|
| 72 |
|
| 73 |
-
def reconstruction_lang_title(lang: str) -> str:
|
| 74 |
-
key = (lang or "").strip().casefold()
|
| 75 |
-
if key in _RECON_LANG_TITLE:
|
| 76 |
-
return _RECON_LANG_TITLE[key]
|
| 77 |
-
return wiki_section_title(lang)
|
| 78 |
-
|
| 79 |
-
|
| 80 |
def mediawiki_path_title(title: str) -> str:
|
| 81 |
"""Percent-encode a wiki title for use in /wiki/… paths."""
|
| 82 |
return quote(title.replace(" ", "_"), safe="/:()'!,*-.")
|
| 83 |
|
| 84 |
|
| 85 |
-
def wiktionary_url(
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
Note: some graph spellings (e.g. Old French *akever*) are cited in etymologies
|
| 92 |
-
but have no Wiktionary entry; those links will 404 until WT has a page.
|
| 93 |
"""
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
form = fold_length_marks(term[1:])
|
| 101 |
-
lang_title = reconstruction_lang_title(lang)
|
| 102 |
-
if not form or not lang_title:
|
| 103 |
-
# Fall back to search rather than a guaranteed-bad *lemma URL.
|
| 104 |
-
q = quote(term)
|
| 105 |
-
return f"https://en.wiktionary.org/w/index.php?search={q}"
|
| 106 |
-
page = f"Reconstruction:{lang_title}/{form}"
|
| 107 |
-
return f"https://en.wiktionary.org/wiki/{mediawiki_path_title(page)}"
|
| 108 |
-
|
| 109 |
section = wiki_section_title(lang, lang_display)
|
| 110 |
-
# Keep attested-orthography diacritics; only encode for the URL path.
|
| 111 |
-
path = mediawiki_path_title(term)
|
| 112 |
if section:
|
| 113 |
frag = quote(section.replace(" ", "_"), safe="")
|
| 114 |
return f"https://en.wiktionary.org/wiki/{path}#{frag}"
|
|
|
|
| 1 |
+
"""Build en.wiktionary.org links from persisted Wiktionary page titles."""
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
from urllib.parse import quote
|
| 6 |
|
| 7 |
+
# Fragment / heading language names for mainspace multi-language pages.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
_SECTION_LANG_TITLE: dict[str, str] = {
|
| 9 |
"old french": "Old French",
|
| 10 |
"middle french": "Middle French",
|
|
|
|
| 16 |
"vulgar latin": "Vulgar Latin",
|
| 17 |
"late latin": "Late Latin",
|
| 18 |
"medieval latin": "Medieval Latin",
|
| 19 |
+
"latin": "Latin",
|
| 20 |
+
"english": "English",
|
| 21 |
+
"french": "French",
|
| 22 |
}
|
| 23 |
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def wiki_section_title(lang: str, lang_display: str | None = None) -> str:
|
| 26 |
+
"""Language heading as used in `#Old_French` fragments on mainspace pages."""
|
| 27 |
key = (lang or "").strip().casefold()
|
| 28 |
if key in _SECTION_LANG_TITLE:
|
| 29 |
return _SECTION_LANG_TITLE[key]
|
|
|
|
|
|
|
|
|
|
| 30 |
name = (lang_display or lang or "").strip().replace("_", " ")
|
| 31 |
if not name:
|
| 32 |
return ""
|
|
|
|
| 33 |
return "-".join(
|
| 34 |
" ".join(w[:1].upper() + w[1:] if w else w for w in part.split())
|
| 35 |
for part in name.split("-")
|
| 36 |
)
|
| 37 |
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def mediawiki_path_title(title: str) -> str:
|
| 40 |
"""Percent-encode a wiki title for use in /wiki/… paths."""
|
| 41 |
return quote(title.replace(" ", "_"), safe="/:()'!,*-.")
|
| 42 |
|
| 43 |
|
| 44 |
+
def wiktionary_url(
|
| 45 |
+
wiki_title: str | None,
|
| 46 |
+
*,
|
| 47 |
+
lang: str = "",
|
| 48 |
+
lang_display: str | None = None,
|
| 49 |
+
) -> str | None:
|
| 50 |
+
"""Build a Wiktionary URL from a stored page title, or None if unknown.
|
| 51 |
|
| 52 |
+
``wiki_title`` is the Kaikki ``original_title`` (e.g. ``Reconstruction:Latin/accapare``)
|
| 53 |
+
or the mainspace lemma. Nodes minted only from descendant-tree labels have no title
|
| 54 |
+
and return ``None`` (no link).
|
|
|
|
|
|
|
| 55 |
"""
|
| 56 |
+
title = (wiki_title or "").strip()
|
| 57 |
+
if not title:
|
| 58 |
+
return None
|
| 59 |
+
path = mediawiki_path_title(title)
|
| 60 |
+
if title.startswith("Reconstruction:"):
|
| 61 |
+
return f"https://en.wiktionary.org/wiki/{path}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
section = wiki_section_title(lang, lang_display)
|
|
|
|
|
|
|
| 63 |
if section:
|
| 64 |
frag = quote(section.replace(" ", "_"), safe="")
|
| 65 |
return f"https://en.wiktionary.org/wiki/{path}#{frag}"
|
frontend/dist/assets/index-CSxQdCV8.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontend/dist/assets/index-Dr1iPrLq.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
@import"https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700&family=Source+Sans+3:wght@400;500;600;700&display=swap";.leaflet-pane,.leaflet-tile,.leaflet-marker-icon,.leaflet-marker-shadow,.leaflet-tile-container,.leaflet-pane>svg,.leaflet-pane>canvas,.leaflet-zoom-box,.leaflet-image-layer,.leaflet-layer{position:absolute;left:0;top:0}.leaflet-container{overflow:hidden}.leaflet-tile,.leaflet-marker-icon,.leaflet-marker-shadow{-webkit-user-select:none;-moz-user-select:none;user-select:none;-webkit-user-drag:none}.leaflet-tile::selection{background:transparent}.leaflet-safari .leaflet-tile{image-rendering:-webkit-optimize-contrast}.leaflet-safari .leaflet-tile-container{width:1600px;height:1600px;-webkit-transform-origin:0 0}.leaflet-marker-icon,.leaflet-marker-shadow{display:block}.leaflet-container .leaflet-overlay-pane svg{max-width:none!important;max-height:none!important}.leaflet-container .leaflet-marker-pane img,.leaflet-container .leaflet-shadow-pane img,.leaflet-container .leaflet-tile-pane img,.leaflet-container img.leaflet-image-layer,.leaflet-container .leaflet-tile{max-width:none!important;max-height:none!important;width:auto;padding:0}.leaflet-container img.leaflet-tile{mix-blend-mode:plus-lighter}.leaflet-container.leaflet-touch-zoom{-ms-touch-action:pan-x pan-y;touch-action:pan-x pan-y}.leaflet-container.leaflet-touch-drag{-ms-touch-action:pinch-zoom;touch-action:none;touch-action:pinch-zoom}.leaflet-container.leaflet-touch-drag.leaflet-touch-zoom{-ms-touch-action:none;touch-action:none}.leaflet-container{-webkit-tap-highlight-color:transparent}.leaflet-container a{-webkit-tap-highlight-color:rgba(51,181,229,.4)}.leaflet-tile{filter:inherit;visibility:hidden}.leaflet-tile-loaded{visibility:inherit}.leaflet-zoom-box{width:0;height:0;-moz-box-sizing:border-box;box-sizing:border-box;z-index:800}.leaflet-overlay-pane svg{-moz-user-select:none}.leaflet-pane{z-index:400}.leaflet-tile-pane{z-index:200}.leaflet-overlay-pane{z-index:400}.leaflet-shadow-pane{z-index:500}.leaflet-marker-pane{z-index:600}.leaflet-tooltip-pane{z-index:650}.leaflet-popup-pane{z-index:700}.leaflet-map-pane canvas{z-index:100}.leaflet-map-pane svg{z-index:200}.leaflet-vml-shape{width:1px;height:1px}.lvml{behavior:url(#default#VML);display:inline-block;position:absolute}.leaflet-control{position:relative;z-index:800;pointer-events:visiblePainted;pointer-events:auto}.leaflet-top,.leaflet-bottom{position:absolute;z-index:1000;pointer-events:none}.leaflet-top{top:0}.leaflet-right{right:0}.leaflet-bottom{bottom:0}.leaflet-left{left:0}.leaflet-control{float:left;clear:both}.leaflet-right .leaflet-control{float:right}.leaflet-top .leaflet-control{margin-top:10px}.leaflet-bottom .leaflet-control{margin-bottom:10px}.leaflet-left .leaflet-control{margin-left:10px}.leaflet-right .leaflet-control{margin-right:10px}.leaflet-fade-anim .leaflet-popup{opacity:0;-webkit-transition:opacity .2s linear;-moz-transition:opacity .2s linear;transition:opacity .2s linear}.leaflet-fade-anim .leaflet-map-pane .leaflet-popup{opacity:1}.leaflet-zoom-animated{-webkit-transform-origin:0 0;-ms-transform-origin:0 0;transform-origin:0 0}svg.leaflet-zoom-animated{will-change:transform}.leaflet-zoom-anim .leaflet-zoom-animated{-webkit-transition:-webkit-transform .25s cubic-bezier(0,0,.25,1);-moz-transition:-moz-transform .25s cubic-bezier(0,0,.25,1);transition:transform .25s cubic-bezier(0,0,.25,1)}.leaflet-zoom-anim .leaflet-tile,.leaflet-pan-anim .leaflet-tile{-webkit-transition:none;-moz-transition:none;transition:none}.leaflet-zoom-anim .leaflet-zoom-hide{visibility:hidden}.leaflet-interactive{cursor:pointer}.leaflet-grab{cursor:-webkit-grab;cursor:-moz-grab;cursor:grab}.leaflet-crosshair,.leaflet-crosshair .leaflet-interactive{cursor:crosshair}.leaflet-popup-pane,.leaflet-control{cursor:auto}.leaflet-dragging .leaflet-grab,.leaflet-dragging .leaflet-grab .leaflet-interactive,.leaflet-dragging .leaflet-marker-draggable{cursor:move;cursor:-webkit-grabbing;cursor:-moz-grabbing;cursor:grabbing}.leaflet-marker-icon,.leaflet-marker-shadow,.leaflet-image-layer,.leaflet-pane>svg path,.leaflet-tile-container{pointer-events:none}.leaflet-marker-icon.leaflet-interactive,.leaflet-image-layer.leaflet-interactive,.leaflet-pane>svg path.leaflet-interactive,svg.leaflet-image-layer.leaflet-interactive path{pointer-events:visiblePainted;pointer-events:auto}.leaflet-container{background:#ddd;outline-offset:1px}.leaflet-container a{color:#0078a8}.leaflet-zoom-box{border:2px dotted #38f;background:#ffffff80}.leaflet-container{font-family:Helvetica Neue,Arial,Helvetica,sans-serif;font-size:12px;font-size:.75rem;line-height:1.5}.leaflet-bar{box-shadow:0 1px 5px #000000a6;border-radius:4px}.leaflet-bar a{background-color:#fff;border-bottom:1px solid #ccc;width:26px;height:26px;line-height:26px;display:block;text-align:center;text-decoration:none;color:#000}.leaflet-bar a,.leaflet-control-layers-toggle{background-position:50% 50%;background-repeat:no-repeat;display:block}.leaflet-bar a:hover,.leaflet-bar a:focus{background-color:#f4f4f4}.leaflet-bar a:first-child{border-top-left-radius:4px;border-top-right-radius:4px}.leaflet-bar a:last-child{border-bottom-left-radius:4px;border-bottom-right-radius:4px;border-bottom:none}.leaflet-bar a.leaflet-disabled{cursor:default;background-color:#f4f4f4;color:#bbb}.leaflet-touch .leaflet-bar a{width:30px;height:30px;line-height:30px}.leaflet-touch .leaflet-bar a:first-child{border-top-left-radius:2px;border-top-right-radius:2px}.leaflet-touch .leaflet-bar a:last-child{border-bottom-left-radius:2px;border-bottom-right-radius:2px}.leaflet-control-zoom-in,.leaflet-control-zoom-out{font:700 18px Lucida Console,Monaco,monospace;text-indent:1px}.leaflet-touch .leaflet-control-zoom-in,.leaflet-touch .leaflet-control-zoom-out{font-size:22px}.leaflet-control-layers{box-shadow:0 1px 5px #0006;background:#fff;border-radius:5px}.leaflet-control-layers-toggle{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAQAAAADQ4RFAAACf0lEQVR4AY1UM3gkARTePdvdoTxXKc+qTl3aU5U6b2Kbkz3Gtq3Zw6ziLGNPzrYx7946Tr6/ee/XeCQ4D3ykPtL5tHno4n0d/h3+xfuWHGLX81cn7r0iTNzjr7LrlxCqPtkbTQEHeqOrTy4Yyt3VCi/IOB0v7rVC7q45Q3Gr5K6jt+3Gl5nCoDD4MtO+j96Wu8atmhGqcNGHObuf8OM/x3AMx38+4Z2sPqzCxRFK2aF2e5Jol56XTLyggAMTL56XOMoS1W4pOyjUcGGQdZxU6qRh7B9Zp+PfpOFlqt0zyDZckPi1ttmIp03jX8gyJ8a/PG2yutpS/Vol7peZIbZcKBAEEheEIAgFbDkz5H6Zrkm2hVWGiXKiF4Ycw0RWKdtC16Q7qe3X4iOMxruonzegJzWaXFrU9utOSsLUmrc0YjeWYjCW4PDMADElpJSSQ0vQvA1Tm6/JlKnqFs1EGyZiFCqnRZTEJJJiKRYzVYzJck2Rm6P4iH+cmSY0YzimYa8l0EtTODFWhcMIMVqdsI2uiTvKmTisIDHJ3od5GILVhBCarCfVRmo4uTjkhrhzkiBV7SsaqS+TzrzM1qpGGUFt28pIySQHR6h7F6KSwGWm97ay+Z+ZqMcEjEWebE7wxCSQwpkhJqoZA5ivCdZDjJepuJ9IQjGGUmuXJdBFUygxVqVsxFsLMbDe8ZbDYVCGKxs+W080max1hFCarCfV+C1KATwcnvE9gRRuMP2prdbWGowm1KB1y+zwMMENkM755cJ2yPDtqhTI6ED1M/82yIDtC/4j4BijjeObflpO9I9MwXTCsSX8jWAFeHr05WoLTJ5G8IQVS/7vwR6ohirYM7f6HzYpogfS3R2OAAAAAElFTkSuQmCC);width:36px;height:36px}.leaflet-retina .leaflet-control-layers-toggle{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADQAAAA0CAQAAABvcdNgAAAEsklEQVR4AWL4TydIhpZK1kpWOlg0w3ZXP6D2soBtG42jeI6ZmQTHzAxiTbSJsYLjO9HhP+WOmcuhciVnmHVQcJnp7DFvScowZorad/+V/fVzMdMT2g9Cv9guXGv/7pYOrXh2U+RRR3dSd9JRx6bIFc/ekqHI29JC6pJ5ZEh1yWkhkbcFeSjxgx3L2m1cb1C7bceyxA+CNjT/Ifff+/kDk2u/w/33/IeCMOSaWZ4glosqT3DNnNZQ7Cs58/3Ce5HL78iZH/vKVIaYlqzfdLu8Vi7dnvUbEza5Idt36tquZFldl6N5Z/POLof0XLK61mZCmJSWjVF9tEjUluu74IUXvgttuVIHE7YxSkaYhJZam7yiM9Pv82JYfl9nptxZaxMJE4YSPty+vF0+Y2up9d3wwijfjZbabqm/3bZ9ecKHsiGmRflnn1MW4pjHf9oLufyn2z3y1D6n8g8TZhxyzipLNPnAUpsOiuWimg52psrTZYnOWYNDTMuWBWa0tJb4rgq1UvmutpaYEbZlwU3CLJm/ayYjHW5/h7xWLn9Hh1vepDkyf7dE7MtT5LR4e7yYpHrkhOUpEfssBLq2pPhAqoSWKUkk7EDqkmK6RrCEzqDjhNDWNE+XSMvkJRDWlZTmCW0l0PHQGRZY5t1L83kT0Y3l2SItk5JAWHl2dCOBm+fPu3fo5/3v61RMCO9Jx2EEYYhb0rmNQMX/vm7gqOEJLcXTGw3CAuRNeyaPWwjR8PRqKQ1PDA/dpv+on9Shox52WFnx0KY8onHayrJzm87i5h9xGw/tfkev0jGsQizqezUKjk12hBMKJ4kbCqGPVNXudyyrShovGw5CgxsRICxF6aRmSjlBnHRzg7Gx8fKqEubI2rahQYdR1YgDIRQO7JvQyD52hoIQx0mxa0ODtW2Iozn1le2iIRdzwWewedyZzewidueOGqlsn1MvcnQpuVwLGG3/IR1hIKxCjelIDZ8ldqWz25jWAsnldEnK0Zxro19TGVb2ffIZEsIO89EIEDvKMPrzmBOQcKQ+rroye6NgRRxqR4U8EAkz0CL6uSGOm6KQCdWjvjRiSP1BPalCRS5iQYiEIvxuBMJEWgzSoHADcVMuN7IuqqTeyUPq22qFimFtxDyBBJEwNyt6TM88blFHao/6tWWhuuOM4SAK4EI4QmFHA+SEyWlp4EQoJ13cYGzMu7yszEIBOm2rVmHUNqwAIQabISNMRstmdhNWcFLsSm+0tjJH1MdRxO5Nx0WDMhCtgD6OKgZeljJqJKc9po8juskR9XN0Y1lZ3mWjLR9JCO1jRDMd0fpYC2VnvjBSEFg7wBENc0R9HFlb0xvF1+TBEpF68d+DHR6IOWVv2BECtxo46hOFUBd/APU57WIoEwJhIi2CdpyZX0m93BZicktMj1AS9dClteUFAUNUIEygRZCtik5zSxI9MubTBH1GOiHsiLJ3OCoSZkILa9PxiN0EbvhsAo8tdAf9Seepd36lGWHmtNANTv5Jd0z4QYyeo/UEJqxKRpg5LZx6btLPsOaEmdMyxYdlc8LMaJnikDlhclqmPiQnTEpLUIZEwkRagjYkEibQErwhkTAKCLQEbUgkzJQWc/0PstHHcfEdQ+UAAAAASUVORK5CYII=);background-size:26px 26px}.leaflet-touch .leaflet-control-layers-toggle{width:44px;height:44px}.leaflet-control-layers .leaflet-control-layers-list,.leaflet-control-layers-expanded .leaflet-control-layers-toggle{display:none}.leaflet-control-layers-expanded .leaflet-control-layers-list{display:block;position:relative}.leaflet-control-layers-expanded{padding:6px 10px 6px 6px;color:#333;background:#fff}.leaflet-control-layers-scrollbar{overflow-y:scroll;overflow-x:hidden;padding-right:5px}.leaflet-control-layers-selector{margin-top:2px;position:relative;top:1px}.leaflet-control-layers label{display:block;font-size:13px;font-size:1.08333em}.leaflet-control-layers-separator{height:0;border-top:1px solid #ddd;margin:5px -10px 5px -6px}.leaflet-default-icon-path{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAApCAYAAADAk4LOAAAFgUlEQVR4Aa1XA5BjWRTN2oW17d3YaZtr2962HUzbDNpjszW24mRt28p47v7zq/bXZtrp/lWnXr337j3nPCe85NcypgSFdugCpW5YoDAMRaIMqRi6aKq5E3YqDQO3qAwjVWrD8Ncq/RBpykd8oZUb/kaJutow8r1aP9II0WmLKLIsJyv1w/kqw9Ch2MYdB++12Onxee/QMwvf4/Dk/Lfp/i4nxTXtOoQ4pW5Aj7wpici1A9erdAN2OH64x8OSP9j3Ft3b7aWkTg/Fm91siTra0f9on5sQr9INejH6CUUUpavjFNq1B+Oadhxmnfa8RfEmN8VNAsQhPqF55xHkMzz3jSmChWU6f7/XZKNH+9+hBLOHYozuKQPxyMPUKkrX/K0uWnfFaJGS1QPRtZsOPtr3NsW0uyh6NNCOkU3Yz+bXbT3I8G3xE5EXLXtCXbbqwCO9zPQYPRTZ5vIDXD7U+w7rFDEoUUf7ibHIR4y6bLVPXrz8JVZEql13trxwue/uDivd3fkWRbS6/IA2bID4uk0UpF1N8qLlbBlXs4Ee7HLTfV1j54APvODnSfOWBqtKVvjgLKzF5YdEk5ewRkGlK0i33Eofffc7HT56jD7/6U+qH3Cx7SBLNntH5YIPvODnyfIXZYRVDPqgHtLs5ABHD3YzLuespb7t79FY34DjMwrVrcTuwlT55YMPvOBnRrJ4VXTdNnYug5ucHLBjEpt30701A3Ts+HEa73u6dT3FNWwflY86eMHPk+Yu+i6pzUpRrW7SNDg5JHR4KapmM5Wv2E8Tfcb1HoqqHMHU+uWDD7zg54mz5/2BSnizi9T1Dg4QQXLToGNCkb6tb1NU+QAlGr1++eADrzhn/u8Q2YZhQVlZ5+CAOtqfbhmaUCS1ezNFVm2imDbPmPng5wmz+gwh+oHDce0eUtQ6OGDIyR0uUhUsoO3vfDmmgOezH0mZN59x7MBi++WDL1g/eEiU3avlidO671bkLfwbw5XV2P8Pzo0ydy4t2/0eu33xYSOMOD8hTf4CrBtGMSoXfPLchX+J0ruSePw3LZeK0juPJbYzrhkH0io7B3k164hiGvawhOKMLkrQLyVpZg8rHFW7E2uHOL888IBPlNZ1FPzstSJM694fWr6RwpvcJK60+0HCILTBzZLFNdtAzJaohze60T8qBzyh5ZuOg5e7uwQppofEmf2++DYvmySqGBuKaicF1blQjhuHdvCIMvp8whTTfZzI7RldpwtSzL+F1+wkdZ2TBOW2gIF88PBTzD/gpeREAMEbxnJcaJHNHrpzji0gQCS6hdkEeYt9DF/2qPcEC8RM28Hwmr3sdNyht00byAut2k3gufWNtgtOEOFGUwcXWNDbdNbpgBGxEvKkOQsxivJx33iow0Vw5S6SVTrpVq11ysA2Rp7gTfPfktc6zhtXBBC+adRLshf6sG2RfHPZ5EAc4sVZ83yCN00Fk/4kggu40ZTvIEm5g24qtU4KjBrx/BTTH8ifVASAG7gKrnWxJDcU7x8X6Ecczhm3o6YicvsLXWfh3Ch1W0k8x0nXF+0fFxgt4phz8QvypiwCCFKMqXCnqXExjq10beH+UUA7+nG6mdG/Pu0f3LgFcGrl2s0kNNjpmoJ9o4B29CMO8dMT4Q5ox8uitF6fqsrJOr8qnwNbRzv6hSnG5wP+64C7h9lp30hKNtKdWjtdkbuPA19nJ7Tz3zR/ibgARbhb4AlhavcBebmTHcFl2fvYEnW0ox9xMxKBS8btJ+KiEbq9zA4RthQXDhPa0T9TEe69gWupwc6uBUphquXgf+/FrIjweHQS4/pduMe5ERUMHUd9xv8ZR98CxkS4F2n3EUrUZ10EYNw7BWm9x1GiPssi3GgiGRDKWRYZfXlON+dfNbM+GgIwYdwAAAAASUVORK5CYII=)}.leaflet-container .leaflet-control-attribution{background:#fff;background:#fffc;margin:0}.leaflet-control-attribution,.leaflet-control-scale-line{padding:0 5px;color:#333;line-height:1.4}.leaflet-control-attribution a{text-decoration:none}.leaflet-control-attribution a:hover,.leaflet-control-attribution a:focus{text-decoration:underline}.leaflet-attribution-flag{display:inline!important;vertical-align:baseline!important;width:1em;height:.6669em}.leaflet-left .leaflet-control-scale{margin-left:5px}.leaflet-bottom .leaflet-control-scale{margin-bottom:5px}.leaflet-control-scale-line{border:2px solid #777;border-top:none;line-height:1.1;padding:2px 5px 1px;white-space:nowrap;-moz-box-sizing:border-box;box-sizing:border-box;background:#fffc;text-shadow:1px 1px #fff}.leaflet-control-scale-line:not(:first-child){border-top:2px solid #777;border-bottom:none;margin-top:-2px}.leaflet-control-scale-line:not(:first-child):not(:last-child){border-bottom:2px solid #777}.leaflet-touch .leaflet-control-attribution,.leaflet-touch .leaflet-control-layers,.leaflet-touch .leaflet-bar{box-shadow:none}.leaflet-touch .leaflet-control-layers,.leaflet-touch .leaflet-bar{border:2px solid rgba(0,0,0,.2);background-clip:padding-box}.leaflet-popup{position:absolute;text-align:center;margin-bottom:20px}.leaflet-popup-content-wrapper{padding:1px;text-align:left;border-radius:12px}.leaflet-popup-content{margin:13px 24px 13px 20px;line-height:1.3;font-size:13px;font-size:1.08333em;min-height:1px}.leaflet-popup-content p{margin:1.3em 0}.leaflet-popup-tip-container{width:40px;height:20px;position:absolute;left:50%;margin-top:-1px;margin-left:-20px;overflow:hidden;pointer-events:none}.leaflet-popup-tip{width:17px;height:17px;padding:1px;margin:-10px auto 0;pointer-events:auto;-webkit-transform:rotate(45deg);-moz-transform:rotate(45deg);-ms-transform:rotate(45deg);transform:rotate(45deg)}.leaflet-popup-content-wrapper,.leaflet-popup-tip{background:#fff;color:#333;box-shadow:0 3px 14px #0006}.leaflet-container a.leaflet-popup-close-button{position:absolute;top:0;right:0;border:none;text-align:center;width:24px;height:24px;font:16px/24px Tahoma,Verdana,sans-serif;color:#757575;text-decoration:none;background:transparent}.leaflet-container a.leaflet-popup-close-button:hover,.leaflet-container a.leaflet-popup-close-button:focus{color:#585858}.leaflet-popup-scrolled{overflow:auto}.leaflet-oldie .leaflet-popup-content-wrapper{-ms-zoom:1}.leaflet-oldie .leaflet-popup-tip{width:24px;margin:0 auto;-ms-filter:"progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=0.70710678, M21=-0.70710678, M22=0.70710678)";filter:progid:DXImageTransform.Microsoft.Matrix(M11=.70710678,M12=.70710678,M21=-.70710678,M22=.70710678)}.leaflet-oldie .leaflet-control-zoom,.leaflet-oldie .leaflet-control-layers,.leaflet-oldie .leaflet-popup-content-wrapper,.leaflet-oldie .leaflet-popup-tip{border:1px solid #999}.leaflet-div-icon{background:#fff;border:1px solid #666}.leaflet-tooltip{position:absolute;padding:6px;background-color:#fff;border:1px solid #fff;border-radius:3px;color:#222;white-space:nowrap;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;pointer-events:none;box-shadow:0 1px 3px #0006}.leaflet-tooltip.leaflet-interactive{cursor:pointer;pointer-events:auto}.leaflet-tooltip-top:before,.leaflet-tooltip-bottom:before,.leaflet-tooltip-left:before,.leaflet-tooltip-right:before{position:absolute;pointer-events:none;border:6px solid transparent;background:transparent;content:""}.leaflet-tooltip-bottom{margin-top:6px}.leaflet-tooltip-top{margin-top:-6px}.leaflet-tooltip-bottom:before,.leaflet-tooltip-top:before{left:50%;margin-left:-6px}.leaflet-tooltip-top:before{bottom:0;margin-bottom:-12px;border-top-color:#fff}.leaflet-tooltip-bottom:before{top:0;margin-top:-12px;margin-left:-6px;border-bottom-color:#fff}.leaflet-tooltip-left{margin-left:-6px}.leaflet-tooltip-right{margin-left:6px}.leaflet-tooltip-left:before,.leaflet-tooltip-right:before{top:50%;margin-top:-6px}.leaflet-tooltip-left:before{right:0;margin-right:-12px;border-left-color:#fff}.leaflet-tooltip-right:before{left:0;margin-left:-12px;border-right-color:#fff}@media print{.leaflet-control{-webkit-print-color-adjust:exact;print-color-adjust:exact}}:root{--ink: #10161c;--ink-2: #182028;--ink-3: #222c36;--parchment: #f4efe4;--muted: #b7aea0;--line: rgba(244, 239, 228, .12);--teal: #3cb8c4;--copper: #e09a45;--moss: #7cb07c;--danger: #c45c5c;--radius: 14px;--font: "Source Sans 3", "Segoe UI", sans-serif;--display: "Fraunces", Georgia, serif}*{box-sizing:border-box}html,body,#root{height:100%;height:100dvh;margin:0;overflow:hidden}body{background:var(--ink);color:var(--parchment);font-family:var(--font);font-size:15px;-webkit-tap-highlight-color:transparent;touch-action:manipulation}button,input,select,textarea{font:inherit;color:inherit}button{cursor:pointer}button,a,input,select,label{touch-action:manipulation}.app{height:100%;display:grid;grid-template-rows:auto auto 1fr;background:radial-gradient(1200px 600px at 10% -10%,rgba(60,184,196,.08),transparent 50%),radial-gradient(900px 500px at 110% 0%,rgba(224,154,69,.07),transparent 46%),var(--ink)}.topbar{display:flex;gap:12px;align-items:center;padding:12px 16px 8px;border-bottom:1px solid var(--line)}.brand{display:flex;flex-direction:column;min-width:180px}.brand strong{font-family:var(--display);font-size:22px;letter-spacing:-.02em;font-weight:700}.brand span{color:var(--muted);font-size:12px}.search-wrap{position:relative;flex:1;min-width:0}.search-wrap input{width:100%;background:var(--ink-2);border:1px solid var(--line);border-radius:999px;padding:10px 16px 10px 40px;outline:none}.search-wrap input:focus{border-color:var(--teal)}.search-icon{position:absolute;left:14px;top:50%;transform:translateY(-50%);color:var(--muted)}.suggest{position:absolute;z-index:20;left:0;right:0;top:calc(100% + 6px);background:var(--ink-2);border:1px solid var(--line);border-radius:var(--radius);max-height:360px;overflow:auto;box-shadow:0 18px 40px #00000059}.suggest button{display:flex;width:100%;text-align:left;background:none;border:0;padding:10px 14px;gap:10px;align-items:baseline}.suggest button:hover,.suggest button.active{background:var(--ink-3)}.suggest .term{font-family:var(--display);font-size:17px}.suggest .alias-from{opacity:.72}.suggest .alias-arrow{opacity:.45;font-family:var(--sans);font-size:13px}.suggest .meta{color:var(--muted);font-size:12px;margin-left:auto}.toolbar{display:flex;gap:8px;align-items:center;padding:8px 16px;flex-wrap:wrap;border-bottom:1px solid var(--line)}.seg{display:flex;background:var(--ink-2);border-radius:999px;padding:3px;border:1px solid var(--line)}.seg button,.chip,.ghost{background:transparent;border:0;color:var(--muted);padding:6px 12px;border-radius:999px}.seg button.on,.chip{background:var(--ink-3);color:var(--parchment)}.chip{border:1px solid var(--line);display:inline-flex;gap:6px;align-items:center;font-size:12px}.chip b{color:var(--teal);font-weight:600}.ghost{border:1px solid var(--line)}.ghost.primary{background:var(--teal);color:var(--ink);border-color:transparent;font-weight:600}.workspace{display:grid;grid-template-columns:320px 1fr 320px;min-height:0;position:relative;overflow:hidden}.panel{background:#182028b8;border-right:1px solid var(--line);overflow:auto;padding:14px;-webkit-overflow-scrolling:touch}.panel.right{border-right:0;border-left:1px solid var(--line)}.stage{position:relative;min-width:0;min-height:0;overflow:hidden;overscroll-behavior:none}.stage canvas,.stage .map,.stage .table-wrap,.stage .stats,.stage .game{position:absolute;inset:0;width:100%;height:100%}.viz-canvas{touch-action:none;display:block;cursor:grab;-webkit-user-select:none;user-select:none}.sheet-grab,.sheet-backdrop{display:none}.tabs{display:flex;gap:6px;margin-bottom:12px}.tabs button{flex:1;background:var(--ink-2);border:1px solid var(--line);border-radius:10px;padding:7px;color:var(--muted)}.tabs button.on{color:var(--parchment);border-color:var(--teal)}label.field{display:block;font-size:12px;color:var(--muted);margin:10px 0 4px}.row{display:flex;gap:8px;align-items:center}select,.field-input{width:100%;background:var(--ink);border:1px solid var(--line);border-radius:10px;padding:8px 10px}.checklist{max-height:140px;overflow:auto;border:1px solid var(--line);border-radius:10px;background:var(--ink)}.checklist label{display:flex;gap:8px;padding:5px 8px;font-size:13px;color:var(--parchment)}.rel-grid{display:grid;grid-template-columns:1fr 1fr;gap:4px}.rel-grid label{display:flex;gap:6px;font-size:13px;align-items:center}.dot{width:8px;height:8px;border-radius:50%;display:inline-block}.legend{position:absolute;left:12px;bottom:12px;background:#10161cd1;border:1px solid var(--line);border-radius:12px;padding:8px 10px;font-size:12px;display:flex;flex-wrap:wrap;gap:8px 12px;max-width:min(520px,calc(100% - 24px))}.status-line{position:absolute;right:12px;bottom:12px;color:var(--muted);font-size:12px;background:#10161cb8;padding:6px 10px;border-radius:999px}.table-wrap{overflow:auto;padding:8px 12px 48px}table{width:100%;border-collapse:collapse;font-size:13px}th,td{text-align:left;padding:8px;border-bottom:1px solid var(--line)}th{color:var(--muted);font-weight:600;position:sticky;top:0;background:var(--ink)}tr:hover td{background:var(--ink-3);cursor:pointer}.stats{overflow:auto;padding:18px}.bars{display:grid;gap:6px}.bar-row{display:grid;grid-template-columns:140px 1fr 40px;gap:8px;align-items:center;font-size:13px}.bar{height:8px;background:var(--ink-3);border-radius:99px;overflow:hidden}.bar>i{display:block;height:100%;background:var(--teal)}.inspector h2{font-family:var(--display);margin:0 0 4px;font-size:28px}.inspector-def{margin:12px 0 4px}.inspector-def h3{margin:0 0 6px;font-size:12px;letter-spacing:.04em;text-transform:uppercase;color:var(--muted);font-weight:600}.kv{display:grid;grid-template-columns:110px 1fr;gap:4px 8px;font-size:13px;margin:12px 0}.kv dt{color:var(--muted)}.path-list{display:flex;flex-direction:column;gap:6px}.path-list button{background:var(--ink);border:1px solid var(--line);border-radius:10px;padding:8px;text-align:left}.formation-list{display:flex;flex-direction:column;gap:10px;margin:0 0 12px}.formation-meta{font-size:12px;letter-spacing:.04em;text-transform:uppercase;color:var(--muted);margin-bottom:4px}.formation-parts{display:flex;flex-wrap:wrap;align-items:baseline;gap:2px 0}.formation-plus{color:var(--muted);padding:0 4px}.formation-part{background:transparent;border:0;border-bottom:1px solid color-mix(in srgb,var(--teal) 55%,transparent);border-radius:0;padding:2px 2px 1px;text-align:left;font-family:var(--display);font-size:18px;line-height:1.2}.formation-part small{display:block;font-family:var(--font);font-size:11px;color:var(--muted);font-weight:500}.formation-part:hover{color:var(--teal)}.cognate-list{display:flex;flex-direction:column;gap:12px;margin:0 0 12px}.cognate-set{display:flex;flex-direction:column;gap:6px}.cognate-meta{font-size:12px;color:var(--muted);letter-spacing:.02em}.cognate-words{display:flex;flex-wrap:wrap;gap:6px;align-items:center}.cognate-word{display:inline-flex;flex-direction:column;align-items:flex-start;gap:1px;padding:4px 8px;border:1px solid color-mix(in srgb,#c56b9b 45%,transparent);background:color-mix(in srgb,#c56b9b 12%,transparent);color:var(--text);font:inherit;font-size:13px;line-height:1.2;cursor:pointer;text-align:left}.cognate-word.static{cursor:default;opacity:.85;border-color:color-mix(in srgb,var(--muted) 35%,transparent);background:transparent}.cognate-word.on,.cognate-word:hover{border-color:#c56b9b;color:#f4efe4}.cognate-word small{font-size:10px;color:var(--muted);max-width:140px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.cognate-more{font-size:12px;color:var(--muted)}.sheet{display:none}.examples{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:8px;padding:16px}.examples button{background:var(--ink-2);border:1px solid var(--line);border-radius:12px;padding:12px;text-align:left}.examples .t{font-family:var(--display);font-size:18px;display:block}.examples .b{color:var(--muted);font-size:12px}.qr img{width:180px;height:180px;background:#fff;padding:8px;border-radius:8px}.modal-root{position:fixed;inset:0;z-index:80;display:grid;place-items:center;padding:16px}.modal-backdrop{position:absolute;inset:0;border:0;padding:0;background:#060a0e9e;cursor:pointer}.modal-dialog{position:relative;z-index:1;width:min(560px,100%);max-height:min(86dvh,820px);display:flex;flex-direction:column;background:radial-gradient(700px 240px at 0% 0%,rgba(60,184,196,.12),transparent 55%),var(--ink-2);border:1px solid var(--line);border-radius:18px;box-shadow:0 24px 60px #00000073;overflow:hidden}.modal-head{display:flex;justify-content:space-between;gap:12px;align-items:flex-start;padding:16px 16px 10px;border-bottom:1px solid var(--line)}.modal-head h2{font-family:var(--display);margin:0;font-size:28px;line-height:1.1}.modal-head p{margin:4px 0 0;color:var(--muted);font-size:13px}.modal-body{overflow:auto;-webkit-overflow-scrolling:touch;padding:8px 16px 16px;flex:1;min-height:0}.modal-body section{margin-top:14px}.modal-body h3{margin:0 0 6px;font-size:12px;letter-spacing:.04em;text-transform:uppercase;color:var(--muted);font-weight:600}.modal-muted{color:var(--muted);font-size:13px;margin:0}.modal-muted a{color:var(--teal)}.modal-senses{display:grid;gap:10px}.modal-pos{font-size:12px;color:var(--copper);font-style:italic;margin-bottom:2px}.modal-sense ol{margin:0;padding-left:18px;display:grid;gap:4px}.modal-sense li{font-size:14px;line-height:1.35}.modal-chips{display:flex;flex-wrap:wrap;gap:6px;margin:8px 0 0}.modal-foot{display:flex;flex-wrap:wrap;gap:8px;padding:12px 16px 16px;border-top:1px solid var(--line)}.modal-foot .ghost,.modal-foot a.ghost{text-decoration:none;display:inline-flex;align-items:center;min-height:40px}@media(max-width:840px){.workspace{grid-template-columns:1fr}.panel{display:none}.sheet-backdrop{display:block;position:absolute;inset:0;z-index:25;border:0;background:#00000073;padding:0}.panel.open-sheet{display:flex;flex-direction:column;position:absolute;left:0;right:0;bottom:0;z-index:30;height:min(78dvh,640px);max-height:calc(100% - 12px);border-right:0;border-left:0;border-top:1px solid var(--line);border-radius:18px 18px 0 0;background:var(--ink-2);padding:0 14px 18px;overflow:hidden;box-shadow:0 -12px 40px #00000059}.sheet-body{overflow:auto;-webkit-overflow-scrolling:touch;flex:1;min-height:0}.sheet-grab{display:grid;grid-template-columns:64px 1fr auto;align-items:center;gap:8px;padding:10px 0 8px;position:sticky;top:0;background:var(--ink-2);z-index:1}.sheet-grab>span{width:42px;height:4px;border-radius:99px;background:#f4efe447;justify-self:start;margin-left:10px}.sheet-grab strong{font-size:14px;font-weight:600}.sheet-close{padding:8px 12px;min-height:40px}.brand{min-width:0}.brand span{display:none}.brand strong{font-size:18px}.topbar{padding:10px;gap:8px}.toolbar{padding:8px 10px;gap:6px;flex-wrap:nowrap;overflow-x:auto;-webkit-overflow-scrolling:touch;scrollbar-width:none}.toolbar::-webkit-scrollbar{display:none}.seg{flex:0 0 auto}.seg button{padding:8px 10px;min-height:36px}.filters-btn{flex:0 0 auto;min-height:40px}.legend{display:none}.status-line{left:12px;right:12px;bottom:10px;text-align:center}.search-wrap input{padding:12px 16px 12px 40px;font-size:16px}.suggest{max-height:min(50dvh,320px)}.suggest button{padding:12px 14px;min-height:44px}.checklist{max-height:180px}.checklist label{padding:10px 8px;min-height:40px}}.game{overflow:auto;padding:28px 28px 48px;background:radial-gradient(900px 420px at 20% 0%,rgba(60,184,196,.1),transparent 55%),radial-gradient(700px 380px at 90% 10%,rgba(224,154,69,.08),transparent 50%),var(--ink)}.game-hero{max-width:720px;margin-bottom:22px}.game-kicker{margin:0 0 6px;color:var(--teal);font-size:12px;letter-spacing:.08em;text-transform:uppercase}.game-hero h2{font-family:var(--display);font-size:clamp(28px,4vw,40px);margin:0 0 8px;letter-spacing:-.02em}.game-hero p{color:var(--muted);margin:0 0 14px;max-width:54ch}.game-scoreline{display:flex;flex-wrap:wrap;gap:14px;align-items:center;color:var(--muted)}.game-scoreline b{color:var(--parchment)}.game-status{color:var(--muted)}.game-status.err{color:var(--danger)}.game-pair{display:grid;grid-template-columns:1fr auto 1fr;gap:16px;align-items:stretch;max-width:860px;margin-bottom:18px}.game-word{background:var(--ink-2);border:1px solid var(--line);border-radius:var(--radius);padding:18px 20px;display:flex;flex-direction:column;gap:6px}.game-lang{color:var(--teal);font-size:12px;text-transform:uppercase;letter-spacing:.06em}.game-word strong{font-family:var(--display);font-size:28px;letter-spacing:-.02em}.game-word em{font-style:normal;color:var(--muted);font-size:14px;line-height:1.35}.game-link{width:36px;display:flex;align-items:center;justify-content:center}.game-link span{display:block;width:100%;height:2px;background:linear-gradient(90deg,var(--teal),var(--copper));border-radius:2px}.game-panel{max-width:860px;background:var(--ink-2);border:1px solid var(--line);border-radius:var(--radius);padding:18px 20px 20px;margin-bottom:16px}.game-panel h3{font-family:var(--display);margin:0 0 6px;font-size:20px}.game-choices,.game-pool,.game-actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:12px}.game-choices button,.game-pool button{background:var(--ink-3);border:1px solid var(--line);border-radius:999px;padding:8px 14px}.game-choices button.on,.game-pool button:hover,.game-choices button:hover{border-color:var(--teal);color:var(--teal)}.game-actions{margin-top:16px}.game-actions .primary{background:var(--teal);color:var(--ink);border:none;border-radius:999px;padding:10px 16px;font-weight:600}.game-actions .primary:disabled{opacity:.4}.game-actions .ghost,.game-scoreline .ghost{background:transparent;border:1px solid var(--line);border-radius:999px;padding:8px 14px;color:var(--muted)}.game-chain{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin-top:14px}.game-anchor{font-family:var(--display);font-size:18px}.game-slot{min-width:88px;min-height:40px;border:1px dashed rgba(244,239,228,.28);background:#0000002e;border-radius:10px;color:var(--muted)}.game-slot.filled{border-style:solid;border-color:var(--copper);color:var(--parchment);background:var(--ink-3)}.game-paths{display:grid;grid-template-columns:1fr 1fr;gap:18px;margin-top:12px}.game-paths ol{margin:0;padding-left:18px}.game-paths li{margin-bottom:8px;display:flex;flex-direction:column;gap:2px}.game-paths span{color:var(--muted);font-size:13px}.game-lca{margin-top:14px;color:var(--muted)}.game-lca b{color:var(--copper)}.game-result{color:var(--teal);margin:0 0 8px}.game-custom{display:grid;grid-template-columns:1fr 1fr auto;gap:10px;align-items:start;margin-top:10px}.game-custom input{width:100%;background:var(--ink-3);border:1px solid var(--line);border-radius:10px;padding:10px 12px}.game-mini-suggest{display:flex;flex-direction:column;gap:4px;margin-top:6px}.game-mini-suggest button{text-align:left;background:var(--ink-3);border:1px solid var(--line);border-radius:8px;padding:6px 10px;font-size:13px}@media(max-width:840px){.game{padding:16px 14px 40px}.game-pair{grid-template-columns:1fr}.game-link{display:none}.game-paths,.game-custom{grid-template-columns:1fr}}
|
frontend/dist/index.html
CHANGED
|
@@ -9,8 +9,8 @@
|
|
| 9 |
<link rel="icon" href="/icon.svg" type="image/svg+xml" />
|
| 10 |
<link rel="apple-touch-icon" href="/icon.svg" />
|
| 11 |
<title>Reverse Etymology Atlas</title>
|
| 12 |
-
<script type="module" crossorigin src="/assets/index-
|
| 13 |
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
| 14 |
</head>
|
| 15 |
<body>
|
| 16 |
<div id="root"></div>
|
|
|
|
| 9 |
<link rel="icon" href="/icon.svg" type="image/svg+xml" />
|
| 10 |
<link rel="apple-touch-icon" href="/icon.svg" />
|
| 11 |
<title>Reverse Etymology Atlas</title>
|
| 12 |
+
<script type="module" crossorigin src="/assets/index-CSxQdCV8.js"></script>
|
| 13 |
+
<link rel="stylesheet" crossorigin href="/assets/index-Dr1iPrLq.css">
|
| 14 |
</head>
|
| 15 |
<body>
|
| 16 |
<div id="root"></div>
|