@mailwoman/corpus 12.0.0 → 12.2.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/holdout/evaluation-groups.v0.9.3.json +224169 -0
- 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-configs/v9.3.0-bytestem-global-v093-s42.yaml +746 -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/data/training-manifests/v0.9.3-compact.effective.json +2660 -0
- package/data/training-manifests/v0.9.3-compact.json +9648 -0
- package/lib/adapters/geonames/features/adapter.ts +163 -20
- 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/adapters/wof/admin/json/dual-role.ts +46 -21
- package/lib/au/adapters/gnaf/source.ts +12 -0
- package/lib/build/schema-invariants.ts +447 -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/jp/corpus/assemble.ts +20 -1
- package/lib/jp/corpus/rows.ts +87 -0
- package/lib/recipes/po/box/cedex/recipe.ts +1 -1
- package/lib/recipes/po/box/cedex/vocabulary.ts +4 -4
- package/lib/recipes/prominent/places.ts +42 -9
- package/lib/recipes/trailing-region.ts +180 -20
- 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/fetch/wikidata/vital-places/classify.ts +23 -7
- package/lib/tools/fetch/wikidata/vital-places/render.ts +57 -7
- package/lib/tools/source-register/build.ts +1 -0
- package/lib/training/config/schema.ts +3 -0
- package/lib/us/adapters/usgov/usgs-structures/adapter.ts +103 -6
- package/lib/us/street-unit.ts +14 -1
- 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 +114 -20
- 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/adapters/wof/admin/json/dual-role.d.ts +8 -3
- package/out/adapters/wof/admin/json/dual-role.d.ts.map +1 -1
- package/out/adapters/wof/admin/json/dual-role.js +40 -19
- package/out/adapters/wof/admin/json/dual-role.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/build/schema-invariants.d.ts +101 -0
- package/out/build/schema-invariants.d.ts.map +1 -0
- package/out/build/schema-invariants.js +302 -0
- package/out/build/schema-invariants.js.map +1 -0
- 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/jp/corpus/assemble.d.ts.map +1 -1
- package/out/jp/corpus/assemble.js +14 -2
- package/out/jp/corpus/assemble.js.map +1 -1
- package/out/jp/corpus/rows.d.ts +8 -0
- package/out/jp/corpus/rows.d.ts.map +1 -1
- package/out/jp/corpus/rows.js +72 -0
- package/out/jp/corpus/rows.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/prominent/places.d.ts.map +1 -1
- package/out/recipes/prominent/places.js +30 -5
- package/out/recipes/prominent/places.js.map +1 -1
- package/out/recipes/trailing-region.d.ts.map +1 -1
- package/out/recipes/trailing-region.js +148 -20
- 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/fetch/wikidata/vital-places/classify.d.ts +12 -2
- package/out/tools/fetch/wikidata/vital-places/classify.d.ts.map +1 -1
- package/out/tools/fetch/wikidata/vital-places/classify.js +19 -7
- package/out/tools/fetch/wikidata/vital-places/classify.js.map +1 -1
- package/out/tools/fetch/wikidata/vital-places/render.d.ts +9 -5
- package/out/tools/fetch/wikidata/vital-places/render.d.ts.map +1 -1
- package/out/tools/fetch/wikidata/vital-places/render.js +44 -7
- package/out/tools/fetch/wikidata/vital-places/render.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/training/config/schema.d.ts +21 -0
- package/out/training/config/schema.d.ts.map +1 -1
- package/out/training/config/schema.js +3 -0
- package/out/training/config/schema.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/out/us/street-unit.d.ts.map +1 -1
- package/out/us/street-unit.js +11 -1
- package/out/us/street-unit.js.map +1 -1
- 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)
|
|
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
|
|
9
|
-
* The corpus held no such rows before this source (#2897), so the parser had never read a bare
|
|
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
|
|
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
|
*/
|
|
@@ -29,6 +29,14 @@ import {
|
|
|
29
29
|
loadAdmin1,
|
|
30
30
|
loadCountries,
|
|
31
31
|
} from "#adapters/geonames/adapter"
|
|
32
|
+
import {
|
|
33
|
+
type CapitalSeats,
|
|
34
|
+
DualRoleBasis,
|
|
35
|
+
dualRoleKey,
|
|
36
|
+
type DualRolePair,
|
|
37
|
+
dualRoleRowRule,
|
|
38
|
+
readCapitalSeats,
|
|
39
|
+
} from "#adapters/wof/admin/json/dual-role"
|
|
32
40
|
import { SourceRegister } from "#registers"
|
|
33
41
|
import { AddressRole, type AdapterOptions, type CanonicalRow, type CorpusAdapter, SurfaceOrigin } from "#types"
|
|
34
42
|
|
|
@@ -38,11 +46,28 @@ import { AddressRole, type AdapterOptions, type CanonicalRow, type CorpusAdapter
|
|
|
38
46
|
export const GEONAMES_FEATURES_ADAPTER_ID = "geonames-features"
|
|
39
47
|
|
|
40
48
|
/**
|
|
41
|
-
* The GeoNames feature classes this adapter reads: undersea (`U`), water (`H`),
|
|
42
|
-
* terrain (`T`), parks and areas (`L`) and vegetation (`V`).
|
|
49
|
+
* The GeoNames feature classes this adapter reads unconditionally: undersea (`U`), water (`H`),
|
|
50
|
+
* terrain (`T`), parks and areas (`L`, which includes ports `PRT`) and vegetation (`V`).
|
|
43
51
|
*/
|
|
44
52
|
export const GEONAMES_FEATURE_CLASSES: ReadonlySet<string> = new Set(["U", "H", "T", "L", "V"])
|
|
45
53
|
|
|
54
|
+
/**
|
|
55
|
+
* The GeoNames transit feature codes this adapter admits from class `S` (spots/buildings/facilities):
|
|
56
|
+
* airports (`AIRP`), rail stations (`RSTN`), metro stations (`MTRO`), bus stations (`BUSTN`),
|
|
57
|
+
* ports (`PRT`, also present under class `L`), and ferries (`FY`).
|
|
58
|
+
*
|
|
59
|
+
* `packages/mailwoman/tools/training/outcomes/masks.ts` routes these codes to the `transit`
|
|
60
|
+
* outcome reading using `geonames_transit_codes` in `packages/trainer/data/outcome_readings.json`.
|
|
61
|
+
*/
|
|
62
|
+
const GEONAMES_TRANSIT_FEATURE_CODES: ReadonlySet<string> = new Set(["AIRP", "RSTN", "MTRO", "BUSTN", "PRT", "FY"])
|
|
63
|
+
|
|
64
|
+
function isSelectedGeonamesFeature(featureClass: string, featureCode: string): boolean {
|
|
65
|
+
return (
|
|
66
|
+
GEONAMES_FEATURE_CLASSES.has(featureClass) ||
|
|
67
|
+
(featureClass === "S" && GEONAMES_TRANSIT_FEATURE_CODES.has(featureCode))
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
46
71
|
/**
|
|
47
72
|
* The most features one (country, feature code) cell contributes.
|
|
48
73
|
*
|
|
@@ -66,6 +91,17 @@ export const GEONAMES_FEATURES_PER_CELL = 25
|
|
|
66
91
|
*/
|
|
67
92
|
export const GEONAMES_FEATURES_WITH_COUNTRY_DIVISOR = 4
|
|
68
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Historical, abandoned, or destroyed populated-place feature codes skipped
|
|
96
|
+
* when detecting dual-role regions.
|
|
97
|
+
*/
|
|
98
|
+
const NON_CURRENT_PPL = new Set(["PPLH", "PPLQ", "PPLW", "PPLCH"])
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* GeoNames feature codes for national capitals and admin-1 seats.
|
|
102
|
+
*/
|
|
103
|
+
const ADMIN1_SEAT_CODES = new Set(["PPLC", "PPLA"])
|
|
104
|
+
|
|
69
105
|
/**
|
|
70
106
|
* One feature the cap kept.
|
|
71
107
|
*/
|
|
@@ -75,22 +111,85 @@ interface KeptFeature {
|
|
|
75
111
|
}
|
|
76
112
|
|
|
77
113
|
/**
|
|
78
|
-
*
|
|
114
|
+
* Result of pass 1 over one GeoNames dump: the capped feature IDs and the dual-role
|
|
115
|
+
* `(country, admin1)` pairs whose homonymous city-region name stays out of `region` (#3504).
|
|
116
|
+
*/
|
|
117
|
+
interface ScannedDump {
|
|
118
|
+
kept: Set<string>
|
|
119
|
+
dualRolePairs: DualRolePair[]
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Scans one GeoNames dump in a single pass to collect:
|
|
124
|
+
* 1. The {@linkcode GEONAMES_FEATURES_PER_CELL} lowest-hashed feature geonameids
|
|
125
|
+
* per `(country, featureCode)` cell.
|
|
126
|
+
* 2. The dual-role admin-1 pairs where a current populated place in `(cc, admin1)`
|
|
127
|
+
* shares the folded name of that admin-1 unit and is either a capital/admin-1 seat
|
|
128
|
+
* or the unit's most populous locality.
|
|
129
|
+
* When a country has no populated-place rows in the dump (as in features-only fixtures),
|
|
130
|
+
* the committed capitals reference decides seats.
|
|
79
131
|
*/
|
|
80
|
-
async function
|
|
132
|
+
async function scanDump(
|
|
133
|
+
input: PathBuilder,
|
|
134
|
+
country: string | undefined,
|
|
135
|
+
admin1: ReadonlyMap<string, string>,
|
|
136
|
+
seats: CapitalSeats
|
|
137
|
+
): Promise<ScannedDump> {
|
|
81
138
|
const cells = new Map<string, KeptFeature[]>()
|
|
139
|
+
const countriesWithPPL = new Set<string>()
|
|
140
|
+
const largestByAdmin1 = new Map<string, { id: number; population: number }>()
|
|
141
|
+
|
|
142
|
+
const candidates: Array<{
|
|
143
|
+
admin1Key: string
|
|
144
|
+
cc: string
|
|
145
|
+
regionName: string
|
|
146
|
+
localityID: number
|
|
147
|
+
isSeat: boolean
|
|
148
|
+
}> = []
|
|
82
149
|
|
|
83
150
|
for await (const rec of readUnquotedTSV(input)) {
|
|
84
151
|
const cls = rec[COL.featureClass] ?? ""
|
|
85
|
-
|
|
86
|
-
if (!GEONAMES_FEATURE_CLASSES.has(cls)) continue
|
|
152
|
+
const code = (rec[COL.featureCode] ?? "").trim()
|
|
87
153
|
const cc = (rec[COL.country] ?? "").trim()
|
|
88
154
|
|
|
89
155
|
if (!cc || (country && cc !== country)) continue
|
|
90
156
|
const geonameid = (rec[COL.geonameid] ?? "").trim()
|
|
157
|
+
const name = (rec[COL.name] ?? "").trim()
|
|
158
|
+
|
|
159
|
+
if (!geonameid || !name) continue
|
|
160
|
+
|
|
161
|
+
if (cls === "P" && !NON_CURRENT_PPL.has(code)) {
|
|
162
|
+
countriesWithPPL.add(cc)
|
|
163
|
+
const admin1Code = (rec[COL.admin1] ?? "").trim()
|
|
164
|
+
const admin1Key = `${cc}.${admin1Code}`
|
|
165
|
+
const regionName = admin1.get(admin1Key)
|
|
166
|
+
|
|
167
|
+
if (regionName) {
|
|
168
|
+
const id = Number.parseInt(geonameid, 10) || 0
|
|
169
|
+
const population = Number.parseInt(rec[COL.population] ?? "0", 10) || 0
|
|
170
|
+
const prev = largestByAdmin1.get(admin1Key)
|
|
171
|
+
|
|
172
|
+
if (
|
|
173
|
+
population > 0 &&
|
|
174
|
+
(!prev || population > prev.population || (population === prev.population && id < prev.id))
|
|
175
|
+
) {
|
|
176
|
+
largestByAdmin1.set(admin1Key, { id, population })
|
|
177
|
+
}
|
|
91
178
|
|
|
92
|
-
|
|
93
|
-
|
|
179
|
+
const regionFolded = dualRoleKey(regionName)
|
|
180
|
+
const asciiName = (rec[COL.asciiname] ?? "").trim()
|
|
181
|
+
|
|
182
|
+
if (dualRoleKey(name) === regionFolded || (asciiName && dualRoleKey(asciiName) === regionFolded)) {
|
|
183
|
+
const isSeat = ADMIN1_SEAT_CODES.has(code) || seats.has(`${cc}|${regionFolded}`)
|
|
184
|
+
|
|
185
|
+
candidates.push({ admin1Key, cc, regionName, localityID: id, isSeat })
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (!isSelectedGeonamesFeature(cls, code)) continue
|
|
191
|
+
|
|
192
|
+
const key = `${cc}\t${code}`
|
|
94
193
|
const kept = cells.get(key) ?? []
|
|
95
194
|
const hash = hashFNV1a(geonameid)
|
|
96
195
|
|
|
@@ -111,7 +210,47 @@ async function keptFeatureIDs(input: PathBuilder, country: string | undefined):
|
|
|
111
210
|
}
|
|
112
211
|
}
|
|
113
212
|
|
|
114
|
-
|
|
213
|
+
const pairsByRegion = new Map<string, DualRolePair>()
|
|
214
|
+
|
|
215
|
+
for (const candidate of candidates) {
|
|
216
|
+
const basis = candidate.isSeat
|
|
217
|
+
? DualRoleBasis.seat
|
|
218
|
+
: largestByAdmin1.get(candidate.admin1Key)?.id === candidate.localityID
|
|
219
|
+
? DualRoleBasis.largest
|
|
220
|
+
: null
|
|
221
|
+
|
|
222
|
+
if (basis && !pairsByRegion.has(candidate.admin1Key)) {
|
|
223
|
+
pairsByRegion.set(candidate.admin1Key, {
|
|
224
|
+
regionID: 0,
|
|
225
|
+
localityID: candidate.localityID,
|
|
226
|
+
country: candidate.cc,
|
|
227
|
+
name: candidate.regionName,
|
|
228
|
+
basis,
|
|
229
|
+
})
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Fallback for features-only dumps that omit populated-place rows: check admin1 names against the capitals reference.
|
|
234
|
+
for (const [admin1Key, regionName] of admin1) {
|
|
235
|
+
const cc = admin1Key.split(".")[0] ?? ""
|
|
236
|
+
|
|
237
|
+
if (!cc || (country && cc !== country) || countriesWithPPL.has(cc) || pairsByRegion.has(admin1Key)) continue
|
|
238
|
+
|
|
239
|
+
if (seats.has(`${cc}|${dualRoleKey(regionName)}`)) {
|
|
240
|
+
pairsByRegion.set(admin1Key, {
|
|
241
|
+
regionID: 0,
|
|
242
|
+
localityID: 0,
|
|
243
|
+
country: cc,
|
|
244
|
+
name: regionName,
|
|
245
|
+
basis: DualRoleBasis.seat,
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
kept: new Set([...cells.values()].flatMap((kept) => kept.map((feature) => feature.geonameid))),
|
|
252
|
+
dualRolePairs: [...pairsByRegion.values()],
|
|
253
|
+
}
|
|
115
254
|
}
|
|
116
255
|
|
|
117
256
|
/**
|
|
@@ -126,7 +265,7 @@ export function createGeonamesFeaturesAdapter(): CorpusAdapter {
|
|
|
126
265
|
register: SourceRegister.GeoNames,
|
|
127
266
|
surface: SurfaceOrigin.Rendered,
|
|
128
267
|
description:
|
|
129
|
-
"GeoNames physical features (CC-BY-4.0): seas, undersea terrain, water bodies, landforms, parks and
|
|
268
|
+
"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
269
|
|
|
131
270
|
async *rows(opts: AdapterOptions): AsyncIterable<CanonicalRow> {
|
|
132
271
|
// The input is one dump (`allCountries.txt`) or a directory of country dumps (`US.txt`, `MP.txt`).
|
|
@@ -144,8 +283,7 @@ export function createGeonamesFeaturesAdapter(): CorpusAdapter {
|
|
|
144
283
|
.map((name: string) => input(name))
|
|
145
284
|
: [input]
|
|
146
285
|
|
|
147
|
-
const admin1 = await loadAdmin1(dir)
|
|
148
|
-
const countries = await loadCountries(dir)
|
|
286
|
+
const [admin1, countries, seats] = await Promise.all([loadAdmin1(dir), loadCountries(dir), readCapitalSeats()])
|
|
149
287
|
let emitted = 0
|
|
150
288
|
|
|
151
289
|
for (const dump of dumps) {
|
|
@@ -153,7 +291,8 @@ export function createGeonamesFeaturesAdapter(): CorpusAdapter {
|
|
|
153
291
|
}
|
|
154
292
|
|
|
155
293
|
async function* rowsOf(dump: PathBuilder): AsyncIterable<CanonicalRow> {
|
|
156
|
-
const kept = await
|
|
294
|
+
const { kept, dualRolePairs } = await scanDump(dump, opts.country, admin1, seats)
|
|
295
|
+
const dualRole = dualRoleRowRule(GEONAMES_FEATURES_ADAPTER_ID, dualRolePairs)
|
|
157
296
|
|
|
158
297
|
for await (const rec of readUnquotedTSV(dump)) {
|
|
159
298
|
if (opts.signal?.aborted) break
|
|
@@ -185,7 +324,7 @@ export function createGeonamesFeaturesAdapter(): CorpusAdapter {
|
|
|
185
324
|
|
|
186
325
|
if (!aligned.venue) continue
|
|
187
326
|
|
|
188
|
-
|
|
327
|
+
const row: CanonicalRow = {
|
|
189
328
|
raw: variant.raw,
|
|
190
329
|
components: aligned,
|
|
191
330
|
country: cc,
|
|
@@ -194,6 +333,10 @@ export function createGeonamesFeaturesAdapter(): CorpusAdapter {
|
|
|
194
333
|
license: GEONAMES_DEFAULT_LICENSE,
|
|
195
334
|
}
|
|
196
335
|
|
|
336
|
+
if (dualRole.drops(row)) continue
|
|
337
|
+
|
|
338
|
+
yield row
|
|
339
|
+
|
|
197
340
|
emitted++
|
|
198
341
|
}
|
|
199
342
|
}
|
|
@@ -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
|
|
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
|
-
*
|
|
26
|
-
* An optional hyphenated range may follow, written with
|
|
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 =
|
|
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
|
|
|
@@ -2,17 +2,21 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @file The `wof-admin` rule for a region that shares its name with the city inside it (Berlin, Zürich, Madrid).
|
|
5
|
+
* @file The `wof-admin` rule for a region that shares its name with the city inside it (Berlin, Zürich, Madrid, Kharkiv, Amman, Riyadh).
|
|
6
6
|
*
|
|
7
|
-
* In the two-part
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* In both the bare `<name>` form and the two-part `<name>, <country>` form, the shared name reads as the city:
|
|
8
|
+
* `Berlin`, `Berlin, Germany`, `Kharkiv`, `Amman`, and `Riyadh` refer to the city rather than the surrounding admin-1
|
|
9
|
+
* unit. The adapter therefore leaves out the region's bare `<region>` and `<region>, <country>` rows and keeps the
|
|
10
|
+
* city's `<locality>, <country>` row whatever the sample would keep (#2909, #3647).
|
|
10
11
|
*
|
|
11
|
-
* A region qualifies when it holds a same-name locality
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* A region qualifies when it holds a same-name locality that descends from it, with names compared without case or
|
|
13
|
+
* diacritics (the canton `Zurich` holds the city `Zürich`), and either:
|
|
14
|
+
*
|
|
15
|
+
* - the locality is a seat in the capitals reference for the country and lies inside the region's bounding box (or
|
|
16
|
+
* within the centroid tolerance when no bounding box is present), which handles large oblasts, governorates, and
|
|
17
|
+
* provinces whose capitals sit off-center.
|
|
18
|
+
* - the locality is the most populous locality inside the region and its centroid lies within 15% of the region's
|
|
19
|
+
* bounding-box diagonal, or within 12 km.
|
|
16
20
|
*/
|
|
17
21
|
|
|
18
22
|
import { foldToken } from "@mailwoman/codex/names/normalize"
|
|
@@ -43,7 +47,7 @@ const BBOX_2D_LENGTH = 4
|
|
|
43
47
|
/**
|
|
44
48
|
* The key two spellings of one place name share: diacritics and case removed, ends trimmed.
|
|
45
49
|
*/
|
|
46
|
-
function dualRoleKey(name: string): string {
|
|
50
|
+
export function dualRoleKey(name: string): string {
|
|
47
51
|
return foldToken(name).trim()
|
|
48
52
|
}
|
|
49
53
|
|
|
@@ -207,8 +211,12 @@ export function findDualRolePairs(
|
|
|
207
211
|
largest.set(regionID, locality)
|
|
208
212
|
}
|
|
209
213
|
|
|
210
|
-
if (dualRoleKey(locality.name) === dualRoleKey(region.name)
|
|
211
|
-
|
|
214
|
+
if (dualRoleKey(locality.name) === dualRoleKey(region.name)) {
|
|
215
|
+
const isSeat = seats.has(`${locality.country}|${dualRoleKey(locality.name)}`)
|
|
216
|
+
|
|
217
|
+
if (isCoincident(region, locality) || (isSeat && isInsideBBox(region, locality))) {
|
|
218
|
+
candidates.push({ region, locality })
|
|
219
|
+
}
|
|
212
220
|
}
|
|
213
221
|
}
|
|
214
222
|
}
|
|
@@ -249,9 +257,27 @@ function isCoincident(region: DualRolePlace, locality: DualRolePlace): boolean {
|
|
|
249
257
|
}
|
|
250
258
|
|
|
251
259
|
/**
|
|
252
|
-
*
|
|
253
|
-
|
|
254
|
-
|
|
260
|
+
* Whether a locality's point lies inside the region's declared bounding box.
|
|
261
|
+
*/
|
|
262
|
+
function isInsideBBox(region: DualRolePlace, locality: DualRolePlace): boolean {
|
|
263
|
+
if (!region.bbox) return false
|
|
264
|
+
|
|
265
|
+
const [west, south, east, north] = region.bbox
|
|
266
|
+
const latIn = locality.latitude >= south && locality.latitude <= north
|
|
267
|
+
|
|
268
|
+
const lonIn =
|
|
269
|
+
west <= east
|
|
270
|
+
? locality.longitude >= west && locality.longitude <= east
|
|
271
|
+
: locality.longitude >= west || locality.longitude <= east
|
|
272
|
+
|
|
273
|
+
return latIn && lonIn
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* The row rule for `pairs`: drops bare `<region>`, `<region>, <country>`,
|
|
278
|
+
* and `<venue>, <region>[, <country>]` rows whose region folds to a paired region's
|
|
279
|
+
* name in that country without a `locality` beside it, and requires each paired
|
|
280
|
+
* locality's canonical `<locality>, <country>` row.
|
|
255
281
|
*/
|
|
256
282
|
export function dualRoleRowRule(adapterID: string, pairs: readonly DualRolePair[]): WOFRowRule {
|
|
257
283
|
const regionNames = new Set(pairs.map((pair) => `${pair.country}|${dualRoleKey(pair.name)}`))
|
|
@@ -262,12 +288,11 @@ export function dualRoleRowRule(adapterID: string, pairs: readonly DualRolePair[
|
|
|
262
288
|
const tags = Object.keys(row.components)
|
|
263
289
|
const region = row.components.region
|
|
264
290
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
)
|
|
291
|
+
if (typeof region !== "string" || !regionNames.has(`${row.country}|${dualRoleKey(region)}`)) {
|
|
292
|
+
return false
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return tags.every((tag) => tag === "region" || tag === "country" || tag === "venue")
|
|
271
296
|
},
|
|
272
297
|
requires: (row: CanonicalRow) => required.has(row.source_id),
|
|
273
298
|
}
|
|
@@ -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
|
*
|