@mailwoman/resolver 10.0.0 → 10.2.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 +31 -172
- package/lib/admin/containment.ts +15 -33
- package/lib/admin/jp-municipality.ts +21 -14
- package/lib/admin/winner.ts +37 -69
- package/lib/backend-capabilities.ts +28 -27
- package/lib/bare-toponym-race.ts +69 -37
- package/lib/decorate-node.ts +25 -49
- package/lib/fold-name.ts +5 -18
- package/lib/index.ts +5 -9
- package/lib/plausibility.ts +41 -68
- package/lib/postcode/country-coherence.ts +92 -296
- package/lib/postcode/prefix.ts +24 -86
- package/lib/postcode/shape-coherence.ts +26 -116
- package/lib/remote-resolver.ts +38 -33
- package/lib/rerank.ts +41 -54
- package/lib/resolve/passes.ts +188 -177
- package/lib/resolve.ts +744 -0
- package/lib/span-rescore.ts +219 -175
- package/lib/street/evidence.ts +65 -73
- package/lib/street/tier.ts +51 -194
- package/lib/toponym-prior.ts +54 -180
- 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 +24 -166
- package/out/admin/coherence-passes.js.map +1 -1
- package/out/admin/containment.d.ts +13 -31
- package/out/admin/containment.d.ts.map +1 -1
- package/out/admin/containment.js +13 -31
- package/out/admin/containment.js.map +1 -1
- package/out/admin/jp-municipality.d.ts +21 -14
- 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 +32 -64
- package/out/admin/winner.d.ts.map +1 -1
- package/out/admin/winner.js +23 -56
- 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 +19 -20
- package/out/backend-capabilities.d.ts.map +1 -1
- package/out/backend-capabilities.js +28 -26
- package/out/backend-capabilities.js.map +1 -1
- package/out/bare-toponym-race.d.ts +54 -27
- 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 +25 -49
- 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 +30 -60
- package/out/plausibility.d.ts.map +1 -1
- package/out/plausibility.js +19 -52
- package/out/plausibility.js.map +1 -1
- package/out/postcode/country-coherence.d.ts +53 -167
- package/out/postcode/country-coherence.d.ts.map +1 -1
- package/out/postcode/country-coherence.js +42 -259
- package/out/postcode/country-coherence.js.map +1 -1
- package/out/postcode/prefix.d.ts +18 -69
- package/out/postcode/prefix.d.ts.map +1 -1
- package/out/postcode/prefix.js +11 -78
- package/out/postcode/prefix.js.map +1 -1
- package/out/postcode/shape-coherence.d.ts +18 -85
- package/out/postcode/shape-coherence.d.ts.map +1 -1
- package/out/postcode/shape-coherence.js +11 -107
- 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 +32 -31
- package/out/remote-resolver.d.ts.map +1 -1
- package/out/remote-resolver.js +12 -20
- package/out/remote-resolver.js.map +1 -1
- package/out/rerank.d.ts +32 -46
- package/out/rerank.d.ts.map +1 -1
- package/out/rerank.js +16 -41
- package/out/rerank.js.map +1 -1
- package/out/resolve/passes.d.ts +108 -95
- package/out/resolve/passes.d.ts.map +1 -1
- package/out/resolve/passes.js +67 -126
- 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 +557 -0
- package/out/resolve.js.map +1 -0
- package/out/span-rescore.d.ts +56 -65
- package/out/span-rescore.d.ts.map +1 -1
- package/out/span-rescore.js +134 -132
- 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 +18 -30
- package/out/street/tier.d.ts.map +1 -1
- package/out/street/tier.js +43 -191
- 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 +22 -110
- 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 -989
- 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 -808
- 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/index.ts
CHANGED
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* `@mailwoman/resolver`
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* what used to be `@mailwoman/core/resolver`.
|
|
6
|
+
* `@mailwoman/resolver` is the address resolver implementation. It depends on
|
|
7
|
+
* `@mailwoman/spatial` (haversine) and `@mailwoman/codex` (USPS directionals) instead of
|
|
8
|
+
* reinventing them. The type interface stays in `@mailwoman/core/resolver`, so `core/pipeline`
|
|
9
|
+
* composes the resolver structurally without a package cycle. This barrel re-exports it, so
|
|
10
|
+
* `@mailwoman/resolver` is a complete drop-in for `@mailwoman/core/resolver`.
|
|
12
11
|
*/
|
|
13
12
|
|
|
14
13
|
export { RemoteResolver, serializableResolveOpts } from "#remote-resolver"
|
|
@@ -60,7 +59,4 @@ export {
|
|
|
60
59
|
|
|
61
60
|
export type { ResolvedPostcodeHit, ResolvedSpecificityInput } from "#admin/winner"
|
|
62
61
|
|
|
63
|
-
// The type contract + placetype helpers live in core (pure types, keep core a leaf). Re-export so
|
|
64
|
-
// consumers get the whole surface from `@mailwoman/resolver`.
|
|
65
|
-
|
|
66
62
|
export * from "#rerank"
|
package/lib/plausibility.ts
CHANGED
|
@@ -2,38 +2,12 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Resolution-plausibility guard (#727 / v7 excision arc).
|
|
7
|
-
*
|
|
8
|
-
* The 2026-07-15 coordinate-parity study
|
|
9
|
-
* (`docs/articles/evals/2026-07-15-v7-parity-floor-diagnosis.md`) found the neural parser is
|
|
10
|
-
* coordinate-safe on well-formed input (98.6% within 1 km of the rules parser through the same
|
|
11
|
-
* resolver) but produces a garbage-geocode tail on the bare-fragment / bare-state-name / US-highway
|
|
12
|
-
* classes — inputs like `California` or `6000, NSW, Australia` that resolve to nothing finer than a
|
|
13
|
-
* country centroid.
|
|
14
|
-
*
|
|
15
|
-
* This guard is the cheap post-resolve check for that tail: a resolved tree whose finest resolved
|
|
16
|
-
* place is only a `country` centroid is implausible for a structured address. It reads only the
|
|
17
|
-
* decorated tree — no gazetteer, no extra query — so it is free to run on every resolve. It is
|
|
18
|
-
* deliberately DIRECTION-AGNOSTIC about what the caller does with the signal: serve the result with
|
|
19
|
-
* a low-confidence marker, prefer a sibling parse hypothesis (the #727 k-best rerank), or decline to
|
|
20
|
-
* emit a coordinate. It is NOT a rules-fallback trigger — the v7 excision deletes the rules parser
|
|
21
|
-
* outright (operator ruling 2026-07-15), so no consumer may route through legacy rules on a trip.
|
|
22
|
-
*
|
|
23
|
-
* It deliberately does NOT flag region-tier resolutions: a US state or a province centroid
|
|
24
|
-
* (`Texas` → the TX centroid) is a legitimate coarse geocode, not garbage. Only "resolved no finer
|
|
25
|
-
* than a country" trips it.
|
|
26
5
|
*/
|
|
27
6
|
|
|
28
7
|
import type { ComponentTag } from "@mailwoman/codex/component"
|
|
29
8
|
import type { AddressNode, AddressTree } from "@mailwoman/core/decoder"
|
|
30
9
|
import type { CountryBBoxFact } from "@mailwoman/core/resolver"
|
|
31
10
|
|
|
32
|
-
/**
|
|
33
|
-
* Resolution granularity, coarse → fine. A resolved node's {@link AddressNode.tag} places it on this ladder; the
|
|
34
|
-
* geocode a caller serves comes from the FINEST resolved node. Tags absent here (unit, po_box, intersection halves, …)
|
|
35
|
-
* are treated as street-tier specificity when resolved.
|
|
36
|
-
*/
|
|
37
11
|
const RESOLUTION_TIER: Partial<Record<ComponentTag, number>> = {
|
|
38
12
|
country: 0,
|
|
39
13
|
region: 1,
|
|
@@ -49,34 +23,35 @@ const RESOLUTION_TIER: Partial<Record<ComponentTag, number>> = {
|
|
|
49
23
|
}
|
|
50
24
|
|
|
51
25
|
/**
|
|
52
|
-
*
|
|
26
|
+
* Holds the coordinate a caller would serve for a resolved tree, with the tag of the node that supplied it.
|
|
53
27
|
*/
|
|
54
28
|
export interface ResolvedCoordinate {
|
|
55
29
|
tag: ComponentTag
|
|
56
30
|
lat: number
|
|
57
31
|
lon: number
|
|
32
|
+
|
|
58
33
|
/**
|
|
59
|
-
*
|
|
34
|
+
* The canonical place URI, such as `wof:…`, when the resolver supplied one.
|
|
60
35
|
*/
|
|
61
|
-
placeID
|
|
36
|
+
placeID: string | null
|
|
62
37
|
}
|
|
63
38
|
|
|
64
39
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
40
|
+
* Returns the resolved coordinate at the finest granularity tier in the tree,
|
|
41
|
+
* preferring the earliest node on a tie.
|
|
42
|
+
* It returns `null` when no node has a `lat`/`lon`.
|
|
68
43
|
*/
|
|
69
44
|
export function finestResolvedCoordinate(tree: AddressTree): ResolvedCoordinate | null {
|
|
70
45
|
let best: ResolvedCoordinate | null = null
|
|
71
46
|
let bestTier = -1
|
|
72
47
|
|
|
73
48
|
const visit = (node: AddressNode): void => {
|
|
74
|
-
if (node.lat
|
|
49
|
+
if (node.lat != null && node.lon != null) {
|
|
75
50
|
const tier = RESOLUTION_TIER[node.tag] ?? 4
|
|
76
51
|
|
|
77
52
|
if (tier > bestTier) {
|
|
78
53
|
bestTier = tier
|
|
79
|
-
best = { tag: node.tag, lat: node.lat, lon: node.lon, placeID: node.placeID }
|
|
54
|
+
best = { tag: node.tag, lat: node.lat, lon: node.lon, placeID: node.placeID ?? null }
|
|
80
55
|
}
|
|
81
56
|
}
|
|
82
57
|
|
|
@@ -93,21 +68,15 @@ export function finestResolvedCoordinate(tree: AddressTree): ResolvedCoordinate
|
|
|
93
68
|
}
|
|
94
69
|
|
|
95
70
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* the mainland east coast; continental FR only; etc. A country absent here simply never trips the guard (fail-open).
|
|
100
|
-
*
|
|
101
|
-
* FALLBACK ROLE (survey candidate #2): these boxes are also baked into the candidate gazetteer's `country_bbox`
|
|
102
|
-
* manifest table at build time (`mailwoman/gazetteer-pipeline/coverage-manifest.ts` owns the measured record). When a
|
|
103
|
-
* caller supplies artifact-declared boxes ({@link PlausibilityOpts.countryBBoxes}), those REPLACE this table wholesale
|
|
104
|
-
* — the artifact speaks for itself, and a country absent from the artifact's table fails open exactly like an absent
|
|
105
|
-
* key here. This constant is the fallback for artifacts predating the manifest; grow the manifest record, not this.
|
|
71
|
+
* Lists coarse per-country bounding boxes, as `[latMin, latMax, lonMin, lonMax]`,
|
|
72
|
+
* for artifacts whose manifest declares none.
|
|
73
|
+
* A country without a box never trips the guard.
|
|
106
74
|
*/
|
|
107
75
|
export const COUNTRY_BBOX: Readonly<Record<string, readonly [number, number, number, number]>> = {
|
|
108
76
|
US: [18, 72, -180, -66],
|
|
109
77
|
AU: [-44, -10, 112, 154],
|
|
110
78
|
BR: [-34, 6, -74, -34],
|
|
79
|
+
CN: [15.7, 53.6, 73.4, 135.1],
|
|
111
80
|
CZ: [48, 51.5, 12, 19],
|
|
112
81
|
DE: [47, 55.5, 5.5, 15.5],
|
|
113
82
|
ES: [35, 44, -10, 5],
|
|
@@ -115,8 +84,11 @@ export const COUNTRY_BBOX: Readonly<Record<string, readonly [number, number, num
|
|
|
115
84
|
GB: [49, 61, -8.7, 2],
|
|
116
85
|
HR: [42, 46.6, 13, 19.5],
|
|
117
86
|
IN: [6, 36, 68, 98],
|
|
87
|
+
IT: [35.4, 47.1, 6.6, 18.6],
|
|
88
|
+
JP: [20.2, 45.7, 122.8, 154.1],
|
|
118
89
|
NL: [50.7, 53.7, 3.3, 7.3],
|
|
119
90
|
NO: [57, 71.5, 4, 31],
|
|
91
|
+
NZ: [-52.7, -29.1, -180, 180],
|
|
120
92
|
PL: [49, 55, 14, 24.2],
|
|
121
93
|
PT: [36.5, 42.2, -9.6, -6.1],
|
|
122
94
|
RO: [43.5, 48.3, 20, 30],
|
|
@@ -126,11 +98,8 @@ export const COUNTRY_BBOX: Readonly<Record<string, readonly [number, number, num
|
|
|
126
98
|
}
|
|
127
99
|
|
|
128
100
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* When `bboxes` (artifact-declared boxes, {@link GazetteerArtifactCoverage.countryBBoxes}) is supplied it REPLACES the
|
|
132
|
-
* built-in {@link COUNTRY_BBOX} table wholesale — absence from the artifact's table fails open, same semantic as an
|
|
133
|
-
* absent constant key. Omitted → the constant, byte-identical to the pre-manifest behavior.
|
|
101
|
+
* Reports whether a coordinate lies outside the country's bounding box, using `bboxes` in
|
|
102
|
+
* place of {@link COUNTRY_BBOX} when supplied and returning `false` for a country with no box.
|
|
134
103
|
*/
|
|
135
104
|
export function outsideExpectedCountry(
|
|
136
105
|
countryCode: string,
|
|
@@ -160,40 +129,44 @@ export function outsideExpectedCountry(
|
|
|
160
129
|
*/
|
|
161
130
|
export interface PlausibilityVerdict {
|
|
162
131
|
implausible: boolean
|
|
132
|
+
|
|
163
133
|
/**
|
|
164
|
-
*
|
|
165
|
-
* `
|
|
134
|
+
* Why the resolution is implausible, set only when `implausible` is true:
|
|
135
|
+
* `country-centroid` or `outside-expected-country`.
|
|
166
136
|
*/
|
|
167
|
-
reason
|
|
137
|
+
reason: "country-centroid" | "outside-expected-country" | null
|
|
138
|
+
|
|
168
139
|
/**
|
|
169
|
-
* The coordinate the verdict was
|
|
140
|
+
* The coordinate the verdict was based on, present when anything resolved.
|
|
170
141
|
*/
|
|
171
|
-
coordinate
|
|
142
|
+
coordinate: ResolvedCoordinate | null
|
|
172
143
|
}
|
|
173
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Configures {@linkcode isImplausibleResolution} with the country the address should
|
|
147
|
+
* fall in and optional artifact-declared bounding boxes.
|
|
148
|
+
*/
|
|
174
149
|
export interface PlausibilityOpts {
|
|
175
150
|
/**
|
|
176
|
-
* ISO-2 country the resolution
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* only in the receipt harness, so the shipped residual read 5/321 while the receipt said 3/321).
|
|
151
|
+
* The ISO 3166-1 alpha-2 country the resolution should land in.
|
|
152
|
+
*
|
|
153
|
+
* A set `expectedCountry` enables the bounding-box check that catches cross-country
|
|
154
|
+
* jumps the country-centroid check cannot.
|
|
181
155
|
*/
|
|
182
156
|
expectedCountry?: string
|
|
157
|
+
|
|
183
158
|
/**
|
|
184
|
-
* Artifact-declared
|
|
185
|
-
*
|
|
186
|
-
* wholesale; omitted → the constant (byte-identical fallback for artifacts predating the manifest).
|
|
159
|
+
* Artifact-declared country bounding boxes that replace the built-in
|
|
160
|
+
* {@link COUNTRY_BBOX} table entirely when supplied.
|
|
187
161
|
*/
|
|
188
162
|
countryBBoxes?: ReadonlyMap<string, CountryBBoxFact>
|
|
189
163
|
}
|
|
190
164
|
|
|
191
165
|
/**
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* to serve.
|
|
166
|
+
* Decides whether a resolved tree's coordinate is implausible: a bare country centroid,
|
|
167
|
+
* or a point outside `expectedCountry`'s bounding box.
|
|
168
|
+
*
|
|
169
|
+
* An unresolved tree is plausible because it serves no coordinate.
|
|
197
170
|
*/
|
|
198
171
|
export function isImplausibleResolution(tree: AddressTree, opts: PlausibilityOpts = {}): PlausibilityVerdict {
|
|
199
172
|
const coordinate = finestResolvedCoordinate(tree)
|
|
@@ -210,5 +183,5 @@ export function isImplausibleResolution(tree: AddressTree, opts: PlausibilityOpt
|
|
|
210
183
|
return { implausible: true, reason: "outside-expected-country", coordinate }
|
|
211
184
|
}
|
|
212
185
|
|
|
213
|
-
return { implausible: false, coordinate: coordinate ??
|
|
186
|
+
return { implausible: false, reason: null, coordinate: coordinate ?? null }
|
|
214
187
|
}
|