@mailwoman/corpus 12.1.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/holdout/evaluation-groups.v0.9.3.json +224169 -0
- package/data/training-configs/v9.3.0-bytestem-global-v093-s42.yaml +746 -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 +135 -10
- package/lib/adapters/wof/admin/json/dual-role.ts +46 -21
- package/lib/build/schema-invariants.ts +447 -0
- package/lib/jp/corpus/assemble.ts +20 -1
- package/lib/jp/corpus/rows.ts +87 -0
- package/lib/recipes/prominent/places.ts +42 -9
- package/lib/recipes/trailing-region.ts +37 -7
- package/lib/tools/fetch/wikidata/vital-places/classify.ts +23 -7
- package/lib/tools/fetch/wikidata/vital-places/render.ts +57 -7
- package/lib/training/config/schema.ts +3 -0
- package/lib/us/street-unit.ts +14 -1
- package/out/adapters/geonames/features/adapter.d.ts.map +1 -1
- package/out/adapters/geonames/features/adapter.js +90 -10
- package/out/adapters/geonames/features/adapter.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/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/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/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 +30 -7
- package/out/recipes/trailing-region.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/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/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
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
* is never confused with a street-number tail, and adds anchor-varied contrast
|
|
17
17
|
* rows for non-US four-digit postcode countries (#1821).
|
|
18
18
|
*
|
|
19
|
+
* For `before_locality` countries (`PL`, `CZ`, `DE`, `FR`, `IT`, `ES`, and peers),
|
|
20
|
+
* one tuple in {@linkcode LOCALITY_FIRST_LEADING_MODULUS} (16.7%) renders in locality-first
|
|
21
|
+
* order (`Warszawa 00-002, Poland`, `Praha 100 00, Czechia`, and with-region counterparts)
|
|
22
|
+
* without a synthetic house number (#3646).
|
|
23
|
+
*
|
|
19
24
|
* A bare `«region»` form is deliberately absent: teaching it as `region` would fight
|
|
20
25
|
* the locality/region ambiguity the dominance race arbitrates.
|
|
21
26
|
* A `dependentLocality`, when present, becomes `«dep_locality», «locality»…`; without it every
|
|
@@ -48,6 +53,12 @@ const US_CONTRAST_REGIONS: readonly string[] = Object.values(US_STATE_BY_ABBREVI
|
|
|
48
53
|
// country-branch: #1821 anchor contrasts test the US country frame independently of the region anchor.
|
|
49
54
|
const US_COUNTRY_NAME = ISO2_TO_NAME.get("US") ?? "United States"
|
|
50
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Deterministic cadence (1 in 6 = 16.7%) for rendering `before_locality` countries in
|
|
58
|
+
* locality-first `<locality> <postcode>[, <region>], <country>` order (#3646).
|
|
59
|
+
*/
|
|
60
|
+
const LOCALITY_FIRST_LEADING_MODULUS = 6
|
|
61
|
+
|
|
51
62
|
/**
|
|
52
63
|
* Infers a country's postcode placement inside the admin tail from its codex
|
|
53
64
|
* address layout and libaddressinput postcode placement, defaulting to `leading`
|
|
@@ -154,15 +165,33 @@ export const trailingRegionRecipe: CorpusRecipe = {
|
|
|
154
165
|
}
|
|
155
166
|
|
|
156
167
|
const withCountry = !region ? true : read % 2 === 0 && country.length > 0
|
|
168
|
+
|
|
169
|
+
// #3646: emit a deterministic 16.7% (1-in-6) locality-first variant for `before_locality`
|
|
170
|
+
// countries (`Warszawa 00-002, Poland`, `Praha 100 00, Czechia`), alternating
|
|
171
|
+
// regionless and with-region tails without synthetic house numbers.
|
|
172
|
+
const localityFirstVariant =
|
|
173
|
+
placement === "leading" &&
|
|
174
|
+
postcode.length > 0 &&
|
|
175
|
+
country.length > 0 &&
|
|
176
|
+
codexPostcodePlacement(cc) === "before_locality" &&
|
|
177
|
+
read % LOCALITY_FIRST_LEADING_MODULUS === 0
|
|
178
|
+
|
|
179
|
+
const effectivePlacement: PostcodePlacement = localityFirstVariant ? "after_locality" : placement
|
|
180
|
+
|
|
157
181
|
// For `after_locality` rows with a region and country, alternate between
|
|
158
182
|
// `«locality» «postcode», «region», «country»` and `«locality» «postcode», «country»`.
|
|
159
|
-
|
|
183
|
+
// For locality-first variants of `before_locality` countries, alternate the same way
|
|
184
|
+
// across every second hit (`read % 12 === 6` regionless, `read % 12 === 0` with region).
|
|
185
|
+
const includeRegion =
|
|
186
|
+
Boolean(region) &&
|
|
187
|
+
!(allowRegionlessAfterLocality && withCountry && read % 4 === 0) &&
|
|
188
|
+
!(localityFirstVariant && read % (LOCALITY_FIRST_LEADING_MODULUS * 2) !== 0)
|
|
160
189
|
|
|
161
190
|
// The house number is the second trigger for `leading` / `after_region` rows:
|
|
162
191
|
// the postcode discards the region, and the house number then displaces the locality.
|
|
163
|
-
// `after_locality` rows omit synthetic house numbers
|
|
164
|
-
// never co-occurs with a house number on a streetless tail.
|
|
165
|
-
const withHouseNumber = postcode.length > 0 &&
|
|
192
|
+
// `after_locality` rows (including locality-first variants) omit synthetic house numbers
|
|
193
|
+
// so `«locality» «postcode»` never co-occurs with a house number on a streetless tail.
|
|
194
|
+
const withHouseNumber = postcode.length > 0 && effectivePlacement !== "after_locality" && read % 4 === 1
|
|
166
195
|
const houseNumber = withHouseNumber ? String((read % 97) + 1) : ""
|
|
167
196
|
|
|
168
197
|
const components: Record<string, string> = { locality }
|
|
@@ -187,7 +216,7 @@ export const trailingRegionRecipe: CorpusRecipe = {
|
|
|
187
216
|
components["house_number"] = houseNumber
|
|
188
217
|
}
|
|
189
218
|
|
|
190
|
-
const bareLocality = postcode &&
|
|
219
|
+
const bareLocality = postcode && effectivePlacement === "after_locality" ? `${locality} ${postcode}` : locality
|
|
191
220
|
|
|
192
221
|
const localitySegment = components["dependent_locality"] ? `${dependentLocality}, ${bareLocality}` : bareLocality
|
|
193
222
|
|
|
@@ -200,7 +229,8 @@ export const trailingRegionRecipe: CorpusRecipe = {
|
|
|
200
229
|
components["region"] = regionCode
|
|
201
230
|
}
|
|
202
231
|
|
|
203
|
-
const regionSegment =
|
|
232
|
+
const regionSegment =
|
|
233
|
+
postcode && effectivePlacement === "after_region" ? `${regionSurface} ${postcode}` : regionSurface
|
|
204
234
|
|
|
205
235
|
const tail = includeRegion
|
|
206
236
|
? withCountry
|
|
@@ -208,7 +238,7 @@ export const trailingRegionRecipe: CorpusRecipe = {
|
|
|
208
238
|
: `${localitySegment}, ${regionSegment}`
|
|
209
239
|
: `${localitySegment}, ${country}`
|
|
210
240
|
|
|
211
|
-
const leadingPostcode = postcode &&
|
|
241
|
+
const leadingPostcode = postcode && effectivePlacement === "leading" ? `${postcode} ` : ""
|
|
212
242
|
const head = withHouseNumber ? `${houseNumber}, ${leadingPostcode}` : leadingPostcode
|
|
213
243
|
const raw = `${head}${tail}`
|
|
214
244
|
// A distinct source for the structured rows: the sampler buckets by `source`,
|
|
@@ -22,10 +22,19 @@ import type { SPARQLResults, WikidataClient } from "#tools/fetch/wikidata/subven
|
|
|
22
22
|
import { chunked, entityQID, formatElapsed, type ProgressReporter } from "#tools/fetch/wikidata/vital-places/progress"
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* A class under one of these roots makes its instances places
|
|
26
|
-
*
|
|
25
|
+
* A class under one of these roots makes its instances places.
|
|
26
|
+
*
|
|
27
|
+
* Covers geographic location, geographical feature, architectural structure,
|
|
28
|
+
* `Q473972` (national parks), and archaeological site.
|
|
29
|
+
*/
|
|
30
|
+
export const PLACE_ROOTS: readonly string[] = ["Q2221906", "Q618123", "Q811979", "Q473972", "Q839954"]
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Direct `P31` classes for located physical features and public monuments whose Wikidata
|
|
34
|
+
* class tree doesn't walk up to {@linkcode PLACE_ROOTS}: oceanic trench (`Q21285941`),
|
|
35
|
+
* sculpture (`Q860861`), and statue (`Q179700`).
|
|
27
36
|
*/
|
|
28
|
-
export const
|
|
37
|
+
export const DIRECT_PLACE_CLASSES: readonly string[] = ["Q21285941", "Q860861", "Q179700"]
|
|
29
38
|
|
|
30
39
|
/**
|
|
31
40
|
* A class under one of these roots excludes its instances: occurrence
|
|
@@ -61,9 +70,11 @@ export const ROAD_ROOTS: readonly string[] = ["Q34442", "Q79007"]
|
|
|
61
70
|
|
|
62
71
|
/**
|
|
63
72
|
* Every root the descent query asks about: the inventory's and the render's.
|
|
73
|
+
*
|
|
74
|
+
* Keeps the v3 root order stable so cached `class-roots.v3.json` entries match without re-querying.
|
|
64
75
|
*/
|
|
65
76
|
export const DESCENT_ROOTS: readonly string[] = [
|
|
66
|
-
...new Set([
|
|
77
|
+
...new Set(["Q2221906", "Q618123", "Q811979", ...EXCLUDED_ROOTS, ...SETTLEMENT_ROOTS, ...SITE_ROOTS, ...ROAD_ROOTS]),
|
|
67
78
|
]
|
|
68
79
|
|
|
69
80
|
/**
|
|
@@ -170,9 +181,14 @@ export function placeVerdict(classes: readonly string[], roots: Readonly<ClassRo
|
|
|
170
181
|
|
|
171
182
|
if (classRoots.some(excludesInstances)) return PLACE_VERDICTS.excluded
|
|
172
183
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
184
|
+
if (
|
|
185
|
+
classes.some((cls) => DIRECT_PLACE_CLASSES.includes(cls)) ||
|
|
186
|
+
classRoots.some((rootsOfClass) => PLACE_ROOTS.some((root) => rootsOfClass.includes(root)))
|
|
187
|
+
) {
|
|
188
|
+
return PLACE_VERDICTS.place
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return PLACE_VERDICTS.unclassified
|
|
176
192
|
}
|
|
177
193
|
|
|
178
194
|
/**
|
|
@@ -65,16 +65,41 @@ export const VITAL_PLACE_RENDERINGS = {
|
|
|
65
65
|
|
|
66
66
|
export type VitalPlaceRendering = (typeof VITAL_PLACE_RENDERINGS)[keyof typeof VITAL_PLACE_RENDERINGS]
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Wikidata root for sovereign countries (`Q6256`).
|
|
70
|
+
*
|
|
71
|
+
* A country stays a settlement even when it also holds a biosphere-reserve or park class.
|
|
72
|
+
*/
|
|
73
|
+
const COUNTRY_ROOT = "Q6256"
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Wikidata root for national parks and nature reserves (`Q473972`).
|
|
77
|
+
*/
|
|
78
|
+
const RESERVE_ROOT = "Q473972"
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Direct `P31` classes for national parks and canyons/gorges that render as venues.
|
|
82
|
+
*
|
|
83
|
+
* Includes national park (`Q46169`), US national park (`Q34918903`), IUCN category
|
|
84
|
+
* II national park (`Q179049`), and canyon/gorge (`Q150784`).
|
|
85
|
+
* These stay venues even with an administrative class and a small staff population.
|
|
86
|
+
*/
|
|
87
|
+
const NATURAL_PARK_AND_GORGE_CLASSES: ReadonlySet<string> = new Set(["Q46169", "Q34918903", "Q179049", "Q150784"])
|
|
88
|
+
|
|
68
89
|
/**
|
|
69
90
|
* Whether a place renders as venues.
|
|
70
91
|
*
|
|
71
|
-
* A place under a settlement root is left to Who's On First unless
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
92
|
+
* A place under a settlement root is left to Who's On First unless it is a non-country
|
|
93
|
+
* national park, canyon/gorge, or `Q473972` reserve without a pure settlement class.
|
|
94
|
+
* A site without positive population also stays a venue.
|
|
95
|
+
*
|
|
96
|
+
* Wikidata puts observation tower, national park, and ancient city under admin roots.
|
|
97
|
+
* The site exception keeps Eiffel Tower, Machu Picchu, and Northeast Greenland National Park as venues.
|
|
75
98
|
*
|
|
76
|
-
* The site exception keeps the Eiffel Tower and Machu Picchu as venues.
|
|
77
99
|
* A capital whose old town is a World Heritage site states a population and stays a locality.
|
|
100
|
+
*
|
|
101
|
+
* A place under a road root renders as a road only when it holds no non-road site class.
|
|
102
|
+
* Charles Bridge stays a venue while streets such as Calle de Alcalá stay roads.
|
|
78
103
|
*/
|
|
79
104
|
export function vitalPlaceRendering(
|
|
80
105
|
place: Pick<VitalPlace, "classes" | "population" | "countryCodes">,
|
|
@@ -83,10 +108,35 @@ export function vitalPlaceRendering(
|
|
|
83
108
|
const placeRoots = new Set(place.classes.flatMap((cls) => roots[cls] ?? []))
|
|
84
109
|
const settlement = SETTLEMENT_ROOTS.some((root) => placeRoots.has(root))
|
|
85
110
|
const site = SITE_ROOTS.some((root) => placeRoots.has(root))
|
|
111
|
+
const isCountry = placeRoots.has(COUNTRY_ROOT)
|
|
112
|
+
const hasPopulation = place.population != null && place.population > 0
|
|
113
|
+
|
|
114
|
+
const isNaturalParkOrGorge = !isCountry && place.classes.some((cls) => NATURAL_PARK_AND_GORGE_CLASSES.has(cls))
|
|
115
|
+
|
|
116
|
+
const hasPureSettlementClass = place.classes.some((cls) => {
|
|
117
|
+
const classRoots = roots[cls] ?? []
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
SETTLEMENT_ROOTS.some((root) => classRoots.includes(root)) &&
|
|
121
|
+
!SITE_ROOTS.some((root) => classRoots.includes(root))
|
|
122
|
+
)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
const isReserveOnly = !isCountry && placeRoots.has(RESERVE_ROOT) && !hasPureSettlementClass
|
|
126
|
+
|
|
127
|
+
if (isCountry || (settlement && !isNaturalParkOrGorge && !isReserveOnly && (!site || hasPopulation))) {
|
|
128
|
+
return VITAL_PLACE_RENDERINGS.settlement
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const hasRoad = ROAD_ROOTS.some((root) => placeRoots.has(root))
|
|
132
|
+
|
|
133
|
+
const hasNonRoadSite = place.classes.some((cls) => {
|
|
134
|
+
const classRoots = roots[cls] ?? []
|
|
86
135
|
|
|
87
|
-
|
|
136
|
+
return SITE_ROOTS.some((root) => classRoots.includes(root)) && !ROAD_ROOTS.some((root) => classRoots.includes(root))
|
|
137
|
+
})
|
|
88
138
|
|
|
89
|
-
if (
|
|
139
|
+
if (hasRoad && !hasNonRoadSite) return VITAL_PLACE_RENDERINGS.road
|
|
90
140
|
|
|
91
141
|
if (!vitalPlaceCountry(place)) return VITAL_PLACE_RENDERINGS.noCountry
|
|
92
142
|
|
|
@@ -226,6 +226,7 @@ export const DATA_SECTION = {
|
|
|
226
226
|
augment_postcode_move_prob: float(0),
|
|
227
227
|
augment_grouping_prob: float(0),
|
|
228
228
|
code_unit_features: bool(false),
|
|
229
|
+
route_features: bool(false),
|
|
229
230
|
augment_exclude_sources: strList(),
|
|
230
231
|
anchor_lookup_path: optionalStr(),
|
|
231
232
|
gazetteer_lexicon_path: optionalStr(),
|
|
@@ -321,6 +322,8 @@ export const MODEL_SECTION = {
|
|
|
321
322
|
locality_surface_feature_dim: int(2n),
|
|
322
323
|
use_code_unit_anchor: bool(false),
|
|
323
324
|
code_unit_feature_dim: int(5n),
|
|
325
|
+
use_route_anchor: bool(false),
|
|
326
|
+
route_feature_dim: int(2n),
|
|
324
327
|
use_char_embed: bool(false),
|
|
325
328
|
char_embed_dim: int(64n),
|
|
326
329
|
char_kernel_sizes: intList([3n, 4n, 5n]),
|
package/lib/us/street-unit.ts
CHANGED
|
@@ -69,9 +69,22 @@ export function splitUSStreetLine(
|
|
|
69
69
|
const box = usPOBoxLine(line)
|
|
70
70
|
|
|
71
71
|
if (box) return box
|
|
72
|
-
|
|
72
|
+
let split = splitStreetLine(line)
|
|
73
73
|
|
|
74
74
|
if (!split) return null
|
|
75
|
+
|
|
76
|
+
// A hyphenated single-letter suffix (`101 - B Street`) belongs to the street
|
|
77
|
+
// when the remainder is only a bare street-type word (`Street`, `Ave`, `Road`)
|
|
78
|
+
// rather than a complete street name (#3506).
|
|
79
|
+
if (split.house_number) {
|
|
80
|
+
const letterSuffix = /^(.+?)\s*-\s*([A-Za-z])$/u.exec(split.house_number)
|
|
81
|
+
const streetWord = split.street.replace(/[.,]$/u, "").toLowerCase()
|
|
82
|
+
|
|
83
|
+
if (letterSuffix && !/\s/u.test(split.street) && units.vocabulary("US")?.streetTypes.has(streetWord)) {
|
|
84
|
+
split = { house_number: letterSuffix[1]!, street: `${letterSuffix[2]!} ${split.street}` }
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
75
88
|
const trailing = units.split(split.street, { ...place, country: "US" })
|
|
76
89
|
|
|
77
90
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../../lib/adapters/geonames/features/adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../../lib/adapters/geonames/features/adapter.ts"],"names":[],"mappings":"AAwCA,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;AAoKvD;;GAEG;AACH,wBAAgB,6BAA6B,IAAI,aAAa,CAuF7D;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,eAAkC,CAAA"}
|
|
@@ -21,6 +21,7 @@ import { compareByScalarValue } from "@mailwoman/core/strings/compare";
|
|
|
21
21
|
import { PathBuilder } from "path-ts";
|
|
22
22
|
import { Globerator } from "spliterator/node/fs";
|
|
23
23
|
import { GEONAMES_DEFAULT_LICENSE, GEONAMES_MAIN_COLUMNS as COL, loadAdmin1, loadCountries, } from "#adapters/geonames/adapter";
|
|
24
|
+
import { DualRoleBasis, dualRoleKey, dualRoleRowRule, readCapitalSeats, } from "#adapters/wof/admin/json/dual-role";
|
|
24
25
|
import { SourceRegister } from "#registers";
|
|
25
26
|
import { AddressRole, SurfaceOrigin } from "#types";
|
|
26
27
|
/**
|
|
@@ -67,20 +68,61 @@ export const GEONAMES_FEATURES_PER_CELL = 25;
|
|
|
67
68
|
*/
|
|
68
69
|
export const GEONAMES_FEATURES_WITH_COUNTRY_DIVISOR = 4;
|
|
69
70
|
/**
|
|
70
|
-
*
|
|
71
|
+
* Historical, abandoned, or destroyed populated-place feature codes skipped
|
|
72
|
+
* when detecting dual-role regions.
|
|
71
73
|
*/
|
|
72
|
-
|
|
74
|
+
const NON_CURRENT_PPL = new Set(["PPLH", "PPLQ", "PPLW", "PPLCH"]);
|
|
75
|
+
/**
|
|
76
|
+
* GeoNames feature codes for national capitals and admin-1 seats.
|
|
77
|
+
*/
|
|
78
|
+
const ADMIN1_SEAT_CODES = new Set(["PPLC", "PPLA"]);
|
|
79
|
+
/**
|
|
80
|
+
* Scans one GeoNames dump in a single pass to collect:
|
|
81
|
+
* 1. The {@linkcode GEONAMES_FEATURES_PER_CELL} lowest-hashed feature geonameids
|
|
82
|
+
* per `(country, featureCode)` cell.
|
|
83
|
+
* 2. The dual-role admin-1 pairs where a current populated place in `(cc, admin1)`
|
|
84
|
+
* shares the folded name of that admin-1 unit and is either a capital/admin-1 seat
|
|
85
|
+
* or the unit's most populous locality.
|
|
86
|
+
* When a country has no populated-place rows in the dump (as in features-only fixtures),
|
|
87
|
+
* the committed capitals reference decides seats.
|
|
88
|
+
*/
|
|
89
|
+
async function scanDump(input, country, admin1, seats) {
|
|
73
90
|
const cells = new Map();
|
|
91
|
+
const countriesWithPPL = new Set();
|
|
92
|
+
const largestByAdmin1 = new Map();
|
|
93
|
+
const candidates = [];
|
|
74
94
|
for await (const rec of readUnquotedTSV(input)) {
|
|
75
95
|
const cls = rec[COL.featureClass] ?? "";
|
|
76
96
|
const code = (rec[COL.featureCode] ?? "").trim();
|
|
77
|
-
if (!isSelectedGeonamesFeature(cls, code))
|
|
78
|
-
continue;
|
|
79
97
|
const cc = (rec[COL.country] ?? "").trim();
|
|
80
98
|
if (!cc || (country && cc !== country))
|
|
81
99
|
continue;
|
|
82
100
|
const geonameid = (rec[COL.geonameid] ?? "").trim();
|
|
83
|
-
|
|
101
|
+
const name = (rec[COL.name] ?? "").trim();
|
|
102
|
+
if (!geonameid || !name)
|
|
103
|
+
continue;
|
|
104
|
+
if (cls === "P" && !NON_CURRENT_PPL.has(code)) {
|
|
105
|
+
countriesWithPPL.add(cc);
|
|
106
|
+
const admin1Code = (rec[COL.admin1] ?? "").trim();
|
|
107
|
+
const admin1Key = `${cc}.${admin1Code}`;
|
|
108
|
+
const regionName = admin1.get(admin1Key);
|
|
109
|
+
if (regionName) {
|
|
110
|
+
const id = Number.parseInt(geonameid, 10) || 0;
|
|
111
|
+
const population = Number.parseInt(rec[COL.population] ?? "0", 10) || 0;
|
|
112
|
+
const prev = largestByAdmin1.get(admin1Key);
|
|
113
|
+
if (population > 0 &&
|
|
114
|
+
(!prev || population > prev.population || (population === prev.population && id < prev.id))) {
|
|
115
|
+
largestByAdmin1.set(admin1Key, { id, population });
|
|
116
|
+
}
|
|
117
|
+
const regionFolded = dualRoleKey(regionName);
|
|
118
|
+
const asciiName = (rec[COL.asciiname] ?? "").trim();
|
|
119
|
+
if (dualRoleKey(name) === regionFolded || (asciiName && dualRoleKey(asciiName) === regionFolded)) {
|
|
120
|
+
const isSeat = ADMIN1_SEAT_CODES.has(code) || seats.has(`${cc}|${regionFolded}`);
|
|
121
|
+
candidates.push({ admin1Key, cc, regionName, localityID: id, isSeat });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (!isSelectedGeonamesFeature(cls, code))
|
|
84
126
|
continue;
|
|
85
127
|
const key = `${cc}\t${code}`;
|
|
86
128
|
const kept = cells.get(key) ?? [];
|
|
@@ -100,7 +142,42 @@ async function keptFeatureIDs(input, country) {
|
|
|
100
142
|
}
|
|
101
143
|
}
|
|
102
144
|
}
|
|
103
|
-
|
|
145
|
+
const pairsByRegion = new Map();
|
|
146
|
+
for (const candidate of candidates) {
|
|
147
|
+
const basis = candidate.isSeat
|
|
148
|
+
? DualRoleBasis.seat
|
|
149
|
+
: largestByAdmin1.get(candidate.admin1Key)?.id === candidate.localityID
|
|
150
|
+
? DualRoleBasis.largest
|
|
151
|
+
: null;
|
|
152
|
+
if (basis && !pairsByRegion.has(candidate.admin1Key)) {
|
|
153
|
+
pairsByRegion.set(candidate.admin1Key, {
|
|
154
|
+
regionID: 0,
|
|
155
|
+
localityID: candidate.localityID,
|
|
156
|
+
country: candidate.cc,
|
|
157
|
+
name: candidate.regionName,
|
|
158
|
+
basis,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// Fallback for features-only dumps that omit populated-place rows: check admin1 names against the capitals reference.
|
|
163
|
+
for (const [admin1Key, regionName] of admin1) {
|
|
164
|
+
const cc = admin1Key.split(".")[0] ?? "";
|
|
165
|
+
if (!cc || (country && cc !== country) || countriesWithPPL.has(cc) || pairsByRegion.has(admin1Key))
|
|
166
|
+
continue;
|
|
167
|
+
if (seats.has(`${cc}|${dualRoleKey(regionName)}`)) {
|
|
168
|
+
pairsByRegion.set(admin1Key, {
|
|
169
|
+
regionID: 0,
|
|
170
|
+
localityID: 0,
|
|
171
|
+
country: cc,
|
|
172
|
+
name: regionName,
|
|
173
|
+
basis: DualRoleBasis.seat,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
kept: new Set([...cells.values()].flatMap((kept) => kept.map((feature) => feature.geonameid))),
|
|
179
|
+
dualRolePairs: [...pairsByRegion.values()],
|
|
180
|
+
};
|
|
104
181
|
}
|
|
105
182
|
/**
|
|
106
183
|
* Creates the GeoNames physical-feature adapter.
|
|
@@ -126,14 +203,14 @@ export function createGeonamesFeaturesAdapter() {
|
|
|
126
203
|
.toSorted(compareByScalarValue)
|
|
127
204
|
.map((name) => input(name))
|
|
128
205
|
: [input];
|
|
129
|
-
const admin1 = await loadAdmin1(dir);
|
|
130
|
-
const countries = await loadCountries(dir);
|
|
206
|
+
const [admin1, countries, seats] = await Promise.all([loadAdmin1(dir), loadCountries(dir), readCapitalSeats()]);
|
|
131
207
|
let emitted = 0;
|
|
132
208
|
for (const dump of dumps) {
|
|
133
209
|
yield* rowsOf(dump);
|
|
134
210
|
}
|
|
135
211
|
async function* rowsOf(dump) {
|
|
136
|
-
const kept = await
|
|
212
|
+
const { kept, dualRolePairs } = await scanDump(dump, opts.country, admin1, seats);
|
|
213
|
+
const dualRole = dualRoleRowRule(GEONAMES_FEATURES_ADAPTER_ID, dualRolePairs);
|
|
137
214
|
for await (const rec of readUnquotedTSV(dump)) {
|
|
138
215
|
if (opts.signal?.aborted)
|
|
139
216
|
break;
|
|
@@ -161,7 +238,7 @@ export function createGeonamesFeaturesAdapter() {
|
|
|
161
238
|
const aligned = componentsPresentIn(variant.comp, variant.raw);
|
|
162
239
|
if (!aligned.venue)
|
|
163
240
|
continue;
|
|
164
|
-
|
|
241
|
+
const row = {
|
|
165
242
|
raw: variant.raw,
|
|
166
243
|
components: aligned,
|
|
167
244
|
country: cc,
|
|
@@ -169,6 +246,9 @@ export function createGeonamesFeaturesAdapter() {
|
|
|
169
246
|
source_id: `${GEONAMES_FEATURES_ADAPTER_ID}-${geonameid}-${variant.slot}`,
|
|
170
247
|
license: GEONAMES_DEFAULT_LICENSE,
|
|
171
248
|
};
|
|
249
|
+
if (dualRole.drops(row))
|
|
250
|
+
continue;
|
|
251
|
+
yield row;
|
|
172
252
|
emitted++;
|
|
173
253
|
}
|
|
174
254
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../../lib/adapters/geonames/features/adapter.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,OAAO,EACN,wBAAwB,EACxB,qBAAqB,IAAI,GAAG,EAC5B,UAAU,EACV,aAAa,GACb,MAAM,4BAA4B,CAAA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G,mBAAmB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;wBAE9D,IAAI,CAAC,OAAO,CAAC,KAAK;4BAAE,SAAQ;wBAE5B,MAAM,GAAG,GAAiB;4BACzB,GAAG,EAAE,OAAO,CAAC,GAAG;4BAChB,UAAU,EAAE,OAAO;4BACnB,OAAO,EAAE,EAAE;4BACX,MAAM,EAAE,4BAA4B;4BACpC,SAAS,EAAE,GAAG,4BAA4B,IAAI,SAAS,IAAI,OAAO,CAAC,IAAI,EAAE;4BACzE,OAAO,EAAE,wBAAwB;yBACjC,CAAA;wBAED,IAAI,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC;4BAAE,SAAQ;wBAEjC,MAAM,GAAG,CAAA;wBAET,OAAO,EAAE,CAAA;oBACV,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;KACD,CAAA;AACF,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,6BAA6B,EAAE,CAAA"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { PathBuilderLike } from "path-ts";
|
|
2
2
|
import type { WOFRowRule } from "#adapters/wof/json-rows";
|
|
3
3
|
import type { WOFRecord } from "#utils";
|
|
4
|
+
/**
|
|
5
|
+
* The key two spellings of one place name share: diacritics and case removed, ends trimmed.
|
|
6
|
+
*/
|
|
7
|
+
export declare function dualRoleKey(name: string): string;
|
|
4
8
|
/**
|
|
5
9
|
* One region or locality as the rule reads it.
|
|
6
10
|
*/
|
|
@@ -75,9 +79,10 @@ export declare function readCapitalSeats(path?: PathBuilderLike): Promise<Capita
|
|
|
75
79
|
*/
|
|
76
80
|
export declare function findDualRolePairs(regionPlaces: Iterable<DualRolePlace>, localities: Iterable<DualRolePlace>, seats: CapitalSeats): DualRolePair[];
|
|
77
81
|
/**
|
|
78
|
-
* The row rule for `pairs`:
|
|
79
|
-
*
|
|
80
|
-
*
|
|
82
|
+
* The row rule for `pairs`: drops bare `<region>`, `<region>, <country>`,
|
|
83
|
+
* and `<venue>, <region>[, <country>]` rows whose region folds to a paired region's
|
|
84
|
+
* name in that country without a `locality` beside it, and requires each paired
|
|
85
|
+
* locality's canonical `<locality>, <country>` row.
|
|
81
86
|
*/
|
|
82
87
|
export declare function dualRoleRowRule(adapterID: string, pairs: readonly DualRolePair[]): WOFRowRule;
|
|
83
88
|
//# sourceMappingURL=dual-role.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dual-role.d.ts","sourceRoot":"","sources":["../../../../../lib/adapters/wof/admin/json/dual-role.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dual-role.d.ts","sourceRoot":"","sources":["../../../../../lib/adapters/wof/admin/json/dual-role.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAiBvC;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAA;IACtD,UAAU,EAAE,MAAM,CAAA;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,CA2BrG;AAED;;GAEG;AACH,eAAO,MAAM,aAAa;aAAK,IAAI,EAAE,MAAM;aAAE,OAAO,EAAE,SAAS;CAAW,CAAA;AAE1E,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAA;AAE9E;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,aAAa,CAAA;CACpB;AAED;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;AAE9C;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,GAAE,eAAyC,GAAG,OAAO,CAAC,YAAY,CAAC,CAuB7G;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAChC,YAAY,EAAE,QAAQ,CAAC,aAAa,CAAC,EACrC,UAAU,EAAE,QAAQ,CAAC,aAAa,CAAC,EACnC,KAAK,EAAE,YAAY,GACjB,YAAY,EAAE,CAoDhB;AAqCD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,YAAY,EAAE,GAAG,UAAU,CAiB7F"}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
3
|
/**
|
|
4
|
-
* @file The `wof-admin` rule for a region that shares its name with the city inside it (Berlin, Zürich, Madrid).
|
|
4
|
+
* @file The `wof-admin` rule for a region that shares its name with the city inside it (Berlin, Zürich, Madrid, Kharkiv, Amman, Riyadh).
|
|
5
5
|
*
|
|
6
|
-
* In the two-part
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* In both the bare `<name>` form and the two-part `<name>, <country>` form, the shared name reads as the city:
|
|
7
|
+
* `Berlin`, `Berlin, Germany`, `Kharkiv`, `Amman`, and `Riyadh` refer to the city rather than the surrounding admin-1
|
|
8
|
+
* unit. The adapter therefore leaves out the region's bare `<region>` and `<region>, <country>` rows and keeps the
|
|
9
|
+
* city's `<locality>, <country>` row whatever the sample would keep (#2909, #3647).
|
|
9
10
|
*
|
|
10
|
-
* A region qualifies when it holds a same-name locality
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* A region qualifies when it holds a same-name locality that descends from it, with names compared without case or
|
|
12
|
+
* diacritics (the canton `Zurich` holds the city `Zürich`), and either:
|
|
13
|
+
*
|
|
14
|
+
* - the locality is a seat in the capitals reference for the country and lies inside the region's bounding box (or
|
|
15
|
+
* within the centroid tolerance when no bounding box is present), which handles large oblasts, governorates, and
|
|
16
|
+
* provinces whose capitals sit off-center.
|
|
17
|
+
* - the locality is the most populous locality inside the region and its centroid lies within 15% of the region's
|
|
18
|
+
* bounding-box diagonal, or within 12 km.
|
|
15
19
|
*/
|
|
16
20
|
import { foldToken } from "@mailwoman/codex/names/normalize";
|
|
17
21
|
import { readLocalJSONFile } from "@mailwoman/core/fs/readers";
|
|
@@ -32,7 +36,7 @@ const BBOX_2D_LENGTH = 4;
|
|
|
32
36
|
/**
|
|
33
37
|
* The key two spellings of one place name share: diacritics and case removed, ends trimmed.
|
|
34
38
|
*/
|
|
35
|
-
function dualRoleKey(name) {
|
|
39
|
+
export function dualRoleKey(name) {
|
|
36
40
|
return foldToken(name).trim();
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
@@ -128,8 +132,11 @@ export function findDualRolePairs(regionPlaces, localities, seats) {
|
|
|
128
132
|
(locality.population === held.population && locality.id < held.id))) {
|
|
129
133
|
largest.set(regionID, locality);
|
|
130
134
|
}
|
|
131
|
-
if (dualRoleKey(locality.name) === dualRoleKey(region.name)
|
|
132
|
-
|
|
135
|
+
if (dualRoleKey(locality.name) === dualRoleKey(region.name)) {
|
|
136
|
+
const isSeat = seats.has(`${locality.country}|${dualRoleKey(locality.name)}`);
|
|
137
|
+
if (isCoincident(region, locality) || (isSeat && isInsideBBox(region, locality))) {
|
|
138
|
+
candidates.push({ region, locality });
|
|
139
|
+
}
|
|
133
140
|
}
|
|
134
141
|
}
|
|
135
142
|
}
|
|
@@ -161,9 +168,23 @@ function isCoincident(region, locality) {
|
|
|
161
168
|
return distance <= Math.max(TOLERANCE_FRACTION * diagonal, MIN_TOLERANCE_KM);
|
|
162
169
|
}
|
|
163
170
|
/**
|
|
164
|
-
*
|
|
165
|
-
|
|
166
|
-
|
|
171
|
+
* Whether a locality's point lies inside the region's declared bounding box.
|
|
172
|
+
*/
|
|
173
|
+
function isInsideBBox(region, locality) {
|
|
174
|
+
if (!region.bbox)
|
|
175
|
+
return false;
|
|
176
|
+
const [west, south, east, north] = region.bbox;
|
|
177
|
+
const latIn = locality.latitude >= south && locality.latitude <= north;
|
|
178
|
+
const lonIn = west <= east
|
|
179
|
+
? locality.longitude >= west && locality.longitude <= east
|
|
180
|
+
: locality.longitude >= west || locality.longitude <= east;
|
|
181
|
+
return latIn && lonIn;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* The row rule for `pairs`: drops bare `<region>`, `<region>, <country>`,
|
|
185
|
+
* and `<venue>, <region>[, <country>]` rows whose region folds to a paired region's
|
|
186
|
+
* name in that country without a `locality` beside it, and requires each paired
|
|
187
|
+
* locality's canonical `<locality>, <country>` row.
|
|
167
188
|
*/
|
|
168
189
|
export function dualRoleRowRule(adapterID, pairs) {
|
|
169
190
|
const regionNames = new Set(pairs.map((pair) => `${pair.country}|${dualRoleKey(pair.name)}`));
|
|
@@ -172,10 +193,10 @@ export function dualRoleRowRule(adapterID, pairs) {
|
|
|
172
193
|
drops: (row) => {
|
|
173
194
|
const tags = Object.keys(row.components);
|
|
174
195
|
const region = row.components.region;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
196
|
+
if (typeof region !== "string" || !regionNames.has(`${row.country}|${dualRoleKey(region)}`)) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
return tags.every((tag) => tag === "region" || tag === "country" || tag === "venue");
|
|
179
200
|
},
|
|
180
201
|
requires: (row) => required.has(row.source_id),
|
|
181
202
|
};
|