@mailwoman/corpus 11.3.0 → 11.5.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 +12 -4
- package/data/builds/v0.8.22-nz-overlay/OVERLAY_PLAN.json +19 -0
- 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 +14 -1
- 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/data/training-configs/v8.14.0-base-c6-wofreps-cursor-v0822-s42.yaml +926 -0
- package/data/training-configs/v8.15.0-base-c6-wofreps-cursor-emit-v0822-s42.yaml +973 -0
- package/data/training-configs/v8.16.0-base-c6-wofreps-positions-v0822-s42.yaml +988 -0
- package/data/training-configs/v8.19.0-nz-v0822-s42.yaml +870 -0
- package/data/training-manifests/v0.8.22-nz-overlay.effective.json +2556 -0
- package/data/training-manifests/v0.8.22-nz-overlay.json +9000 -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/overlay/manifest.ts +36 -5
- package/lib/tools/region-slot-census.run.ts +2 -2
- package/lib/training/config/schema.ts +17 -0
- 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 +40 -7
- 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/overlay/manifest.d.ts.map +1 -1
- package/out/tools/overlay/manifest.js +29 -5
- package/out/tools/overlay/manifest.js.map +1 -1
- package/out/tools/region-slot-census.run.js +2 -2
- package/out/training/config/schema.d.ts +46 -0
- package/out/training/config/schema.d.ts.map +1 -1
- package/out/training/config/schema.js +13 -0
- package/out/training/config/schema.js.map +1 -1
- 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 +19 -0
- package/out/us/adapters/usgov/nad/adapter.d.ts.map +1 -1
- package/out/us/adapters/usgov/nad/adapter.js +29 -6
- 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
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* `postcode_move` augmentation's job (#2750).
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import { countryRenderForms } from "@mailwoman/codex/country"
|
|
15
15
|
import { currentSourcePath } from "@mailwoman/core/data-root"
|
|
16
16
|
import { pathExists } from "@mailwoman/core/fs/readers/stat"
|
|
17
17
|
import { openReadStream } from "@mailwoman/core/fs/streams"
|
|
@@ -227,6 +227,9 @@ const COUNTRY_SOURCES: Record<string, LocaleCountrySource> = {
|
|
|
227
227
|
// The share of rows #2676 shipped in v0.7.10: 52,103 of 786,626 train rows (6.6%) labeled the county
|
|
228
228
|
// or constituent country. The run skips a row whose text it already wrote (#2765), and a row with a
|
|
229
229
|
// region rarely repeats, so 5.7% of draws yields 6.6% of written rows.
|
|
230
|
+
// Royal Mail prints no county.
|
|
231
|
+
// Its description: "The county name is no longer required in the address if the post town and postcode
|
|
232
|
+
// are provided". The share stays a minority of typed rows that write the county.
|
|
230
233
|
regionFraction: 0.057,
|
|
231
234
|
// OS Open Names writes a Welsh county as `<Welsh> - <English>`, as in `Caerdydd - Cardiff`
|
|
232
235
|
// or `Gwynedd - Gwynedd`, and an address writes one of the two.
|
|
@@ -546,9 +549,9 @@ export function applyCountryAppend(
|
|
|
546
549
|
random: () => number
|
|
547
550
|
): void {
|
|
548
551
|
if (countryFraction > 0 && random() < countryFraction) {
|
|
549
|
-
const forms =
|
|
552
|
+
const forms = countryRenderForms(country)
|
|
550
553
|
|
|
551
|
-
if (!forms
|
|
554
|
+
if (!forms.length) {
|
|
552
555
|
throw new Error(
|
|
553
556
|
`No COUNTRY_SURFACE_FORMS entry for ${country} — add it to codex/country/country.ts before using --country-fraction`
|
|
554
557
|
)
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
* Every row records that license.
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
-
import { formatAddressRow } from "@mailwoman/codex/address/format"
|
|
35
34
|
import { readLocalBuffer } from "@mailwoman/core/fs/readers"
|
|
36
35
|
import { decodeBytes } from "@mailwoman/core/fs/streams"
|
|
37
36
|
import { readZipEntry } from "@mailwoman/core/fs/zip"
|
|
@@ -43,6 +42,7 @@ import { UnsupportedCountryError } from "#adapters/errors"
|
|
|
43
42
|
import { present } from "#adapters/present"
|
|
44
43
|
import { stableSourceIDFromParts } from "#adapters/source-id"
|
|
45
44
|
import { SourceRegister } from "#registers"
|
|
45
|
+
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
46
46
|
import {
|
|
47
47
|
AddressRole,
|
|
48
48
|
type AdapterOptions,
|
|
@@ -203,7 +203,7 @@ export function createLLVLiechtensteinAdapter(): CorpusAdapter {
|
|
|
203
203
|
|
|
204
204
|
if (!components) continue
|
|
205
205
|
|
|
206
|
-
const rendered =
|
|
206
|
+
const rendered = formatCorpusRow(components, "LI", {
|
|
207
207
|
singleLine: true,
|
|
208
208
|
})
|
|
209
209
|
|
|
@@ -78,12 +78,12 @@
|
|
|
78
78
|
* It honors `opts.limit`, `opts.signal` and `opts.country`.
|
|
79
79
|
*/
|
|
80
80
|
|
|
81
|
-
import { formatAddressRow } from "@mailwoman/codex/address/format"
|
|
82
81
|
import { CSVSpliterator } from "spliterator"
|
|
83
82
|
|
|
84
83
|
import { UnsupportedCountryError } from "#adapters/errors"
|
|
85
84
|
import { stableSourceID } from "#adapters/source-id"
|
|
86
85
|
import { SourceRegister } from "#registers"
|
|
86
|
+
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
87
87
|
import { AddressRole, type AdapterOptions, type CanonicalRow, type CorpusAdapter, SurfaceOrigin } from "#types"
|
|
88
88
|
|
|
89
89
|
/**
|
|
@@ -201,7 +201,7 @@ export function createBDAdressesAdapter(): CorpusAdapter {
|
|
|
201
201
|
components.locality = locality
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
const rendered =
|
|
204
|
+
const rendered = formatCorpusRow(components, "LU", { singleLine: true })
|
|
205
205
|
|
|
206
206
|
if (!rendered) continue
|
|
207
207
|
|
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
* It honors `opts.limit`, `opts.signal` and `opts.country`.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import { formatAddressRow } from "@mailwoman/codex/address/format"
|
|
27
26
|
import { CSVSpliterator } from "spliterator"
|
|
28
27
|
|
|
29
28
|
import { UnsupportedCountryError } from "#adapters/errors"
|
|
30
29
|
import { stableSourceID } from "#adapters/source-id"
|
|
31
30
|
import { composeHouseNumber } from "#adapters/street/line"
|
|
32
31
|
import { SourceRegister } from "#registers"
|
|
32
|
+
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
33
33
|
import { AddressRole, type AdapterOptions, type CanonicalRow, type CorpusAdapter, SurfaceOrigin } from "#types"
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -148,7 +148,7 @@ export function createMatrikkelenAdapter(): CorpusAdapter {
|
|
|
148
148
|
components.locality = locality
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
const rendered =
|
|
151
|
+
const rendered = formatCorpusRow(components, country, { singleLine: true })
|
|
152
152
|
|
|
153
153
|
if (!rendered) continue
|
|
154
154
|
|
package/lib/parquet/streams.ts
CHANGED
|
@@ -72,6 +72,15 @@ export interface ParquetRowStreamOptions {
|
|
|
72
72
|
* The caller builds it, escaping every literal with `escapeSQLString`.
|
|
73
73
|
*/
|
|
74
74
|
where?: string
|
|
75
|
+
/**
|
|
76
|
+
* Read DuckDB's `file_row_number`, each row's position in its file,
|
|
77
|
+
* and yield it as a `file_row_number` field.
|
|
78
|
+
*
|
|
79
|
+
* `where` may then select a range of positions.
|
|
80
|
+
* DuckDB skips the row groups outside such a range, so reading the last million rows
|
|
81
|
+
* of a 99-million-row file costs what reading the first million does.
|
|
82
|
+
*/
|
|
83
|
+
fileRowNumber?: boolean
|
|
75
84
|
/**
|
|
76
85
|
* A DuckDB `ORDER BY` expression, interpolated as written.
|
|
77
86
|
*
|
|
@@ -106,15 +115,21 @@ export async function* openParquetRowStream<T>(
|
|
|
106
115
|
path: PathBuilderLike | readonly PathBuilderLike[],
|
|
107
116
|
options: ParquetRowStreamOptions = {}
|
|
108
117
|
): AsyncGenerator<T> {
|
|
109
|
-
const { columns, limit, where, orderBy, limits } = options
|
|
118
|
+
const { columns, limit, where, orderBy, limits, fileRowNumber } = options
|
|
110
119
|
// Disposed when this generator finishes or a consumer abandons it,
|
|
111
120
|
// since `for await` calls `.return()` on break.
|
|
112
121
|
using db = await openDuckDB(limits)
|
|
113
|
-
const
|
|
122
|
+
const projected = columns?.length ? columns.map(escapeSQLIdentifier).join(", ") : "*"
|
|
123
|
+
const projection = fileRowNumber && columns?.length ? `${projected}, file_row_number` : projected
|
|
114
124
|
const limitClause = typeof limit !== "number" ? "" : ` LIMIT ${validateRowLimit(limit)}`
|
|
115
125
|
const whereClause = where ? ` WHERE ${where}` : ""
|
|
116
126
|
const orderClause = orderBy ? ` ORDER BY ${orderBy}` : ""
|
|
117
|
-
|
|
127
|
+
|
|
128
|
+
const source = fileRowNumber
|
|
129
|
+
? readParquetSQL(path).replace(/\)$/u, ", file_row_number = true)")
|
|
130
|
+
: readParquetSQL(path)
|
|
131
|
+
|
|
132
|
+
const sql = `SELECT ${projection} FROM ${source}${whereClause}${orderClause}${limitClause}`
|
|
118
133
|
|
|
119
134
|
try {
|
|
120
135
|
const stream = await db.stream(sql)
|
package/lib/parquet/writers.ts
CHANGED
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
writeLocalJSONFile,
|
|
46
46
|
} from "@mailwoman/core/fs/writers"
|
|
47
47
|
import { once } from "@mailwoman/core/utils/events"
|
|
48
|
-
import { stringifyJSON } from "@mailwoman/core/values/json"
|
|
48
|
+
import { parseJSONStrict, stringifyJSON } from "@mailwoman/core/values/json"
|
|
49
49
|
import { Field, Int32, Int64, List, Null, Table as ArrowTable, tableToIPC, Utf8, vectorFromArray } from "apache-arrow"
|
|
50
50
|
import { Compression, Table as WasmTable, WriterPropertiesBuilder, writeParquet } from "parquet-wasm"
|
|
51
51
|
import { type PathBuilderLike, resolvePathBuilder } from "path-ts"
|
|
@@ -249,14 +249,90 @@ export function stampRowLicense(
|
|
|
249
249
|
context: string
|
|
250
250
|
): ParquetRow {
|
|
251
251
|
const id = licenses.require(row.source, context)
|
|
252
|
+
const statement = displacedLicenseStatement(row.license, id)
|
|
252
253
|
|
|
253
|
-
if (
|
|
254
|
-
statements.set(
|
|
254
|
+
if (statement) {
|
|
255
|
+
statements.set(statement, (statements.get(statement) ?? 0) + 1)
|
|
255
256
|
}
|
|
256
257
|
|
|
257
258
|
return { ...row, license: id }
|
|
258
259
|
}
|
|
259
260
|
|
|
261
|
+
/**
|
|
262
|
+
* The producer's own license statement that the register id `id` replaces in a row,
|
|
263
|
+
* or `null` when the row states the register id or states none.
|
|
264
|
+
*/
|
|
265
|
+
function displacedLicenseStatement(license: unknown, id: string): string | null {
|
|
266
|
+
return typeof license === "string" && license && license !== id ? license : null
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* One row as a parquet part's staging file holds it, with the fields the writer reads from it.
|
|
271
|
+
*
|
|
272
|
+
* A parallel build's align worker stages each row once, so the finish worker shuffles
|
|
273
|
+
* and writes lines without parsing a row or serializing it again.
|
|
274
|
+
*/
|
|
275
|
+
export interface StagedRow {
|
|
276
|
+
source: string
|
|
277
|
+
source_id: string
|
|
278
|
+
/**
|
|
279
|
+
* The register license id the row's `license` column holds.
|
|
280
|
+
*/
|
|
281
|
+
license: string
|
|
282
|
+
/**
|
|
283
|
+
* The producer's license statement the register id replaced, counted in the file's record.
|
|
284
|
+
*/
|
|
285
|
+
statement: string | null
|
|
286
|
+
/**
|
|
287
|
+
* The row's parquet columns as one JSON object, without a trailing newline.
|
|
288
|
+
*/
|
|
289
|
+
line: string
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Convert a labeled row to the line a staging file holds, its license replaced by its source's register id.
|
|
294
|
+
*
|
|
295
|
+
* @throws When the row fails {@linkcode rowToParquet}'s checks or its source has no license id.
|
|
296
|
+
*/
|
|
297
|
+
export function stageRow(row: LabeledRow, licenses: RowLicenses, context: string): StagedRow {
|
|
298
|
+
const parquet = rowToParquet(row)
|
|
299
|
+
const license = licenses.require(row.source, context)
|
|
300
|
+
|
|
301
|
+
return {
|
|
302
|
+
source: row.source,
|
|
303
|
+
source_id: row.source_id,
|
|
304
|
+
license,
|
|
305
|
+
statement: displacedLicenseStatement(parquet.license, license),
|
|
306
|
+
line: stringifyJSON({ ...parquet, license }),
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* One staged row as a line of a staged-rows file: its `source_id` and statement
|
|
312
|
+
* as a JSON array, a tab, and its parquet line.
|
|
313
|
+
*
|
|
314
|
+
* JSON escapes a tab inside a string, so the first tab ends the array.
|
|
315
|
+
* The source and license id are the same for every row of one source's file,
|
|
316
|
+
* so the file doesn't repeat them.
|
|
317
|
+
*/
|
|
318
|
+
export function encodeStagedRow(row: StagedRow): string {
|
|
319
|
+
return `${stringifyJSON([row.source_id, row.statement])}\t${row.line}\n`
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Read one line {@linkcode encodeStagedRow} wrote, for rows of `source` whose license id is `license`.
|
|
324
|
+
*/
|
|
325
|
+
export function decodeStagedRow(text: string, source: string, license: string): StagedRow {
|
|
326
|
+
const tab = text.indexOf("\t")
|
|
327
|
+
|
|
328
|
+
if (tab === -1) throw new Error(`decodeStagedRow: a staged ${source} line holds no tab: ${text.slice(0, 120)}`)
|
|
329
|
+
|
|
330
|
+
const [sourceID, statement] = parseJSONStrict<[string, string | null]>(text.slice(0, tab))
|
|
331
|
+
const end = text.endsWith("\n") ? text.length - 1 : text.length
|
|
332
|
+
|
|
333
|
+
return { source, source_id: sourceID, license, statement, line: text.slice(tab + 1, end) }
|
|
334
|
+
}
|
|
335
|
+
|
|
260
336
|
/**
|
|
261
337
|
* Options for {@linkcode writeParquetFile}.
|
|
262
338
|
*/
|
|
@@ -510,8 +586,8 @@ export async function writeStagedParquet(stagePath: string, outputPath: string,
|
|
|
510
586
|
)
|
|
511
587
|
}
|
|
512
588
|
|
|
513
|
-
async function
|
|
514
|
-
if (!stage.write(
|
|
589
|
+
async function writeStagedLine(stage: WriteStream, line: string): Promise<void> {
|
|
590
|
+
if (!stage.write(line + "\n")) {
|
|
515
591
|
await once(stage, "drain")
|
|
516
592
|
}
|
|
517
593
|
}
|
|
@@ -547,8 +623,10 @@ interface OpenPart {
|
|
|
547
623
|
*
|
|
548
624
|
* Rows are staged to newline-delimited JSON with backpressure, then DuckDB
|
|
549
625
|
* writes the Parquet file from disk.
|
|
550
|
-
* A staged part is removed as soon as its conversion succeeds
|
|
551
|
-
*
|
|
626
|
+
* A staged part is removed as soon as its conversion succeeds.
|
|
627
|
+
*
|
|
628
|
+
* One conversion runs while the rows of the next parts are staged, so the split's staging
|
|
629
|
+
* directory holds at most one open part per source and the part being converted.
|
|
552
630
|
*
|
|
553
631
|
* Each source's final part stays open until the split's rows end.
|
|
554
632
|
* Peak disk demand is therefore the unfinished staged parts, plus the conversion
|
|
@@ -571,6 +649,36 @@ interface OpenPart {
|
|
|
571
649
|
export async function writeParquetSplits(
|
|
572
650
|
perSplit: PerSplitRows,
|
|
573
651
|
opts: WriteParquetSplitsOptions
|
|
652
|
+
): Promise<ParquetManifest> {
|
|
653
|
+
const licenses = opts.licenses ?? (await committedRowLicenses())
|
|
654
|
+
|
|
655
|
+
async function* staged(rows: AsyncIterable<LabeledRow>): AsyncGenerator<StagedRow> {
|
|
656
|
+
for await (const row of rows) {
|
|
657
|
+
yield stageRow(row, licenses, "writeParquetSplits")
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
return writeStagedParquetSplits(
|
|
662
|
+
Object.fromEntries(
|
|
663
|
+
Object.entries(perSplit).map(([split, rows]) => [split, rows ? staged(rows) : rows])
|
|
664
|
+
) as PerSplitStagedRows,
|
|
665
|
+
opts
|
|
666
|
+
)
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Each split's staged rows, in the order {@linkcode writeStagedParquetSplits} writes them.
|
|
671
|
+
*/
|
|
672
|
+
export type PerSplitStagedRows = Partial<Record<SplitName, AsyncIterable<StagedRow>>>
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* {@linkcode writeParquetSplits} over rows already staged by {@linkcode stageRow}.
|
|
676
|
+
*
|
|
677
|
+
* `opts.licenses` is unread: each staged row holds its license id.
|
|
678
|
+
*/
|
|
679
|
+
export async function writeStagedParquetSplits(
|
|
680
|
+
perSplit: PerSplitStagedRows,
|
|
681
|
+
opts: WriteParquetSplitsOptions
|
|
574
682
|
): Promise<ParquetManifest> {
|
|
575
683
|
const rowsPerFile = opts.rowsPerFile ?? ROWS_PER_FILE
|
|
576
684
|
const corpusDir = resolvePathBuilder(opts.outputDir, corpusDirectoryName(opts.corpusVersion))
|
|
@@ -578,7 +686,6 @@ export async function writeParquetSplits(
|
|
|
578
686
|
await makeDirectories(corpusDir, storeDir)
|
|
579
687
|
|
|
580
688
|
const manifestPath = opts.manifestPath ?? corpusDir("MANIFEST.json")
|
|
581
|
-
const licenses = opts.licenses ?? (await committedRowLicenses())
|
|
582
689
|
const files: ParquetFileDescriptor[] = opts.resume ? await readFinishedParquetFiles(manifestPath) : []
|
|
583
690
|
const derivations = new Map<string, Promise<DerivationInputs>>()
|
|
584
691
|
|
|
@@ -649,6 +756,13 @@ export async function writeParquetSplits(
|
|
|
649
756
|
return opened
|
|
650
757
|
}
|
|
651
758
|
|
|
759
|
+
// The conversion of the last closed part.
|
|
760
|
+
// The row loop fills the next part while it runs.
|
|
761
|
+
// Conversions run one at a time and in close order, so the split holds one DuckDB instance,
|
|
762
|
+
// `files` keeps close order, and the manifest on disk always lists a prefix of each source's parts.
|
|
763
|
+
// A resume's row skip counts on that prefix.
|
|
764
|
+
let converting: Promise<void> = Promise.resolve()
|
|
765
|
+
|
|
652
766
|
const closePart = async (opened: OpenPart): Promise<void> => {
|
|
653
767
|
open.delete(opened.source)
|
|
654
768
|
|
|
@@ -656,6 +770,14 @@ export async function writeParquetSplits(
|
|
|
656
770
|
opened.stage.end((error?: Error | null) => (error ? reject(error) : resolve()))
|
|
657
771
|
})
|
|
658
772
|
|
|
773
|
+
await converting
|
|
774
|
+
|
|
775
|
+
converting = convertPart(opened)
|
|
776
|
+
// A failure surfaces at the next close or at the end of the split.
|
|
777
|
+
converting.catch(() => {})
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
const convertPart = async (opened: OpenPart): Promise<void> => {
|
|
659
781
|
if (!opened.rows) {
|
|
660
782
|
await removePath(opened.stagePath)
|
|
661
783
|
|
|
@@ -702,7 +824,7 @@ export async function writeParquetSplits(
|
|
|
702
824
|
|
|
703
825
|
// The converter's connection closed when `writeStagedParquet` returned,
|
|
704
826
|
// so no reader holds the staged part open.
|
|
705
|
-
// This removes the staged part and bounds staging to parts
|
|
827
|
+
// This removes the staged part and bounds staging to the open parts and the one being converted.
|
|
706
828
|
await removePath(opened.stagePath)
|
|
707
829
|
|
|
708
830
|
const sha256 = await sha256File(pending)
|
|
@@ -752,37 +874,47 @@ export async function writeParquetSplits(
|
|
|
752
874
|
await writeLocalJSONFile(manifestNow(), manifestPath)
|
|
753
875
|
}
|
|
754
876
|
|
|
755
|
-
|
|
756
|
-
const
|
|
877
|
+
try {
|
|
878
|
+
for await (const row of rows) {
|
|
879
|
+
const skip = skipRows.get(row.source) ?? 0
|
|
757
880
|
|
|
758
|
-
|
|
759
|
-
|
|
881
|
+
if (skip > 0) {
|
|
882
|
+
skipRows.set(row.source, skip - 1)
|
|
760
883
|
|
|
761
|
-
|
|
762
|
-
|
|
884
|
+
continue
|
|
885
|
+
}
|
|
763
886
|
|
|
764
|
-
|
|
765
|
-
const pq = stampRowLicense(rowToParquet(row), licenses, opened.statements, "writeParquetSplits")
|
|
887
|
+
const opened = open.get(row.source) ?? openPart(row.source)
|
|
766
888
|
|
|
767
|
-
|
|
889
|
+
if (row.statement) {
|
|
890
|
+
opened.statements.set(row.statement, (opened.statements.get(row.statement) ?? 0) + 1)
|
|
891
|
+
}
|
|
768
892
|
|
|
769
|
-
|
|
893
|
+
await writeStagedLine(opened.stage, row.line)
|
|
770
894
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
895
|
+
opened.rows++
|
|
896
|
+
|
|
897
|
+
if (opened.rows === 1) {
|
|
898
|
+
opened.firstSourceID = row.source_id
|
|
899
|
+
}
|
|
774
900
|
|
|
775
|
-
|
|
776
|
-
|
|
901
|
+
opened.lastSourceID = row.source_id
|
|
902
|
+
addToTally(opened.tally, row.source, row.license, 1)
|
|
777
903
|
|
|
778
|
-
|
|
904
|
+
if (opened.rows >= rowsPerFile) {
|
|
905
|
+
await closePart(opened)
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
// The Map iterator permits `closePart` to delete the entry currently being visited.
|
|
910
|
+
for (const opened of open.values()) {
|
|
779
911
|
await closePart(opened)
|
|
780
912
|
}
|
|
781
|
-
}
|
|
782
913
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
914
|
+
await converting
|
|
915
|
+
} finally {
|
|
916
|
+
// The staging directory is removed when this block exits, so no conversion may still read from it.
|
|
917
|
+
await converting.catch(() => {})
|
|
786
918
|
}
|
|
787
919
|
}
|
|
788
920
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { ComponentTag } from "@mailwoman/codex/component"
|
|
12
|
-
import { COUNTRY_SURFACE_FORMS, CountryNames } from "@mailwoman/codex/country"
|
|
12
|
+
import { COUNTRY_SURFACE_FORMS, CountryNames, countryRenderForms } from "@mailwoman/codex/country"
|
|
13
13
|
import { currentSourcePath } from "@mailwoman/core/data-root"
|
|
14
14
|
import { sample } from "@mailwoman/core/math/random"
|
|
15
15
|
import { mulberry32 as makeMulberry32 } from "@mailwoman/core/utils"
|
|
@@ -28,9 +28,9 @@ import { alignRow } from "#utils"
|
|
|
28
28
|
|
|
29
29
|
// Country names are drawn without regard to the address's own country.
|
|
30
30
|
const COUNTRY_FORM_POOL = (() => {
|
|
31
|
-
// `surface` holds curated endonyms and abbreviations.
|
|
31
|
+
// `surface` holds curated endonyms and abbreviations, without the two-letter codes.
|
|
32
32
|
// `names` holds canonical English names.
|
|
33
|
-
const surface = Object.
|
|
33
|
+
const surface = Object.keys(COUNTRY_SURFACE_FORMS).flatMap((iso2) => countryRenderForms(iso2))
|
|
34
34
|
const names = [...CountryNames]
|
|
35
35
|
|
|
36
36
|
return { surface, names }
|
|
@@ -303,6 +303,11 @@ const HOMOGRAPHS: readonly Homograph[] = [
|
|
|
303
303
|
},
|
|
304
304
|
]
|
|
305
305
|
|
|
306
|
+
/**
|
|
307
|
+
* US street names for the US side of the contrasts.
|
|
308
|
+
*
|
|
309
|
+
* They're American English vocabulary, so no row in another country takes one.
|
|
310
|
+
*/
|
|
306
311
|
const STREET_POOL: readonly string[] = [
|
|
307
312
|
"Main Street",
|
|
308
313
|
"Oak Avenue",
|
|
@@ -318,11 +323,19 @@ const STREET_POOL: readonly string[] = [
|
|
|
318
323
|
|
|
319
324
|
const houseNo = (random: () => number): string => String(1 + Math.floor(random() * 998))
|
|
320
325
|
|
|
321
|
-
// The share of
|
|
326
|
+
// The share of US-reading homograph rows that include a street address.
|
|
322
327
|
const HOMOGRAPH_WITH_STREET_SHARE = 0.6
|
|
323
328
|
|
|
324
329
|
/**
|
|
325
330
|
* Renders a homograph as either the country or the US place, with the matching country code.
|
|
331
|
+
*
|
|
332
|
+
* The country reading writes the city and the country only.
|
|
333
|
+
* The recipe holds no street of Tbilisi, Amman or Beirut.
|
|
334
|
+
*
|
|
335
|
+
* A US street name in front of one (`289 Main Street, Rustavi, Georgia`) writes
|
|
336
|
+
* an address no such country has.
|
|
337
|
+
* The US reading writes the bare form on the share without a street.
|
|
338
|
+
* A street then isn't what tells the two readings apart.
|
|
326
339
|
*/
|
|
327
340
|
function renderHomograph(random: () => number): {
|
|
328
341
|
fmt: string
|
|
@@ -332,36 +345,37 @@ function renderHomograph(random: () => number): {
|
|
|
332
345
|
} {
|
|
333
346
|
const h = sample(HOMOGRAPHS, random)
|
|
334
347
|
|
|
335
|
-
const hn = houseNo(random),
|
|
336
|
-
street = sample(STREET_POOL, random)
|
|
337
|
-
|
|
338
348
|
if (random() < 0.5) {
|
|
339
349
|
const city = sample(h.cities, random)
|
|
340
|
-
const withStreet = random() < HOMOGRAPH_WITH_STREET_SHARE
|
|
341
|
-
const raw = withStreet ? `${hn} ${street}, ${city}, ${h.surface}` : `${city}, ${h.surface}`
|
|
342
|
-
|
|
343
|
-
const components: Partial<Record<ComponentTag, string>> = withStreet
|
|
344
|
-
? { house_number: hn, street, locality: city, country: h.surface }
|
|
345
|
-
: { locality: city, country: h.surface }
|
|
346
350
|
|
|
347
|
-
return {
|
|
351
|
+
return {
|
|
352
|
+
fmt: "homograph-country",
|
|
353
|
+
raw: `${city}, ${h.surface}`,
|
|
354
|
+
components: { locality: city, country: h.surface },
|
|
355
|
+
iso2: h.iso2,
|
|
356
|
+
}
|
|
348
357
|
}
|
|
349
358
|
|
|
350
359
|
const pc = sample(h.us.postcodes, random)
|
|
360
|
+
const withStreet = random() < HOMOGRAPH_WITH_STREET_SHARE
|
|
361
|
+
const hn = houseNo(random)
|
|
362
|
+
const street = sample(STREET_POOL, random)
|
|
363
|
+
const lead = withStreet ? `${hn} ${street}, ` : ""
|
|
364
|
+
const streetComponents: Partial<Record<ComponentTag, string>> = withStreet ? { house_number: hn, street } : {}
|
|
351
365
|
|
|
352
366
|
if (h.us.role === "region") {
|
|
353
367
|
return {
|
|
354
368
|
fmt: "homograph-us-region",
|
|
355
|
-
raw: `${
|
|
356
|
-
components: {
|
|
369
|
+
raw: `${lead}${h.us.locality}, ${h.surface} ${pc}`,
|
|
370
|
+
components: { ...streetComponents, locality: h.us.locality, region: h.surface, postcode: pc },
|
|
357
371
|
iso2: "US",
|
|
358
372
|
}
|
|
359
373
|
}
|
|
360
374
|
|
|
361
375
|
return {
|
|
362
376
|
fmt: "homograph-us-locality",
|
|
363
|
-
raw: `${
|
|
364
|
-
components: {
|
|
377
|
+
raw: `${lead}${h.surface}, ${h.us.region} ${pc}`,
|
|
378
|
+
components: { ...streetComponents, locality: h.surface, region: h.us.region, postcode: pc },
|
|
365
379
|
iso2: "US",
|
|
366
380
|
}
|
|
367
381
|
}
|
|
@@ -45,15 +45,18 @@ import {
|
|
|
45
45
|
import { stampRowLicenses } from "#source-register/row-license"
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* The columns of the recipe output, in the order and with the types
|
|
49
|
-
*
|
|
48
|
+
* The columns of the recipe output, in the order the Python builder wrote them and with the corpus's types.
|
|
49
|
+
*
|
|
50
|
+
* The spans are 32-bit and `base_source_id` is a string, as in every other corpus file.
|
|
51
|
+
* A file with 64-bit spans reads back as `BigInt` values.
|
|
52
|
+
* The corpus re-split's workers refuse them.
|
|
50
53
|
*/
|
|
51
54
|
export const FRAGMENT_COLUMNS: ParquetColumns = [
|
|
52
55
|
["raw", ParquetColumnKind.String],
|
|
53
56
|
["tokens", ParquetColumnKind.StringList],
|
|
54
57
|
["labels", ParquetColumnKind.StringList],
|
|
55
|
-
["span_starts", ParquetColumnKind.
|
|
56
|
-
["span_ends", ParquetColumnKind.
|
|
58
|
+
["span_starts", ParquetColumnKind.Int32List],
|
|
59
|
+
["span_ends", ParquetColumnKind.Int32List],
|
|
57
60
|
["span_tags", ParquetColumnKind.StringList],
|
|
58
61
|
["country", ParquetColumnKind.String],
|
|
59
62
|
["locale", ParquetColumnKind.String],
|
|
@@ -62,7 +65,7 @@ export const FRAGMENT_COLUMNS: ParquetColumns = [
|
|
|
62
65
|
["license", ParquetColumnKind.String],
|
|
63
66
|
["register", ParquetColumnKind.String],
|
|
64
67
|
["surface", ParquetColumnKind.String],
|
|
65
|
-
["base_source_id", ParquetColumnKind.
|
|
68
|
+
["base_source_id", ParquetColumnKind.String],
|
|
66
69
|
]
|
|
67
70
|
|
|
68
71
|
/**
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* tokens of each field, labeled `B-<tag>` then `I-<tag>`.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { COUNTRY_SURFACE_FORMS, ISO2_TO_NAME } from "@mailwoman/codex/country"
|
|
12
|
+
import { COUNTRY_SURFACE_FORMS, countryRenderForms, ISO2_TO_NAME } from "@mailwoman/codex/country"
|
|
13
13
|
import { codePointLength } from "@mailwoman/core/strings/code-points"
|
|
14
14
|
import { splitWhitespace } from "@mailwoman/core/strings/unicode"
|
|
15
15
|
|
|
@@ -54,13 +54,13 @@ export const FRAGMENT_COUNTRY_NAMES: Readonly<Record<string, string>> = {
|
|
|
54
54
|
const MIN_COUNTRY_SURFACE_CHARS = 3
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* Each country's word-form surfaces in the codex's order: its curated forms
|
|
58
|
-
* or its ISO English name, keeping those of at least three characters.
|
|
57
|
+
* Each country's word-form surfaces in the codex's order: its curated forms without the two-letter
|
|
58
|
+
* codes (`countryRenderForms`), or its ISO English name, keeping those of at least three characters.
|
|
59
59
|
* A country left with none is absent.
|
|
60
60
|
*/
|
|
61
61
|
export function codexCountrySurfaces(): Map<string, string[]> {
|
|
62
62
|
const all = new Map<string, string[]>(
|
|
63
|
-
Object.
|
|
63
|
+
Object.keys(COUNTRY_SURFACE_FORMS).map((iso2) => [iso2, [...countryRenderForms(iso2)]])
|
|
64
64
|
)
|
|
65
65
|
|
|
66
66
|
for (const [iso2, name] of ISO2_TO_NAME) {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { layoutForCountry, layoutPrintsTag } from "@mailwoman/codex/address/layouts"
|
|
14
14
|
import { makeLcg } from "@mailwoman/core/utils"
|
|
15
15
|
|
|
16
|
+
import { withConventionStreet } from "#adapters/street/convention"
|
|
16
17
|
import {
|
|
17
18
|
alignAndWrite,
|
|
18
19
|
readTuples,
|
|
@@ -83,7 +84,7 @@ export const houseVenueRecipe: CorpusRecipe = {
|
|
|
83
84
|
write,
|
|
84
85
|
{
|
|
85
86
|
raw: synth.raw,
|
|
86
|
-
components: synth.components,
|
|
87
|
+
components: withConventionStreet(synth.components, tuple.country),
|
|
87
88
|
country: tuple.country,
|
|
88
89
|
locale: synth.locale,
|
|
89
90
|
source,
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
* Each leg lives under its country's directory and renders only the forms its codex rule table cites.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { formatAddressRow } from "@mailwoman/codex/address/format"
|
|
11
10
|
import type { ComponentDict } from "@mailwoman/codex/address/render"
|
|
12
11
|
import type { PostalGuidelineRule } from "@mailwoman/codex/designators/guideline"
|
|
13
12
|
|
|
13
|
+
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
14
|
+
|
|
14
15
|
/**
|
|
15
16
|
* The longest GeoNames place name a leg writes, the same cap the `po-box-cedex` place readers apply.
|
|
16
17
|
*/
|
|
@@ -167,7 +168,7 @@ export function renderGuidelineLine(
|
|
|
167
168
|
components: Record<string, string>,
|
|
168
169
|
separator: string
|
|
169
170
|
): Pick<PostalGuidelineRendering, "raw" | "components"> {
|
|
170
|
-
const row =
|
|
171
|
+
const row = formatCorpusRow(components as ComponentDict, country, { separator })
|
|
171
172
|
|
|
172
173
|
if (!row || row.unplaced.length) {
|
|
173
174
|
throw new Error(
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import type { ComponentTag } from "@mailwoman/codex/component"
|
|
30
|
-
import {
|
|
30
|
+
import { countryRenderForms } from "@mailwoman/codex/country/country"
|
|
31
31
|
import { stringifyJSON } from "@mailwoman/core/values/json"
|
|
32
32
|
import { JSONSpliterator } from "spliterator"
|
|
33
33
|
|
|
@@ -146,8 +146,8 @@ export interface ProminentPlaceTuple {
|
|
|
146
146
|
/**
|
|
147
147
|
* The shortest country form a row writes.
|
|
148
148
|
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
149
|
+
* `countryRenderForms` already leaves out a two-letter code (`CA`, `U.S.`).
|
|
150
|
+
* The floor also applies to the display name and to the WOF name of a country the codex lists no forms for.
|
|
151
151
|
*/
|
|
152
152
|
const COUNTRY_FORM_MIN_LENGTH = 3
|
|
153
153
|
|
|
@@ -172,7 +172,7 @@ function secondForms(
|
|
|
172
172
|
case "country": {
|
|
173
173
|
const forms = [
|
|
174
174
|
COUNTRY_DISPLAY_NAME[tuple.country] ?? tuple.country_name,
|
|
175
|
-
...
|
|
175
|
+
...countryRenderForms(tuple.country),
|
|
176
176
|
].filter((form): form is string => typeof form === "string" && form.length >= COUNTRY_FORM_MIN_LENGTH)
|
|
177
177
|
|
|
178
178
|
return forms.length ? { tag: "country", forms: [...new Set(forms)] } : null
|