@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,62 +2,46 @@
2
2
  * @copyright Sister Software
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
- *
6
- * #727 stage-2 phase 4c — street-NAME existence as the k-best arbiter signal.
7
- *
8
- * Phase 4a measured the planned arbiter (full-geocode resolution tier) at exactly ZERO collected
9
- * headroom: the failing class is context-free fragments, which never reach rooftop layers, so
10
- * every hypothesis ties at admin tier. The corrected signal is street-NAME existence — "does this
11
- * hypothesis's street surface exist as a street name in the national register?" — which IS
12
- * queryable for a bare fragment. Measured on the FR fragment board over the v3.10.1 8k span model:
13
- * the rerank collects +6.0pp street@1 (0.791 → 0.851), 96 fixes / 3 breaks (32:1), the value
14
- * concentrated on the date-name class (+16.7pp). Receipts:
15
- * `docs/articles/evals/2026-07-17-v3101-span-head-8k-result.md`, spec
16
- * `docs/superpowers/specs/2026-07-17-727-phase4c-street-name-evidence.md`.
17
- *
18
- * THE ANTI-PELIAS RULE (shared with `rerank.ts`): ONE bit of evidence, not a score. We do NOT
19
- * blend the name signal into the parse scores — those already share a partition function and rank
20
- * fine within an input. The reranker's only job is to prefer a sibling hypothesis whose street the
21
- * world confirms exists, over a rank-1 whose street it does not. Positive evidence only: the
22
- * ABSENCE of a name is never evidence against a parse (index incompleteness is the default state
23
- * of the world), so the policy always fails open to the model's own ranking.
24
- *
25
- * This module is PURE — the interface + the fold + the measured pick policy, no SQLite. The FR BAN
26
- * backend lives in `@mailwoman/resolver-wof-sqlite` (`SQLiteStreetNameLookup`); callers inject it,
27
- * mirroring the `PlaceLookup` pattern.
28
5
  */
29
6
 
30
7
  import type { Exclusion } from "@mailwoman/evidence"
31
8
 
32
9
  /**
33
- * A street-name existence probe. Backend-agnostic; the FR instance is BAN street-centroids, a future US instance is
34
- * TIGER, etc. (per the registry-backed-structured-prediction doctrine tiers).
10
+ * Answers whether a street name exists, optionally within a locality or postcode,
11
+ * for the countries a backend such as BAN street centroids covers.
35
12
  */
36
13
  export interface StreetLocalityEvidence {
37
14
  /**
38
- * True when `streetSurface` exists as a street name — optionally scoped to a locality or postcode when the hypothesis
39
- * carries one (fragments usually don't; unscoped is the measured mode). The implementation is responsible for folding
40
- * the surface with {@link foldStreetSurface} so the caller passes raw text.
15
+ * Returns whether the raw street surface exists as a street name within `scope`, when provided.
41
16
  *
42
- * POSITIVE EVIDENCE ONLY: return `false` on any doubt — a missing index, an unsupported country, a read error — so
43
- * {@link pickByStreetEvidence} fails open to the model's ranking. Absence is never a veto.
17
+ * The implementation folds the surface itself.
18
+ * It returns `false` when an index is missing or a read fails.
19
+ * A `false` answer only withholds promotion.
44
20
  */
45
21
  hasStreetName(streetSurface: string, scope?: StreetEvidenceScope): boolean
22
+
46
23
  /**
47
- * ISO-2 (upper-case) countries this instance can answer for. Anything else → no evidence, never a veto.
24
+ * The upper-case ISO 3166-1 alpha-2 countries this instance covers.
48
25
  */
49
26
  readonly countries: ReadonlySet<string>
50
27
  }
51
28
 
29
+ /**
30
+ * Narrows a street-name existence probe to a locality, a postcode, or both.
31
+ */
52
32
  export interface StreetEvidenceScope {
53
33
  locality?: string
54
34
  postcode?: string
55
35
  }
56
36
 
57
37
  /**
58
- * The fold CONTRACT — the index builder and every runtime prober MUST share this exact function, or lookups silently
59
- * miss (the 4 v1-policy breaks were fold mismatches: `pillet-will` stored unhyphenated). NFD strip-diacritics,
60
- * lowercase, hyphen/apostrophe → space, whitespace-collapse. Import this beside the interface; never re-implement it.
38
+ * Folds a street surface the same way for index build and lookup.
39
+ *
40
+ * It strips diacritics and lowercases.
41
+ * It turns hyphens and dashes into spaces.
42
+ *
43
+ * It maps apostrophes to spaces too.
44
+ * It also collapses whitespace.
61
45
  */
62
46
  export function foldStreetSurface(surface: string): string {
63
47
  return surface
@@ -69,12 +53,6 @@ export function foldStreetSurface(surface: string): string {
69
53
  .trim()
70
54
  }
71
55
 
72
- /**
73
- * FR street-type + particle vocabulary — the G1 guard. A street surface made ONLY of these words carries no NAME (bare
74
- * `rue`/`chemin` is a truncation, and it IS in the index), so it earns no evidence credit. Folded forms (particles are
75
- * pre-folded: `l'` → `l`). Kept small and lexical — it is a dictionary fact, not a tuned weight (the anti-Pelias
76
- * line).
77
- */
78
56
  const FR_STREET_TYPE_WORDS: ReadonlySet<string> = new Set([
79
57
  "rue",
80
58
  "avenue",
@@ -112,10 +90,11 @@ const FR_STREET_TYPE_WORDS: ReadonlySet<string> = new Set([
112
90
  ])
113
91
 
114
92
  /**
115
- * True when the folded surface contains no token outside {@link FR_STREET_TYPE_WORDS} — i.e. it is pure type/particle.
93
+ * Returns true when a folded street surface is empty or consists only of French
94
+ * street-type words and particles, such as "rue de la".
116
95
  */
117
96
  export function isPureTypeVocabulary(foldedSurface: string): boolean {
118
- const tokens = foldedSurface.split(" ").filter((value) => value.length > 0)
97
+ const tokens = foldedSurface.split(" ").filter((value) => value.length)
119
98
 
120
99
  if (!tokens.length) return true
121
100
 
@@ -123,75 +102,93 @@ export function isPureTypeVocabulary(foldedSurface: string): boolean {
123
102
  }
124
103
 
125
104
  /**
126
- * One candidate parse for the street-evidence rerank — its street surface + its (within-input comparable) score.
105
+ * One candidate parse for {@link pickByStreetEvidence}; scores are comparable
106
+ * only among candidates for the same input.
127
107
  */
128
108
  export interface StreetCandidate<T = unknown> {
129
109
  /**
130
- * The candidate's street surface (raw; folded internally). Empty string = no street parsed → never the evidence pick.
110
+ * The candidate's raw street surface.
111
+ *
112
+ * An empty string means the parse found no street.
113
+ * Evidence skips that candidate.
131
114
  */
132
115
  streetSurface: string
116
+
133
117
  /**
134
- * The parse score, comparable to its siblings from the SAME input. Higher is better.
118
+ * The parse score, where higher is better.
135
119
  */
136
120
  score: number
121
+
137
122
  /**
138
- * Opaque caller payload carried through to the result (the segmentation, the tree, …).
123
+ * An opaque caller value, such as the segmentation or tree, returned unchanged with the pick.
139
124
  */
140
125
  payload?: T
141
126
  }
142
127
 
128
+ /**
129
+ * Options for {@link pickByStreetEvidence}.
130
+ */
143
131
  export interface PickByStreetEvidenceOpts {
144
132
  /**
145
- * Locality/postcode scope forwarded to {@link StreetLocalityEvidence.hasStreetName} (fragments usually carry none).
133
+ * The locality or postcode scope passed to {@link StreetLocalityEvidence.hasStreetName}.
146
134
  */
147
135
  scope?: StreetEvidenceScope
136
+
148
137
  /**
149
- * G2 — the margin cap. A candidate whose score is more than this far below rank-1 is never promoted by evidence
150
- * (without it, evidence reaches deep down the list and moves off correct rank-1 parses). Default 2.5 — the value the
151
- * v2 board measured (148 fixes / 3 breaks). UNCALIBRATED across models: re-fit when the span head retrains, since raw
152
- * score margins are not comparable across models. (Plan #1134 pre-registers an isotonic ambiguity check to replace
153
- * it.)
138
+ * The largest score gap below rank 1 at which evidence may still promote a candidate.
139
+ * it defaults to 2.5 and needs refitting when the span head is retrained.
154
140
  */
155
141
  marginCap?: number
142
+
156
143
  /**
157
- * One entry per candidate, positionally aligned. A non-null entry DEMOTES that candidate by one bit — it is
158
- * considered only after every un-excluded sibling. It is never removed: with every candidate excluded the pick is
159
- * still rank-1, because the worst case this policy accepts is the model's own ranking.
144
+ * One entry per candidate, in the same order.
160
145
  *
161
- * Omitted or all-null reproduces the measured v2 policy exactly.
146
+ * A non-null entry moves that candidate behind every candidate without an exclusion.
147
+ * If every candidate has an exclusion, the fallback pick is rank 1.
162
148
  */
163
149
  exclusions?: ReadonlyArray<Exclusion | null>
164
150
  }
165
151
 
152
+ /**
153
+ * The result of {@link pickByStreetEvidence}.
154
+ */
166
155
  export interface StreetEvidencePick<T = unknown> {
167
156
  /**
168
- * The chosen candidate — the first evidence-passing sibling, or rank-1 when none passes (fail-open).
157
+ * The first candidate that passes the evidence checks, or the first non-excluded
158
+ * candidate when none passes.
169
159
  */
170
160
  candidate: StreetCandidate<T>
161
+
171
162
  /**
172
- * Index of the chosen candidate in the input array.
163
+ * The chosen candidate's index in the input array.
173
164
  */
174
165
  index: number
166
+
175
167
  /**
176
- * True when evidence MOVED the pick off rank-1 (a rank-2-beats-rank-1 correction — loggable training signal).
168
+ * Whether the pick differs from rank 1, through evidence or because rank 1 was excluded.
177
169
  */
178
170
  moved: boolean
171
+
179
172
  /**
180
- * Indices an exclusion demoted, in input order. Empty when no exclusion applied — a loggable record of what the
181
- * coverage check licensed, distinct from what evidence found.
173
+ * The input indexes that exclusions demoted, in input order.
182
174
  */
183
175
  demoted: number[]
184
176
  }
185
177
 
186
178
  /**
187
- * The measured v2 rerank policy. Given candidates in PARSE-SCORE order (rank-1 first) and an evidence probe, return the
188
- * first candidate whose street surface passes ALL of: (1) exists in the index, (2) G1 — not pure type vocabulary, (3)
189
- * G2 — within `marginCap` of rank-1. If none passes, return rank-1 (fail-open). Positive evidence only; the model's
190
- * order is preserved among equal-evidence candidates. This is the `resolver/rerank.ts` anti-Pelias discipline applied
191
- * to the name signal: one bit, no blending. `opts.exclusions` adds one more bit in the same fold: a coverage-licensed
192
- * absence demotes its candidate behind every un-excluded sibling and never removes it.
179
+ * Checks candidates in score order.
180
+ *
181
+ * Selects the first candidate that meets all three checks.
182
+ * Its street name exists in the evidence index.
183
+ *
184
+ * The name contains more than street-type words.
185
+ * Its score falls within `marginCap` of rank 1.
186
+ *
187
+ * Excluded candidates are checked after all others.
188
+ * The first candidate without an exclusion wins when no candidate passes the evidence checks.
193
189
  *
194
- * @param candidates Parse candidates, rank-1 FIRST (the caller sorts by score descending).
190
+ * @param candidates Parse candidates sorted by score, rank 1 first.
191
+ * @throws When `candidates` is empty.
195
192
  */
196
193
  export function pickByStreetEvidence<T>(
197
194
  candidates: ReadonlyArray<StreetCandidate<T>>,
@@ -217,7 +214,6 @@ export function pickByStreetEvidence<T>(
217
214
  }
218
215
  }
219
216
 
220
- // An excluded candidate is considered only after every un-excluded sibling; it is never dropped.
221
217
  const order = demoted.length ? [...considered, ...demoted] : considered
222
218
 
223
219
  for (const i of order) {
@@ -225,10 +221,8 @@ export function pickByStreetEvidence<T>(
225
221
 
226
222
  if (!c.streetSurface) continue
227
223
 
228
- // G2: the margin is measured from rank-1's score, whatever position the candidate is considered at.
229
224
  if (topScore - c.score > marginCap) continue
230
225
 
231
- // G1: a pure street-type/particle surface (bare `rue`) carries no name — no evidence credit.
232
226
  if (isPureTypeVocabulary(foldStreetSurface(c.streetSurface))) continue
233
227
 
234
228
  if (evidence.hasStreetName(c.streetSurface, opts.scope)) {
@@ -236,8 +230,6 @@ export function pickByStreetEvidence<T>(
236
230
  }
237
231
  }
238
232
 
239
- // Fail-open: the first un-excluded candidate, which is rank-1 unless an exclusion demoted it, and rank-1 again when
240
- // every candidate is excluded.
241
233
  const fallback = order[0] ?? 0
242
234
 
243
235
  return { candidate: candidates[fallback]!, index: fallback, moved: fallback > 0, demoted }
@@ -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,9 +66,6 @@ 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
69
  function firstOfTag(roots: readonly AddressNode[], tag: AddressNode["tag"]): AddressNode | undefined {
115
70
  for (const node of walkNodes(roots)) {
116
71
  if (node.tag === tag && node.value.trim()) return node
@@ -119,14 +74,19 @@ function firstOfTag(roots: readonly AddressNode[], tag: AddressNode["tag"]): Add
119
74
  return undefined
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,9 +94,6 @@ 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
97
  let bbox: { minLat: number; maxLat: number; minLon: number; maxLon: number } | undefined
141
98
 
142
99
  if (bboxFallback && localityNode?.lat != null && localityNode.lon != null) {
@@ -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,8 +139,7 @@ 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.
142
+
188
143
  ...(hit.localityNorm ? { locality_norm: hit.localityNorm } : {}),
189
144
  ...(hit.postcode ? { postcode: hit.postcode } : {}),
190
145
  },
@@ -193,11 +148,11 @@ export function applyAddressPoint(roots: AddressNode[], lookup: AddressPointLook
193
148
  }
194
149
 
195
150
  /**
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.
151
+ * Stamps the street with an interpolated house-number coordinate when the
152
+ * address-point tier did not already place it.
153
+ *
154
+ * It writes `interpolated_point` rather than `address_point`, so an estimate
155
+ * never overwrites a real situs point.
201
156
  */
202
157
  export function applyInterpolation(
203
158
  roots: AddressNode[],
@@ -207,16 +162,13 @@ export function applyInterpolation(
207
162
  const pairs = streetNumberPairs(roots)
208
163
  const directionalUnit = [...walkNodes(roots)].find((n) => n.tag === "unit" && isDirectionalUnit(n.value))
209
164
  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.
165
+
213
166
  const resolvedLocality = [...walkNodes(roots)].find((n) => n.tag === "locality" && n.lat != null && n.lon != null)
214
167
 
215
168
  const localityCoord = resolvedLocality ? { lat: resolvedLocality.lat!, lon: resolvedLocality.lon! } : undefined
216
169
 
217
170
  if (!pairs.length) return
218
171
 
219
- // The fall-through check: an exact situs point already won — never override it with an estimate.
220
172
  if (pairs.some((pair) => pair.street.metadata?.["resolution_tier"] === "address_point")) return
221
173
 
222
174
  const near = postcode ? undefined : localityCoord
@@ -244,12 +196,7 @@ export function applyInterpolation(
244
196
  if (!hit || !street || !houseNumber) return
245
197
 
246
198
  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.
199
+
253
200
  const factor = radiusCalibration ?? lookup.radiusCalibration
254
201
  const calibrated = factor ? Math.round(hit.uncertaintyM * factor) : hit.uncertaintyM
255
202
 
@@ -265,69 +212,12 @@ export function applyInterpolation(
265
212
  }
266
213
  }
267
214
 
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",
215
+ const FR_GENEROUS_VOIE_TOKENS: ReadonlySet<string> = new Set([
320
216
  "quartier",
321
- "lotissement",
322
- "residence",
217
+
323
218
  "rond",
324
219
  ])
325
220
 
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
221
  function foldVoieTokens(s: string): string[] {
332
222
  return s
333
223
  .normalize("NFKD")
@@ -336,21 +226,17 @@ function foldVoieTokens(s: string): string[] {
336
226
  .replaceAll(/[.,'’]/g, "")
337
227
  .replaceAll("-", " ")
338
228
  .split(/\s+/)
339
- .filter((token) => token.length > 0)
229
+ .filter((token) => token.length)
340
230
  }
341
231
 
342
- /**
343
- * Does a string START with a French thoroughfare type token ("Rue …", "Place …")?
344
- */
345
232
  function isVoieShaped(s: string): boolean {
346
233
  const first = foldVoieTokens(s)[0]
347
234
 
348
- return first !== undefined && FR_VOIE_TYPES.has(first)
235
+ if (first === undefined) return false
236
+
237
+ return isFrenchStreetWord(first) || FR_GENEROUS_VOIE_TOKENS.has(first)
349
238
  }
350
239
 
351
- /**
352
- * Push `v` (trimmed, non-empty, deduped, capped) onto `list`.
353
- */
354
240
  function pushCandidate(list: string[], v: string | undefined, cap: number): void {
355
241
  const t = v?.trim()
356
242
 
@@ -360,17 +246,7 @@ function pushCandidate(list: string[], v: string | undefined, cap: number): void
360
246
  }
361
247
 
362
248
  /**
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.
249
+ * Adds a street centroid to a street-only query when no address-point or interpolated coordinate exists.
374
250
  */
375
251
  export function applyStreetCentroid(
376
252
  roots: AddressNode[],
@@ -381,8 +257,7 @@ export function applyStreetCentroid(
381
257
  let streetNode: AddressNode | undefined
382
258
  let houseNumber = false
383
259
  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.
260
+
386
261
  const adminValues: string[] = []
387
262
  const resolvedCountries: string[] = []
388
263
 
@@ -395,7 +270,6 @@ export function applyStreetCentroid(
395
270
  streetNode = n
396
271
  }
397
272
 
398
- // Never shadow a real street-level coordinate the exact/interp tiers already stamped.
399
273
  if (n.metadata?.["resolution_tier"] === "address_point" || n.metadata?.["resolution_tier"] === "interpolated") {
400
274
  return
401
275
  }
@@ -415,10 +289,8 @@ export function applyStreetCentroid(
415
289
  }
416
290
  }
417
291
 
418
- if (houseNumber) return // street-only tier — a numbered address is the rooftop tiers' job
292
+ if (houseNumber) return
419
293
 
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
294
  const countries: string[] = []
423
295
 
424
296
  for (const c of [...hints, ...resolvedCountries]) {
@@ -433,16 +305,10 @@ export function applyStreetCentroid(
433
305
 
434
306
  if (!lookups.length) return
435
307
 
436
- const rawSegments = raw
437
- .split(",")
438
- .map((s) => s.trim())
439
- .filter((segment) => segment.length > 0)
308
+ const rawSegments = TextSpliterator.from(raw, { delimiter: "," }).toArray()
440
309
 
441
310
  const CAP = 5
442
311
 
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
312
  const thoroughfares: string[] = []
447
313
 
448
314
  if (streetNode) {
@@ -463,8 +329,6 @@ export function applyStreetCentroid(
463
329
 
464
330
  if (!thoroughfares.length) return
465
331
 
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
332
  const communes: string[] = []
469
333
 
470
334
  for (const v of adminValues) {
@@ -518,12 +382,6 @@ export function applyStreetCentroid(
518
382
  uncertainty_m: hit.uncertaintyM,
519
383
  }
520
384
 
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
385
  if (matchedCommune) {
528
386
  target.metadata = { ...target.metadata, street_locality: matchedCommune }
529
387