@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.
Files changed (134) hide show
  1. package/README.md +9 -7
  2. package/lib/admin/coherence-passes.ts +21 -161
  3. package/lib/admin/containment.ts +12 -30
  4. package/lib/admin/jp-municipality.ts +20 -13
  5. package/lib/admin/winner.ts +30 -62
  6. package/lib/backend-capabilities.ts +25 -24
  7. package/lib/bare-toponym-race.ts +73 -39
  8. package/lib/decorate-node.ts +17 -41
  9. package/lib/fold-name.ts +5 -18
  10. package/lib/index.ts +5 -9
  11. package/lib/plausibility.ts +37 -63
  12. package/lib/postcode/country-coherence.ts +64 -284
  13. package/lib/postcode/prefix.ts +20 -84
  14. package/lib/postcode/shape-coherence.ts +23 -113
  15. package/lib/remote-resolver.ts +32 -29
  16. package/lib/rerank.ts +34 -50
  17. package/lib/resolve/passes.ts +145 -148
  18. package/lib/resolve.ts +726 -0
  19. package/lib/span-rescore.ts +215 -172
  20. package/lib/street/evidence.ts +65 -73
  21. package/lib/street/tier.ts +33 -175
  22. package/lib/toponym-prior.ts +53 -179
  23. package/out/admin/coherence-passes.d.ts +18 -69
  24. package/out/admin/coherence-passes.d.ts.map +1 -1
  25. package/out/admin/coherence-passes.js +19 -161
  26. package/out/admin/coherence-passes.js.map +1 -1
  27. package/out/admin/containment.d.ts +11 -29
  28. package/out/admin/containment.d.ts.map +1 -1
  29. package/out/admin/containment.js +12 -30
  30. package/out/admin/containment.js.map +1 -1
  31. package/out/admin/jp-municipality.d.ts +20 -13
  32. package/out/admin/jp-municipality.d.ts.map +1 -1
  33. package/out/admin/jp-municipality.js +18 -12
  34. package/out/admin/jp-municipality.js.map +1 -1
  35. package/out/admin/winner.d.ts +30 -62
  36. package/out/admin/winner.d.ts.map +1 -1
  37. package/out/admin/winner.js +18 -51
  38. package/out/admin/winner.js.map +1 -1
  39. package/out/{admin/index.d.ts → admin.d.ts} +1 -1
  40. package/out/admin.d.ts.map +1 -0
  41. package/out/{admin/index.js → admin.js} +1 -1
  42. package/out/admin.js.map +1 -0
  43. package/out/backend-capabilities.d.ts +18 -19
  44. package/out/backend-capabilities.d.ts.map +1 -1
  45. package/out/backend-capabilities.js +25 -24
  46. package/out/backend-capabilities.js.map +1 -1
  47. package/out/bare-toponym-race.d.ts +56 -28
  48. package/out/bare-toponym-race.d.ts.map +1 -1
  49. package/out/bare-toponym-race.js +69 -37
  50. package/out/bare-toponym-race.js.map +1 -1
  51. package/out/decorate-node.d.ts +6 -8
  52. package/out/decorate-node.d.ts.map +1 -1
  53. package/out/decorate-node.js +17 -41
  54. package/out/decorate-node.js.map +1 -1
  55. package/out/fold-name.d.ts +5 -18
  56. package/out/fold-name.d.ts.map +1 -1
  57. package/out/fold-name.js +5 -18
  58. package/out/fold-name.js.map +1 -1
  59. package/out/index.d.ts +5 -6
  60. package/out/index.d.ts.map +1 -1
  61. package/out/index.js +5 -8
  62. package/out/index.js.map +1 -1
  63. package/out/plausibility.d.ts +29 -58
  64. package/out/plausibility.d.ts.map +1 -1
  65. package/out/plausibility.js +16 -49
  66. package/out/plausibility.js.map +1 -1
  67. package/out/postcode/country-coherence.d.ts +48 -162
  68. package/out/postcode/country-coherence.d.ts.map +1 -1
  69. package/out/postcode/country-coherence.js +19 -252
  70. package/out/postcode/country-coherence.js.map +1 -1
  71. package/out/postcode/prefix.d.ts +17 -68
  72. package/out/postcode/prefix.d.ts.map +1 -1
  73. package/out/postcode/prefix.js +8 -77
  74. package/out/postcode/prefix.js.map +1 -1
  75. package/out/postcode/shape-coherence.d.ts +17 -84
  76. package/out/postcode/shape-coherence.d.ts.map +1 -1
  77. package/out/postcode/shape-coherence.js +9 -105
  78. package/out/postcode/shape-coherence.js.map +1 -1
  79. package/out/{postcode/index.d.ts → postcode.d.ts} +1 -1
  80. package/out/postcode.d.ts.map +1 -0
  81. package/out/{postcode/index.js → postcode.js} +1 -1
  82. package/out/postcode.js.map +1 -0
  83. package/out/remote-resolver.d.ts +27 -28
  84. package/out/remote-resolver.d.ts.map +1 -1
  85. package/out/remote-resolver.js +9 -19
  86. package/out/remote-resolver.js.map +1 -1
  87. package/out/rerank.d.ts +28 -45
  88. package/out/rerank.d.ts.map +1 -1
  89. package/out/rerank.js +13 -38
  90. package/out/rerank.js.map +1 -1
  91. package/out/resolve/passes.d.ts +97 -86
  92. package/out/resolve/passes.d.ts.map +1 -1
  93. package/out/resolve/passes.js +40 -105
  94. package/out/resolve/passes.js.map +1 -1
  95. package/out/resolve.d.ts +15 -0
  96. package/out/resolve.d.ts.map +1 -0
  97. package/out/resolve.js +543 -0
  98. package/out/resolve.js.map +1 -0
  99. package/out/span-rescore.d.ts +51 -64
  100. package/out/span-rescore.d.ts.map +1 -1
  101. package/out/span-rescore.js +132 -130
  102. package/out/span-rescore.js.map +1 -1
  103. package/out/street/evidence.d.ts +56 -61
  104. package/out/street/evidence.d.ts.map +1 -1
  105. package/out/street/evidence.js +22 -46
  106. package/out/street/evidence.js.map +1 -1
  107. package/out/street/tier.d.ts +17 -29
  108. package/out/street/tier.d.ts.map +1 -1
  109. package/out/street/tier.js +27 -175
  110. package/out/street/tier.js.map +1 -1
  111. package/out/{street/index.d.ts → street.d.ts} +1 -1
  112. package/out/street.d.ts.map +1 -0
  113. package/out/{street/index.js → street.js} +1 -1
  114. package/out/street.js.map +1 -0
  115. package/out/toponym-prior.d.ts +21 -109
  116. package/out/toponym-prior.d.ts.map +1 -1
  117. package/out/toponym-prior.js +41 -170
  118. package/out/toponym-prior.js.map +1 -1
  119. package/package.json +44 -147
  120. package/lib/resolve/index.ts +0 -995
  121. package/out/admin/index.d.ts.map +0 -1
  122. package/out/admin/index.js.map +0 -1
  123. package/out/postcode/index.d.ts.map +0 -1
  124. package/out/postcode/index.js.map +0 -1
  125. package/out/resolve/index.d.ts +0 -20
  126. package/out/resolve/index.d.ts.map +0 -1
  127. package/out/resolve/index.js +0 -807
  128. package/out/resolve/index.js.map +0 -1
  129. package/out/street/index.d.ts.map +0 -1
  130. package/out/street/index.js.map +0 -1
  131. package/vitest.config.ts +0 -38
  132. /package/lib/{admin/index.ts → admin.ts} +0 -0
  133. /package/lib/{postcode/index.ts → postcode.ts} +0 -0
  134. /package/lib/{street/index.ts → street.ts} +0 -0
@@ -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 { AddressNode, AddressTree, ComponentTag } from "@mailwoman/core/decoder"
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
- * A resolved place lifted off the tree — the coordinate a caller would serve, plus its granularity tag.
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
- * Canonical place URI (`wof:…`) when the resolver supplied one.
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
- * Walk a resolved {@link AddressTree} and return the FINEST resolved place — the node carrying a resolver-supplied
65
- * coordinate at the deepest granularity tier. Returns `null` when nothing resolved (no node carries a `lat`/`lon`).
66
- * Ties break toward the first node in document order.
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
- * Coarse per-country bounding boxes `[latMin, latMax, lonMin, lonMax]` for the cross-country guard (guard B). These are
96
- * DELIBERATELY rough — a guard needs "obviously the wrong country", not cartography — and they mirror the boxes the
97
- * 2026-07-15 coordinate-parity receipt harness measured with (`scratchpad/coord-parity.mjs`). The US box spans Alaska →
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
- * True when the coordinate lies outside `countryCode`'s coarse bbox. Unknown country codes are fail-open (false).
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
- * Set when `implausible` is true. `country-centroid` = resolved no finer than a country (guard A);
164
- * `outside-expected-country` = the served coordinate lies outside the expected country's bbox (guard B).
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 drawn from, when anything resolved.
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 is EXPECTED to land in, when the caller knows it (a locale hint, a parsed country, a
176
- * fixture's gold country). Enables guard B: a coordinate outside this country's coarse bbox is implausible — the
177
- * cross-country-jump class guard A structurally cannot catch (`1210a IA 10 W IA` → a coordinate ~10,000 km from the
178
- * US was country-centroid-free and sailed through until guard B landed here, 2026-07-17; previously the check lived
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 guard-B boxes (the loaded gazetteer's `country_bbox` manifest, via
184
- * `resolver.artifactCoverage?.countryBBoxes`). When supplied they replace the built-in {@link COUNTRY_BBOX} table
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
- * Decide whether a resolved tree's geocode is implausible for a structured address — the cheap guard the v7 hybrid
192
- * check runs after routing an input to the neural parser (#38). Trips when the finest resolved place is a bare
193
- * `country` centroid (guard A), or — when the caller supplies `expectedCountry` — when the served coordinate falls
194
- * outside that country's coarse bbox (guard B). An unresolved tree (nothing to serve) is plausible: there is no garbage
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)