@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
|
@@ -2,23 +2,28 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* `usgov-usgs-
|
|
5
|
+
* `usgov-usgs-structures`: the National Structures Dataset served by the USGS
|
|
6
|
+
* National Map structures MapServer.
|
|
7
|
+
*
|
|
8
|
+
* The dataset holds public facilities across the states and the five primary territories:
|
|
9
|
+
* schools, colleges, hospitals, fire, police and ambulance stations, prisons,
|
|
10
|
+
* courthouses, town halls, post offices, cemeteries, and recreation sites.
|
|
11
|
+
* `#us/structures/usgs/layers` lists each point layer.
|
|
6
12
|
*
|
|
7
|
-
* The National Structures Dataset's layer 38 holds the United States Postal Service
|
|
8
|
-
* facilities (feature code 78006) across the states and the five primary territories.
|
|
9
13
|
* Each feature holds a permanent identifier, the facility's name, its street address,
|
|
10
14
|
* city, state and ZIP Code, and a point.
|
|
11
15
|
*
|
|
12
|
-
* `mailwoman corpus fetch usgs-
|
|
13
|
-
* with the ZIP Code as a string whose leading zeros are intact.
|
|
16
|
+
* `mailwoman corpus fetch usgs-structures` writes one GeoJSON feature per line,
|
|
17
|
+
* with the ZIP Code as a string whose leading zeros are intact and the layer it came from.
|
|
14
18
|
*
|
|
15
19
|
* Each row is the facility's name as a venue followed by its address,
|
|
16
20
|
* the same venue-plus-address shape as `usgov-hrsa-fqhc`.
|
|
17
21
|
* `venue` is inserted first so alignment claims its span before `locality` searches for its own:
|
|
18
22
|
* "Palm Bay West Post Office, …, Palm Bay, FL" holds the locality's words inside the venue.
|
|
23
|
+
* A layer whose `trains` flag is unset yields no row.
|
|
19
24
|
*
|
|
20
25
|
* License: a work of the United States Government, public domain under 17 U.S.C. § 105.
|
|
21
|
-
* The service describes the
|
|
26
|
+
* The service describes the dataset as "public domain structures data".
|
|
22
27
|
*/
|
|
23
28
|
|
|
24
29
|
import { formatAddressRow } from "@mailwoman/codex/address/format"
|
|
@@ -30,31 +35,47 @@ import { streetIndexOpener } from "#street-index/reader"
|
|
|
30
35
|
import { AddressRole, type AdapterOptions, type CanonicalRow, type CorpusAdapter, SurfaceOrigin } from "#types"
|
|
31
36
|
import { lookupStateAbbreviation } from "#us/fips-state"
|
|
32
37
|
import { splitUSStreetLine } from "#us/street-unit"
|
|
38
|
+
import { usgsStructureLayer } from "#us/structures/usgs/layers"
|
|
33
39
|
|
|
34
40
|
/**
|
|
35
41
|
* Registry id for this adapter, and the source directory its fetcher writes.
|
|
36
42
|
*/
|
|
37
|
-
export const
|
|
43
|
+
export const USGOV_USGS_STRUCTURES_ADAPTER_ID = "usgov-usgs-structures"
|
|
38
44
|
|
|
39
45
|
/**
|
|
40
46
|
* License stamped on each row: a US federal work, public domain under 17 U.S.C. § 105.
|
|
41
47
|
*/
|
|
42
|
-
export const
|
|
48
|
+
export const USGOV_USGS_STRUCTURES_DEFAULT_LICENSE = "Public Domain"
|
|
43
49
|
|
|
44
50
|
/**
|
|
45
51
|
* The file the fetcher writes and the adapter reads, one GeoJSON feature per line.
|
|
46
52
|
*/
|
|
47
|
-
export const
|
|
53
|
+
export const USGS_STRUCTURES_FILENAME = "structures.geojsonl"
|
|
48
54
|
|
|
49
55
|
/**
|
|
50
|
-
* The properties of one
|
|
56
|
+
* The properties of one structure as the fetcher writes them.
|
|
51
57
|
*
|
|
52
|
-
* Keys are the service's field names in lower case
|
|
58
|
+
* Keys are the service's field names in lower case, plus `layer_id` and `layer`.
|
|
53
59
|
* A field the service left empty is `null`.
|
|
54
60
|
*/
|
|
55
|
-
export interface
|
|
61
|
+
export interface USGSStructureProperties {
|
|
62
|
+
/**
|
|
63
|
+
* The id of the MapServer layer the feature was read from.
|
|
64
|
+
*/
|
|
65
|
+
layer_id: number
|
|
66
|
+
/**
|
|
67
|
+
* The layer's slug in `#us/structures/usgs/layers`.
|
|
68
|
+
*/
|
|
69
|
+
layer: string
|
|
70
|
+
/**
|
|
71
|
+
* The service's `OBJECTID`, unique across the layers.
|
|
72
|
+
*/
|
|
73
|
+
objectid: number
|
|
56
74
|
permanent_identifier: string | null
|
|
75
|
+
fcode: number | null
|
|
76
|
+
gnis_id: string | null
|
|
57
77
|
name: string | null
|
|
78
|
+
addressbuildingname: string | null
|
|
58
79
|
address: string | null
|
|
59
80
|
city: string | null
|
|
60
81
|
state: string | null
|
|
@@ -66,26 +87,31 @@ export interface USGSPostOfficeProperties {
|
|
|
66
87
|
* The value the service published, present only when it differs from `zipcode`.
|
|
67
88
|
*/
|
|
68
89
|
zipcode_published?: string
|
|
90
|
+
/**
|
|
91
|
+
* The date the publisher loaded the feature, as an ISO 8601 date, or `null` when unstated.
|
|
92
|
+
*/
|
|
93
|
+
loaddate: string | null
|
|
94
|
+
source_originator: string | null
|
|
69
95
|
}
|
|
70
96
|
|
|
71
97
|
/**
|
|
72
|
-
* One
|
|
98
|
+
* One structure as the fetcher writes it.
|
|
73
99
|
*/
|
|
74
|
-
export interface
|
|
100
|
+
export interface USGSStructureFeature {
|
|
75
101
|
type: "Feature"
|
|
76
102
|
geometry: { type: "Point"; coordinates: [longitude: number, latitude: number] } | null
|
|
77
|
-
properties:
|
|
103
|
+
properties: USGSStructureProperties
|
|
78
104
|
}
|
|
79
105
|
|
|
80
106
|
/**
|
|
81
|
-
* A
|
|
82
|
-
*
|
|
107
|
+
* A structure's address as labeled components, or `null` when it lacks a street address,
|
|
108
|
+
* city, recognized state or ZIP Code.
|
|
83
109
|
*
|
|
84
110
|
* `splitUSStreetLine` moves a trailing suite into `unit` when the remainder still reads as a street:
|
|
85
111
|
* by a street-type word, a number, or the street index scoped to the row's city and ZIP Code.
|
|
86
112
|
*/
|
|
87
|
-
export function
|
|
88
|
-
properties:
|
|
113
|
+
export function usgsStructureAddress(
|
|
114
|
+
properties: Pick<USGSStructureProperties, "address" | "city" | "state" | "zipcode">,
|
|
89
115
|
units: UnitSplitter
|
|
90
116
|
): CanonicalRow["components"] | null {
|
|
91
117
|
const { address, city, state: stateCode, zipcode } = properties
|
|
@@ -99,37 +125,41 @@ export function usgsPostOfficeAddress(
|
|
|
99
125
|
}
|
|
100
126
|
|
|
101
127
|
/**
|
|
102
|
-
* Creates the
|
|
128
|
+
* Creates the structures adapter.
|
|
103
129
|
*
|
|
104
|
-
* A
|
|
105
|
-
* yields no row, because the row's purpose
|
|
130
|
+
* A structure in a layer that doesn't train, or with no name or no full address
|
|
131
|
+
* ({@linkcode usgsStructureAddress}), yields no row, because the row's purpose
|
|
132
|
+
* is the venue beside a full address.
|
|
106
133
|
*/
|
|
107
|
-
export function
|
|
134
|
+
export function createUSGovUSGSStructuresAdapter(): CorpusAdapter {
|
|
108
135
|
return {
|
|
109
|
-
id:
|
|
110
|
-
defaultLicense:
|
|
136
|
+
id: USGOV_USGS_STRUCTURES_ADAPTER_ID,
|
|
137
|
+
defaultLicense: USGOV_USGS_STRUCTURES_DEFAULT_LICENSE,
|
|
111
138
|
addressRole: AddressRole.Facility,
|
|
112
|
-
register: SourceRegister.
|
|
139
|
+
register: SourceRegister.USGSStructures,
|
|
113
140
|
surface: SurfaceOrigin.Rendered,
|
|
114
141
|
description:
|
|
115
|
-
"USGS National
|
|
142
|
+
"USGS National Structures Dataset (public domain). Venue + address co-occurrence for the schools, hospitals, emergency stations, government buildings, post offices and cemeteries the National Map holds.",
|
|
116
143
|
|
|
117
144
|
async *rows(opts: AdapterOptions): AsyncIterable<CanonicalRow> {
|
|
118
145
|
if (opts.country && opts.country !== "US") {
|
|
119
|
-
throw new Error(`${
|
|
146
|
+
throw new Error(`${USGOV_USGS_STRUCTURES_ADAPTER_ID} adapter: only US supported, got country=${opts.country}`)
|
|
120
147
|
}
|
|
121
148
|
|
|
122
149
|
const units = await createUnitSplitter({ streetIndex: streetIndexOpener(opts.streetIndex) })
|
|
123
150
|
|
|
124
151
|
let emitted = 0
|
|
125
152
|
|
|
126
|
-
for await (const feature of JSONSpliterator.fromAsync<
|
|
153
|
+
for await (const feature of JSONSpliterator.fromAsync<USGSStructureFeature>(opts.inputPath)) {
|
|
127
154
|
if (opts.signal?.aborted) break
|
|
128
155
|
|
|
129
156
|
if (typeof opts.limit === "number" && emitted >= opts.limit) break
|
|
130
157
|
|
|
131
|
-
const { permanent_identifier: id, name } = feature.properties
|
|
132
|
-
|
|
158
|
+
const { permanent_identifier: id, name, layer_id: layerID } = feature.properties
|
|
159
|
+
|
|
160
|
+
if (!usgsStructureLayer(layerID).trains) continue
|
|
161
|
+
|
|
162
|
+
const address = usgsStructureAddress(feature.properties, units)
|
|
133
163
|
|
|
134
164
|
if (!id || !name || !address) continue
|
|
135
165
|
|
|
@@ -145,9 +175,9 @@ export function createUSGovUSGSPostOfficesAdapter(): CorpusAdapter {
|
|
|
145
175
|
components: rendered.components,
|
|
146
176
|
country: "US",
|
|
147
177
|
locale: "en-US",
|
|
148
|
-
source:
|
|
149
|
-
source_id: `${
|
|
150
|
-
license:
|
|
178
|
+
source: USGOV_USGS_STRUCTURES_ADAPTER_ID,
|
|
179
|
+
source_id: `${USGOV_USGS_STRUCTURES_ADAPTER_ID}-${id}`,
|
|
180
|
+
license: USGOV_USGS_STRUCTURES_DEFAULT_LICENSE,
|
|
151
181
|
}
|
|
152
182
|
|
|
153
183
|
emitted++
|
|
@@ -159,4 +189,4 @@ export function createUSGovUSGSPostOfficesAdapter(): CorpusAdapter {
|
|
|
159
189
|
/**
|
|
160
190
|
* The configured adapter instance registered with the corpus builder.
|
|
161
191
|
*/
|
|
162
|
-
export const
|
|
192
|
+
export const usgovUSGSStructuresAdapter = createUSGovUSGSStructuresAdapter()
|
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `us-county` — US counties written as an address writes them, read from Who's On First.
|
|
6
|
+
*
|
|
7
|
+
* The recipe writes three sources, so a training config weighs each shape on its own:
|
|
8
|
+
*
|
|
9
|
+
* - `rendered-us-county`: `Polk County, OR` and `Polk County, Oregon`, two rows per county.
|
|
10
|
+
* - `rendered-us-city-county`: `Dallas, Polk County, OR 97338`, a WOF locality inside
|
|
11
|
+
* that county, with one of the locality's ZIP Codes on half the rows that have one.
|
|
12
|
+
* - `rendered-us-city-state`: `Dallas, OR` and `Dallas, OR 97338`, the same localities without
|
|
13
|
+
* the county, so a trailing `, CA` has California rows to weigh against the Canadian ones.
|
|
14
|
+
*
|
|
15
|
+
* The designator (`County`, `Parish`, `Borough`, `Census Area`, `City and Borough`)
|
|
16
|
+
* is part of the `subregion` span.
|
|
17
|
+
* WOF's admin database writes a county's name bare (`Polk`), so the designator comes from
|
|
18
|
+
* the record's own `wof:label` (`Polk County`), else from an English name that writes one.
|
|
19
|
+
*
|
|
20
|
+
* A county whose records write none, and an independent city (`City of Richmond`), get no county row.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { splitUSCountyDesignator, type USCountyDesignator } from "@mailwoman/codex/us/county"
|
|
24
|
+
import { lookupUSState, US_STATE_BY_ABBREVIATION, type USStateAbbreviation } from "@mailwoman/codex/us/state"
|
|
25
|
+
import { dataRootPath } from "@mailwoman/core/data-root"
|
|
26
|
+
import { assertPathExists } from "@mailwoman/core/fs/readers/stat"
|
|
27
|
+
import { mulberry32, shuffleWith } from "@mailwoman/core/random"
|
|
28
|
+
import {
|
|
29
|
+
storedWOFRecords,
|
|
30
|
+
wofRecordStorePathFor,
|
|
31
|
+
type WOFRecordStoreDatabase,
|
|
32
|
+
} from "@mailwoman/gazetteer/whosonfirst/record-store"
|
|
33
|
+
import { wofDatabasePath } from "@mailwoman/resolver-wof-sqlite/paths"
|
|
34
|
+
import type { WOFDatabase } from "@mailwoman/resolver-wof-sqlite/schema"
|
|
35
|
+
import { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
36
|
+
import type { PathBuilderLike } from "path-ts"
|
|
37
|
+
|
|
38
|
+
import { alignAndWrite, type CanonicalRecipeRow, type CorpusRecipe, recipeSourceID } from "#recipes/scaffold"
|
|
39
|
+
import { defaultRecipeSource } from "#recipes/sources"
|
|
40
|
+
import { SourceRegister } from "#registers"
|
|
41
|
+
import { SurfaceOrigin } from "#types"
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* One county with the designator its WOF records write.
|
|
45
|
+
*/
|
|
46
|
+
export interface USCounty {
|
|
47
|
+
id: number
|
|
48
|
+
/**
|
|
49
|
+
* The county as an address writes it: `Polk County`.
|
|
50
|
+
*/
|
|
51
|
+
surface: string
|
|
52
|
+
designator: USCountyDesignator
|
|
53
|
+
state: USStateAbbreviation
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* One WOF locality inside exactly one county, with the ZIP Codes whose parent it is.
|
|
58
|
+
*/
|
|
59
|
+
export interface USCountyLocality {
|
|
60
|
+
id: number
|
|
61
|
+
name: string
|
|
62
|
+
countyID: number
|
|
63
|
+
postcodes: readonly string[]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* What {@link readUSCountyPool} read, and what it set aside with the reason.
|
|
68
|
+
*/
|
|
69
|
+
export interface USCountyPool {
|
|
70
|
+
counties: readonly USCounty[]
|
|
71
|
+
localities: readonly USCountyLocality[]
|
|
72
|
+
/**
|
|
73
|
+
* Current US county records the pool holds no county for, keyed by why.
|
|
74
|
+
*/
|
|
75
|
+
setAside: Readonly<Record<"noDesignator" | "noState", readonly string[]>>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The surface a county's WOF record writes it with: the first of `wof:label`
|
|
80
|
+
* and its English names that's its own name followed by a designator.
|
|
81
|
+
*/
|
|
82
|
+
export function countySurface(
|
|
83
|
+
name: string,
|
|
84
|
+
written: readonly unknown[]
|
|
85
|
+
): { surface: string; designator: USCountyDesignator } | null {
|
|
86
|
+
for (const candidate of written) {
|
|
87
|
+
if (typeof candidate !== "string") continue
|
|
88
|
+
|
|
89
|
+
const split = splitUSCountyDesignator(candidate)
|
|
90
|
+
|
|
91
|
+
if (split && split.name.toLowerCase() === name.trim().toLowerCase()) {
|
|
92
|
+
return { surface: `${split.name} ${split.designator}`, designator: split.designator }
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return null
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Where {@link readUSCountyPool} reads.
|
|
101
|
+
*/
|
|
102
|
+
export interface USCountyPoolPaths {
|
|
103
|
+
/**
|
|
104
|
+
* @defaultValue `$MAILWOMAN_DATA_ROOT/db/wof/admin-global-priority.db`
|
|
105
|
+
*/
|
|
106
|
+
adminDB?: PathBuilderLike
|
|
107
|
+
/**
|
|
108
|
+
* @defaultValue `$MAILWOMAN_DATA_ROOT/db/wof/postalcode-us.db`
|
|
109
|
+
*/
|
|
110
|
+
postcodeDB?: PathBuilderLike
|
|
111
|
+
/**
|
|
112
|
+
* The WOF record store.
|
|
113
|
+
* It keeps each record's `wof:label`.
|
|
114
|
+
*
|
|
115
|
+
* @defaultValue the store for `$MAILWOMAN_DATA_ROOT/src/wof-repos`
|
|
116
|
+
*/
|
|
117
|
+
recordStore?: PathBuilderLike
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Reads every current US county, its state and its designator, and every current locality
|
|
122
|
+
* that WOF places in exactly one of those counties, with its ZIP Codes.
|
|
123
|
+
*
|
|
124
|
+
* @throws When a database is absent, because a pool read without one would hold
|
|
125
|
+
* no designators or no ZIP Codes and still look whole.
|
|
126
|
+
*/
|
|
127
|
+
export async function readUSCountyPool(paths: USCountyPoolPaths = {}): Promise<USCountyPool> {
|
|
128
|
+
const adminDB = paths.adminDB ?? wofDatabasePath("admin-global-priority.db")
|
|
129
|
+
const postcodeDB = paths.postcodeDB ?? wofDatabasePath("postalcode-us.db")
|
|
130
|
+
const recordStore = paths.recordStore ?? wofRecordStorePathFor(dataRootPath("src", "wof-repos"))
|
|
131
|
+
|
|
132
|
+
await assertPathExists(adminDB, `us-county: no admin gazetteer at ${adminDB}`)
|
|
133
|
+
await assertPathExists(postcodeDB, `us-county: no US postcode database at ${postcodeDB}`)
|
|
134
|
+
await assertPathExists(recordStore, `us-county: no WOF record store at ${recordStore}`)
|
|
135
|
+
|
|
136
|
+
const written = new Map<number, unknown[]>()
|
|
137
|
+
|
|
138
|
+
{
|
|
139
|
+
using store = new DatabaseClient<WOFRecordStoreDatabase>(recordStore, { readOnly: true })
|
|
140
|
+
|
|
141
|
+
for (const record of storedWOFRecords(store, { country: "US", placetypes: new Set(["county"]) })) {
|
|
142
|
+
const properties = record.feature.properties ?? {}
|
|
143
|
+
const variants = properties["name:eng_x_variant"]
|
|
144
|
+
|
|
145
|
+
written.set(record.id, [properties["wof:label"], ...(Array.isArray(variants) ? variants : [])])
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
using db = new DatabaseClient<WOFDatabase>(adminDB, { readOnly: true })
|
|
150
|
+
|
|
151
|
+
const countyRecords = db
|
|
152
|
+
.prepare(
|
|
153
|
+
`SELECT s.id AS id, s.name AS name, min(r.name) AS region
|
|
154
|
+
FROM spr s
|
|
155
|
+
JOIN ancestors a ON a.id = s.id AND a.ancestor_placetype = 'region'
|
|
156
|
+
JOIN spr r ON r.id = a.ancestor_id
|
|
157
|
+
WHERE s.country = 'US' AND s.placetype = 'county' AND s.is_current != 0 AND s.is_deprecated = 0
|
|
158
|
+
GROUP BY s.id ORDER BY s.id`
|
|
159
|
+
)
|
|
160
|
+
.all() as Array<{ id: number; name: string; region: string }>
|
|
161
|
+
|
|
162
|
+
const englishVariants = db.prepare(
|
|
163
|
+
`SELECT name FROM names WHERE id = ? AND language = 'eng' AND privateuse = 'variant' ORDER BY name`
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
const counties: USCounty[] = []
|
|
167
|
+
const noDesignator: string[] = []
|
|
168
|
+
const noState: string[] = []
|
|
169
|
+
|
|
170
|
+
for (const row of countyRecords) {
|
|
171
|
+
const state = lookupUSState(row.region)
|
|
172
|
+
|
|
173
|
+
if (!state) {
|
|
174
|
+
noState.push(`${row.id} ${row.name}, ${row.region}`)
|
|
175
|
+
|
|
176
|
+
continue
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const variants = (englishVariants.all(row.id) as Array<{ name: string }>).map((v) => v.name)
|
|
180
|
+
const found = countySurface(row.name, [...(written.get(row.id) ?? []), ...variants])
|
|
181
|
+
|
|
182
|
+
if (!found) {
|
|
183
|
+
noDesignator.push(`${row.id} ${row.name}, ${state}`)
|
|
184
|
+
|
|
185
|
+
continue
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
counties.push({ id: row.id, ...found, state })
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const known = new Set(counties.map((county) => county.id))
|
|
192
|
+
const postcodes = new Map<number, string[]>()
|
|
193
|
+
|
|
194
|
+
{
|
|
195
|
+
using pc = new DatabaseClient<WOFDatabase>(postcodeDB, { readOnly: true })
|
|
196
|
+
|
|
197
|
+
for (const row of pc
|
|
198
|
+
.prepare(
|
|
199
|
+
`SELECT parent_id, name FROM spr WHERE placetype = 'postalcode' AND parent_id > 0 AND is_current != 0 ORDER BY name`
|
|
200
|
+
)
|
|
201
|
+
.all() as Array<{ parent_id: number; name: string }>) {
|
|
202
|
+
const list = postcodes.get(row.parent_id) ?? []
|
|
203
|
+
|
|
204
|
+
list.push(row.name)
|
|
205
|
+
postcodes.set(row.parent_id, list)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// A locality WOF places in two counties names neither as its own.
|
|
210
|
+
const localityRows = db
|
|
211
|
+
.prepare(
|
|
212
|
+
`SELECT s.id AS id, s.name AS name, min(a.ancestor_id) AS county_id
|
|
213
|
+
FROM spr s
|
|
214
|
+
JOIN ancestors a ON a.id = s.id AND a.ancestor_placetype = 'county'
|
|
215
|
+
WHERE s.country = 'US' AND s.placetype = 'locality' AND s.is_current != 0 AND s.is_deprecated = 0
|
|
216
|
+
GROUP BY s.id HAVING count(DISTINCT a.ancestor_id) = 1 ORDER BY s.id`
|
|
217
|
+
)
|
|
218
|
+
.all() as Array<{ id: number; name: string; county_id: number }>
|
|
219
|
+
|
|
220
|
+
const localities = localityRows
|
|
221
|
+
.filter((row) => row.name.trim() && known.has(row.county_id))
|
|
222
|
+
.map((row) => ({
|
|
223
|
+
id: row.id,
|
|
224
|
+
name: row.name.trim(),
|
|
225
|
+
countyID: row.county_id,
|
|
226
|
+
postcodes: postcodes.get(row.id) ?? [],
|
|
227
|
+
}))
|
|
228
|
+
|
|
229
|
+
return { counties, localities, setAside: { noDesignator, noState } }
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The three sources this recipe writes, in the table spelling {@linkcode defaultRecipeSource} answers.
|
|
234
|
+
*/
|
|
235
|
+
export const US_COUNTY_SOURCES = {
|
|
236
|
+
county: defaultRecipeSource("synth-us-county"),
|
|
237
|
+
cityCounty: defaultRecipeSource("synth-us-city-county"),
|
|
238
|
+
cityState: defaultRecipeSource("synth-us-city-state"),
|
|
239
|
+
} as const
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* One row the recipe writes, before alignment, with the template that shaped it.
|
|
243
|
+
*/
|
|
244
|
+
export interface USCountyRow {
|
|
245
|
+
canonical: CanonicalRecipeRow
|
|
246
|
+
template: string
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const LICENSE = "Who's On First — us-county; county, locality and ZIP Code records (CC0/ODC-By per source)"
|
|
250
|
+
|
|
251
|
+
function recipeRow(
|
|
252
|
+
source: string,
|
|
253
|
+
template: string,
|
|
254
|
+
raw: string,
|
|
255
|
+
components: Record<string, string>,
|
|
256
|
+
parts: Record<string, string>
|
|
257
|
+
): USCountyRow {
|
|
258
|
+
return {
|
|
259
|
+
template,
|
|
260
|
+
canonical: {
|
|
261
|
+
raw,
|
|
262
|
+
components,
|
|
263
|
+
country: "US",
|
|
264
|
+
locale: "en-US",
|
|
265
|
+
source,
|
|
266
|
+
source_id: recipeSourceID(source, { template, ...parts }),
|
|
267
|
+
license: LICENSE,
|
|
268
|
+
},
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Every county's two bare rows, `Polk County, OR` and `Polk County, Oregon`.
|
|
274
|
+
*/
|
|
275
|
+
export function countyRows(counties: readonly USCounty[]): USCountyRow[] {
|
|
276
|
+
return counties.flatMap((county) => {
|
|
277
|
+
const stateName = US_STATE_BY_ABBREVIATION[county.state]
|
|
278
|
+
const parts = { county: String(county.id) }
|
|
279
|
+
|
|
280
|
+
return [
|
|
281
|
+
recipeRow(
|
|
282
|
+
US_COUNTY_SOURCES.county,
|
|
283
|
+
"us-county:code",
|
|
284
|
+
`${county.surface}, ${county.state}`,
|
|
285
|
+
{ subregion: county.surface, region: county.state },
|
|
286
|
+
parts
|
|
287
|
+
),
|
|
288
|
+
recipeRow(
|
|
289
|
+
US_COUNTY_SOURCES.county,
|
|
290
|
+
"us-county:name",
|
|
291
|
+
`${county.surface}, ${stateName}`,
|
|
292
|
+
{ subregion: county.surface, region: stateName },
|
|
293
|
+
parts
|
|
294
|
+
),
|
|
295
|
+
]
|
|
296
|
+
})
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Localities in a seeded order that reaches every group before any group's second:
|
|
301
|
+
* each round takes the next locality of every group.
|
|
302
|
+
*/
|
|
303
|
+
function roundRobin(
|
|
304
|
+
localities: readonly USCountyLocality[],
|
|
305
|
+
groupOf: (locality: USCountyLocality) => string,
|
|
306
|
+
random: () => number
|
|
307
|
+
): USCountyLocality[] {
|
|
308
|
+
const groups = new Map<string, USCountyLocality[]>()
|
|
309
|
+
|
|
310
|
+
for (const locality of localities) {
|
|
311
|
+
const key = groupOf(locality)
|
|
312
|
+
const list = groups.get(key) ?? []
|
|
313
|
+
|
|
314
|
+
list.push(locality)
|
|
315
|
+
groups.set(key, list)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const order = [...groups.keys()]
|
|
319
|
+
|
|
320
|
+
shuffleWith(order, random)
|
|
321
|
+
|
|
322
|
+
for (const list of groups.values()) {
|
|
323
|
+
shuffleWith(list, random)
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const out: USCountyLocality[] = []
|
|
327
|
+
const deepest = Math.max(0, ...[...groups.values()].map((list) => list.length))
|
|
328
|
+
|
|
329
|
+
for (let round = 0; round < deepest; round++) {
|
|
330
|
+
for (const key of order) {
|
|
331
|
+
const locality = groups.get(key)![round]
|
|
332
|
+
|
|
333
|
+
if (locality) {
|
|
334
|
+
out.push(locality)
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return out
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Draws a ZIP Code for every other row whose locality has one, from that locality's own,
|
|
344
|
+
* so the rows with a ZIP Code and those without split the localities that have one.
|
|
345
|
+
*/
|
|
346
|
+
function postcodeDrawer(random: () => number): (locality: USCountyLocality) => string | null {
|
|
347
|
+
let eligible = 0
|
|
348
|
+
|
|
349
|
+
return (locality) => {
|
|
350
|
+
if (!locality.postcodes.length || eligible++ % 2 === 1) return null
|
|
351
|
+
|
|
352
|
+
return locality.postcodes[Math.floor(random() * locality.postcodes.length)]!
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* `<City>, <Name> County, <ST>[ <ZIP>]` rows, at most `count`, spread so every
|
|
358
|
+
* county contributes a row before any contributes a second.
|
|
359
|
+
*/
|
|
360
|
+
export function cityCountyRows(pool: USCountyPool, count: number, random: () => number): USCountyRow[] {
|
|
361
|
+
const counties = new Map(pool.counties.map((county) => [county.id, county]))
|
|
362
|
+
const drawPostcode = postcodeDrawer(random)
|
|
363
|
+
|
|
364
|
+
return roundRobin(pool.localities, (locality) => String(locality.countyID), random)
|
|
365
|
+
.slice(0, count)
|
|
366
|
+
.map((locality) => {
|
|
367
|
+
const county = counties.get(locality.countyID)!
|
|
368
|
+
const postcode = drawPostcode(locality)
|
|
369
|
+
const tail = postcode ? `${county.state} ${postcode}` : county.state
|
|
370
|
+
|
|
371
|
+
return recipeRow(
|
|
372
|
+
US_COUNTY_SOURCES.cityCounty,
|
|
373
|
+
postcode ? "us-county:city-county-zip" : "us-county:city-county",
|
|
374
|
+
`${locality.name}, ${county.surface}, ${tail}`,
|
|
375
|
+
{
|
|
376
|
+
locality: locality.name,
|
|
377
|
+
subregion: county.surface,
|
|
378
|
+
region: county.state,
|
|
379
|
+
...(postcode ? { postcode } : {}),
|
|
380
|
+
},
|
|
381
|
+
{ locality: String(locality.id), county: String(county.id), postcode: postcode ?? "" }
|
|
382
|
+
)
|
|
383
|
+
})
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* `<City>, <ST>[ <ZIP>]` rows, at most `count`, spread so every state contributes a row
|
|
388
|
+
* before any contributes a second.
|
|
389
|
+
*/
|
|
390
|
+
export function cityStateRows(pool: USCountyPool, count: number, random: () => number): USCountyRow[] {
|
|
391
|
+
const counties = new Map(pool.counties.map((county) => [county.id, county]))
|
|
392
|
+
const drawPostcode = postcodeDrawer(random)
|
|
393
|
+
|
|
394
|
+
return roundRobin(pool.localities, (locality) => counties.get(locality.countyID)!.state, random)
|
|
395
|
+
.slice(0, count)
|
|
396
|
+
.map((locality) => {
|
|
397
|
+
const state = counties.get(locality.countyID)!.state
|
|
398
|
+
const postcode = drawPostcode(locality)
|
|
399
|
+
|
|
400
|
+
return recipeRow(
|
|
401
|
+
US_COUNTY_SOURCES.cityState,
|
|
402
|
+
postcode ? "us-county:city-state-zip" : "us-county:city-state",
|
|
403
|
+
postcode ? `${locality.name}, ${state} ${postcode}` : `${locality.name}, ${state}`,
|
|
404
|
+
{ locality: locality.name, region: state, ...(postcode ? { postcode } : {}) },
|
|
405
|
+
{ locality: String(locality.id), postcode: postcode ?? "" }
|
|
406
|
+
)
|
|
407
|
+
})
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* The rows read straight from a published record, so the register is WOF's.
|
|
412
|
+
*/
|
|
413
|
+
const US_COUNTY_PROVENANCE = {
|
|
414
|
+
register: SourceRegister.WhosOnFirst,
|
|
415
|
+
surface: SurfaceOrigin.Composed,
|
|
416
|
+
// The WOF ids that make each row are in its `source_id` parts.
|
|
417
|
+
// No corpus row stands behind it.
|
|
418
|
+
baseSourceID: null,
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Recipe registered with the corpus builder.
|
|
423
|
+
*/
|
|
424
|
+
export const usCountyRecipe: CorpusRecipe = {
|
|
425
|
+
name: "us-county",
|
|
426
|
+
description:
|
|
427
|
+
"US counties from WOF: 'Polk County, OR', 'Polk County, Oregon', 'Dallas, Polk County, OR 97338' and 'Dallas, OR[ 97338]'",
|
|
428
|
+
mode: "generate",
|
|
429
|
+
options: [
|
|
430
|
+
{
|
|
431
|
+
flag: "--count <n>",
|
|
432
|
+
description:
|
|
433
|
+
"Rows for each of rendered-us-city-county and rendered-us-city-state. Every county writes its two rendered-us-county rows regardless.",
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
flag: "--admin-db <path>",
|
|
437
|
+
description: "WOF admin database. Default $MAILWOMAN_DATA_ROOT/db/wof/admin-global-priority.db",
|
|
438
|
+
},
|
|
439
|
+
],
|
|
440
|
+
async run(opts, write) {
|
|
441
|
+
const count = opts.count ?? 0
|
|
442
|
+
|
|
443
|
+
if (!(count >= 0)) throw new Error(`us-county: --count must be a non-negative number, got ${opts.count}`)
|
|
444
|
+
|
|
445
|
+
const pool = await readUSCountyPool({ adminDB: opts.adminDB })
|
|
446
|
+
|
|
447
|
+
console.error(
|
|
448
|
+
` us-county: ${pool.counties.length} counties, ${pool.localities.length} localities; ` +
|
|
449
|
+
`set aside ${pool.setAside.noDesignator.length} with no designator (${pool.setAside.noDesignator.join("; ")}) ` +
|
|
450
|
+
`and ${pool.setAside.noState.length} with no state`
|
|
451
|
+
)
|
|
452
|
+
|
|
453
|
+
const random = mulberry32(opts.seed)
|
|
454
|
+
|
|
455
|
+
const rows = [
|
|
456
|
+
...countyRows(pool.counties),
|
|
457
|
+
...cityCountyRows(pool, count, random),
|
|
458
|
+
...cityStateRows(pool, count, random),
|
|
459
|
+
]
|
|
460
|
+
|
|
461
|
+
let emitted = 0
|
|
462
|
+
let skipped = 0
|
|
463
|
+
|
|
464
|
+
for (const { canonical, template } of rows) {
|
|
465
|
+
if (alignAndWrite(write, canonical, template, US_COUNTY_PROVENANCE)) {
|
|
466
|
+
emitted++
|
|
467
|
+
} else {
|
|
468
|
+
skipped++
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
return { read: pool.counties.length + pool.localities.length, emitted, skipped }
|
|
473
|
+
},
|
|
474
|
+
}
|