@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.
Files changed (134) hide show
  1. package/README.md +9 -7
  2. package/lib/admin/coherence-passes.ts +31 -172
  3. package/lib/admin/containment.ts +15 -33
  4. package/lib/admin/jp-municipality.ts +21 -14
  5. package/lib/admin/winner.ts +37 -69
  6. package/lib/backend-capabilities.ts +28 -27
  7. package/lib/bare-toponym-race.ts +69 -37
  8. package/lib/decorate-node.ts +25 -49
  9. package/lib/fold-name.ts +5 -18
  10. package/lib/index.ts +5 -9
  11. package/lib/plausibility.ts +41 -68
  12. package/lib/postcode/country-coherence.ts +92 -296
  13. package/lib/postcode/prefix.ts +24 -86
  14. package/lib/postcode/shape-coherence.ts +26 -116
  15. package/lib/remote-resolver.ts +38 -33
  16. package/lib/rerank.ts +41 -54
  17. package/lib/resolve/passes.ts +188 -177
  18. package/lib/resolve.ts +744 -0
  19. package/lib/span-rescore.ts +219 -175
  20. package/lib/street/evidence.ts +65 -73
  21. package/lib/street/tier.ts +51 -194
  22. package/lib/toponym-prior.ts +54 -180
  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 +24 -166
  26. package/out/admin/coherence-passes.js.map +1 -1
  27. package/out/admin/containment.d.ts +13 -31
  28. package/out/admin/containment.d.ts.map +1 -1
  29. package/out/admin/containment.js +13 -31
  30. package/out/admin/containment.js.map +1 -1
  31. package/out/admin/jp-municipality.d.ts +21 -14
  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 +32 -64
  36. package/out/admin/winner.d.ts.map +1 -1
  37. package/out/admin/winner.js +23 -56
  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 +19 -20
  44. package/out/backend-capabilities.d.ts.map +1 -1
  45. package/out/backend-capabilities.js +28 -26
  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 +25 -49
  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 +30 -60
  64. package/out/plausibility.d.ts.map +1 -1
  65. package/out/plausibility.js +19 -52
  66. package/out/plausibility.js.map +1 -1
  67. package/out/postcode/country-coherence.d.ts +53 -167
  68. package/out/postcode/country-coherence.d.ts.map +1 -1
  69. package/out/postcode/country-coherence.js +42 -259
  70. package/out/postcode/country-coherence.js.map +1 -1
  71. package/out/postcode/prefix.d.ts +18 -69
  72. package/out/postcode/prefix.d.ts.map +1 -1
  73. package/out/postcode/prefix.js +11 -78
  74. package/out/postcode/prefix.js.map +1 -1
  75. package/out/postcode/shape-coherence.d.ts +18 -85
  76. package/out/postcode/shape-coherence.d.ts.map +1 -1
  77. package/out/postcode/shape-coherence.js +11 -107
  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 +32 -31
  84. package/out/remote-resolver.d.ts.map +1 -1
  85. package/out/remote-resolver.js +12 -20
  86. package/out/remote-resolver.js.map +1 -1
  87. package/out/rerank.d.ts +32 -46
  88. package/out/rerank.d.ts.map +1 -1
  89. package/out/rerank.js +16 -41
  90. package/out/rerank.js.map +1 -1
  91. package/out/resolve/passes.d.ts +108 -95
  92. package/out/resolve/passes.d.ts.map +1 -1
  93. package/out/resolve/passes.js +67 -126
  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 +557 -0
  98. package/out/resolve.js.map +1 -0
  99. package/out/span-rescore.d.ts +56 -65
  100. package/out/span-rescore.d.ts.map +1 -1
  101. package/out/span-rescore.js +134 -132
  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 +18 -30
  108. package/out/street/tier.d.ts.map +1 -1
  109. package/out/street/tier.js +43 -191
  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 +22 -110
  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,41 +2,21 @@
2
2
  * @copyright Sister Software
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
- *
6
- * The street-level coordinate tiers, in cascade order: exact address point (#476), house-number
7
- * interpolation (#483), then the street-centroid fallback. Each answers WHERE, never WHICH PLACE —
8
- * they stamp a coordinate onto the STREET node's metadata and never touch admin resolution.
9
- *
10
- * Split out of `resolve.ts` so the resolver file holds the walk and the admin-coherence passes, and
11
- * this one holds the tiers. The FR voie-type folding lives here because only the street-centroid
12
- * tier consults it.
13
5
  */
14
6
 
7
+ import { isFrenchStreetWord } from "@mailwoman/codex/fr"
15
8
  import { isStreetDirectionalToken } from "@mailwoman/codex/us"
16
9
  import { collectNodes, walkNodes, type AddressNode } from "@mailwoman/core/decoder"
17
10
  import type { AddressPointLookup, InterpolationLookup, StreetCentroidLookup } from "@mailwoman/core/resolver"
11
+ import { TextSpliterator } from "spliterator"
18
12
 
19
13
  import { foldName } from "#fold-name"
20
14
 
21
- /**
22
- * Street-name component tags that, with the street node itself, reconstruct the full street string.
23
- */
24
15
  const STREET_NAME_TAGS = new Set(["street", "street_prefix", "street_prefix_particle", "street_suffix"])
25
16
 
26
- /**
27
- * Reassemble the full street string from the street node's subtree (#483 coverage fix). The parser nests the
28
- * directional/suffix as `street_prefix`/`street_suffix` CHILDREN of `street` (containment.ts), so `street.value` alone
29
- * is the bare base name ("Sheldon" for "East Sheldon Rd") — which misses the coordinate extracts keyed on the FULL
30
- * normalized name. Collect street + its prefix/particle/suffix descendants (NOT house_number/unit, which also nest
31
- * under street), order by span offset, and join.
32
- */
33
17
  function assembleStreetValue(streetNode: AddressNode, directionalUnit?: AddressNode): string {
34
- const parts = collectNodes([streetNode], (n) => STREET_NAME_TAGS.has(n.tag) && n.value.trim().length > 0)
18
+ const parts = collectNodes([streetNode], (n) => STREET_NAME_TAGS.has(n.tag) && n.value.trim().length)
35
19
 
36
- // #718 admin-tail: a directional quadrant the model mis-tagged `unit` ("1532 Taylor Street NE" →
37
- // [unit] "NE") folds back into the street key by span order, so the situs/interp lookup matches the
38
- // extract's "taylor street northeast" (the lookup normalizer expands the abbreviation). Lookup-key
39
- // only — the parse output and admin resolution are untouched. Byte-stable when absent (undefined).
40
20
  if (directionalUnit && directionalUnit.value.trim()) {
41
21
  parts.push(directionalUnit)
42
22
  }
@@ -46,34 +26,16 @@ function assembleStreetValue(streetNode: AddressNode, directionalUnit?: AddressN
46
26
  return parts.map((n) => n.value.trim()).join(" ")
47
27
  }
48
28
 
49
- /**
50
- * Directional quadrant values the model sometimes emits as a `unit` node instead of inside the street subtree (#718
51
- * admin-tail diagnostic: ~19% of the admin-fallback tail, 83% of DC). Folded into the street lookup key by
52
- * {@link assembleStreetValue}; the situs/interp lookup normalizer expands the abbreviation ("ne" → "northeast") so the
53
- * extract's full street name matches.
54
- */
55
- // The 8 USPS cardinals/intercardinals (abbrev or name) — @codex/us owns the canonical table (#215).
56
29
  const isDirectionalUnit = (value: string): boolean => isStreetDirectionalToken(value.replaceAll(".", ""))
57
30
 
58
- /**
59
- * Address-point tier (#476): find `street` + `house_number` in the tree (first occurrence, depth-first), scope by the
60
- * tree's postcode/locality values, and on an exact hit stamp the point onto the STREET node's metadata. Additive only —
61
- * admin resolution is never altered.
62
- */
63
- /**
64
- * Half-width (degrees) of the bbox derived from a resolved locality centroid for the #247 OSM bbox fall-through. ~0.25°
65
- * ≈ 28 km N–S — generous enough for a large metro whose centroid sits off the queried point, while the EXACT `(street,
66
- * number)` match keeps a cross-commune collision rare. The proper fix is per-point scope backfill (the OSM association
67
- * / point-in-polygon pass, #250); this is the coverage stopgap until then.
68
- */
69
31
  const LOCALITY_BBOX_RADIUS_DEG = 0.25
70
32
 
71
33
  /**
72
- * Every `(street, house_number)` pair the tree offers, nearest pair first: the house number whose span sits closest to
73
- * the street's, a number BEFORE the street winning a tie. A venue-led string parses more than one of each — `Bar 1802,
74
- * 22 Rue Pascal, 75005 Paris, France` carries two house numbers and one street, and `22` is the one written beside `Rue
75
- * Pascal`. The tiers probe the pairs in this order and stop at the first register hit, and the pair that hit is what
76
- * the result names; a walk that took "the first node of each tag" paired whatever the traversal met first.
34
+ * Returns every `(street, house_number)` pair in the tree, ordered by how close the
35
+ * two spans sit, with a number before the street winning a tie.
36
+ *
37
+ * A venue-led address can contain several house numbers.
38
+ * The tiers take the first pair that hits the register.
77
39
  */
78
40
  export function streetNumberPairs(
79
41
  roots: readonly AddressNode[]
@@ -96,10 +58,6 @@ export function streetNumberPairs(
96
58
  return pairs.toSorted((a, b) => pairGap(a) - pairGap(b))
97
59
  }
98
60
 
99
- /**
100
- * Characters between a house number and its street; a number after the street costs one extra so the tie goes to the
101
- * number written before it, the order every Latin-script address system this resolver serves writes.
102
- */
103
61
  function pairGap(pair: { street: AddressNode; houseNumber: AddressNode }): number {
104
62
  const { street, houseNumber } = pair
105
63
 
@@ -108,25 +66,27 @@ function pairGap(pair: { street: AddressNode; houseNumber: AddressNode }): numbe
108
66
  return houseNumber.start - street.end + 1
109
67
  }
110
68
 
111
- /**
112
- * The first node of `tag` in document order whose value is non-blank, when the tree carries one.
113
- */
114
- function firstOfTag(roots: readonly AddressNode[], tag: AddressNode["tag"]): AddressNode | undefined {
69
+ function firstOfTag(roots: readonly AddressNode[], tag: AddressNode["tag"]): AddressNode | null {
115
70
  for (const node of walkNodes(roots)) {
116
71
  if (node.tag === tag && node.value.trim()) return node
117
72
  }
118
73
 
119
- return undefined
74
+ return null
120
75
  }
121
76
 
77
+ /**
78
+ * Stamps the street with an exact address-point coordinate from the first street
79
+ * and number pair the lookup finds.
80
+ *
81
+ * With `bboxFallback`, the lookup is also bounded to a box around the resolved locality's coordinate.
82
+ */
122
83
  export function applyAddressPoint(roots: AddressNode[], lookup: AddressPointLookup, bboxFallback?: boolean): void {
123
84
  const pairs = streetNumberPairs(roots)
124
85
  const directionalUnit = [...walkNodes(roots)].find((n) => n.tag === "unit" && isDirectionalUnit(n.value))
125
86
  const localityNode = firstOfTag(roots, "locality")
126
87
  const locality = localityNode?.value.trim()
127
88
  const postcode = firstOfTag(roots, "postcode")?.value.trim()
128
- // The admin pair a register with no postcode and no locality tier scopes by (the Taiwanese 縣市 + 鄉鎮市區). Carried
129
- // beside `locality`, never in its place: a Latin reader ignores both.
89
+
130
90
  const region = firstOfTag(roots, "region")?.value.trim()
131
91
  const subregion = firstOfTag(roots, "subregion")?.value.trim()
132
92
 
@@ -134,10 +94,7 @@ export function applyAddressPoint(roots: AddressNode[], lookup: AddressPointLook
134
94
 
135
95
  if (pairs.some((pair) => pair.street.metadata?.["resolution_tier"] === "address_point")) return
136
96
 
137
- // #247 OSM bbox fall-through: when enabled (an OSM extract is wired) and the locality resolved to a
138
- // coordinate, scope a final `(street, number)` probe by the locality's box — recovering OSM points that
139
- // carry no postcode/locality tag of their own. US situs never enables it, so its probes are byte-identical.
140
- let bbox: { minLat: number; maxLat: number; minLon: number; maxLon: number } | undefined
97
+ let bbox: { minLat: number; maxLat: number; minLon: number; maxLon: number } | null = null
141
98
 
142
99
  if (bboxFallback && localityNode?.lat != null && localityNode.lon != null) {
143
100
  bbox = {
@@ -148,9 +105,9 @@ export function applyAddressPoint(roots: AddressNode[], lookup: AddressPointLook
148
105
  }
149
106
  }
150
107
 
151
- let street: AddressNode | undefined
152
- let houseNumber: AddressNode | undefined
153
- let hit: ReturnType<AddressPointLookup["find"]> | undefined
108
+ let street: AddressNode | null = null
109
+ let houseNumber: AddressNode | null = null
110
+ let hit: ReturnType<AddressPointLookup["find"]> | null = null
154
111
 
155
112
  for (const pair of pairs) {
156
113
  hit = lookup.find({
@@ -173,7 +130,6 @@ export function applyAddressPoint(roots: AddressNode[], lookup: AddressPointLook
173
130
 
174
131
  if (!hit || !street || !houseNumber) return
175
132
 
176
- // The number the register answered for is the one the result names (tree-shape.ts `slotNodes` reads the stamp).
177
133
  houseNumber.metadata = { ...houseNumber.metadata, resolution_tier: "address_point" }
178
134
 
179
135
  street.metadata = {
@@ -183,21 +139,19 @@ export function applyAddressPoint(roots: AddressNode[], lookup: AddressPointLook
183
139
  lon: hit.lon,
184
140
  source: hit.source,
185
141
  release: hit.release,
186
- // The register row's OWN scope tags, when carried — a rooftop consumer can decorate the
187
- // commune/postcode the register attests even when the query never named them.
188
- ...(hit.localityNorm ? { locality_norm: hit.localityNorm } : {}),
189
- ...(hit.postcode ? { postcode: hit.postcode } : {}),
142
+ locality_norm: hit.localityNorm || null,
143
+ postcode: hit.postcode || null,
190
144
  },
191
145
  resolution_tier: "address_point",
192
146
  }
193
147
  }
194
148
 
195
149
  /**
196
- * House-number interpolation tier (#483): the third rung, consulted ONLY when the exact address-point tier
197
- * ({@link applyAddressPoint}) did NOT already stamp the street node (`resolution_tier === "address_point"`). That check
198
- * IS the "after the exact-point fall-through" — an estimate never overwrites a real situs point. Postcode-scoped (no
199
- * locality — the interpolators abstain statewide without a postcode). Stamps a DISTINCT metadata key
200
- * (`interpolated_point`, never `address_point`). Additive only — admin resolution is untouched.
150
+ * Stamps the street with an interpolated house-number coordinate when the
151
+ * address-point tier did not already place it.
152
+ *
153
+ * It writes `interpolated_point` rather than `address_point`, so an estimate
154
+ * never overwrites a real situs point.
201
155
  */
202
156
  export function applyInterpolation(
203
157
  roots: AddressNode[],
@@ -207,23 +161,20 @@ export function applyInterpolation(
207
161
  const pairs = streetNumberPairs(roots)
208
162
  const directionalUnit = [...walkNodes(roots)].find((n) => n.tag === "unit" && isDirectionalUnit(n.value))
209
163
  const postcode = firstOfTag(roots, "postcode")?.value.trim()
210
- // The resolved locality's coordinate — the `near` tie-breaker the interpolator may consult when the query carries
211
- // no postcode and the covering ranges span several ZIPs (the borough-namesake class). Only a RESOLVED locality
212
- // qualifies; an unresolved one contributes nothing.
164
+
213
165
  const resolvedLocality = [...walkNodes(roots)].find((n) => n.tag === "locality" && n.lat != null && n.lon != null)
214
166
 
215
167
  const localityCoord = resolvedLocality ? { lat: resolvedLocality.lat!, lon: resolvedLocality.lon! } : undefined
216
168
 
217
169
  if (!pairs.length) return
218
170
 
219
- // The fall-through check: an exact situs point already won — never override it with an estimate.
220
171
  if (pairs.some((pair) => pair.street.metadata?.["resolution_tier"] === "address_point")) return
221
172
 
222
173
  const near = postcode ? undefined : localityCoord
223
174
 
224
- let street: AddressNode | undefined
225
- let houseNumber: AddressNode | undefined
226
- let hit: ReturnType<InterpolationLookup["find"]> | undefined
175
+ let street: AddressNode | null = null
176
+ let houseNumber: AddressNode | null = null
177
+ let hit: ReturnType<InterpolationLookup["find"]> | null = null
227
178
 
228
179
  for (const pair of pairs) {
229
180
  hit = lookup.find({
@@ -244,12 +195,7 @@ export function applyInterpolation(
244
195
  if (!hit || !street || !houseNumber) return
245
196
 
246
197
  houseNumber.metadata = { ...houseNumber.metadata, resolution_tier: "interpolated" }
247
- // Conformal-calibrated radius (#374): the raw half-segment heuristic underestimates the true spread
248
- // (~72% coverage on Travis); ×1.70 → a 90% bound. The ARTIFACT's own multiplier (read from the extract's
249
- // `interp_calibration` metadata table at open time — `lookup.radiusCalibration`) is the default; an
250
- // explicit caller factor is the @internal instrument override. Neither present (extracts predating the
251
- // metadata table, no caller factor) keeps the raw value, byte-stable. Preserve the raw radius for
252
- // transparency.
198
+
253
199
  const factor = radiusCalibration ?? lookup.radiusCalibration
254
200
  const calibrated = factor ? Math.round(hit.uncertaintyM * factor) : hit.uncertaintyM
255
201
 
@@ -260,74 +206,17 @@ export function applyInterpolation(
260
206
  uncertainty_m: calibrated,
261
207
  ...(factor ? { uncertainty_raw_m: hit.uncertaintyM, uncertainty_calibration: factor } : {}),
262
208
  interpolation_method: hit.method,
263
- ...(hit.parityMatched !== undefined ? { parity_matched: hit.parityMatched } : {}),
264
- ...(hit.bracket !== undefined ? { interpolation_bracket: hit.bracket } : {}),
209
+ ...(hit.parityMatched != null ? { parity_matched: hit.parityMatched } : {}),
210
+ ...(hit.bracket ? { interpolation_bracket: hit.bracket } : {}),
265
211
  }
266
212
  }
267
213
 
268
- /**
269
- * French thoroughfare (voie) type tokens — the leading word that marks a street-only span as a THOROUGHFARE rather than
270
- * a place name ("Place Bellecour", "Cours de l'Intendance", "Quai des Bateliers"). Used by the #1042 street-centroid
271
- * tier to recognize a thoroughfare that the model mis-parsed as a `locality` (the FR no-street class, #901).
272
- * Deliberately generous — a false positive simply misses the exact street-centroid lookup and no-ops; the lookup is the
273
- * real check.
274
- */
275
- const FR_VOIE_TYPES: ReadonlySet<string> = new Set([
276
- "rue",
277
- "ruelle",
278
- "venelle",
279
- "avenue",
280
- "av",
281
- "ave",
282
- "boulevard",
283
- "bd",
284
- "bld",
285
- "bvd",
286
- "boul",
287
- "place",
288
- "pl",
289
- "cours",
290
- "quai",
291
- "impasse",
292
- "imp",
293
- "allee",
294
- "all",
295
- "chemin",
296
- "ch",
297
- "che",
298
- "passage",
299
- "pas",
300
- "square",
301
- "sq",
302
- "faubourg",
303
- "fg",
304
- "fbg",
305
- "route",
306
- "rte",
307
- "esplanade",
308
- "promenade",
309
- "sentier",
310
- "sente",
311
- "villa",
312
- "cite",
313
- "hameau",
314
- "montee",
315
- "chaussee",
316
- "traverse",
317
- "mail",
318
- "clos",
319
- "voie",
214
+ const FR_GENEROUS_VOIE_TOKENS: ReadonlySet<string> = new Set([
320
215
  "quartier",
321
- "lotissement",
322
- "residence",
216
+
323
217
  "rond",
324
218
  ])
325
219
 
326
- /**
327
- * Fold to lower-case, diacritic-stripped, punctuation-free tokens — a deliberate local copy of
328
- * `@mailwoman/resolver-wof-sqlite/street-normalize`'s `fold`: `@mailwoman/resolver` does not depend on that package, so
329
- * the two are kept in step by hand.
330
- */
331
220
  function foldVoieTokens(s: string): string[] {
332
221
  return s
333
222
  .normalize("NFKD")
@@ -336,22 +225,18 @@ function foldVoieTokens(s: string): string[] {
336
225
  .replaceAll(/[.,'’]/g, "")
337
226
  .replaceAll("-", " ")
338
227
  .split(/\s+/)
339
- .filter((token) => token.length > 0)
228
+ .filter((token) => token.length)
340
229
  }
341
230
 
342
- /**
343
- * Does a string START with a French thoroughfare type token ("Rue …", "Place …")?
344
- */
345
231
  function isVoieShaped(s: string): boolean {
346
232
  const first = foldVoieTokens(s)[0]
347
233
 
348
- return first !== undefined && FR_VOIE_TYPES.has(first)
234
+ if (!first) return false
235
+
236
+ return isFrenchStreetWord(first) || FR_GENEROUS_VOIE_TOKENS.has(first)
349
237
  }
350
238
 
351
- /**
352
- * Push `v` (trimmed, non-empty, deduped, capped) onto `list`.
353
- */
354
- function pushCandidate(list: string[], v: string | undefined, cap: number): void {
239
+ function pushCandidate(list: string[], v: string | null, cap: number): void {
355
240
  const t = v?.trim()
356
241
 
357
242
  if (t && list.length < cap && !list.includes(t)) {
@@ -360,29 +245,18 @@ function pushCandidate(list: string[], v: string | undefined, cap: number): void
360
245
  }
361
246
 
362
247
  /**
363
- * Street-centroid tier (#1042): the street-level rung BELOW the exact/interpolation tiers and ABOVE admin-centroid
364
- * resolution. For a STREET-ONLY query (a thoroughfare with NO house number), stamp the street's centroid onto a
365
- * `street` node so a consumer gets a street-level coordinate instead of the commune centroid (or a wrong namesake).
366
- *
367
- * The FR no-street class mis-parses the thoroughfare — "Place Bellecour, Lyon" parses `region=Lyon`, `locality="Place
368
- * Bellecour"`; "Avenue des Champs-Élysées" truncates — so this recovers the thoroughfare + commune RAW-TEXT-first (the
369
- * same substrate as span-rescore), preferring parsed nodes and falling back to the comma-split raw query. A
370
- * thoroughfare is recognized by its leading voie type ({@link isVoieShaped}); the commune is any non-voie span. Every
371
- * (thoroughfare, commune) pair is probed against the exact street-centroid lookup, first hit wins — a false candidate
372
- * simply misses. Additive only: fires ONLY when no house number is present (rooftop tiers untouched) and no
373
- * street-level coordinate already resolved, and never alters admin resolution.
248
+ * Adds a street centroid to a street-only query when no address-point or interpolated coordinate exists.
374
249
  */
375
250
  export function applyStreetCentroid(
376
251
  roots: AddressNode[],
377
252
  raw: string,
378
- provider: (country: string) => StreetCentroidLookup | undefined,
253
+ provider: (country: string) => StreetCentroidLookup | null | undefined,
379
254
  hints: readonly string[]
380
255
  ): void {
381
- let streetNode: AddressNode | undefined
256
+ let streetNode: AddressNode | null = null
382
257
  let houseNumber = false
383
- let postcode: string | undefined
384
- // Region / locality values in document order (thoroughfare and commune both hide here), and the countries the tree
385
- // resolved to — a post-resolution country hint.
258
+ let postcode: string | null = null
259
+
386
260
  const adminValues: string[] = []
387
261
  const resolvedCountries: string[] = []
388
262
 
@@ -395,7 +269,6 @@ export function applyStreetCentroid(
395
269
  streetNode = n
396
270
  }
397
271
 
398
- // Never shadow a real street-level coordinate the exact/interp tiers already stamped.
399
272
  if (n.metadata?.["resolution_tier"] === "address_point" || n.metadata?.["resolution_tier"] === "interpolated") {
400
273
  return
401
274
  }
@@ -415,10 +288,8 @@ export function applyStreetCentroid(
415
288
  }
416
289
  }
417
290
 
418
- if (houseNumber) return // street-only tier — a numbered address is the rooftop tiers' job
291
+ if (houseNumber) return
419
292
 
420
- // Candidate countries: pre-resolution hints (defaultCountry + unrestricted placer) then the resolved countries. BAN is
421
- // FR-only, so a non-FR candidate simply yields no lookup; the exact (street, base-commune) match is the real filter.
422
293
  const countries: string[] = []
423
294
 
424
295
  for (const c of [...hints, ...resolvedCountries]) {
@@ -433,16 +304,10 @@ export function applyStreetCentroid(
433
304
 
434
305
  if (!lookups.length) return
435
306
 
436
- const rawSegments = raw
437
- .split(",")
438
- .map((s) => s.trim())
439
- .filter((segment) => segment.length > 0)
307
+ const rawSegments = TextSpliterator.from(raw, { delimiter: "," }).toArray()
440
308
 
441
309
  const CAP = 5
442
310
 
443
- // Thoroughfare candidates (parsed-first, then raw): the assembled street node, any voie-shaped parsed value, any
444
- // voie-shaped raw comma-segment. The parse often truncates these (Champs-Élysées → "Avenue des Champs"), so the raw
445
- // segment is the recovery — a candidate that misses just advances to the next.
446
311
  const thoroughfares: string[] = []
447
312
 
448
313
  if (streetNode) {
@@ -463,8 +328,6 @@ export function applyStreetCentroid(
463
328
 
464
329
  if (!thoroughfares.length) return
465
330
 
466
- // Commune candidates: non-voie parsed admin values, then non-voie raw segments (a truncated/garbled parse loses the
467
- // commune — "Rue de la République, Marseille" parses `locality="e"` — so the raw "Marseille" is the recovery).
468
331
  const communes: string[] = []
469
332
 
470
333
  for (const v of adminValues) {
@@ -482,13 +345,13 @@ export function applyStreetCentroid(
482
345
  for (const lookup of lookups) {
483
346
  for (const street of thoroughfares) {
484
347
  let hit = postcode ? lookup.find({ street, postcode }) : null
485
- let matchedCommune: string | undefined
348
+ let matchedCommune: string | null = null
486
349
 
487
350
  for (let i = 0; !hit && i < communes.length; i++) {
488
351
  hit = lookup.find({ street, locality: communes[i]! })
489
352
 
490
353
  if (hit) {
491
- matchedCommune = communes[i]
354
+ matchedCommune = communes[i] ?? null
492
355
  }
493
356
  }
494
357
 
@@ -518,12 +381,6 @@ export function applyStreetCentroid(
518
381
  uncertainty_m: hit.uncertaintyM,
519
382
  }
520
383
 
521
- // #1058: a commune-scoped hit is REGISTER evidence of the street's locality — record it for
522
- // the geocode layer's locality/city decoration, and drop any span-rescored locality that
523
- // contradicts it. Span-rescore injects SPECULATIVELY (a low-confidence street prefix like
524
- // "Rue" exact-matches the commune Rue in Somme); the register's exact (street, commune)
525
- // match is strictly stronger, so the injected token-of-the-street must not survive as the
526
- // result's city.
527
384
  if (matchedCommune) {
528
385
  target.metadata = { ...target.metadata, street_locality: matchedCommune }
529
386