@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/plausibility.ts
CHANGED
|
@@ -2,37 +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
|
-
import type {
|
|
7
|
+
import type { ComponentTag } from "@mailwoman/codex/component"
|
|
8
|
+
import type { AddressNode, AddressTree } from "@mailwoman/core/decoder"
|
|
29
9
|
import type { CountryBBoxFact } from "@mailwoman/core/resolver"
|
|
30
10
|
|
|
31
|
-
/**
|
|
32
|
-
* Resolution granularity, coarse → fine. A resolved node's {@link AddressNode.tag} places it on this ladder; the
|
|
33
|
-
* geocode a caller serves comes from the FINEST resolved node. Tags absent here (unit, po_box, intersection halves, …)
|
|
34
|
-
* are treated as street-tier specificity when resolved.
|
|
35
|
-
*/
|
|
36
11
|
const RESOLUTION_TIER: Partial<Record<ComponentTag, number>> = {
|
|
37
12
|
country: 0,
|
|
38
13
|
region: 1,
|
|
@@ -48,22 +23,23 @@ const RESOLUTION_TIER: Partial<Record<ComponentTag, number>> = {
|
|
|
48
23
|
}
|
|
49
24
|
|
|
50
25
|
/**
|
|
51
|
-
*
|
|
26
|
+
* Holds the coordinate a caller would serve for a resolved tree, with the tag of the node that supplied it.
|
|
52
27
|
*/
|
|
53
28
|
export interface ResolvedCoordinate {
|
|
54
29
|
tag: ComponentTag
|
|
55
30
|
lat: number
|
|
56
31
|
lon: number
|
|
32
|
+
|
|
57
33
|
/**
|
|
58
|
-
*
|
|
34
|
+
* The canonical place URI, such as `wof:…`, when the resolver supplied one.
|
|
59
35
|
*/
|
|
60
36
|
placeID?: string
|
|
61
37
|
}
|
|
62
38
|
|
|
63
39
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
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`.
|
|
67
43
|
*/
|
|
68
44
|
export function finestResolvedCoordinate(tree: AddressTree): ResolvedCoordinate | null {
|
|
69
45
|
let best: ResolvedCoordinate | null = null
|
|
@@ -92,21 +68,15 @@ export function finestResolvedCoordinate(tree: AddressTree): ResolvedCoordinate
|
|
|
92
68
|
}
|
|
93
69
|
|
|
94
70
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* the mainland east coast; continental FR only; etc. A country absent here simply never trips the guard (fail-open).
|
|
99
|
-
*
|
|
100
|
-
* FALLBACK ROLE (survey candidate #2): these boxes are also baked into the candidate gazetteer's `country_bbox`
|
|
101
|
-
* manifest table at build time (`mailwoman/gazetteer-pipeline/coverage-manifest.ts` owns the measured record). When a
|
|
102
|
-
* caller supplies artifact-declared boxes ({@link PlausibilityOpts.countryBBoxes}), those REPLACE this table wholesale
|
|
103
|
-
* — the artifact speaks for itself, and a country absent from the artifact's table fails open exactly like an absent
|
|
104
|
-
* 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.
|
|
105
74
|
*/
|
|
106
75
|
export const COUNTRY_BBOX: Readonly<Record<string, readonly [number, number, number, number]>> = {
|
|
107
76
|
US: [18, 72, -180, -66],
|
|
108
77
|
AU: [-44, -10, 112, 154],
|
|
109
78
|
BR: [-34, 6, -74, -34],
|
|
79
|
+
CN: [15.7, 53.6, 73.4, 135.1],
|
|
110
80
|
CZ: [48, 51.5, 12, 19],
|
|
111
81
|
DE: [47, 55.5, 5.5, 15.5],
|
|
112
82
|
ES: [35, 44, -10, 5],
|
|
@@ -114,8 +84,11 @@ export const COUNTRY_BBOX: Readonly<Record<string, readonly [number, number, num
|
|
|
114
84
|
GB: [49, 61, -8.7, 2],
|
|
115
85
|
HR: [42, 46.6, 13, 19.5],
|
|
116
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],
|
|
117
89
|
NL: [50.7, 53.7, 3.3, 7.3],
|
|
118
90
|
NO: [57, 71.5, 4, 31],
|
|
91
|
+
NZ: [-52.7, -29.1, -180, 180],
|
|
119
92
|
PL: [49, 55, 14, 24.2],
|
|
120
93
|
PT: [36.5, 42.2, -9.6, -6.1],
|
|
121
94
|
RO: [43.5, 48.3, 20, 30],
|
|
@@ -125,11 +98,8 @@ export const COUNTRY_BBOX: Readonly<Record<string, readonly [number, number, num
|
|
|
125
98
|
}
|
|
126
99
|
|
|
127
100
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* When `bboxes` (artifact-declared boxes, {@link GazetteerArtifactCoverage.countryBBoxes}) is supplied it REPLACES the
|
|
131
|
-
* built-in {@link COUNTRY_BBOX} table wholesale — absence from the artifact's table fails open, same semantic as an
|
|
132
|
-
* 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.
|
|
133
103
|
*/
|
|
134
104
|
export function outsideExpectedCountry(
|
|
135
105
|
countryCode: string,
|
|
@@ -159,40 +129,44 @@ export function outsideExpectedCountry(
|
|
|
159
129
|
*/
|
|
160
130
|
export interface PlausibilityVerdict {
|
|
161
131
|
implausible: boolean
|
|
132
|
+
|
|
162
133
|
/**
|
|
163
|
-
*
|
|
164
|
-
* `
|
|
134
|
+
* Why the resolution is implausible, set only when `implausible` is true:
|
|
135
|
+
* `country-centroid` or `outside-expected-country`.
|
|
165
136
|
*/
|
|
166
137
|
reason?: "country-centroid" | "outside-expected-country"
|
|
138
|
+
|
|
167
139
|
/**
|
|
168
|
-
* The coordinate the verdict was
|
|
140
|
+
* The coordinate the verdict was based on, present when anything resolved.
|
|
169
141
|
*/
|
|
170
142
|
coordinate?: ResolvedCoordinate
|
|
171
143
|
}
|
|
172
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Configures {@linkcode isImplausibleResolution} with the country the address should
|
|
147
|
+
* fall in and optional artifact-declared bounding boxes.
|
|
148
|
+
*/
|
|
173
149
|
export interface PlausibilityOpts {
|
|
174
150
|
/**
|
|
175
|
-
* ISO-2 country the resolution
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* 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.
|
|
180
155
|
*/
|
|
181
156
|
expectedCountry?: string
|
|
157
|
+
|
|
182
158
|
/**
|
|
183
|
-
* Artifact-declared
|
|
184
|
-
*
|
|
185
|
-
* 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.
|
|
186
161
|
*/
|
|
187
162
|
countryBBoxes?: ReadonlyMap<string, CountryBBoxFact>
|
|
188
163
|
}
|
|
189
164
|
|
|
190
165
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* 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.
|
|
196
170
|
*/
|
|
197
171
|
export function isImplausibleResolution(tree: AddressTree, opts: PlausibilityOpts = {}): PlausibilityVerdict {
|
|
198
172
|
const coordinate = finestResolvedCoordinate(tree)
|