@mailwoman/corpus 11.1.0 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -14
- package/data/address-source-register.json +618 -13
- package/data/builds/v0.8.19-overlay/OVERLAY_PLAN.json +4778 -0
- package/data/builds/v0.8.19-rebuild/inputs.json +128 -0
- package/data/builds/v0.8.20-overlay/OVERLAY_PLAN.json +3595 -0
- package/data/builds/v0.8.20-rebuild/inputs.json +131 -0
- package/data/builds/v0.8.21-overlay/OVERLAY_PLAN.json +72 -0
- package/data/corpus-source-inputs.json +104 -2
- package/data/holdout/evaluation-groups.v0.8.18.json +90511 -0
- package/data/holdout/evaluation-groups.v0.8.19.json +100537 -0
- package/data/holdout/evaluation-groups.v0.8.20.json +129215 -0
- package/data/holdout/evaluation-groups.v0.8.21.json +173286 -0
- package/data/holdout/probe-text-collisions.v0.8.20.json +1478 -0
- package/data/license-decisions.json +393 -3
- package/data/licenses/PROVENANCE.md +15 -9
- package/data/licenses/au-acnc-cc-by-3.0-au.md +37 -0
- package/data/licenses/es-sanidad-aviso-legal.md +26 -0
- package/data/licenses/it-miur-iodl-2.0.md +41 -0
- package/data/licenses/nz-charities-cc-by-3.0-nz.md +36 -0
- package/data/region-slot-second-level.json +966 -0
- package/data/source-additions.json +126 -6
- package/data/source-resolutions.json +97 -0
- package/data/training-configs/v8.7.0-base-c6-90k-usgs-structures-s42.yaml +801 -0
- package/data/training-configs/v8.7.0-base-c6-90k-usgs-structures-s43.yaml +726 -0
- package/data/training-configs/v8.8.0-base-c6-90k-v0820-county-s42.yaml +944 -0
- package/data/training-configs/v8.9.0-base-c6-90k-v0821-s42.yaml +848 -0
- package/data/training-manifests/v0.8.19-retention-overlay.json +4553 -0
- package/data/training-manifests/v0.8.20-retention-overlay.json +4579 -0
- package/data/training-manifests/v0.8.21-retention-overlay.effective.json +2521 -0
- package/data/training-manifests/v0.8.21-retention-overlay.json +4579 -0
- package/lib/adapters/cordis/adapter.ts +10 -2
- package/lib/adapters/gleif/adapter.ts +23 -5
- package/lib/adapters/osm/adapter.ts +2 -2
- package/lib/adapters/street/repetition.ts +87 -0
- package/lib/adapters/street/unit.ts +14 -0
- package/lib/adapters/wof/admin/json/adapter.ts +34 -21
- package/lib/adapters/wof/admin/json/dual-role.ts +274 -0
- package/lib/adapters/wof/admin/json/explore.ts +4 -4
- package/lib/adapters/wof/admin/json/region-codes.ts +74 -3
- package/lib/adapters/wof/json-rows.ts +36 -21
- package/lib/adapters/wof/postalcode-json/adapter.ts +10 -28
- package/lib/adapters/wof/sample.ts +15 -3
- package/lib/adapters/wof/stored-records.ts +162 -0
- package/lib/adapters.ts +18 -6
- package/lib/au/adapters/acnc-register/adapter.ts +40 -0
- package/lib/au/evaluation/acnc-register.ts +144 -0
- package/lib/build/align/range.ts +9 -0
- package/lib/build/align/totals.ts +23 -0
- package/lib/build/align.ts +74 -4
- package/lib/build/budget.ts +11 -45
- package/lib/build/checkpoint.ts +11 -0
- package/lib/build/component-check.ts +99 -3
- package/lib/build/manifest.ts +4 -0
- package/lib/build/parallel.ts +8 -34
- package/lib/build/region-names.ts +609 -0
- package/lib/build/source-record.ts +7 -0
- package/lib/build/types.ts +20 -0
- package/lib/build/worker.ts +3 -1
- package/lib/build.ts +3 -6
- package/lib/de/recipes/locale.ts +3 -2
- package/lib/env.ts +0 -6
- package/lib/es/adapters/sanidad-centros-ap/adapter.ts +40 -0
- package/lib/es/evaluation/sanidad-centros-ap.ts +164 -0
- package/lib/evaluation/corpus-adapter.ts +153 -0
- package/lib/evaluation/source.ts +209 -0
- package/lib/evaluation/sources.ts +25 -0
- package/lib/fr/adapters/laposte-poincont/adapter.ts +381 -0
- package/lib/fr/recipes/unit-line-guideline.ts +9 -4
- package/lib/fr/structures/laposte.ts +139 -0
- package/lib/fr/tools/fetch/laposte-poincont.ts +234 -0
- package/lib/it/adapters/miur-scuole/adapter.ts +39 -0
- package/lib/it/evaluation/miur-scuole.ts +125 -0
- package/lib/jp/adapters/wof-admin/adapter.ts +4 -4
- package/lib/nc/adapters/opt-nc/adapter.ts +237 -0
- package/lib/nc/structures/opt-nc.ts +101 -0
- package/lib/nc/tools/fetch/opt-nc.ts +249 -0
- package/lib/nz/adapters/charities-register/adapter.ts +40 -0
- package/lib/nz/evaluation/charities-register.ts +149 -0
- package/lib/recipes/bare/postcode.ts +14 -11
- package/lib/recipes/deepseek/batches.ts +8 -8
- package/lib/recipes/po/box/cedex/recipe.ts +12 -1
- package/lib/recipes/po/box/cedex/us.ts +43 -2
- package/lib/recipes/scaffold.ts +1 -1
- package/lib/recipes/sources.ts +16 -0
- package/lib/recipes.ts +2 -0
- package/lib/registers.ts +28 -2
- package/lib/{post-offices → structures}/source.ts +49 -16
- package/lib/structures/sources.ts +26 -0
- package/lib/synthesizers/house-venue.ts +11 -6
- package/lib/synthesizers/tail.ts +27 -3
- package/lib/tools/audit.ts +1 -1
- package/lib/tools/fetch/storage.ts +18 -4
- package/lib/tools/fetch.ts +10 -2
- package/lib/tools/overlay/kryptonite.ts +6 -2
- package/lib/tools/overlay/split/attribute.ts +14 -2
- package/lib/tools/overlay/split/overlay.ts +36 -7
- package/lib/tools/postcode/triples.ts +3 -3
- package/lib/tools/region-slot-census.run.ts +184 -0
- package/lib/training/config/load.ts +19 -0
- package/lib/training/config/schema.ts +6 -0
- package/lib/tw/registers.ts +15 -4
- package/lib/tw/structures/chunghwa-post.ts +191 -0
- package/lib/tw/tools/fetch/chunghwa-post.ts +174 -0
- package/lib/us/adapters/state/ny-notaries/adapter.ts +7 -2
- package/lib/us/adapters/state/tx-notaries/adapter.ts +126 -21
- package/lib/us/adapters/usgov/nad/adapter.ts +111 -31
- package/lib/us/adapters/usgov/nppes/adapter.ts +8 -11
- package/lib/us/adapters/usgov/{usgs-post-offices → usgs-structures}/adapter.ts +65 -35
- package/lib/us/recipes/county.ts +474 -0
- package/lib/us/street-unit.ts +15 -5
- package/lib/us/structures/usgs/layers.ts +171 -0
- package/lib/us/structures/usgs/national-map.ts +95 -0
- package/lib/us/tools/fetch/usgs/gnis.ts +288 -0
- package/lib/us/tools/fetch/usgs/structures.ts +362 -0
- package/lib/utils/align.ts +2 -2
- package/lib/utils/evaluation-groups.ts +172 -0
- package/lib/utils/split.ts +40 -4
- package/lib/utils/tokenize.ts +7 -7
- package/lib/utils/validation-groups.ts +292 -0
- package/lib/utils/wof-json.ts +96 -134
- package/out/adapters/cordis/adapter.d.ts +3 -1
- package/out/adapters/cordis/adapter.d.ts.map +1 -1
- package/out/adapters/cordis/adapter.js +8 -2
- package/out/adapters/cordis/adapter.js.map +1 -1
- package/out/adapters/gleif/adapter.d.ts.map +1 -1
- package/out/adapters/gleif/adapter.js +19 -5
- package/out/adapters/gleif/adapter.js.map +1 -1
- package/out/adapters/osm/adapter.js +2 -2
- package/out/adapters/osm/adapter.js.map +1 -1
- package/out/adapters/street/repetition.d.ts +19 -0
- package/out/adapters/street/repetition.d.ts.map +1 -0
- package/out/adapters/street/repetition.js +71 -0
- package/out/adapters/street/repetition.js.map +1 -0
- package/out/adapters/street/unit.d.ts +10 -0
- package/out/adapters/street/unit.d.ts.map +1 -1
- package/out/adapters/street/unit.js +6 -0
- package/out/adapters/street/unit.js.map +1 -1
- package/out/adapters/wof/admin/json/adapter.d.ts +8 -0
- package/out/adapters/wof/admin/json/adapter.d.ts.map +1 -1
- package/out/adapters/wof/admin/json/adapter.js +26 -22
- package/out/adapters/wof/admin/json/adapter.js.map +1 -1
- package/out/adapters/wof/admin/json/dual-role.d.ts +83 -0
- package/out/adapters/wof/admin/json/dual-role.d.ts.map +1 -0
- package/out/adapters/wof/admin/json/dual-role.js +183 -0
- package/out/adapters/wof/admin/json/dual-role.js.map +1 -0
- package/out/adapters/wof/admin/json/explore.d.ts.map +1 -1
- package/out/adapters/wof/admin/json/explore.js +4 -4
- package/out/adapters/wof/admin/json/explore.js.map +1 -1
- package/out/adapters/wof/admin/json/region-codes.d.ts +16 -0
- package/out/adapters/wof/admin/json/region-codes.d.ts.map +1 -1
- package/out/adapters/wof/admin/json/region-codes.js +62 -3
- package/out/adapters/wof/admin/json/region-codes.js.map +1 -1
- package/out/adapters/wof/json-rows.d.ts +28 -6
- package/out/adapters/wof/json-rows.d.ts.map +1 -1
- package/out/adapters/wof/json-rows.js +9 -15
- package/out/adapters/wof/json-rows.js.map +1 -1
- package/out/adapters/wof/postalcode-json/adapter.d.ts +1 -1
- package/out/adapters/wof/postalcode-json/adapter.d.ts.map +1 -1
- package/out/adapters/wof/postalcode-json/adapter.js +9 -26
- package/out/adapters/wof/postalcode-json/adapter.js.map +1 -1
- package/out/adapters/wof/sample.d.ts +8 -1
- package/out/adapters/wof/sample.d.ts.map +1 -1
- package/out/adapters/wof/sample.js +12 -4
- package/out/adapters/wof/sample.js.map +1 -1
- package/out/adapters/wof/stored-records.d.ts +62 -0
- package/out/adapters/wof/stored-records.d.ts.map +1 -0
- package/out/adapters/wof/stored-records.js +91 -0
- package/out/adapters/wof/stored-records.js.map +1 -0
- package/out/adapters.d.ts +1 -1
- package/out/adapters.d.ts.map +1 -1
- package/out/adapters.js +15 -3
- package/out/adapters.js.map +1 -1
- package/out/au/adapters/acnc-register/adapter.d.ts +9 -0
- package/out/au/adapters/acnc-register/adapter.d.ts.map +1 -0
- package/out/au/adapters/acnc-register/adapter.js +37 -0
- package/out/au/adapters/acnc-register/adapter.js.map +1 -0
- package/out/au/evaluation/acnc-register.d.ts +56 -0
- package/out/au/evaluation/acnc-register.d.ts.map +1 -0
- package/out/au/evaluation/acnc-register.js +84 -0
- package/out/au/evaluation/acnc-register.js.map +1 -0
- package/out/build/align/range.d.ts.map +1 -1
- package/out/build/align/range.js +9 -0
- package/out/build/align/range.js.map +1 -1
- package/out/build/align/totals.d.ts +5 -0
- package/out/build/align/totals.d.ts.map +1 -1
- package/out/build/align/totals.js +15 -0
- package/out/build/align/totals.js.map +1 -1
- package/out/build/align.d.ts +26 -0
- package/out/build/align.d.ts.map +1 -1
- package/out/build/align.js +35 -2
- package/out/build/align.js.map +1 -1
- package/out/build/budget.d.ts +9 -26
- package/out/build/budget.d.ts.map +1 -1
- package/out/build/budget.js +10 -31
- package/out/build/budget.js.map +1 -1
- package/out/build/checkpoint.d.ts +11 -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 +55 -1
- package/out/build/component-check.d.ts.map +1 -1
- package/out/build/component-check.js +65 -3
- package/out/build/component-check.js.map +1 -1
- package/out/build/manifest.d.ts.map +1 -1
- package/out/build/manifest.js +4 -0
- package/out/build/manifest.js.map +1 -1
- package/out/build/parallel.d.ts.map +1 -1
- package/out/build/parallel.js +8 -24
- package/out/build/parallel.js.map +1 -1
- package/out/build/region-names.d.ts +120 -0
- package/out/build/region-names.d.ts.map +1 -0
- package/out/build/region-names.js +430 -0
- package/out/build/region-names.js.map +1 -0
- package/out/build/source-record.d.ts.map +1 -1
- package/out/build/source-record.js +4 -0
- package/out/build/source-record.js.map +1 -1
- package/out/build/types.d.ts +20 -0
- package/out/build/types.d.ts.map +1 -1
- package/out/build/worker.js +3 -1
- package/out/build/worker.js.map +1 -1
- package/out/build.d.ts +0 -1
- package/out/build.d.ts.map +1 -1
- package/out/build.js +3 -5
- package/out/build.js.map +1 -1
- package/out/de/recipes/locale.d.ts.map +1 -1
- package/out/de/recipes/locale.js +3 -2
- package/out/de/recipes/locale.js.map +1 -1
- package/out/env.d.ts +0 -2
- package/out/env.d.ts.map +1 -1
- package/out/env.js +0 -5
- package/out/env.js.map +1 -1
- package/out/es/adapters/sanidad-centros-ap/adapter.d.ts +9 -0
- package/out/es/adapters/sanidad-centros-ap/adapter.d.ts.map +1 -0
- package/out/es/adapters/sanidad-centros-ap/adapter.js +36 -0
- package/out/es/adapters/sanidad-centros-ap/adapter.js.map +1 -0
- package/out/es/evaluation/sanidad-centros-ap.d.ts +34 -0
- package/out/es/evaluation/sanidad-centros-ap.d.ts.map +1 -0
- package/out/es/evaluation/sanidad-centros-ap.js +128 -0
- package/out/es/evaluation/sanidad-centros-ap.js.map +1 -0
- package/out/evaluation/corpus-adapter.d.ts +60 -0
- package/out/evaluation/corpus-adapter.d.ts.map +1 -0
- package/out/evaluation/corpus-adapter.js +100 -0
- package/out/evaluation/corpus-adapter.js.map +1 -0
- package/out/evaluation/source.d.ts +134 -0
- package/out/evaluation/source.d.ts.map +1 -0
- package/out/evaluation/source.js +80 -0
- package/out/evaluation/source.js.map +1 -0
- package/out/evaluation/sources.d.ts +6 -0
- package/out/evaluation/sources.d.ts.map +1 -0
- package/out/evaluation/sources.js +22 -0
- package/out/evaluation/sources.js.map +1 -0
- package/out/fr/adapters/laposte-poincont/adapter.d.ts +110 -0
- package/out/fr/adapters/laposte-poincont/adapter.d.ts.map +1 -0
- package/out/fr/adapters/laposte-poincont/adapter.js +315 -0
- package/out/fr/adapters/laposte-poincont/adapter.js.map +1 -0
- package/out/fr/recipes/unit-line-guideline.d.ts.map +1 -1
- package/out/fr/recipes/unit-line-guideline.js +8 -4
- package/out/fr/recipes/unit-line-guideline.js.map +1 -1
- package/out/fr/structures/laposte.d.ts +27 -0
- package/out/fr/structures/laposte.d.ts.map +1 -0
- package/out/fr/structures/laposte.js +96 -0
- package/out/fr/structures/laposte.js.map +1 -0
- package/out/fr/tools/fetch/laposte-poincont.d.ts +95 -0
- package/out/fr/tools/fetch/laposte-poincont.d.ts.map +1 -0
- package/out/fr/tools/fetch/laposte-poincont.js +135 -0
- package/out/fr/tools/fetch/laposte-poincont.js.map +1 -0
- package/out/it/adapters/miur-scuole/adapter.d.ts +9 -0
- package/out/it/adapters/miur-scuole/adapter.d.ts.map +1 -0
- package/out/it/adapters/miur-scuole/adapter.js +35 -0
- package/out/it/adapters/miur-scuole/adapter.js.map +1 -0
- package/out/it/evaluation/miur-scuole.d.ts +53 -0
- package/out/it/evaluation/miur-scuole.d.ts.map +1 -0
- package/out/it/evaluation/miur-scuole.js +68 -0
- package/out/it/evaluation/miur-scuole.js.map +1 -0
- package/out/jp/adapters/wof-admin/adapter.js +4 -4
- package/out/nc/adapters/opt-nc/adapter.d.ts +84 -0
- package/out/nc/adapters/opt-nc/adapter.d.ts.map +1 -0
- package/out/nc/adapters/opt-nc/adapter.js +173 -0
- package/out/nc/adapters/opt-nc/adapter.js.map +1 -0
- package/out/nc/structures/opt-nc.d.ts +12 -0
- package/out/nc/structures/opt-nc.d.ts.map +1 -0
- package/out/nc/structures/opt-nc.js +64 -0
- package/out/nc/structures/opt-nc.js.map +1 -0
- package/out/nc/tools/fetch/opt-nc.d.ts +81 -0
- package/out/nc/tools/fetch/opt-nc.d.ts.map +1 -0
- package/out/nc/tools/fetch/opt-nc.js +162 -0
- package/out/nc/tools/fetch/opt-nc.js.map +1 -0
- package/out/nz/adapters/charities-register/adapter.d.ts +9 -0
- package/out/nz/adapters/charities-register/adapter.d.ts.map +1 -0
- package/out/nz/adapters/charities-register/adapter.js +36 -0
- package/out/nz/adapters/charities-register/adapter.js.map +1 -0
- package/out/nz/evaluation/charities-register.d.ts +60 -0
- package/out/nz/evaluation/charities-register.d.ts.map +1 -0
- package/out/nz/evaluation/charities-register.js +84 -0
- package/out/nz/evaluation/charities-register.js.map +1 -0
- package/out/recipes/bare/postcode.d.ts +2 -1
- package/out/recipes/bare/postcode.d.ts.map +1 -1
- package/out/recipes/bare/postcode.js +14 -11
- package/out/recipes/bare/postcode.js.map +1 -1
- package/out/recipes/deepseek/batches.d.ts +11 -1
- package/out/recipes/deepseek/batches.d.ts.map +1 -1
- package/out/recipes/deepseek/batches.js +8 -7
- package/out/recipes/deepseek/batches.js.map +1 -1
- package/out/recipes/po/box/cedex/recipe.d.ts.map +1 -1
- package/out/recipes/po/box/cedex/recipe.js +12 -1
- package/out/recipes/po/box/cedex/recipe.js.map +1 -1
- package/out/recipes/po/box/cedex/us.d.ts +12 -0
- package/out/recipes/po/box/cedex/us.d.ts.map +1 -1
- package/out/recipes/po/box/cedex/us.js +36 -2
- package/out/recipes/po/box/cedex/us.js.map +1 -1
- package/out/recipes/scaffold.d.ts +1 -1
- package/out/recipes/sources.d.ts.map +1 -1
- package/out/recipes/sources.js +16 -0
- package/out/recipes/sources.js.map +1 -1
- package/out/recipes.d.ts.map +1 -1
- package/out/recipes.js +2 -0
- package/out/recipes.js.map +1 -1
- package/out/registers.d.ts +28 -2
- package/out/registers.d.ts.map +1 -1
- package/out/registers.js +28 -2
- package/out/registers.js.map +1 -1
- package/out/{post-offices → structures}/source.d.ts +34 -16
- package/out/structures/source.d.ts.map +1 -0
- package/out/structures/source.js +39 -0
- package/out/structures/source.js.map +1 -0
- package/out/structures/sources.d.ts +6 -0
- package/out/structures/sources.d.ts.map +1 -0
- package/out/structures/sources.js +23 -0
- package/out/structures/sources.js.map +1 -0
- package/out/synthesizers/house-venue.d.ts.map +1 -1
- package/out/synthesizers/house-venue.js +2 -1
- package/out/synthesizers/house-venue.js.map +1 -1
- package/out/synthesizers/tail.d.ts +15 -1
- package/out/synthesizers/tail.d.ts.map +1 -1
- package/out/synthesizers/tail.js +8 -3
- package/out/synthesizers/tail.js.map +1 -1
- package/out/tools/audit.js +1 -1
- package/out/tools/audit.js.map +1 -1
- package/out/tools/fetch/storage.d.ts +10 -2
- package/out/tools/fetch/storage.d.ts.map +1 -1
- package/out/tools/fetch/storage.js +18 -4
- package/out/tools/fetch/storage.js.map +1 -1
- package/out/tools/fetch.d.ts +10 -2
- package/out/tools/fetch.d.ts.map +1 -1
- package/out/tools/fetch.js +10 -2
- package/out/tools/fetch.js.map +1 -1
- package/out/tools/overlay/kryptonite.d.ts.map +1 -1
- package/out/tools/overlay/kryptonite.js +5 -2
- package/out/tools/overlay/kryptonite.js.map +1 -1
- package/out/tools/overlay/split/attribute.d.ts +7 -1
- package/out/tools/overlay/split/attribute.d.ts.map +1 -1
- package/out/tools/overlay/split/attribute.js +4 -1
- package/out/tools/overlay/split/attribute.js.map +1 -1
- package/out/tools/overlay/split/overlay.d.ts +10 -0
- package/out/tools/overlay/split/overlay.d.ts.map +1 -1
- package/out/tools/overlay/split/overlay.js +17 -4
- package/out/tools/overlay/split/overlay.js.map +1 -1
- package/out/tools/postcode/triples.js +3 -3
- package/out/tools/postcode/triples.js.map +1 -1
- package/out/tools/region-slot-census.run.d.ts +2 -0
- package/out/tools/region-slot-census.run.d.ts.map +1 -0
- package/out/tools/region-slot-census.run.js +134 -0
- package/out/tools/region-slot-census.run.js.map +1 -0
- package/out/training/config/load.d.ts.map +1 -1
- package/out/training/config/load.js +10 -0
- package/out/training/config/load.js.map +1 -1
- package/out/training/config/schema.d.ts +13 -0
- package/out/training/config/schema.d.ts.map +1 -1
- package/out/training/config/schema.js +6 -0
- package/out/training/config/schema.js.map +1 -1
- package/out/tw/registers.d.ts +9 -0
- package/out/tw/registers.d.ts.map +1 -1
- package/out/tw/registers.js +11 -4
- package/out/tw/registers.js.map +1 -1
- package/out/tw/structures/chunghwa-post.d.ts +39 -0
- package/out/tw/structures/chunghwa-post.d.ts.map +1 -0
- package/out/tw/structures/chunghwa-post.js +150 -0
- package/out/tw/structures/chunghwa-post.js.map +1 -0
- package/out/tw/tools/fetch/chunghwa-post.d.ts +55 -0
- package/out/tw/tools/fetch/chunghwa-post.d.ts.map +1 -0
- package/out/tw/tools/fetch/chunghwa-post.js +110 -0
- package/out/tw/tools/fetch/chunghwa-post.js.map +1 -0
- package/out/us/adapters/state/ny-notaries/adapter.d.ts.map +1 -1
- package/out/us/adapters/state/ny-notaries/adapter.js +7 -2
- package/out/us/adapters/state/ny-notaries/adapter.js.map +1 -1
- package/out/us/adapters/state/tx-notaries/adapter.d.ts +42 -0
- package/out/us/adapters/state/tx-notaries/adapter.d.ts.map +1 -1
- package/out/us/adapters/state/tx-notaries/adapter.js +92 -19
- package/out/us/adapters/state/tx-notaries/adapter.js.map +1 -1
- package/out/us/adapters/usgov/nad/adapter.d.ts +35 -2
- package/out/us/adapters/usgov/nad/adapter.d.ts.map +1 -1
- package/out/us/adapters/usgov/nad/adapter.js +90 -27
- package/out/us/adapters/usgov/nad/adapter.js.map +1 -1
- package/out/us/adapters/usgov/nppes/adapter.d.ts.map +1 -1
- package/out/us/adapters/usgov/nppes/adapter.js +8 -11
- package/out/us/adapters/usgov/nppes/adapter.js.map +1 -1
- package/out/us/adapters/usgov/usgs-structures/adapter.d.ts +87 -0
- package/out/us/adapters/usgov/usgs-structures/adapter.d.ts.map +1 -0
- package/out/us/adapters/usgov/{usgs-post-offices → usgs-structures}/adapter.js +36 -27
- package/out/us/adapters/usgov/usgs-structures/adapter.js.map +1 -0
- package/out/us/recipes/county.d.ts +124 -0
- package/out/us/recipes/county.d.ts.map +1 -0
- package/out/us/recipes/county.js +295 -0
- package/out/us/recipes/county.js.map +1 -0
- package/out/us/street-unit.d.ts +10 -3
- package/out/us/street-unit.d.ts.map +1 -1
- package/out/us/street-unit.js +14 -6
- package/out/us/street-unit.js.map +1 -1
- package/out/us/structures/usgs/layers.d.ts +57 -0
- package/out/us/structures/usgs/layers.d.ts.map +1 -0
- package/out/us/structures/usgs/layers.js +121 -0
- package/out/us/structures/usgs/layers.js.map +1 -0
- package/out/us/structures/usgs/national-map.d.ts +14 -0
- package/out/us/structures/usgs/national-map.d.ts.map +1 -0
- package/out/us/{post-offices/usgs-national-map.js → structures/usgs/national-map.js} +16 -14
- package/out/us/structures/usgs/national-map.js.map +1 -0
- package/out/us/tools/fetch/usgs/gnis.d.ts +118 -0
- package/out/us/tools/fetch/usgs/gnis.d.ts.map +1 -0
- package/out/us/tools/fetch/usgs/gnis.js +177 -0
- package/out/us/tools/fetch/usgs/gnis.js.map +1 -0
- package/out/us/tools/fetch/usgs/structures.d.ts +99 -0
- package/out/us/tools/fetch/usgs/structures.d.ts.map +1 -0
- package/out/us/tools/fetch/usgs/structures.js +233 -0
- package/out/us/tools/fetch/usgs/structures.js.map +1 -0
- package/out/utils/align.js.map +1 -1
- package/out/utils/evaluation-groups.d.ts +98 -0
- package/out/utils/evaluation-groups.d.ts.map +1 -0
- package/out/utils/evaluation-groups.js +92 -0
- package/out/utils/evaluation-groups.js.map +1 -0
- package/out/utils/split.d.ts +26 -1
- package/out/utils/split.d.ts.map +1 -1
- package/out/utils/split.js +28 -3
- package/out/utils/split.js.map +1 -1
- package/out/utils/tokenize.d.ts +3 -3
- package/out/utils/tokenize.d.ts.map +1 -1
- package/out/utils/tokenize.js.map +1 -1
- package/out/utils/validation-groups.d.ts +168 -0
- package/out/utils/validation-groups.d.ts.map +1 -0
- package/out/utils/validation-groups.js +135 -0
- package/out/utils/validation-groups.js.map +1 -0
- package/out/utils/wof-json.d.ts +31 -57
- package/out/utils/wof-json.d.ts.map +1 -1
- package/out/utils/wof-json.js +81 -98
- package/out/utils/wof-json.js.map +1 -1
- package/package.json +18 -18
- package/lib/adapters/wof/record-cache.ts +0 -118
- package/lib/build/heap.ts +0 -60
- package/lib/post-offices/sources.ts +0 -18
- package/lib/us/post-offices/usgs-national-map.ts +0 -89
- package/lib/us/tools/fetch/usgs-post-offices.ts +0 -362
- package/out/adapters/wof/record-cache.d.ts +0 -22
- package/out/adapters/wof/record-cache.d.ts.map +0 -1
- package/out/adapters/wof/record-cache.js +0 -89
- package/out/adapters/wof/record-cache.js.map +0 -1
- package/out/build/heap.d.ts +0 -26
- package/out/build/heap.d.ts.map +0 -1
- package/out/build/heap.js +0 -52
- package/out/build/heap.js.map +0 -1
- package/out/post-offices/source.d.ts.map +0 -1
- package/out/post-offices/source.js +0 -21
- package/out/post-offices/source.js.map +0 -1
- package/out/post-offices/sources.d.ts +0 -13
- package/out/post-offices/sources.d.ts.map +0 -1
- package/out/post-offices/sources.js +0 -8
- package/out/post-offices/sources.js.map +0 -1
- package/out/us/adapters/usgov/usgs-post-offices/adapter.d.ts +0 -66
- package/out/us/adapters/usgov/usgs-post-offices/adapter.d.ts.map +0 -1
- package/out/us/adapters/usgov/usgs-post-offices/adapter.js.map +0 -1
- package/out/us/post-offices/usgs-national-map.d.ts +0 -14
- package/out/us/post-offices/usgs-national-map.d.ts.map +0 -1
- package/out/us/post-offices/usgs-national-map.js.map +0 -1
- package/out/us/tools/fetch/usgs-post-offices.d.ts +0 -99
- package/out/us/tools/fetch/usgs-post-offices.d.ts.map +0 -1
- package/out/us/tools/fetch/usgs-post-offices.js +0 -246
- package/out/us/tools/fetch/usgs-post-offices.js.map +0 -1
package/lib/us/street-unit.ts
CHANGED
|
@@ -39,11 +39,21 @@ export function unitLine(line: string): string | null {
|
|
|
39
39
|
export type USStreetLineComponents = { po_box: string } | { house_number?: string; street: string; unit?: string }
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
* Splits one US street line, as a register writes it, into its address components.
|
|
43
|
-
*
|
|
44
42
|
* A whole line that's a box designator and an identifier holding a digit
|
|
45
|
-
* (`PO BOX 846`, `P.O. Box 10240`)
|
|
43
|
+
* (`PO BOX 846`, `P.O. Box 10240`, `POB 1088`) as the `po_box` component, or `null` for any other line.
|
|
44
|
+
*
|
|
46
45
|
* The digit requirement keeps a street such as `BOX ELDER RD` a street.
|
|
46
|
+
*/
|
|
47
|
+
export function usPOBoxLine(line: string): { po_box: string } | null {
|
|
48
|
+
const box = matchPOBox(line)
|
|
49
|
+
|
|
50
|
+
return box && /\d/u.test(box.id) ? { po_box: line.trim() } : null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Splits one US street line, as a register writes it, into its address components.
|
|
55
|
+
*
|
|
56
|
+
* A whole-line PO box ({@linkcode usPOBoxLine}) becomes `po_box`.
|
|
47
57
|
*
|
|
48
58
|
* Any other line takes the house number off its start with `splitStreetLine`
|
|
49
59
|
* and a secondary unit off its end with the shared unit splitter (`#adapters/street/unit`),
|
|
@@ -56,9 +66,9 @@ export function splitUSStreetLine(
|
|
|
56
66
|
units: UnitSplitter,
|
|
57
67
|
place: Omit<StreetPlace, "country"> = {}
|
|
58
68
|
): USStreetLineComponents | null {
|
|
59
|
-
const box =
|
|
69
|
+
const box = usPOBoxLine(line)
|
|
60
70
|
|
|
61
|
-
if (box
|
|
71
|
+
if (box) return box
|
|
62
72
|
const split = splitStreetLine(line)
|
|
63
73
|
|
|
64
74
|
if (!split) return null
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The point layers of the USGS National Map structures MapServer, one entry per layer the
|
|
6
|
+
* fetcher pulls, the adapter trains on, and the structures layer folds into `structures.db`.
|
|
7
|
+
*
|
|
8
|
+
* The service publishes every layer twice: layers 0–34 are the `Labels` group
|
|
9
|
+
* and serve the same rows as the `Features` layers 35 ids above them.
|
|
10
|
+
* The table lists the `Features` layers.
|
|
11
|
+
*
|
|
12
|
+
* The group layers (35, 36, 48, 52, 55, 59, 68) hold no features.
|
|
13
|
+
*
|
|
14
|
+
* Each layer is queried by its own id rather than by feature code, because a feature
|
|
15
|
+
* code isn't unique to a layer: Campgrounds (60) and Shelters (63) are both FCODE 82008.
|
|
16
|
+
*
|
|
17
|
+
* Layer 69, `Alaska Pipeline`, is left out: it holds polylines with no name, address
|
|
18
|
+
* or feature-level identifier, so it is neither a venue nor an address.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* One point layer of the structures MapServer.
|
|
23
|
+
*/
|
|
24
|
+
export interface USGSStructureLayer {
|
|
25
|
+
/**
|
|
26
|
+
* The layer's id in the MapServer's `Features` group.
|
|
27
|
+
*/
|
|
28
|
+
layerID: number
|
|
29
|
+
/**
|
|
30
|
+
* A stable identifier for the layer, stored on every fetched feature as `layer`.
|
|
31
|
+
*/
|
|
32
|
+
slug: string
|
|
33
|
+
/**
|
|
34
|
+
* The layer's name as the service states it.
|
|
35
|
+
*/
|
|
36
|
+
name: string
|
|
37
|
+
/**
|
|
38
|
+
* The `@mailwoman/poi-taxonomy` category id a feature of the layer is filed under.
|
|
39
|
+
*/
|
|
40
|
+
poiCategory: string
|
|
41
|
+
/**
|
|
42
|
+
* Whether the adapter emits venue-and-address training rows for the layer.
|
|
43
|
+
*
|
|
44
|
+
* A layer whose features have no street address (picnic areas, cabins, trailheads)
|
|
45
|
+
* is a retrieval layer only: its few addressed features describe the access road
|
|
46
|
+
* of a remote site rather than a delivery address.
|
|
47
|
+
*/
|
|
48
|
+
trains: boolean
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Every point layer of the structures MapServer, in layer-id order.
|
|
53
|
+
*/
|
|
54
|
+
export const USGS_STRUCTURE_LAYERS: readonly USGSStructureLayer[] = [
|
|
55
|
+
{ layerID: 37, slug: "cemeteries", name: "Cemeteries", poiCategory: "cemeteries", trains: true },
|
|
56
|
+
{ layerID: 38, slug: "post-offices", name: "Post Offices", poiCategory: "post_office", trains: true },
|
|
57
|
+
{ layerID: 39, slug: "city-town-halls", name: "City/Town Halls", poiCategory: "town_hall", trains: true },
|
|
58
|
+
{ layerID: 40, slug: "courthouses", name: "Courthouses", poiCategory: "courthouse", trains: true },
|
|
59
|
+
{
|
|
60
|
+
layerID: 41,
|
|
61
|
+
slug: "state-capitols",
|
|
62
|
+
name: "State Capitols",
|
|
63
|
+
poiCategory: "local_and_state_government_offices",
|
|
64
|
+
trains: true,
|
|
65
|
+
},
|
|
66
|
+
{ layerID: 42, slug: "state-supreme-courts", name: "State Supreme Courts", poiCategory: "courthouse", trains: true },
|
|
67
|
+
{
|
|
68
|
+
layerID: 43,
|
|
69
|
+
slug: "white-house",
|
|
70
|
+
name: "The White House",
|
|
71
|
+
poiCategory: "federal_government_offices",
|
|
72
|
+
trains: true,
|
|
73
|
+
},
|
|
74
|
+
{ layerID: 44, slug: "us-capitol", name: "U.S. Capitol", poiCategory: "federal_government_offices", trains: true },
|
|
75
|
+
{ layerID: 45, slug: "us-supreme-court", name: "U.S. Supreme Court", poiCategory: "courthouse", trains: true },
|
|
76
|
+
{
|
|
77
|
+
layerID: 46,
|
|
78
|
+
slug: "historic-sites",
|
|
79
|
+
name: "Historic Sites/Points of Interest",
|
|
80
|
+
poiCategory: "landmark_and_historical_building",
|
|
81
|
+
trains: false,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
layerID: 47,
|
|
85
|
+
slug: "national-symbols-monuments",
|
|
86
|
+
name: "National Symbols/Monuments",
|
|
87
|
+
poiCategory: "monument",
|
|
88
|
+
trains: false,
|
|
89
|
+
},
|
|
90
|
+
{ layerID: 49, slug: "hospitals", name: "Hospitals/Medical Centers", poiCategory: "hospital", trains: true },
|
|
91
|
+
{
|
|
92
|
+
layerID: 50,
|
|
93
|
+
slug: "ambulance-services",
|
|
94
|
+
name: "Ambulance Services",
|
|
95
|
+
poiCategory: "ambulance_and_ems_services",
|
|
96
|
+
trains: true,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
layerID: 51,
|
|
100
|
+
slug: "fire-ems-stations",
|
|
101
|
+
name: "Fire Stations/EMS Stations",
|
|
102
|
+
poiCategory: "fire_station",
|
|
103
|
+
trains: true,
|
|
104
|
+
},
|
|
105
|
+
{ layerID: 53, slug: "police-stations", name: "Police Stations", poiCategory: "police_station", trains: true },
|
|
106
|
+
{
|
|
107
|
+
layerID: 54,
|
|
108
|
+
slug: "prisons",
|
|
109
|
+
name: "Prisons/Correctional Facilities",
|
|
110
|
+
poiCategory: "jail_and_prison",
|
|
111
|
+
trains: true,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
layerID: 56,
|
|
115
|
+
slug: "colleges-universities",
|
|
116
|
+
name: "Colleges/Universities",
|
|
117
|
+
poiCategory: "college_university",
|
|
118
|
+
trains: true,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
layerID: 57,
|
|
122
|
+
slug: "technical-trade-schools",
|
|
123
|
+
name: "Technical/Trade Schools",
|
|
124
|
+
poiCategory: "vocational_and_technical_school",
|
|
125
|
+
trains: true,
|
|
126
|
+
},
|
|
127
|
+
{ layerID: 58, slug: "schools", name: "Schools", poiCategory: "school", trains: true },
|
|
128
|
+
{ layerID: 60, slug: "campgrounds", name: "Campgrounds", poiCategory: "campground", trains: false },
|
|
129
|
+
{ layerID: 61, slug: "trailheads", name: "Trailheads", poiCategory: "trail", trains: false },
|
|
130
|
+
{ layerID: 62, slug: "cabins", name: "Cabins", poiCategory: "cabin", trains: false },
|
|
131
|
+
// The publisher files shelters under the campground feature code, 82008.
|
|
132
|
+
{ layerID: 63, slug: "shelters", name: "Shelters", poiCategory: "campground", trains: false },
|
|
133
|
+
{ layerID: 64, slug: "picnic-areas", name: "Picnic Areas", poiCategory: "park", trains: false },
|
|
134
|
+
{
|
|
135
|
+
layerID: 65,
|
|
136
|
+
slug: "headquarters",
|
|
137
|
+
name: "Headquarters",
|
|
138
|
+
poiCategory: "federal_government_offices",
|
|
139
|
+
trains: true,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
layerID: 66,
|
|
143
|
+
slug: "visitor-centers",
|
|
144
|
+
name: "Visitor/Information Centers",
|
|
145
|
+
poiCategory: "visitor_center",
|
|
146
|
+
trains: true,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
layerID: 67,
|
|
150
|
+
slug: "ranger-stations",
|
|
151
|
+
name: "Ranger Stations",
|
|
152
|
+
poiCategory: "federal_government_offices",
|
|
153
|
+
trains: true,
|
|
154
|
+
},
|
|
155
|
+
]
|
|
156
|
+
|
|
157
|
+
const BY_ID = new Map(USGS_STRUCTURE_LAYERS.map((layer) => [layer.layerID, layer]))
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The layer with id `layerID`.
|
|
161
|
+
*
|
|
162
|
+
* @throws When the table holds no such layer, so a feature from an unlisted layer
|
|
163
|
+
* is never filed under a guessed category.
|
|
164
|
+
*/
|
|
165
|
+
export function usgsStructureLayer(layerID: number): USGSStructureLayer {
|
|
166
|
+
const layer = BY_ID.get(layerID)
|
|
167
|
+
|
|
168
|
+
if (!layer) throw new Error(`the USGS structures layer table holds no layer ${layerID}`)
|
|
169
|
+
|
|
170
|
+
return layer
|
|
171
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The United States entry of the structures layer: every point layer of the
|
|
6
|
+
* USGS National Map structures MapServer (`#us/structures/usgs/layers`),
|
|
7
|
+
* as `mailwoman corpus fetch usgs-structures` writes them.
|
|
8
|
+
*
|
|
9
|
+
* Each record is filed under its layer's POI category, so the post offices of layer
|
|
10
|
+
* 38 are the United States' post offices in the post-office parse suite.
|
|
11
|
+
*
|
|
12
|
+
* The list is the USGS's compilation rather than each operator's own facility list,
|
|
13
|
+
* so its provenance is a mapping agency's.
|
|
14
|
+
* A work of the United States Government, public domain under 17 U.S.C. § 105.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { PathBuilder } from "path-ts"
|
|
18
|
+
import { JSONSpliterator } from "spliterator"
|
|
19
|
+
|
|
20
|
+
import { createUnitSplitter, type UnitSplitter } from "#adapters/street/unit"
|
|
21
|
+
import {
|
|
22
|
+
StructureProvenance,
|
|
23
|
+
type StructureRecord,
|
|
24
|
+
type StructureSource,
|
|
25
|
+
type StructureSourceRead,
|
|
26
|
+
} from "#structures/source"
|
|
27
|
+
import { readManifest } from "#tools/fetch/download"
|
|
28
|
+
import {
|
|
29
|
+
USGOV_USGS_STRUCTURES_ADAPTER_ID,
|
|
30
|
+
USGS_STRUCTURES_FILENAME,
|
|
31
|
+
type USGSStructureFeature,
|
|
32
|
+
usgsStructureAddress,
|
|
33
|
+
} from "#us/adapters/usgov/usgs-structures/adapter"
|
|
34
|
+
import { usgsStructureLayer } from "#us/structures/usgs/layers"
|
|
35
|
+
import type { USGSStructuresManifest } from "#us/tools/fetch/usgs/structures"
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* One fetched feature as a structure record, or `null` when it has no permanent identifier.
|
|
39
|
+
*
|
|
40
|
+
* The address is split as the `usgov-usgs-structures` adapter splits it.
|
|
41
|
+
*/
|
|
42
|
+
export function usgsStructureRecord(feature: USGSStructureFeature, units: UnitSplitter): StructureRecord | null {
|
|
43
|
+
const id = feature.properties.permanent_identifier
|
|
44
|
+
|
|
45
|
+
if (!id) return null
|
|
46
|
+
|
|
47
|
+
const [longitude, latitude] = feature.geometry?.coordinates ?? []
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
id,
|
|
51
|
+
name: feature.properties.name,
|
|
52
|
+
category: usgsStructureLayer(feature.properties.layer_id).poiCategory,
|
|
53
|
+
point: typeof latitude === "number" && typeof longitude === "number" ? { latitude, longitude } : null,
|
|
54
|
+
address: usgsStructureAddress(feature.properties, units),
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function* records(path: PathBuilder): AsyncIterable<StructureRecord> {
|
|
59
|
+
const units = await createUnitSplitter()
|
|
60
|
+
|
|
61
|
+
for await (const feature of JSONSpliterator.fromAsync<USGSStructureFeature>(path.toString())) {
|
|
62
|
+
const record = usgsStructureRecord(feature, units)
|
|
63
|
+
|
|
64
|
+
if (record) {
|
|
65
|
+
yield record
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const FETCH_COMMAND = "mailwoman corpus fetch usgs-structures"
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The USGS National Map's structures.
|
|
74
|
+
*/
|
|
75
|
+
export const usgsNationalMapStructures: StructureSource = {
|
|
76
|
+
id: "usgs-national-map",
|
|
77
|
+
country: "US",
|
|
78
|
+
publisher: "U.S. Geological Survey",
|
|
79
|
+
attribution: "U.S. Geological Survey, The National Map",
|
|
80
|
+
license: "LicenseRef-USGov-Public-Domain",
|
|
81
|
+
registerSource: "us-public-administration-3",
|
|
82
|
+
provenance: StructureProvenance.MappingAgency,
|
|
83
|
+
fetchCommand: FETCH_COMMAND,
|
|
84
|
+
|
|
85
|
+
async read(sourcesRoot): Promise<StructureSourceRead> {
|
|
86
|
+
const directory = sourcesRoot(USGOV_USGS_STRUCTURES_ADAPTER_ID)
|
|
87
|
+
const manifest = await readManifest<USGSStructuresManifest>(directory("MANIFEST.json"))
|
|
88
|
+
|
|
89
|
+
if (!manifest?.downloaded_at) {
|
|
90
|
+
throw new Error(`${directory} holds no MANIFEST.json with a fetch date. Run \`${FETCH_COMMAND}\` first.`)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return { vintage: manifest.downloaded_at.slice(0, 10), records: records(directory(USGS_STRUCTURES_FILENAME)) }
|
|
94
|
+
},
|
|
95
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Fetches the Populated Places layer of the USGS National Map geonames MapServer: the Geographic
|
|
6
|
+
* Names Information System's populated places, one per GNIS id, in every state and territory.
|
|
7
|
+
*
|
|
8
|
+
* A work of the United States Government, public domain under 17 U.S.C. § 105.
|
|
9
|
+
*
|
|
10
|
+
* The layer answers at most 2,000 features per request, and `pageArcGISLayer` pages it by `OBJECTID`.
|
|
11
|
+
* Each place is written as one JSON line: its GNIS id, name, feature class, state, county and point.
|
|
12
|
+
*
|
|
13
|
+
* The layer stores a place's point as a one-point multipoint, and the fetcher writes that point.
|
|
14
|
+
*
|
|
15
|
+
* The service description is saved beside the places as `service.json`.
|
|
16
|
+
* Its `copyrightText` states the publisher's refresh date.
|
|
17
|
+
*
|
|
18
|
+
* Invoke via `mailwoman corpus fetch usgs-gnis`.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { APIClient } from "@mailwoman/core/api"
|
|
22
|
+
import { arcGISFields, arcGISInteger, arcGISText, pageArcGISLayer, readArcGISJSON } from "@mailwoman/core/api/arcgis"
|
|
23
|
+
import { ByteFormatter } from "@mailwoman/core/fs/formatters"
|
|
24
|
+
import { statPath } from "@mailwoman/core/fs/readers/stat"
|
|
25
|
+
import {
|
|
26
|
+
appendLocalTextFile,
|
|
27
|
+
makeDirectories,
|
|
28
|
+
movePath,
|
|
29
|
+
removePathIfPresent,
|
|
30
|
+
stagingSiblingPath,
|
|
31
|
+
writeLocalJSONFile,
|
|
32
|
+
} from "@mailwoman/core/fs/writers"
|
|
33
|
+
import { sha256File } from "@mailwoman/core/hash"
|
|
34
|
+
import { stringifyJSON } from "@mailwoman/core/json"
|
|
35
|
+
import { readPointCoordinates } from "@mailwoman/spatial/geometries/point/coordinates"
|
|
36
|
+
import { PathBuilder, type PathBuilderLike } from "path-ts"
|
|
37
|
+
|
|
38
|
+
import type { BaseFetchOptions, FetchSummary, SourceManifest } from "#tools/fetch/download"
|
|
39
|
+
import { writeManifest } from "#tools/fetch/download"
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The directory a fetch writes under, below the fetch root.
|
|
43
|
+
*/
|
|
44
|
+
export const USGS_GNIS_SLUG = "usgov-usgs-gnis"
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The geonames MapServer.
|
|
48
|
+
*/
|
|
49
|
+
export const USGS_GNIS_SERVICE_URL = "https://carto.nationalmap.gov/arcgis/rest/services/geonames/MapServer"
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The Populated Places layer of {@link USGS_GNIS_SERVICE_URL}.
|
|
53
|
+
*/
|
|
54
|
+
export const USGS_GNIS_POPULATED_PLACES_LAYER = 3
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The service's `maxRecordCount`: the most features one query returns.
|
|
58
|
+
*/
|
|
59
|
+
export const USGS_GNIS_PAGE_SIZE = 2000
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The layer fields the fetcher asks for, in the service's spelling.
|
|
63
|
+
*/
|
|
64
|
+
export const USGS_GNIS_FIELDS = [
|
|
65
|
+
"OBJECTID",
|
|
66
|
+
"gaz_id",
|
|
67
|
+
"gaz_name",
|
|
68
|
+
"gaz_featureclass",
|
|
69
|
+
"fcode",
|
|
70
|
+
"state_alpha",
|
|
71
|
+
"county_name",
|
|
72
|
+
"incounty_id",
|
|
73
|
+
"isunknowncoords",
|
|
74
|
+
] as const
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The file the places are written to.
|
|
78
|
+
*/
|
|
79
|
+
export const USGS_GNIS_PLACES_FILENAME = "populated-places.jsonl"
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The file the service description is saved to, beside the places.
|
|
83
|
+
*/
|
|
84
|
+
export const USGS_GNIS_SERVICE_FILENAME = "service.json"
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* One GNIS populated place as the fetch writes it.
|
|
88
|
+
*/
|
|
89
|
+
export interface GNISPopulatedPlace {
|
|
90
|
+
gnisID: number
|
|
91
|
+
name: string
|
|
92
|
+
featureClass: string | null
|
|
93
|
+
fcode: number | null
|
|
94
|
+
/**
|
|
95
|
+
* The USPS state or territory code.
|
|
96
|
+
*/
|
|
97
|
+
state: string | null
|
|
98
|
+
county: string | null
|
|
99
|
+
/**
|
|
100
|
+
* The GNIS id of the county the place lies in.
|
|
101
|
+
*/
|
|
102
|
+
countyGNISID: number | null
|
|
103
|
+
/**
|
|
104
|
+
* Whether GNIS marks the place's coordinates as unknown.
|
|
105
|
+
*/
|
|
106
|
+
unknownCoordinates: boolean
|
|
107
|
+
longitude: number | null
|
|
108
|
+
latitude: number | null
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* What one run recorded.
|
|
113
|
+
*
|
|
114
|
+
* `publisher_version` is the service's `copyrightText`, which states its refresh.
|
|
115
|
+
*/
|
|
116
|
+
export interface USGSGNISManifest extends SourceManifest {
|
|
117
|
+
service_url: string
|
|
118
|
+
layer_id: number
|
|
119
|
+
feature_count: number
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The point of a GeoJSON Point, or the first point of a MultiPoint, or `null` when it has none.
|
|
124
|
+
*
|
|
125
|
+
* `readPointCoordinates` refuses an out-of-range value and the `(0, 0)` placeholder.
|
|
126
|
+
*/
|
|
127
|
+
function firstPoint(geometry: unknown): [number, number] | null {
|
|
128
|
+
const { type, coordinates } = (geometry ?? {}) as { type?: unknown; coordinates?: unknown }
|
|
129
|
+
const point = readPointCoordinates(type === "MultiPoint" && Array.isArray(coordinates) ? coordinates[0] : geometry)
|
|
130
|
+
|
|
131
|
+
return point ? [point[0], point[1]] : null
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* One service feature as a {@link GNISPopulatedPlace}.
|
|
136
|
+
*
|
|
137
|
+
* @throws When the value isn't a GeoJSON feature, or has no GNIS id or name.
|
|
138
|
+
*/
|
|
139
|
+
export function normalizeGNISFeature(value: unknown): GNISPopulatedPlace {
|
|
140
|
+
if (value == null || typeof value !== "object" || (value as { type?: unknown }).type !== "Feature") {
|
|
141
|
+
throw new Error(`${USGS_GNIS_SLUG}: expected a GeoJSON Feature, got ${String(stringifyJSON(value)).slice(0, 200)}`)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const feature = value as { geometry?: unknown; properties?: unknown }
|
|
145
|
+
|
|
146
|
+
const properties = arcGISFields(feature.properties)
|
|
147
|
+
const gnisID = arcGISInteger(properties["gaz_id"])
|
|
148
|
+
const name = arcGISText(properties["gaz_name"])
|
|
149
|
+
|
|
150
|
+
if (gnisID === null || !name) {
|
|
151
|
+
throw new Error(`${USGS_GNIS_SLUG}: a feature has no GNIS id or name: ${String(stringifyJSON(properties))}`)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const point = firstPoint(feature.geometry)
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
gnisID,
|
|
158
|
+
name,
|
|
159
|
+
featureClass: arcGISText(properties["gaz_featureclass"]),
|
|
160
|
+
fcode: arcGISInteger(properties["fcode"]),
|
|
161
|
+
state: arcGISText(properties["state_alpha"])?.toUpperCase() ?? null,
|
|
162
|
+
county: arcGISText(properties["county_name"]),
|
|
163
|
+
countyGNISID: arcGISInteger(properties["incounty_id"]),
|
|
164
|
+
unknownCoordinates: arcGISInteger(properties["isunknowncoords"]) === 1,
|
|
165
|
+
longitude: point?.[0] ?? null,
|
|
166
|
+
latitude: point?.[1] ?? null,
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Per-invocation options.
|
|
172
|
+
*/
|
|
173
|
+
export interface DownloadUSGSGNISOptions {
|
|
174
|
+
outputDir: PathBuilderLike
|
|
175
|
+
signal?: AbortSignal
|
|
176
|
+
report?: (line: string) => void
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Pages the Populated Places layer into `<outputDir>/populated-places.jsonl` and writes the manifest.
|
|
181
|
+
*
|
|
182
|
+
* The places are written to a staging file.
|
|
183
|
+
* The file moves into place only once the pull holds the feature count the service stated.
|
|
184
|
+
* A failed run leaves the previous file as it was.
|
|
185
|
+
*/
|
|
186
|
+
export async function downloadUSGSGNIS(
|
|
187
|
+
client: Pick<APIClient, "fetch">,
|
|
188
|
+
options: DownloadUSGSGNISOptions
|
|
189
|
+
): Promise<FetchSummary> {
|
|
190
|
+
const { report, signal } = options
|
|
191
|
+
const destDir = PathBuilder.from(options.outputDir)
|
|
192
|
+
const placesPath = destDir(USGS_GNIS_PLACES_FILENAME)
|
|
193
|
+
|
|
194
|
+
report?.(`=== ${USGS_GNIS_SLUG} / ${USGS_GNIS_PLACES_FILENAME}`)
|
|
195
|
+
|
|
196
|
+
const service = await readArcGISJSON<{ copyrightText?: string }>(
|
|
197
|
+
client,
|
|
198
|
+
`${USGS_GNIS_SERVICE_URL}?f=json`,
|
|
199
|
+
USGS_GNIS_SLUG,
|
|
200
|
+
signal
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
report?.(` ${service.copyrightText ?? "no copyrightText"}`)
|
|
204
|
+
|
|
205
|
+
await makeDirectories(destDir)
|
|
206
|
+
|
|
207
|
+
const staging = stagingSiblingPath(placesPath)
|
|
208
|
+
let written = 0
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
await appendLocalTextFile("", staging)
|
|
212
|
+
|
|
213
|
+
const pages = pageArcGISLayer(
|
|
214
|
+
client,
|
|
215
|
+
{ serviceURL: USGS_GNIS_SERVICE_URL, layerID: USGS_GNIS_POPULATED_PLACES_LAYER },
|
|
216
|
+
{
|
|
217
|
+
outFields: USGS_GNIS_FIELDS,
|
|
218
|
+
pageSize: USGS_GNIS_PAGE_SIZE,
|
|
219
|
+
context: USGS_GNIS_SLUG,
|
|
220
|
+
signal,
|
|
221
|
+
onCount: (count) => report?.(` Populated Places: ${count.toLocaleString()} features`),
|
|
222
|
+
onPage: (done, count) => report?.(` ${done.toLocaleString()} / ${count.toLocaleString()}`),
|
|
223
|
+
}
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
for await (const page of pages) {
|
|
227
|
+
const places = page.map(normalizeGNISFeature)
|
|
228
|
+
|
|
229
|
+
await appendLocalTextFile(`${places.map((place) => stringifyJSON(place)).join("\n")}\n`, staging)
|
|
230
|
+
written += places.length
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
await movePath(staging, placesPath)
|
|
234
|
+
} finally {
|
|
235
|
+
await removePathIfPresent(staging)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
await writeLocalJSONFile(service as Record<string, unknown>, destDir(USGS_GNIS_SERVICE_FILENAME))
|
|
239
|
+
|
|
240
|
+
const sha256 = await sha256File(placesPath)
|
|
241
|
+
const { size: bytes } = await statPath(placesPath)
|
|
242
|
+
|
|
243
|
+
const manifest: USGSGNISManifest = {
|
|
244
|
+
source_url: USGS_GNIS_SERVICE_URL,
|
|
245
|
+
service_url: USGS_GNIS_SERVICE_URL,
|
|
246
|
+
layer_id: USGS_GNIS_POPULATED_PLACES_LAYER,
|
|
247
|
+
filename: USGS_GNIS_PLACES_FILENAME,
|
|
248
|
+
feature_count: written,
|
|
249
|
+
bytes,
|
|
250
|
+
sha256,
|
|
251
|
+
...(service.copyrightText ? { publisher_version: service.copyrightText } : {}),
|
|
252
|
+
downloaded_at: new Date().toISOString(),
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
await writeManifest(destDir("MANIFEST.json"), manifest)
|
|
256
|
+
|
|
257
|
+
report?.(` ✓ ${written.toLocaleString()} places, ${ByteFormatter.formatIEC(bytes)} sha256=${sha256}`)
|
|
258
|
+
|
|
259
|
+
return { fetched: 1, skipped: 0, failed: 0, failedCodes: [] }
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* The path a fetch under `outRoot` writes the places to.
|
|
264
|
+
*/
|
|
265
|
+
export function usgsGNISPlacesPath(outRoot: BaseFetchOptions["outRoot"]): PathBuilderLike {
|
|
266
|
+
return outRoot(USGS_GNIS_SLUG, USGS_GNIS_PLACES_FILENAME)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Per-invocation options for the registry entry.
|
|
271
|
+
*/
|
|
272
|
+
export interface FetchUSGSGNISOptions extends BaseFetchOptions {
|
|
273
|
+
signal?: AbortSignal
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* The registry entry.
|
|
278
|
+
*/
|
|
279
|
+
export async function fetchUSGSGNIS(
|
|
280
|
+
options: FetchUSGSGNISOptions,
|
|
281
|
+
report?: (line: string) => void
|
|
282
|
+
): Promise<FetchSummary> {
|
|
283
|
+
// One request at a time with a pause between them: a full pull is about 100 requests to a public service.
|
|
284
|
+
await using client = new APIClient({ displayName: USGS_GNIS_SLUG, retry: true, minRequestIntervalMs: 500 })
|
|
285
|
+
|
|
286
|
+
// Awaited rather than returned, because `await using` disposes the client when this scope exits.
|
|
287
|
+
return await downloadUSGSGNIS(client, { outputDir: options.outRoot(USGS_GNIS_SLUG), signal: options.signal, report })
|
|
288
|
+
}
|