@mailwoman/corpus 11.3.0 → 11.4.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/PROVENANCE.md +3 -4
- package/data/address-source-register.json +4 -4
- package/data/builds/v0.8.23-overlay/OVERLAY_PLAN.json +3656 -0
- package/data/builds/v0.8.23-prominent-overlay/OVERLAY_PLAN.json +42 -0
- package/data/builds/v0.8.23-rebuild/inputs.json +141 -0
- package/data/builds/v0.8.24-rebuild/inputs.json +111 -0
- package/data/corpus-source-inputs.json +95 -1
- package/data/holdout/evaluation-groups.v0.8.24.json +222158 -0
- package/data/license-decisions.json +5 -0
- package/data/region-slot-second-level.json +1 -1
- package/data/training-configs/v8.11.0-base-c6-90k-v0823-s42.yaml +920 -0
- package/data/training-configs/v8.12.0-base-c6-wofreps-v0823-s42.yaml +944 -0
- package/data/training-configs/v8.13.0-base-c6-wofreps-v0822-s42.yaml +918 -0
- package/lib/adapters/cordis/adapter.ts +3 -2
- package/lib/adapters/gleif/adapter.ts +123 -20
- package/lib/adapters/openaddresses/adapter.ts +2 -2
- package/lib/adapters/osm/adapter.ts +62 -4
- package/lib/adapters/overture/adapter.ts +97 -15
- package/lib/adapters/overture/address-key.ts +89 -0
- package/lib/adapters/overture/places-in/adapter.ts +258 -0
- package/lib/adapters/street/convention.ts +49 -0
- package/lib/adapters/street/country-line.ts +65 -0
- package/lib/adapters/wof/admin/json/adapter.ts +4 -4
- package/lib/adapters/wof/admin/json/region-codes.ts +98 -0
- package/lib/adapters/wof/json-rows.ts +2 -2
- package/lib/adapters.ts +2 -0
- package/lib/build/align/range.ts +21 -11
- package/lib/build/align/totals.ts +20 -0
- package/lib/build/align.ts +218 -20
- package/lib/build/budget.ts +55 -20
- package/lib/build/checkpoint.ts +9 -0
- package/lib/build/component-check.ts +97 -3
- package/lib/build/inputs.ts +122 -31
- package/lib/build/manifest.ts +1 -0
- package/lib/build/parallel.ts +140 -23
- package/lib/build/{region-names.ts → region/names.ts} +16 -4
- package/lib/build/region/recount.ts +153 -0
- package/lib/build/reuse.ts +112 -0
- package/lib/build/settings.ts +84 -3
- package/lib/build/source-record.ts +45 -8
- package/lib/build/types.ts +26 -0
- package/lib/build/worker.ts +75 -10
- package/lib/build.ts +2 -1
- package/lib/de/recipes/locale.ts +9 -3
- package/lib/evaluation/corpus-adapter.ts +2 -2
- package/lib/fi/adapters/ryhti/adapter.ts +2 -2
- package/lib/fo/adapters/adressur/adapter.ts +2 -2
- package/lib/fr/recipes/lieudit.ts +3 -4
- package/lib/in/street-line/segment.ts +370 -0
- package/lib/international/recipes/locale.ts +6 -3
- package/lib/li/adapters/llv/adapter.ts +2 -2
- package/lib/lu/adapters/bd-adresses/adapter.ts +2 -2
- package/lib/no/adapters/matrikkelen/adapter.ts +2 -2
- package/lib/parquet/streams.ts +18 -3
- package/lib/parquet/writers.ts +161 -29
- package/lib/recipes/country-balanced.ts +32 -18
- package/lib/recipes/fragment-assay/build.ts +8 -5
- package/lib/recipes/fragment-assay/rows.ts +4 -4
- package/lib/recipes/house/venue.ts +2 -1
- package/lib/recipes/postal/guideline/leg.ts +3 -2
- package/lib/recipes/prominent/places.ts +4 -4
- package/lib/runner.ts +139 -20
- package/lib/sg/recipes/register.ts +6 -1
- package/lib/source-register/row-license.ts +12 -2
- package/lib/surfaces/corpus-row.ts +84 -0
- package/lib/surfaces/locale.ts +20 -24
- package/lib/synthesizers/house-venue.ts +33 -40
- package/lib/synthesizers/no-street.ts +2 -2
- package/lib/synthesizers/po-box.ts +3 -3
- package/lib/synthesizers/tail.ts +3 -2
- package/lib/synthesizers/utils.ts +95 -56
- package/lib/test-kit.ts +50 -1
- package/lib/tools/fetch/overture-places-in.ts +118 -0
- package/lib/tools/fetch/storage.ts +3 -0
- package/lib/tools/fetch.ts +2 -0
- package/lib/tools/region-slot-census.run.ts +2 -2
- package/lib/types.ts +39 -0
- package/lib/us/adapters/state/tx-notaries/adapter.ts +2 -1
- package/lib/us/adapters/usgov/imls-pls/adapter.ts +2 -1
- package/lib/us/adapters/usgov/nad/adapter.ts +32 -4
- package/lib/us/adapters/usgov/nad/address-key.ts +8 -47
- package/lib/us/adapters/usgov/nppes/adapter.ts +2 -1
- package/lib/utils/address-key.ts +57 -0
- package/lib/utils/align.ts +22 -10
- package/lib/utils/evaluation-groups.ts +13 -6
- package/lib/utils/split.ts +24 -3
- package/out/adapters/cordis/adapter.d.ts.map +1 -1
- package/out/adapters/cordis/adapter.js +3 -2
- package/out/adapters/cordis/adapter.js.map +1 -1
- package/out/adapters/gleif/adapter.d.ts +4 -0
- package/out/adapters/gleif/adapter.d.ts.map +1 -1
- package/out/adapters/gleif/adapter.js +100 -20
- package/out/adapters/gleif/adapter.js.map +1 -1
- package/out/adapters/openaddresses/adapter.js +2 -2
- package/out/adapters/openaddresses/adapter.js.map +1 -1
- package/out/adapters/osm/adapter.d.ts +9 -0
- package/out/adapters/osm/adapter.d.ts.map +1 -1
- package/out/adapters/osm/adapter.js +55 -13
- package/out/adapters/osm/adapter.js.map +1 -1
- package/out/adapters/overture/adapter.d.ts +6 -0
- package/out/adapters/overture/adapter.d.ts.map +1 -1
- package/out/adapters/overture/adapter.js +72 -9
- package/out/adapters/overture/adapter.js.map +1 -1
- package/out/adapters/overture/address-key.d.ts +39 -0
- package/out/adapters/overture/address-key.d.ts.map +1 -0
- package/out/adapters/overture/address-key.js +75 -0
- package/out/adapters/overture/address-key.js.map +1 -0
- package/out/adapters/overture/places-in/adapter.d.ts +20 -0
- package/out/adapters/overture/places-in/adapter.d.ts.map +1 -0
- package/out/adapters/overture/places-in/adapter.js +191 -0
- package/out/adapters/overture/places-in/adapter.js.map +1 -0
- package/out/adapters/street/convention.d.ts +11 -0
- package/out/adapters/street/convention.d.ts.map +1 -0
- package/out/adapters/street/convention.js +40 -0
- package/out/adapters/street/convention.js.map +1 -0
- package/out/adapters/street/country-line.d.ts +31 -0
- package/out/adapters/street/country-line.d.ts.map +1 -0
- package/out/adapters/street/country-line.js +31 -0
- package/out/adapters/street/country-line.js.map +1 -0
- package/out/adapters/wof/admin/json/adapter.js +4 -4
- package/out/adapters/wof/admin/json/adapter.js.map +1 -1
- package/out/adapters/wof/admin/json/region-codes.d.ts +5 -0
- package/out/adapters/wof/admin/json/region-codes.d.ts.map +1 -1
- package/out/adapters/wof/admin/json/region-codes.js +83 -0
- package/out/adapters/wof/admin/json/region-codes.js.map +1 -1
- package/out/adapters/wof/json-rows.d.ts.map +1 -1
- package/out/adapters/wof/json-rows.js +2 -2
- package/out/adapters/wof/json-rows.js.map +1 -1
- package/out/adapters.d.ts.map +1 -1
- package/out/adapters.js +2 -0
- package/out/adapters.js.map +1 -1
- package/out/build/align/range.d.ts +7 -3
- package/out/build/align/range.d.ts.map +1 -1
- package/out/build/align/range.js +17 -9
- package/out/build/align/range.js.map +1 -1
- package/out/build/align/totals.d.ts +12 -0
- package/out/build/align/totals.d.ts.map +1 -1
- package/out/build/align/totals.js +8 -0
- package/out/build/align/totals.js.map +1 -1
- package/out/build/align.d.ts +60 -5
- package/out/build/align.d.ts.map +1 -1
- package/out/build/align.js +136 -12
- package/out/build/align.js.map +1 -1
- package/out/build/budget.d.ts +35 -11
- package/out/build/budget.d.ts.map +1 -1
- package/out/build/budget.js +52 -20
- package/out/build/budget.js.map +1 -1
- package/out/build/checkpoint.d.ts +9 -0
- package/out/build/checkpoint.d.ts.map +1 -1
- package/out/build/checkpoint.js.map +1 -1
- package/out/build/component-check.d.ts +29 -1
- package/out/build/component-check.d.ts.map +1 -1
- package/out/build/component-check.js +57 -2
- package/out/build/component-check.js.map +1 -1
- package/out/build/inputs.d.ts +58 -0
- package/out/build/inputs.d.ts.map +1 -1
- package/out/build/inputs.js +57 -20
- package/out/build/inputs.js.map +1 -1
- package/out/build/manifest.d.ts.map +1 -1
- package/out/build/manifest.js +1 -0
- package/out/build/manifest.js.map +1 -1
- package/out/build/parallel.d.ts +19 -1
- package/out/build/parallel.d.ts.map +1 -1
- package/out/build/parallel.js +92 -11
- package/out/build/parallel.js.map +1 -1
- package/out/build/{region-names.d.ts → region/names.d.ts} +10 -1
- package/out/build/region/names.d.ts.map +1 -0
- package/out/build/{region-names.js → region/names.js} +16 -5
- package/out/build/region/names.js.map +1 -0
- package/out/build/region/recount.d.ts +47 -0
- package/out/build/region/recount.d.ts.map +1 -0
- package/out/build/region/recount.js +105 -0
- package/out/build/region/recount.js.map +1 -0
- package/out/build/reuse.d.ts +31 -0
- package/out/build/reuse.d.ts.map +1 -0
- package/out/build/reuse.js +50 -0
- package/out/build/reuse.js.map +1 -0
- package/out/build/settings.d.ts +38 -0
- package/out/build/settings.d.ts.map +1 -1
- package/out/build/settings.js +67 -3
- package/out/build/settings.js.map +1 -1
- package/out/build/source-record.d.ts +32 -7
- package/out/build/source-record.d.ts.map +1 -1
- package/out/build/source-record.js +17 -4
- package/out/build/source-record.js.map +1 -1
- package/out/build/types.d.ts +24 -0
- package/out/build/types.d.ts.map +1 -1
- package/out/build/worker.d.ts +17 -0
- package/out/build/worker.d.ts.map +1 -1
- package/out/build/worker.js +44 -9
- package/out/build/worker.js.map +1 -1
- package/out/build.d.ts.map +1 -1
- package/out/build.js +2 -1
- package/out/build.js.map +1 -1
- package/out/de/recipes/locale.d.ts.map +1 -1
- package/out/de/recipes/locale.js +9 -3
- package/out/de/recipes/locale.js.map +1 -1
- package/out/evaluation/corpus-adapter.d.ts +14 -0
- package/out/evaluation/corpus-adapter.d.ts.map +1 -1
- package/out/evaluation/corpus-adapter.js +2 -16
- package/out/evaluation/corpus-adapter.js.map +1 -1
- package/out/fi/adapters/ryhti/adapter.js +2 -2
- package/out/fi/adapters/ryhti/adapter.js.map +1 -1
- package/out/fo/adapters/adressur/adapter.js +2 -2
- package/out/fo/adapters/adressur/adapter.js.map +1 -1
- package/out/fr/recipes/lieudit.d.ts.map +1 -1
- package/out/fr/recipes/lieudit.js +3 -3
- package/out/fr/recipes/lieudit.js.map +1 -1
- package/out/in/street-line/segment.d.ts +75 -0
- package/out/in/street-line/segment.d.ts.map +1 -0
- package/out/in/street-line/segment.js +298 -0
- package/out/in/street-line/segment.js.map +1 -0
- package/out/international/recipes/locale.d.ts.map +1 -1
- package/out/international/recipes/locale.js +6 -3
- package/out/international/recipes/locale.js.map +1 -1
- package/out/li/adapters/llv/adapter.js +2 -2
- package/out/li/adapters/llv/adapter.js.map +1 -1
- package/out/lu/adapters/bd-adresses/adapter.js +2 -2
- package/out/lu/adapters/bd-adresses/adapter.js.map +1 -1
- package/out/no/adapters/matrikkelen/adapter.js +2 -2
- package/out/no/adapters/matrikkelen/adapter.js.map +1 -1
- package/out/parquet/streams.d.ts +9 -0
- package/out/parquet/streams.d.ts.map +1 -1
- package/out/parquet/streams.js +7 -3
- package/out/parquet/streams.js.map +1 -1
- package/out/parquet/writers.d.ts +55 -2
- package/out/parquet/writers.d.ts.map +1 -1
- package/out/parquet/writers.js +109 -27
- package/out/parquet/writers.js.map +1 -1
- package/out/recipes/country-balanced.d.ts.map +1 -1
- package/out/recipes/country-balanced.js +32 -15
- package/out/recipes/country-balanced.js.map +1 -1
- package/out/recipes/fragment-assay/build.d.ts +5 -2
- package/out/recipes/fragment-assay/build.d.ts.map +1 -1
- package/out/recipes/fragment-assay/build.js +8 -5
- package/out/recipes/fragment-assay/build.js.map +1 -1
- package/out/recipes/fragment-assay/rows.d.ts +2 -2
- package/out/recipes/fragment-assay/rows.js +4 -4
- package/out/recipes/fragment-assay/rows.js.map +1 -1
- package/out/recipes/house/venue.d.ts.map +1 -1
- package/out/recipes/house/venue.js +2 -1
- package/out/recipes/house/venue.js.map +1 -1
- package/out/recipes/postal/guideline/leg.d.ts.map +1 -1
- package/out/recipes/postal/guideline/leg.js +2 -7
- package/out/recipes/postal/guideline/leg.js.map +1 -1
- package/out/recipes/prominent/places.js +4 -4
- package/out/recipes/prominent/places.js.map +1 -1
- package/out/runner.d.ts +28 -0
- package/out/runner.d.ts.map +1 -1
- package/out/runner.js +85 -18
- package/out/runner.js.map +1 -1
- package/out/sg/recipes/register.d.ts.map +1 -1
- package/out/sg/recipes/register.js +6 -1
- package/out/sg/recipes/register.js.map +1 -1
- package/out/source-register/row-license.d.ts +8 -0
- package/out/source-register/row-license.d.ts.map +1 -1
- package/out/source-register/row-license.js +10 -2
- package/out/source-register/row-license.js.map +1 -1
- package/out/surfaces/corpus-row.d.ts +32 -0
- package/out/surfaces/corpus-row.d.ts.map +1 -0
- package/out/surfaces/corpus-row.js +70 -0
- package/out/surfaces/corpus-row.js.map +1 -0
- package/out/surfaces/locale.d.ts.map +1 -1
- package/out/surfaces/locale.js +16 -22
- package/out/surfaces/locale.js.map +1 -1
- package/out/synthesizers/house-venue.d.ts +9 -4
- package/out/synthesizers/house-venue.d.ts.map +1 -1
- package/out/synthesizers/house-venue.js +25 -35
- package/out/synthesizers/house-venue.js.map +1 -1
- package/out/synthesizers/no-street.js +2 -9
- package/out/synthesizers/no-street.js.map +1 -1
- package/out/synthesizers/po-box.js +3 -7
- package/out/synthesizers/po-box.js.map +1 -1
- package/out/synthesizers/tail.d.ts.map +1 -1
- package/out/synthesizers/tail.js +2 -2
- package/out/synthesizers/tail.js.map +1 -1
- package/out/synthesizers/utils.d.ts +20 -3
- package/out/synthesizers/utils.d.ts.map +1 -1
- package/out/synthesizers/utils.js +74 -57
- package/out/synthesizers/utils.js.map +1 -1
- package/out/test-kit.d.ts +11 -0
- package/out/test-kit.d.ts.map +1 -1
- package/out/test-kit.js +30 -1
- package/out/test-kit.js.map +1 -1
- package/out/tools/fetch/overture-places-in.d.ts +14 -0
- package/out/tools/fetch/overture-places-in.d.ts.map +1 -0
- package/out/tools/fetch/overture-places-in.js +82 -0
- package/out/tools/fetch/overture-places-in.js.map +1 -0
- package/out/tools/fetch/storage.d.ts +2 -0
- package/out/tools/fetch/storage.d.ts.map +1 -1
- package/out/tools/fetch/storage.js +3 -0
- package/out/tools/fetch/storage.js.map +1 -1
- package/out/tools/fetch.d.ts +2 -0
- package/out/tools/fetch.d.ts.map +1 -1
- package/out/tools/fetch.js +2 -0
- package/out/tools/fetch.js.map +1 -1
- package/out/tools/region-slot-census.run.js +2 -2
- package/out/types.d.ts +41 -0
- package/out/types.d.ts.map +1 -1
- package/out/types.js.map +1 -1
- package/out/us/adapters/state/tx-notaries/adapter.d.ts.map +1 -1
- package/out/us/adapters/state/tx-notaries/adapter.js +2 -1
- package/out/us/adapters/state/tx-notaries/adapter.js.map +1 -1
- package/out/us/adapters/usgov/imls-pls/adapter.d.ts.map +1 -1
- package/out/us/adapters/usgov/imls-pls/adapter.js +2 -1
- package/out/us/adapters/usgov/imls-pls/adapter.js.map +1 -1
- package/out/us/adapters/usgov/nad/adapter.d.ts +15 -0
- package/out/us/adapters/usgov/nad/adapter.d.ts.map +1 -1
- package/out/us/adapters/usgov/nad/adapter.js +21 -3
- package/out/us/adapters/usgov/nad/adapter.js.map +1 -1
- package/out/us/adapters/usgov/nad/address-key.d.ts +1 -5
- package/out/us/adapters/usgov/nad/address-key.d.ts.map +1 -1
- package/out/us/adapters/usgov/nad/address-key.js +8 -33
- package/out/us/adapters/usgov/nad/address-key.js.map +1 -1
- package/out/us/adapters/usgov/nppes/adapter.d.ts.map +1 -1
- package/out/us/adapters/usgov/nppes/adapter.js +2 -1
- package/out/us/adapters/usgov/nppes/adapter.js.map +1 -1
- package/out/utils/address-key.d.ts +23 -0
- package/out/utils/address-key.d.ts.map +1 -0
- package/out/utils/address-key.js +43 -0
- package/out/utils/address-key.js.map +1 -0
- package/out/utils/align.d.ts +7 -0
- package/out/utils/align.d.ts.map +1 -1
- package/out/utils/align.js +18 -8
- package/out/utils/align.js.map +1 -1
- package/out/utils/evaluation-groups.d.ts +5 -1
- package/out/utils/evaluation-groups.d.ts.map +1 -1
- package/out/utils/evaluation-groups.js +12 -1
- package/out/utils/evaluation-groups.js.map +1 -1
- package/out/utils/split.d.ts +11 -0
- package/out/utils/split.d.ts.map +1 -1
- package/out/utils/split.js +18 -3
- package/out/utils/split.js.map +1 -1
- package/package.json +19 -19
- package/out/build/region-names.d.ts.map +0 -1
- package/out/build/region-names.js.map +0 -1
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
*/
|
|
124
124
|
|
|
125
125
|
import { ConventionClaimID, ObservationStance } from "@mailwoman/codex/address/convention-claims"
|
|
126
|
-
import {
|
|
126
|
+
import { scriptOfComponents } from "@mailwoman/codex/address/format"
|
|
127
127
|
import { conventionClaimForCountry, layoutForCountry } from "@mailwoman/codex/address/layouts"
|
|
128
128
|
import { CountryISO2 } from "@mailwoman/codex/country/codes"
|
|
129
129
|
import { matchCountry } from "@mailwoman/codex/country/country"
|
|
@@ -139,6 +139,7 @@ import { joinRepetitionIndex } from "#adapters/street/repetition"
|
|
|
139
139
|
import { createUnitSplitter, type UnitSplitter } from "#adapters/street/unit"
|
|
140
140
|
import { SourceRegister } from "#registers"
|
|
141
141
|
import { streetIndexOpener } from "#street-index/reader"
|
|
142
|
+
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
142
143
|
import {
|
|
143
144
|
AddressRole,
|
|
144
145
|
type AdapterOptions,
|
|
@@ -609,7 +610,7 @@ export function readCORDISRecord(
|
|
|
609
610
|
// That keeps a country's local order whenever its Latin order has fewer slots:
|
|
610
611
|
// `Weixing Road` and `Changchun` would otherwise print run together in China's
|
|
611
612
|
// Han-script line, with no separator between them.
|
|
612
|
-
const rendered =
|
|
613
|
+
const rendered = formatCorpusRow(components, country, {
|
|
613
614
|
singleLine: true,
|
|
614
615
|
script: scriptOfComponents(components, country),
|
|
615
616
|
})
|
|
@@ -91,12 +91,26 @@
|
|
|
91
91
|
* when it holds a letter, as `Suite 4` does.
|
|
92
92
|
* A bare number there would render as a second house number.
|
|
93
93
|
*
|
|
94
|
+
* Where the split refuses a line as `street-number-unplaced` or `street-line-segmented`,
|
|
95
|
+
* a country with its own street-line reader (`streetLineReaderFor`) reads the line instead.
|
|
96
|
+
* India's reader labels `NO. 1034, 3RD FLOOR, 1ST MAIN ROAD` as the premise
|
|
97
|
+
* number `1034` and the street `1ST MAIN ROAD`.
|
|
98
|
+
*
|
|
99
|
+
* A reading that needs a building name is refused, because the legal name holds the row's `venue`.
|
|
100
|
+
*
|
|
94
101
|
* ## Region
|
|
95
102
|
*
|
|
96
103
|
* `Region` is an ISO 3166-2 code such as `SK-KI`, which isn't how an address writes the region.
|
|
97
|
-
* It reaches a row
|
|
104
|
+
* It reaches a row as the form the country's addresses write for it.
|
|
105
|
+
*
|
|
106
|
+
* `matchSubdivisionIn` answers for the United States, Canada and Australia, where addresses write the code.
|
|
107
|
+
* For every other country, `citedSubdivisionForISO` reads the libaddressinput key
|
|
108
|
+
* listed beside the ISO id: `IN-MH` becomes `Maharashtra`.
|
|
98
109
|
*
|
|
99
|
-
*
|
|
110
|
+
* It answers only where the country's codex layout prints a region and its primary citation writes
|
|
111
|
+
* one of those keys in an example, because libaddressinput is a dataset rather than a citation.
|
|
112
|
+
*
|
|
113
|
+
* Any other country gets no region.
|
|
100
114
|
* A code whose country prefix differs from `Country` refuses the address as contradicting it.
|
|
101
115
|
*
|
|
102
116
|
* ## One row per address
|
|
@@ -123,13 +137,17 @@ import { Globerator } from "spliterator/node/fs"
|
|
|
123
137
|
|
|
124
138
|
import { UnsupportedCountryError } from "#adapters/errors"
|
|
125
139
|
import { stableSourceID } from "#adapters/source-id"
|
|
140
|
+
import { withConventionStreet } from "#adapters/street/convention"
|
|
141
|
+
import { type CountryStreetLineContext, streetLineReaderFor } from "#adapters/street/country-line"
|
|
126
142
|
import { splitStreetLine, splitTrailingStreetLine } from "#adapters/street/line"
|
|
127
143
|
import { joinRepetitionIndex, withoutRepetitionIndex } from "#adapters/street/repetition"
|
|
128
144
|
import { createUnitSplitter, type UnitSplitter } from "#adapters/street/unit"
|
|
145
|
+
import { citedSubdivisionForISO } from "#adapters/wof/admin/json/region-codes"
|
|
129
146
|
import { FingerprintSet } from "#fingerprints"
|
|
130
147
|
import { isPlaceholderValue } from "#it/adapters/anac/adapter"
|
|
131
148
|
import { SourceRegister } from "#registers"
|
|
132
149
|
import { streetIndexOpener } from "#street-index/reader"
|
|
150
|
+
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
133
151
|
import {
|
|
134
152
|
AddressRole,
|
|
135
153
|
type AdapterOptions,
|
|
@@ -345,7 +363,15 @@ export type GLEIFRecord = Readonly<Record<string, string | undefined>>
|
|
|
345
363
|
/**
|
|
346
364
|
* What one address block yielded: a row, or the reason it yielded none.
|
|
347
365
|
*/
|
|
348
|
-
export type GLEIFAddressReading =
|
|
366
|
+
export type GLEIFAddressReading =
|
|
367
|
+
| {
|
|
368
|
+
readonly admitted: CanonicalRow
|
|
369
|
+
/**
|
|
370
|
+
* Whether the country's own street-line reader read the line after the generic split refused it.
|
|
371
|
+
*/
|
|
372
|
+
readonly byCountryReader: boolean
|
|
373
|
+
}
|
|
374
|
+
| { readonly refused: GLEIFRefusal }
|
|
349
375
|
|
|
350
376
|
/**
|
|
351
377
|
* The address fields a block holds, in the order the CDF lists them.
|
|
@@ -577,6 +603,10 @@ export function readGLEIFAddress(
|
|
|
577
603
|
}
|
|
578
604
|
|
|
579
605
|
const script = scriptOfComponents({ street: line, locality: city }, country)
|
|
606
|
+
const regionSuffix = regionCode ? regionCode.slice(country.length + 1) : ""
|
|
607
|
+
const codedRegion = regionSuffix && matchSubdivisionIn(country, regionSuffix) ? regionSuffix : null
|
|
608
|
+
const lookedUpRegion = regionSuffix && !codedRegion ? citedSubdivisionForISO(country, regionSuffix) : null
|
|
609
|
+
let byCountryReader = false
|
|
580
610
|
|
|
581
611
|
if (PO_BOX_LINE.test(line)) {
|
|
582
612
|
components.po_box = line
|
|
@@ -592,20 +622,27 @@ export function readGLEIFAddress(
|
|
|
592
622
|
script
|
|
593
623
|
)
|
|
594
624
|
|
|
595
|
-
if ("refused" in placed)
|
|
625
|
+
if ("refused" in placed) {
|
|
626
|
+
const read = readByCountryReader(placed.refused, line, country, { locality: city, region: lookedUpRegion })
|
|
596
627
|
|
|
597
|
-
|
|
598
|
-
components.house_number = placed.house_number
|
|
599
|
-
}
|
|
628
|
+
if (!read) return placed
|
|
600
629
|
|
|
601
|
-
|
|
630
|
+
Object.assign(components, read)
|
|
631
|
+
byCountryReader = true
|
|
632
|
+
} else {
|
|
633
|
+
if (placed.house_number) {
|
|
634
|
+
components.house_number = placed.house_number
|
|
635
|
+
}
|
|
602
636
|
|
|
603
|
-
|
|
637
|
+
components.street = placed.street
|
|
604
638
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
639
|
+
const unit = addressField(record, block, "AddressNumberWithinBuilding")
|
|
640
|
+
|
|
641
|
+
if (lineUnit) {
|
|
642
|
+
components.unit = lineUnit.unit
|
|
643
|
+
} else if (unit && /\p{L}/u.test(unit) && !unit.includes(",") && !line.includes(unit)) {
|
|
644
|
+
components.unit = unit
|
|
645
|
+
}
|
|
609
646
|
}
|
|
610
647
|
}
|
|
611
648
|
|
|
@@ -617,15 +654,13 @@ export function readGLEIFAddress(
|
|
|
617
654
|
|
|
618
655
|
components.locality = city
|
|
619
656
|
|
|
620
|
-
|
|
621
|
-
const suffix = regionCode.slice(country.length + 1)
|
|
657
|
+
const region = codedRegion ?? lookedUpRegion
|
|
622
658
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
}
|
|
659
|
+
if (region) {
|
|
660
|
+
components.region = region
|
|
626
661
|
}
|
|
627
662
|
|
|
628
|
-
const rendered =
|
|
663
|
+
const rendered = formatCorpusRow(withConventionStreet(components, country), country, { singleLine: true, script })
|
|
629
664
|
|
|
630
665
|
if (!rendered) return { refused: GLEIFRefusal.Unrenderable }
|
|
631
666
|
|
|
@@ -635,16 +670,57 @@ export function readGLEIFAddress(
|
|
|
635
670
|
return { refused: GLEIFRefusal.ComponentsTooFew }
|
|
636
671
|
}
|
|
637
672
|
|
|
673
|
+
// A region read through `citedSubdivisionForISO` stays out of the id, so a row built
|
|
674
|
+
// before that lookup existed keeps the id the evaluation groups hold it under.
|
|
675
|
+
const { region: _region, ...withoutLookedUpRegion } = aligned
|
|
676
|
+
const identity = lookedUpRegion ? withoutLookedUpRegion : aligned
|
|
677
|
+
|
|
638
678
|
return {
|
|
639
679
|
admitted: {
|
|
640
680
|
raw,
|
|
641
681
|
components: aligned,
|
|
642
682
|
country,
|
|
643
683
|
source: GLEIF_ADAPTER_ID,
|
|
644
|
-
source_id: stableSourceID(GLEIF_ADAPTER_ID, { country, ...
|
|
684
|
+
source_id: stableSourceID(GLEIF_ADAPTER_ID, { country, ...identity }),
|
|
645
685
|
license: GLEIF_LICENSE,
|
|
646
686
|
addressRole: block === GLEIFAddressBlock.Legal ? AddressRole.RegisteredOffice : AddressRole.Facility,
|
|
647
687
|
},
|
|
688
|
+
byCountryReader,
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* The refusals of the generic split that a country's own street-line reader may still read:
|
|
694
|
+
* a digit the split couldn't place, and a line that joins several comma-separated parts.
|
|
695
|
+
*/
|
|
696
|
+
const COUNTRY_READER_REFUSALS: ReadonlySet<GLEIFRefusal> = new Set([
|
|
697
|
+
GLEIFRefusal.StreetNumberUnplaced,
|
|
698
|
+
GLEIFRefusal.StreetLineSegmented,
|
|
699
|
+
])
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Read a line the generic split refused through the country's own street-line reader
|
|
703
|
+
* (`streetLineReaderFor`), or return `null` when the country has none or the reader refuses it too.
|
|
704
|
+
*
|
|
705
|
+
* A line whose reading needs a building name is refused as well, because the entity's
|
|
706
|
+
* legal name already holds the row's one `venue` slot.
|
|
707
|
+
*/
|
|
708
|
+
function readByCountryReader(
|
|
709
|
+
refusal: GLEIFRefusal,
|
|
710
|
+
line: string,
|
|
711
|
+
country: string,
|
|
712
|
+
context: CountryStreetLineContext
|
|
713
|
+
): Pick<CanonicalRow["components"], "house_number" | "street" | "dependent_locality"> | null {
|
|
714
|
+
if (!COUNTRY_READER_REFUSALS.has(refusal)) return null
|
|
715
|
+
|
|
716
|
+
const read = streetLineReaderFor(country)?.(line, context)
|
|
717
|
+
|
|
718
|
+
if (!read || "refused" in read || read.building) return null
|
|
719
|
+
|
|
720
|
+
return {
|
|
721
|
+
...(read.house_number ? { house_number: read.house_number } : {}),
|
|
722
|
+
street: read.street,
|
|
723
|
+
...(read.dependent_locality ? { dependent_locality: read.dependent_locality } : {}),
|
|
648
724
|
}
|
|
649
725
|
}
|
|
650
726
|
|
|
@@ -780,6 +856,8 @@ export function createGLEIFAdapter(): CorpusAdapter {
|
|
|
780
856
|
const units = await createUnitSplitter({ streetIndex: streetIndexOpener(opts.streetIndex) })
|
|
781
857
|
let count = 0
|
|
782
858
|
let checkedHeader = false
|
|
859
|
+
// The rows a country's street-line reader read, held in memory: 12,722 for India over the 2026-10-03 golden copy.
|
|
860
|
+
const countryReaderRows: CanonicalRow[] = []
|
|
783
861
|
|
|
784
862
|
for await (const record of readGLEIFRecords(opts.inputPath)) {
|
|
785
863
|
if (opts.signal?.aborted) break
|
|
@@ -822,6 +900,12 @@ export function createGLEIFAdapter(): CorpusAdapter {
|
|
|
822
900
|
|
|
823
901
|
if (wanted && row.country !== wanted) continue
|
|
824
902
|
|
|
903
|
+
if (reading.byCountryReader) {
|
|
904
|
+
countryReaderRows.push(row)
|
|
905
|
+
|
|
906
|
+
continue
|
|
907
|
+
}
|
|
908
|
+
|
|
825
909
|
if (!emitted.add(addressKey(row))) {
|
|
826
910
|
countDropped(opts, "row:address-already-emitted")
|
|
827
911
|
|
|
@@ -833,6 +917,25 @@ export function createGLEIFAdapter(): CorpusAdapter {
|
|
|
833
917
|
count++
|
|
834
918
|
}
|
|
835
919
|
}
|
|
920
|
+
|
|
921
|
+
// A row a country's reader read is held until every row of the generic split has
|
|
922
|
+
// claimed its address, so it never takes the address of a row that corpora built
|
|
923
|
+
// before the reader existed already hold.
|
|
924
|
+
for (const row of countryReaderRows) {
|
|
925
|
+
if (opts.signal?.aborted) break
|
|
926
|
+
|
|
927
|
+
if (typeof opts.limit === "number" && count >= opts.limit) break
|
|
928
|
+
|
|
929
|
+
if (!emitted.add(addressKey(row))) {
|
|
930
|
+
countDropped(opts, "row:address-already-emitted")
|
|
931
|
+
|
|
932
|
+
continue
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
yield row
|
|
936
|
+
|
|
937
|
+
count++
|
|
938
|
+
}
|
|
836
939
|
},
|
|
837
940
|
}
|
|
838
941
|
}
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
* The adapter omits that field because mapping it would inflate alignment quarantine.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import { formatAddressRow } from "@mailwoman/codex/address/format"
|
|
17
16
|
import { tryParsingJSON } from "@mailwoman/core/values/json"
|
|
18
17
|
import { createLicenseVerdictCache, LicensePolicy } from "@mailwoman/license/policy"
|
|
19
18
|
import { TextSpliterator } from "spliterator"
|
|
20
19
|
|
|
21
20
|
import { stableSourceID } from "#adapters/source-id"
|
|
22
21
|
import { SourceRegister } from "#registers"
|
|
22
|
+
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
23
23
|
import { AddressRole, type AdapterOptions, type CanonicalRow, type CorpusAdapter, SurfaceOrigin } from "#types"
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -209,7 +209,7 @@ export function createOpenaddressesAdapter(opts: OpenaddressesAdapterOptions = {
|
|
|
209
209
|
components.postcode = postcode
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
const rendered =
|
|
212
|
+
const rendered = formatCorpusRow(components, country, { singleLine: true })
|
|
213
213
|
|
|
214
214
|
if (!rendered) continue
|
|
215
215
|
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
* That's why `defaultLicense` isn't an option on this adapter.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import { formatAddressRow } from "@mailwoman/codex/address/format"
|
|
15
14
|
import type { ComponentTag } from "@mailwoman/codex/component"
|
|
16
15
|
import { countryDisplayNames } from "@mailwoman/codex/country/display-names"
|
|
16
|
+
import { countriesDeclaredBy, hasCountry } from "@mailwoman/codex/country/sets"
|
|
17
17
|
import { sha256Hex } from "@mailwoman/core/crypto/hash"
|
|
18
18
|
import { extractDelimited } from "@mailwoman/core/scripting/arguments"
|
|
19
19
|
import { tryParsingJSON } from "@mailwoman/core/values/json"
|
|
@@ -24,6 +24,7 @@ import { TextSpliterator } from "spliterator"
|
|
|
24
24
|
import { OSM_LICENSE } from "#adapters/osm/license"
|
|
25
25
|
import { stableSourceID } from "#adapters/source-id"
|
|
26
26
|
import { SourceRegister } from "#registers"
|
|
27
|
+
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
27
28
|
import {
|
|
28
29
|
AddressRole,
|
|
29
30
|
type AdapterOptions,
|
|
@@ -111,6 +112,23 @@ interface OSMCorpusRow {
|
|
|
111
112
|
|
|
112
113
|
const MAX_STREET_WORDS = 8
|
|
113
114
|
|
|
115
|
+
/**
|
|
116
|
+
* The countries whose mappers write the raion that contains the settlement in `addr:district`.
|
|
117
|
+
*
|
|
118
|
+
* Over the October 2026 extracts, every Moldovan `addr:district` value spans more than
|
|
119
|
+
* three settlements (880,282 rows: `Raionul Ialoveni`, `Municipiul Chișinău`).
|
|
120
|
+
* The Russian and Belarusian values do so on 182,210 and 3,042 rows (`Аксайский район`, `Кобрынскі раён`).
|
|
121
|
+
*
|
|
122
|
+
* In other countries the tag holds a part of the city: `Hoàn Kiếm` in Hà Nội,
|
|
123
|
+
* `越秀区` in 广州, `Արաբկիր` in Yerevan.
|
|
124
|
+
* A count of distinct settlements can't separate the two by itself.
|
|
125
|
+
*
|
|
126
|
+
* A city written several ways spans several names too (`黄浦区` under five spellings of Shanghai).
|
|
127
|
+
*/
|
|
128
|
+
// country-branch: what `addr:district` denotes is a per-country mapping convention of OpenStreetMap.
|
|
129
|
+
// A WOF ancestry lookup of the district's name above the row's locality would replace this list.
|
|
130
|
+
const OSM_DISTRICT_CONTAINS_LOCALITY = countriesDeclaredBy("OSM addr:district raion convention", ["BY", "MD", "RU"])
|
|
131
|
+
|
|
114
132
|
/**
|
|
115
133
|
* Whether `addr:housenumber` holds a street designator — digits with an optional letter,
|
|
116
134
|
* fraction or dash suffix (`12`, `188a`, `14/E`, `1/1146`, `167-c`) or a one-
|
|
@@ -120,9 +138,31 @@ const MAX_STREET_WORDS = 8
|
|
|
120
138
|
export function housenumberIsDesignator(value: string): boolean {
|
|
121
139
|
const trimmed = value.trim()
|
|
122
140
|
|
|
141
|
+
if (longestDigitRun(trimmed) > MAX_HOUSE_NUMBER_DIGITS) return false
|
|
142
|
+
|
|
123
143
|
return /^\d+[A-Za-z]?(?:[/-]\d*[A-Za-z]?)?$/u.test(trimmed) || /^[A-Za-z]{1,2}[-\s]?\d+[A-Za-z]?$/u.test(trimmed)
|
|
124
144
|
}
|
|
125
145
|
|
|
146
|
+
/**
|
|
147
|
+
* The most digits in a row a house number holds.
|
|
148
|
+
*
|
|
149
|
+
* The longest the national registers write are six, the rural grid numbers of the US
|
|
150
|
+
* National Address Database (`129504 US 65 Highway North, Gould, AR`).
|
|
151
|
+
* A run of seven or more in `addr:housenumber` is a telephone number
|
|
152
|
+
* (`22796800` in Costa Rica, `07505156040` in Iraq) or a postcode, in every country's extract alike.
|
|
153
|
+
*/
|
|
154
|
+
const MAX_HOUSE_NUMBER_DIGITS = 6
|
|
155
|
+
|
|
156
|
+
function longestDigitRun(value: string): number {
|
|
157
|
+
let longest = 0
|
|
158
|
+
|
|
159
|
+
for (const run of value.match(/\d+/gu) ?? []) {
|
|
160
|
+
longest = Math.max(longest, run.length)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return longest
|
|
164
|
+
}
|
|
165
|
+
|
|
126
166
|
/**
|
|
127
167
|
* Whether `addr:street` matches the street-name shape.
|
|
128
168
|
*
|
|
@@ -259,10 +299,26 @@ export function componentsForOSMRow(
|
|
|
259
299
|
}
|
|
260
300
|
}
|
|
261
301
|
|
|
302
|
+
// Where `addr:district` holds the raion that contains the locality, it is the locality's `subregion`.
|
|
303
|
+
// The country's layout then places it, or drops it and counts the drop.
|
|
304
|
+
const district = clean(row.district)
|
|
305
|
+
const districtContainsLocality = hasCountry(OSM_DISTRICT_CONTAINS_LOCALITY, country)
|
|
306
|
+
|
|
307
|
+
if (district && districtContainsLocality && (!components.locality || !sameName(district, components.locality))) {
|
|
308
|
+
components.subregion = district
|
|
309
|
+
}
|
|
310
|
+
|
|
262
311
|
// Dependent-locality candidates in priority order (suburb, subdistrict, district, place,
|
|
263
312
|
// city head, then the containing boundary's name); `district` never becomes `region`,
|
|
264
313
|
// because Vietnam's country template renders it only when no city is present.
|
|
265
|
-
const dependent = [
|
|
314
|
+
const dependent = [
|
|
315
|
+
row.suburb,
|
|
316
|
+
row.subdistrict,
|
|
317
|
+
districtContainsLocality ? null : row.district,
|
|
318
|
+
row.place,
|
|
319
|
+
split?.head,
|
|
320
|
+
row.boundary_dependent_locality,
|
|
321
|
+
]
|
|
266
322
|
.map((value) => clean(value))
|
|
267
323
|
.find(
|
|
268
324
|
(value) =>
|
|
@@ -292,7 +348,9 @@ export function componentsForOSMRow(
|
|
|
292
348
|
|
|
293
349
|
// An address row needs another component alongside the street or the streetless house number.
|
|
294
350
|
// Coarse adapters already teach bare names.
|
|
295
|
-
|
|
351
|
+
// A subregion doesn't count.
|
|
352
|
+
// The layouts of the countries that write one in `addr:district` print none.
|
|
353
|
+
if (Object.keys(components).filter((tag) => tag !== "subregion").length === 1) {
|
|
296
354
|
countDropped(tally, street ? "row:street-only" : "row:house-number-only")
|
|
297
355
|
|
|
298
356
|
return null
|
|
@@ -378,7 +436,7 @@ export function createOSMAdapter(): CorpusAdapter {
|
|
|
378
436
|
|
|
379
437
|
if (!components) continue
|
|
380
438
|
|
|
381
|
-
const rendered =
|
|
439
|
+
const rendered = formatCorpusRow(components, country, { singleLine: true })
|
|
382
440
|
|
|
383
441
|
if (!rendered) {
|
|
384
442
|
countDropped(opts, "row:render-failed")
|
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
* The downstream affix-relabel step splits `street_prefix` from that value.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { CA_PROVINCES } from "@mailwoman/codex/ca/province"
|
|
12
|
+
import { countryRenderForms } from "@mailwoman/codex/country"
|
|
13
|
+
import { writtenPostcode } from "@mailwoman/codex/labels/postcode/written-groups"
|
|
14
|
+
import { mxStatePostalAbbreviation } from "@mailwoman/codex/mx/state"
|
|
13
15
|
import { sample } from "@mailwoman/core/math/random"
|
|
14
16
|
import { mulberry32 as makeMulberry32 } from "@mailwoman/core/utils"
|
|
15
17
|
import { tryParsingJSON } from "@mailwoman/core/values/json"
|
|
@@ -17,12 +19,19 @@ import { TextSpliterator } from "spliterator"
|
|
|
17
19
|
|
|
18
20
|
import { stableSourceID } from "#adapters/source-id"
|
|
19
21
|
import { SourceRegister } from "#registers"
|
|
22
|
+
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
20
23
|
import { AddressRole, type AdapterOptions, type CanonicalRow, type CorpusAdapter, SurfaceOrigin } from "#types"
|
|
21
24
|
|
|
22
25
|
/**
|
|
23
26
|
* Registry id stamped into every row this adapter emits, so a corpus record traces back to its dataset.
|
|
24
27
|
*/
|
|
25
28
|
export const OVERTURE_ADAPTER_ID = "overture"
|
|
29
|
+
/**
|
|
30
|
+
* The `source` the Brazilian, Mexican and Canadian runs of this adapter
|
|
31
|
+
* stamp on their rows (`corpus run overture --source-name overture-latam`),
|
|
32
|
+
* which training configs weight apart from `overture`.
|
|
33
|
+
*/
|
|
34
|
+
export const OVERTURE_LATAM_SOURCE = "overture-latam"
|
|
26
35
|
/**
|
|
27
36
|
* License assigned by this source (`cdla-Permissive-2.0`, attribution-only
|
|
28
37
|
* rather than share-alike), attached to every row.
|
|
@@ -32,15 +41,15 @@ export const OVERTURE_DEFAULT_LICENSE = "CDLA-Permissive-2.0"
|
|
|
32
41
|
const DEFAULT_COUNTRY_SEED = 20_260_922
|
|
33
42
|
|
|
34
43
|
/**
|
|
35
|
-
* One attested written form of a country's name.
|
|
44
|
+
* One attested written form of a country's name, never a two-letter code (`countryRenderForms`).
|
|
36
45
|
*
|
|
37
46
|
* Raises rather than returning empty when the codex has no entry, so a requested
|
|
38
47
|
* fraction cannot silently produce no country rows.
|
|
39
48
|
*/
|
|
40
49
|
function countrySurfaceForm(country: string, random: () => number): string {
|
|
41
|
-
const forms =
|
|
50
|
+
const forms = countryRenderForms(country)
|
|
42
51
|
|
|
43
|
-
if (!forms
|
|
52
|
+
if (!forms.length) {
|
|
44
53
|
throw new Error(
|
|
45
54
|
`No COUNTRY_SURFACE_FORMS entry for ${country} — add it to codex/country/country.ts before using --country-fraction`
|
|
46
55
|
)
|
|
@@ -50,14 +59,77 @@ function countrySurfaceForm(country: string, random: () => number): string {
|
|
|
50
59
|
}
|
|
51
60
|
|
|
52
61
|
/**
|
|
53
|
-
* The flattened per-row shape
|
|
62
|
+
* The flattened per-row shape `mailwoman gazetteer overture-ingest --corpus-jsonl` emits.
|
|
63
|
+
*
|
|
64
|
+
* `region` is Overture's first address level.
|
|
65
|
+
* A file written before the ingest emitted it has none.
|
|
54
66
|
*/
|
|
55
67
|
interface OvertureCorpusRow {
|
|
56
|
-
street?: string
|
|
57
|
-
number?: string
|
|
58
|
-
unit?: string
|
|
59
|
-
postcode?: string
|
|
60
|
-
locality?: string
|
|
68
|
+
street?: string | null
|
|
69
|
+
number?: string | null
|
|
70
|
+
unit?: string | null
|
|
71
|
+
postcode?: string | null
|
|
72
|
+
locality?: string | null
|
|
73
|
+
region?: string | null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* What Overture's `unit` field holds in a country where it isn't a secondary unit.
|
|
78
|
+
*
|
|
79
|
+
* - `orientation-number`: the street number (`číslo orientační`) of a building whose
|
|
80
|
+
* `number` is its district-wide descriptive number (`číslo popisné`).
|
|
81
|
+
* The two are written `descriptive/orientation`.
|
|
82
|
+
* - `number-suffix`: a letter written against the house number.
|
|
83
|
+
*/
|
|
84
|
+
type OvertureUnitFieldRole = "orientation-number" | "number-suffix"
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The role of Overture's `unit` field in each country where it isn't a secondary unit.
|
|
88
|
+
*
|
|
89
|
+
* Read off the 2026-06-17.0 per-country corpus JSONL: every filled Czech `unit` is digits
|
|
90
|
+
* beside a digit `number` (101,127 of 394,880 rows, such as `Nad Stadiónem` `320` `28`),
|
|
91
|
+
* and in the first 400,000 German rows 17,250 of the 17,304 filled ones are one
|
|
92
|
+
* or two letters (`Neutrale Straße` `28` `a`).
|
|
93
|
+
*/
|
|
94
|
+
const OVERTURE_UNIT_FIELD_ROLES: Readonly<Record<string, OvertureUnitFieldRole>> = {
|
|
95
|
+
// UPU, Czech Rep. (02/2018): `The street number often consists of two numbers separated by a slash.
|
|
96
|
+
// The first number is a unique district-related building number [...], the second number is the
|
|
97
|
+
// street number`, as in `Hrušovská 455/10`.
|
|
98
|
+
CZ: "orientation-number",
|
|
99
|
+
// UPU, Germany (01/2015): `Wacholderweg 52a`.
|
|
100
|
+
DE: "number-suffix",
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The house number with the `unit` field joined into it as the country's role for that
|
|
105
|
+
* field states, or `null` when the field doesn't belong in the number.
|
|
106
|
+
*/
|
|
107
|
+
function joinUnitIntoNumber(number: string, unit: string, role: OvertureUnitFieldRole | null): string | null {
|
|
108
|
+
if (!role || !/^\d/u.test(number)) return null
|
|
109
|
+
|
|
110
|
+
if (role === "orientation-number") return /^\d+\p{Letter}?$/u.test(unit) ? `${number}/${unit}` : null
|
|
111
|
+
|
|
112
|
+
return /^\p{Letter}{1,2}$/u.test(unit) ? `${number}${unit}` : null
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* How a region value in Overture's first address level becomes the form the country's
|
|
117
|
+
* operator prints, for each country where Overture's value can be read as that form.
|
|
118
|
+
*
|
|
119
|
+
* A country absent here renders no region from Overture.
|
|
120
|
+
* Its first level is a unit the operator doesn't print: Italy's is `Sardegna`,
|
|
121
|
+
* where the operator prints the province `RM`.
|
|
122
|
+
*/
|
|
123
|
+
const OVERTURE_REGION_FORMS: Readonly<Record<string, (value: string) => string | null>> = {
|
|
124
|
+
// UPU, Brazil (03/2012): `The state abbreviation (two characters) must follow the town's name separated
|
|
125
|
+
// by a dash`, as in `GUARAPUAVA – PR`. Overture writes the two-letter UF (`RS`).
|
|
126
|
+
BR: (value) => (/^[A-Z]{2}$/u.test(value) ? value : null),
|
|
127
|
+
// UPU, Canada (09/2014): `MONTREAL QC H3Z 2Y7`, `QC is the province abbreviation`.
|
|
128
|
+
// Overture writes the ISO 3166-2:CA code, and the code is that abbreviation.
|
|
129
|
+
CA: (value) => (Object.hasOwn(CA_PROVINCES, value) ? value : null),
|
|
130
|
+
// UPU, Mexico (03/2017): `02860 MEXICO, CDMX`.
|
|
131
|
+
// Overture writes the state's name (`Michoacán de Ocampo`).
|
|
132
|
+
MX: mxStatePostalAbbreviation,
|
|
61
133
|
}
|
|
62
134
|
|
|
63
135
|
/**
|
|
@@ -106,6 +178,9 @@ export function createOvertureAdapter(): CorpusAdapter {
|
|
|
106
178
|
const country = opts.country
|
|
107
179
|
const countryFraction = opts.countryFraction ?? 0
|
|
108
180
|
const random = makeMulberry32(opts.seed ?? DEFAULT_COUNTRY_SEED)
|
|
181
|
+
const code = country.toUpperCase()
|
|
182
|
+
const unitRole = Object.hasOwn(OVERTURE_UNIT_FIELD_ROLES, code) ? OVERTURE_UNIT_FIELD_ROLES[code]! : null
|
|
183
|
+
const regionForm = Object.hasOwn(OVERTURE_REGION_FORMS, code) ? OVERTURE_REGION_FORMS[code]! : null
|
|
109
184
|
|
|
110
185
|
// The path string lets `TextSpliterator` own and dispose the file handle, including on an early `break`.
|
|
111
186
|
const lines = TextSpliterator.fromAsync(opts.inputPath)
|
|
@@ -133,33 +208,40 @@ export function createOvertureAdapter(): CorpusAdapter {
|
|
|
133
208
|
if (!postcode && !locality) continue
|
|
134
209
|
|
|
135
210
|
const components: CanonicalRow["components"] = {}
|
|
211
|
+
const joined = unit ? joinUnitIntoNumber(number, unit, unitRole) : null
|
|
136
212
|
|
|
137
213
|
// Overture "S-N" / "S/N" = sin número; only keep a real numeric house number.
|
|
138
214
|
if (/^\d/.test(number)) {
|
|
139
|
-
components.house_number = number
|
|
215
|
+
components.house_number = joined ?? number
|
|
140
216
|
}
|
|
141
217
|
|
|
142
218
|
components.street = street
|
|
143
219
|
|
|
144
|
-
if (unitFieldIsDesignator(unit)) {
|
|
220
|
+
if (!joined && unitFieldIsDesignator(unit)) {
|
|
145
221
|
components.unit = unit
|
|
146
222
|
}
|
|
147
223
|
|
|
148
224
|
if (postcode) {
|
|
149
|
-
components.postcode = postcode
|
|
225
|
+
components.postcode = writtenPostcode(postcode, country)
|
|
150
226
|
}
|
|
151
227
|
|
|
152
228
|
if (locality) {
|
|
153
229
|
components.locality = locality
|
|
154
230
|
}
|
|
155
231
|
|
|
232
|
+
const region = regionForm && r.region?.trim() ? regionForm(r.region.trim()) : null
|
|
233
|
+
|
|
234
|
+
if (region) {
|
|
235
|
+
components.region = region
|
|
236
|
+
}
|
|
237
|
+
|
|
156
238
|
// Overture rows are country-implicit, so the surface form goes into `components`
|
|
157
239
|
// and each country's layout decides where the country lands in the rendered string.
|
|
158
240
|
if (countryFraction > 0 && random() < countryFraction) {
|
|
159
241
|
components.country = countrySurfaceForm(country, random)
|
|
160
242
|
}
|
|
161
243
|
|
|
162
|
-
const rendered =
|
|
244
|
+
const rendered = formatCorpusRow(components, country, { singleLine: true })
|
|
163
245
|
|
|
164
246
|
if (!rendered) continue
|
|
165
247
|
|