@mailwoman/corpus 11.3.0 → 11.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/PROVENANCE.md +3 -4
- package/data/address-source-register.json +4 -4
- package/data/builds/v0.8.23-overlay/OVERLAY_PLAN.json +3656 -0
- package/data/builds/v0.8.23-prominent-overlay/OVERLAY_PLAN.json +42 -0
- package/data/builds/v0.8.23-rebuild/inputs.json +141 -0
- package/data/builds/v0.8.24-rebuild/inputs.json +111 -0
- package/data/corpus-source-inputs.json +95 -1
- package/data/holdout/evaluation-groups.v0.8.24.json +222158 -0
- package/data/license-decisions.json +5 -0
- package/data/region-slot-second-level.json +1 -1
- package/data/training-configs/v8.11.0-base-c6-90k-v0823-s42.yaml +920 -0
- package/data/training-configs/v8.12.0-base-c6-wofreps-v0823-s42.yaml +944 -0
- package/data/training-configs/v8.13.0-base-c6-wofreps-v0822-s42.yaml +918 -0
- package/lib/adapters/cordis/adapter.ts +3 -2
- package/lib/adapters/gleif/adapter.ts +123 -20
- package/lib/adapters/openaddresses/adapter.ts +2 -2
- package/lib/adapters/osm/adapter.ts +62 -4
- package/lib/adapters/overture/adapter.ts +97 -15
- package/lib/adapters/overture/address-key.ts +89 -0
- package/lib/adapters/overture/places-in/adapter.ts +258 -0
- package/lib/adapters/street/convention.ts +49 -0
- package/lib/adapters/street/country-line.ts +65 -0
- package/lib/adapters/wof/admin/json/adapter.ts +4 -4
- package/lib/adapters/wof/admin/json/region-codes.ts +98 -0
- package/lib/adapters/wof/json-rows.ts +2 -2
- package/lib/adapters.ts +2 -0
- package/lib/build/align/range.ts +21 -11
- package/lib/build/align/totals.ts +20 -0
- package/lib/build/align.ts +218 -20
- package/lib/build/budget.ts +55 -20
- package/lib/build/checkpoint.ts +9 -0
- package/lib/build/component-check.ts +97 -3
- package/lib/build/inputs.ts +122 -31
- package/lib/build/manifest.ts +1 -0
- package/lib/build/parallel.ts +140 -23
- package/lib/build/{region-names.ts → region/names.ts} +16 -4
- package/lib/build/region/recount.ts +153 -0
- package/lib/build/reuse.ts +112 -0
- package/lib/build/settings.ts +84 -3
- package/lib/build/source-record.ts +45 -8
- package/lib/build/types.ts +26 -0
- package/lib/build/worker.ts +75 -10
- package/lib/build.ts +2 -1
- package/lib/de/recipes/locale.ts +9 -3
- package/lib/evaluation/corpus-adapter.ts +2 -2
- package/lib/fi/adapters/ryhti/adapter.ts +2 -2
- package/lib/fo/adapters/adressur/adapter.ts +2 -2
- package/lib/fr/recipes/lieudit.ts +3 -4
- package/lib/in/street-line/segment.ts +370 -0
- package/lib/international/recipes/locale.ts +6 -3
- package/lib/li/adapters/llv/adapter.ts +2 -2
- package/lib/lu/adapters/bd-adresses/adapter.ts +2 -2
- package/lib/no/adapters/matrikkelen/adapter.ts +2 -2
- package/lib/parquet/streams.ts +18 -3
- package/lib/parquet/writers.ts +161 -29
- package/lib/recipes/country-balanced.ts +32 -18
- package/lib/recipes/fragment-assay/build.ts +8 -5
- package/lib/recipes/fragment-assay/rows.ts +4 -4
- package/lib/recipes/house/venue.ts +2 -1
- package/lib/recipes/postal/guideline/leg.ts +3 -2
- package/lib/recipes/prominent/places.ts +4 -4
- package/lib/runner.ts +139 -20
- package/lib/sg/recipes/register.ts +6 -1
- package/lib/source-register/row-license.ts +12 -2
- package/lib/surfaces/corpus-row.ts +84 -0
- package/lib/surfaces/locale.ts +20 -24
- package/lib/synthesizers/house-venue.ts +33 -40
- package/lib/synthesizers/no-street.ts +2 -2
- package/lib/synthesizers/po-box.ts +3 -3
- package/lib/synthesizers/tail.ts +3 -2
- package/lib/synthesizers/utils.ts +95 -56
- package/lib/test-kit.ts +50 -1
- package/lib/tools/fetch/overture-places-in.ts +118 -0
- package/lib/tools/fetch/storage.ts +3 -0
- package/lib/tools/fetch.ts +2 -0
- package/lib/tools/region-slot-census.run.ts +2 -2
- package/lib/types.ts +39 -0
- package/lib/us/adapters/state/tx-notaries/adapter.ts +2 -1
- package/lib/us/adapters/usgov/imls-pls/adapter.ts +2 -1
- package/lib/us/adapters/usgov/nad/adapter.ts +32 -4
- package/lib/us/adapters/usgov/nad/address-key.ts +8 -47
- package/lib/us/adapters/usgov/nppes/adapter.ts +2 -1
- package/lib/utils/address-key.ts +57 -0
- package/lib/utils/align.ts +22 -10
- package/lib/utils/evaluation-groups.ts +13 -6
- package/lib/utils/split.ts +24 -3
- package/out/adapters/cordis/adapter.d.ts.map +1 -1
- package/out/adapters/cordis/adapter.js +3 -2
- package/out/adapters/cordis/adapter.js.map +1 -1
- package/out/adapters/gleif/adapter.d.ts +4 -0
- package/out/adapters/gleif/adapter.d.ts.map +1 -1
- package/out/adapters/gleif/adapter.js +100 -20
- package/out/adapters/gleif/adapter.js.map +1 -1
- package/out/adapters/openaddresses/adapter.js +2 -2
- package/out/adapters/openaddresses/adapter.js.map +1 -1
- package/out/adapters/osm/adapter.d.ts +9 -0
- package/out/adapters/osm/adapter.d.ts.map +1 -1
- package/out/adapters/osm/adapter.js +55 -13
- package/out/adapters/osm/adapter.js.map +1 -1
- package/out/adapters/overture/adapter.d.ts +6 -0
- package/out/adapters/overture/adapter.d.ts.map +1 -1
- package/out/adapters/overture/adapter.js +72 -9
- package/out/adapters/overture/adapter.js.map +1 -1
- package/out/adapters/overture/address-key.d.ts +39 -0
- package/out/adapters/overture/address-key.d.ts.map +1 -0
- package/out/adapters/overture/address-key.js +75 -0
- package/out/adapters/overture/address-key.js.map +1 -0
- package/out/adapters/overture/places-in/adapter.d.ts +20 -0
- package/out/adapters/overture/places-in/adapter.d.ts.map +1 -0
- package/out/adapters/overture/places-in/adapter.js +191 -0
- package/out/adapters/overture/places-in/adapter.js.map +1 -0
- package/out/adapters/street/convention.d.ts +11 -0
- package/out/adapters/street/convention.d.ts.map +1 -0
- package/out/adapters/street/convention.js +40 -0
- package/out/adapters/street/convention.js.map +1 -0
- package/out/adapters/street/country-line.d.ts +31 -0
- package/out/adapters/street/country-line.d.ts.map +1 -0
- package/out/adapters/street/country-line.js +31 -0
- package/out/adapters/street/country-line.js.map +1 -0
- package/out/adapters/wof/admin/json/adapter.js +4 -4
- package/out/adapters/wof/admin/json/adapter.js.map +1 -1
- package/out/adapters/wof/admin/json/region-codes.d.ts +5 -0
- package/out/adapters/wof/admin/json/region-codes.d.ts.map +1 -1
- package/out/adapters/wof/admin/json/region-codes.js +83 -0
- package/out/adapters/wof/admin/json/region-codes.js.map +1 -1
- package/out/adapters/wof/json-rows.d.ts.map +1 -1
- package/out/adapters/wof/json-rows.js +2 -2
- package/out/adapters/wof/json-rows.js.map +1 -1
- package/out/adapters.d.ts.map +1 -1
- package/out/adapters.js +2 -0
- package/out/adapters.js.map +1 -1
- package/out/build/align/range.d.ts +7 -3
- package/out/build/align/range.d.ts.map +1 -1
- package/out/build/align/range.js +17 -9
- package/out/build/align/range.js.map +1 -1
- package/out/build/align/totals.d.ts +12 -0
- package/out/build/align/totals.d.ts.map +1 -1
- package/out/build/align/totals.js +8 -0
- package/out/build/align/totals.js.map +1 -1
- package/out/build/align.d.ts +60 -5
- package/out/build/align.d.ts.map +1 -1
- package/out/build/align.js +136 -12
- package/out/build/align.js.map +1 -1
- package/out/build/budget.d.ts +35 -11
- package/out/build/budget.d.ts.map +1 -1
- package/out/build/budget.js +52 -20
- package/out/build/budget.js.map +1 -1
- package/out/build/checkpoint.d.ts +9 -0
- package/out/build/checkpoint.d.ts.map +1 -1
- package/out/build/checkpoint.js.map +1 -1
- package/out/build/component-check.d.ts +29 -1
- package/out/build/component-check.d.ts.map +1 -1
- package/out/build/component-check.js +57 -2
- package/out/build/component-check.js.map +1 -1
- package/out/build/inputs.d.ts +58 -0
- package/out/build/inputs.d.ts.map +1 -1
- package/out/build/inputs.js +57 -20
- package/out/build/inputs.js.map +1 -1
- package/out/build/manifest.d.ts.map +1 -1
- package/out/build/manifest.js +1 -0
- package/out/build/manifest.js.map +1 -1
- package/out/build/parallel.d.ts +19 -1
- package/out/build/parallel.d.ts.map +1 -1
- package/out/build/parallel.js +92 -11
- package/out/build/parallel.js.map +1 -1
- package/out/build/{region-names.d.ts → region/names.d.ts} +10 -1
- package/out/build/region/names.d.ts.map +1 -0
- package/out/build/{region-names.js → region/names.js} +16 -5
- package/out/build/region/names.js.map +1 -0
- package/out/build/region/recount.d.ts +47 -0
- package/out/build/region/recount.d.ts.map +1 -0
- package/out/build/region/recount.js +105 -0
- package/out/build/region/recount.js.map +1 -0
- package/out/build/reuse.d.ts +31 -0
- package/out/build/reuse.d.ts.map +1 -0
- package/out/build/reuse.js +50 -0
- package/out/build/reuse.js.map +1 -0
- package/out/build/settings.d.ts +38 -0
- package/out/build/settings.d.ts.map +1 -1
- package/out/build/settings.js +67 -3
- package/out/build/settings.js.map +1 -1
- package/out/build/source-record.d.ts +32 -7
- package/out/build/source-record.d.ts.map +1 -1
- package/out/build/source-record.js +17 -4
- package/out/build/source-record.js.map +1 -1
- package/out/build/types.d.ts +24 -0
- package/out/build/types.d.ts.map +1 -1
- package/out/build/worker.d.ts +17 -0
- package/out/build/worker.d.ts.map +1 -1
- package/out/build/worker.js +44 -9
- package/out/build/worker.js.map +1 -1
- package/out/build.d.ts.map +1 -1
- package/out/build.js +2 -1
- package/out/build.js.map +1 -1
- package/out/de/recipes/locale.d.ts.map +1 -1
- package/out/de/recipes/locale.js +9 -3
- package/out/de/recipes/locale.js.map +1 -1
- package/out/evaluation/corpus-adapter.d.ts +14 -0
- package/out/evaluation/corpus-adapter.d.ts.map +1 -1
- package/out/evaluation/corpus-adapter.js +2 -16
- package/out/evaluation/corpus-adapter.js.map +1 -1
- package/out/fi/adapters/ryhti/adapter.js +2 -2
- package/out/fi/adapters/ryhti/adapter.js.map +1 -1
- package/out/fo/adapters/adressur/adapter.js +2 -2
- package/out/fo/adapters/adressur/adapter.js.map +1 -1
- package/out/fr/recipes/lieudit.d.ts.map +1 -1
- package/out/fr/recipes/lieudit.js +3 -3
- package/out/fr/recipes/lieudit.js.map +1 -1
- package/out/in/street-line/segment.d.ts +75 -0
- package/out/in/street-line/segment.d.ts.map +1 -0
- package/out/in/street-line/segment.js +298 -0
- package/out/in/street-line/segment.js.map +1 -0
- package/out/international/recipes/locale.d.ts.map +1 -1
- package/out/international/recipes/locale.js +6 -3
- package/out/international/recipes/locale.js.map +1 -1
- package/out/li/adapters/llv/adapter.js +2 -2
- package/out/li/adapters/llv/adapter.js.map +1 -1
- package/out/lu/adapters/bd-adresses/adapter.js +2 -2
- package/out/lu/adapters/bd-adresses/adapter.js.map +1 -1
- package/out/no/adapters/matrikkelen/adapter.js +2 -2
- package/out/no/adapters/matrikkelen/adapter.js.map +1 -1
- package/out/parquet/streams.d.ts +9 -0
- package/out/parquet/streams.d.ts.map +1 -1
- package/out/parquet/streams.js +7 -3
- package/out/parquet/streams.js.map +1 -1
- package/out/parquet/writers.d.ts +55 -2
- package/out/parquet/writers.d.ts.map +1 -1
- package/out/parquet/writers.js +109 -27
- package/out/parquet/writers.js.map +1 -1
- package/out/recipes/country-balanced.d.ts.map +1 -1
- package/out/recipes/country-balanced.js +32 -15
- package/out/recipes/country-balanced.js.map +1 -1
- package/out/recipes/fragment-assay/build.d.ts +5 -2
- package/out/recipes/fragment-assay/build.d.ts.map +1 -1
- package/out/recipes/fragment-assay/build.js +8 -5
- package/out/recipes/fragment-assay/build.js.map +1 -1
- package/out/recipes/fragment-assay/rows.d.ts +2 -2
- package/out/recipes/fragment-assay/rows.js +4 -4
- package/out/recipes/fragment-assay/rows.js.map +1 -1
- package/out/recipes/house/venue.d.ts.map +1 -1
- package/out/recipes/house/venue.js +2 -1
- package/out/recipes/house/venue.js.map +1 -1
- package/out/recipes/postal/guideline/leg.d.ts.map +1 -1
- package/out/recipes/postal/guideline/leg.js +2 -7
- package/out/recipes/postal/guideline/leg.js.map +1 -1
- package/out/recipes/prominent/places.js +4 -4
- package/out/recipes/prominent/places.js.map +1 -1
- package/out/runner.d.ts +28 -0
- package/out/runner.d.ts.map +1 -1
- package/out/runner.js +85 -18
- package/out/runner.js.map +1 -1
- package/out/sg/recipes/register.d.ts.map +1 -1
- package/out/sg/recipes/register.js +6 -1
- package/out/sg/recipes/register.js.map +1 -1
- package/out/source-register/row-license.d.ts +8 -0
- package/out/source-register/row-license.d.ts.map +1 -1
- package/out/source-register/row-license.js +10 -2
- package/out/source-register/row-license.js.map +1 -1
- package/out/surfaces/corpus-row.d.ts +32 -0
- package/out/surfaces/corpus-row.d.ts.map +1 -0
- package/out/surfaces/corpus-row.js +70 -0
- package/out/surfaces/corpus-row.js.map +1 -0
- package/out/surfaces/locale.d.ts.map +1 -1
- package/out/surfaces/locale.js +16 -22
- package/out/surfaces/locale.js.map +1 -1
- package/out/synthesizers/house-venue.d.ts +9 -4
- package/out/synthesizers/house-venue.d.ts.map +1 -1
- package/out/synthesizers/house-venue.js +25 -35
- package/out/synthesizers/house-venue.js.map +1 -1
- package/out/synthesizers/no-street.js +2 -9
- package/out/synthesizers/no-street.js.map +1 -1
- package/out/synthesizers/po-box.js +3 -7
- package/out/synthesizers/po-box.js.map +1 -1
- package/out/synthesizers/tail.d.ts.map +1 -1
- package/out/synthesizers/tail.js +2 -2
- package/out/synthesizers/tail.js.map +1 -1
- package/out/synthesizers/utils.d.ts +20 -3
- package/out/synthesizers/utils.d.ts.map +1 -1
- package/out/synthesizers/utils.js +74 -57
- package/out/synthesizers/utils.js.map +1 -1
- package/out/test-kit.d.ts +11 -0
- package/out/test-kit.d.ts.map +1 -1
- package/out/test-kit.js +30 -1
- package/out/test-kit.js.map +1 -1
- package/out/tools/fetch/overture-places-in.d.ts +14 -0
- package/out/tools/fetch/overture-places-in.d.ts.map +1 -0
- package/out/tools/fetch/overture-places-in.js +82 -0
- package/out/tools/fetch/overture-places-in.js.map +1 -0
- package/out/tools/fetch/storage.d.ts +2 -0
- package/out/tools/fetch/storage.d.ts.map +1 -1
- package/out/tools/fetch/storage.js +3 -0
- package/out/tools/fetch/storage.js.map +1 -1
- package/out/tools/fetch.d.ts +2 -0
- package/out/tools/fetch.d.ts.map +1 -1
- package/out/tools/fetch.js +2 -0
- package/out/tools/fetch.js.map +1 -1
- package/out/tools/region-slot-census.run.js +2 -2
- package/out/types.d.ts +41 -0
- package/out/types.d.ts.map +1 -1
- package/out/types.js.map +1 -1
- package/out/us/adapters/state/tx-notaries/adapter.d.ts.map +1 -1
- package/out/us/adapters/state/tx-notaries/adapter.js +2 -1
- package/out/us/adapters/state/tx-notaries/adapter.js.map +1 -1
- package/out/us/adapters/usgov/imls-pls/adapter.d.ts.map +1 -1
- package/out/us/adapters/usgov/imls-pls/adapter.js +2 -1
- package/out/us/adapters/usgov/imls-pls/adapter.js.map +1 -1
- package/out/us/adapters/usgov/nad/adapter.d.ts +15 -0
- package/out/us/adapters/usgov/nad/adapter.d.ts.map +1 -1
- package/out/us/adapters/usgov/nad/adapter.js +21 -3
- package/out/us/adapters/usgov/nad/adapter.js.map +1 -1
- package/out/us/adapters/usgov/nad/address-key.d.ts +1 -5
- package/out/us/adapters/usgov/nad/address-key.d.ts.map +1 -1
- package/out/us/adapters/usgov/nad/address-key.js +8 -33
- package/out/us/adapters/usgov/nad/address-key.js.map +1 -1
- package/out/us/adapters/usgov/nppes/adapter.d.ts.map +1 -1
- package/out/us/adapters/usgov/nppes/adapter.js +2 -1
- package/out/us/adapters/usgov/nppes/adapter.js.map +1 -1
- package/out/utils/address-key.d.ts +23 -0
- package/out/utils/address-key.d.ts.map +1 -0
- package/out/utils/address-key.js +43 -0
- package/out/utils/address-key.js.map +1 -0
- package/out/utils/align.d.ts +7 -0
- package/out/utils/align.d.ts.map +1 -1
- package/out/utils/align.js +18 -8
- package/out/utils/align.js.map +1 -1
- package/out/utils/evaluation-groups.d.ts +5 -1
- package/out/utils/evaluation-groups.d.ts.map +1 -1
- package/out/utils/evaluation-groups.js +12 -1
- package/out/utils/evaluation-groups.js.map +1 -1
- package/out/utils/split.d.ts +11 -0
- package/out/utils/split.d.ts.map +1 -1
- package/out/utils/split.js +18 -3
- package/out/utils/split.js.map +1 -1
- package/package.json +19 -19
- package/out/build/region-names.d.ts.map +0 -1
- package/out/build/region-names.js.map +0 -1
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* Synthesis and augmentation utilities.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { formatAddressRow } from "@mailwoman/codex/address/format"
|
|
9
8
|
import type { BIOLabel, ComponentTag } from "@mailwoman/codex/component"
|
|
10
9
|
import {
|
|
11
10
|
US_STREET_SUFFIX_PREFERRED_ABBR,
|
|
@@ -19,14 +18,43 @@ import { isPresent } from "@mailwoman/core/values/objects"
|
|
|
19
18
|
import { stripCombiningMarks } from "@mailwoman/normalize/fold"
|
|
20
19
|
import { matchCase } from "spliterator"
|
|
21
20
|
|
|
21
|
+
import { formatCorpusRow } from "#surfaces/corpus-row"
|
|
22
22
|
import type { CanonicalRow, LabeledRow, QuarantinedRow } from "#types"
|
|
23
23
|
import { alignRow, assertSpanInvariants, type ComponentSpan } from "#utils/align"
|
|
24
24
|
import { whitespaceTokenizer, type Tokenizer } from "#utils/tokenize"
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* One augmentation: a function from a row to its variant, or `null` when the row
|
|
28
|
+
* offers no text to vary, with its method name.
|
|
29
|
+
*
|
|
30
|
+
* The variant writes that name as its `augmentation.name` and as its `source_id` suffix.
|
|
31
|
+
*
|
|
32
|
+
* The name lets a caller decide whether it wants a variant before the augmentation runs.
|
|
33
|
+
*/
|
|
34
|
+
export interface Augmentation {
|
|
35
|
+
(row: CanonicalRow): CanonicalRow | null
|
|
36
|
+
readonly method: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Builds the variant of the row an augmentation's body was given, under the augmentation's method name.
|
|
41
|
+
*/
|
|
42
|
+
type EmitVariant = (newRaw: string, newComponents: ComponentDict) => CanonicalRow
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Defines an augmentation whose method name is `method`.
|
|
46
|
+
*
|
|
47
|
+
* Its body builds the variant through `emit`, so the name is written once.
|
|
28
48
|
*/
|
|
29
|
-
|
|
49
|
+
function augmentation(
|
|
50
|
+
method: string,
|
|
51
|
+
body: (row: CanonicalRow, emit: EmitVariant) => CanonicalRow | null
|
|
52
|
+
): Augmentation {
|
|
53
|
+
const apply = (row: CanonicalRow): CanonicalRow | null =>
|
|
54
|
+
body(row, (newRaw, newComponents) => withAugmentation(row, method, newRaw, newComponents))
|
|
55
|
+
|
|
56
|
+
return Object.assign(apply, { method })
|
|
57
|
+
}
|
|
30
58
|
|
|
31
59
|
type ComponentDict = Partial<Record<ComponentTag, string>>
|
|
32
60
|
|
|
@@ -55,7 +83,7 @@ function withAugmentation(
|
|
|
55
83
|
/**
|
|
56
84
|
* Upper-case raw and components.
|
|
57
85
|
*/
|
|
58
|
-
export const caseUpper
|
|
86
|
+
export const caseUpper = augmentation("case-upper", (row, emit) => {
|
|
59
87
|
if (row.raw === row.raw.toUpperCase()) return null
|
|
60
88
|
const upRaw = row.raw.toUpperCase()
|
|
61
89
|
const upComponents: ComponentDict = {}
|
|
@@ -66,13 +94,13 @@ export const caseUpper: Augmentation = (row) => {
|
|
|
66
94
|
}
|
|
67
95
|
}
|
|
68
96
|
|
|
69
|
-
return
|
|
70
|
-
}
|
|
97
|
+
return emit(upRaw, upComponents)
|
|
98
|
+
})
|
|
71
99
|
|
|
72
100
|
/**
|
|
73
101
|
* Lower-case raw and components.
|
|
74
102
|
*/
|
|
75
|
-
export const caseLower
|
|
103
|
+
export const caseLower = augmentation("case-lower", (row, emit) => {
|
|
76
104
|
if (row.raw === row.raw.toLowerCase()) return null
|
|
77
105
|
const downRaw = row.raw.toLowerCase()
|
|
78
106
|
const downComponents: ComponentDict = {}
|
|
@@ -83,8 +111,8 @@ export const caseLower: Augmentation = (row) => {
|
|
|
83
111
|
}
|
|
84
112
|
}
|
|
85
113
|
|
|
86
|
-
return
|
|
87
|
-
}
|
|
114
|
+
return emit(downRaw, downComponents)
|
|
115
|
+
})
|
|
88
116
|
|
|
89
117
|
/**
|
|
90
118
|
* Drop commas from raw and from every component, each the same way.
|
|
@@ -93,7 +121,7 @@ export const caseLower: Augmentation = (row) => {
|
|
|
93
121
|
* The aligner places a span of the component's length, so a component left one character
|
|
94
122
|
* longer than its text in raw ends its span on the space after it.
|
|
95
123
|
*/
|
|
96
|
-
export const dropCommas
|
|
124
|
+
export const dropCommas = augmentation("drop-commas", (row, emit) => {
|
|
97
125
|
if (!row.raw.includes(",")) return null
|
|
98
126
|
const strip = (text: string) => text.replaceAll(",", "").replaceAll(/\s+/g, " ").trim()
|
|
99
127
|
const components: ComponentDict = {}
|
|
@@ -104,13 +132,13 @@ export const dropCommas: Augmentation = (row) => {
|
|
|
104
132
|
}
|
|
105
133
|
}
|
|
106
134
|
|
|
107
|
-
return
|
|
108
|
-
}
|
|
135
|
+
return emit(strip(row.raw), components)
|
|
136
|
+
})
|
|
109
137
|
|
|
110
138
|
/**
|
|
111
139
|
* Double spaces in raw and components.
|
|
112
140
|
*/
|
|
113
|
-
export const doubleSpace
|
|
141
|
+
export const doubleSpace = augmentation("double-space", (row, emit) => {
|
|
114
142
|
if (!/ /.test(row.raw)) return null
|
|
115
143
|
const newRaw = row.raw.replaceAll(" ", " ")
|
|
116
144
|
const newComponents: ComponentDict = {}
|
|
@@ -121,8 +149,8 @@ export const doubleSpace: Augmentation = (row) => {
|
|
|
121
149
|
}
|
|
122
150
|
}
|
|
123
151
|
|
|
124
|
-
return
|
|
125
|
-
}
|
|
152
|
+
return emit(newRaw, newComponents)
|
|
153
|
+
})
|
|
126
154
|
|
|
127
155
|
/**
|
|
128
156
|
* The share of rows that get a line-break variant, chosen per row from its source id.
|
|
@@ -136,22 +164,22 @@ const LINE_BREAK_SHARE = 0.25
|
|
|
136
164
|
* The variant's components are the ones the layout printed.
|
|
137
165
|
* A row whose layout puts everything on one line, or a country with no layout, gets no variant.
|
|
138
166
|
*/
|
|
139
|
-
export const lineBreaks
|
|
167
|
+
export const lineBreaks = augmentation("line-breaks", (row, emit) => {
|
|
140
168
|
if (/[\r\n]/.test(row.raw)) return null
|
|
141
169
|
|
|
142
170
|
if (mulberry32(hashString(`${row.source_id}:line-breaks`))() >= LINE_BREAK_SHARE) return null
|
|
143
171
|
|
|
144
|
-
const rendered =
|
|
172
|
+
const rendered = formatCorpusRow(row.components, row.country)
|
|
145
173
|
|
|
146
174
|
if (!rendered?.raw.includes("\n")) return null
|
|
147
175
|
|
|
148
|
-
return
|
|
149
|
-
}
|
|
176
|
+
return emit(rendered.raw, rendered.components)
|
|
177
|
+
})
|
|
150
178
|
|
|
151
179
|
/**
|
|
152
180
|
* Strip accents/diacritics from raw and components.
|
|
153
181
|
*/
|
|
154
|
-
export const accentStrip
|
|
182
|
+
export const accentStrip = augmentation("accent-strip", (row, emit) => {
|
|
155
183
|
const stripped = stripCombiningMarks(row.raw)
|
|
156
184
|
|
|
157
185
|
if (stripped === row.raw) return null
|
|
@@ -163,8 +191,8 @@ export const accentStrip: Augmentation = (row) => {
|
|
|
163
191
|
}
|
|
164
192
|
}
|
|
165
193
|
|
|
166
|
-
return
|
|
167
|
-
}
|
|
194
|
+
return emit(stripped, newComponents)
|
|
195
|
+
})
|
|
168
196
|
|
|
169
197
|
// Typo helpers are deterministic per row.
|
|
170
198
|
|
|
@@ -221,7 +249,7 @@ function hashString(s: string): number {
|
|
|
221
249
|
/**
|
|
222
250
|
* Inject one deterministic typo into an eligible component.
|
|
223
251
|
*/
|
|
224
|
-
export const typoInject
|
|
252
|
+
export const typoInject = augmentation("typo-inject", (row, emit) => {
|
|
225
253
|
const rng = mulberry32(hashString(`${row.source_id}:typo`))
|
|
226
254
|
|
|
227
255
|
// Only edit an unambiguous component value.
|
|
@@ -274,8 +302,8 @@ export const typoInject: Augmentation = (row) => {
|
|
|
274
302
|
const newRaw = row.raw.replace(value, typed)
|
|
275
303
|
|
|
276
304
|
// `replace(string, …)` updates the first literal match.
|
|
277
|
-
return
|
|
278
|
-
}
|
|
305
|
+
return emit(newRaw, { ...row.components, [tag]: typed })
|
|
306
|
+
})
|
|
279
307
|
|
|
280
308
|
// US-specific augmentations.
|
|
281
309
|
|
|
@@ -359,7 +387,11 @@ function replaceRegionWord(raw: string, region: string, replacement: string): st
|
|
|
359
387
|
return raw.slice(0, match.index) + replacement + raw.slice(match.index + region.length)
|
|
360
388
|
}
|
|
361
389
|
|
|
362
|
-
|
|
390
|
+
/**
|
|
391
|
+
* Writes a US row's state abbreviation as the state's full name (`AK` to `Alaska`),
|
|
392
|
+
* in the text and the region.
|
|
393
|
+
*/
|
|
394
|
+
export const stateExpand = augmentation("state-expand", (row, emit) => {
|
|
363
395
|
// country-branch: the state, directional, street-suffix, unit and ZIP+4
|
|
364
396
|
// augmentations below read US vocabulary tables.
|
|
365
397
|
// Per-country abbreviation tables in the codex would let
|
|
@@ -381,13 +413,13 @@ export const stateExpand: Augmentation = (row) => {
|
|
|
381
413
|
if (!newRaw) return null
|
|
382
414
|
const newComponents: ComponentDict = { ...row.components, region: full }
|
|
383
415
|
|
|
384
|
-
return
|
|
385
|
-
}
|
|
416
|
+
return emit(newRaw, newComponents)
|
|
417
|
+
})
|
|
386
418
|
|
|
387
419
|
/**
|
|
388
420
|
* Abbreviate full state name to alpha-2.
|
|
389
421
|
*/
|
|
390
|
-
export const stateAbbreviate
|
|
422
|
+
export const stateAbbreviate = augmentation("state-abbreviate", (row, emit) => {
|
|
391
423
|
// country-branch: see `stateExpand`.
|
|
392
424
|
if (row.country !== "US") return null
|
|
393
425
|
const region = row.components.region
|
|
@@ -401,8 +433,8 @@ export const stateAbbreviate: Augmentation = (row) => {
|
|
|
401
433
|
if (!newRaw) return null
|
|
402
434
|
const newComponents: ComponentDict = { ...row.components, region: abbr }
|
|
403
435
|
|
|
404
|
-
return
|
|
405
|
-
}
|
|
436
|
+
return emit(newRaw, newComponents)
|
|
437
|
+
})
|
|
406
438
|
|
|
407
439
|
const DIRECTIONAL_FULL_TO_ABBR: Record<string, string> = {
|
|
408
440
|
North: "N",
|
|
@@ -422,7 +454,7 @@ const DIRECTIONAL_ABBR_TO_FULL: Record<string, string> = Object.fromEntries(
|
|
|
422
454
|
/**
|
|
423
455
|
* Expand directional abbreviations.
|
|
424
456
|
*/
|
|
425
|
-
export const directionalExpand
|
|
457
|
+
export const directionalExpand = augmentation("directional-expand", (row, emit) => {
|
|
426
458
|
// country-branch: see `stateExpand`.
|
|
427
459
|
if (row.country !== "US") return null
|
|
428
460
|
const tagsToCheck: ComponentTag[] = ["street", "street_suffix", "street_prefix"]
|
|
@@ -447,13 +479,13 @@ export const directionalExpand: Augmentation = (row) => {
|
|
|
447
479
|
|
|
448
480
|
if (!changed) return null
|
|
449
481
|
|
|
450
|
-
return
|
|
451
|
-
}
|
|
482
|
+
return emit(newRaw, newComponents)
|
|
483
|
+
})
|
|
452
484
|
|
|
453
485
|
/**
|
|
454
486
|
* Abbreviate directional words.
|
|
455
487
|
*/
|
|
456
|
-
export const directionalAbbreviate
|
|
488
|
+
export const directionalAbbreviate = augmentation("directional-abbreviate", (row, emit) => {
|
|
457
489
|
// country-branch: see `stateExpand`.
|
|
458
490
|
if (row.country !== "US") return null
|
|
459
491
|
const tagsToCheck: ComponentTag[] = ["street", "street_suffix", "street_prefix"]
|
|
@@ -482,8 +514,8 @@ export const directionalAbbreviate: Augmentation = (row) => {
|
|
|
482
514
|
|
|
483
515
|
if (!changed) return null
|
|
484
516
|
|
|
485
|
-
return
|
|
486
|
-
}
|
|
517
|
+
return emit(newRaw, newComponents)
|
|
518
|
+
})
|
|
487
519
|
|
|
488
520
|
/**
|
|
489
521
|
* An augmentation rewrites one component's text in `raw`.
|
|
@@ -515,7 +547,7 @@ function siblingHoldsValue(components: ComponentDict, editedTag: ComponentTag, v
|
|
|
515
547
|
/**
|
|
516
548
|
* Abbreviate trailing US street suffix.
|
|
517
549
|
*/
|
|
518
|
-
export const streetSuffixAbbreviate
|
|
550
|
+
export const streetSuffixAbbreviate = augmentation("us-street-suffix-abbreviate", (row, emit) => {
|
|
519
551
|
// country-branch: see `stateExpand`.
|
|
520
552
|
if (row.country !== "US") return null
|
|
521
553
|
const street = row.components.street
|
|
@@ -541,13 +573,13 @@ export const streetSuffixAbbreviate: Augmentation = (row) => {
|
|
|
541
573
|
|
|
542
574
|
if (newRaw === row.raw) return null
|
|
543
575
|
|
|
544
|
-
return
|
|
545
|
-
}
|
|
576
|
+
return emit(newRaw, newComponents)
|
|
577
|
+
})
|
|
546
578
|
|
|
547
579
|
/**
|
|
548
580
|
* Expand trailing US street suffix.
|
|
549
581
|
*/
|
|
550
|
-
export const streetSuffixExpand
|
|
582
|
+
export const streetSuffixExpand = augmentation("us-street-suffix-expand", (row, emit) => {
|
|
551
583
|
// country-branch: see `stateExpand`.
|
|
552
584
|
if (row.country !== "US") return null
|
|
553
585
|
const street = row.components.street
|
|
@@ -572,13 +604,13 @@ export const streetSuffixExpand: Augmentation = (row) => {
|
|
|
572
604
|
|
|
573
605
|
if (newRaw === row.raw) return null
|
|
574
606
|
|
|
575
|
-
return
|
|
576
|
-
}
|
|
607
|
+
return emit(newRaw, newComponents)
|
|
608
|
+
})
|
|
577
609
|
|
|
578
610
|
/**
|
|
579
611
|
* Abbreviate leading US unit designator.
|
|
580
612
|
*/
|
|
581
|
-
export const unitDesignatorAbbreviate
|
|
613
|
+
export const unitDesignatorAbbreviate = augmentation("us-unit-designator-abbreviate", (row, emit) => {
|
|
582
614
|
// country-branch: see `stateExpand`.
|
|
583
615
|
if (row.country !== "US") return null
|
|
584
616
|
const unit = row.components.unit
|
|
@@ -604,13 +636,13 @@ export const unitDesignatorAbbreviate: Augmentation = (row) => {
|
|
|
604
636
|
|
|
605
637
|
if (newRaw === row.raw) return null
|
|
606
638
|
|
|
607
|
-
return
|
|
608
|
-
}
|
|
639
|
+
return emit(newRaw, newComponents)
|
|
640
|
+
})
|
|
609
641
|
|
|
610
642
|
/**
|
|
611
643
|
* Expand leading US unit designator.
|
|
612
644
|
*/
|
|
613
|
-
export const unitDesignatorExpand
|
|
645
|
+
export const unitDesignatorExpand = augmentation("us-unit-designator-expand", (row, emit) => {
|
|
614
646
|
// country-branch: see `stateExpand`.
|
|
615
647
|
if (row.country !== "US") return null
|
|
616
648
|
const unit = row.components.unit
|
|
@@ -635,13 +667,13 @@ export const unitDesignatorExpand: Augmentation = (row) => {
|
|
|
635
667
|
|
|
636
668
|
if (newRaw === row.raw) return null
|
|
637
669
|
|
|
638
|
-
return
|
|
639
|
-
}
|
|
670
|
+
return emit(newRaw, newComponents)
|
|
671
|
+
})
|
|
640
672
|
|
|
641
673
|
/**
|
|
642
674
|
* Drop dash from ZIP+4.
|
|
643
675
|
*/
|
|
644
|
-
export const zipPlus4DashDrop
|
|
676
|
+
export const zipPlus4DashDrop = augmentation("zip-plus4-dash-drop", (row, emit) => {
|
|
645
677
|
// country-branch: see `stateExpand`.
|
|
646
678
|
if (row.country !== "US") return null
|
|
647
679
|
const postcode = row.components.postcode
|
|
@@ -652,15 +684,15 @@ export const zipPlus4DashDrop: Augmentation = (row) => {
|
|
|
652
684
|
|
|
653
685
|
if (newRaw === row.raw) return null
|
|
654
686
|
|
|
655
|
-
return
|
|
656
|
-
}
|
|
687
|
+
return emit(newRaw, { ...row.components, postcode: noDash })
|
|
688
|
+
})
|
|
657
689
|
|
|
658
690
|
// French-specific augmentations.
|
|
659
691
|
|
|
660
692
|
/**
|
|
661
693
|
* Drop French street particle.
|
|
662
694
|
*/
|
|
663
|
-
export const particleStrip
|
|
695
|
+
export const particleStrip = augmentation("particle-strip", (row, emit) => {
|
|
664
696
|
// country-branch: the particle list is French.
|
|
665
697
|
// A per-language particle table in the codex would replace this.
|
|
666
698
|
if (row.country !== "FR") return null
|
|
@@ -675,8 +707,8 @@ export const particleStrip: Augmentation = (row) => {
|
|
|
675
707
|
if (!re.test(row.raw)) return null
|
|
676
708
|
const newRaw = row.raw.replaceAll(re, " ").replaceAll(/\s+/g, " ").trim()
|
|
677
709
|
|
|
678
|
-
return
|
|
679
|
-
}
|
|
710
|
+
return emit(newRaw, newComponents)
|
|
711
|
+
})
|
|
680
712
|
|
|
681
713
|
// Stable augmentation registry.
|
|
682
714
|
|
|
@@ -738,9 +770,16 @@ export function defaultAugmentationsForCountry(country: string): readonly Augmen
|
|
|
738
770
|
*/
|
|
739
771
|
export function* synthesizeRow(
|
|
740
772
|
row: CanonicalRow,
|
|
741
|
-
augmentations: readonly Augmentation[] = defaultAugmentationsForCountry(row.country)
|
|
773
|
+
augmentations: readonly Augmentation[] = defaultAugmentationsForCountry(row.country),
|
|
774
|
+
/**
|
|
775
|
+
* Whether the caller wants the variant an augmentation's method writes. An augmentation it doesn't want isn't
|
|
776
|
+
* run, so a caller that would drop the variant skips its work.
|
|
777
|
+
*/
|
|
778
|
+
wants?: (method: string) => boolean
|
|
742
779
|
): Generator<CanonicalRow> {
|
|
743
780
|
for (const aug of augmentations) {
|
|
781
|
+
if (wants && !wants(aug.method)) continue
|
|
782
|
+
|
|
744
783
|
const out = aug(row)
|
|
745
784
|
|
|
746
785
|
if (out) {
|
package/lib/test-kit.ts
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
|
|
14
14
|
import { readLocalJSONFile } from "@mailwoman/core/fs/readers"
|
|
15
15
|
import { temporaryDirectory, type TemporaryDirectory } from "@mailwoman/core/fs/temporary"
|
|
16
|
-
import { writeLocalJSONFile } from "@mailwoman/core/fs/writers"
|
|
16
|
+
import { writeLocalJSONFile, writeLocalTextFile } from "@mailwoman/core/fs/writers"
|
|
17
|
+
import { workspacePath } from "@mailwoman/core/paths"
|
|
17
18
|
import { stringifyJSON } from "@mailwoman/core/values/json"
|
|
18
19
|
import { PathBuilder, type PathBuilderLike } from "path-ts"
|
|
19
20
|
import { createNewlineWriter, JSONSpliterator } from "spliterator"
|
|
@@ -21,6 +22,8 @@ import { afterEach, beforeEach, expect } from "vitest"
|
|
|
21
22
|
|
|
22
23
|
import type { ParquetRow } from "#parquet/schema"
|
|
23
24
|
import type { CanonicalRow } from "#types"
|
|
25
|
+
import { NAD_RECORD_COLUMNS } from "#us/adapters/usgov/nad/adapter"
|
|
26
|
+
import { convertNADToParquet } from "#us/tools/fetch/nad/parquet"
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* A per-test scratch directory.
|
|
@@ -191,6 +194,52 @@ export class ReferenceFixture<T extends object> {
|
|
|
191
194
|
}
|
|
192
195
|
}
|
|
193
196
|
|
|
197
|
+
/**
|
|
198
|
+
* The NAD adapter's fixture records, one JSON object per line.
|
|
199
|
+
*/
|
|
200
|
+
export const NAD_FIXTURE = workspacePath(
|
|
201
|
+
"corpus",
|
|
202
|
+
"lib",
|
|
203
|
+
"us",
|
|
204
|
+
"adapters",
|
|
205
|
+
"usgov",
|
|
206
|
+
"nad",
|
|
207
|
+
"fixtures",
|
|
208
|
+
"fixture.ndjson"
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Writes `records` as NAD release text with every column the adapter reads into `dir`,
|
|
213
|
+
* and converts it to `NAD_test.parquet` there the way the fetcher does.
|
|
214
|
+
*
|
|
215
|
+
* Without `records`, it writes {@linkcode NAD_FIXTURE}'s.
|
|
216
|
+
*/
|
|
217
|
+
export async function writeNADReleaseParquet(
|
|
218
|
+
dir: PathBuilder,
|
|
219
|
+
records?: ReadonlyArray<Record<string, unknown>>
|
|
220
|
+
): Promise<PathBuilder> {
|
|
221
|
+
const rows = records ?? (await Array.fromAsync(JSONSpliterator.fromAsync<Record<string, unknown>>(NAD_FIXTURE)))
|
|
222
|
+
|
|
223
|
+
const cell = (value: unknown) => {
|
|
224
|
+
const text = value == null ? "" : String(value)
|
|
225
|
+
|
|
226
|
+
return /[",\r\n]/u.test(text) ? `"${text.replaceAll('"', '""')}"` : text
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const lines = [
|
|
230
|
+
NAD_RECORD_COLUMNS.join(","),
|
|
231
|
+
...rows.map((record) => NAD_RECORD_COLUMNS.map((column) => cell(record[column])).join(",")),
|
|
232
|
+
]
|
|
233
|
+
|
|
234
|
+
const textPath = dir("NAD_test.txt")
|
|
235
|
+
const parquetPath = dir("NAD_test.parquet")
|
|
236
|
+
|
|
237
|
+
await writeLocalTextFile(`${lines.join("\n")}\n`, textPath)
|
|
238
|
+
await convertNADToParquet({ textPath, parquetPath, sourceSHA256: "test", member: "NAD_test.txt" })
|
|
239
|
+
|
|
240
|
+
return parquetPath
|
|
241
|
+
}
|
|
242
|
+
|
|
194
243
|
/**
|
|
195
244
|
* One GB parquet row whose postcode sits at the end of `raw`, the shape `rendered-gb-os-open` renders.
|
|
196
245
|
*
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copies the Indian places of an Overture Maps release, with their first address,
|
|
6
|
+
* into the `overture-places-in/<release>/` snapshot the `overture-places-in` adapter reads.
|
|
7
|
+
*
|
|
8
|
+
* The places theme sits on Overture's public bucket,
|
|
9
|
+
* `s3://overturemaps-us-west-2/release/<release>/theme=places/`, which needs no credential.
|
|
10
|
+
* The query reads only the row groups whose bounding boxes fall in India's
|
|
11
|
+
* (68–98° E, 6–37.5° N) and keeps the rows whose first address has the country `IN`,
|
|
12
|
+
* so the copy reads a few hundred megabytes of the theme rather than all of it.
|
|
13
|
+
*
|
|
14
|
+
* Overture's attribution page lists the places theme's contributors under CDLA Permissive 2.0,
|
|
15
|
+
* Foursquare under Apache 2.0 and AllThePlaces under CC0 1.0.
|
|
16
|
+
* Each row keeps the dataset of its first source, so a count can be split by contributor.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { sha256File } from "@mailwoman/core/crypto/hash"
|
|
20
|
+
import { statPath } from "@mailwoman/core/fs/readers/stat"
|
|
21
|
+
import { DEFAULT_RELEASE } from "@mailwoman/gazetteer/tools/pipeline/poi/defaults"
|
|
22
|
+
import type { PathBuilder } from "path-ts"
|
|
23
|
+
|
|
24
|
+
import { escapeSQLString, openDuckDB } from "#parquet/duckdb"
|
|
25
|
+
import { countParquetRows } from "#parquet/readers"
|
|
26
|
+
import type { FetchSummary } from "#tools/fetch/download"
|
|
27
|
+
import { writeManifest } from "#tools/fetch/download"
|
|
28
|
+
import { fetchSnapshot, type SnapshotFetchOptions } from "#tools/fetch/storage"
|
|
29
|
+
|
|
30
|
+
const SLUG = "overture-places-in"
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The file the snapshot holds.
|
|
34
|
+
*/
|
|
35
|
+
const OVERTURE_PLACES_IN_FILE = "places-in.parquet"
|
|
36
|
+
|
|
37
|
+
export interface FetchOverturePlacesINOptions extends SnapshotFetchOptions {
|
|
38
|
+
/**
|
|
39
|
+
* The Overture release to copy, such as `2026-09-23.1`.
|
|
40
|
+
* It is also the snapshot's vintage.
|
|
41
|
+
*/
|
|
42
|
+
release?: string | null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The places theme's files in one release.
|
|
47
|
+
*/
|
|
48
|
+
function placesGlob(release: string): string {
|
|
49
|
+
return `s3://overturemaps-us-west-2/release/${release}/theme=places/type=place/*.parquet`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Copies the release's Indian places with an address into its snapshot.
|
|
54
|
+
*/
|
|
55
|
+
export async function fetchOverturePlacesIN(
|
|
56
|
+
options: FetchOverturePlacesINOptions,
|
|
57
|
+
report?: (line: string) => void
|
|
58
|
+
): Promise<FetchSummary> {
|
|
59
|
+
// Without a release from the caller, the one the gazetteer's places build pins.
|
|
60
|
+
const release = options.release || options.snapshots.vintage || DEFAULT_RELEASE
|
|
61
|
+
|
|
62
|
+
report?.(`=== ${SLUG} (Overture release ${release})`)
|
|
63
|
+
|
|
64
|
+
return fetchSnapshot(options.snapshots, SLUG, release, (directory) => copyPlaces(release, directory, report), report)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function copyPlaces(
|
|
68
|
+
release: string,
|
|
69
|
+
directory: PathBuilder,
|
|
70
|
+
report?: (line: string) => void
|
|
71
|
+
): Promise<FetchSummary> {
|
|
72
|
+
const glob = placesGlob(release)
|
|
73
|
+
const dest = directory(OVERTURE_PLACES_IN_FILE)
|
|
74
|
+
const started = Date.now()
|
|
75
|
+
|
|
76
|
+
{
|
|
77
|
+
using db = await openDuckDB({ threads: 4 })
|
|
78
|
+
|
|
79
|
+
await db.run("INSTALL httpfs; LOAD httpfs;")
|
|
80
|
+
await db.run("SET s3_region='us-west-2';")
|
|
81
|
+
|
|
82
|
+
report?.(` Reading ${glob} ...`)
|
|
83
|
+
|
|
84
|
+
await db.run(`COPY (
|
|
85
|
+
SELECT
|
|
86
|
+
id,
|
|
87
|
+
addresses[1].freeform AS freeform,
|
|
88
|
+
addresses[1].locality AS locality,
|
|
89
|
+
addresses[1].region AS region,
|
|
90
|
+
addresses[1].postcode AS postcode,
|
|
91
|
+
sources[1].dataset AS dataset,
|
|
92
|
+
sources[1].record_id AS record_id
|
|
93
|
+
FROM read_parquet('${escapeSQLString(glob)}', hive_partitioning = false)
|
|
94
|
+
WHERE bbox.xmin BETWEEN 68 AND 98 AND bbox.ymin BETWEEN 6 AND 37.5
|
|
95
|
+
AND addresses[1].country = 'IN'
|
|
96
|
+
) TO '${escapeSQLString(dest.toString())}' (FORMAT parquet, COMPRESSION zstd)`)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const rows = await countParquetRows(dest)
|
|
100
|
+
const bytes = (await statPath(dest)).size
|
|
101
|
+
const sha256 = await sha256File(dest)
|
|
102
|
+
|
|
103
|
+
await writeManifest(directory("MANIFEST.json"), {
|
|
104
|
+
source_url: glob,
|
|
105
|
+
downloaded_at: new Date().toISOString(),
|
|
106
|
+
filename: OVERTURE_PLACES_IN_FILE,
|
|
107
|
+
sha256,
|
|
108
|
+
bytes,
|
|
109
|
+
publisher_version: release,
|
|
110
|
+
rows,
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
report?.(
|
|
114
|
+
` ✓ ${rows} places, ${(bytes / 1024 / 1024).toFixed(1)} MB in ${((Date.now() - started) / 1000).toFixed(0)} s`
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
return { fetched: 1, skipped: 0, failed: 0, failedCodes: [] }
|
|
118
|
+
}
|
|
@@ -102,6 +102,8 @@ export const SOURCE_STORAGE_CLASSES = {
|
|
|
102
102
|
"nga-wpi": StorageClass.current,
|
|
103
103
|
openaddresses: StorageClass.current,
|
|
104
104
|
ourairports: StorageClass.current,
|
|
105
|
+
// One Overture release's Indian places, under the release id as the vintage.
|
|
106
|
+
"overture-places-in": StorageClass.snapshot,
|
|
105
107
|
"ro-retea-scolara": StorageClass.current,
|
|
106
108
|
ryhti: StorageClass.current,
|
|
107
109
|
"sk-inspire": StorageClass.current,
|
|
@@ -221,6 +223,7 @@ export const FETCH_SOURCE_DIRECTORIES = {
|
|
|
221
223
|
nppes: ["usgov-nppes"],
|
|
222
224
|
openaddresses: ["openaddresses"],
|
|
223
225
|
ourairports: ["ourairports"],
|
|
226
|
+
"overture-places-in": ["overture-places-in"],
|
|
224
227
|
"ro-retea-scolara": ["ro-retea-scolara"],
|
|
225
228
|
ryhti: ["ryhti"],
|
|
226
229
|
"sk-inspire": ["sk-inspire"],
|
package/lib/tools/fetch.ts
CHANGED
|
@@ -42,6 +42,7 @@ import { fetchGeonamesPostal } from "#tools/fetch/geonames/postal"
|
|
|
42
42
|
import { fetchGLEIF } from "#tools/fetch/gleif"
|
|
43
43
|
import { fetchOpenAddresses } from "#tools/fetch/openaddresses"
|
|
44
44
|
import { fetchOurAirports } from "#tools/fetch/ourairports"
|
|
45
|
+
import { fetchOverturePlacesIN } from "#tools/fetch/overture-places-in"
|
|
45
46
|
import { fetchVlaanderenAD } from "#tools/fetch/vlaanderen-ad"
|
|
46
47
|
import { fetchWikidataSubVenue } from "#tools/fetch/wikidata/subvenue"
|
|
47
48
|
import { fetchWikidataVitalPlaces } from "#tools/fetch/wikidata/vital-places"
|
|
@@ -102,6 +103,7 @@ export const FETCH_SOURCES = {
|
|
|
102
103
|
"nga-wpi": fetchNGAWPI,
|
|
103
104
|
openaddresses: fetchOpenAddresses,
|
|
104
105
|
ourairports: fetchOurAirports,
|
|
106
|
+
"overture-places-in": fetchOverturePlacesIN,
|
|
105
107
|
vlaanderen: fetchVlaanderenAD,
|
|
106
108
|
wallonie: fetchWallonie,
|
|
107
109
|
"state-sources": fetchStateSources,
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
readSecondLevelNames,
|
|
24
24
|
secondLevelAdmitted,
|
|
25
25
|
type SecondLevelRegionTable,
|
|
26
|
-
} from "#build/region
|
|
26
|
+
} from "#build/region/names"
|
|
27
27
|
import { escapeSQLString, openDuckDB } from "#parquet/duckdb"
|
|
28
28
|
import { parquetColumnNames } from "#parquet/readers"
|
|
29
29
|
import { localManifestFilePath } from "#tools/overlay/manifest"
|
|
@@ -155,7 +155,7 @@ const table: SecondLevelRegionTable = {
|
|
|
155
155
|
$description:
|
|
156
156
|
"Per country, the base rows with a region and those whose region is a second-level (WOF county) name " +
|
|
157
157
|
"of the country and no region name of it. Written by packages/corpus/lib/tools/region-slot-census.run.ts; " +
|
|
158
|
-
"secondLevelAdmitted in packages/corpus/lib/build/region
|
|
158
|
+
"secondLevelAdmitted in packages/corpus/lib/build/region/names.ts decides which countries the region:unknown rule admits.",
|
|
159
159
|
manifest: manifestPath,
|
|
160
160
|
countries: Object.fromEntries(
|
|
161
161
|
countries
|
package/lib/types.ts
CHANGED
|
@@ -387,6 +387,36 @@ export interface AdapterOptions {
|
|
|
387
387
|
*/
|
|
388
388
|
sample?: RowSample | null
|
|
389
389
|
|
|
390
|
+
/**
|
|
391
|
+
* The share of the source's training rows a build keeps, from 0 to 1, or no value to keep them all.
|
|
392
|
+
*
|
|
393
|
+
* Align applies it after each row's split is decided, so validation and test keep every row.
|
|
394
|
+
* A training row is kept when a salted hash of its id up to the last `#` falls
|
|
395
|
+
* under the share (`keepsTrainRow`).
|
|
396
|
+
*
|
|
397
|
+
* An id with no `#` draws per row, so a record's variants draw apart.
|
|
398
|
+
* The adapter ignores it.
|
|
399
|
+
*/
|
|
400
|
+
trainShare?: number | null
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* The input rows to read, by position in the input file from `start` up to `end`,
|
|
404
|
+
* for an adapter that declares {@linkcode CorpusAdapter.inputRowCount}.
|
|
405
|
+
*
|
|
406
|
+
* A parallel build runs one partition of a large input per range and merges them in order,
|
|
407
|
+
* so a row's output must depend only on the row: its id comes from its own fields
|
|
408
|
+
* or its position in the file, never from a count of the rows before it.
|
|
409
|
+
*/
|
|
410
|
+
rowRange?: { start: number; end: number } | null
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Limits for the DuckDB instance an adapter reading parquet opens, set by a parallel
|
|
414
|
+
* build's partition worker so several partitions fit the host at once.
|
|
415
|
+
*
|
|
416
|
+
* An adapter without DuckDB ignores it, and it changes no row.
|
|
417
|
+
*/
|
|
418
|
+
duckdb?: { memoryLimitBytes: number; threads: number } | null
|
|
419
|
+
|
|
390
420
|
/**
|
|
391
421
|
* A cancellation signal that adapters should check at each iteration.
|
|
392
422
|
*/
|
|
@@ -535,4 +565,13 @@ export interface CorpusAdapter {
|
|
|
535
565
|
* They mustn't mutate rows already yielded.
|
|
536
566
|
*/
|
|
537
567
|
rows(opts: AdapterOptions): AsyncIterable<CanonicalRow>
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* The number of rows in the input `opts.inputPath` names, for an adapter that
|
|
571
|
+
* reads {@linkcode AdapterOptions.rowRange}.
|
|
572
|
+
*
|
|
573
|
+
* Its presence declares that the adapter can read its input in row ranges,
|
|
574
|
+
* so a parallel build may split a large input across workers.
|
|
575
|
+
*/
|
|
576
|
+
inputRowCount?(opts: AdapterOptions): Promise<number>
|
|
538
577
|
}
|