@mailwoman/corpus 11.5.0 → 12.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 (232) hide show
  1. package/data/address-source-register.json +545 -11
  2. package/data/builds/v0.8.22-wofrank-overlay/OVERLAY_PLAN.json +51 -0
  3. package/data/builds/v0.8.24-everyplace/inputs.json +35 -0
  4. package/data/license-decisions.json +440 -9
  5. package/data/licenses/PROVENANCE.md +27 -18
  6. package/data/licenses/at-bev-adressregister-cc-by-4.0.md +25 -0
  7. package/data/licenses/br-ibge-cnefe-open-data.md +21 -0
  8. package/data/licenses/ca-qc-mrnf-cc-by-4.0.md +29 -0
  9. package/data/licenses/ca-statcan-open-licence.md +41 -0
  10. package/data/licenses/ca-yukon-ogl-2.0.md +19 -0
  11. package/data/licenses/dk-dmikg-cc-by-4.0.md +43 -0
  12. package/data/licenses/jp-mlit-isj-pdl-1.0.md +35 -0
  13. package/data/source-additions.json +90 -0
  14. package/data/source-resolutions.json +3 -2
  15. package/data/training-configs/v8.17.0-stage1-gazetteer-v0822-s42.yaml +557 -0
  16. package/data/training-configs/v8.17.0-stage2-corpus-v0822-s42.yaml +1008 -0
  17. package/data/training-configs/v8.18.0-gazetteer-then-mixture-v0822-s42.yaml +1225 -0
  18. package/data/training-configs/v8.20.0-wofrank-v0822-s42.yaml +863 -0
  19. package/data/training-configs/v8.21.0-outcomes-v0822-s42.yaml +873 -0
  20. package/data/training-configs/v8.22.0-stage1-everyplace-v0824-s42.yaml +374 -0
  21. package/data/training-configs/v8.22.0-stage2-corpus-v0824-s42.yaml +808 -0
  22. package/data/training-configs/v8.22.1-stage1-everyplace-v0824-s42.yaml +376 -0
  23. package/data/training-configs/v8.22.1-stage2-corpus-v0824-s42.yaml +793 -0
  24. package/data/training-configs/v9.0.0-bytestem-v090-s42.yaml +665 -0
  25. package/data/training-configs/v9.1.0-bytestem-global-v091-s42.yaml +710 -0
  26. package/data/training-configs/v9.2.0-bytestem-global-v092-s42.yaml +714 -0
  27. package/data/training-manifests/v0.8.22-wofrank-overlay.json +9000 -0
  28. package/data/training-manifests/v0.8.24-everyplace-overlay.json +9000 -0
  29. package/data/training-manifests/v0.9.0-compact.effective.json +2556 -0
  30. package/data/training-manifests/v0.9.0-compact.json +9000 -0
  31. package/data/training-manifests/v0.9.1-compact.json +9660 -0
  32. package/data/training-manifests/v0.9.2-compact.effective.json +2670 -0
  33. package/data/training-manifests/v0.9.2-compact.json +9660 -0
  34. package/lib/adapters/geonames/features/adapter.ts +29 -11
  35. package/lib/adapters/overture/adapter.ts +26 -6
  36. package/lib/adapters/street/line.ts +6 -5
  37. package/lib/adapters/street/unit.ts +7 -0
  38. package/lib/adapters/wof/admin/json/adapter.ts +38 -3
  39. package/lib/adapters/wof/json-rows.ts +84 -5
  40. package/lib/adapters/wof/sample.ts +42 -6
  41. package/lib/au/adapters/gnaf/source.ts +12 -0
  42. package/lib/build/code-hash.ts +1 -1
  43. package/lib/cjk/foreign-places.ts +1 -1
  44. package/lib/fr/adapters/ban/adapter.ts +57 -8
  45. package/lib/fr/recipes/admin-split.ts +14 -2
  46. package/lib/fr/recipes/lieudit.ts +1 -1
  47. package/lib/fr/recipes/order.ts +14 -5
  48. package/lib/international/recipes/locale.ts +1 -1
  49. package/lib/kr/adapters/localdata/permit-rows.ts +1 -1
  50. package/lib/parquet/schema.ts +7 -0
  51. package/lib/recipes/po/box/cedex/recipe.ts +1 -1
  52. package/lib/recipes/po/box/cedex/vocabulary.ts +4 -4
  53. package/lib/recipes/trailing-region.ts +147 -17
  54. package/lib/synthesizers/po-box.ts +51 -12
  55. package/lib/test-kit/corpus-recipe.ts +3 -0
  56. package/lib/tools/anthropic/batches.ts +221 -0
  57. package/lib/tools/anthropic/labeling.ts +263 -0
  58. package/lib/tools/compact-v9.ts +890 -0
  59. package/lib/tools/fetch/wikidata/vital-places/entities.ts +20 -2
  60. package/lib/tools/fetch/wikidata/vital-places/qrank.ts +5 -4
  61. package/lib/tools/fragment-assay.run.ts +2 -1
  62. package/lib/tools/name-roles/name-roles.run.ts +296 -0
  63. package/lib/tools/name-roles/prompt.ts +253 -0
  64. package/lib/tools/overlay/deletions.ts +1 -1
  65. package/lib/tools/overlay/draw-weight.ts +275 -0
  66. package/lib/tools/place-twins/place-twins.run.ts +528 -0
  67. package/lib/tools/place-twins/prompt.ts +276 -0
  68. package/lib/tools/prominent-shapes/prominent-shapes.run.ts +420 -0
  69. package/lib/tools/prominent-shapes/prompt.ts +189 -0
  70. package/lib/tools/prominent-shapes/read-seeds.ts +286 -0
  71. package/lib/tools/prominent-shapes/seeds.ts +281 -0
  72. package/lib/tools/prominent-shapes/validate.ts +563 -0
  73. package/lib/tools/source-register/build.ts +1 -0
  74. package/lib/training/config/admission.ts +9 -2
  75. package/lib/training/config/schema.ts +68 -1
  76. package/lib/types.ts +23 -0
  77. package/lib/us/adapters/usgov/usgs-structures/adapter.ts +103 -6
  78. package/lib/utils/split.ts +1 -1
  79. package/out/adapters/geonames/features/adapter.d.ts +2 -2
  80. package/out/adapters/geonames/features/adapter.d.ts.map +1 -1
  81. package/out/adapters/geonames/features/adapter.js +25 -11
  82. package/out/adapters/geonames/features/adapter.js.map +1 -1
  83. package/out/adapters/overture/adapter.d.ts.map +1 -1
  84. package/out/adapters/overture/adapter.js +21 -5
  85. package/out/adapters/overture/adapter.js.map +1 -1
  86. package/out/adapters/street/line.d.ts +4 -4
  87. package/out/adapters/street/line.d.ts.map +1 -1
  88. package/out/adapters/street/line.js +5 -5
  89. package/out/adapters/street/line.js.map +1 -1
  90. package/out/adapters/street/unit.d.ts +4 -0
  91. package/out/adapters/street/unit.d.ts.map +1 -1
  92. package/out/adapters/street/unit.js +3 -0
  93. package/out/adapters/street/unit.js.map +1 -1
  94. package/out/adapters/wof/admin/json/adapter.d.ts +7 -0
  95. package/out/adapters/wof/admin/json/adapter.d.ts.map +1 -1
  96. package/out/adapters/wof/admin/json/adapter.js +28 -3
  97. package/out/adapters/wof/admin/json/adapter.js.map +1 -1
  98. package/out/adapters/wof/json-rows.d.ts +8 -0
  99. package/out/adapters/wof/json-rows.d.ts.map +1 -1
  100. package/out/adapters/wof/json-rows.js +56 -4
  101. package/out/adapters/wof/json-rows.js.map +1 -1
  102. package/out/adapters/wof/sample.d.ts +12 -0
  103. package/out/adapters/wof/sample.d.ts.map +1 -1
  104. package/out/adapters/wof/sample.js +37 -6
  105. package/out/adapters/wof/sample.js.map +1 -1
  106. package/out/au/adapters/gnaf/source.d.ts +9 -0
  107. package/out/au/adapters/gnaf/source.d.ts.map +1 -1
  108. package/out/au/adapters/gnaf/source.js +9 -0
  109. package/out/au/adapters/gnaf/source.js.map +1 -1
  110. package/out/build/code-hash.js +1 -1
  111. package/out/build/code-hash.js.map +1 -1
  112. package/out/cjk/foreign-places.js +1 -1
  113. package/out/cjk/foreign-places.js.map +1 -1
  114. package/out/fr/adapters/ban/adapter.d.ts.map +1 -1
  115. package/out/fr/adapters/ban/adapter.js +49 -7
  116. package/out/fr/adapters/ban/adapter.js.map +1 -1
  117. package/out/fr/recipes/admin-split.d.ts.map +1 -1
  118. package/out/fr/recipes/admin-split.js +15 -2
  119. package/out/fr/recipes/admin-split.js.map +1 -1
  120. package/out/fr/recipes/lieudit.js +1 -1
  121. package/out/fr/recipes/lieudit.js.map +1 -1
  122. package/out/fr/recipes/order.d.ts.map +1 -1
  123. package/out/fr/recipes/order.js +16 -5
  124. package/out/fr/recipes/order.js.map +1 -1
  125. package/out/international/recipes/locale.js +1 -1
  126. package/out/international/recipes/locale.js.map +1 -1
  127. package/out/kr/adapters/localdata/permit-rows.js +1 -1
  128. package/out/kr/adapters/localdata/permit-rows.js.map +1 -1
  129. package/out/parquet/schema.d.ts +6 -0
  130. package/out/parquet/schema.d.ts.map +1 -1
  131. package/out/parquet/schema.js +6 -0
  132. package/out/parquet/schema.js.map +1 -1
  133. package/out/recipes/po/box/cedex/recipe.js +1 -1
  134. package/out/recipes/po/box/cedex/recipe.js.map +1 -1
  135. package/out/recipes/po/box/cedex/vocabulary.d.ts +1 -1
  136. package/out/recipes/po/box/cedex/vocabulary.d.ts.map +1 -1
  137. package/out/recipes/po/box/cedex/vocabulary.js +4 -4
  138. package/out/recipes/po/box/cedex/vocabulary.js.map +1 -1
  139. package/out/recipes/trailing-region.d.ts.map +1 -1
  140. package/out/recipes/trailing-region.js +122 -17
  141. package/out/recipes/trailing-region.js.map +1 -1
  142. package/out/synthesizers/po-box.d.ts +7 -0
  143. package/out/synthesizers/po-box.d.ts.map +1 -1
  144. package/out/synthesizers/po-box.js +36 -12
  145. package/out/synthesizers/po-box.js.map +1 -1
  146. package/out/test-kit/corpus-recipe.d.ts +3 -0
  147. package/out/test-kit/corpus-recipe.d.ts.map +1 -1
  148. package/out/test-kit/corpus-recipe.js.map +1 -1
  149. package/out/tools/anthropic/batches.d.ts +117 -0
  150. package/out/tools/anthropic/batches.d.ts.map +1 -0
  151. package/out/tools/anthropic/batches.js +141 -0
  152. package/out/tools/anthropic/batches.js.map +1 -0
  153. package/out/tools/anthropic/labeling.d.ts +97 -0
  154. package/out/tools/anthropic/labeling.d.ts.map +1 -0
  155. package/out/tools/anthropic/labeling.js +146 -0
  156. package/out/tools/anthropic/labeling.js.map +1 -0
  157. package/out/tools/compact-v9.d.ts +124 -0
  158. package/out/tools/compact-v9.d.ts.map +1 -0
  159. package/out/tools/compact-v9.js +507 -0
  160. package/out/tools/compact-v9.js.map +1 -0
  161. package/out/tools/fetch/wikidata/vital-places/entities.d.ts +3 -0
  162. package/out/tools/fetch/wikidata/vital-places/entities.d.ts.map +1 -1
  163. package/out/tools/fetch/wikidata/vital-places/entities.js +19 -1
  164. package/out/tools/fetch/wikidata/vital-places/entities.js.map +1 -1
  165. package/out/tools/fetch/wikidata/vital-places/qrank.d.ts.map +1 -1
  166. package/out/tools/fetch/wikidata/vital-places/qrank.js +4 -4
  167. package/out/tools/fetch/wikidata/vital-places/qrank.js.map +1 -1
  168. package/out/tools/fragment-assay.run.js +1 -1
  169. package/out/tools/fragment-assay.run.js.map +1 -1
  170. package/out/tools/name-roles/name-roles.run.d.ts +2 -0
  171. package/out/tools/name-roles/name-roles.run.d.ts.map +1 -0
  172. package/out/tools/name-roles/name-roles.run.js +230 -0
  173. package/out/tools/name-roles/name-roles.run.js.map +1 -0
  174. package/out/tools/name-roles/prompt.d.ts +166 -0
  175. package/out/tools/name-roles/prompt.d.ts.map +1 -0
  176. package/out/tools/name-roles/prompt.js +176 -0
  177. package/out/tools/name-roles/prompt.js.map +1 -0
  178. package/out/tools/overlay/deletions.js +1 -1
  179. package/out/tools/overlay/deletions.js.map +1 -1
  180. package/out/tools/overlay/draw-weight.d.ts +86 -0
  181. package/out/tools/overlay/draw-weight.d.ts.map +1 -0
  182. package/out/tools/overlay/draw-weight.js +131 -0
  183. package/out/tools/overlay/draw-weight.js.map +1 -0
  184. package/out/tools/place-twins/place-twins.run.d.ts +2 -0
  185. package/out/tools/place-twins/place-twins.run.d.ts.map +1 -0
  186. package/out/tools/place-twins/place-twins.run.js +385 -0
  187. package/out/tools/place-twins/place-twins.run.js.map +1 -0
  188. package/out/tools/place-twins/prompt.d.ts +169 -0
  189. package/out/tools/place-twins/prompt.d.ts.map +1 -0
  190. package/out/tools/place-twins/prompt.js +183 -0
  191. package/out/tools/place-twins/prompt.js.map +1 -0
  192. package/out/tools/prominent-shapes/prominent-shapes.run.d.ts +2 -0
  193. package/out/tools/prominent-shapes/prominent-shapes.run.d.ts.map +1 -0
  194. package/out/tools/prominent-shapes/prominent-shapes.run.js +302 -0
  195. package/out/tools/prominent-shapes/prominent-shapes.run.js.map +1 -0
  196. package/out/tools/prominent-shapes/prompt.d.ts +74 -0
  197. package/out/tools/prominent-shapes/prompt.d.ts.map +1 -0
  198. package/out/tools/prominent-shapes/prompt.js +156 -0
  199. package/out/tools/prominent-shapes/prompt.js.map +1 -0
  200. package/out/tools/prominent-shapes/read-seeds.d.ts +23 -0
  201. package/out/tools/prominent-shapes/read-seeds.d.ts.map +1 -0
  202. package/out/tools/prominent-shapes/read-seeds.js +219 -0
  203. package/out/tools/prominent-shapes/read-seeds.js.map +1 -0
  204. package/out/tools/prominent-shapes/seeds.d.ts +132 -0
  205. package/out/tools/prominent-shapes/seeds.d.ts.map +1 -0
  206. package/out/tools/prominent-shapes/seeds.js +178 -0
  207. package/out/tools/prominent-shapes/seeds.js.map +1 -0
  208. package/out/tools/prominent-shapes/validate.d.ts +152 -0
  209. package/out/tools/prominent-shapes/validate.d.ts.map +1 -0
  210. package/out/tools/prominent-shapes/validate.js +389 -0
  211. package/out/tools/prominent-shapes/validate.js.map +1 -0
  212. package/out/tools/source-register/build.d.ts.map +1 -1
  213. package/out/tools/source-register/build.js +1 -0
  214. package/out/tools/source-register/build.js.map +1 -1
  215. package/out/training/config/admission.d.ts +2 -1
  216. package/out/training/config/admission.d.ts.map +1 -1
  217. package/out/training/config/admission.js +9 -2
  218. package/out/training/config/admission.js.map +1 -1
  219. package/out/training/config/schema.d.ts +276 -1
  220. package/out/training/config/schema.d.ts.map +1 -1
  221. package/out/training/config/schema.js +64 -1
  222. package/out/training/config/schema.js.map +1 -1
  223. package/out/types.d.ts +21 -0
  224. package/out/types.d.ts.map +1 -1
  225. package/out/types.js +13 -0
  226. package/out/types.js.map +1 -1
  227. package/out/us/adapters/usgov/usgs-structures/adapter.d.ts.map +1 -1
  228. package/out/us/adapters/usgov/usgs-structures/adapter.js +78 -4
  229. package/out/us/adapters/usgov/usgs-structures/adapter.js.map +1 -1
  230. package/out/utils/split.js +1 -1
  231. package/out/utils/split.js.map +1 -1
  232. package/package.json +24 -24
@@ -2,15 +2,15 @@
2
2
  // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
3
 
4
4
  /**
5
- * @file Reads GeoNames physical features (seas and undersea terrain, water, landforms, parks and vegetation) from a
6
- * country dump and emits rows that label each feature's name as `venue`.
5
+ * @file Reads GeoNames physical features (seas and undersea terrain, water, landforms, parks and vegetation)
6
+ * and class `S` transit stations from a country dump and emits rows that label each feature's name as `venue`.
7
7
  *
8
- * A search for `Mariana Trench` or `Lake Tahoe, California` asks for a place that has a name and no address.
9
- * The corpus held no such rows before this source (#2897), so the parser had never read a bare physical-feature
10
- * name. Each feature renders bare and with its region where GeoNames records one, and one feature in
8
+ * A search for `Mariana Trench`, `Lake Tahoe, California`, or `Heathrow Airport` asks for a place that has a name
9
+ * and no address. The corpus held no such rows before this source (#2897), so the parser had never read a bare
10
+ * physical-feature name. Each feature renders bare and with its region where GeoNames records one, and one feature in
11
11
  * {@linkcode GEONAMES_FEATURES_WITH_COUNTRY_DIVISOR} also renders with its own country.
12
12
  *
13
- * The dump holds 5,076,239 such features in 16,318 (country, feature code) cells on 2026-11-02, and 991,667 of them
13
+ * The dump holds 5,076,239 physical features in 16,318 (country, feature code) cells on 2026-11-02, and 991,667 of them
14
14
  * are streams (feature code `STM`). A cell keeps at most {@linkcode GEONAMES_FEATURES_PER_CELL} features, chosen by the lowest hash of their
15
15
  * geonameid, so every feature code of every country is represented and no one class dominates.
16
16
  */
@@ -38,11 +38,28 @@ import { AddressRole, type AdapterOptions, type CanonicalRow, type CorpusAdapter
38
38
  export const GEONAMES_FEATURES_ADAPTER_ID = "geonames-features"
39
39
 
40
40
  /**
41
- * The GeoNames feature classes this adapter reads: undersea (`U`), water (`H`),
42
- * terrain (`T`), parks and areas (`L`) and vegetation (`V`).
41
+ * The GeoNames feature classes this adapter reads unconditionally: undersea (`U`), water (`H`),
42
+ * terrain (`T`), parks and areas (`L`, which includes ports `PRT`) and vegetation (`V`).
43
43
  */
44
44
  export const GEONAMES_FEATURE_CLASSES: ReadonlySet<string> = new Set(["U", "H", "T", "L", "V"])
45
45
 
46
+ /**
47
+ * The GeoNames transit feature codes this adapter admits from class `S` (spots/buildings/facilities):
48
+ * airports (`AIRP`), rail stations (`RSTN`), metro stations (`MTRO`), bus stations (`BUSTN`),
49
+ * ports (`PRT`, also present under class `L`), and ferries (`FY`).
50
+ *
51
+ * `packages/mailwoman/tools/training/outcomes/masks.ts` routes these codes to the `transit`
52
+ * outcome reading using `geonames_transit_codes` in `packages/trainer/data/outcome_readings.json`.
53
+ */
54
+ const GEONAMES_TRANSIT_FEATURE_CODES: ReadonlySet<string> = new Set(["AIRP", "RSTN", "MTRO", "BUSTN", "PRT", "FY"])
55
+
56
+ function isSelectedGeonamesFeature(featureClass: string, featureCode: string): boolean {
57
+ return (
58
+ GEONAMES_FEATURE_CLASSES.has(featureClass) ||
59
+ (featureClass === "S" && GEONAMES_TRANSIT_FEATURE_CODES.has(featureCode))
60
+ )
61
+ }
62
+
46
63
  /**
47
64
  * The most features one (country, feature code) cell contributes.
48
65
  *
@@ -82,15 +99,16 @@ async function keptFeatureIDs(input: PathBuilder, country: string | undefined):
82
99
 
83
100
  for await (const rec of readUnquotedTSV(input)) {
84
101
  const cls = rec[COL.featureClass] ?? ""
102
+ const code = (rec[COL.featureCode] ?? "").trim()
85
103
 
86
- if (!GEONAMES_FEATURE_CLASSES.has(cls)) continue
104
+ if (!isSelectedGeonamesFeature(cls, code)) continue
87
105
  const cc = (rec[COL.country] ?? "").trim()
88
106
 
89
107
  if (!cc || (country && cc !== country)) continue
90
108
  const geonameid = (rec[COL.geonameid] ?? "").trim()
91
109
 
92
110
  if (!geonameid || !(rec[COL.name] ?? "").trim()) continue
93
- const key = `${cc}\t${rec[COL.featureCode] ?? ""}`
111
+ const key = `${cc}\t${code}`
94
112
  const kept = cells.get(key) ?? []
95
113
  const hash = hashFNV1a(geonameid)
96
114
 
@@ -126,7 +144,7 @@ export function createGeonamesFeaturesAdapter(): CorpusAdapter {
126
144
  register: SourceRegister.GeoNames,
127
145
  surface: SurfaceOrigin.Rendered,
128
146
  description:
129
- "GeoNames physical features (CC-BY-4.0): seas, undersea terrain, water bodies, landforms, parks and forests, labeled as venue.",
147
+ "GeoNames physical and transit features (CC-BY-4.0): seas, undersea terrain, water bodies, landforms, parks, forests, and transit hubs (airports, rail/metro/bus stations, ports, ferries), labeled as venue.",
130
148
 
131
149
  async *rows(opts: AdapterOptions): AsyncIterable<CanonicalRow> {
132
150
  // The input is one dump (`allCountries.txt`) or a directory of country dumps (`US.txt`, `MP.txt`).
@@ -41,13 +41,14 @@ export const OVERTURE_DEFAULT_LICENSE = "CDLA-Permissive-2.0"
41
41
  const DEFAULT_COUNTRY_SEED = 20_260_922
42
42
 
43
43
  /**
44
- * One attested written form of a country's name, never a two-letter code (`countryRenderForms`).
44
+ * One attested written form of a country's name (`countryRenderForms`), including the
45
+ * country's own bare alpha-2 code only when trailing a postcode of that same country (#3519).
45
46
  *
46
47
  * Raises rather than returning empty when the codex has no entry, so a requested
47
48
  * fraction cannot silently produce no country rows.
48
49
  */
49
- function countrySurfaceForm(country: string, random: () => number): string {
50
- const forms = countryRenderForms(country)
50
+ function countrySurfaceForm(country: string, random: () => number, afterPostcode: boolean): string {
51
+ const forms = countryRenderForms(country, { afterPostcode })
51
52
 
52
53
  if (!forms.length) {
53
54
  throw new Error(
@@ -80,8 +81,12 @@ interface OvertureCorpusRow {
80
81
  * `number` is its district-wide descriptive number (`číslo popisné`).
81
82
  * The two are written `descriptive/orientation`.
82
83
  * - `number-suffix`: a letter written against the house number.
84
+ * - `spaced-number-suffix`: a single letter written after the house number with a space,
85
+ * such as a Spanish cadastral portal suffix (`58 B`).
83
86
  */
84
- type OvertureUnitFieldRole = "orientation-number" | "number-suffix"
87
+ type OvertureUnitFieldRole = "orientation-number" | "number-suffix" | "spaced-number-suffix"
88
+
89
+ const SINGLE_LETTER_UNIT = /^\p{Letter}$/u
85
90
 
86
91
  /**
87
92
  * The role of Overture's `unit` field in each country where it isn't a secondary unit.
@@ -90,6 +95,9 @@ type OvertureUnitFieldRole = "orientation-number" | "number-suffix"
90
95
  * beside a digit `number` (101,127 of 394,880 rows, such as `Nad Stadiónem` `320` `28`),
91
96
  * and in the first 400,000 German rows 17,250 of the 17,304 filled ones are one
92
97
  * or two letters (`Neutrale Straße` `28` `a`).
98
+ *
99
+ * In Spanish Overture rows, single-letter `unit` values are cadastral portal letters
100
+ * (`8 A`, `58 B`) that Spanish INSPIRE cadastres write inside `house_number`.
93
101
  */
94
102
  const OVERTURE_UNIT_FIELD_ROLES: Readonly<Record<string, OvertureUnitFieldRole>> = {
95
103
  // UPU, Czech Rep. (02/2018): `The street number often consists of two numbers separated by a slash.
@@ -98,6 +106,8 @@ const OVERTURE_UNIT_FIELD_ROLES: Readonly<Record<string, OvertureUnitFieldRole>>
98
106
  CZ: "orientation-number",
99
107
  // UPU, Germany (01/2015): `Wacholderweg 52a`.
100
108
  DE: "number-suffix",
109
+ // Spanish INSPIRE cadastres write portal letters in `house_number` (`58 B`, `8 Ñ`).
110
+ ES: "spaced-number-suffix",
101
111
  }
102
112
 
103
113
  /**
@@ -109,9 +119,19 @@ function joinUnitIntoNumber(number: string, unit: string, role: OvertureUnitFiel
109
119
 
110
120
  if (role === "orientation-number") return /^\d+\p{Letter}?$/u.test(unit) ? `${number}/${unit}` : null
111
121
 
122
+ if (role === "spaced-number-suffix") return SINGLE_LETTER_UNIT.test(unit) ? `${number} ${unit}` : null
123
+
112
124
  return /^\p{Letter}{1,2}$/u.test(unit) ? `${number}${unit}` : null
113
125
  }
114
126
 
127
+ /**
128
+ * Whether `unit` is a bare single-letter portal suffix for a `spaced-number-suffix` country
129
+ * that couldn't join because the row has no numeric house number (such as Spanish `S-N` rows).
130
+ */
131
+ function isOrphanedSpacedNumberSuffix(unit: string, role: OvertureUnitFieldRole | null): boolean {
132
+ return role === "spaced-number-suffix" && SINGLE_LETTER_UNIT.test(unit)
133
+ }
134
+
115
135
  /**
116
136
  * How a region value in Overture's first address level becomes the form the country's
117
137
  * operator prints, for each country where Overture's value can be read as that form.
@@ -217,7 +237,7 @@ export function createOvertureAdapter(): CorpusAdapter {
217
237
 
218
238
  components.street = street
219
239
 
220
- if (!joined && unitFieldIsDesignator(unit)) {
240
+ if (!joined && !isOrphanedSpacedNumberSuffix(unit, unitRole) && unitFieldIsDesignator(unit)) {
221
241
  components.unit = unit
222
242
  }
223
243
 
@@ -238,7 +258,7 @@ export function createOvertureAdapter(): CorpusAdapter {
238
258
  // Overture rows are country-implicit, so the surface form goes into `components`
239
259
  // and each country's layout decides where the country lands in the rendered string.
240
260
  if (countryFraction > 0 && random() < countryFraction) {
241
- components.country = countrySurfaceForm(country, random)
261
+ components.country = countrySurfaceForm(country, random, Boolean(components.postcode))
242
262
  }
243
263
 
244
264
  const rendered = formatCorpusRow(components, country, { singleLine: true })
@@ -21,10 +21,10 @@
21
21
  * This pattern matches a leading house number on a US-style street line,
22
22
  * followed by whitespace and the rest.
23
23
  *
24
- * The number is digits, or a grid number with a directional letter before
25
- * or inside it (Wisconsin's `N8722`, Illinois' `40W514`).
26
- * An optional hyphenated range may follow, written with or without spaces
27
- * (Queens `40-12`, Hawaii `91 - 760`).
24
+ * The number is digits, or a grid number with a directional letter before or inside
25
+ * it (Wisconsin's `N8722` and two-axis `W330N4361`, Illinois' `40W514`).
26
+ * An optional hyphenated range or single-letter suffix may follow, written with
27
+ * or without spaces (Queens `40-12`, Hawaii `91 - 760`, Pennsylvania `4001 - B`).
28
28
  *
29
29
  * Then come an optional single alpha suffix (`101A`) and an optional half (`111 1/2`, `111 1 / 2`).
30
30
  * The half is only `1/2`, so a fractional street name stays in the street (`12345 16 1/2 Mile Rd`).
@@ -37,7 +37,8 @@
37
37
  * Group 2 is trimmed by the caller either way, so the two forms are indistinguishable on real input.
38
38
  * Only the failure cost differs.
39
39
  */
40
- export const HOUSE_NUMBER_PREFIX = /^((?:[NSEW]\d+|\d+(?:[NSEW]\d+)?)(?: ?- ?\d+)?[A-Za-z]?(?: 1 ?\/ ?2)?)\s+(\S.*)$/
40
+ export const HOUSE_NUMBER_PREFIX =
41
+ /^((?:[NSEW]\d+(?:[NSEW]\d+)?|\d+(?:[NSEW]\d+)?)(?: ?- ?(?:\d+[A-Za-z]?|[A-Za-z])|[A-Za-z])?(?: 1 ?\/ ?2)?)\s+(\S.*)$/
41
42
 
42
43
  /**
43
44
  * A grid house number written with its directional spelled out (Michigan's `West 17194 Main Street`).
@@ -464,6 +464,10 @@ export interface UnitSplitter {
464
464
  * @returns `null` when the street ends in no unit the country's vocabulary writes.
465
465
  */
466
466
  trailingUnit(street: string, place: StreetPlace): { street: string; unit: string } | null
467
+ /**
468
+ * The loaded street-type, directional, and unit vocabulary for `country`, or `null` when none was loaded.
469
+ */
470
+ vocabulary(country: string): UnitVocabulary | null
467
471
  }
468
472
 
469
473
  export interface CreateUnitSplitterOptions {
@@ -517,6 +521,9 @@ export async function createUnitSplitter(options: CreateUnitSplitterOptions = {}
517
521
 
518
522
  return splitLastUnit(street, vocabulary, place.postcode)
519
523
  },
524
+ vocabulary(country) {
525
+ return vocabularies.get(country.toUpperCase()) ?? null
526
+ },
520
527
  }
521
528
  }
522
529
 
@@ -72,9 +72,16 @@ import {
72
72
  import { RowSampler } from "#adapters/wof/sample"
73
73
  import { openStoredRecordEntries } from "#adapters/wof/stored-records"
74
74
  import { SourceRegister } from "#registers"
75
- import { AddressRole, type AdapterOptions, type CanonicalRow, type CorpusAdapter, SurfaceOrigin } from "#types"
75
+ import {
76
+ AddressRole,
77
+ type AdapterOptions,
78
+ type CanonicalRow,
79
+ type CorpusAdapter,
80
+ EveryPlaceNames,
81
+ SurfaceOrigin,
82
+ } from "#types"
76
83
  import { nameValues, preferredName, type AncestorRecords, type WOFRecord } from "#utils"
77
- import { ancestorRecordsOf } from "#utils/wof-json"
84
+ import { ancestorRecordsOf, parseWOFSlotKey } from "#utils/wof-json"
78
85
 
79
86
  /**
80
87
  * Map a WOF placetype to a Mailwoman `ComponentTag`, or `undefined` to skip.
@@ -633,6 +640,33 @@ export function nameSlotsFor(rec: WOFRecord): NameSlot[] {
633
640
  return slots.map((slot) => (slot.language && !kept.has(slot.language) ? { key: slot.key, value: slot.value } : slot))
634
641
  }
635
642
 
643
+ /**
644
+ * Whether the adapter renders `record` as a place: its placetype maps to a
645
+ * component tag, and WOF assigns it to a country.
646
+ *
647
+ * The place-coverage audit counts the places a corpus can train against this same rule.
648
+ */
649
+ export function rendersWOFAdminPlace(record: WOFRecord): boolean {
650
+ return Boolean(placetypeToTag(record.placetype)) && record.country !== WOF_NO_COUNTRY
651
+ }
652
+
653
+ /**
654
+ * The name slots of which every place keeps one row under `names`: the default name,
655
+ * and under {@linkcode EveryPlaceNames.Official} the first preferred name in
656
+ * each official language of the place's country.
657
+ */
658
+ function everyPlaceSlot(names: EveryPlaceNames): (country: string, slotKey: string) => boolean {
659
+ return (country, slotKey) => {
660
+ if (slotKey === "default") return true
661
+
662
+ if (names !== EveryPlaceNames.Official || /-[0-9]+$/.test(slotKey)) return false
663
+
664
+ const { kind, language } = parseWOFSlotKey(slotKey)
665
+
666
+ return kind === "preferred" && OFFICIAL_LANGUAGES[country]?.official.includes(language) === true
667
+ }
668
+ }
669
+
636
670
  /**
637
671
  * The `wof:country` WOF writes on a record it assigns to no country,
638
672
  * such as a disputed area or a record not yet placed.
@@ -672,7 +706,7 @@ export function createWOFAdminAdapter(): CorpusAdapter {
672
706
  // A record WOF assigns to no country names none for its rows, so it is skipped too.
673
707
  // A country-filtered run keeps only that country's records, ancestors included.
674
708
  using stored = await openStoredRecordEntries(opts, {
675
- keep: (record) => Boolean(placetypeToTag(record.placetype)) && record.country !== WOF_NO_COUNTRY,
709
+ keep: rendersWOFAdminPlace,
676
710
  resolve: (record, lookup) => ancestorRecordsOf(record, lookup, placetypeToTag),
677
711
  })
678
712
 
@@ -694,6 +728,7 @@ export function createWOFAdminAdapter(): CorpusAdapter {
694
728
  variantsFor,
695
729
  sampler,
696
730
  rowRule: dualRoleRowRule(WOF_ADMIN_ADAPTER_ID, pairs),
731
+ ...(opts.sample?.everyPlace ? { placeSlot: everyPlaceSlot(opts.sample.everyPlace) } : {}),
697
732
  })
698
733
 
699
734
  await sampler?.writeOutputs()
@@ -275,6 +275,14 @@ interface EmitWOFJSONRowsOptions<A extends object> {
275
275
  * Rows the adapter refuses or requires whatever the sample keeps.
276
276
  */
277
277
  rowRule?: WOFRowRule
278
+ /**
279
+ * Whether a place keeps one row of a name slot whatever the sample keeps,
280
+ * read from the row's country and slot key.
281
+ *
282
+ * Of a kept slot's rows, the one with the most components is emitted while the
283
+ * records are rendered, so the sampler holds no payload for it.
284
+ */
285
+ placeSlot?: (country: string, slotKey: string) => boolean
278
286
  }
279
287
 
280
288
  /**
@@ -301,13 +309,31 @@ export interface WOFRowRule {
301
309
  * while the row keeps the record's own country.
302
310
  */
303
311
  export function* emitWOFJSONRows<A extends object>(options: EmitWOFJSONRowsOptions<A>): Generator<CanonicalRow> {
304
- const { adapterOptions, sampler, rowRule } = options
312
+ const { adapterOptions, sampler, rowRule, placeSlot } = options
305
313
  const limit = adapterOptions.limit
306
314
  let emitted = 0
307
315
 
308
316
  if (sampler) {
309
- for (const { row, slotKey } of renderWOFRows(options)) {
310
- sampler.observe(sampledRow(row, slotKey), row, rowRule?.requires(row) ?? false)
317
+ for (const place of rowsByRecord(renderWOFRows(options))) {
318
+ const placeRows = placeSlot ? fullestRowPerSlot(place, placeSlot, rowRule) : new Set<CanonicalRow>()
319
+
320
+ for (const { row, slotKey } of place) {
321
+ const sampled = sampledRow(row, slotKey)
322
+
323
+ if (placeRows.has(row)) {
324
+ if (!sampler.observeEmitted(sampled, row)) continue
325
+
326
+ if (typeof limit === "number" && emitted >= limit) return
327
+
328
+ yield row
329
+
330
+ emitted++
331
+
332
+ continue
333
+ }
334
+
335
+ sampler.observe(sampled, row, rowRule?.requires(row) ?? false)
336
+ }
311
337
  }
312
338
  }
313
339
 
@@ -330,16 +356,68 @@ export function* emitWOFJSONRows<A extends object>(options: EmitWOFJSONRowsOptio
330
356
  }
331
357
  }
332
358
 
359
+ /**
360
+ * The rendered rows grouped by record, one group per record in the order rendered.
361
+ *
362
+ * The renderer writes all of a record's rows before the next record's,
363
+ * so a group closes when the record id changes.
364
+ */
365
+ function* rowsByRecord(
366
+ rows: Iterable<{ row: CanonicalRow; slotKey: string; recordID: number }>
367
+ ): Generator<Array<{ row: CanonicalRow; slotKey: string }>> {
368
+ let group: Array<{ row: CanonicalRow; slotKey: string }> = []
369
+ let current: number | null = null
370
+
371
+ for (const { row, slotKey, recordID } of rows) {
372
+ if (recordID !== current && group.length) {
373
+ yield group
374
+ group = []
375
+ }
376
+
377
+ current = recordID
378
+ group.push({ row, slotKey })
379
+ }
380
+
381
+ if (group.length) {
382
+ yield group
383
+ }
384
+ }
385
+
386
+ /**
387
+ * Of each name slot `placeSlot` keeps, the row with the most components, leaving out a row `rowRule` drops.
388
+ * A tie keeps the row rendered first.
389
+ */
390
+ function fullestRowPerSlot(
391
+ place: ReadonlyArray<{ row: CanonicalRow; slotKey: string }>,
392
+ placeSlot: (country: string, slotKey: string) => boolean,
393
+ rowRule: WOFRowRule | undefined
394
+ ): Set<CanonicalRow> {
395
+ const fullest = new Map<string, CanonicalRow>()
396
+
397
+ for (const { row, slotKey } of place) {
398
+ if (!placeSlot(row.country, slotKey) || rowRule?.drops(row)) continue
399
+
400
+ const held = fullest.get(slotKey)
401
+
402
+ if (!held || Object.keys(row.components).length > Object.keys(held.components).length) {
403
+ fullest.set(slotKey, row)
404
+ }
405
+ }
406
+
407
+ return new Set(fullest.values())
408
+ }
409
+
333
410
  function sampledRow(row: CanonicalRow, slotKey: string): SampledRow {
334
411
  return { sourceID: row.source_id, country: row.country, slotKey, raw: row.raw, components: row.components }
335
412
  }
336
413
 
337
414
  /**
338
- * Every row the records render, in WOF-id order, each with the name-slot key it came from.
415
+ * Every row the records render, in WOF-id order, each with the name-slot key
416
+ * and the record id it came from.
339
417
  */
340
418
  function* renderWOFRows<A extends object>(
341
419
  options: EmitWOFJSONRowsOptions<A>
342
- ): Generator<{ row: CanonicalRow; slotKey: string }> {
420
+ ): Generator<{ row: CanonicalRow; slotKey: string; recordID: number }> {
343
421
  const {
344
422
  records,
345
423
  adapterOptions,
@@ -367,6 +445,7 @@ function* renderWOFRows<A extends object>(
367
445
 
368
446
  yield {
369
447
  slotKey: slot.key,
448
+ recordID: record.id,
370
449
  row: {
371
450
  raw,
372
451
  components,
@@ -209,6 +209,11 @@ export class RowSampler<T = SampledRow> {
209
209
  readonly #comparison = new Map<string, LowestValues>()
210
210
  readonly #comparisonCandidates = new Map<string, Candidate<T> & { order: number }>()
211
211
  #keptRaws: Set<number> | null = null
212
+ /**
213
+ * Case-folded text hashes of the rows the caller emitted itself
214
+ * through {@linkcode RowSampler.observeEmitted}.
215
+ */
216
+ readonly #emittedRaws = new Set<number>()
212
217
  /**
213
218
  * Renderable rows per full cell, `country|tag order|kind|language`.
214
219
  */
@@ -251,9 +256,28 @@ export class RowSampler<T = SampledRow> {
251
256
  * moves no other row's keep decision.
252
257
  */
253
258
  observe(row: SampledRow, payload: T, required = false): void {
259
+ this.#observe(row, payload, required ? "required" : "sampled")
260
+ }
261
+
262
+ /**
263
+ * Counts a row its caller emits itself, whatever its hash, and returns whether the caller may emit it.
264
+ *
265
+ * The row enters its cells' heaps as a required row does, so emitting it
266
+ * moves no other row's keep decision.
267
+ * The sampler holds no payload for it, so emitting a row of every place adds
268
+ * no row to the sampler's memory.
269
+ *
270
+ * A row the aligner would quarantine, or a row in a held-out cell, returns false:
271
+ * the first is dropped and the second is held out as {@linkcode RowSampler.observe} holds it.
272
+ */
273
+ observeEmitted(row: SampledRow, payload: T): boolean {
274
+ return this.#observe(row, payload, "emitted")
275
+ }
276
+
277
+ #observe(row: SampledRow, payload: T, mode: "sampled" | "required" | "emitted"): boolean {
254
278
  const keys = this.#keys(row)
255
279
 
256
- if (!keys) return
280
+ if (!keys) return false
257
281
 
258
282
  const { hash, structure, order, language, cell } = keys
259
283
  const raw = hashFNV1a(row.raw.normalize("NFC").toLowerCase())
@@ -285,7 +309,7 @@ export class RowSampler<T = SampledRow> {
285
309
  this.#heldOutCandidates.set(row.sourceID, { ...base, group: heldOutGroup })
286
310
  }
287
311
 
288
- return
312
+ return false
289
313
  }
290
314
 
291
315
  const held = [
@@ -294,8 +318,15 @@ export class RowSampler<T = SampledRow> {
294
318
  lowest(this.#country, row.country, this.#sample.rowsPerCountry),
295
319
  ].some(Boolean)
296
320
 
297
- if (held || required) {
298
- this.#candidates.set(row.sourceID, required ? { ...base, required } : base)
321
+ // An emitted row is kept by construction, so it can't be a comparison row and needs no candidate.
322
+ if (mode === "emitted") {
323
+ this.#emittedRaws.add(raw)
324
+
325
+ return true
326
+ }
327
+
328
+ if (held || mode === "required") {
329
+ this.#candidates.set(row.sourceID, mode === "required" ? { ...base, required: true } : base)
299
330
  }
300
331
 
301
332
  const compareGroup = [structure, order].find((key) => this.#compare.has(key))
@@ -313,6 +344,8 @@ export class RowSampler<T = SampledRow> {
313
344
  this.#comparisonCandidates.set(row.sourceID, { ...base, group: compareGroup, order: second })
314
345
  }
315
346
  }
347
+
348
+ return false
316
349
  }
317
350
 
318
351
  #isKept(candidate: Candidate<T>): boolean {
@@ -325,10 +358,13 @@ export class RowSampler<T = SampledRow> {
325
358
  }
326
359
 
327
360
  /**
328
- * Case-folded text hashes of every kept row, computed once the pass is over.
361
+ * Case-folded text hashes of every kept or emitted row, computed once the pass is over.
329
362
  */
330
363
  #keptRawHashes(): Set<number> {
331
- this.#keptRaws ??= new Set([...this.#candidates.values()].filter((c) => this.#isKept(c)).map((c) => c.raw))
364
+ this.#keptRaws ??= new Set([
365
+ ...this.#emittedRaws,
366
+ ...[...this.#candidates.values()].filter((c) => this.#isKept(c)).map((c) => c.raw),
367
+ ])
332
368
 
333
369
  return this.#keptRaws
334
370
  }
@@ -13,6 +13,18 @@ import type { SourceLocation } from "@mailwoman/core/resolver"
13
13
  */
14
14
  export const GNAF_SOURCE_NAME = "gnaf"
15
15
 
16
+ /**
17
+ * The repository-defined license identifier for the Open G-NAF End User License
18
+ * Agreement (26 February 2016).
19
+ */
20
+ export const GNAF_LICENSE = "LicenseRef-Open-GNAF-EULA-2016"
21
+
22
+ /**
23
+ * The attribution line recorded in a G-NAF layer manifest, naming the §2(a)(2) mail-list verification rider.
24
+ */
25
+ export const GNAF_ATTRIBUTION =
26
+ "© Geoscape Australia — G-NAF, Open G-NAF EULA (26 February 2016; CC BY 4.0 with §2(a)(2) mail-list verification use restriction)"
27
+
16
28
  /**
17
29
  * Where a user obtains G-NAF.
18
30
  *
@@ -136,7 +136,7 @@ export async function cruiseModuleGraph(roots: readonly string[], repositoryRoot
136
136
  {}
137
137
  )
138
138
 
139
- if (typeof result.output === "string") throw new Error("cruiseModuleGraph: dependency-cruiser returned text")
139
+ if (typeof result.output === "string") throw new TypeError("cruiseModuleGraph: dependency-cruiser returned text")
140
140
 
141
141
  const edges = new Map<string, string[]>()
142
142
  const packages = new Map<string, string[]>()
@@ -233,7 +233,7 @@ export async function heldOutIDs(splitAttribute: string): Promise<Map<string, st
233
233
  for (const split of ["val", "test"] as const) {
234
234
  const ids = attribute[split]
235
235
 
236
- if (!Array.isArray(ids)) throw new Error(`split attribute ${splitAttribute} has no ${split} list`)
236
+ if (!Array.isArray(ids)) throw new TypeError(`split attribute ${splitAttribute} has no ${split} list`)
237
237
 
238
238
  for (const id of ids) {
239
239
  held.set(id, split)
@@ -32,6 +32,8 @@
32
32
  */
33
33
 
34
34
  import { formatAddressRow } from "@mailwoman/codex/address/format"
35
+ import { hashFNV1a } from "@mailwoman/core/coarse-placer/fnv-hash"
36
+ import { isPresent } from "@mailwoman/core/values/objects"
35
37
  import { CSVSpliterator } from "spliterator"
36
38
 
37
39
  import { UnsupportedCountryError } from "#adapters/errors"
@@ -74,6 +76,53 @@ interface BanRow {
74
76
  nom_commune: string
75
77
  }
76
78
 
79
+ /**
80
+ * Number of hash buckets per 100 rows rendered in French postcode-first or separator formats
81
+ * (5% total: 1% per variant, preserving canonical street-first rendering for 95% of BAN rows).
82
+ */
83
+ const POSTCODE_FIRST_BUCKET_MODULUS = 100
84
+ const POSTCODE_FIRST_VARIANT_COUNT = 5
85
+
86
+ /**
87
+ * Renders a deterministic 5% share of postcode-carrying, unit-free BAN rows in observed French
88
+ * postcode-first and comma/dash separator shapes, returning `null` for the 95% canonical majority.
89
+ */
90
+ function maybeFormatPostcodeFirstRow(
91
+ components: CanonicalRow["components"],
92
+ sourceID: string
93
+ ): { raw: string; components: CanonicalRow["components"] } | null {
94
+ if (!components.postcode || !components.locality || components.unit) return null
95
+
96
+ const bucket = hashFNV1a(`ban-postcode-first:${sourceID}`) % POSTCODE_FIRST_BUCKET_MODULUS
97
+
98
+ if (bucket >= POSTCODE_FIRST_VARIANT_COUNT) return null
99
+
100
+ const { postcode, locality } = components
101
+ const streetLine = [components.house_number, components.street_prefix, components.street].filter(isPresent).join(" ")
102
+
103
+ if (!streetLine) return null
104
+
105
+ switch (bucket) {
106
+ case 0:
107
+ // `47110, 14 Rue Mozart, Sainte-Livrade-sur-Lot`
108
+ return { raw: `${postcode}, ${streetLine}, ${locality}`, components }
109
+ case 1:
110
+ // `37000, Tours`
111
+ return { raw: `${postcode}, ${locality}`, components: { postcode, locality } }
112
+ case 2:
113
+ // `35650 - Le Rheu`
114
+ return { raw: `${postcode} - ${locality}`, components: { postcode, locality } }
115
+ case 3:
116
+ // `47110, Sainte-Livrade-sur-Lot, 14 Rue Mozart`
117
+ return { raw: `${postcode}, ${locality}, ${streetLine}`, components }
118
+ case 4:
119
+ // `47110 - 14 Rue Mozart, Sainte-Livrade-sur-Lot`
120
+ return { raw: `${postcode} - ${streetLine}, ${locality}`, components }
121
+ default:
122
+ return null
123
+ }
124
+ }
125
+
77
126
  export function createBanAdapter(): CorpusAdapter {
78
127
  return {
79
128
  id: BAN_ADAPTER_ID,
@@ -167,7 +216,13 @@ export function createBanAdapter(): CorpusAdapter {
167
216
  components.locality = locality
168
217
  }
169
218
 
170
- const rendered = formatAddressRow(components, country, { singleLine: true })
219
+ // BAN repeats an `id` across the postcodes of a merged commune: `27213_0028_00001` is
220
+ // `1 Grande Rue` in each of Vexin-sur-Epte's 27420, 27510 and 27630 villages (#2894).
221
+ // The postcode in the id keeps those addresses apart.
222
+ const recordID = record.id ? `${BAN_ADAPTER_ID}-${record.id}${postcode ? `-${postcode}` : ""}` : null
223
+ const variant = maybeFormatPostcodeFirstRow(components, recordID ?? stableSourceID(BAN_ADAPTER_ID, components))
224
+
225
+ const rendered = variant ?? formatAddressRow(components, country, { singleLine: true })
171
226
 
172
227
  if (!rendered) {
173
228
  countDropped(opts, "row:render-failed")
@@ -176,13 +231,7 @@ export function createBanAdapter(): CorpusAdapter {
176
231
  }
177
232
 
178
233
  const { raw, components: aligned } = rendered
179
-
180
- // BAN repeats an `id` across the postcodes of a merged commune: `27213_0028_00001` is
181
- // `1 Grande Rue` in each of Vexin-sur-Epte's 27420, 27510 and 27630 villages (#2894).
182
- // The postcode in the id keeps those addresses apart.
183
- const sourceID = record.id
184
- ? `${BAN_ADAPTER_ID}-${record.id}${postcode ? `-${postcode}` : ""}`
185
- : stableSourceID(BAN_ADAPTER_ID, aligned)
234
+ const sourceID = recordID ?? stableSourceID(BAN_ADAPTER_ID, aligned)
186
235
 
187
236
  yield {
188
237
  raw,
@@ -77,6 +77,9 @@ const BARE_COMMA_CUTOFF = 0.25
77
77
  const BARE_COMMA_PC_CUTOFF = 0.5
78
78
  const SPACE_PC_CUTOFF = 0.7
79
79
  const CANONICAL_PC_FIRST_CUTOFF = 0.85
80
+ // Separator split inside postcode-first commune rows: 50% space, 25% comma, 25% dash.
81
+ const PC_FIRST_SPACE_CUTOFF = 0.5
82
+ const PC_FIRST_COMMA_CUTOFF = 0.75
80
83
  // Share of rows with an explicit country component.
81
84
  const APPEND_COUNTRY_SHARE = 0.2
82
85
 
@@ -104,8 +107,17 @@ function render(random: () => number, c: CommuneRow): AdminSplitVariant {
104
107
  // Space-delimited region with postcode.
105
108
  out = { raw: `${loc} ${dep} ${pc}`, components: { locality: loc, region: dep, postcode: pc }, order: "space-pc" }
106
109
  } else if (r < CANONICAL_PC_FIRST_CUTOFF) {
107
- // Canonical postcode-first form without département.
108
- out = { raw: `${pc} ${loc}`, components: { postcode: pc, locality: loc }, order: "canonical-pc-first" }
110
+ // Postcode-first commune forms without département, covering space (`37000 Tours`),
111
+ // comma (`37000, Tours`), and dash (`35650 - Le Rheu`) separators.
112
+ const sepRoll = random()
113
+
114
+ if (sepRoll < PC_FIRST_SPACE_CUTOFF) {
115
+ out = { raw: `${pc} ${loc}`, components: { postcode: pc, locality: loc }, order: "canonical-pc-first" }
116
+ } else if (sepRoll < PC_FIRST_COMMA_CUTOFF) {
117
+ out = { raw: `${pc}, ${loc}`, components: { postcode: pc, locality: loc }, order: "comma-pc-first" }
118
+ } else {
119
+ out = { raw: `${pc} - ${loc}`, components: { postcode: pc, locality: loc }, order: "dash-pc-first" }
120
+ }
109
121
  } else {
110
122
  // Commune and postcode without département.
111
123
  out = { raw: `${loc} ${pc}`, components: { locality: loc, postcode: pc }, order: "commune-pc" }