@mailwoman/resolver 9.4.0 → 10.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/lib/admin/coherence-passes.ts +21 -161
- package/lib/admin/containment.ts +12 -30
- package/lib/admin/jp-municipality.ts +20 -13
- package/lib/admin/winner.ts +30 -62
- package/lib/backend-capabilities.ts +25 -24
- package/lib/bare-toponym-race.ts +73 -39
- package/lib/decorate-node.ts +17 -41
- package/lib/fold-name.ts +5 -18
- package/lib/index.ts +5 -9
- package/lib/plausibility.ts +37 -63
- package/lib/postcode/country-coherence.ts +64 -284
- package/lib/postcode/prefix.ts +20 -84
- package/lib/postcode/shape-coherence.ts +23 -113
- package/lib/remote-resolver.ts +32 -29
- package/lib/rerank.ts +34 -50
- package/lib/resolve/passes.ts +145 -148
- package/lib/resolve.ts +726 -0
- package/lib/span-rescore.ts +215 -172
- package/lib/street/evidence.ts +65 -73
- package/lib/street/tier.ts +33 -175
- package/lib/toponym-prior.ts +53 -179
- package/out/admin/coherence-passes.d.ts +18 -69
- package/out/admin/coherence-passes.d.ts.map +1 -1
- package/out/admin/coherence-passes.js +19 -161
- package/out/admin/coherence-passes.js.map +1 -1
- package/out/admin/containment.d.ts +11 -29
- package/out/admin/containment.d.ts.map +1 -1
- package/out/admin/containment.js +12 -30
- package/out/admin/containment.js.map +1 -1
- package/out/admin/jp-municipality.d.ts +20 -13
- package/out/admin/jp-municipality.d.ts.map +1 -1
- package/out/admin/jp-municipality.js +18 -12
- package/out/admin/jp-municipality.js.map +1 -1
- package/out/admin/winner.d.ts +30 -62
- package/out/admin/winner.d.ts.map +1 -1
- package/out/admin/winner.js +18 -51
- package/out/admin/winner.js.map +1 -1
- package/out/{admin/index.d.ts → admin.d.ts} +1 -1
- package/out/admin.d.ts.map +1 -0
- package/out/{admin/index.js → admin.js} +1 -1
- package/out/admin.js.map +1 -0
- package/out/backend-capabilities.d.ts +18 -19
- package/out/backend-capabilities.d.ts.map +1 -1
- package/out/backend-capabilities.js +25 -24
- package/out/backend-capabilities.js.map +1 -1
- package/out/bare-toponym-race.d.ts +56 -28
- package/out/bare-toponym-race.d.ts.map +1 -1
- package/out/bare-toponym-race.js +69 -37
- package/out/bare-toponym-race.js.map +1 -1
- package/out/decorate-node.d.ts +6 -8
- package/out/decorate-node.d.ts.map +1 -1
- package/out/decorate-node.js +17 -41
- package/out/decorate-node.js.map +1 -1
- package/out/fold-name.d.ts +5 -18
- package/out/fold-name.d.ts.map +1 -1
- package/out/fold-name.js +5 -18
- package/out/fold-name.js.map +1 -1
- package/out/index.d.ts +5 -6
- package/out/index.d.ts.map +1 -1
- package/out/index.js +5 -8
- package/out/index.js.map +1 -1
- package/out/plausibility.d.ts +29 -58
- package/out/plausibility.d.ts.map +1 -1
- package/out/plausibility.js +16 -49
- package/out/plausibility.js.map +1 -1
- package/out/postcode/country-coherence.d.ts +48 -162
- package/out/postcode/country-coherence.d.ts.map +1 -1
- package/out/postcode/country-coherence.js +19 -252
- package/out/postcode/country-coherence.js.map +1 -1
- package/out/postcode/prefix.d.ts +17 -68
- package/out/postcode/prefix.d.ts.map +1 -1
- package/out/postcode/prefix.js +8 -77
- package/out/postcode/prefix.js.map +1 -1
- package/out/postcode/shape-coherence.d.ts +17 -84
- package/out/postcode/shape-coherence.d.ts.map +1 -1
- package/out/postcode/shape-coherence.js +9 -105
- package/out/postcode/shape-coherence.js.map +1 -1
- package/out/{postcode/index.d.ts → postcode.d.ts} +1 -1
- package/out/postcode.d.ts.map +1 -0
- package/out/{postcode/index.js → postcode.js} +1 -1
- package/out/postcode.js.map +1 -0
- package/out/remote-resolver.d.ts +27 -28
- package/out/remote-resolver.d.ts.map +1 -1
- package/out/remote-resolver.js +9 -19
- package/out/remote-resolver.js.map +1 -1
- package/out/rerank.d.ts +28 -45
- package/out/rerank.d.ts.map +1 -1
- package/out/rerank.js +13 -38
- package/out/rerank.js.map +1 -1
- package/out/resolve/passes.d.ts +97 -86
- package/out/resolve/passes.d.ts.map +1 -1
- package/out/resolve/passes.js +40 -105
- package/out/resolve/passes.js.map +1 -1
- package/out/resolve.d.ts +15 -0
- package/out/resolve.d.ts.map +1 -0
- package/out/resolve.js +543 -0
- package/out/resolve.js.map +1 -0
- package/out/span-rescore.d.ts +51 -64
- package/out/span-rescore.d.ts.map +1 -1
- package/out/span-rescore.js +132 -130
- package/out/span-rescore.js.map +1 -1
- package/out/street/evidence.d.ts +56 -61
- package/out/street/evidence.d.ts.map +1 -1
- package/out/street/evidence.js +22 -46
- package/out/street/evidence.js.map +1 -1
- package/out/street/tier.d.ts +17 -29
- package/out/street/tier.d.ts.map +1 -1
- package/out/street/tier.js +27 -175
- package/out/street/tier.js.map +1 -1
- package/out/{street/index.d.ts → street.d.ts} +1 -1
- package/out/street.d.ts.map +1 -0
- package/out/{street/index.js → street.js} +1 -1
- package/out/street.js.map +1 -0
- package/out/toponym-prior.d.ts +21 -109
- package/out/toponym-prior.d.ts.map +1 -1
- package/out/toponym-prior.js +41 -170
- package/out/toponym-prior.js.map +1 -1
- package/package.json +44 -147
- package/lib/resolve/index.ts +0 -995
- package/out/admin/index.d.ts.map +0 -1
- package/out/admin/index.js.map +0 -1
- package/out/postcode/index.d.ts.map +0 -1
- package/out/postcode/index.js.map +0 -1
- package/out/resolve/index.d.ts +0 -20
- package/out/resolve/index.d.ts.map +0 -1
- package/out/resolve/index.js +0 -807
- package/out/resolve/index.js.map +0 -1
- package/out/street/index.d.ts.map +0 -1
- package/out/street/index.js.map +0 -1
- package/vitest.config.ts +0 -38
- /package/lib/{admin/index.ts → admin.ts} +0 -0
- /package/lib/{postcode/index.ts → postcode.ts} +0 -0
- /package/lib/{street/index.ts → street.ts} +0 -0
package/lib/toponym-prior.ts
CHANGED
|
@@ -2,139 +2,38 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* #17 bare city-name disambiguation — two SOFT ranking keys for the bare-toponym class.
|
|
7
|
-
*
|
|
8
|
-
* A bare city name is the one query shape where the resolver has no geography to reason with: no
|
|
9
|
-
* postcode to anchor against, no region to scope by, no country the address itself named. All that
|
|
10
|
-
* is left is a prior over which same-named place a person typing that word alone probably meant.
|
|
11
|
-
* The shipped prior is POPULATION, and population is measurably the wrong prior for this class —
|
|
12
|
-
* the panel run of 2026-08-10 caught it four times over:
|
|
13
|
-
*
|
|
14
|
-
* | query | population winner | gold | miss |
|
|
15
|
-
* | ------- | -------------------- | --------------------- | -------- |
|
|
16
|
-
* | Whitby | Whitby ON (128,377) | Whitby, N Yorks (13,130) | 5,508 km |
|
|
17
|
-
* | Warwick | Warwick RI (82,999) | Warwick, Warks (32,719) | 5,211 km |
|
|
18
|
-
* | Epping | Epping VIC (32,395) | Epping, Essex (12,547) | 16,874 km |
|
|
19
|
-
* | Windsor | Windsor ON (217,188) | Windsor, Berks (26,885) | 6,007 km |
|
|
20
|
-
*
|
|
21
|
-
* Every one of those is a place people know for something other than its size, and the gazetteer
|
|
22
|
-
* already measures that: `admin-global-priority-importance.db` ranks all four the RIGHT way round
|
|
23
|
-
* (Whitby GB 0.5496 over CA 0.5089; Windsor GB 0.5648 over CA 0.5607 — a 0.004 margin population
|
|
24
|
-
* inverts by a factor of eight). What it measures is a BLENDED global toponym prior
|
|
25
|
-
* (`ResolvedPlace.importance`): the concordance's encyclopedia-derived channel where a concordance
|
|
26
|
-
* matched, a population-derived proxy everywhere else — the one scale on which every bearer of a
|
|
27
|
-
* name is scored comparably, which is the precondition for comparing them at all.
|
|
28
|
-
* {@link rankByImportance} consumes it. (The STRICT encyclopedia-evidence channel keeps its own
|
|
29
|
-
* reserved slot, `ResolvedPlace.encyclopedic`, which no ranking key reads and no shipped artifact
|
|
30
|
-
* yet populates — see `core/resolver/types.ts`.)
|
|
31
|
-
*
|
|
32
|
-
* {@link rankByCountryPrior} covers the other half of the class — the query where a country IS
|
|
33
|
-
* known, but only because a locale said so. See `span-rescore.ts` for where that one applies.
|
|
34
|
-
*
|
|
35
|
-
* Both obey the same three house rules, and neither is a check:
|
|
36
|
-
*
|
|
37
|
-
* 1. **Tier-safe.** `exactMatch` stays the primary key. A soft prior re-orders WITHIN a tier; it never
|
|
38
|
-
* promotes a partial match over an exact one.
|
|
39
|
-
* 2. **Positive evidence only.** An absent score is unmeasured, not zero (the meaning-of-zero rule), so an
|
|
40
|
-
* unscored candidate is never moved BY the signal and never penalized FOR lacking it — it keeps the
|
|
41
|
-
* rank population gave it while the scored rows reorder among themselves. On a candidate.db built
|
|
42
|
-
* before the #28 `importance` column, nothing is scored, so {@link rankByImportance} is
|
|
43
|
-
* byte-stable by construction.
|
|
44
|
-
* 3. **Stable.** Equal keys keep their incoming order, so the backend's own ranking survives underneath. That order
|
|
45
|
-
* carries decisions only the backend can make — the candidate backend's seat tiebreak
|
|
46
|
-
* (`resolver-wof-sqlite/primary-preference.ts`) reaches an end-to-end answer solely through this stability
|
|
47
|
-
* (#1729), so equal-key stability here is required, not cosmetic.
|
|
48
5
|
*/
|
|
49
6
|
|
|
50
7
|
import type { ResolvedPlace } from "@mailwoman/core/resolver"
|
|
51
8
|
|
|
52
9
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
10
|
+
* The default bonus, in log10-population units, that {@link rankByCountryPrior}
|
|
11
|
+
* gives a candidate in the locale country.
|
|
55
12
|
*
|
|
56
|
-
*
|
|
57
|
-
* postcode-anchor country pin, and this is the same quantity from a weaker source, so the two should not disagree about
|
|
58
|
-
* what a country signal is worth. Calibrated against the live board (2026-08-10, shipped `candidate.db`), it moves
|
|
59
|
-
* exactly the queries where the locale is implausible and leaves the rest alone:
|
|
60
|
-
*
|
|
61
|
-
* - `Zürich` en-US — Zurich KS 1.91 + 2 = 3.91 loses to Zürich CH 5.65. **Flips** (was 8,043 km off).
|
|
62
|
-
* - `Berlin` en-US — Berlin CT 4.30 + 2 = 6.30 loses to Berlin DE 6.56. **Flips.**
|
|
63
|
-
* - `Manchester` en-US — Manchester NH 5.06 + 2 = 7.06 beats Manchester GB 5.74. **Held.**
|
|
64
|
-
* - `Springfield` en-US — every bearer is US, so the bonus is uniform. **Held.**
|
|
65
|
-
* - `Moscow` en-US — Moscow ID 4.42 + 2 = 6.42 beats Москва 6.10. **Held.**
|
|
66
|
-
* - `Fulda` en-US — Fulda MN 3.13 + 2 = 5.13 beats Fulda DE 4.84. **Held.**
|
|
13
|
+
* A weight of 2 lets an in-country place be up to 100 times smaller and still win.
|
|
67
14
|
*/
|
|
68
15
|
export const DEFAULT_COUNTRY_PRIOR_WEIGHT = 2
|
|
69
16
|
|
|
70
|
-
/**
|
|
71
|
-
* Importance margin below which two SAME-COUNTRY bearers are a tie, and the tie falls back to referential (size) order.
|
|
72
|
-
* Ratified 2026-08-11 (the five bare-query flip decisions): bare `Springfield` must stay on the referential answer —
|
|
73
|
-
* the live chain is IL 0.612605 → MA 0.611142 → MO 0.596195 (adjacent gaps 0.0015 and 0.0149, full span 0.0164), so the
|
|
74
|
-
* band must cover at least the 0.0149 adjacent gap for the trio to chain into one cluster.
|
|
75
|
-
*
|
|
76
|
-
* The band never compares across countries, and that scope is forced by decided rows, not preference: Windsor's
|
|
77
|
-
* accepted flip (GB 0.564842 over CA 0.560687) sits at a 0.0042 gap — inside ANY band that covers Springfield. The two
|
|
78
|
-
* decisions are only co-satisfiable if the band binds same-country pairs alone. That is also what the §2 referential
|
|
79
|
-
* policy (ROAD_TO_V9) says: within a country the geocoder ranks referentially; the blended prior's job is the
|
|
80
|
-
* cross-country question — which country's bearer a bare query meant.
|
|
81
|
-
*/
|
|
82
17
|
const SAME_COUNTRY_IMPORTANCE_TIE_BAND = 0.02
|
|
83
18
|
|
|
84
|
-
/**
|
|
85
|
-
* The fields a ranking key reads. Structural rather than `ResolvedPlace` so the backend's own `PlaceCandidate` (a
|
|
86
|
-
* structural twin) can be ranked without a cast.
|
|
87
|
-
*/
|
|
88
19
|
type Rankable = Pick<ResolvedPlace, "score"> &
|
|
89
|
-
Partial<Pick<ResolvedPlace, "country" | "exactMatch" | "importance" | "prominence">>
|
|
20
|
+
Partial<Pick<ResolvedPlace, "country" | "exactMatch" | "importance" | "population" | "prominence">>
|
|
90
21
|
|
|
91
|
-
/**
|
|
92
|
-
* Partition into (exact, rest), sort each half with `key` DESC, and re-join. The partition is what keeps a soft prior
|
|
93
|
-
* soft: it can only ever re-order candidates the backend already considers equally good matches. Backends that don't
|
|
94
|
-
* stamp `exactMatch` land every row in one tier, which is the correct degradation — the key then applies to the whole
|
|
95
|
-
* list.
|
|
96
|
-
*/
|
|
97
22
|
function rankWithinTier<T extends Rankable>(candidates: readonly T[], compare: (a: T, b: T) => number): T[] {
|
|
98
23
|
const exact: T[] = []
|
|
99
24
|
const rest: T[] = []
|
|
100
25
|
|
|
101
26
|
for (const c of candidates) {
|
|
102
|
-
// `exactMatch` is TRI-STATE: true / false / undefined (a backend path that stamps no flag —
|
|
103
|
-
// e.g. WOFSQLitePlaceLookup's postcode-area neighbours from #fetchLocalitiesByID). Only a
|
|
104
|
-
// stated TRUE earns the exact tier; undefined must not outrank a real fuzzy name match
|
|
105
|
-
// (the 2026-08-10 de.native_locality incident: 75 Saxon towns lost to nameless neighbours).
|
|
106
27
|
;(c.exactMatch === true ? exact : rest).push(c)
|
|
107
28
|
}
|
|
108
29
|
|
|
109
|
-
// `toSorted` is stable, so equal keys keep the backend's incoming order.
|
|
110
30
|
return [...exact.toSorted(compare), ...rest.toSorted(compare)]
|
|
111
31
|
}
|
|
112
32
|
|
|
113
|
-
/**
|
|
114
|
-
* Size, in the backend's own units — the candidate backend's `prominence` is log10(population + 1); a backend that
|
|
115
|
-
* computes no prominence falls back to its raw `score`.
|
|
116
|
-
*/
|
|
117
33
|
const size = (c: Rankable): number => c.prominence ?? c.score
|
|
118
34
|
|
|
119
|
-
/**
|
|
120
|
-
* A candidate the gazetteer actually scored. An absent value means "the score source never measured this place" OR
|
|
121
|
-
* "this artifact predates the column" OR "the join refused the row" — three different things, none of them zero.
|
|
122
|
-
*/
|
|
123
35
|
const measured = (c: Rankable): boolean => typeof c.importance === "number" && Number.isFinite(c.importance)
|
|
124
36
|
|
|
125
|
-
/**
|
|
126
|
-
* Reorder ONLY the measured candidates, and only among the positions they already occupy.
|
|
127
|
-
*
|
|
128
|
-
* This is what "positive evidence only" has to mean when coverage is partial, which it always is — measured on the
|
|
129
|
-
* shipped importance artifact, the four bare GB panel rows have 2/7, 8/10, 8/10 and 9/10 of their candidates scored. A
|
|
130
|
-
* blanket "abstain unless everything is measured" throws the signal away on all four; treating absent as 0 would let a
|
|
131
|
-
* scored hamlet leapfrog an unscored metropolis. Neither is right, and the resolution is that an unmeasured row simply
|
|
132
|
-
* does not participate: it holds the rank population gave it, and the scored rows permute among the slots they hold
|
|
133
|
-
* between them.
|
|
134
|
-
*
|
|
135
|
-
* So for `Whitby` — CA(0.5089), GB(0.5496), TC(—), then four unscored bearers — the swap is confined to slots 0 and 1,
|
|
136
|
-
* GB takes the lead, and TC never moves.
|
|
137
|
-
*/
|
|
138
37
|
function reorderMeasured<T extends Rankable>(tier: readonly T[], order: (measuredRows: T[]) => T[]): T[] {
|
|
139
38
|
const slots: number[] = []
|
|
140
39
|
|
|
@@ -155,18 +54,38 @@ function reorderMeasured<T extends Rankable>(tier: readonly T[], order: (measure
|
|
|
155
54
|
return out
|
|
156
55
|
}
|
|
157
56
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
57
|
+
const counted = (c: Rankable): boolean => typeof c.population === "number" && c.population > 0
|
|
58
|
+
|
|
59
|
+
function countedFirstWithinCountry<T extends Rankable>(rows: readonly T[]): T[] {
|
|
60
|
+
const out = [...rows]
|
|
61
|
+
const slotsByCountry = new Map<string, number[]>()
|
|
62
|
+
|
|
63
|
+
for (const [index, row] of out.entries()) {
|
|
64
|
+
const country = row.country?.toUpperCase()
|
|
65
|
+
|
|
66
|
+
if (!country) continue
|
|
67
|
+
|
|
68
|
+
const slots = slotsByCountry.get(country) ?? []
|
|
69
|
+
|
|
70
|
+
slots.push(index)
|
|
71
|
+
slotsByCountry.set(country, slots)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (const slots of slotsByCountry.values()) {
|
|
75
|
+
if (slots.length < 2) continue
|
|
76
|
+
|
|
77
|
+
const members = slots.map((slot) => out[slot]!)
|
|
78
|
+
const reordered = [...members.filter((row) => counted(row)), ...members.filter((row) => !counted(row))]
|
|
79
|
+
|
|
80
|
+
for (const [k, slot] of slots.entries()) {
|
|
81
|
+
out[slot] = reordered[k]!
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return out
|
|
86
|
+
}
|
|
87
|
+
|
|
167
88
|
function orderMeasuredByImportance<T extends Rankable>(rows: readonly T[]): T[] {
|
|
168
|
-
// Group by country in first-appearance order; a row without a country can never substantiate a
|
|
169
|
-
// same-country tie, so it stays a singleton.
|
|
170
89
|
const groups = new Map<string, { firstIndex: number; members: T[] }>()
|
|
171
90
|
const clusters: Array<{ firstIndex: number; members: T[] }> = []
|
|
172
91
|
|
|
@@ -214,42 +133,26 @@ function orderMeasuredByImportance<T extends Rankable>(rows: readonly T[]): T[]
|
|
|
214
133
|
|
|
215
134
|
keyed.sort((a, b) => b.key - a.key || size(b.members[0]!) - size(a.members[0]!) || a.firstIndex - b.firstIndex)
|
|
216
135
|
|
|
217
|
-
return keyed.flatMap((c) => c.members)
|
|
136
|
+
return countedFirstWithinCountry(keyed.flatMap((c) => c.members))
|
|
218
137
|
}
|
|
219
138
|
|
|
220
139
|
/**
|
|
221
|
-
*
|
|
140
|
+
* Reorders candidates by gazetteer `importance`, highest first, within the exact-match
|
|
141
|
+
* and partial-match tiers.
|
|
222
142
|
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* fewer than two candidates are scored.
|
|
227
|
-
*
|
|
228
|
-
* The producer is the candidate build's `importance` column (#28) — the BLENDED prior (the concordance's
|
|
229
|
-
* encyclopedia-derived channel clamped around a population-derived base — `place-importance-schema.ts`'s
|
|
230
|
-
* `blendImportance`; see `candidate-schema.ts` → `CandidateTable.importance` for why the strict channel is deliberately
|
|
231
|
-
* NOT what lands there). On an artifact predating the column, `importance` is `undefined` on every candidate the
|
|
232
|
-
* backend produces and the abstention below keeps the ranking byte-stable.
|
|
233
|
-
*
|
|
234
|
-
* Flip decisions, ratified 2026-08-11: bare `Moscow`→Москва, `Manchester`→GB, `Fulda`→DE, `Cambridge`→GB are ACCEPTED
|
|
235
|
-
* behavior — all cross-country contests, where this prior answers the question population cannot. Bare `Springfield`
|
|
236
|
-
* ABSTAINS to the referential answer via {@link SAME_COUNTRY_IMPORTANCE_TIE_BAND}; no candidate is dropped, so the
|
|
237
|
-
* runner-up survives as a declared alternative downstream.
|
|
143
|
+
* Candidates without an importance keep their positions.
|
|
144
|
+
* Same-country candidates whose importance differs by at most 0.02 are ordered by size
|
|
145
|
+
* instead, with populated places first within each country.
|
|
238
146
|
*/
|
|
239
147
|
export function rankByImportance<T extends Rankable>(candidates: readonly T[]): T[] {
|
|
240
148
|
if (candidates.length < 2) return [...candidates]
|
|
241
149
|
|
|
242
|
-
// Abstain entirely until at least one candidate carries a MEASURED score — the tier split
|
|
243
|
-
// below is only meaningful as a tiebreak among scored rows. Without this, wiring the consumer
|
|
244
|
-
// before the #28 producer reordered candidates on the exactMatch flag alone (meaning-of-zero:
|
|
245
|
-
// an absent score must not act as evidence).
|
|
246
150
|
if (!candidates.some(measured)) return [...candidates]
|
|
247
151
|
|
|
248
152
|
const exact: T[] = []
|
|
249
153
|
const rest: T[] = []
|
|
250
154
|
|
|
251
155
|
for (const c of candidates) {
|
|
252
|
-
// Tri-state exactMatch: only a stated TRUE earns the exact tier (see rankWithinTier).
|
|
253
156
|
;(c.exactMatch === true ? exact : rest).push(c)
|
|
254
157
|
}
|
|
255
158
|
|
|
@@ -257,15 +160,10 @@ export function rankByImportance<T extends Rankable>(candidates: readonly T[]):
|
|
|
257
160
|
}
|
|
258
161
|
|
|
259
162
|
/**
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
* Additive, never a filter — a far more prominent foreign namesake still wins (Zürich CH over Zurich KS) while a close
|
|
263
|
-
* contest goes to the locale (Manchester NH over Manchester GB). No-op without a `country`, so the un-scoped path stays
|
|
264
|
-
* byte-identical.
|
|
163
|
+
* Reorders candidates within each match tier by size, adding `weight` for candidates in `country`.
|
|
265
164
|
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
* effectively hard, `0` to disable.
|
|
165
|
+
* It returns the candidates unchanged when no country is given.
|
|
166
|
+
* The bonus is additive, so a much larger foreign place of the same name still wins.
|
|
269
167
|
*/
|
|
270
168
|
export function rankByCountryPrior<T extends Rankable>(
|
|
271
169
|
candidates: readonly T[],
|
|
@@ -281,49 +179,26 @@ export function rankByCountryPrior<T extends Rankable>(
|
|
|
281
179
|
}
|
|
282
180
|
|
|
283
181
|
/**
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
* verdict.
|
|
182
|
+
* Returns a place's capital status: 2 for a national capital, 1 for an admin-1 seat and 0 otherwise.
|
|
183
|
+
*
|
|
184
|
+
* The caller supplies it, so the resolver never loads a capitals reference itself.
|
|
288
185
|
*/
|
|
289
186
|
export type CapitalLevelFn = (place: Pick<ResolvedPlace, "name" | "country" | "lat" | "lon">) => number
|
|
290
187
|
|
|
291
|
-
/**
|
|
292
|
-
* The level a candidate must hold to be PROMOTED: national capitals only. Admin-1 seats stay un-promoted, and that
|
|
293
|
-
* scope is forced by decided rows, not caution — a seat margin of even 1 log10 unit flips bare `Springfield` to
|
|
294
|
-
* Springfield, Illinois against the ratified 2026-08-11 referential decision
|
|
295
|
-
* ({@link SAME_COUNTRY_IMPORTANCE_TIE_BAND}), and sends bare `Hamilton` to the Waikato seat (Hamilton NZ, 2.8x smaller
|
|
296
|
-
* than Hamilton, Ontario), both measured on the shipped `candidate.db`. The reference still records seats; no consumer
|
|
297
|
-
* promotes on them.
|
|
298
|
-
*/
|
|
299
188
|
const PROMOTABLE_CAPITAL_LEVEL = 2
|
|
300
189
|
|
|
301
190
|
/**
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
191
|
+
* The size lead, in log10-population units, that another place needs to stay ahead of a national capital.
|
|
192
|
+
*
|
|
193
|
+
* A value of 2 means 100 times more populous.
|
|
305
194
|
*/
|
|
306
195
|
export const NATIONAL_CAPITAL_MARGIN_LOG10 = 2
|
|
307
196
|
|
|
308
197
|
/**
|
|
309
|
-
*
|
|
310
|
-
* {@link
|
|
311
|
-
* deciding stage measurably never reaches an answer (the iteration-1 board run: the candidate-order bonus reordered
|
|
312
|
-
* `findPlace` on every target row and moved 0 of the 12).
|
|
313
|
-
*
|
|
314
|
-
* The rule: within the exact tier, take the first NATIONAL-capital row and walk it upward past each row it is within
|
|
315
|
-
* {@link NATIONAL_CAPITAL_MARGIN_LOG10} of, stopping at the first row over the margin or at another national capital.
|
|
316
|
-
* Same three house rules as the other keys — tier-safe (never crosses the exact/partial boundary.
|
|
317
|
-
*
|
|
318
|
-
* A capital that only PARTIALLY matched the query — Saint George's, Grenada for the abbreviated "St. George's" — stays
|
|
319
|
-
* behind every exact match, because crossing that line is how iteration 1 answered bare "Djibouti" with the capital
|
|
320
|
-
* city instead of the country), positive evidence only (no capital in the list → identity, and the margin reads the
|
|
321
|
-
* same `prominence ?? score` size every other key does), and stable (non-promoted rows keep their order).
|
|
198
|
+
* Moves the first national capital in the leading match tier above each preceding row that
|
|
199
|
+
* is at most {@link NATIONAL_CAPITAL_MARGIN_LOG10} larger, stopping at another capital.
|
|
322
200
|
*
|
|
323
|
-
*
|
|
324
|
-
* decisions (Whitby/Windsor/Springfield) sit on gaps of 0.004–0.02, while the capital contests this key exists for sit
|
|
325
|
-
* on gaps of 0.21–0.24 — an importance-scale bonus big enough to win them would dwarf every ratified decision on the
|
|
326
|
-
* same scale.
|
|
201
|
+
* It runs after {@link rankByImportance} and never moves a capital across the exact-match boundary.
|
|
327
202
|
*/
|
|
328
203
|
export function promoteCapitals<T extends Rankable & Pick<ResolvedPlace, "name" | "country" | "lat" | "lon">>(
|
|
329
204
|
candidates: readonly T[],
|
|
@@ -335,7 +210,6 @@ export function promoteCapitals<T extends Rankable & Pick<ResolvedPlace, "name"
|
|
|
335
210
|
const rest: T[] = []
|
|
336
211
|
|
|
337
212
|
for (const c of candidates) {
|
|
338
|
-
// Tri-state exactMatch, same reading as rankWithinTier: only a stated TRUE earns the tier.
|
|
339
213
|
;(c.exactMatch === true ? exact : rest).push(c)
|
|
340
214
|
}
|
|
341
215
|
|
|
@@ -2,91 +2,40 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* The three post-walk admin coherence passes (#263 / #822 / the region-country pass) — split from
|
|
7
|
-
* `resolve.ts` on the `bare-toponym-race.ts` precedent: the walk file holds the walk, this one
|
|
8
|
-
* holds the joint-consistency re-picks that run after it. Each pass's contract, triggers, and
|
|
9
|
-
* byte-stability guarantees are documented on the pass itself; `resolveTree` sequences them.
|
|
10
5
|
*/
|
|
11
6
|
import type { AddressNode } from "@mailwoman/core/decoder";
|
|
12
|
-
import {
|
|
7
|
+
import type { ResolverBackend } from "@mailwoman/core/resolver";
|
|
13
8
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* The walk scopes a child lookup to its resolved parent. When that scoped probe misses, two widenings exist so an
|
|
18
|
-
* incomplete hierarchy (a real place whose ancestor chain lacks its region) still resolves: the resolver's retry
|
|
19
|
-
* without the parent, and the candidate backend's interior region-scope fallback (#1731), which re-admits rows from
|
|
20
|
-
* outside the region and stamps them `regionScopeMiss`. Both also admit a namesake under another region: `臺南市北區`
|
|
21
|
-
* resolved 臺南市 (Tainan City), found no 北區 under it — the candidate table carries no Han key for Tainan's — and the
|
|
22
|
-
* widening answered Hsinchu's 北區, 214 km away, which the coherence report then marked `region: contradicted` while the
|
|
23
|
-
* point stood. Of the 289 held-out Taiwanese 鄉鎮市區, 21 resolved this way at 15.6–238 km when the register was read as
|
|
24
|
-
* bare `縣市鄉鎮市區` lines.
|
|
9
|
+
* Un-resolves a parent-fallback pick whose stamped ancestors name a region other than
|
|
10
|
+
* the resolved region above it, marking it `parent_fallback_refused`.
|
|
25
11
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* different place and is un-resolved here, so the admin ladder answers the parent's own point rather than a namesake
|
|
29
|
-
* elsewhere. Only widened picks are examined (`metadata.parent_fallback`, stamped by the walk for either mechanism),
|
|
30
|
-
* and only when the parent region resolved to a place identity; no-op without the ancestor sidecar, since a chain that
|
|
31
|
-
* cannot be read is not a contradiction. The classifier attribution stays on the node; `parent_fallback_refused`
|
|
32
|
-
* records what happened.
|
|
12
|
+
* A pick whose ancestor chain names no region is kept, because the fallback
|
|
13
|
+
* exists for places with incomplete hierarchies.
|
|
33
14
|
*/
|
|
34
15
|
export declare function applyParentFallbackContradiction(roots: readonly AddressNode[]): void;
|
|
35
16
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* Messina's descendants, finds nothing, and the result falls back to the region centroid (Sicily). The region's
|
|
39
|
-
* same-named runner-ups (Maine, Missouri, …) were already captured as `alternatives`; this pass asks the question the
|
|
40
|
-
* greedy order skipped — _which "ME" has a "Portland" under it?_ — and re-picks the (region, locality) pair where a
|
|
41
|
-
* same-named locality descends from a same-named region candidate. Geography decides; no country prior, no list.
|
|
17
|
+
* Re-picks a resolved region and its unresolved child locality as a pair, choosing the
|
|
18
|
+
* region candidate that actually contains a locality with the same name.
|
|
42
19
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
20
|
+
* This recovers cases such as "Portland, ME" where the region was picked in isolation
|
|
21
|
+
* before the locality was known.
|
|
22
|
+
* It leaves trees with a resolved locality untouched.
|
|
46
23
|
*/
|
|
47
24
|
export declare function applyAdminCoherence(roots: readonly AddressNode[], backend: ResolverBackend): Promise<void>;
|
|
48
25
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* (Vienna WV) and IGNORES the "Austria" the address named. This pass asks the question the greedy order skipped —
|
|
52
|
-
* _which "Vienna" is in the country the address names?_ — and re-picks the locality to the same-named place under that
|
|
53
|
-
* country. The country code comes from the parser's OWN `country` emission via codex's ISO-3166 table (a name→code
|
|
54
|
-
* normalization of a token the model already classified, NOT a routing prior or safelist); the gazetteer's `country`
|
|
55
|
-
* column does the geographic confirmation. No pin, no list; generalizes to every country.
|
|
26
|
+
* Re-picks a locality to the place with the same name inside the country specified in
|
|
27
|
+
* the address, when that country is the locality's nearest admin context.
|
|
56
28
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* and then regardless of the locality's resolution state — so it covers both the resolved-but-foreign locality (Sydney
|
|
60
|
-
* → the greedy AU pick was wrong) and the unresolved locality the span-rescore tier would otherwise back-fill with the
|
|
61
|
-
* US namesake (Vienna → Vienna WV). Byte-stable when the locality already resolved in-country (the id guard) or the
|
|
62
|
-
* named country holds no same-named locality (the fail-safe — what also protects "Turkey, TX": no country token ⇒ no
|
|
63
|
-
* trigger; and an in-country lookup that finds nothing keeps the greedy result). Costs one country-scoped locality
|
|
64
|
-
* lookup per triggering pair. See `ResolveOpts.adminCoherence`.
|
|
29
|
+
* It leaves the locality unchanged when it already resolved to that place or
|
|
30
|
+
* when that country has no locality with the same name.
|
|
65
31
|
*/
|
|
66
32
|
export declare function applyExplicitCountryCoherence(roots: readonly AddressNode[], backend: ResolverBackend): Promise<void>;
|
|
67
33
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* and disjoint from {@link applyAdminCoherence} (which needs a region that DID resolve): this pass owns the mirror case,
|
|
71
|
-
* where the region qualifier is a foreign subdivision the default-country hard filter (`spr.country = ?`) discarded.
|
|
72
|
-
*
|
|
73
|
-
* "Montreal QC" under a US locale: the walk applies `defaultCountry="US"` as a hard candidate filter to every admin
|
|
74
|
-
* lookup, so the region "QC" (a Canadian subdivision) resolves to nothing and is dropped — the one signal that would
|
|
75
|
-
* redirect the country to CA — and the locality "Montreal" is force-matched to the populous US namesake (Montreal, WI).
|
|
76
|
-
* The greedy order threw away the evidence that could correct it.
|
|
77
|
-
*
|
|
78
|
-
* The fix expands the region token to its country via codex's ISO-3166-2 subdivision table (`matchSubdivision`: "QC" →
|
|
79
|
-
* `{ name: "Quebec", country: "CA" }`, handling the FTS index's missing "QC" alt-name code-side), then asks the two
|
|
80
|
-
* questions the greedy walk skipped: does that subdivision genuinely resolve UNDER its own country, and is there a
|
|
81
|
-
* same-named locality under it? Only when BOTH hold does it swap the region and locality to the in-country pair.
|
|
82
|
-
* Geography confirms; the subdivision table is a soft name→country prior, not a routing decision.
|
|
34
|
+
* Re-picks the region and locality into a foreign country when the region token is that
|
|
35
|
+
* country's subdivision and the default-country filter left it unresolved.
|
|
83
36
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* so a well-formed US query never trips this), (c) the token is a subdivision of a DIFFERENT country than the default,
|
|
87
|
-
* and (d) both the foreign region and a same-named foreign locality resolve. "Springfield, IL" / "Portland, ME": the
|
|
88
|
-
* region resolves under `US`, so check (b) fails and the tree is untouched. Costs one region + one locality lookup per
|
|
89
|
-
* triggering pair. See `ResolveOpts.adminCoherence`.
|
|
37
|
+
* Both the foreign region and a locality with the same name under that country must resolve,
|
|
38
|
+
* so domestic queries whose region resolves are never changed.
|
|
90
39
|
*/
|
|
91
40
|
export declare function applyRegionCountryCoherence(roots: readonly AddressNode[], backend: ResolverBackend, defaultCountry: string | undefined): Promise<void>;
|
|
92
41
|
//# sourceMappingURL=coherence-passes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coherence-passes.d.ts","sourceRoot":"","sources":["../../lib/admin/coherence-passes.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"coherence-passes.d.ts","sourceRoot":"","sources":["../../lib/admin/coherence-passes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAiB,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAY9E;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,CAuCpF;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBhH;AA4HD;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CAClD,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,IAAI,CAAC,CAkBf;AAiCD;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAChD,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,OAAO,EAAE,eAAe,EACxB,cAAc,EAAE,MAAM,GAAG,SAAS,GAChC,OAAO,CAAC,IAAI,CAAC,CAuBf"}
|