@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.
- package/data/address-source-register.json +545 -11
- package/data/license-decisions.json +440 -9
- package/data/licenses/PROVENANCE.md +27 -18
- package/data/licenses/at-bev-adressregister-cc-by-4.0.md +25 -0
- package/data/licenses/br-ibge-cnefe-open-data.md +21 -0
- package/data/licenses/ca-qc-mrnf-cc-by-4.0.md +29 -0
- package/data/licenses/ca-statcan-open-licence.md +41 -0
- package/data/licenses/ca-yukon-ogl-2.0.md +19 -0
- package/data/licenses/dk-dmikg-cc-by-4.0.md +43 -0
- package/data/licenses/jp-mlit-isj-pdl-1.0.md +35 -0
- package/data/source-additions.json +90 -0
- package/data/source-resolutions.json +3 -2
- package/data/training-configs/v9.1.0-bytestem-global-v091-s42.yaml +710 -0
- package/data/training-configs/v9.2.0-bytestem-global-v092-s42.yaml +714 -0
- package/data/training-manifests/v0.9.1-compact.json +9660 -0
- package/data/training-manifests/v0.9.2-compact.effective.json +2670 -0
- package/data/training-manifests/v0.9.2-compact.json +9660 -0
- package/lib/adapters/geonames/features/adapter.ts +29 -11
- package/lib/adapters/overture/adapter.ts +26 -6
- package/lib/adapters/street/line.ts +6 -5
- package/lib/adapters/street/unit.ts +7 -0
- package/lib/au/adapters/gnaf/source.ts +12 -0
- package/lib/fr/adapters/ban/adapter.ts +57 -8
- package/lib/fr/recipes/admin-split.ts +14 -2
- package/lib/fr/recipes/lieudit.ts +1 -1
- package/lib/fr/recipes/order.ts +14 -5
- package/lib/international/recipes/locale.ts +1 -1
- package/lib/recipes/po/box/cedex/recipe.ts +1 -1
- package/lib/recipes/po/box/cedex/vocabulary.ts +4 -4
- package/lib/recipes/trailing-region.ts +147 -17
- package/lib/synthesizers/po-box.ts +51 -12
- package/lib/test-kit/corpus-recipe.ts +3 -0
- package/lib/tools/compact-v9.ts +22 -4
- package/lib/tools/source-register/build.ts +1 -0
- package/lib/us/adapters/usgov/usgs-structures/adapter.ts +103 -6
- package/out/adapters/geonames/features/adapter.d.ts +2 -2
- package/out/adapters/geonames/features/adapter.d.ts.map +1 -1
- package/out/adapters/geonames/features/adapter.js +25 -11
- package/out/adapters/geonames/features/adapter.js.map +1 -1
- package/out/adapters/overture/adapter.d.ts.map +1 -1
- package/out/adapters/overture/adapter.js +21 -5
- package/out/adapters/overture/adapter.js.map +1 -1
- package/out/adapters/street/line.d.ts +4 -4
- package/out/adapters/street/line.d.ts.map +1 -1
- package/out/adapters/street/line.js +5 -5
- package/out/adapters/street/line.js.map +1 -1
- package/out/adapters/street/unit.d.ts +4 -0
- package/out/adapters/street/unit.d.ts.map +1 -1
- package/out/adapters/street/unit.js +3 -0
- package/out/adapters/street/unit.js.map +1 -1
- package/out/au/adapters/gnaf/source.d.ts +9 -0
- package/out/au/adapters/gnaf/source.d.ts.map +1 -1
- package/out/au/adapters/gnaf/source.js +9 -0
- package/out/au/adapters/gnaf/source.js.map +1 -1
- package/out/fr/adapters/ban/adapter.d.ts.map +1 -1
- package/out/fr/adapters/ban/adapter.js +49 -7
- package/out/fr/adapters/ban/adapter.js.map +1 -1
- package/out/fr/recipes/admin-split.d.ts.map +1 -1
- package/out/fr/recipes/admin-split.js +15 -2
- package/out/fr/recipes/admin-split.js.map +1 -1
- package/out/fr/recipes/lieudit.js +1 -1
- package/out/fr/recipes/lieudit.js.map +1 -1
- package/out/fr/recipes/order.d.ts.map +1 -1
- package/out/fr/recipes/order.js +16 -5
- package/out/fr/recipes/order.js.map +1 -1
- package/out/international/recipes/locale.js +1 -1
- package/out/international/recipes/locale.js.map +1 -1
- package/out/recipes/po/box/cedex/recipe.js +1 -1
- package/out/recipes/po/box/cedex/recipe.js.map +1 -1
- package/out/recipes/po/box/cedex/vocabulary.d.ts +1 -1
- package/out/recipes/po/box/cedex/vocabulary.d.ts.map +1 -1
- package/out/recipes/po/box/cedex/vocabulary.js +4 -4
- package/out/recipes/po/box/cedex/vocabulary.js.map +1 -1
- package/out/recipes/trailing-region.d.ts.map +1 -1
- package/out/recipes/trailing-region.js +122 -17
- package/out/recipes/trailing-region.js.map +1 -1
- package/out/synthesizers/po-box.d.ts +7 -0
- package/out/synthesizers/po-box.d.ts.map +1 -1
- package/out/synthesizers/po-box.js +36 -12
- package/out/synthesizers/po-box.js.map +1 -1
- package/out/test-kit/corpus-recipe.d.ts +3 -0
- package/out/test-kit/corpus-recipe.d.ts.map +1 -1
- package/out/test-kit/corpus-recipe.js.map +1 -1
- package/out/tools/compact-v9.d.ts +8 -1
- package/out/tools/compact-v9.d.ts.map +1 -1
- package/out/tools/compact-v9.js +17 -4
- package/out/tools/compact-v9.js.map +1 -1
- package/out/tools/source-register/build.d.ts.map +1 -1
- package/out/tools/source-register/build.js +1 -0
- package/out/tools/source-register/build.js.map +1 -1
- package/out/us/adapters/usgov/usgs-structures/adapter.d.ts.map +1 -1
- package/out/us/adapters/usgov/usgs-structures/adapter.js +78 -4
- package/out/us/adapters/usgov/usgs-structures/adapter.js.map +1 -1
- package/package.json +19 -19
|
@@ -5,9 +5,16 @@
|
|
|
5
5
|
* `trailing-region` — the `«locality», «region»[, «country»]` admin tail,
|
|
6
6
|
* built from real `(locality, region)` WOF ancestor pairs.
|
|
7
7
|
*
|
|
8
|
-
* A tuple's `postcodePlacement` selects where the postcode sits: `leading
|
|
9
|
-
* (the default, so a tuples file written before the field existed is unchanged),
|
|
8
|
+
* A tuple's `postcodePlacement` selects where the postcode sits: `leading`,
|
|
10
9
|
* `after_locality`, or `after_region`.
|
|
10
|
+
* When absent, placement is inferred from the country's codex layout and postcode format
|
|
11
|
+
* (defaulting to `leading` when unknown, so tuples files written before the field existed are unchanged).
|
|
12
|
+
*
|
|
13
|
+
* For `after_locality` tuples (for example `Barcelona 6001, Venezuela`
|
|
14
|
+
* and `Barcelona 6001, Anzoátegui, Venezuela`), the recipe emits rows both with
|
|
15
|
+
* and without a region, omits synthetic house numbers so the locality-postcode pair
|
|
16
|
+
* is never confused with a street-number tail, and adds anchor-varied contrast
|
|
17
|
+
* rows for non-US four-digit postcode countries (#1821).
|
|
11
18
|
*
|
|
12
19
|
* A bare `«region»` form is deliberately absent: teaching it as `region` would fight
|
|
13
20
|
* the locality/region ambiguity the dominance race arbitrates.
|
|
@@ -15,9 +22,16 @@
|
|
|
15
22
|
* row begins with the locality and teaches the model that the first segment is the locality.
|
|
16
23
|
*/
|
|
17
24
|
|
|
25
|
+
import { formatAddress } from "@mailwoman/codex/address/format"
|
|
18
26
|
import { lookupCanadianProvince } from "@mailwoman/codex/ca"
|
|
19
|
-
import {
|
|
27
|
+
import { ISO2_TO_NAME } from "@mailwoman/codex/country"
|
|
28
|
+
import { lookupUSState, US_STATE_BY_ABBREVIATION } from "@mailwoman/codex/us"
|
|
20
29
|
import { mulberry32 as makeMulberry32 } from "@mailwoman/core/utils"
|
|
30
|
+
import {
|
|
31
|
+
hasPostcodeForm,
|
|
32
|
+
postcodePlacement as codexPostcodePlacement,
|
|
33
|
+
postcodeSyntaxCountries,
|
|
34
|
+
} from "@mailwoman/postcode/country-formats"
|
|
21
35
|
|
|
22
36
|
import {
|
|
23
37
|
alignAndWrite,
|
|
@@ -30,6 +44,48 @@ import {
|
|
|
30
44
|
import { defaultRecipeSource } from "#recipes/sources"
|
|
31
45
|
import { SurfaceOrigin } from "#types"
|
|
32
46
|
|
|
47
|
+
const US_CONTRAST_REGIONS: readonly string[] = Object.values(US_STATE_BY_ABBREVIATION)
|
|
48
|
+
// country-branch: #1821 anchor contrasts test the US country frame independently of the region anchor.
|
|
49
|
+
const US_COUNTRY_NAME = ISO2_TO_NAME.get("US") ?? "United States"
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Infers a country's postcode placement inside the admin tail from its codex
|
|
53
|
+
* address layout and libaddressinput postcode placement, defaulting to `leading`
|
|
54
|
+
* when the country is unknown or prints postcodes before the locality.
|
|
55
|
+
*/
|
|
56
|
+
function inferPostcodePlacement(cc: string): PostcodePlacement {
|
|
57
|
+
const country = cc.trim().toUpperCase()
|
|
58
|
+
|
|
59
|
+
if (!country || codexPostcodePlacement(country) !== "after_locality") return "leading"
|
|
60
|
+
|
|
61
|
+
const probe = formatAddress({ locality: "__LOC__", region: "__REG__", postcode: "__PC__" }, country, {
|
|
62
|
+
singleLine: true,
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
if (probe) {
|
|
66
|
+
const regionAt = probe.indexOf("__REG__")
|
|
67
|
+
const postcodeAt = probe.indexOf("__PC__")
|
|
68
|
+
|
|
69
|
+
if (regionAt !== -1 && postcodeAt !== -1 && regionAt < postcodeAt) {
|
|
70
|
+
return "after_region"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return "after_locality"
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Non-US countries whose postcode syntax accepts a four-digit numeric postcode,
|
|
79
|
+
* derived from `@mailwoman/postcode` rather than a static country list.
|
|
80
|
+
*/
|
|
81
|
+
function nonUSFourDigitPostcodeCountries(): readonly string[] {
|
|
82
|
+
// country-branch: #1821 targets non-US four-digit postcode countries whose locality-postcode
|
|
83
|
+
// tails collapse to street + house_number outside the US country frame.
|
|
84
|
+
return postcodeSyntaxCountries().filter((cc) => cc !== "US" && hasPostcodeForm("6001", cc))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const FOUR_DIGIT_NON_US_COUNTRIES: ReadonlySet<string> = new Set(nonUSFourDigitPostcodeCountries())
|
|
88
|
+
|
|
33
89
|
/**
|
|
34
90
|
* The region code an address line in this country writes, or `null` where the region name is written out.
|
|
35
91
|
*
|
|
@@ -78,28 +134,47 @@ export const trailingRegionRecipe: CorpusRecipe = {
|
|
|
78
134
|
const region = String(t.region ?? "").trim()
|
|
79
135
|
const country = String(t.country ?? "").trim()
|
|
80
136
|
const dependentLocality = String(t.dependentLocality ?? "").trim()
|
|
137
|
+
const postcode = String(t.postcode ?? "").trim()
|
|
138
|
+
|
|
139
|
+
const cc = String(t.cc ?? "")
|
|
140
|
+
.trim()
|
|
141
|
+
.toUpperCase()
|
|
142
|
+
|
|
143
|
+
const placement = (t.postcodePlacement as PostcodePlacement | undefined) ?? inferPostcodePlacement(cc)
|
|
144
|
+
|
|
145
|
+
const allowRegionlessAfterLocality = placement === "after_locality" && postcode.length > 0 && country.length > 0
|
|
81
146
|
|
|
82
147
|
// A pair whose region equals its locality provides no signal about the boundary this recipe teaches.
|
|
83
|
-
|
|
148
|
+
// Region-less tuples are admitted only for `after_locality` postcode tails with a country
|
|
149
|
+
// (e.g. `Barcelona 6001, Venezuela`), where the postcode separates locality from country.
|
|
150
|
+
if (!locality || (region && locality === region) || (!region && !allowRegionlessAfterLocality)) {
|
|
84
151
|
skipped++
|
|
85
152
|
|
|
86
153
|
continue
|
|
87
154
|
}
|
|
88
155
|
|
|
89
|
-
const withCountry = read % 2 === 0 && country.length > 0
|
|
90
|
-
|
|
156
|
+
const withCountry = !region ? true : read % 2 === 0 && country.length > 0
|
|
157
|
+
// For `after_locality` rows with a region and country, alternate between
|
|
158
|
+
// `«locality» «postcode», «region», «country»` and `«locality» «postcode», «country»`.
|
|
159
|
+
const includeRegion = Boolean(region) && !(allowRegionlessAfterLocality && withCountry && read % 4 === 0)
|
|
91
160
|
|
|
92
|
-
// The house number is the second trigger
|
|
93
|
-
// the house number then displaces the locality.
|
|
94
|
-
|
|
161
|
+
// The house number is the second trigger for `leading` / `after_region` rows:
|
|
162
|
+
// the postcode discards the region, and the house number then displaces the locality.
|
|
163
|
+
// `after_locality` rows omit synthetic house numbers so `«locality» «postcode»`
|
|
164
|
+
// never co-occurs with a house number on a streetless tail.
|
|
165
|
+
const withHouseNumber = postcode.length > 0 && placement !== "after_locality" && read % 4 === 1
|
|
95
166
|
const houseNumber = withHouseNumber ? String((read % 97) + 1) : ""
|
|
96
167
|
|
|
97
|
-
const components: Record<string, string> = { locality
|
|
168
|
+
const components: Record<string, string> = { locality }
|
|
98
169
|
|
|
99
170
|
if (dependentLocality && dependentLocality !== locality) {
|
|
100
171
|
components["dependent_locality"] = dependentLocality
|
|
101
172
|
}
|
|
102
173
|
|
|
174
|
+
if (includeRegion) {
|
|
175
|
+
components["region"] = region
|
|
176
|
+
}
|
|
177
|
+
|
|
103
178
|
if (withCountry) {
|
|
104
179
|
components["country"] = country
|
|
105
180
|
}
|
|
@@ -112,25 +187,26 @@ export const trailingRegionRecipe: CorpusRecipe = {
|
|
|
112
187
|
components["house_number"] = houseNumber
|
|
113
188
|
}
|
|
114
189
|
|
|
115
|
-
const placement = (t.postcodePlacement as PostcodePlacement | undefined) ?? "leading"
|
|
116
190
|
const bareLocality = postcode && placement === "after_locality" ? `${locality} ${postcode}` : locality
|
|
117
191
|
|
|
118
192
|
const localitySegment = components["dependent_locality"] ? `${dependentLocality}, ${bareLocality}` : bareLocality
|
|
119
193
|
|
|
120
194
|
// The code alternates with the region name rather than replacing it:
|
|
121
195
|
// both forms are posted and the resolver matches on the name.
|
|
122
|
-
const regionCode = read % 3 === 2 ? regionCodeSurface(
|
|
196
|
+
const regionCode = includeRegion && read % 3 === 2 ? regionCodeSurface(cc, region) : null
|
|
123
197
|
const regionSurface = regionCode ?? region
|
|
124
198
|
|
|
125
|
-
if (regionCode) {
|
|
199
|
+
if (includeRegion && regionCode) {
|
|
126
200
|
components["region"] = regionCode
|
|
127
201
|
}
|
|
128
202
|
|
|
129
203
|
const regionSegment = postcode && placement === "after_region" ? `${regionSurface} ${postcode}` : regionSurface
|
|
130
204
|
|
|
131
|
-
const tail =
|
|
132
|
-
?
|
|
133
|
-
|
|
205
|
+
const tail = includeRegion
|
|
206
|
+
? withCountry
|
|
207
|
+
? `${localitySegment}, ${regionSegment}, ${country}`
|
|
208
|
+
: `${localitySegment}, ${regionSegment}`
|
|
209
|
+
: `${localitySegment}, ${country}`
|
|
134
210
|
|
|
135
211
|
const leadingPostcode = postcode && placement === "leading" ? `${postcode} ` : ""
|
|
136
212
|
const head = withHouseNumber ? `${houseNumber}, ${leadingPostcode}` : leadingPostcode
|
|
@@ -143,7 +219,7 @@ export const trailingRegionRecipe: CorpusRecipe = {
|
|
|
143
219
|
const canonical = {
|
|
144
220
|
raw,
|
|
145
221
|
components,
|
|
146
|
-
country:
|
|
222
|
+
country: cc || "und",
|
|
147
223
|
locale: String(t.locale ?? "und"),
|
|
148
224
|
source: sourceLabel,
|
|
149
225
|
source_id,
|
|
@@ -163,6 +239,60 @@ export const trailingRegionRecipe: CorpusRecipe = {
|
|
|
163
239
|
} else {
|
|
164
240
|
skipped++
|
|
165
241
|
}
|
|
242
|
+
|
|
243
|
+
// #1821 anchor contrasts: US competence on `«locality» «postcode», «region», «country»`
|
|
244
|
+
// requires both a US region and `United States`.
|
|
245
|
+
// These contrast pairs vary each anchor independently so neither anchor by
|
|
246
|
+
// itself decides the locality-postcode boundary.
|
|
247
|
+
if (
|
|
248
|
+
placement === "after_locality" &&
|
|
249
|
+
includeRegion &&
|
|
250
|
+
withCountry &&
|
|
251
|
+
read % 8 === 2 &&
|
|
252
|
+
FOUR_DIGIT_NON_US_COUNTRIES.has(cc) &&
|
|
253
|
+
/^\d{4}$/u.test(postcode)
|
|
254
|
+
) {
|
|
255
|
+
const usRegion = US_CONTRAST_REGIONS[read % US_CONTRAST_REGIONS.length]!
|
|
256
|
+
|
|
257
|
+
const contrastRows: Array<{ suffix: string; regionValue: string; countryValue: string }> = [
|
|
258
|
+
{ suffix: "contrast-us-region", regionValue: usRegion, countryValue: country },
|
|
259
|
+
{ suffix: "contrast-us-country", regionValue: regionSurface, countryValue: US_COUNTRY_NAME },
|
|
260
|
+
]
|
|
261
|
+
|
|
262
|
+
for (const contrast of contrastRows) {
|
|
263
|
+
const contrastComponents: Record<string, string> = {
|
|
264
|
+
locality,
|
|
265
|
+
postcode,
|
|
266
|
+
region: contrast.regionValue,
|
|
267
|
+
country: contrast.countryValue,
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (components["dependent_locality"]) {
|
|
271
|
+
contrastComponents["dependent_locality"] = components["dependent_locality"]
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const contrastCanonical = {
|
|
275
|
+
raw: `${localitySegment}, ${contrast.regionValue}, ${contrast.countryValue}`,
|
|
276
|
+
components: contrastComponents,
|
|
277
|
+
country: cc,
|
|
278
|
+
locale: String(t.locale ?? "und"),
|
|
279
|
+
source: sourceLabel,
|
|
280
|
+
source_id: recipeSourceID(sourceLabel, { ...contrastComponents, v: `${read}-${contrast.suffix}` }),
|
|
281
|
+
license: canonical.license,
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (
|
|
285
|
+
alignAndWrite(write, contrastCanonical, `trailing-region:${contrast.suffix}`, {
|
|
286
|
+
...TRAILING_REGION_PROVENANCE,
|
|
287
|
+
baseSourceID: t.sourceID ?? null,
|
|
288
|
+
})
|
|
289
|
+
) {
|
|
290
|
+
emitted++
|
|
291
|
+
} else {
|
|
292
|
+
skipped++
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
166
296
|
}
|
|
167
297
|
|
|
168
298
|
return { read, emitted, skipped }
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import type { ComponentDict } from "@mailwoman/codex/address/render"
|
|
10
10
|
import { countryCodeForTable } from "@mailwoman/codex/country"
|
|
11
|
+
import { US_MILITARY_POST_OFFICE_CODES, US_MILITARY_UNIT_DESIGNATORS } from "@mailwoman/codex/us"
|
|
11
12
|
import { sample } from "@mailwoman/core/math/random"
|
|
12
13
|
|
|
13
14
|
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
@@ -69,11 +70,19 @@ export const PO_BOX_LOCALE_TEMPLATES: ReadonlyArray<LocaleTemplate> = [
|
|
|
69
70
|
},
|
|
70
71
|
{
|
|
71
72
|
locale: "en-AU",
|
|
72
|
-
leaders: ["PO Box", "P.O. Box", "Post Office Box", "GPO Box", "Locked Bag"],
|
|
73
|
+
leaders: ["PO Box", "P.O. Box", "Post Office Box", "GPO Box", "Locked Bag", "Private Bag", "Community Mail Bag"],
|
|
73
74
|
},
|
|
74
75
|
{
|
|
75
76
|
locale: "en-NZ",
|
|
76
|
-
leaders: [
|
|
77
|
+
leaders: [
|
|
78
|
+
"PO Box",
|
|
79
|
+
"P.O. Box",
|
|
80
|
+
"Post Office Box",
|
|
81
|
+
"Private Bag",
|
|
82
|
+
"Private Box",
|
|
83
|
+
"Response Bag",
|
|
84
|
+
"Community Mail Box",
|
|
85
|
+
],
|
|
77
86
|
},
|
|
78
87
|
{
|
|
79
88
|
locale: "fr-FR",
|
|
@@ -157,6 +166,13 @@ export interface PoBoxSynthesisOpts {
|
|
|
157
166
|
* @defaultValue `0`
|
|
158
167
|
*/
|
|
159
168
|
pmbRatio?: number
|
|
169
|
+
/**
|
|
170
|
+
* Vary casing of US military PO-box lines across title, uppercase (`UNIT 2050 BOX 4190`),
|
|
171
|
+
* and lowercase (`psc 802 box 74, apo ae 09499`).
|
|
172
|
+
*
|
|
173
|
+
* @defaultValue `false`
|
|
174
|
+
*/
|
|
175
|
+
varyCase?: boolean
|
|
160
176
|
}
|
|
161
177
|
|
|
162
178
|
function defaultPickNumber(random: () => number): string {
|
|
@@ -237,13 +253,14 @@ export function synthesizePoBoxRow(
|
|
|
237
253
|
}
|
|
238
254
|
}
|
|
239
255
|
|
|
240
|
-
const MIL_UNITS: ReadonlyArray<{ code: string; boxRequired: boolean }> =
|
|
241
|
-
{ code
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
256
|
+
const MIL_UNITS: ReadonlyArray<{ code: string; boxRequired: boolean }> = US_MILITARY_UNIT_DESIGNATORS.map(
|
|
257
|
+
({ code, requiresBox }) => ({
|
|
258
|
+
code: code === "UNIT" ? "Unit" : code,
|
|
259
|
+
boxRequired: requiresBox,
|
|
260
|
+
})
|
|
261
|
+
)
|
|
245
262
|
|
|
246
|
-
const MIL_PO_CODES =
|
|
263
|
+
const MIL_PO_CODES: ReadonlyArray<string> = US_MILITARY_POST_OFFICE_CODES.map(({ code }) => code)
|
|
247
264
|
|
|
248
265
|
// Each armed-forces region has its own ZIP range.
|
|
249
266
|
const MIL_REGION_ZIP: ReadonlyArray<{ region: string; zip: (r: () => number) => string }> = [
|
|
@@ -263,11 +280,33 @@ export function synthesizeMilitaryPoBoxRow(opts: PoBoxSynthesisOpts = {}): Synth
|
|
|
263
280
|
const random = opts.random ?? Math.random
|
|
264
281
|
const unit = sample(MIL_UNITS, random)
|
|
265
282
|
const unitID = String(1 + Math.floor(random() * 9999))
|
|
266
|
-
const { region, zip } = sample(MIL_REGION_ZIP, random)
|
|
283
|
+
const { region: baseRegion, zip } = sample(MIL_REGION_ZIP, random)
|
|
267
284
|
const zipStr = zip(random)
|
|
268
|
-
const
|
|
269
|
-
const hasBox = unit.boxRequired || random() < 0.
|
|
270
|
-
const
|
|
285
|
+
const basePo = sample(MIL_PO_CODES, random)
|
|
286
|
+
const hasBox = unit.boxRequired || random() < 0.75
|
|
287
|
+
const rawBoxNumber = 1 + Math.floor(random() * 9999)
|
|
288
|
+
|
|
289
|
+
const boxNumber =
|
|
290
|
+
rawBoxNumber < 1000 && random() < 0.15 ? String(rawBoxNumber).padStart(4, "0") : String(rawBoxNumber)
|
|
291
|
+
|
|
292
|
+
const baseUnitLine = hasBox ? `${unit.code} ${unitID} Box ${boxNumber}` : `${unit.code} ${unitID}`
|
|
293
|
+
|
|
294
|
+
let unitLine = baseUnitLine
|
|
295
|
+
let po = basePo
|
|
296
|
+
let region = baseRegion
|
|
297
|
+
|
|
298
|
+
if (opts.varyCase) {
|
|
299
|
+
const caseDraw = random()
|
|
300
|
+
|
|
301
|
+
if (caseDraw < 0.2) {
|
|
302
|
+
unitLine = baseUnitLine.toUpperCase()
|
|
303
|
+
} else if (caseDraw < 0.35) {
|
|
304
|
+
unitLine = baseUnitLine.toLowerCase()
|
|
305
|
+
po = basePo.toLowerCase()
|
|
306
|
+
region = baseRegion.toLowerCase()
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
271
310
|
const raw = `${unitLine}, ${po} ${region} ${zipStr}`
|
|
272
311
|
|
|
273
312
|
return {
|
package/lib/tools/compact-v9.ts
CHANGED
|
@@ -37,6 +37,11 @@ export const DEFAULT_SKELETON_CAP = 6
|
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Default Tier-2 dense register sources subject to cross-source deduplication and skeleton capping.
|
|
40
|
+
*
|
|
41
|
+
* The multi-country European `overture` source stays in Tier 1 rather than here:
|
|
42
|
+
* its rows span 16 countries at roughly 100k to 150k rows each.
|
|
43
|
+
* Skeleton-capping it dropped 700,104 of 1,825,956 rows in `v0.9.0-compact`,
|
|
44
|
+
* including ES and IT single-letter unit rows and CZ/SI addresses.
|
|
40
45
|
*/
|
|
41
46
|
export const DEFAULT_TIER2_SOURCES = [
|
|
42
47
|
"usgov-nad",
|
|
@@ -57,7 +62,6 @@ export const DEFAULT_TIER2_SOURCES = [
|
|
|
57
62
|
"state-ia-contractors",
|
|
58
63
|
"state-ny-notaries",
|
|
59
64
|
"state-tx-notaries",
|
|
60
|
-
"overture",
|
|
61
65
|
"overture-latam",
|
|
62
66
|
"gleif-lei",
|
|
63
67
|
] as const
|
|
@@ -104,6 +108,8 @@ export interface CompactCorpusV9Options {
|
|
|
104
108
|
* `intersection_a`, `venue`, `building_name`, `building_number`).
|
|
105
109
|
*
|
|
106
110
|
* A `null` value keeps rare patterns uncapped.
|
|
111
|
+
* Bare single-letter `unit` rows (one token matching a single letter, such as ES
|
|
112
|
+
* `CALLE LA CRUZ A, 45` or IT `VIA NAPOLI A 5`) stay uncapped even when `rareSkeletonCap` is set.
|
|
107
113
|
*
|
|
108
114
|
* @default null
|
|
109
115
|
*/
|
|
@@ -239,6 +245,7 @@ interface PreparedFile {
|
|
|
239
245
|
tier: 1 | 2
|
|
240
246
|
hasAugmentation: boolean
|
|
241
247
|
hasSpanTags: boolean
|
|
248
|
+
hasTokens: boolean
|
|
242
249
|
splitAttribute: SplitAttributeFile | null
|
|
243
250
|
}
|
|
244
251
|
|
|
@@ -328,6 +335,7 @@ async function prepareInputFiles(
|
|
|
328
335
|
tier,
|
|
329
336
|
hasAugmentation: columns.has("augmentation"),
|
|
330
337
|
hasSpanTags: columns.has("span_tags"),
|
|
338
|
+
hasTokens: columns.has("tokens"),
|
|
331
339
|
splitAttribute,
|
|
332
340
|
})
|
|
333
341
|
}
|
|
@@ -377,6 +385,7 @@ async function buildTier2KeepTable(
|
|
|
377
385
|
"dedup_key VARCHAR, " +
|
|
378
386
|
"skeleton_key VARCHAR, " +
|
|
379
387
|
"is_rare BOOLEAN, " +
|
|
388
|
+
"is_single_letter_unit BOOLEAN, " +
|
|
380
389
|
"tie_hash VARCHAR)"
|
|
381
390
|
)
|
|
382
391
|
|
|
@@ -412,6 +421,14 @@ async function buildTier2KeepTable(
|
|
|
412
421
|
`OR list_has_any(p.span_tags, ${rareTagsSQL}))`
|
|
413
422
|
: `list_has_any(list_transform(p.labels, lambda x: regexp_replace(x, '^[BI]-', '')), ${rareTagsSQL})`
|
|
414
423
|
|
|
424
|
+
const unitTokensExpr = `list_filter(list_zip(p.tokens, p.labels), lambda x: x[2] IN ('B-unit', 'I-unit'))`
|
|
425
|
+
|
|
426
|
+
const singleLetterUnitExpr = file.hasTokens
|
|
427
|
+
? `(CASE WHEN len(${unitTokensExpr}) = 1 ` +
|
|
428
|
+
`THEN regexp_matches(${unitTokensExpr}[1][1], '^\\p{L}$') ` +
|
|
429
|
+
`ELSE FALSE END)`
|
|
430
|
+
: "FALSE"
|
|
431
|
+
|
|
415
432
|
await db.run(
|
|
416
433
|
`INSERT INTO tier2_candidates ` +
|
|
417
434
|
`SELECT ${file.index}, p.file_row_number, '${escapeSQLString(file.source)}', p.source_id, ` +
|
|
@@ -419,6 +436,7 @@ async function buildTier2KeepTable(
|
|
|
419
436
|
`sha256(coalesce(p.country, '') || chr(0) || array_to_string(p.labels, ',') || chr(0) || ` +
|
|
420
437
|
`regexp_replace(lower(p.raw), '[0-9]+', '#', 'g')), ` +
|
|
421
438
|
`${rareExpr}, ` +
|
|
439
|
+
`${singleLetterUnitExpr}, ` +
|
|
422
440
|
`md5(coalesce(p.source_id, '') || ':' || p.raw) ` +
|
|
423
441
|
`FROM ${scan} p WHERE (${trainPredicate}) AND (${augPredicate})`
|
|
424
442
|
)
|
|
@@ -426,7 +444,7 @@ async function buildTier2KeepTable(
|
|
|
426
444
|
|
|
427
445
|
await db.run(
|
|
428
446
|
"CREATE TEMP TABLE tier2_deduped AS " +
|
|
429
|
-
"SELECT file_idx, file_row_number, source, source_id, skeleton_key, is_rare, tie_hash, " +
|
|
447
|
+
"SELECT file_idx, file_row_number, source, source_id, skeleton_key, is_rare, is_single_letter_unit, tie_hash, " +
|
|
430
448
|
"row_number() OVER (PARTITION BY dedup_key ORDER BY source, source_id, file_idx, file_row_number) AS dedup_rn " +
|
|
431
449
|
"FROM tier2_candidates"
|
|
432
450
|
)
|
|
@@ -443,7 +461,7 @@ async function buildTier2KeepTable(
|
|
|
443
461
|
|
|
444
462
|
await db.run(
|
|
445
463
|
"CREATE TEMP TABLE tier2_ranked AS " +
|
|
446
|
-
"SELECT file_idx, file_row_number, source, is_rare, " +
|
|
464
|
+
"SELECT file_idx, file_row_number, source, is_rare, is_single_letter_unit, " +
|
|
447
465
|
"row_number() OVER (PARTITION BY skeleton_key ORDER BY tie_hash, source, source_id, file_idx, file_row_number) AS skel_rn " +
|
|
448
466
|
"FROM tier2_deduped WHERE dedup_rn = 1"
|
|
449
467
|
)
|
|
@@ -453,7 +471,7 @@ async function buildTier2KeepTable(
|
|
|
453
471
|
const keepPredicate =
|
|
454
472
|
rareSkeletonCap == null
|
|
455
473
|
? `(is_rare OR skel_rn <= ${skeletonCap})`
|
|
456
|
-
: `((is_rare AND skel_rn <= ${rareSkeletonCap}) OR (NOT is_rare AND skel_rn <= ${skeletonCap}))`
|
|
474
|
+
: `(is_single_letter_unit OR (is_rare AND skel_rn <= ${rareSkeletonCap}) OR (NOT is_rare AND skel_rn <= ${skeletonCap}))`
|
|
457
475
|
|
|
458
476
|
const skelDrops = await db.runAndReadAll(
|
|
459
477
|
`SELECT source, count(*) AS dropped FROM tier2_ranked WHERE NOT ${keepPredicate} GROUP BY source`
|
|
@@ -95,6 +95,7 @@ const RESEARCH_PASS_BY_ORIGIN: Readonly<Record<string, ResearchPass>> = {
|
|
|
95
95
|
"2026-11-21_rights_review": ResearchPass.RightsReview,
|
|
96
96
|
"2026-11-22_rights_review": ResearchPass.RightsReview,
|
|
97
97
|
"2026-11-23_rights_review": ResearchPass.RightsReview,
|
|
98
|
+
"2026-12-02_rights_review": ResearchPass.RightsReview,
|
|
98
99
|
"2026-10-03_decoder_exposure": ResearchPass.DecoderExposureSurvey,
|
|
99
100
|
"2026-10-17_corpus_input_mapping": ResearchPass.CorpusInputMapping,
|
|
100
101
|
}
|
|
@@ -27,13 +27,14 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import { formatAddressRow } from "@mailwoman/codex/address/format"
|
|
30
|
+
import { escapeRegExp } from "@mailwoman/core/strings/regexp"
|
|
30
31
|
import { JSONSpliterator } from "spliterator"
|
|
31
32
|
|
|
32
|
-
import { createUnitSplitter, type UnitSplitter } from "#adapters/street/unit"
|
|
33
|
+
import { createUnitSplitter, type UnitSplitter, type UnitVocabulary } from "#adapters/street/unit"
|
|
33
34
|
import { SourceRegister } from "#registers"
|
|
34
35
|
import { streetIndexOpener } from "#street-index/reader"
|
|
35
36
|
import { AddressRole, type AdapterOptions, type CanonicalRow, type CorpusAdapter, SurfaceOrigin } from "#types"
|
|
36
|
-
import { lookupStateAbbreviation } from "#us/fips-state"
|
|
37
|
+
import { lookupStateAbbreviation, type USStateInfo } from "#us/fips-state"
|
|
37
38
|
import { splitUSStreetLine } from "#us/street-unit"
|
|
38
39
|
import { usgsStructureLayer } from "#us/structures/usgs/layers"
|
|
39
40
|
|
|
@@ -103,6 +104,90 @@ export interface USGSStructureFeature {
|
|
|
103
104
|
properties: USGSStructureProperties
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Strips stray commas and any repeated state or ZIP Code tail from a USGS `city` value
|
|
109
|
+
* (such as `Matawan, NJ 07747`, `Boynton Beach, Florida 33435`, or `Grand Rapids, MI`).
|
|
110
|
+
*/
|
|
111
|
+
function cleanUSCity(city: string, state: USStateInfo, zipcode: string): string {
|
|
112
|
+
const stripped = city
|
|
113
|
+
.trim()
|
|
114
|
+
.replaceAll(/^,+\s*|\s*,+$/gu, "")
|
|
115
|
+
.trim()
|
|
116
|
+
|
|
117
|
+
if (!stripped) return ""
|
|
118
|
+
|
|
119
|
+
const statePattern = `(?:${escapeRegExp(state.abbreviation)}|${escapeRegExp(state.name)})`
|
|
120
|
+
const stateTail = new RegExp(`,\\s*${statePattern}(?:\\s*,?\\s*\\d{5}(?:-\\d{4})?)?$`, "iu")
|
|
121
|
+
let cleaned = stripped.replace(stateTail, "").trim()
|
|
122
|
+
|
|
123
|
+
// Catch publisher typos in the state name (such as `Raiford, Florda 32083`)
|
|
124
|
+
// when the trailing five-digit ZIP Code matches the row's own postcode.
|
|
125
|
+
const zip5 = zipcode.slice(0, 5)
|
|
126
|
+
|
|
127
|
+
if (cleaned === stripped && /^\d{5}$/u.test(zip5)) {
|
|
128
|
+
const zipTail = new RegExp(`,\\s*[A-Za-z]+(?:\\s+[A-Za-z]+)?\\s*,?\\s*${escapeRegExp(zip5)}(?:-\\d{4})?$`, "iu")
|
|
129
|
+
|
|
130
|
+
cleaned = stripped.replace(zipTail, "").trim()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return cleaned.replaceAll(/\s*,+$/gu, "").trim()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Strips a trailing repeated locality from a USGS street name when it follows a comma
|
|
138
|
+
* (`Calle Lina R Corretger, Ciales`) or a complete US street suffix or route number
|
|
139
|
+
* (`Walnut Street Big Stone City`, `US Highway 70 East Otway`).
|
|
140
|
+
*
|
|
141
|
+
* Leaves street names that share words with the locality untouched: `Camino Del Mar`,
|
|
142
|
+
* `Stanton Terrace Southeast`, `Avenida de Mesilla`, and `US Highway 101 North of Ilwaco`.
|
|
143
|
+
*/
|
|
144
|
+
function stripRepeatedLocality(
|
|
145
|
+
street: string,
|
|
146
|
+
locality: string,
|
|
147
|
+
rawCity: string,
|
|
148
|
+
vocabulary: UnitVocabulary | null
|
|
149
|
+
): string {
|
|
150
|
+
const trimmedRawCity = rawCity.trim()
|
|
151
|
+
|
|
152
|
+
if (trimmedRawCity && trimmedRawCity.toLowerCase() !== locality.toLowerCase()) {
|
|
153
|
+
const rawTail = new RegExp(`,\\s*${escapeRegExp(trimmedRawCity)}$`, "iu")
|
|
154
|
+
const withoutRawCity = street.replace(rawTail, "").trim()
|
|
155
|
+
|
|
156
|
+
if (withoutRawCity && withoutRawCity !== street) return withoutRawCity
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (vocabulary?.directionals.has(locality.toLowerCase())) return street
|
|
160
|
+
|
|
161
|
+
const tailMatch = new RegExp(`(,\\s*|\\s+)${escapeRegExp(locality)}$`, "iu").exec(street)
|
|
162
|
+
|
|
163
|
+
if (!tailMatch) return street
|
|
164
|
+
|
|
165
|
+
const prefix = street.slice(0, tailMatch.index).trim()
|
|
166
|
+
|
|
167
|
+
if (!prefix) return street
|
|
168
|
+
|
|
169
|
+
if (tailMatch[1]!.includes(",")) return prefix
|
|
170
|
+
|
|
171
|
+
if (!vocabulary) return street
|
|
172
|
+
|
|
173
|
+
const words = prefix
|
|
174
|
+
.split(/\s+/u)
|
|
175
|
+
.map((word) => word.replaceAll(/[.,]+$/gu, "").toLowerCase())
|
|
176
|
+
.filter((word) => word.length > 0)
|
|
177
|
+
|
|
178
|
+
// Require at least two words before the repeated locality so prefix-led names like
|
|
179
|
+
// `Camino Del Mar` are never reduced to a bare street-type word (`Camino`).
|
|
180
|
+
if (words.length < 2) return street
|
|
181
|
+
|
|
182
|
+
if (words.length > 2 && vocabulary.directionals.has(words.at(-1)!) && !vocabulary.streetTypes.has(words.at(-1)!)) {
|
|
183
|
+
words.pop()
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const last = words.at(-1)!
|
|
187
|
+
|
|
188
|
+
return vocabulary.streetTypes.has(last) || /\d/u.test(last) ? prefix : street
|
|
189
|
+
}
|
|
190
|
+
|
|
106
191
|
/**
|
|
107
192
|
* A structure's address as labeled components, or `null` when it lacks a street address,
|
|
108
193
|
* city, recognized state or ZIP Code.
|
|
@@ -115,13 +200,25 @@ export function usgsStructureAddress(
|
|
|
115
200
|
units: UnitSplitter
|
|
116
201
|
): CanonicalRow["components"] | null {
|
|
117
202
|
const { address, city, state: stateCode, zipcode } = properties
|
|
118
|
-
const place = { ...(city ? { locality: city } : {}), ...(zipcode ? { postcode: zipcode } : {}) }
|
|
119
|
-
const line = address ? splitUSStreetLine(address, units, place) : null
|
|
120
203
|
const state = lookupStateAbbreviation(stateCode)
|
|
121
204
|
|
|
122
|
-
if (!
|
|
205
|
+
if (!address || !city || !state || !zipcode) return null
|
|
206
|
+
|
|
207
|
+
const cleanedCity = cleanUSCity(city, state, zipcode)
|
|
208
|
+
|
|
209
|
+
if (!cleanedCity) return null
|
|
210
|
+
|
|
211
|
+
const place = { locality: cleanedCity, postcode: zipcode }
|
|
212
|
+
const line = splitUSStreetLine(address, units, place)
|
|
213
|
+
|
|
214
|
+
if (!line) return null
|
|
215
|
+
|
|
216
|
+
const cleanedLine =
|
|
217
|
+
"street" in line && !line.unit
|
|
218
|
+
? { ...line, street: stripRepeatedLocality(line.street, cleanedCity, city, units.vocabulary("US")) }
|
|
219
|
+
: line
|
|
123
220
|
|
|
124
|
-
return { ...
|
|
221
|
+
return { ...cleanedLine, locality: cleanedCity, region: state.abbreviation, postcode: zipcode }
|
|
125
222
|
}
|
|
126
223
|
|
|
127
224
|
/**
|
|
@@ -4,8 +4,8 @@ import { type CorpusAdapter } from "#types";
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const GEONAMES_FEATURES_ADAPTER_ID = "geonames-features";
|
|
6
6
|
/**
|
|
7
|
-
* The GeoNames feature classes this adapter reads: undersea (`U`), water (`H`),
|
|
8
|
-
* terrain (`T`), parks and areas (`L`) and vegetation (`V`).
|
|
7
|
+
* The GeoNames feature classes this adapter reads unconditionally: undersea (`U`), water (`H`),
|
|
8
|
+
* terrain (`T`), parks and areas (`L`, which includes ports `PRT`) and vegetation (`V`).
|
|
9
9
|
*/
|
|
10
10
|
export declare const GEONAMES_FEATURE_CLASSES: ReadonlySet<string>;
|
|
11
11
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../../lib/adapters/geonames/features/adapter.ts"],"names":[],"mappings":"AAgCA,OAAO,EAAuD,KAAK,aAAa,EAAiB,MAAM,QAAQ,CAAA;AAE/G;;GAEG;AACH,eAAO,MAAM,4BAA4B,sBAAsB,CAAA;AAE/D;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,MAAM,CAAsC,CAAA;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../../lib/adapters/geonames/features/adapter.ts"],"names":[],"mappings":"AAgCA,OAAO,EAAuD,KAAK,aAAa,EAAiB,MAAM,QAAQ,CAAA;AAE/G;;GAEG;AACH,eAAO,MAAM,4BAA4B,sBAAsB,CAAA;AAE/D;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,MAAM,CAAsC,CAAA;AAmB/F;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,KAAK,CAAA;AAE5C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sCAAsC,IAAI,CAAA;AAmDvD;;GAEG;AACH,wBAAgB,6BAA6B,IAAI,aAAa,CAmF7D;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,eAAkC,CAAA"}
|