@mailwoman/resolver 10.0.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 +19 -160
  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 +69 -37
  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 +35 -62
  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 +144 -147
  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 +17 -68
  24. package/out/admin/coherence-passes.d.ts.map +1 -1
  25. package/out/admin/coherence-passes.js +18 -160
  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 +54 -27
  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 +27 -57
  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 +95 -85
  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 -989
  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 -808
  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,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,22 +23,23 @@ const RESOLUTION_TIER: Partial<Record<ComponentTag, number>> = {
49
23
  }
50
24
 
51
25
  /**
52
- * 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.
53
27
  */
54
28
  export interface ResolvedCoordinate {
55
29
  tag: ComponentTag
56
30
  lat: number
57
31
  lon: number
32
+
58
33
  /**
59
- * Canonical place URI (`wof:…`) when the resolver supplied one.
34
+ * The canonical place URI, such as `wof:…`, when the resolver supplied one.
60
35
  */
61
36
  placeID?: string
62
37
  }
63
38
 
64
39
  /**
65
- * Walk a resolved {@link AddressTree} and return the FINEST resolved place — the node carrying a resolver-supplied
66
- * coordinate at the deepest granularity tier. Returns `null` when nothing resolved (no node carries a `lat`/`lon`).
67
- * 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`.
68
43
  */
69
44
  export function finestResolvedCoordinate(tree: AddressTree): ResolvedCoordinate | null {
70
45
  let best: ResolvedCoordinate | null = null
@@ -93,21 +68,15 @@ export function finestResolvedCoordinate(tree: AddressTree): ResolvedCoordinate
93
68
  }
94
69
 
95
70
  /**
96
- * Coarse per-country bounding boxes `[latMin, latMax, lonMin, lonMax]` for the cross-country guard (guard B). These are
97
- * DELIBERATELY rough — a guard needs "obviously the wrong country", not cartography — and they mirror the boxes the
98
- * 2026-07-15 coordinate-parity receipt harness measured with (`scratchpad/coord-parity.mjs`). The US box spans Alaska →
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
- * True when the coordinate lies outside `countryCode`'s coarse bbox. Unknown country codes are fail-open (false).
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
- * Set when `implausible` is true. `country-centroid` = resolved no finer than a country (guard A);
165
- * `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`.
166
136
  */
167
137
  reason?: "country-centroid" | "outside-expected-country"
138
+
168
139
  /**
169
- * The coordinate the verdict was drawn from, when anything resolved.
140
+ * The coordinate the verdict was based on, present when anything resolved.
170
141
  */
171
142
  coordinate?: ResolvedCoordinate
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 is EXPECTED to land in, when the caller knows it (a locale hint, a parsed country, a
177
- * fixture's gold country). Enables guard B: a coordinate outside this country's coarse bbox is implausible — the
178
- * cross-country-jump class guard A structurally cannot catch (`1210a IA 10 W IA` → a coordinate ~10,000 km from the
179
- * US was country-centroid-free and sailed through until guard B landed here, 2026-07-17; previously the check lived
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 guard-B boxes (the loaded gazetteer's `country_bbox` manifest, via
185
- * `resolver.artifactCoverage?.countryBBoxes`). When supplied they replace the built-in {@link COUNTRY_BBOX} table
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
- * Decide whether a resolved tree's geocode is implausible for a structured address — the cheap guard the v7 hybrid
193
- * check runs after routing an input to the neural parser (#38). Trips when the finest resolved place is a bare
194
- * `country` centroid (guard A), or — when the caller supplies `expectedCountry` — when the served coordinate falls
195
- * outside that country's coarse bbox (guard B). An unresolved tree (nothing to serve) is plausible: there is no garbage
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)