@mailwoman/resolver 9.2.0 → 9.4.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 (143) hide show
  1. package/README.md +5 -5
  2. package/{admin-coherence-passes.ts → lib/admin/coherence-passes.ts} +87 -9
  3. package/{admin-containment.ts → lib/admin/containment.ts} +5 -14
  4. package/lib/admin/index.ts +10 -0
  5. package/lib/admin/jp-municipality.ts +97 -0
  6. package/{admin-winner.ts → lib/admin/winner.ts} +18 -2
  7. package/{backend-capabilities.ts → lib/backend-capabilities.ts} +3 -3
  8. package/{bare-toponym-race.ts → lib/bare-toponym-race.ts} +1 -1
  9. package/{decorate-node.ts → lib/decorate-node.ts} +2 -2
  10. package/{fold-name.ts → lib/fold-name.ts} +2 -2
  11. package/{index.ts → lib/index.ts} +16 -22
  12. package/{plausibility.ts → lib/plausibility.ts} +5 -4
  13. package/{postcode-country-coherence.ts → lib/postcode/country-coherence.ts} +27 -32
  14. package/lib/postcode/index.ts +9 -0
  15. package/{postcode-prefix.ts → lib/postcode/prefix.ts} +4 -4
  16. package/{postcode-shape-coherence.ts → lib/postcode/shape-coherence.ts} +10 -24
  17. package/{remote-resolver.ts → lib/remote-resolver.ts} +13 -4
  18. package/{rerank.ts → lib/rerank.ts} +2 -2
  19. package/{resolve.ts → lib/resolve/index.ts} +133 -602
  20. package/lib/resolve/passes.ts +544 -0
  21. package/{span-rescore.ts → lib/span-rescore.ts} +63 -97
  22. package/{street-evidence.ts → lib/street/evidence.ts} +39 -6
  23. package/lib/street/index.ts +8 -0
  24. package/{street-tier.ts → lib/street/tier.ts} +131 -110
  25. package/{toponym-prior.ts → lib/toponym-prior.ts} +8 -8
  26. package/out/{admin-coherence-passes.d.ts → admin/coherence-passes.d.ts} +29 -7
  27. package/out/admin/coherence-passes.d.ts.map +1 -0
  28. package/out/{admin-coherence-passes.js → admin/coherence-passes.js} +73 -9
  29. package/out/admin/coherence-passes.js.map +1 -0
  30. package/out/{admin-containment.d.ts → admin/containment.d.ts} +5 -5
  31. package/out/admin/containment.d.ts.map +1 -0
  32. package/out/{admin-containment.js → admin/containment.js} +6 -12
  33. package/out/admin/containment.js.map +1 -0
  34. package/out/admin/index.d.ts +10 -0
  35. package/out/admin/index.d.ts.map +1 -0
  36. package/out/admin/index.js +10 -0
  37. package/out/admin/index.js.map +1 -0
  38. package/out/admin/jp-municipality.d.ts +50 -0
  39. package/out/admin/jp-municipality.d.ts.map +1 -0
  40. package/out/admin/jp-municipality.js +54 -0
  41. package/out/admin/jp-municipality.js.map +1 -0
  42. package/out/{admin-winner.d.ts → admin/winner.d.ts} +11 -3
  43. package/out/admin/winner.d.ts.map +1 -0
  44. package/out/{admin-winner.js → admin/winner.js} +19 -3
  45. package/out/admin/winner.js.map +1 -0
  46. package/out/backend-capabilities.d.ts.map +1 -1
  47. package/out/backend-capabilities.js +3 -3
  48. package/out/backend-capabilities.js.map +1 -1
  49. package/out/bare-toponym-race.d.ts.map +1 -1
  50. package/out/bare-toponym-race.js +1 -1
  51. package/out/bare-toponym-race.js.map +1 -1
  52. package/out/decorate-node.d.ts +1 -1
  53. package/out/decorate-node.d.ts.map +1 -1
  54. package/out/decorate-node.js +1 -1
  55. package/out/decorate-node.js.map +1 -1
  56. package/out/fold-name.d.ts +2 -2
  57. package/out/fold-name.d.ts.map +1 -1
  58. package/out/fold-name.js +2 -2
  59. package/out/fold-name.js.map +1 -1
  60. package/out/index.d.ts +15 -16
  61. package/out/index.d.ts.map +1 -1
  62. package/out/index.js +9 -10
  63. package/out/index.js.map +1 -1
  64. package/out/plausibility.d.ts +5 -4
  65. package/out/plausibility.d.ts.map +1 -1
  66. package/out/plausibility.js +5 -4
  67. package/out/plausibility.js.map +1 -1
  68. package/out/{postcode-country-coherence.d.ts → postcode/country-coherence.d.ts} +16 -16
  69. package/out/postcode/country-coherence.d.ts.map +1 -0
  70. package/out/{postcode-country-coherence.js → postcode/country-coherence.js} +24 -25
  71. package/out/postcode/country-coherence.js.map +1 -0
  72. package/out/postcode/index.d.ts +9 -0
  73. package/out/postcode/index.d.ts.map +1 -0
  74. package/out/postcode/index.js +9 -0
  75. package/out/postcode/index.js.map +1 -0
  76. package/out/{postcode-prefix.d.ts → postcode/prefix.d.ts} +4 -4
  77. package/out/postcode/prefix.d.ts.map +1 -0
  78. package/out/{postcode-prefix.js → postcode/prefix.js} +4 -4
  79. package/out/postcode/prefix.js.map +1 -0
  80. package/out/{postcode-shape-coherence.d.ts → postcode/shape-coherence.d.ts} +3 -3
  81. package/out/postcode/shape-coherence.d.ts.map +1 -0
  82. package/out/{postcode-shape-coherence.js → postcode/shape-coherence.js} +11 -20
  83. package/out/postcode/shape-coherence.js.map +1 -0
  84. package/out/remote-resolver.d.ts +18 -3
  85. package/out/remote-resolver.d.ts.map +1 -1
  86. package/out/remote-resolver.js +2 -2
  87. package/out/remote-resolver.js.map +1 -1
  88. package/out/rerank.d.ts +1 -1
  89. package/out/rerank.d.ts.map +1 -1
  90. package/out/rerank.js +2 -2
  91. package/out/rerank.js.map +1 -1
  92. package/out/{resolve.d.ts → resolve/index.d.ts} +1 -1
  93. package/out/resolve/index.d.ts.map +1 -0
  94. package/out/{resolve.js → resolve/index.js} +100 -387
  95. package/out/resolve/index.js.map +1 -0
  96. package/out/resolve/passes.d.ts +218 -0
  97. package/out/resolve/passes.d.ts.map +1 -0
  98. package/out/resolve/passes.js +333 -0
  99. package/out/resolve/passes.js.map +1 -0
  100. package/out/span-rescore.d.ts +16 -16
  101. package/out/span-rescore.d.ts.map +1 -1
  102. package/out/span-rescore.js +43 -69
  103. package/out/span-rescore.js.map +1 -1
  104. package/out/{street-evidence.d.ts → street/evidence.d.ts} +18 -3
  105. package/out/street/evidence.d.ts.map +1 -0
  106. package/out/{street-evidence.js → street/evidence.js} +22 -6
  107. package/out/street/evidence.js.map +1 -0
  108. package/out/street/index.d.ts +8 -0
  109. package/out/street/index.d.ts.map +1 -0
  110. package/out/street/index.js +8 -0
  111. package/out/street/index.js.map +1 -0
  112. package/out/{street-tier.d.ts → street/tier.d.ts} +14 -3
  113. package/out/street/tier.d.ts.map +1 -0
  114. package/out/{street-tier.js → street/tier.js} +121 -99
  115. package/out/street/tier.js.map +1 -0
  116. package/out/toponym-prior.d.ts +8 -8
  117. package/out/toponym-prior.d.ts.map +1 -1
  118. package/out/toponym-prior.js +8 -8
  119. package/out/toponym-prior.js.map +1 -1
  120. package/package.json +116 -59
  121. package/vitest.config.ts +5 -6
  122. package/out/admin-coherence-passes.d.ts.map +0 -1
  123. package/out/admin-coherence-passes.js.map +0 -1
  124. package/out/admin-containment.d.ts.map +0 -1
  125. package/out/admin-containment.js.map +0 -1
  126. package/out/admin-winner.d.ts.map +0 -1
  127. package/out/admin-winner.js.map +0 -1
  128. package/out/postcode-country-coherence.d.ts.map +0 -1
  129. package/out/postcode-country-coherence.js.map +0 -1
  130. package/out/postcode-prefix.d.ts.map +0 -1
  131. package/out/postcode-prefix.js.map +0 -1
  132. package/out/postcode-shape-coherence.d.ts.map +0 -1
  133. package/out/postcode-shape-coherence.js.map +0 -1
  134. package/out/resolve.d.ts.map +0 -1
  135. package/out/resolve.js.map +0 -1
  136. package/out/street-evidence.d.ts.map +0 -1
  137. package/out/street-evidence.js.map +0 -1
  138. package/out/street-tier.d.ts.map +0 -1
  139. package/out/street-tier.js.map +0 -1
  140. package/out/vitest.config.d.ts +0 -16
  141. package/out/vitest.config.d.ts.map +0 -1
  142. package/out/vitest.config.js +0 -36
  143. package/out/vitest.config.js.map +0 -1
@@ -13,10 +13,10 @@
13
13
  */
14
14
 
15
15
  import { isStreetDirectionalToken } from "@mailwoman/codex/us"
16
- import type { AddressNode } from "@mailwoman/core/decoder"
16
+ import { collectNodes, walkNodes, type AddressNode } from "@mailwoman/core/decoder"
17
17
  import type { AddressPointLookup, InterpolationLookup, StreetCentroidLookup } from "@mailwoman/core/resolver"
18
18
 
19
- import { foldName } from "./fold-name.ts"
19
+ import { foldName } from "#fold-name"
20
20
 
21
21
  /**
22
22
  * Street-name component tags that, with the street node itself, reconstruct the full street string.
@@ -26,27 +26,16 @@ const STREET_NAME_TAGS = new Set(["street", "street_prefix", "street_prefix_part
26
26
  /**
27
27
  * Reassemble the full street string from the street node's subtree (#483 coverage fix). The parser nests the
28
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 shards keyed on the FULL
29
+ * is the bare base name ("Sheldon" for "East Sheldon Rd") — which misses the coordinate extracts keyed on the FULL
30
30
  * normalized name. Collect street + its prefix/particle/suffix descendants (NOT house_number/unit, which also nest
31
31
  * under street), order by span offset, and join.
32
32
  */
33
33
  function assembleStreetValue(streetNode: AddressNode, directionalUnit?: AddressNode): string {
34
- const parts: AddressNode[] = []
35
- const stack = [streetNode]
36
-
37
- while (stack.length) {
38
- const n = stack.pop()!
39
-
40
- if (STREET_NAME_TAGS.has(n.tag) && n.value.trim()) {
41
- parts.push(n)
42
- }
43
-
44
- stack.push(...n.children)
45
- }
34
+ const parts = collectNodes([streetNode], (n) => STREET_NAME_TAGS.has(n.tag) && n.value.trim().length > 0)
46
35
 
47
36
  // #718 admin-tail: a directional quadrant the model mis-tagged `unit` ("1532 Taylor Street NE" →
48
37
  // [unit] "NE") folds back into the street key by span order, so the situs/interp lookup matches the
49
- // shard's "taylor street northeast" (the lookup normalizer expands the abbreviation). Lookup-key
38
+ // extract's "taylor street northeast" (the lookup normalizer expands the abbreviation). Lookup-key
50
39
  // only — the parse output and admin resolution are untouched. Byte-stable when absent (undefined).
51
40
  if (directionalUnit && directionalUnit.value.trim()) {
52
41
  parts.push(directionalUnit)
@@ -61,7 +50,7 @@ function assembleStreetValue(streetNode: AddressNode, directionalUnit?: AddressN
61
50
  * Directional quadrant values the model sometimes emits as a `unit` node instead of inside the street subtree (#718
62
51
  * admin-tail diagnostic: ~19% of the admin-fallback tail, 83% of DC). Folded into the street lookup key by
63
52
  * {@link assembleStreetValue}; the situs/interp lookup normalizer expands the abbreviation ("ne" → "northeast") so the
64
- * shard's full street name matches.
53
+ * extract's full street name matches.
65
54
  */
66
55
  // The 8 USPS cardinals/intercardinals (abbrev or name) — @codex/us owns the canonical table (#215).
67
56
  const isDirectionalUnit = (value: string): boolean => isStreetDirectionalToken(value.replaceAll(".", ""))
@@ -79,47 +68,73 @@ const isDirectionalUnit = (value: string): boolean => isStreetDirectionalToken(v
79
68
  */
80
69
  const LOCALITY_BBOX_RADIUS_DEG = 0.25
81
70
 
82
- export function applyAddressPoint(roots: AddressNode[], lookup: AddressPointLookup, bboxFallback?: boolean): void {
83
- let street: AddressNode | undefined
84
- let houseNumber: AddressNode | undefined
85
- let directionalUnit: AddressNode | undefined
86
- let localityNode: AddressNode | undefined
87
- let locality: string | undefined
88
- let postcode: string | undefined
89
- const stack = [...roots]
90
-
91
- while (stack.length) {
92
- const n = stack.pop()!
93
-
94
- if (n.tag === "street" && !street) {
95
- street = n
71
+ /**
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.
77
+ */
78
+ export function streetNumberPairs(
79
+ roots: readonly AddressNode[]
80
+ ): Array<{ street: AddressNode; houseNumber: AddressNode }> {
81
+ const streets: AddressNode[] = []
82
+ const numbers: AddressNode[] = []
83
+
84
+ for (const node of walkNodes(roots)) {
85
+ if (node.tag === "street") {
86
+ streets.push(node)
96
87
  }
97
88
 
98
- if (n.tag === "house_number" && !houseNumber) {
99
- houseNumber = n
89
+ if (node.tag === "house_number") {
90
+ numbers.push(node)
100
91
  }
92
+ }
101
93
 
102
- if (n.tag === "unit" && !directionalUnit && isDirectionalUnit(n.value)) {
103
- directionalUnit = n
104
- }
94
+ const pairs = streets.flatMap((street) => numbers.map((houseNumber) => ({ street, houseNumber })))
105
95
 
106
- if (n.tag === "locality" && !localityNode && n.value.trim()) {
107
- localityNode = n
108
- locality = n.value.trim()
109
- }
96
+ return pairs.toSorted((a, b) => pairGap(a) - pairGap(b))
97
+ }
110
98
 
111
- if (n.tag === "postcode" && !postcode && n.value.trim()) {
112
- postcode = n.value.trim()
113
- }
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
+ function pairGap(pair: { street: AddressNode; houseNumber: AddressNode }): number {
104
+ const { street, houseNumber } = pair
114
105
 
115
- stack.push(...n.children)
106
+ if (houseNumber.end <= street.start) return street.start - houseNumber.end
107
+
108
+ return houseNumber.start - street.end + 1
109
+ }
110
+
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 {
115
+ for (const node of walkNodes(roots)) {
116
+ if (node.tag === tag && node.value.trim()) return node
116
117
  }
117
118
 
118
- if (!street || !houseNumber) return
119
+ return undefined
120
+ }
119
121
 
120
- if (street.metadata?.["resolution_tier"] === "address_point") return
122
+ export function applyAddressPoint(roots: AddressNode[], lookup: AddressPointLookup, bboxFallback?: boolean): void {
123
+ const pairs = streetNumberPairs(roots)
124
+ const directionalUnit = [...walkNodes(roots)].find((n) => n.tag === "unit" && isDirectionalUnit(n.value))
125
+ const localityNode = firstOfTag(roots, "locality")
126
+ const locality = localityNode?.value.trim()
127
+ 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.
130
+ const region = firstOfTag(roots, "region")?.value.trim()
131
+ const subregion = firstOfTag(roots, "subregion")?.value.trim()
121
132
 
122
- // #247 OSM bbox fall-through: when enabled (an OSM shard is wired) and the locality resolved to a
133
+ if (!pairs.length) return
134
+
135
+ if (pairs.some((pair) => pair.street.metadata?.["resolution_tier"] === "address_point")) return
136
+
137
+ // #247 OSM bbox fall-through: when enabled (an OSM extract is wired) and the locality resolved to a
123
138
  // coordinate, scope a final `(street, number)` probe by the locality's box — recovering OSM points that
124
139
  // carry no postcode/locality tag of their own. US situs never enables it, so its probes are byte-identical.
125
140
  let bbox: { minLat: number; maxLat: number; minLon: number; maxLon: number } | undefined
@@ -133,15 +148,33 @@ export function applyAddressPoint(roots: AddressNode[], lookup: AddressPointLook
133
148
  }
134
149
  }
135
150
 
136
- const hit = lookup.find({
137
- street: assembleStreetValue(street, directionalUnit),
138
- number: houseNumber.value,
139
- postcode,
140
- locality,
141
- bbox,
142
- })
151
+ let street: AddressNode | undefined
152
+ let houseNumber: AddressNode | undefined
153
+ let hit: ReturnType<AddressPointLookup["find"]> | undefined
154
+
155
+ for (const pair of pairs) {
156
+ hit = lookup.find({
157
+ street: assembleStreetValue(pair.street, directionalUnit),
158
+ number: pair.houseNumber.value,
159
+ postcode,
160
+ locality,
161
+ region,
162
+ subregion,
163
+ bbox,
164
+ })
165
+
166
+ if (hit) {
167
+ street = pair.street
168
+ houseNumber = pair.houseNumber
169
+
170
+ break
171
+ }
172
+ }
173
+
174
+ if (!hit || !street || !houseNumber) return
143
175
 
144
- if (!hit) return
176
+ // The number the register answered for is the one the result names (tree-shape.ts `slotNodes` reads the stamp).
177
+ houseNumber.metadata = { ...houseNumber.metadata, resolution_tier: "address_point" }
145
178
 
146
179
  street.metadata = {
147
180
  ...street.metadata,
@@ -161,7 +194,7 @@ export function applyAddressPoint(roots: AddressNode[], lookup: AddressPointLook
161
194
 
162
195
  /**
163
196
  * House-number interpolation tier (#483): the third rung, consulted ONLY when the exact address-point tier
164
- * ({@link applyAddressPoint}) did NOT already stamp the street node (`resolution_tier === "address_point"`). That gate
197
+ * ({@link applyAddressPoint}) did NOT already stamp the street node (`resolution_tier === "address_point"`). That check
165
198
  * IS the "after the exact-point fall-through" — an estimate never overwrites a real situs point. Postcode-scoped (no
166
199
  * locality — the interpolators abstain statewide without a postcode). Stamps a DISTINCT metadata key
167
200
  * (`interpolated_point`, never `address_point`). Additive only — admin resolution is untouched.
@@ -171,61 +204,50 @@ export function applyInterpolation(
171
204
  lookup: InterpolationLookup,
172
205
  radiusCalibration?: number
173
206
  ): void {
174
- let street: AddressNode | undefined
175
- let houseNumber: AddressNode | undefined
176
- let directionalUnit: AddressNode | undefined
177
- let postcode: string | undefined
178
- let localityCoord: { lat: number; lon: number } | undefined
179
- const stack = [...roots]
207
+ const pairs = streetNumberPairs(roots)
208
+ const directionalUnit = [...walkNodes(roots)].find((n) => n.tag === "unit" && isDirectionalUnit(n.value))
209
+ 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.
213
+ const resolvedLocality = [...walkNodes(roots)].find((n) => n.tag === "locality" && n.lat != null && n.lon != null)
180
214
 
181
- while (stack.length) {
182
- const n = stack.pop()!
215
+ const localityCoord = resolvedLocality ? { lat: resolvedLocality.lat!, lon: resolvedLocality.lon! } : undefined
183
216
 
184
- if (n.tag === "street" && !street) {
185
- street = n
186
- }
217
+ if (!pairs.length) return
187
218
 
188
- if (n.tag === "house_number" && !houseNumber) {
189
- houseNumber = n
190
- }
191
-
192
- if (n.tag === "unit" && !directionalUnit && isDirectionalUnit(n.value)) {
193
- directionalUnit = n
194
- }
219
+ // The fall-through check: an exact situs point already won — never override it with an estimate.
220
+ if (pairs.some((pair) => pair.street.metadata?.["resolution_tier"] === "address_point")) return
195
221
 
196
- if (n.tag === "postcode" && !postcode && n.value.trim()) {
197
- postcode = n.value.trim()
198
- }
199
-
200
- // The resolved locality's coordinate — the `near` tie-breaker the interpolator may consult when
201
- // the query carries no postcode and the covering ranges span several ZIPs (the borough-namesake
202
- // class). Only a RESOLVED locality qualifies; an unresolved one contributes nothing.
203
- if (n.tag === "locality" && !localityCoord && n.lat != null && n.lon != null) {
204
- localityCoord = { lat: n.lat, lon: n.lon }
205
- }
222
+ const near = postcode ? undefined : localityCoord
206
223
 
207
- stack.push(...n.children)
208
- }
224
+ let street: AddressNode | undefined
225
+ let houseNumber: AddressNode | undefined
226
+ let hit: ReturnType<InterpolationLookup["find"]> | undefined
209
227
 
210
- if (!street || !houseNumber) return
228
+ for (const pair of pairs) {
229
+ hit = lookup.find({
230
+ street: assembleStreetValue(pair.street, directionalUnit),
231
+ number: pair.houseNumber.value,
232
+ postcode,
233
+ ...(near ? { near } : {}),
234
+ })
211
235
 
212
- // The fall-through gate: an exact situs point already won — never override it with an estimate.
213
- if (street.metadata?.["resolution_tier"] === "address_point") return
236
+ if (hit) {
237
+ street = pair.street
238
+ houseNumber = pair.houseNumber
214
239
 
215
- const near = postcode ? undefined : localityCoord
240
+ break
241
+ }
242
+ }
216
243
 
217
- const hit = lookup.find({
218
- street: assembleStreetValue(street, directionalUnit),
219
- number: houseNumber.value,
220
- postcode,
221
- ...(near ? { near } : {}),
222
- })
244
+ if (!hit || !street || !houseNumber) return
223
245
 
224
- if (!hit) return
246
+ houseNumber.metadata = { ...houseNumber.metadata, resolution_tier: "interpolated" }
225
247
  // Conformal-calibrated radius (#374): the raw half-segment heuristic underestimates the true spread
226
- // (~72% coverage on Travis); ×1.70 → a 90% bound. The ARTIFACT's own multiplier (read from the shard's
248
+ // (~72% coverage on Travis); ×1.70 → a 90% bound. The ARTIFACT's own multiplier (read from the extract's
227
249
  // `interp_calibration` metadata table at open time — `lookup.radiusCalibration`) is the default; an
228
- // explicit caller factor is the @internal instrument override. Neither present (shards predating the
250
+ // explicit caller factor is the @internal instrument override. Neither present (extracts predating the
229
251
  // metadata table, no caller factor) keeps the raw value, byte-stable. Preserve the raw radius for
230
252
  // transparency.
231
253
  const factor = radiusCalibration ?? lookup.radiusCalibration
@@ -248,7 +270,7 @@ export function applyInterpolation(
248
270
  * a place name ("Place Bellecour", "Cours de l'Intendance", "Quai des Bateliers"). Used by the #1042 street-centroid
249
271
  * tier to recognize a thoroughfare that the model mis-parsed as a `locality` (the FR no-street class, #901).
250
272
  * Deliberately generous — a false positive simply misses the exact street-centroid lookup and no-ops; the lookup is the
251
- * real gate.
273
+ * real check.
252
274
  */
253
275
  const FR_VOIE_TYPES: ReadonlySet<string> = new Set([
254
276
  "rue",
@@ -302,7 +324,9 @@ const FR_VOIE_TYPES: ReadonlySet<string> = new Set([
302
324
  ])
303
325
 
304
326
  /**
305
- * Fold to lower-case, diacritic-stripped, punctuation-free tokens — mirrors `street-normalize.ts`'s `fold`.
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.
306
330
  */
307
331
  function foldVoieTokens(s: string): string[] {
308
332
  return s
@@ -357,13 +381,12 @@ export function applyStreetCentroid(
357
381
  let streetNode: AddressNode | undefined
358
382
  let houseNumber = false
359
383
  let postcode: string | undefined
360
- const adminValues: string[] = [] // region / locality values, in tree order (thoroughfare and commune both hide here)
361
- const resolvedCountries: string[] = [] // countries the tree actually resolved to — a post-resolution country hint
362
- const stack = [...roots]
363
-
364
- while (stack.length) {
365
- const n = stack.pop()!
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.
386
+ const adminValues: string[] = []
387
+ const resolvedCountries: string[] = []
366
388
 
389
+ for (const n of walkNodes(roots)) {
367
390
  if (n.tag === "house_number") {
368
391
  houseNumber = true
369
392
  }
@@ -390,13 +413,11 @@ export function applyStreetCentroid(
390
413
  if (rc && !resolvedCountries.includes(rc)) {
391
414
  resolvedCountries.push(rc)
392
415
  }
393
-
394
- stack.push(...n.children)
395
416
  }
396
417
 
397
418
  if (houseNumber) return // street-only tier — a numbered address is the rooftop tiers' job
398
419
 
399
- // Candidate countries: pre-resolution hints (defaultCountry + ungated placer) then the resolved countries. BAN is
420
+ // Candidate countries: pre-resolution hints (defaultCountry + unrestricted placer) then the resolved countries. BAN is
400
421
  // FR-only, so a non-FR candidate simply yields no lookup; the exact (street, base-commune) match is the real filter.
401
422
  const countries: string[] = []
402
423
 
@@ -32,7 +32,7 @@
32
32
  * {@link rankByCountryPrior} covers the other half of the class — the query where a country IS
33
33
  * known, but only because a locale said so. See `span-rescore.ts` for where that one applies.
34
34
  *
35
- * Both obey the same three house rules, and neither is a gate:
35
+ * Both obey the same three house rules, and neither is a check:
36
36
  *
37
37
  * 1. **Tier-safe.** `exactMatch` stays the primary key. A soft prior re-orders WITHIN a tier; it never
38
38
  * promotes a partial match over an exact one.
@@ -44,7 +44,7 @@
44
44
  * 3. **Stable.** Equal keys keep their incoming order, so the backend's own ranking survives underneath. That order
45
45
  * carries decisions only the backend can make — the candidate backend's seat tiebreak
46
46
  * (`resolver-wof-sqlite/primary-preference.ts`) reaches an end-to-end answer solely through this stability
47
- * (#1729), so equal-key stability here is load-bearing, not cosmetic.
47
+ * (#1729), so equal-key stability here is required, not cosmetic.
48
48
  */
49
49
 
50
50
  import type { ResolvedPlace } from "@mailwoman/core/resolver"
@@ -313,12 +313,12 @@ export const NATIONAL_CAPITAL_MARGIN_LOG10 = 2
313
313
  *
314
314
  * The rule: within the exact tier, take the first NATIONAL-capital row and walk it upward past each row it is within
315
315
  * {@link NATIONAL_CAPITAL_MARGIN_LOG10} of, stopping at the first row over the margin or at another national capital.
316
- * Same three house rules as the other keys — tier-safe (never crosses the exact/partial boundary; the cost is real and
317
- * accepted: a capital that only PARTIALLY matched the query — Saint George's, Grenada for the abbreviated "St.
318
- * George's" — stays behind every exact match, because crossing that line is how iteration 1 answered bare "Djibouti"
319
- * with the capital city instead of the country), positive evidence only (no capital in the list → identity, and the
320
- * margin reads the same `prominence ?? score` size every other key does), and stable (non-promoted rows keep their
321
- * order).
316
+ * Same three house rules as the other keys — tier-safe (never crosses the exact/partial boundary.
317
+ *
318
+ * A capital that only PARTIALLY matched the query — Saint George's, Grenada for the abbreviated "St. George's" — stays
319
+ * behind every exact match, because crossing that line is how iteration 1 answered bare "Djibouti" with the capital
320
+ * city instead of the country), positive evidence only (no capital in the list → identity, and the margin reads the
321
+ * same `prominence ?? score` size every other key does), and stable (non-promoted rows keep their order).
322
322
  *
323
323
  * The margin deliberately re-uses log10-population units rather than the importance scale: the ratified importance flip
324
324
  * decisions (Whitby/Windsor/Springfield) sit on gaps of 0.004–0.02, while the capital contests this key exists for sit
@@ -9,7 +9,29 @@
9
9
  * byte-stability guarantees are documented on the pass itself; `resolveTree` sequences them.
10
10
  */
11
11
  import type { AddressNode } from "@mailwoman/core/decoder";
12
- import type { ResolverBackend } from "@mailwoman/core/resolver";
12
+ import { type ResolverBackend } from "@mailwoman/core/resolver";
13
+ /**
14
+ * Refuse a pick admitted from outside its parent's scope whose own lineage names a DIFFERENT region than the one the
15
+ * walk resolved above it.
16
+ *
17
+ * The walk scopes a child lookup to its resolved parent. When that scoped probe misses, two widenings exist so an
18
+ * incomplete hierarchy (a real place whose ancestor chain lacks its region) still resolves: the resolver's retry
19
+ * without the parent, and the candidate backend's interior region-scope fallback (#1731), which re-admits rows from
20
+ * outside the region and stamps them `regionScopeMiss`. Both also admit a namesake under another region: `臺南市北區`
21
+ * resolved 臺南市 (Tainan City), found no 北區 under it — the candidate table carries no Han key for Tainan's — and the
22
+ * widening answered Hsinchu's 北區, 214 km away, which the coherence report then marked `region: contradicted` while the
23
+ * point stood. Of the 289 held-out Taiwanese 鄉鎮市區, 21 resolved this way at 15.6–238 km when the register was read as
24
+ * bare `縣市鄉鎮市區` lines.
25
+ *
26
+ * The two cases a widening conflates are told apart by the pick's stamped ancestors: an incomplete chain names NO
27
+ * region and is kept, the case the widenings exist for; a chain that names a region other than the resolved parent is a
28
+ * different place and is un-resolved here, so the admin ladder answers the parent's own point rather than a namesake
29
+ * elsewhere. Only widened picks are examined (`metadata.parent_fallback`, stamped by the walk for either mechanism),
30
+ * and only when the parent region resolved to a place identity; no-op without the ancestor sidecar, since a chain that
31
+ * cannot be read is not a contradiction. The classifier attribution stays on the node; `parent_fallback_refused`
32
+ * records what happened.
33
+ */
34
+ export declare function applyParentFallbackContradiction(roots: readonly AddressNode[]): void;
13
35
  /**
14
36
  * Admin descendant-consistency (#263) — the joint-consistency resolve, scoped to the admin assignment. The greedy walk
15
37
  * resolves a region on its own (name + population), so "ME" picks Messina (IT) over Maine, then scopes "Portland" to
@@ -59,12 +81,12 @@ export declare function applyExplicitCountryCoherence(roots: readonly AddressNod
59
81
  * same-named locality under it? Only when BOTH hold does it swap the region and locality to the in-country pair.
60
82
  * Geography confirms; the subdivision table is a soft name→country prior, not a routing decision.
61
83
  *
62
- * Evidence-gated to stay byte-stable on the domestic path. It fires ONLY when (a) a default country is in force, (b)
63
- * the region node is UNRESOLVED (the default-country filter came up empty — a US region resolves fine under `US`, so a
64
- * well-formed US query never trips this), (c) the token is a subdivision of a DIFFERENT country than the default, and
65
- * (d) both the foreign region and a same-named foreign locality resolve. "Springfield, IL" / "Portland, ME": the region
66
- * resolves under `US`, so gate (b) fails and the tree is untouched. Costs one region + one locality lookup per
84
+ * Evidence-conditional to stay byte-stable on the domestic path. It fires ONLY when (a) a default country is in force,
85
+ * (b) the region node is UNRESOLVED (the default-country filter came up empty — a US region resolves fine under `US`,
86
+ * so a well-formed US query never trips this), (c) the token is a subdivision of a DIFFERENT country than the default,
87
+ * and (d) both the foreign region and a same-named foreign locality resolve. "Springfield, IL" / "Portland, ME": the
88
+ * region resolves under `US`, so check (b) fails and the tree is untouched. Costs one region + one locality lookup per
67
89
  * triggering pair. See `ResolveOpts.adminCoherence`.
68
90
  */
69
91
  export declare function applyRegionCountryCoherence(roots: readonly AddressNode[], backend: ResolverBackend, defaultCountry: string | undefined): Promise<void>;
70
- //# sourceMappingURL=admin-coherence-passes.d.ts.map
92
+ //# sourceMappingURL=coherence-passes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coherence-passes.d.ts","sourceRoot":"","sources":["../../lib/admin/coherence-passes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAA+C,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAoB5G;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,CAuCpF;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBhH;AAoKD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,6BAA6B,CAClD,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,IAAI,CAAC,CA2Bf;AA2CD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,2BAA2B,CAChD,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,OAAO,EAAE,eAAe,EACxB,cAAc,EAAE,MAAM,GAAG,SAAS,GAChC,OAAO,CAAC,IAAI,CAAC,CA8Bf"}
@@ -9,7 +9,71 @@
9
9
  * byte-stability guarantees are documented on the pass itself; `resolveTree` sequences them.
10
10
  */
11
11
  import { matchCountry, matchSubdivision } from "@mailwoman/codex/country";
12
- import { decorateNode, isResolvedWithCoord } from "./decorate-node.js";
12
+ import { PLACETYPE_FILTER_GROUPS } from "@mailwoman/core/resolver";
13
+ import { decorateNode, isResolvedWithCoord } from "#decorate-node";
14
+ /**
15
+ * The region-band placetypes a lineage names a region by — `region` and its macro widening, the same set the lookup
16
+ * filter admits for a `region` request.
17
+ */
18
+ const REGION_LINEAGE_PLACETYPES = new Set(PLACETYPE_FILTER_GROUPS["region"] ?? ["region"]);
19
+ /**
20
+ * The numeric or string id behind a node's `placeID` (`wof:85679553` → `85679553`), or undefined when the node resolved
21
+ * to no place.
22
+ */
23
+ function placeIDValue(node) {
24
+ const match = /^[a-z]+:(.+)$/u.exec(node.placeID ?? "");
25
+ return match?.[1];
26
+ }
27
+ /**
28
+ * Refuse a pick admitted from outside its parent's scope whose own lineage names a DIFFERENT region than the one the
29
+ * walk resolved above it.
30
+ *
31
+ * The walk scopes a child lookup to its resolved parent. When that scoped probe misses, two widenings exist so an
32
+ * incomplete hierarchy (a real place whose ancestor chain lacks its region) still resolves: the resolver's retry
33
+ * without the parent, and the candidate backend's interior region-scope fallback (#1731), which re-admits rows from
34
+ * outside the region and stamps them `regionScopeMiss`. Both also admit a namesake under another region: `臺南市北區`
35
+ * resolved 臺南市 (Tainan City), found no 北區 under it — the candidate table carries no Han key for Tainan's — and the
36
+ * widening answered Hsinchu's 北區, 214 km away, which the coherence report then marked `region: contradicted` while the
37
+ * point stood. Of the 289 held-out Taiwanese 鄉鎮市區, 21 resolved this way at 15.6–238 km when the register was read as
38
+ * bare `縣市鄉鎮市區` lines.
39
+ *
40
+ * The two cases a widening conflates are told apart by the pick's stamped ancestors: an incomplete chain names NO
41
+ * region and is kept, the case the widenings exist for; a chain that names a region other than the resolved parent is a
42
+ * different place and is un-resolved here, so the admin ladder answers the parent's own point rather than a namesake
43
+ * elsewhere. Only widened picks are examined (`metadata.parent_fallback`, stamped by the walk for either mechanism),
44
+ * and only when the parent region resolved to a place identity; no-op without the ancestor sidecar, since a chain that
45
+ * cannot be read is not a contradiction. The classifier attribution stays on the node; `parent_fallback_refused`
46
+ * records what happened.
47
+ */
48
+ export function applyParentFallbackContradiction(roots) {
49
+ const visit = (node, regionAncestor) => {
50
+ const regionHere = node.tag === "region" && placeIDValue(node) !== undefined ? node : regionAncestor;
51
+ if (regionHere && node !== regionHere && node.metadata?.["parent_fallback"] === true) {
52
+ const regionID = placeIDValue(regionHere);
53
+ const ancestors = node.metadata?.["ancestors"];
54
+ const regions = (ancestors ?? []).filter((a) => REGION_LINEAGE_PLACETYPES.has(a.placetype));
55
+ if (regionID !== undefined && regions.length && !regions.some((a) => String(a.id) === regionID)) {
56
+ delete node.lat;
57
+ delete node.lon;
58
+ delete node.placeID;
59
+ delete node.alternatives;
60
+ const kept = {};
61
+ for (const [key, value] of Object.entries(node.metadata ?? {})) {
62
+ if (!key.startsWith("resolver_") && key !== "ancestors" && key !== "resolution_quality") {
63
+ kept[key] = value;
64
+ }
65
+ }
66
+ node.metadata = { ...kept, parent_fallback_refused: true };
67
+ }
68
+ }
69
+ for (const child of node.children) {
70
+ visit(child, regionHere);
71
+ }
72
+ };
73
+ for (const root of roots) {
74
+ visit(root, null);
75
+ }
76
+ }
13
77
  /**
14
78
  * Admin descendant-consistency (#263) — the joint-consistency resolve, scoped to the admin assignment. The greedy walk
15
79
  * resolves a region on its own (name + population), so "ME" picks Messina (IT) over Maine, then scopes "Portland" to
@@ -243,11 +307,11 @@ async function reconcileExplicitCountry(countryNode, localityNode, backend) {
243
307
  * same-named locality under it? Only when BOTH hold does it swap the region and locality to the in-country pair.
244
308
  * Geography confirms; the subdivision table is a soft name→country prior, not a routing decision.
245
309
  *
246
- * Evidence-gated to stay byte-stable on the domestic path. It fires ONLY when (a) a default country is in force, (b)
247
- * the region node is UNRESOLVED (the default-country filter came up empty — a US region resolves fine under `US`, so a
248
- * well-formed US query never trips this), (c) the token is a subdivision of a DIFFERENT country than the default, and
249
- * (d) both the foreign region and a same-named foreign locality resolve. "Springfield, IL" / "Portland, ME": the region
250
- * resolves under `US`, so gate (b) fails and the tree is untouched. Costs one region + one locality lookup per
310
+ * Evidence-conditional to stay byte-stable on the domestic path. It fires ONLY when (a) a default country is in force,
311
+ * (b) the region node is UNRESOLVED (the default-country filter came up empty — a US region resolves fine under `US`,
312
+ * so a well-formed US query never trips this), (c) the token is a subdivision of a DIFFERENT country than the default,
313
+ * and (d) both the foreign region and a same-named foreign locality resolve. "Springfield, IL" / "Portland, ME": the
314
+ * region resolves under `US`, so check (b) fails and the tree is untouched. Costs one region + one locality lookup per
251
315
  * triggering pair. See `ResolveOpts.adminCoherence`.
252
316
  */
253
317
  export async function applyRegionCountryCoherence(roots, backend, defaultCountry) {
@@ -261,7 +325,7 @@ export async function applyRegionCountryCoherence(roots, backend, defaultCountry
261
325
  // Fire for an UNRESOLVED region (the default-country filter came up empty) whose companion locality node
262
326
  // exists — regardless of the locality's resolution state, so it covers both the resolved-but-foreign namesake
263
327
  // (Montreal → the greedy US pick, Montreal WI) and the unresolved locality the span-rescore tier would
264
- // otherwise back-fill with a US namesake. The in-country lookups below are the evidence gate.
328
+ // otherwise back-fill with a US namesake. The in-country lookups below are the evidence check.
265
329
  if (regionHere &&
266
330
  !isResolvedWithCoord(regionHere) &&
267
331
  (node.tag === "locality" || node.tag === "dependent_locality") &&
@@ -281,7 +345,7 @@ export async function applyRegionCountryCoherence(roots, backend, defaultCountry
281
345
  * default-country filter hid. `matchSubdivision` turns the region token into `{ name, country }` (null for anything
282
346
  * that isn't a US state or CA province → no-op); the region's full name then resolves it under that country (expanding
283
347
  * the abbreviation the gazetteer FTS index lacks), and the locality is re-scoped to the same country. Leaves both nodes
284
- * untouched unless every gate holds — the subdivision names a different country than the default, the region resolves
348
+ * untouched unless every check holds — the subdivision names a different country than the default, the region resolves
285
349
  * under it, and a same-named locality exists there — so the domestic path stays byte-identical.
286
350
  */
287
351
  async function reconcileRegionCountry(regionNode, localityNode, backend, defaultCountry) {
@@ -324,4 +388,4 @@ async function reconcileRegionCountry(regionNode, localityNode, backend, default
324
388
  decorateNode(localityNode, lc, scoped.filter((l) => l !== lc));
325
389
  localityNode.metadata = { ...localityNode.metadata, region_country_repicked: true };
326
390
  }
327
- //# sourceMappingURL=admin-coherence-passes.js.map
391
+ //# sourceMappingURL=coherence-passes.js.map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U,EACV,EAAE,EACF,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CACpC,CAAA;IAED,UAAU,CAAC,QAAQ,GAAG,EAAE,GAAG,UAAU,CAAC,QAAQ,EAAE,uBAAuB,EAAE,IAAI,EAAE,CAAA;IAE/E,YAAY,CACX,YAAY,EACZ,EAAE,EACF,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAC9B,CAAA;IAED,YAAY,CAAC,QAAQ,GAAG,EAAE,GAAG,YAAY,CAAC,QAAQ,EAAE,uBAAuB,EAAE,IAAI,EAAE,CAAA;AACpF,CAAC"}
@@ -9,13 +9,13 @@
9
9
  * before the limit window (so a contained candidate can reach the walk at all), and the resolver
10
10
  * walk partitions AGAIN after its fame/anchor re-ranks (so `rankByImportance` cannot hand the top
11
11
  * slot back to a more-famous uncontained namesake — Richmond VA outscores Richmond, North
12
- * Yorkshire on importance, and without the second partition the lever loses exactly where fame
12
+ * Yorkshire on importance, and without the second partition the change loses exactly where fame
13
13
  * disagrees with the qualifier). Two call sites, one function, one ordering.
14
14
  */
15
- import type { AddressNode } from "@mailwoman/core/decoder";
15
+ import { type AddressNode } from "@mailwoman/core/decoder";
16
16
  /**
17
17
  * Find the first non-empty region-tagged span anywhere in a tree — the qualifier the walk threads onto locality
18
- * lookups. Deliberately the same node the admin-coherence VERDICTS read (the first `region` node), so the lever's
18
+ * lookups. Deliberately the same node the admin-coherence VERDICTS read (the first `region` node), so the change's
19
19
  * firing population and the flag's `contradicted` population are the same rows. A `region` slot can hold a country name
20
20
  * the parser mislabeled ("Moscow, Russia" parses region="Russia") — the backend's qualifier probe answers that too,
21
21
  * because containment is containment whatever tier the container sits at.
@@ -36,7 +36,7 @@ export declare function firstRegionQualifier(roots: readonly AddressNode[]): str
36
36
  */
37
37
  export declare function partitionByContainment<T>(rows: readonly T[], isContained: (row: T) => boolean, isExact: (row: T) => boolean): T[];
38
38
  /**
39
- * The trace verdict for one locality pick under the lever — stamped as `metadata.admin_containment` so an inert
39
+ * The trace verdict for one locality pick under the change — stamped as `metadata.admin_containment` so an inert
40
40
  * mechanism is visible in the result rather than silently dead (#1719's rule). Derived from the candidates'
41
41
  * `containedByQualifier` stamps: any `true` → `"contained"`; stamps present but none true → `"no_contained_candidate"`;
42
42
  * no stamps at all → `"unavailable"` (the backend or artifact cannot answer — a pre-sidecar candidate.db, the FTS or
@@ -45,4 +45,4 @@ export declare function partitionByContainment<T>(rows: readonly T[], isContaine
45
45
  export declare function adminContainmentVerdict(candidates: ReadonlyArray<{
46
46
  containedByQualifier?: boolean | undefined;
47
47
  }>): "contained" | "no_contained_candidate" | "unavailable";
48
- //# sourceMappingURL=admin-containment.d.ts.map
48
+ //# sourceMappingURL=containment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"containment.d.ts","sourceRoot":"","sources":["../../lib/admin/containment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE1E;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,GAAG,SAAS,CAEtF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EACvC,IAAI,EAAE,SAAS,CAAC,EAAE,EAClB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,EAChC,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,GAC1B,CAAC,EAAE,CAuBL;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACtC,UAAU,EAAE,aAAa,CAAC;IAAE,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,CAAC,GACvE,WAAW,GAAG,wBAAwB,GAAG,aAAa,CAYxD"}