@mailwoman/corpus 12.0.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 (94) hide show
  1. package/data/address-source-register.json +545 -11
  2. package/data/license-decisions.json +440 -9
  3. package/data/licenses/PROVENANCE.md +27 -18
  4. package/data/licenses/at-bev-adressregister-cc-by-4.0.md +25 -0
  5. package/data/licenses/br-ibge-cnefe-open-data.md +21 -0
  6. package/data/licenses/ca-qc-mrnf-cc-by-4.0.md +29 -0
  7. package/data/licenses/ca-statcan-open-licence.md +41 -0
  8. package/data/licenses/ca-yukon-ogl-2.0.md +19 -0
  9. package/data/licenses/dk-dmikg-cc-by-4.0.md +43 -0
  10. package/data/licenses/jp-mlit-isj-pdl-1.0.md +35 -0
  11. package/data/source-additions.json +90 -0
  12. package/data/source-resolutions.json +3 -2
  13. package/data/training-configs/v9.1.0-bytestem-global-v091-s42.yaml +710 -0
  14. package/data/training-configs/v9.2.0-bytestem-global-v092-s42.yaml +714 -0
  15. package/data/training-manifests/v0.9.1-compact.json +9660 -0
  16. package/data/training-manifests/v0.9.2-compact.effective.json +2670 -0
  17. package/data/training-manifests/v0.9.2-compact.json +9660 -0
  18. package/lib/adapters/geonames/features/adapter.ts +29 -11
  19. package/lib/adapters/overture/adapter.ts +26 -6
  20. package/lib/adapters/street/line.ts +6 -5
  21. package/lib/adapters/street/unit.ts +7 -0
  22. package/lib/au/adapters/gnaf/source.ts +12 -0
  23. package/lib/fr/adapters/ban/adapter.ts +57 -8
  24. package/lib/fr/recipes/admin-split.ts +14 -2
  25. package/lib/fr/recipes/lieudit.ts +1 -1
  26. package/lib/fr/recipes/order.ts +14 -5
  27. package/lib/international/recipes/locale.ts +1 -1
  28. package/lib/recipes/po/box/cedex/recipe.ts +1 -1
  29. package/lib/recipes/po/box/cedex/vocabulary.ts +4 -4
  30. package/lib/recipes/trailing-region.ts +147 -17
  31. package/lib/synthesizers/po-box.ts +51 -12
  32. package/lib/test-kit/corpus-recipe.ts +3 -0
  33. package/lib/tools/compact-v9.ts +22 -4
  34. package/lib/tools/source-register/build.ts +1 -0
  35. package/lib/us/adapters/usgov/usgs-structures/adapter.ts +103 -6
  36. package/out/adapters/geonames/features/adapter.d.ts +2 -2
  37. package/out/adapters/geonames/features/adapter.d.ts.map +1 -1
  38. package/out/adapters/geonames/features/adapter.js +25 -11
  39. package/out/adapters/geonames/features/adapter.js.map +1 -1
  40. package/out/adapters/overture/adapter.d.ts.map +1 -1
  41. package/out/adapters/overture/adapter.js +21 -5
  42. package/out/adapters/overture/adapter.js.map +1 -1
  43. package/out/adapters/street/line.d.ts +4 -4
  44. package/out/adapters/street/line.d.ts.map +1 -1
  45. package/out/adapters/street/line.js +5 -5
  46. package/out/adapters/street/line.js.map +1 -1
  47. package/out/adapters/street/unit.d.ts +4 -0
  48. package/out/adapters/street/unit.d.ts.map +1 -1
  49. package/out/adapters/street/unit.js +3 -0
  50. package/out/adapters/street/unit.js.map +1 -1
  51. package/out/au/adapters/gnaf/source.d.ts +9 -0
  52. package/out/au/adapters/gnaf/source.d.ts.map +1 -1
  53. package/out/au/adapters/gnaf/source.js +9 -0
  54. package/out/au/adapters/gnaf/source.js.map +1 -1
  55. package/out/fr/adapters/ban/adapter.d.ts.map +1 -1
  56. package/out/fr/adapters/ban/adapter.js +49 -7
  57. package/out/fr/adapters/ban/adapter.js.map +1 -1
  58. package/out/fr/recipes/admin-split.d.ts.map +1 -1
  59. package/out/fr/recipes/admin-split.js +15 -2
  60. package/out/fr/recipes/admin-split.js.map +1 -1
  61. package/out/fr/recipes/lieudit.js +1 -1
  62. package/out/fr/recipes/lieudit.js.map +1 -1
  63. package/out/fr/recipes/order.d.ts.map +1 -1
  64. package/out/fr/recipes/order.js +16 -5
  65. package/out/fr/recipes/order.js.map +1 -1
  66. package/out/international/recipes/locale.js +1 -1
  67. package/out/international/recipes/locale.js.map +1 -1
  68. package/out/recipes/po/box/cedex/recipe.js +1 -1
  69. package/out/recipes/po/box/cedex/recipe.js.map +1 -1
  70. package/out/recipes/po/box/cedex/vocabulary.d.ts +1 -1
  71. package/out/recipes/po/box/cedex/vocabulary.d.ts.map +1 -1
  72. package/out/recipes/po/box/cedex/vocabulary.js +4 -4
  73. package/out/recipes/po/box/cedex/vocabulary.js.map +1 -1
  74. package/out/recipes/trailing-region.d.ts.map +1 -1
  75. package/out/recipes/trailing-region.js +122 -17
  76. package/out/recipes/trailing-region.js.map +1 -1
  77. package/out/synthesizers/po-box.d.ts +7 -0
  78. package/out/synthesizers/po-box.d.ts.map +1 -1
  79. package/out/synthesizers/po-box.js +36 -12
  80. package/out/synthesizers/po-box.js.map +1 -1
  81. package/out/test-kit/corpus-recipe.d.ts +3 -0
  82. package/out/test-kit/corpus-recipe.d.ts.map +1 -1
  83. package/out/test-kit/corpus-recipe.js.map +1 -1
  84. package/out/tools/compact-v9.d.ts +8 -1
  85. package/out/tools/compact-v9.d.ts.map +1 -1
  86. package/out/tools/compact-v9.js +17 -4
  87. package/out/tools/compact-v9.js.map +1 -1
  88. package/out/tools/source-register/build.d.ts.map +1 -1
  89. package/out/tools/source-register/build.js +1 -0
  90. package/out/tools/source-register/build.js.map +1 -1
  91. package/out/us/adapters/usgov/usgs-structures/adapter.d.ts.map +1 -1
  92. package/out/us/adapters/usgov/usgs-structures/adapter.js +78 -4
  93. package/out/us/adapters/usgov/usgs-structures/adapter.js.map +1 -1
  94. package/package.json +19 -19
@@ -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
 
@@ -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
  *
@@ -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" }
@@ -249,7 +249,7 @@ export const frLieuditRecipe: CorpusRecipe = {
249
249
  // This keeps the byte-stream a function of `countryFraction` rather than of
250
250
  // the mixture of jurisdictions in the input files.
251
251
  if (countryFraction > 0 && random() < countryFraction) {
252
- const forms = countryRenderForms(country)
252
+ const forms = countryRenderForms(country, { afterPostcode: Boolean(components.postcode) })
253
253
 
254
254
  if (forms.length) {
255
255
  const form = sample(forms, random)
@@ -84,11 +84,14 @@ function renderCanonical(
84
84
  return { raw, components: { house_number: hn, street, postcode, locality } }
85
85
  }
86
86
 
87
- // Cumulative cutoffs for three reversed layouts.
88
- // Each moves the admin tail ahead of the street or splits it around the street.
87
+ // Cumulative cutoffs for five reversed layouts.
88
+ // Each moves the admin tail ahead of the street or splits it around the street, including comma-
89
+ // and dash-separated postcode-first shapes observed in French postcode misses.
89
90
  // The training-time `postcode_move` augmentation (#2750) moves the postcode across the locality.
90
- const REVERSED_VARIANT_A_CUTOFF = 1 / 3
91
- const REVERSED_VARIANT_B_CUTOFF = 2 / 3
91
+ const REVERSED_VARIANT_A_CUTOFF = 0.2
92
+ const REVERSED_VARIANT_B_CUTOFF = 0.4
93
+ const REVERSED_VARIANT_C_CUTOFF = 0.6
94
+ const REVERSED_VARIANT_D_CUTOFF = 0.8
92
95
 
93
96
  /**
94
97
  * Recipe registered with the corpus builder.
@@ -145,9 +148,15 @@ export const frOrderRecipe: CorpusRecipe = {
145
148
  } else if (variantRoll < REVERSED_VARIANT_B_CUTOFF) {
146
149
  // Locality, postcode, number and street.
147
150
  raw = `${locality}, ${postcode}, ${house_number} ${street}`
148
- } else {
151
+ } else if (variantRoll < REVERSED_VARIANT_C_CUTOFF) {
149
152
  // Postcode, number, street, then locality.
150
153
  raw = `${postcode}, ${house_number} ${street}, ${locality}`
154
+ } else if (variantRoll < REVERSED_VARIANT_D_CUTOFF) {
155
+ // Postcode, locality, then number and street.
156
+ raw = `${postcode}, ${locality}, ${house_number} ${street}`
157
+ } else {
158
+ // Dash-separated postcode, number and street, then locality.
159
+ raw = `${postcode} - ${house_number} ${street}, ${locality}`
151
160
  }
152
161
 
153
162
  rendered = { raw, components: { house_number, street, postcode, locality } }
@@ -549,7 +549,7 @@ export function applyCountryAppend(
549
549
  random: () => number
550
550
  ): void {
551
551
  if (countryFraction > 0 && random() < countryFraction) {
552
- const forms = countryRenderForms(country)
552
+ const forms = countryRenderForms(country, { afterPostcode: Boolean(synth.components.postcode) })
553
553
 
554
554
  if (!forms.length) {
555
555
  throw new Error(
@@ -154,7 +154,7 @@ export const poBoxCedexRecipe: CorpusRecipe = {
154
154
  country = "NZ"
155
155
  locale = "en-NZ"
156
156
  } else if (kind === "po-box-us-military") {
157
- const military = synthesizeMilitaryPoBoxRow({ random })
157
+ const military = synthesizeMilitaryPoBoxRow({ random, varyCase: true })
158
158
  const { country: _country, ...components } = military.components
159
159
  rendered = { fmt: "po-box-military", raw: military.raw, components: components as Record<string, string> }
160
160
  country = "US"
@@ -51,15 +51,15 @@ export const AU_LEADERS_CURRENT = ["PO Box", "P.O. Box", "Post Office Box", "GPO
51
51
  /**
52
52
  * Recognized legacy Australian delivery-service leaders.
53
53
  */
54
- export const AU_LEADERS_LEGACY = ["RMB", "RSD", "CMB"]
54
+ export const AU_LEADERS_LEGACY = ["RMB", "RSD", "CMB", "Community Mail Bag"]
55
55
  /**
56
56
  * Common New Zealand delivery-service leaders.
57
57
  */
58
- export const NZ_LEADERS_COMMON = ["PO Box", "Private Bag"]
58
+ export const NZ_LEADERS_COMMON = ["PO Box", "Private Bag", "Private Box"]
59
59
  /**
60
- * Rare New Zealand delivery-service leader.
60
+ * Rare New Zealand delivery-service leaders.
61
61
  */
62
- export const NZ_LEADERS_RARE = ["CMB"]
62
+ export const NZ_LEADERS_RARE = ["CMB", "Response Bag", "Community Mail Box"]
63
63
 
64
64
  /**
65
65
  * Quebec first-letter choices from the Canadian FSA prior.