@mailwoman/resolver 9.2.0 → 9.4.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 +5 -5
- package/{admin-coherence-passes.ts → lib/admin/coherence-passes.ts} +87 -9
- package/{admin-containment.ts → lib/admin/containment.ts} +5 -14
- package/lib/admin/index.ts +10 -0
- package/lib/admin/jp-municipality.ts +97 -0
- package/{admin-winner.ts → lib/admin/winner.ts} +18 -2
- package/{backend-capabilities.ts → lib/backend-capabilities.ts} +3 -3
- package/{bare-toponym-race.ts → lib/bare-toponym-race.ts} +1 -1
- package/{decorate-node.ts → lib/decorate-node.ts} +2 -2
- package/{fold-name.ts → lib/fold-name.ts} +2 -2
- package/{index.ts → lib/index.ts} +16 -22
- package/{plausibility.ts → lib/plausibility.ts} +5 -4
- package/{postcode-country-coherence.ts → lib/postcode/country-coherence.ts} +27 -32
- package/lib/postcode/index.ts +9 -0
- package/{postcode-prefix.ts → lib/postcode/prefix.ts} +4 -4
- package/{postcode-shape-coherence.ts → lib/postcode/shape-coherence.ts} +10 -24
- package/{remote-resolver.ts → lib/remote-resolver.ts} +13 -4
- package/{rerank.ts → lib/rerank.ts} +2 -2
- package/{resolve.ts → lib/resolve/index.ts} +133 -602
- package/lib/resolve/passes.ts +544 -0
- package/{span-rescore.ts → lib/span-rescore.ts} +63 -97
- package/{street-evidence.ts → lib/street/evidence.ts} +39 -6
- package/lib/street/index.ts +8 -0
- package/{street-tier.ts → lib/street/tier.ts} +131 -110
- package/{toponym-prior.ts → lib/toponym-prior.ts} +8 -8
- package/out/{admin-coherence-passes.d.ts → admin/coherence-passes.d.ts} +29 -7
- package/out/admin/coherence-passes.d.ts.map +1 -0
- package/out/{admin-coherence-passes.js → admin/coherence-passes.js} +73 -9
- package/out/admin/coherence-passes.js.map +1 -0
- package/out/{admin-containment.d.ts → admin/containment.d.ts} +5 -5
- package/out/admin/containment.d.ts.map +1 -0
- package/out/{admin-containment.js → admin/containment.js} +6 -12
- package/out/admin/containment.js.map +1 -0
- package/out/admin/index.d.ts +10 -0
- package/out/admin/index.d.ts.map +1 -0
- package/out/admin/index.js +10 -0
- package/out/admin/index.js.map +1 -0
- package/out/admin/jp-municipality.d.ts +50 -0
- package/out/admin/jp-municipality.d.ts.map +1 -0
- package/out/admin/jp-municipality.js +54 -0
- package/out/admin/jp-municipality.js.map +1 -0
- package/out/{admin-winner.d.ts → admin/winner.d.ts} +11 -3
- package/out/admin/winner.d.ts.map +1 -0
- package/out/{admin-winner.js → admin/winner.js} +19 -3
- package/out/admin/winner.js.map +1 -0
- package/out/backend-capabilities.d.ts.map +1 -1
- package/out/backend-capabilities.js +3 -3
- package/out/backend-capabilities.js.map +1 -1
- package/out/bare-toponym-race.d.ts.map +1 -1
- package/out/bare-toponym-race.js +1 -1
- package/out/bare-toponym-race.js.map +1 -1
- package/out/decorate-node.d.ts +1 -1
- package/out/decorate-node.d.ts.map +1 -1
- package/out/decorate-node.js +1 -1
- package/out/decorate-node.js.map +1 -1
- package/out/fold-name.d.ts +2 -2
- package/out/fold-name.d.ts.map +1 -1
- package/out/fold-name.js +2 -2
- package/out/fold-name.js.map +1 -1
- package/out/index.d.ts +15 -16
- package/out/index.d.ts.map +1 -1
- package/out/index.js +9 -10
- package/out/index.js.map +1 -1
- package/out/plausibility.d.ts +5 -4
- package/out/plausibility.d.ts.map +1 -1
- package/out/plausibility.js +5 -4
- package/out/plausibility.js.map +1 -1
- package/out/{postcode-country-coherence.d.ts → postcode/country-coherence.d.ts} +16 -16
- package/out/postcode/country-coherence.d.ts.map +1 -0
- package/out/{postcode-country-coherence.js → postcode/country-coherence.js} +24 -25
- package/out/postcode/country-coherence.js.map +1 -0
- package/out/postcode/index.d.ts +9 -0
- package/out/postcode/index.d.ts.map +1 -0
- package/out/postcode/index.js +9 -0
- package/out/postcode/index.js.map +1 -0
- package/out/{postcode-prefix.d.ts → postcode/prefix.d.ts} +4 -4
- package/out/postcode/prefix.d.ts.map +1 -0
- package/out/{postcode-prefix.js → postcode/prefix.js} +4 -4
- package/out/postcode/prefix.js.map +1 -0
- package/out/{postcode-shape-coherence.d.ts → postcode/shape-coherence.d.ts} +3 -3
- package/out/postcode/shape-coherence.d.ts.map +1 -0
- package/out/{postcode-shape-coherence.js → postcode/shape-coherence.js} +11 -20
- package/out/postcode/shape-coherence.js.map +1 -0
- package/out/remote-resolver.d.ts +18 -3
- package/out/remote-resolver.d.ts.map +1 -1
- package/out/remote-resolver.js +2 -2
- package/out/remote-resolver.js.map +1 -1
- package/out/rerank.d.ts +1 -1
- package/out/rerank.d.ts.map +1 -1
- package/out/rerank.js +2 -2
- package/out/rerank.js.map +1 -1
- package/out/{resolve.d.ts → resolve/index.d.ts} +1 -1
- package/out/resolve/index.d.ts.map +1 -0
- package/out/{resolve.js → resolve/index.js} +100 -387
- package/out/resolve/index.js.map +1 -0
- package/out/resolve/passes.d.ts +218 -0
- package/out/resolve/passes.d.ts.map +1 -0
- package/out/resolve/passes.js +333 -0
- package/out/resolve/passes.js.map +1 -0
- package/out/span-rescore.d.ts +16 -16
- package/out/span-rescore.d.ts.map +1 -1
- package/out/span-rescore.js +43 -69
- package/out/span-rescore.js.map +1 -1
- package/out/{street-evidence.d.ts → street/evidence.d.ts} +18 -3
- package/out/street/evidence.d.ts.map +1 -0
- package/out/{street-evidence.js → street/evidence.js} +22 -6
- package/out/street/evidence.js.map +1 -0
- package/out/street/index.d.ts +8 -0
- package/out/street/index.d.ts.map +1 -0
- package/out/street/index.js +8 -0
- package/out/street/index.js.map +1 -0
- package/out/{street-tier.d.ts → street/tier.d.ts} +14 -3
- package/out/street/tier.d.ts.map +1 -0
- package/out/{street-tier.js → street/tier.js} +121 -99
- package/out/street/tier.js.map +1 -0
- package/out/toponym-prior.d.ts +8 -8
- package/out/toponym-prior.d.ts.map +1 -1
- package/out/toponym-prior.js +8 -8
- package/out/toponym-prior.js.map +1 -1
- package/package.json +116 -59
- package/vitest.config.ts +5 -6
- package/out/admin-coherence-passes.d.ts.map +0 -1
- package/out/admin-coherence-passes.js.map +0 -1
- package/out/admin-containment.d.ts.map +0 -1
- package/out/admin-containment.js.map +0 -1
- package/out/admin-winner.d.ts.map +0 -1
- package/out/admin-winner.js.map +0 -1
- package/out/postcode-country-coherence.d.ts.map +0 -1
- package/out/postcode-country-coherence.js.map +0 -1
- package/out/postcode-prefix.d.ts.map +0 -1
- package/out/postcode-prefix.js.map +0 -1
- package/out/postcode-shape-coherence.d.ts.map +0 -1
- package/out/postcode-shape-coherence.js.map +0 -1
- package/out/resolve.d.ts.map +0 -1
- package/out/resolve.js.map +0 -1
- package/out/street-evidence.d.ts.map +0 -1
- package/out/street-evidence.js.map +0 -1
- package/out/street-tier.d.ts.map +0 -1
- package/out/street-tier.js.map +0 -1
- package/out/vitest.config.d.ts +0 -16
- package/out/vitest.config.d.ts.map +0 -1
- package/out/vitest.config.js +0 -36
- package/out/vitest.config.js.map +0 -1
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
* turns THAT into a hard `spr.country = 'US'` WHERE clause. The candidate pool is all-US before
|
|
12
12
|
* ranking begins, so a coarse placer that already called this address FR at confidence
|
|
13
13
|
* 0.9999908844 has nothing to promote — a soft re-rank downstream of a hard filter is inert by
|
|
14
|
-
* construction. Population then picks Paris, Texas (pop 24,969). With the postal
|
|
14
|
+
* construction. Population then picks Paris, Texas (pop 24,969). With the postal extracts attached
|
|
15
15
|
* the answer gets WORSE, not merely wrong: the postcode resolves to the US row (ZIP 75001,
|
|
16
|
-
* Addison TX), `applyPostcodeConsistency` finds no Paris within its 50 km
|
|
16
|
+
* Addison TX), `applyPostcodeConsistency` finds no Paris within its 50 km check (the nearest is
|
|
17
17
|
* 143.8 km), and falls the locality coordinate back to the ZIP point. See
|
|
18
18
|
* `docs/records/evals/2026-08-03-postcode-locality-scoping.md` for the instrumented diagnosis.
|
|
19
19
|
*
|
|
20
|
-
* No pattern-only
|
|
20
|
+
* No pattern-only change can fix this. `75001` is NOT unambiguously French:
|
|
21
21
|
* `candidateSystemsForPostcode("75001")` returns `["us", "de", "fr"]`, and the 2026-08-04
|
|
22
22
|
* candidate gazetteer holds the literal string in FOUR countries — FR 48.863,2.336 (Paris 1er),
|
|
23
23
|
* US 32.960,-96.838 (Addison TX), DE 48.844,9.367, PL 54.190,16.188 (×2 rows). The SHAPE is
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
* `state.defaultCountry` for the whole walk. Everything downstream — including the three post-walk
|
|
41
41
|
* coherence passes and the street/rooftop tiers — then sees the corrected country.
|
|
42
42
|
*
|
|
43
|
-
* ## Why it is not a hard veto (the doctrine
|
|
43
|
+
* ## Why it is not a hard veto (the doctrine check)
|
|
44
44
|
*
|
|
45
45
|
* Registries are SOFT priors here, positive evidence only. Two properties keep this one honest:
|
|
46
46
|
*
|
|
@@ -86,9 +86,9 @@
|
|
|
86
86
|
* Prototyped out-of-tree against the live gazetteer over the public `findPlace` surface (2026-08-03):
|
|
87
87
|
* 400 real US (ZIP, city) pairs from `postalcode-us.db` + 400 real FR (CP, commune) pairs from
|
|
88
88
|
* `postcode-locality-fr.db` — 800 pairs, **zero** border crossings, at both the 15 km and 25 km
|
|
89
|
-
*
|
|
89
|
+
* checks. The 22 US abstentions were pairs whose ZIP parent name is not an exact-matching locality
|
|
90
90
|
* in the admin gazetteer (a recall gap; abstention is the safe outcome). The confound board's
|
|
91
|
-
* verdicts were identical at 15, 25 AND 50 km, so the mechanism is not
|
|
91
|
+
* verdicts were identical at 15, 25 AND 50 km, so the mechanism is not check-tuned; the default
|
|
92
92
|
* below is the 25 km the scale run measured.
|
|
93
93
|
*
|
|
94
94
|
* Cost: 2 lookups on the byte-stable path (postcode + locality under the default country), and at
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
* unless the tree carries both a postcode and a locality.
|
|
98
98
|
*
|
|
99
99
|
* **Default-ON** since the operator promotion of 2026-08-05 (#1477) — the resolver gauntlet, pinned
|
|
100
|
-
* both ways, returned zero newly-failing
|
|
100
|
+
* both ways, returned zero newly-failing conditional cases, and 56,000 pair evaluations across both
|
|
101
101
|
* backends returned zero false positives. `ResolveOpts.postcodeCountryCoherence: false` opts out,
|
|
102
102
|
* and the walk is byte-stable then. Receipts:
|
|
103
103
|
* `docs/records/evals/2026-08-05-postcode-coherence-default-on-evidence.md`.
|
|
@@ -106,21 +106,21 @@
|
|
|
106
106
|
// `postcode-systems` has no dedicated export subpath; the barrel is where every other consumer
|
|
107
107
|
// (`neural/postcode-anchor.ts`) reaches it from.
|
|
108
108
|
import { candidateSystemsForPostcode } from "@mailwoman/codex"
|
|
109
|
-
import type
|
|
109
|
+
import { walkNodes, type AddressNode } from "@mailwoman/core/decoder"
|
|
110
110
|
import type { ResolvedPlace, ResolverBackend } from "@mailwoman/core/resolver"
|
|
111
111
|
import { haversineKm } from "@mailwoman/spatial"
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
* Default
|
|
114
|
+
* Default check radius (km) for the postcode↔locality consistency test. 25 km is what the 800-pair scale run measured;
|
|
115
115
|
* the confound board returned identical verdicts at 15, 25 and 50, so this is a floor choice, not a tuned one.
|
|
116
116
|
*/
|
|
117
|
-
export const
|
|
117
|
+
export const POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM = 25
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
120
|
* Which half (or halves) of the address bought the verdict — the firing receipt, so a reader of a scoped result can
|
|
121
121
|
* tell a two-sided agreement from a one-sided uniqueness claim without re-deriving it.
|
|
122
122
|
*
|
|
123
|
-
* - `pair` — postcode AND locality both resolve in this country, within the
|
|
123
|
+
* - `pair` — postcode AND locality both resolve in this country, within the radius. The strongest rung and the only one
|
|
124
124
|
* that existed before #24.
|
|
125
125
|
* - `locality` — the locality names exactly one country in the whole gazetteer, and the postcode names none that
|
|
126
126
|
* contradict it. This is the CH/BE class: the gazetteer carries no Swiss or Belgian postcodes at all, so the pair
|
|
@@ -151,7 +151,7 @@ export interface PostcodeCountryScope {
|
|
|
151
151
|
*/
|
|
152
152
|
evidence: PostcodeCountryScopeEvidence
|
|
153
153
|
/**
|
|
154
|
-
* Distance between the resolved postcode point and the nearest same-named locality, in km. Always `<=
|
|
154
|
+
* Distance between the resolved postcode point and the nearest same-named locality, in km. Always `<= thresholdKm`.
|
|
155
155
|
* Present ONLY for the `pair` rung — a single-sided verdict has no two points to measure between, and reporting a `0`
|
|
156
156
|
* there would assert an agreement nobody tested (the meaning-of-zero rule).
|
|
157
157
|
*/
|
|
@@ -180,9 +180,9 @@ export interface PostcodeCountryScopeOpts {
|
|
|
180
180
|
*/
|
|
181
181
|
defaultCountry: string | undefined
|
|
182
182
|
/**
|
|
183
|
-
* Consistency
|
|
183
|
+
* Consistency check radius in km. Defaults to {@link POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM}.
|
|
184
184
|
*/
|
|
185
|
-
|
|
185
|
+
thresholdKm?: number
|
|
186
186
|
/**
|
|
187
187
|
* Optional narrowing of the SHAPE half of the candidate-country set — the shape-coherence pass's intersection for a
|
|
188
188
|
* CONFIRMED postcode span (see `resolver/postcode-shape-coherence.ts`, #31 Mechanism 1). When present it REPLACES
|
|
@@ -197,7 +197,7 @@ export interface PostcodeCountryScopeOpts {
|
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
/**
|
|
200
|
-
* A usable coordinate — the gazetteer stores an unlocated row as 0,0, which haversine would
|
|
200
|
+
* A usable coordinate — the gazetteer stores an unlocated row as 0,0, which haversine would measure against.
|
|
201
201
|
*/
|
|
202
202
|
function hasCoord(p: ResolvedPlace): boolean {
|
|
203
203
|
return p.lat !== 0 || p.lon !== 0
|
|
@@ -214,7 +214,7 @@ const MAX_LOCALITY_VALUES = 3
|
|
|
214
214
|
* case-insensitively deduplicated. Two passes so a real locality always beats a dependent one regardless of tree
|
|
215
215
|
* order.
|
|
216
216
|
*
|
|
217
|
-
* Document order is
|
|
217
|
+
* Document order is required, not cosmetic. The original stack-pop traversal visited the LAST node first, so on `92
|
|
218
218
|
* Laurell Road, Gander, NL A1V 0A9` — where the model tags both `Gander` and the province abbreviation `NL` as
|
|
219
219
|
* localities — the pass keyed its whole country verdict on "NL", whose only exact locality-band bearer is an alias of
|
|
220
220
|
* Nal, Afghanistan, and the walk resolved a Newfoundland street 10,000 km away. The FIRST-written locality is the one
|
|
@@ -326,15 +326,16 @@ async function countriesHolding(
|
|
|
326
326
|
/**
|
|
327
327
|
* Is the (postcode, locality) pair geographically consistent in `country`? Returns the winning pair and its distance,
|
|
328
328
|
* or `null` when the postcode does not resolve there, no same-named locality exists there, or the nearest one is
|
|
329
|
-
* outside the
|
|
330
|
-
* when the caller already knows the country's postcode row (`knownPostcodePlace`, from the exhaustive unscoped
|
|
329
|
+
* outside the check. Costs one postcode lookup plus (only if that hit) one locality lookup — or just the locality
|
|
330
|
+
* lookup when the caller already knows the country's postcode row (`knownPostcodePlace`, from the exhaustive unscoped
|
|
331
|
+
* probe).
|
|
331
332
|
*/
|
|
332
333
|
async function coherenceIn(
|
|
333
334
|
country: string,
|
|
334
335
|
postcode: string,
|
|
335
336
|
locality: string,
|
|
336
337
|
backend: ResolverBackend,
|
|
337
|
-
|
|
338
|
+
thresholdKm: number,
|
|
338
339
|
knownPostcodePlace?: ResolvedPlace
|
|
339
340
|
): Promise<{ postcodePlace: ResolvedPlace; localityPlace: ResolvedPlace; distanceKm: number } | null> {
|
|
340
341
|
let postcodePlace = knownPostcodePlace
|
|
@@ -370,7 +371,7 @@ async function coherenceIn(
|
|
|
370
371
|
if (!candidate.exactMatch || !hasCoord(candidate)) continue
|
|
371
372
|
const distanceKm = haversineKm(postcodePlace.lat, postcodePlace.lon, candidate.lat, candidate.lon)
|
|
372
373
|
|
|
373
|
-
if (distanceKm >
|
|
374
|
+
if (distanceKm > thresholdKm) continue
|
|
374
375
|
|
|
375
376
|
if (!best || distanceKm < best.distanceKm) {
|
|
376
377
|
best = { localityPlace: candidate, distanceKm }
|
|
@@ -411,7 +412,7 @@ export async function findPostcodeCountryScope(
|
|
|
411
412
|
// and on every bare-postcode query.
|
|
412
413
|
if (!localities.length) return null
|
|
413
414
|
|
|
414
|
-
const
|
|
415
|
+
const thresholdKm = opts.thresholdKm ?? POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM
|
|
415
416
|
|
|
416
417
|
// 1. Is the caller's own default country coherent with ANY of the address's locality values? If so we are done —
|
|
417
418
|
// positive evidence for the default, no override, and the common domestic path (one locality value) costs two
|
|
@@ -419,7 +420,7 @@ export async function findPostcodeCountryScope(
|
|
|
419
420
|
// sweep below carries the whole verdict.
|
|
420
421
|
if (defaultCountry) {
|
|
421
422
|
for (const locality of localities) {
|
|
422
|
-
if (await coherenceIn(defaultCountry, postcode, locality, backend,
|
|
423
|
+
if (await coherenceIn(defaultCountry, postcode, locality, backend, thresholdKm)) return null
|
|
423
424
|
}
|
|
424
425
|
}
|
|
425
426
|
|
|
@@ -455,7 +456,7 @@ export async function findPostcodeCountryScope(
|
|
|
455
456
|
const coherent: PostcodeCountryScope[] = []
|
|
456
457
|
|
|
457
458
|
for (const country of candidates) {
|
|
458
|
-
const hit = await coherenceIn(country, postcode, locality, backend,
|
|
459
|
+
const hit = await coherenceIn(country, postcode, locality, backend, thresholdKm, pcHolders.get(country))
|
|
459
460
|
|
|
460
461
|
if (hit) {
|
|
461
462
|
coherent.push({ country, postcode, locality, evidence: "pair", ...hit })
|
|
@@ -495,7 +496,7 @@ export async function findPostcodeCountryScope(
|
|
|
495
496
|
|
|
496
497
|
// 4a. A locality value names exactly one country. Stronger than the postcode rung — a place name is far
|
|
497
498
|
// more discriminative than a four-digit code — so it is tried first. A verdict stands down when that
|
|
498
|
-
// country's OWN postcode row contradicts the locality (outside the
|
|
499
|
+
// country's OWN postcode row contradicts the locality (outside the check): the two halves disagreeing
|
|
499
500
|
// inside one country is exactly what the pair test exists to catch, and a single-sided rung must not
|
|
500
501
|
// launder it.
|
|
501
502
|
// PRIMARY-keyed rows only (#1626's re-reading discipline, applied to a country verdict): "the locality
|
|
@@ -528,7 +529,7 @@ export async function findPostcodeCountryScope(
|
|
|
528
529
|
|
|
529
530
|
const contradicted =
|
|
530
531
|
ownPostcode !== undefined &&
|
|
531
|
-
haversineKm(ownPostcode.lat, ownPostcode.lon, localityPlace.lat, localityPlace.lon) >
|
|
532
|
+
haversineKm(ownPostcode.lat, ownPostcode.lon, localityPlace.lat, localityPlace.lon) > thresholdKm
|
|
532
533
|
|
|
533
534
|
if (country !== defaultCountry && !contradicted && !verdicts.has(country)) {
|
|
534
535
|
verdicts.set(country, { country, postcode, locality, evidence: "locality", localityPlace })
|
|
@@ -578,13 +579,7 @@ async function holdsLocality(backend: ResolverBackend, locality: string, country
|
|
|
578
579
|
* untouched, this only writes `metadata`.
|
|
579
580
|
*/
|
|
580
581
|
export function stampPostcodeCountryScope(roots: readonly AddressNode[], scope: PostcodeCountryScope): void {
|
|
581
|
-
const
|
|
582
|
-
|
|
583
|
-
while (stack.length) {
|
|
584
|
-
const n = stack.pop()!
|
|
585
|
-
|
|
586
|
-
stack.push(...n.children)
|
|
587
|
-
|
|
582
|
+
for (const n of walkNodes(roots)) {
|
|
588
583
|
if (n.tag !== "postcode" && n.tag !== "locality" && n.tag !== "dependent_locality") continue
|
|
589
584
|
|
|
590
585
|
n.metadata = {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
* acquisition) — the branch exists so the law is tested before the data.
|
|
30
30
|
* - **Anything else** — abstain (null).
|
|
31
31
|
*
|
|
32
|
-
* ## The probe's country
|
|
32
|
+
* ## The probe's country restriction
|
|
33
33
|
*
|
|
34
34
|
* The index is country-specific EVIDENCE: it is only probed when its `country` matches the
|
|
35
35
|
* query's country scope (or the scope is absent). A GB index must not speak under a US scope —
|
|
@@ -63,7 +63,7 @@ import type { PostcodePrefixIndexLike, PostcodePrefixNode, ResolvedPlace } from
|
|
|
63
63
|
* even the 0,0 unlocated sentinel), and the prefix prior's ancestry-only tier must express absence as `undefined`
|
|
64
64
|
* instead — B3-3: inventing a centroid would reproduce the `BT3 9QQ` → Sheffield defect #1480. `decorateNode` copies
|
|
65
65
|
* `lat`/`lon` onto the node verbatim, so an undefined coordinate stays absent on the node — the meaning-of-zero rule.
|
|
66
|
-
* Widened ONLY at this
|
|
66
|
+
* Widened ONLY at this boundary: gazetteer places (always coordinate-bearing) remain plain `ResolvedPlace`.
|
|
67
67
|
*/
|
|
68
68
|
export type CoordinateOptionalPlace = Omit<ResolvedPlace, "lat" | "lon"> & { lat?: number; lon?: number }
|
|
69
69
|
|
|
@@ -117,7 +117,7 @@ export interface PostcodePrefixProbeResult {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
|
-
* Probe the index for `code`'s prefix. Two abstention
|
|
120
|
+
* Probe the index for `code`'s prefix. Two abstention checks, in order: the index's country must match the query's
|
|
121
121
|
* country scope (or the scope is absent), and the derivation law must yield a prefix the index carries. Returns null to
|
|
122
122
|
* abstain — never throws, never guesses.
|
|
123
123
|
*/
|
|
@@ -128,7 +128,7 @@ export function probePostcodePrefix(
|
|
|
128
128
|
): PostcodePrefixProbeResult | null {
|
|
129
129
|
const indexCountry = index.country?.toUpperCase()
|
|
130
130
|
|
|
131
|
-
// Country
|
|
131
|
+
// Country check: the index is evidence FOR its own country only. A GB index under a US scope stays
|
|
132
132
|
// silent — the walk's country filter is the caller's declared universe.
|
|
133
133
|
if (queryCountry && indexCountry && queryCountry.toUpperCase() !== indexCountry) return null
|
|
134
134
|
|
|
@@ -69,23 +69,24 @@
|
|
|
69
69
|
* CONFIRMS it instead.
|
|
70
70
|
*
|
|
71
71
|
* **D-rule: opt-in behind `ResolveOpts.postcodeShapeCoherence`, default-OFF.** Demotion is the
|
|
72
|
-
* failure mode with teeth, so a default-on promotion needs the full pre-registered
|
|
72
|
+
* failure mode with teeth, so a default-on promotion needs the full pre-registered eval (B1-1
|
|
73
73
|
* byte-stability, B1-2 exclusion ≥90% with the correct sibling tag surviving, B1-3 confound ≤2%
|
|
74
74
|
* false exclusions; kill on any B1-3 δ).
|
|
75
75
|
*/
|
|
76
76
|
|
|
77
|
-
import { candidateSystemsForPostcode } from "@mailwoman/codex"
|
|
77
|
+
import { candidateSystemsForPostcode, SYSTEM_CODES } from "@mailwoman/codex"
|
|
78
78
|
import { matchCountry, matchSubdivision } from "@mailwoman/codex/country"
|
|
79
79
|
import { isUSStateAbbreviation } from "@mailwoman/codex/us"
|
|
80
|
-
import type
|
|
80
|
+
import { collectNodes, walkNodes, type AddressNode } from "@mailwoman/core/decoder"
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* The codex address systems a sibling signal can speak for — the universe `candidateSystemsForPostcode` can return, in
|
|
84
84
|
* the upper-case ISO form this module's signals are emitted in (`SystemCode` itself is lower-case). Signals from
|
|
85
85
|
* countries with no codex slice are filtered out BEFORE the intersection test, so a slice-less country can never
|
|
86
|
-
* manufacture an empty intersection (the false-exclusion trap; see the header).
|
|
86
|
+
* manufacture an empty intersection (the false-exclusion trap; see the header). Derived from codex's own list so a
|
|
87
|
+
* system added there is admitted here in the same change.
|
|
87
88
|
*/
|
|
88
|
-
const SYSTEM_UNIVERSE: ReadonlySet<string> = new Set<string>(
|
|
89
|
+
const SYSTEM_UNIVERSE: ReadonlySet<string> = new Set<string>(SYSTEM_CODES.map((system) => system.toUpperCase()))
|
|
89
90
|
|
|
90
91
|
/**
|
|
91
92
|
* The pass's per-tree verdict — the caller (and the B1 board tests) can see exactly which spans were confirmed,
|
|
@@ -119,12 +120,8 @@ export interface PostcodeShapeVerdict {
|
|
|
119
120
|
*/
|
|
120
121
|
function collectSiblingSystems(roots: readonly AddressNode[]): Set<string> {
|
|
121
122
|
const out = new Set<string>()
|
|
122
|
-
const stack: AddressNode[] = [...roots]
|
|
123
|
-
|
|
124
|
-
while (stack.length) {
|
|
125
|
-
const n = stack.pop()!
|
|
126
|
-
stack.push(...n.children)
|
|
127
123
|
|
|
124
|
+
for (const n of walkNodes(roots)) {
|
|
128
125
|
if (n.tag === "country") {
|
|
129
126
|
const matched = matchCountry(n.value)
|
|
130
127
|
|
|
@@ -143,7 +140,7 @@ function collectSiblingSystems(roots: readonly AddressNode[]): Set<string> {
|
|
|
143
140
|
if (n.tag === "region") {
|
|
144
141
|
// (a) The region's value as a subdivision ("CA" → US, "ON" → CA — the US-wins tiebreak for
|
|
145
142
|
// "CA" is matchSubdivision's own). (b) The `country_hint` stamp annotateUSRegions writes on
|
|
146
|
-
// 2-letter US state abbreviations — the same evidence via the pipeline's other
|
|
143
|
+
// 2-letter US state abbreviations — the same evidence via the pipeline's other path.
|
|
147
144
|
const sub = matchSubdivision(n.value)
|
|
148
145
|
|
|
149
146
|
if (sub && SYSTEM_UNIVERSE.has(sub.country.toUpperCase())) {
|
|
@@ -169,20 +166,9 @@ function collectSiblingSystems(roots: readonly AddressNode[]): Set<string> {
|
|
|
169
166
|
export function applyPostcodeShapeCoherence(roots: readonly AddressNode[]): PostcodeShapeVerdict {
|
|
170
167
|
const verdict: PostcodeShapeVerdict = { confirmed: [], excluded: [], abstained: [] }
|
|
171
168
|
|
|
172
|
-
// The postcode spans in
|
|
169
|
+
// The postcode spans in document order — the same walk `firstPostcodeValue` uses, so the verdict's
|
|
173
170
|
// "first confirmed" is the node `state.postcode` will read.
|
|
174
|
-
const postcodes
|
|
175
|
-
const stack: AddressNode[] = [...roots]
|
|
176
|
-
|
|
177
|
-
while (stack.length) {
|
|
178
|
-
const n = stack.pop()!
|
|
179
|
-
|
|
180
|
-
if (n.tag === "postcode" && n.value.trim().length) {
|
|
181
|
-
postcodes.push(n)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
stack.push(...n.children)
|
|
185
|
-
}
|
|
171
|
+
const postcodes = collectNodes(roots, (n) => n.tag === "postcode" && n.value.trim().length > 0)
|
|
186
172
|
|
|
187
173
|
if (!postcodes.length) return verdict
|
|
188
174
|
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
*
|
|
6
6
|
* `RemoteResolver` — the `Resolver` interface (`resolveTree`) over HTTP. The adapter the interface
|
|
7
7
|
* docstring anticipated (Phase 4.4): a client POSTs a parsed `AddressTree` + the serializable
|
|
8
|
-
* `ResolveOpts` to a resolver service, which owns the gazetteer + situs/interpolation
|
|
8
|
+
* `ResolveOpts` to a resolver service, which owns the gazetteer + situs/interpolation extracts,
|
|
9
9
|
* runs the cascade, and returns the resolved tree. Two payoffs:
|
|
10
10
|
*
|
|
11
11
|
* 1. **Multi-instance** — stateless parser nodes (the ~30 MB ONNX model) talk to ONE resolver service
|
|
12
|
-
* (the multi-GB gazetteer +
|
|
12
|
+
* (the multi-GB gazetteer + extracts). `parse` locally, `new RemoteResolver(...).resolveTree`
|
|
13
13
|
* remotely — same interface the in-process `WOFResolver` satisfies, so it's a drop-in.
|
|
14
14
|
* 2. **Canary** — point it at a second resolver build (or an adapter fronting Pelias/Nominatim/BAN)
|
|
15
15
|
* and diff the resolved trees through the identical contract.
|
|
@@ -39,6 +39,11 @@ export function serializableResolveOpts(opts?: ResolveOpts): SerializableResolve
|
|
|
39
39
|
return rest
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
export type RemoteResolverFetch = (
|
|
43
|
+
url: string,
|
|
44
|
+
init: { method: string; headers: Record<string, string>; body: string; signal?: AbortSignal }
|
|
45
|
+
) => Promise<{ ok: boolean; status: number; statusText: string; json(): Promise<unknown> }>
|
|
46
|
+
|
|
42
47
|
export interface RemoteResolverOpts {
|
|
43
48
|
/**
|
|
44
49
|
* Full URL of the resolver service's resolve-tree endpoint, e.g. `http://resolver:7081/v1/resolve`.
|
|
@@ -46,8 +51,12 @@ export interface RemoteResolverOpts {
|
|
|
46
51
|
endpoint: string
|
|
47
52
|
/**
|
|
48
53
|
* Injectable fetch (tests / custom agents). Defaults to the global `fetch`.
|
|
54
|
+
*
|
|
55
|
+
* Typed by what this module reads — `ok`, `status`, `statusText`, `json()` — rather than the full `fetch`, whose
|
|
56
|
+
* `Response` carries a body stream and headers no code here touches. The global `fetch` satisfies this shape, and a
|
|
57
|
+
* test double can be an object instead of an assertion.
|
|
49
58
|
*/
|
|
50
|
-
fetch?:
|
|
59
|
+
fetch?: RemoteResolverFetch
|
|
51
60
|
/**
|
|
52
61
|
* Per-request timeout in ms. Default 10000.
|
|
53
62
|
*/
|
|
@@ -75,7 +84,7 @@ export interface ResolveTreeResponse {
|
|
|
75
84
|
|
|
76
85
|
export class RemoteResolver implements Resolver {
|
|
77
86
|
readonly #endpoint: string
|
|
78
|
-
readonly #fetch:
|
|
87
|
+
readonly #fetch: RemoteResolverFetch
|
|
79
88
|
readonly #timeoutMs: number
|
|
80
89
|
readonly #headers: Record<string, string>
|
|
81
90
|
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
import type { AddressTree } from "@mailwoman/core/decoder"
|
|
34
34
|
|
|
35
|
-
import { isImplausibleResolution } from "
|
|
35
|
+
import { isImplausibleResolution } from "#plausibility"
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* One candidate parse from the k-best decode, with its (within-input comparable) score.
|
|
@@ -107,7 +107,7 @@ export interface RerankOpts {
|
|
|
107
107
|
*
|
|
108
108
|
* **When every resolved candidate is implausible, the model's rank-1 wins.** A reranker that returns nothing is worse
|
|
109
109
|
* than one that defers: "all my evidence says these are all bad" is not grounds to invent a different answer, only
|
|
110
|
-
* grounds to flag low confidence (the Phase-4b ambiguity
|
|
110
|
+
* grounds to flag low confidence (the Phase-4b ambiguity check).
|
|
111
111
|
*/
|
|
112
112
|
export async function rerankByResolution<T>(
|
|
113
113
|
candidates: ReadonlyArray<RerankCandidate<T>>,
|