@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
package/lib/build/worker.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { cliArguments } from "@mailwoman/core/scripting/arguments"
|
|
|
21
21
|
import { heapLimitBytes } from "@mailwoman/core/utils/system"
|
|
22
22
|
import type { LicensePolicy } from "@mailwoman/license/policy"
|
|
23
23
|
import { PathBuilder } from "path-ts"
|
|
24
|
+
import { TextSpliterator } from "spliterator"
|
|
24
25
|
|
|
25
26
|
import { alignSettings } from "#build/align"
|
|
26
27
|
import {
|
|
@@ -36,7 +37,7 @@ import { mergeAlignTotals, serializeAlignTotals } from "#build/align/totals"
|
|
|
36
37
|
import type { WorkerResources } from "#build/budget"
|
|
37
38
|
import { loadAdapterFromModule } from "#build/code-hash"
|
|
38
39
|
import { readSourceEligibility } from "#build/eligibility"
|
|
39
|
-
import {
|
|
40
|
+
import { regionCheckFingerprints } from "#build/settings"
|
|
40
41
|
import {
|
|
41
42
|
recordFile,
|
|
42
43
|
SOURCE_RECORD_FILE,
|
|
@@ -46,9 +47,16 @@ import {
|
|
|
46
47
|
import { BuildProfile } from "#build/types"
|
|
47
48
|
import { resolveDerivation, type FileDerivation } from "#parquet/record"
|
|
48
49
|
import { shuffleSplitRows, SPLIT_SHUFFLE_SALT } from "#parquet/shuffle"
|
|
49
|
-
import {
|
|
50
|
-
import {
|
|
51
|
-
|
|
50
|
+
import { decodeStagedRow, writeStagedParquetSplits, type ParquetManifest, type StagedRow } from "#parquet/writers"
|
|
51
|
+
import {
|
|
52
|
+
mergeAdapterPartitions,
|
|
53
|
+
runAdapter,
|
|
54
|
+
runAdapterPartition,
|
|
55
|
+
type AdapterPartitionRecord,
|
|
56
|
+
type AdapterRunManifest,
|
|
57
|
+
} from "#runner"
|
|
58
|
+
import { committedRowLicenses } from "#source-register/row-license"
|
|
59
|
+
import type { AdapterOptions } from "#types"
|
|
52
60
|
import { SPLIT_NAMES, sortLines, type CountryHoldout, type SplitName } from "#utils/split"
|
|
53
61
|
|
|
54
62
|
/**
|
|
@@ -61,6 +69,7 @@ export interface AlignTaskSettings {
|
|
|
61
69
|
licensePolicy: LicensePolicy
|
|
62
70
|
excludeLicenses: { source: string; flags: string }[]
|
|
63
71
|
holdouts: Record<string, CountryHoldout>
|
|
72
|
+
trainShares: Record<string, number>
|
|
64
73
|
}
|
|
65
74
|
|
|
66
75
|
interface TaskBase {
|
|
@@ -93,6 +102,15 @@ export interface AdapterTask extends TaskBase {
|
|
|
93
102
|
*/
|
|
94
103
|
inputs: string
|
|
95
104
|
intermediateDir: string
|
|
105
|
+
/**
|
|
106
|
+
* Set for one partition of a partitioned run: the rows to read and the files
|
|
107
|
+
* to write them and their record to.
|
|
108
|
+
*/
|
|
109
|
+
partition?: { rowRange: { start: number; end: number }; outputPath: string; recordPath: string } | null
|
|
110
|
+
/**
|
|
111
|
+
* Set for the task that merges a partitioned run: each partition's record, in input order.
|
|
112
|
+
*/
|
|
113
|
+
mergeRecords?: string[] | null
|
|
96
114
|
}
|
|
97
115
|
|
|
98
116
|
export interface AlignTask extends TaskBase {
|
|
@@ -145,6 +163,7 @@ function alignInputs(settings: AlignTaskSettings) {
|
|
|
145
163
|
licensePolicy: settings.licensePolicy,
|
|
146
164
|
excludeLicenses: compileTaskLicensePatterns(settings),
|
|
147
165
|
holdouts: settings.holdouts,
|
|
166
|
+
trainShares: settings.trainShares,
|
|
148
167
|
}
|
|
149
168
|
}
|
|
150
169
|
|
|
@@ -161,13 +180,46 @@ export function workerModulePath(): string {
|
|
|
161
180
|
async function runAdapterTask(task: AdapterTask): Promise<void> {
|
|
162
181
|
const adapter = await loadAdapterFromModule(task.adapterModule, task.source)
|
|
163
182
|
|
|
164
|
-
|
|
183
|
+
if (task.partition) {
|
|
184
|
+
const record = await runAdapterPartition({
|
|
185
|
+
adapter,
|
|
186
|
+
adapterOptions: {
|
|
187
|
+
...task.adapterOptions,
|
|
188
|
+
rowRange: task.partition.rowRange,
|
|
189
|
+
duckdb: { memoryLimitBytes: task.resources.duckdbBytes, threads: task.resources.duckdbThreads },
|
|
190
|
+
},
|
|
191
|
+
outputPath: task.partition.outputPath,
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
// The record is written last, so a record on disk means its partition file is complete.
|
|
195
|
+
await writeLocalJSONFile(record, task.partition.recordPath)
|
|
196
|
+
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const options = {
|
|
165
201
|
adapter,
|
|
166
202
|
adapterOptions: task.adapterOptions,
|
|
167
203
|
outputDir: task.intermediateDir,
|
|
168
204
|
corpusVersion: task.corpusVersion,
|
|
169
205
|
inputs: task.inputs,
|
|
170
|
-
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (task.mergeRecords) {
|
|
209
|
+
const partitions = await Promise.all(
|
|
210
|
+
task.mergeRecords.map((path) => readLocalJSONFile<AdapterPartitionRecord>(path))
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
await mergeAdapterPartitions(options, partitions)
|
|
214
|
+
|
|
215
|
+
for (const partition of partitions) {
|
|
216
|
+
await removePathIfPresent(partition.path)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
await runAdapter(options)
|
|
171
223
|
}
|
|
172
224
|
|
|
173
225
|
async function runAlignTask(task: AlignTask): Promise<void> {
|
|
@@ -201,9 +253,18 @@ async function finishedPartProblem(manifestPath: PathBuilder): Promise<string |
|
|
|
201
253
|
return null
|
|
202
254
|
}
|
|
203
255
|
|
|
204
|
-
|
|
256
|
+
/**
|
|
257
|
+
* The staged rows of one source's files, in order.
|
|
258
|
+
*/
|
|
259
|
+
async function* concatenatedStagedRows(
|
|
260
|
+
paths: readonly PathBuilder[],
|
|
261
|
+
source: string,
|
|
262
|
+
license: string
|
|
263
|
+
): AsyncGenerator<StagedRow> {
|
|
205
264
|
for (const path of paths) {
|
|
206
|
-
|
|
265
|
+
for await (const line of TextSpliterator.fromAsync(path)) {
|
|
266
|
+
yield decodeStagedRow(line, source, license)
|
|
267
|
+
}
|
|
207
268
|
}
|
|
208
269
|
}
|
|
209
270
|
|
|
@@ -254,12 +315,15 @@ async function runFinishTask(task: FinishTask, report: (message: string) => void
|
|
|
254
315
|
report("writing parquet files")
|
|
255
316
|
|
|
256
317
|
const derivation = task.derivation
|
|
318
|
+
// Every row of one source holds its register license id.
|
|
319
|
+
// The align range stamped that id on each staged line.
|
|
320
|
+
const license = (await committedRowLicenses()).require(task.source, `worker ${task.id}`)
|
|
257
321
|
|
|
258
|
-
const parquet = await
|
|
322
|
+
const parquet = await writeStagedParquetSplits(
|
|
259
323
|
Object.fromEntries(
|
|
260
324
|
SPLIT_NAMES.map((split) => [
|
|
261
325
|
split,
|
|
262
|
-
shuffleSplitRows(
|
|
326
|
+
shuffleSplitRows(concatenatedStagedRows(files[split].staged, task.source, license), {
|
|
263
327
|
seed: task.buildSettings.shuffleSeed,
|
|
264
328
|
salt: SPLIT_SHUFFLE_SALT[split],
|
|
265
329
|
window: task.buildSettings.shuffleWindow,
|
|
@@ -302,6 +366,7 @@ async function runFinishTask(task: FinishTask, report: (message: string) => void
|
|
|
302
366
|
task.plans.map((plan) => recordFile(alignRangeDirectory(sourceDir, plan)("quarantine.jsonl")))
|
|
303
367
|
),
|
|
304
368
|
totals: serializeAlignTotals(mergeAlignTotals(ranges.map((range) => range.totals))),
|
|
369
|
+
regionCheck: await regionCheckFingerprints(),
|
|
305
370
|
completed_at: new Date().toISOString(),
|
|
306
371
|
}
|
|
307
372
|
|
package/lib/build.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { PathBuilder } from "path-ts"
|
|
|
17
17
|
|
|
18
18
|
import { defaultAdapterRegistry } from "#adapters/registry"
|
|
19
19
|
import { adapterRunInputs, runAdapterPhase } from "#build/adapters"
|
|
20
|
-
import { runAlignPhase } from "#build/align"
|
|
20
|
+
import { runAlignPhase, trainSharesOf } from "#build/align"
|
|
21
21
|
import { alignTotalsOf } from "#build/align/totals"
|
|
22
22
|
import { planWorkerBudget } from "#build/budget"
|
|
23
23
|
import { readSourceDecisionTable, readSourceEligibility } from "#build/eligibility"
|
|
@@ -164,6 +164,7 @@ export async function buildCorpus(opts: BuildCorpusOptions): Promise<BuildCorpus
|
|
|
164
164
|
licensePolicy,
|
|
165
165
|
excludeLicenses: settings.excludeLicenses,
|
|
166
166
|
holdouts,
|
|
167
|
+
trainShares: trainSharesOf(opts.adapterInputs),
|
|
167
168
|
eligibility: profile === BuildProfile.ReleaseEligible ? await readSourceEligibility() : null,
|
|
168
169
|
labeledPaths,
|
|
169
170
|
sourceIDPaths,
|
package/lib/de/recipes/locale.ts
CHANGED
|
@@ -44,9 +44,15 @@ import { alignRow } from "#utils"
|
|
|
44
44
|
/**
|
|
45
45
|
* The share of rows that write the Bundesland as `region` after the postcode and locality.
|
|
46
46
|
*
|
|
47
|
-
*
|
|
47
|
+
* Deutsche Post prints no Land.
|
|
48
|
+
* Every example in its UPU description ends `<postcode> <TOWN>` (`Wacholderweg 52a / 26133 OLDENBURG`).
|
|
49
|
+
*
|
|
50
|
+
* A typed query still writes one (`04860 Torgau, Sachsen`).
|
|
51
|
+
* A minority of rows keep it, so the operator's form stays the majority.
|
|
52
|
+
*
|
|
53
|
+
* A Berlin row never takes one, because the Land is the city (see `renderLocaleRow`).
|
|
48
54
|
*/
|
|
49
|
-
const BUNDESLAND_REGION_FRACTION = 0.
|
|
55
|
+
const BUNDESLAND_REGION_FRACTION = 0.2
|
|
50
56
|
|
|
51
57
|
/**
|
|
52
58
|
* A German OA source (cached zip) + the Bundesland the file covers (OA's region column is empty for DE).
|
|
@@ -169,7 +175,7 @@ export const germanRecipe: CorpusRecipe = {
|
|
|
169
175
|
},
|
|
170
176
|
{
|
|
171
177
|
flag: "--region-fraction <f>",
|
|
172
|
-
description: "Fraction of rows that write the Bundesland as region after the locality. Default 0.
|
|
178
|
+
description: "Fraction of rows that write the Bundesland as region after the locality. Default 0.2",
|
|
173
179
|
},
|
|
174
180
|
{
|
|
175
181
|
flag: "--ortsteil-fraction <f>",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
* under {@linkcode EvaluationAdapterRefusal.Duplicate}.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import { formatAddressRow } from "@mailwoman/codex/address/format"
|
|
20
19
|
import type { PathBuilderLike } from "path-ts"
|
|
21
20
|
|
|
22
21
|
import { UnsupportedCountryError } from "#adapters/errors"
|
|
23
22
|
import { stableSourceID } from "#adapters/source-id"
|
|
24
23
|
import type { EvaluationRecordReading, EvaluationSource } from "#evaluation/source"
|
|
24
|
+
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
25
25
|
import { type AddressRole, type CanonicalRow, type CorpusAdapter, countDropped, SurfaceOrigin } from "#types"
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -78,7 +78,7 @@ export function evaluationRecordRow(
|
|
|
78
78
|
if ("refused" in reading) return reading
|
|
79
79
|
|
|
80
80
|
const { country } = spec.source
|
|
81
|
-
const rendered =
|
|
81
|
+
const rendered = formatCorpusRow(reading.components, country, { singleLine: true })
|
|
82
82
|
|
|
83
83
|
if (!rendered || rendered.unplaced.length) return { refused: EvaluationAdapterRefusal.Unrenderable }
|
|
84
84
|
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
* It honors `opts.limit`, `opts.signal` and `opts.country`.
|
|
63
63
|
*/
|
|
64
64
|
|
|
65
|
-
import { formatAddressRow } from "@mailwoman/codex/address/format"
|
|
66
65
|
import { CSVSpliterator } from "spliterator"
|
|
67
66
|
|
|
68
67
|
import { UnsupportedCountryError } from "#adapters/errors"
|
|
69
68
|
import { stableSourceID } from "#adapters/source-id"
|
|
70
69
|
import { composeHouseNumber } from "#adapters/street/line"
|
|
71
70
|
import { SourceRegister } from "#registers"
|
|
71
|
+
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
72
72
|
import { AddressRole, type AdapterOptions, type CanonicalRow, type CorpusAdapter, SurfaceOrigin } from "#types"
|
|
73
73
|
|
|
74
74
|
/**
|
|
@@ -286,7 +286,7 @@ export function createRyhtiAdapter(): CorpusAdapter {
|
|
|
286
286
|
components.locality = surface.locality
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
const rendered =
|
|
289
|
+
const rendered = formatCorpusRow(components, country, { singleLine: true })
|
|
290
290
|
|
|
291
291
|
if (!rendered) continue
|
|
292
292
|
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
* Every row records those terms.
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
|
-
import { formatAddressRow } from "@mailwoman/codex/address/format"
|
|
33
32
|
import { readLocalTextFile } from "@mailwoman/core/fs/readers"
|
|
34
33
|
import { tryStat } from "@mailwoman/core/fs/readers/stat"
|
|
35
34
|
import { parseJSONStrict } from "@mailwoman/core/values/json"
|
|
@@ -42,6 +41,7 @@ import { present } from "#adapters/present"
|
|
|
42
41
|
import { stableSourceIDFromParts } from "#adapters/source-id"
|
|
43
42
|
import { composeHouseNumber } from "#adapters/street/line"
|
|
44
43
|
import { SourceRegister } from "#registers"
|
|
44
|
+
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
45
45
|
import {
|
|
46
46
|
AddressRole,
|
|
47
47
|
type AdapterOptions,
|
|
@@ -195,7 +195,7 @@ export function createAdressurFaroeAdapter(): CorpusAdapter {
|
|
|
195
195
|
|
|
196
196
|
if (!components) continue
|
|
197
197
|
|
|
198
|
-
const rendered =
|
|
198
|
+
const rendered = formatCorpusRow(components, "FO", {
|
|
199
199
|
singleLine: true,
|
|
200
200
|
})
|
|
201
201
|
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
import { extractBANAddrPoints } from "@mailwoman/ban/sdk/extract"
|
|
31
31
|
import { formatAddress } from "@mailwoman/codex/address/format"
|
|
32
32
|
import type { ComponentTag } from "@mailwoman/codex/component"
|
|
33
|
-
import {
|
|
33
|
+
import { countryRenderForms } from "@mailwoman/codex/country"
|
|
34
34
|
import { currentSourcePath } from "@mailwoman/core/data-root"
|
|
35
35
|
import { sample, shuffleWith } from "@mailwoman/core/math/random"
|
|
36
36
|
import { mulberry32 as makeMulberry32 } from "@mailwoman/core/utils"
|
|
@@ -249,10 +249,9 @@ export const frLieuditRecipe: CorpusRecipe = {
|
|
|
249
249
|
// This keeps the byte-stream a function of `countryFraction` rather than of
|
|
250
250
|
// the mixture of jurisdictions in the input files.
|
|
251
251
|
if (countryFraction > 0 && random() < countryFraction) {
|
|
252
|
-
const forms
|
|
253
|
-
COUNTRY_SURFACE_FORMS[country as keyof typeof COUNTRY_SURFACE_FORMS]
|
|
252
|
+
const forms = countryRenderForms(country)
|
|
254
253
|
|
|
255
|
-
if (forms) {
|
|
254
|
+
if (forms.length) {
|
|
256
255
|
const form = sample(forms, random)
|
|
257
256
|
raw = `${raw}, ${form}`
|
|
258
257
|
components.country = form
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reads the parts of an Indian street line written as one comma-separated field.
|
|
6
|
+
*
|
|
7
|
+
* A publisher that holds an Indian address as one free-text line
|
|
8
|
+
* writes it in the order India Post's UPU description shows
|
|
9
|
+
* (`https://www.upu.int/UPU/media/upu/PostalEntitiesFiles/addressingUnit/indEn.pdf`, 01/2013).
|
|
10
|
+
* The premise and the street come first, then the sub-localities from smallest to largest.
|
|
11
|
+
*
|
|
12
|
+
* Its examples are `4, Amrita Shergill Road`, `32/1, 2nd Main Road / 8th Block / Jayanagar`
|
|
13
|
+
* and `Flat 408, Tagore Road Hostel / Tagore Road`.
|
|
14
|
+
*
|
|
15
|
+
* {@linkcode segmentINStreetLine} labels a line only where every part it keeps has one reading:
|
|
16
|
+
* the premise number, a building name before the street, the street, and one sub-locality after it.
|
|
17
|
+
* Door, floor and shop designators and landmark phrases (`Near`, `Opp.`) are left out.
|
|
18
|
+
*
|
|
19
|
+
* The IN layout has no slot that prints them where the line wrote them.
|
|
20
|
+
* Any other part refuses the line.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { foldName as fold } from "@mailwoman/codex/names/normalize"
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The words that end an Indian thoroughfare's name, as the line writes them, folded to lower case.
|
|
27
|
+
*
|
|
28
|
+
* The English forms are libpostal's `en/street_types.txt` entries for road,
|
|
29
|
+
* street, lane, avenue, highway, bypass, cross and path, without the one-
|
|
30
|
+
* and two-letter forms (`r`, `l`, `la`) that end other words too.
|
|
31
|
+
* `marg` is libpostal's `hi/street_types.txt`.
|
|
32
|
+
*
|
|
33
|
+
* `main` (Bengaluru's `2nd Main Road` is also written `2nd Main`), `salai` (Tamil, as in `Anna Salai`)
|
|
34
|
+
* and `gali` (Hindi) are added here. libpostal's Hindi list also holds `nagar` and `bazar`.
|
|
35
|
+
* In Indian addresses those words end a neighborhood's name rather than a street's,
|
|
36
|
+
* so the table leaves them out.
|
|
37
|
+
*/
|
|
38
|
+
const THOROUGHFARE_WORDS: ReadonlySet<string> = new Set([
|
|
39
|
+
"road",
|
|
40
|
+
"rd",
|
|
41
|
+
"roa",
|
|
42
|
+
"street",
|
|
43
|
+
"st",
|
|
44
|
+
"str",
|
|
45
|
+
"lane",
|
|
46
|
+
"ln",
|
|
47
|
+
"avenue",
|
|
48
|
+
"ave",
|
|
49
|
+
"highway",
|
|
50
|
+
"hwy",
|
|
51
|
+
"bypass",
|
|
52
|
+
"byepass",
|
|
53
|
+
"cross",
|
|
54
|
+
"path",
|
|
55
|
+
"marg",
|
|
56
|
+
"main",
|
|
57
|
+
"salai",
|
|
58
|
+
"gali",
|
|
59
|
+
"galli",
|
|
60
|
+
])
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The words that end a building or complex name, folded to lower case.
|
|
64
|
+
*
|
|
65
|
+
* The UPU description writes `Astro High Complex` and `Tagore Road Hostel`,
|
|
66
|
+
* and street lines write `Tower`, `Plaza` and `Bhavan`.
|
|
67
|
+
* A part before the street is read as a building only when it ends in one of them.
|
|
68
|
+
*
|
|
69
|
+
* Lines also write a village or a neighborhood there (`Kurumassery, Angamaly Road`).
|
|
70
|
+
* No word of such a part tells it from a building.
|
|
71
|
+
*/
|
|
72
|
+
const BUILDING_WORDS: ReadonlySet<string> = new Set([
|
|
73
|
+
"apartment",
|
|
74
|
+
"apartments",
|
|
75
|
+
"arcade",
|
|
76
|
+
"bhavan",
|
|
77
|
+
"bhawan",
|
|
78
|
+
"building",
|
|
79
|
+
"buildings",
|
|
80
|
+
"centre",
|
|
81
|
+
"center",
|
|
82
|
+
"chambers",
|
|
83
|
+
"complex",
|
|
84
|
+
"court",
|
|
85
|
+
"heights",
|
|
86
|
+
"hostel",
|
|
87
|
+
"house",
|
|
88
|
+
"mall",
|
|
89
|
+
"mansion",
|
|
90
|
+
"plaza",
|
|
91
|
+
"residency",
|
|
92
|
+
"tower",
|
|
93
|
+
"towers",
|
|
94
|
+
])
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The fewest words a street or a building name holds, so a bare `Road` or `Complex` is neither.
|
|
98
|
+
*/
|
|
99
|
+
const MIN_NAME_WORDS = 2
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* A national or state highway written by its number, `NH 17` or `SH-4`.
|
|
103
|
+
*/
|
|
104
|
+
const NUMBERED_HIGHWAY = /^(?:NH|SH)[\s-]?\d+[A-Z]?$/i
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A premise number, optionally after the label a line writes before it
|
|
108
|
+
* (`No.`, `Door No`, `Plot No`, `H.No`, `#`).
|
|
109
|
+
*
|
|
110
|
+
* The number is digits, optionally with a slash, a hyphen or a letter
|
|
111
|
+
* (`32/1`, `21/5794`, `2/A1`, `49-1`, `5B`).
|
|
112
|
+
* Group 1 is the number without the label.
|
|
113
|
+
*/
|
|
114
|
+
const PREMISE_NUMBER =
|
|
115
|
+
/^(?:(?:no|door\s*no|d\.?\s*no|plot\s*no|h\.?\s*no|house\s*no|#)\.?\s*)?(\d+[A-Za-z]?(?:\s?[/-]\s?[0-9A-Za-z]{1,6}){0,2})$/i
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A street part that opens with its premise number: `No 14 Muthuvelapa Street`, `318 DB Road`.
|
|
119
|
+
*
|
|
120
|
+
* Group 1 is the number and group 2 the street.
|
|
121
|
+
* A number followed by a measure belongs to the street's name (`100 Ft. Road`), so it isn't split off.
|
|
122
|
+
*/
|
|
123
|
+
const NUMBER_THEN_STREET =
|
|
124
|
+
/^(?:(?:no|door\s*no|plot\s*no|h\.?\s*no|#)\.?\s*)?(\d+[A-Za-z]?(?:[/-][0-9A-Za-z]{1,6})?)\s+(?!(?:ft|feet|km|kms|mtrs?|met(?:er|re)s?)\b)(\S.*)$/i
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A door, floor, shop or flat designator: `Ground Floor`, `1st Floor`, `Gr Flr`, `Shop No 70`, `Flat 408`.
|
|
128
|
+
*/
|
|
129
|
+
const DESIGNATOR =
|
|
130
|
+
/^(?:(?:ground|gr\.?|grd\.?|upper|lower|first|second|third|fourth|fifth|top|\d+(?:st|nd|rd|th)?)\s*(?:floor|flr)\b|(?:shop|flat|office|unit|suite|room|stall|apartment|apt|door)\b)/i
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* A landmark phrase.
|
|
134
|
+
*
|
|
135
|
+
* It places the premise beside something else rather than giving its address.
|
|
136
|
+
*/
|
|
137
|
+
const LANDMARK =
|
|
138
|
+
/^(?:opp|opposite|near|nr|behind|beside|besides|next\s+to|adjacent|adj|in\s+front\s+of|off|above|inside)\b/i
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A landmark phrase inside a part, as in `318 DB Road Near Axis Bank`, which no one split of the part reads.
|
|
142
|
+
*/
|
|
143
|
+
const LANDMARK_INSIDE = /\s(?:opp|opposite|near|nr|behind|beside)\.?\s/i
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* A sub-province or post-office designator: a district, taluk or tehsil,
|
|
147
|
+
* a hobli or mandal, or a post office.
|
|
148
|
+
*
|
|
149
|
+
* The UPU description writes these on their own lines (`Pennukonda Taluk / Anantpur District`).
|
|
150
|
+
* The IN layout has no slot for them, so a line that holds one is refused.
|
|
151
|
+
*/
|
|
152
|
+
const SUB_PROVINCE =
|
|
153
|
+
/\b(?:dist|distt|district|sub-district|taluk|taluka|tehsil|tahsil|hobli|mandal|block|post|p\.?\s?o)\b\.?/i
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* A census sub-district numbered in Roman numerals, `Purulia-II`.
|
|
157
|
+
*/
|
|
158
|
+
const NUMBERED_SUB_DISTRICT = /[\s-](?:I|II|III|IV|V|VI)$/u
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Whether a value is a district, taluk, tehsil, hobli, mandal or post office,
|
|
162
|
+
* or a census sub-district numbered in Roman numerals, rather than a locality or a street.
|
|
163
|
+
*/
|
|
164
|
+
export function isINSubProvince(value: string): boolean {
|
|
165
|
+
return SUB_PROVINCE.test(value) || NUMBERED_SUB_DISTRICT.test(value.trim())
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* A sub-locality as a line writes it after the street: a name of letters, at least three of them, with
|
|
170
|
+
* the spaces, dots, hyphens and apostrophes a name holds (`Jayanagar`, `R.S. Puram`, `Kalyan Nagar`).
|
|
171
|
+
*/
|
|
172
|
+
const SUB_LOCALITY = /^[\p{L}\p{M}][\p{L}\p{M} .'-]{2,}$/u
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The numbers a street's name holds: an ordinal (`2nd Main Road`), a numbered highway (`NH 17`),
|
|
176
|
+
* a measure (`100 Ft. Road`, `12th KM`) and a sector, phase or stage (`Sector 11 Road`).
|
|
177
|
+
*/
|
|
178
|
+
const NUMBER_IN_STREET_NAME =
|
|
179
|
+
/\b\d+(?:st|nd|rd|th)\b|\b(?:NH|SH)[\s-]?\d+[A-Z]?\b|\b\d+\s*(?:ft|feet|km|kms|mtrs?|met(?:er|re)s?)\b|\b(?:sector|phase|stage)[\s-]?\d+[A-Z]?\b/giu
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Whether a street holds a digit its name doesn't account for,
|
|
183
|
+
* as `MORARJEE VELJEE BLDGR 16 KOLBHAT LANE` holds a building's number.
|
|
184
|
+
*/
|
|
185
|
+
function streetHoldsNumber(street: string): boolean {
|
|
186
|
+
return /\d/u.test(street.replaceAll(NUMBER_IN_STREET_NAME, ""))
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* A PIN code written into the street line: six digits, with an optional space after the third.
|
|
191
|
+
*/
|
|
192
|
+
const PIN_IN_LINE = /(?<!\d)\d{3}\s?\d{3}(?!\d)/u
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Why a line was not labeled.
|
|
196
|
+
*/
|
|
197
|
+
export const INStreetLineRefusal = {
|
|
198
|
+
/**
|
|
199
|
+
* The line is empty once the parts that repeat the locality or the state are removed.
|
|
200
|
+
*/
|
|
201
|
+
Empty: "empty",
|
|
202
|
+
/**
|
|
203
|
+
* The line writes a six-digit number: the PIN code, written into the street line.
|
|
204
|
+
*/
|
|
205
|
+
PostcodeInLine: "postcode-in-line",
|
|
206
|
+
/**
|
|
207
|
+
* The line holds a district, taluk, tehsil, hobli, mandal or post office.
|
|
208
|
+
*/
|
|
209
|
+
SubProvinceInLine: "sub-province-in-line",
|
|
210
|
+
/**
|
|
211
|
+
* A landmark phrase sits inside a part rather than in a part of its own.
|
|
212
|
+
*/
|
|
213
|
+
LandmarkInsidePart: "landmark-inside-part",
|
|
214
|
+
/**
|
|
215
|
+
* No part ends in a thoroughfare word.
|
|
216
|
+
*/
|
|
217
|
+
NoThoroughfare: "no-thoroughfare",
|
|
218
|
+
/**
|
|
219
|
+
* More than one part before the street remains once designators and the premise number are
|
|
220
|
+
* removed, or the one that remains isn't a building name (`RS No 514/4`, a village name).
|
|
221
|
+
*/
|
|
222
|
+
PremiseUnread: "premise-unread",
|
|
223
|
+
/**
|
|
224
|
+
* The street holds a digit its name doesn't account for, such as a building's number inside it.
|
|
225
|
+
*/
|
|
226
|
+
StreetHoldsNumber: "street-holds-number",
|
|
227
|
+
/**
|
|
228
|
+
* More than one part follows the street, or the part that does isn't a name of three letters or more.
|
|
229
|
+
*/
|
|
230
|
+
SubLocalityUnread: "sub-locality-unread",
|
|
231
|
+
} as const
|
|
232
|
+
|
|
233
|
+
export type INStreetLineRefusal = (typeof INStreetLineRefusal)[keyof typeof INStreetLineRefusal]
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The parts of an Indian street line, labeled.
|
|
237
|
+
*/
|
|
238
|
+
export interface INStreetLineParts {
|
|
239
|
+
house_number?: string
|
|
240
|
+
/**
|
|
241
|
+
* A building or complex name written before the street, as `Tagore Road Hostel` is in the UPU description.
|
|
242
|
+
*/
|
|
243
|
+
venue?: string
|
|
244
|
+
street: string
|
|
245
|
+
dependent_locality?: string
|
|
246
|
+
/**
|
|
247
|
+
* The count of designator and landmark parts left out.
|
|
248
|
+
*/
|
|
249
|
+
omitted: number
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* The fields of the record beside the line.
|
|
254
|
+
* A line may repeat their values.
|
|
255
|
+
*/
|
|
256
|
+
export interface INStreetLineContext {
|
|
257
|
+
locality?: string | null
|
|
258
|
+
region?: string | null
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* A part's words in lower case, with the punctuation at either end of each word removed (`Rd.` → `rd`).
|
|
263
|
+
*/
|
|
264
|
+
function foldedWords(part: string): string[] {
|
|
265
|
+
return part
|
|
266
|
+
.toLowerCase()
|
|
267
|
+
.split(/\s+/u)
|
|
268
|
+
.map((word) => word.replaceAll(/^[\p{P}]+|[\p{P}]+$/gu, ""))
|
|
269
|
+
.filter((word) => word.length > 0)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Whether a part is a street: its last word is a thoroughfare word, or it is a numbered highway.
|
|
274
|
+
*/
|
|
275
|
+
function isINThoroughfare(part: string): boolean {
|
|
276
|
+
if (NUMBERED_HIGHWAY.test(part.trim())) return true
|
|
277
|
+
|
|
278
|
+
const words = foldedWords(part)
|
|
279
|
+
|
|
280
|
+
return words.length >= MIN_NAME_WORDS && THOROUGHFARE_WORDS.has(words.at(-1)!)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Whether a part is a building's name: its last word a building word, and no digit.
|
|
285
|
+
*/
|
|
286
|
+
function isINBuilding(part: string): boolean {
|
|
287
|
+
const words = foldedWords(part)
|
|
288
|
+
|
|
289
|
+
return words.length >= MIN_NAME_WORDS && BUILDING_WORDS.has(words.at(-1)!) && !/\d/u.test(part)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Label the parts of an Indian street line, or return the reason it can't be labeled.
|
|
294
|
+
*/
|
|
295
|
+
export function segmentINStreetLine(
|
|
296
|
+
line: string,
|
|
297
|
+
context: INStreetLineContext = {}
|
|
298
|
+
): INStreetLineParts | { refused: INStreetLineRefusal } {
|
|
299
|
+
const echoes = new Set(
|
|
300
|
+
[context.locality, context.region].filter((value) => value?.trim()).map((value) => fold(value!))
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
const parts = line
|
|
304
|
+
.replaceAll(/\s+/gu, " ")
|
|
305
|
+
.split(/\s*,\s*/u)
|
|
306
|
+
.map((part) => part.trim().replace(/[.;:-]+$/u, ""))
|
|
307
|
+
.filter((part) => part.length > 0 && !echoes.has(fold(part)))
|
|
308
|
+
|
|
309
|
+
if (!parts.length) return { refused: INStreetLineRefusal.Empty }
|
|
310
|
+
|
|
311
|
+
if (parts.some((part) => PIN_IN_LINE.test(part))) return { refused: INStreetLineRefusal.PostcodeInLine }
|
|
312
|
+
|
|
313
|
+
if (parts.some(isINSubProvince)) return { refused: INStreetLineRefusal.SubProvinceInLine }
|
|
314
|
+
|
|
315
|
+
if (parts.some((part) => LANDMARK_INSIDE.test(` ${part} `) && !LANDMARK.test(part))) {
|
|
316
|
+
return { refused: INStreetLineRefusal.LandmarkInsidePart }
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
let omitted = 0
|
|
320
|
+
const kept: string[] = []
|
|
321
|
+
|
|
322
|
+
for (const part of parts) {
|
|
323
|
+
if (DESIGNATOR.test(part) || LANDMARK.test(part)) {
|
|
324
|
+
omitted++
|
|
325
|
+
} else {
|
|
326
|
+
kept.push(part)
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const streetAt = kept.findIndex(isINThoroughfare)
|
|
331
|
+
|
|
332
|
+
if (streetAt === -1) return { refused: INStreetLineRefusal.NoThoroughfare }
|
|
333
|
+
|
|
334
|
+
let street = kept[streetAt]!
|
|
335
|
+
let houseNumber: string | undefined
|
|
336
|
+
const before = kept.slice(0, streetAt)
|
|
337
|
+
const after = kept.slice(streetAt + 1)
|
|
338
|
+
const leading = NUMBER_THEN_STREET.exec(street)
|
|
339
|
+
|
|
340
|
+
if (leading && isINThoroughfare(leading[2]!)) {
|
|
341
|
+
houseNumber = leading[1]!
|
|
342
|
+
street = leading[2]!
|
|
343
|
+
} else {
|
|
344
|
+
// The premise number may stand before a building name (`No. 484/2, Rithvi Tower, Perundurai Rd`).
|
|
345
|
+
const at = before.findLastIndex((part) => PREMISE_NUMBER.test(part))
|
|
346
|
+
|
|
347
|
+
if (at !== -1) {
|
|
348
|
+
houseNumber = PREMISE_NUMBER.exec(before[at]!)![1]!
|
|
349
|
+
before.splice(at, 1)
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (streetHoldsNumber(street)) return { refused: INStreetLineRefusal.StreetHoldsNumber }
|
|
354
|
+
|
|
355
|
+
if (before.length > 1 || (before.length === 1 && !isINBuilding(before[0]!))) {
|
|
356
|
+
return { refused: INStreetLineRefusal.PremiseUnread }
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (after.length > 1 || (after.length === 1 && !SUB_LOCALITY.test(after[0]!))) {
|
|
360
|
+
return { refused: INStreetLineRefusal.SubLocalityUnread }
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return {
|
|
364
|
+
...(houseNumber ? { house_number: houseNumber.replaceAll(/\s+/gu, "") } : {}),
|
|
365
|
+
...(before.length ? { venue: before[0]! } : {}),
|
|
366
|
+
street,
|
|
367
|
+
...(after.length ? { dependent_locality: after[0]! } : {}),
|
|
368
|
+
omitted,
|
|
369
|
+
}
|
|
370
|
+
}
|