@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
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Fetches every point layer of the USGS National Map structures MapServer
|
|
6
|
+
* (`#us/structures/usgs/layers`), the source of the `usgov-usgs-structures` adapter.
|
|
7
|
+
* US public domain under 17 U.S.C. § 105.
|
|
8
|
+
*
|
|
9
|
+
* Each layer is an ArcGIS MapServer layer that answers at most 2,000 features per request.
|
|
10
|
+
* `pageArcGISLayer` asks each layer for its feature count, then pages it by `OBJECTID`.
|
|
11
|
+
*
|
|
12
|
+
* A `resultOffset` query slows as the offset grows (1.7 s for the first page of Cemeteries
|
|
13
|
+
* and 8.7 s at offset 184,000, against 0.8 s for the same page by `OBJECTID`).
|
|
14
|
+
* A pull whose feature count for any layer differs from the count the service stated is refused.
|
|
15
|
+
*
|
|
16
|
+
* Each feature is written as one GeoJSON line carrying its layer id and slug,
|
|
17
|
+
* with its ZIP Code as a string, leading zeros intact, normalized by `normalizeZIPCode`
|
|
18
|
+
* where the feature's state is known.
|
|
19
|
+
*
|
|
20
|
+
* The service description is saved beside the features as `service.json`, because it holds the
|
|
21
|
+
* publisher's statement about the data ("public domain structures data") and its refresh date.
|
|
22
|
+
*
|
|
23
|
+
* Invoke via `mailwoman corpus fetch usgs-structures`.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { isUSStateAbbreviation } from "@mailwoman/codex/us/state"
|
|
27
|
+
import { normalizeZIPCode } from "@mailwoman/codex/us/zipcode"
|
|
28
|
+
import { APIClient } from "@mailwoman/core/api"
|
|
29
|
+
import { arcGISFields, arcGISInteger, arcGISText, pageArcGISLayer, readArcGISJSON } from "@mailwoman/core/api/arcgis"
|
|
30
|
+
import { ByteFormatter } from "@mailwoman/core/fs/formatters"
|
|
31
|
+
import { statPath } from "@mailwoman/core/fs/readers/stat"
|
|
32
|
+
import {
|
|
33
|
+
appendLocalTextFile,
|
|
34
|
+
makeDirectories,
|
|
35
|
+
movePath,
|
|
36
|
+
removePathIfPresent,
|
|
37
|
+
stagingSiblingPath,
|
|
38
|
+
writeLocalJSONFile,
|
|
39
|
+
} from "@mailwoman/core/fs/writers"
|
|
40
|
+
import { sha256File } from "@mailwoman/core/hash"
|
|
41
|
+
import { stringifyJSON } from "@mailwoman/core/json"
|
|
42
|
+
import { isoDate } from "@mailwoman/core/utils"
|
|
43
|
+
import { PathBuilder, type PathBuilderLike } from "path-ts"
|
|
44
|
+
|
|
45
|
+
import type { BaseFetchOptions, FetchSummary, SourceManifest } from "#tools/fetch/download"
|
|
46
|
+
import { writeManifest } from "#tools/fetch/download"
|
|
47
|
+
import {
|
|
48
|
+
USGOV_USGS_STRUCTURES_ADAPTER_ID,
|
|
49
|
+
USGS_STRUCTURES_FILENAME,
|
|
50
|
+
type USGSStructureFeature,
|
|
51
|
+
type USGSStructureProperties,
|
|
52
|
+
} from "#us/adapters/usgov/usgs-structures/adapter"
|
|
53
|
+
import { USGS_STRUCTURE_LAYERS, type USGSStructureLayer } from "#us/structures/usgs/layers"
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The structures MapServer.
|
|
57
|
+
*
|
|
58
|
+
* Its description states the publisher's terms and refresh date.
|
|
59
|
+
*/
|
|
60
|
+
export const USGS_STRUCTURES_SERVICE_URL = "https://carto.nationalmap.gov/arcgis/rest/services/structures/MapServer"
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The service's `maxRecordCount`: the most features one query returns.
|
|
64
|
+
*/
|
|
65
|
+
export const USGS_STRUCTURES_PAGE_SIZE = 2000
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The service fields the fetcher asks for, in the service's spelling.
|
|
69
|
+
*/
|
|
70
|
+
export const USGS_STRUCTURE_FIELDS = [
|
|
71
|
+
"OBJECTID",
|
|
72
|
+
"PERMANENT_IDENTIFIER",
|
|
73
|
+
"FCODE",
|
|
74
|
+
"GNIS_ID",
|
|
75
|
+
"NAME",
|
|
76
|
+
"ADDRESSBUILDINGNAME",
|
|
77
|
+
"ADDRESS",
|
|
78
|
+
"CITY",
|
|
79
|
+
"STATE",
|
|
80
|
+
"ZIPCODE",
|
|
81
|
+
"LOADDATE",
|
|
82
|
+
"SOURCE_ORIGINATOR",
|
|
83
|
+
] as const
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The file the service description is saved to, beside the features.
|
|
87
|
+
*/
|
|
88
|
+
export const USGS_STRUCTURES_SERVICE_FILENAME = "service.json"
|
|
89
|
+
|
|
90
|
+
const SLUG = USGOV_USGS_STRUCTURES_ADAPTER_ID
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* What one layer contributed to a run.
|
|
94
|
+
*/
|
|
95
|
+
export interface USGSStructuresLayerCount {
|
|
96
|
+
layer_id: number
|
|
97
|
+
layer: string
|
|
98
|
+
name: string
|
|
99
|
+
feature_count: number
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* What one run recorded.
|
|
104
|
+
*
|
|
105
|
+
* `publisher_version` is the service's `copyrightText`, which states its
|
|
106
|
+
* refresh (`USGS TNM – National Structures Dataset. Data Refreshed October, 2026.`).
|
|
107
|
+
*/
|
|
108
|
+
export interface USGSStructuresManifest extends SourceManifest {
|
|
109
|
+
service_url: string
|
|
110
|
+
feature_count: number
|
|
111
|
+
layers: USGSStructuresLayerCount[]
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The parts of the MapServer description a fetch records.
|
|
116
|
+
*/
|
|
117
|
+
interface StructuresService {
|
|
118
|
+
copyrightText?: string
|
|
119
|
+
serviceDescription?: string
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A date field as an ISO 8601 date.
|
|
124
|
+
* The service answers a date as epoch milliseconds.
|
|
125
|
+
*/
|
|
126
|
+
function dateField(value: unknown): string | null {
|
|
127
|
+
const milliseconds = arcGISInteger(value)
|
|
128
|
+
|
|
129
|
+
return milliseconds === null ? null : isoDate(new Date(milliseconds))
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The ZIP Code fields for one structure.
|
|
134
|
+
*
|
|
135
|
+
* A known state passes the value through `normalizeZIPCode`, which restores leading zeros a numeric
|
|
136
|
+
* value lost (`725` in Puerto Rico is `00725`) and reads a value that isn't a ZIP Code as `null`.
|
|
137
|
+
* An unknown state keeps the trimmed value.
|
|
138
|
+
*
|
|
139
|
+
* The published value is kept beside the result whenever the two differ.
|
|
140
|
+
*/
|
|
141
|
+
export function structureZIPCode(
|
|
142
|
+
value: unknown,
|
|
143
|
+
state: string | null
|
|
144
|
+
): Pick<USGSStructureProperties, "zipcode" | "zipcode_published"> {
|
|
145
|
+
const published = arcGISText(value)
|
|
146
|
+
|
|
147
|
+
if (!published) return { zipcode: null }
|
|
148
|
+
|
|
149
|
+
const zipcode = state && isUSStateAbbreviation(state) ? normalizeZIPCode(published, state) : published
|
|
150
|
+
|
|
151
|
+
return zipcode === published ? { zipcode } : { zipcode, zipcode_published: published }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* One service feature of `layer` in the shape the adapter reads.
|
|
156
|
+
*
|
|
157
|
+
* @throws When the value isn't a GeoJSON feature, or has no `OBJECTID`.
|
|
158
|
+
*/
|
|
159
|
+
export function normalizeStructureFeature(
|
|
160
|
+
value: unknown,
|
|
161
|
+
layer: Pick<USGSStructureLayer, "layerID" | "slug">
|
|
162
|
+
): USGSStructureFeature {
|
|
163
|
+
if (value == null || typeof value !== "object" || (value as { type?: unknown }).type !== "Feature") {
|
|
164
|
+
throw new Error(`${SLUG}: expected a GeoJSON Feature, got ${String(stringifyJSON(value)).slice(0, 200)}`)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const feature = value as { geometry?: unknown; properties?: unknown }
|
|
168
|
+
const properties = arcGISFields(feature.properties)
|
|
169
|
+
const objectid = arcGISInteger(properties["objectid"])
|
|
170
|
+
|
|
171
|
+
if (objectid === null) {
|
|
172
|
+
throw new Error(`${SLUG}: layer ${layer.layerID} answered a feature with no OBJECTID`)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const state = arcGISText(properties["state"])?.toUpperCase() ?? null
|
|
176
|
+
|
|
177
|
+
const geometry = (feature.geometry ?? {}) as { type?: unknown; coordinates?: unknown }
|
|
178
|
+
const coordinates: number[] = Array.isArray(geometry.coordinates) ? geometry.coordinates.map(Number) : []
|
|
179
|
+
|
|
180
|
+
const point =
|
|
181
|
+
geometry.type === "Point" &&
|
|
182
|
+
coordinates.length >= 2 &&
|
|
183
|
+
coordinates.every((coordinate) => Number.isFinite(coordinate))
|
|
184
|
+
? { type: "Point" as const, coordinates: [coordinates[0]!, coordinates[1]!] as [number, number] }
|
|
185
|
+
: null
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
type: "Feature",
|
|
189
|
+
geometry: point,
|
|
190
|
+
properties: {
|
|
191
|
+
layer_id: layer.layerID,
|
|
192
|
+
layer: layer.slug,
|
|
193
|
+
objectid,
|
|
194
|
+
permanent_identifier: arcGISText(properties["permanent_identifier"]),
|
|
195
|
+
fcode: arcGISInteger(properties["fcode"]),
|
|
196
|
+
gnis_id: arcGISText(properties["gnis_id"]),
|
|
197
|
+
name: arcGISText(properties["name"]),
|
|
198
|
+
addressbuildingname: arcGISText(properties["addressbuildingname"]),
|
|
199
|
+
address: arcGISText(properties["address"]),
|
|
200
|
+
city: arcGISText(properties["city"]),
|
|
201
|
+
state,
|
|
202
|
+
...structureZIPCode(properties["zipcode"], state),
|
|
203
|
+
loaddate: dateField(properties["loaddate"]),
|
|
204
|
+
source_originator: arcGISText(properties["source_originator"]),
|
|
205
|
+
},
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Per-invocation options.
|
|
211
|
+
*/
|
|
212
|
+
export interface DownloadUSGSStructuresOptions {
|
|
213
|
+
outputDir: PathBuilderLike
|
|
214
|
+
/**
|
|
215
|
+
* The layers to pull.
|
|
216
|
+
*
|
|
217
|
+
* @defaultValue {@linkcode USGS_STRUCTURE_LAYERS}
|
|
218
|
+
*/
|
|
219
|
+
layers?: readonly USGSStructureLayer[]
|
|
220
|
+
signal?: AbortSignal
|
|
221
|
+
report?: (line: string) => void
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Pages every feature of one layer into `staging`, and returns the number written.
|
|
226
|
+
*
|
|
227
|
+
* @throws When {@link pageArcGISLayer} refuses the pull, or a feature isn't one the adapter can read.
|
|
228
|
+
*/
|
|
229
|
+
async function pullLayer(
|
|
230
|
+
client: Pick<APIClient, "fetch">,
|
|
231
|
+
layer: USGSStructureLayer,
|
|
232
|
+
staging: PathBuilderLike,
|
|
233
|
+
options: Pick<DownloadUSGSStructuresOptions, "signal" | "report">
|
|
234
|
+
): Promise<number> {
|
|
235
|
+
const { signal, report } = options
|
|
236
|
+
let written = 0
|
|
237
|
+
|
|
238
|
+
const pages = pageArcGISLayer(
|
|
239
|
+
client,
|
|
240
|
+
{ serviceURL: USGS_STRUCTURES_SERVICE_URL, layerID: layer.layerID },
|
|
241
|
+
{
|
|
242
|
+
outFields: USGS_STRUCTURE_FIELDS,
|
|
243
|
+
pageSize: USGS_STRUCTURES_PAGE_SIZE,
|
|
244
|
+
context: SLUG,
|
|
245
|
+
signal,
|
|
246
|
+
onCount: (count) => report?.(` ${layer.layerID} ${layer.name}: ${count.toLocaleString()} features`),
|
|
247
|
+
onPage: (done, count) => report?.(` ${done.toLocaleString()} / ${count.toLocaleString()}`),
|
|
248
|
+
}
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
for await (const page of pages) {
|
|
252
|
+
const features = page.map((feature) => normalizeStructureFeature(feature, layer))
|
|
253
|
+
|
|
254
|
+
await appendLocalTextFile(`${features.map((feature) => stringifyJSON(feature)).join("\n")}\n`, staging)
|
|
255
|
+
written += features.length
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return written
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Pages every layer into `<outputDir>/structures.geojsonl` and writes the manifest.
|
|
263
|
+
*
|
|
264
|
+
* The features are written to a staging file.
|
|
265
|
+
* It moves into place only once every layer's pull holds the feature count the service stated.
|
|
266
|
+
* A failed run leaves the previous file as it was.
|
|
267
|
+
*
|
|
268
|
+
* @throws When the service answers an error, a page that isn't a FeatureCollection,
|
|
269
|
+
* or a layer pull whose size differs from its count.
|
|
270
|
+
*/
|
|
271
|
+
export async function downloadUSGSStructures(
|
|
272
|
+
client: Pick<APIClient, "fetch">,
|
|
273
|
+
options: DownloadUSGSStructuresOptions
|
|
274
|
+
): Promise<FetchSummary> {
|
|
275
|
+
const { report, signal } = options
|
|
276
|
+
const layers = options.layers ?? USGS_STRUCTURE_LAYERS
|
|
277
|
+
const destDir = PathBuilder.from(options.outputDir)
|
|
278
|
+
const featuresPath = destDir(USGS_STRUCTURES_FILENAME)
|
|
279
|
+
|
|
280
|
+
report?.(`=== ${SLUG} / ${USGS_STRUCTURES_FILENAME}`)
|
|
281
|
+
|
|
282
|
+
const service = await readArcGISJSON<StructuresService>(client, `${USGS_STRUCTURES_SERVICE_URL}?f=json`, SLUG, signal)
|
|
283
|
+
|
|
284
|
+
report?.(` ${service.copyrightText ?? "no copyrightText"}; ${layers.length} layers`)
|
|
285
|
+
|
|
286
|
+
await makeDirectories(destDir)
|
|
287
|
+
|
|
288
|
+
const staging = stagingSiblingPath(featuresPath)
|
|
289
|
+
const counts: USGSStructuresLayerCount[] = []
|
|
290
|
+
|
|
291
|
+
try {
|
|
292
|
+
// An empty pull writes no page, and an empty input is a valid one.
|
|
293
|
+
await appendLocalTextFile("", staging)
|
|
294
|
+
|
|
295
|
+
for (const layer of layers) {
|
|
296
|
+
const written = await pullLayer(client, layer, staging, { signal, report })
|
|
297
|
+
|
|
298
|
+
counts.push({ layer_id: layer.layerID, layer: layer.slug, name: layer.name, feature_count: written })
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
await movePath(staging, featuresPath)
|
|
302
|
+
} finally {
|
|
303
|
+
await removePathIfPresent(staging)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
await writeLocalJSONFile(service as Record<string, unknown>, destDir(USGS_STRUCTURES_SERVICE_FILENAME))
|
|
307
|
+
|
|
308
|
+
const sha256 = await sha256File(featuresPath)
|
|
309
|
+
const { size: bytes } = await statPath(featuresPath)
|
|
310
|
+
const total = counts.reduce((sum, layer) => sum + layer.feature_count, 0)
|
|
311
|
+
|
|
312
|
+
const manifest: USGSStructuresManifest = {
|
|
313
|
+
source_url: USGS_STRUCTURES_SERVICE_URL,
|
|
314
|
+
service_url: USGS_STRUCTURES_SERVICE_URL,
|
|
315
|
+
filename: USGS_STRUCTURES_FILENAME,
|
|
316
|
+
feature_count: total,
|
|
317
|
+
layers: counts,
|
|
318
|
+
bytes,
|
|
319
|
+
sha256,
|
|
320
|
+
...(service.copyrightText ? { publisher_version: service.copyrightText } : {}),
|
|
321
|
+
downloaded_at: new Date().toISOString(),
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
await writeManifest(destDir("MANIFEST.json"), manifest)
|
|
325
|
+
|
|
326
|
+
report?.(` ✓ ${total.toLocaleString()} features, ${ByteFormatter.formatIEC(bytes)} sha256=${sha256}`)
|
|
327
|
+
|
|
328
|
+
return { fetched: 1, skipped: 0, failed: 0, failedCodes: [] }
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* The path `#us/adapters/usgov/usgs-structures/adapter` reads, given the root a fetch wrote under.
|
|
333
|
+
*/
|
|
334
|
+
export function usgsStructuresInputPath(outRoot: BaseFetchOptions["outRoot"]): PathBuilderLike {
|
|
335
|
+
return outRoot(SLUG, USGS_STRUCTURES_FILENAME)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Per-invocation options for the registry entry.
|
|
340
|
+
*/
|
|
341
|
+
export interface FetchUSGSStructuresOptions extends BaseFetchOptions {
|
|
342
|
+
signal?: AbortSignal
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* The registry entry.
|
|
347
|
+
*/
|
|
348
|
+
export async function fetchUSGSStructures(
|
|
349
|
+
options: FetchUSGSStructuresOptions,
|
|
350
|
+
report?: (line: string) => void
|
|
351
|
+
): Promise<FetchSummary> {
|
|
352
|
+
// One request at a time with a pause between them: a full pull is about 270 requests to a public service.
|
|
353
|
+
await using client = new APIClient({ displayName: SLUG, retry: true, minRequestIntervalMs: 500 })
|
|
354
|
+
|
|
355
|
+
// Awaited rather than returned: `await using` disposes the client when this scope exits,
|
|
356
|
+
// and a disposed `APIClient` refuses every later request.
|
|
357
|
+
return await downloadUSGSStructures(client, {
|
|
358
|
+
outputDir: options.outRoot(SLUG),
|
|
359
|
+
signal: options.signal,
|
|
360
|
+
report,
|
|
361
|
+
})
|
|
362
|
+
}
|
package/lib/utils/align.ts
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
34
|
import type { BIOLabel, ComponentTag } from "@mailwoman/codex/component"
|
|
35
|
-
import type {
|
|
35
|
+
import type { TextFragment } from "@mailwoman/core/tokenization/Span"
|
|
36
36
|
import { distance as levenshteinDistance } from "fastest-levenshtein"
|
|
37
37
|
|
|
38
38
|
import type { CanonicalRow, LabeledRow, QuarantinedRow } from "#types"
|
|
@@ -338,7 +338,7 @@ function overlapsClaimed(start: number, end: number, claimed: Array<[number, num
|
|
|
338
338
|
/**
|
|
339
339
|
* Assign BIO labels to tokens from component spans sorted by start offset.
|
|
340
340
|
*/
|
|
341
|
-
function labelTokens(tokens: readonly
|
|
341
|
+
function labelTokens(tokens: readonly TextFragment[], spans: readonly ComponentSpan[]): readonly BIOLabel[] {
|
|
342
342
|
const out: BIOLabel[] = []
|
|
343
343
|
const seenSpan = new Set<number>()
|
|
344
344
|
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @file The groups the frozen evaluation sets drew from.
|
|
6
|
+
* A split under them keeps those groups out of train.
|
|
7
|
+
*
|
|
8
|
+
* Under the evaluation-group policy (HOLDOUT_AND_EVALUATION section 4.6) the rows of these groups go to
|
|
9
|
+
* `test`, a small fixed sample of the holdout policy's places goes to `val`, and every other row trains.
|
|
10
|
+
* A group is `recordIDOf(base_source_id ?? source_id)`, the key the held-out freeze writes on each dataset
|
|
11
|
+
* entry and the overlap audit compares against training rows, so a base row, its augmentations and the
|
|
12
|
+
* other rendered rows of its record stay out of train together.
|
|
13
|
+
*
|
|
14
|
+
* The list is committed beside the corpus data, derived from the frozen manifests by
|
|
15
|
+
* `heldout/dataset/evaluation-groups.run.ts`. Its sha256 joins the split policy hash.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { readLocalJSONFile } from "@mailwoman/core/fs/readers"
|
|
19
|
+
import { sha256File } from "@mailwoman/core/hash"
|
|
20
|
+
import { resolveModulePath } from "@mailwoman/core/module/resolvers"
|
|
21
|
+
|
|
22
|
+
import { recordIDOf } from "#adapters/record-id"
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The attribute name an evaluation-group file declares.
|
|
26
|
+
*/
|
|
27
|
+
export const EVALUATION_GROUPS_ATTRIBUTE = "evaluation-groups"
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* One frozen set the group list was derived from.
|
|
31
|
+
*/
|
|
32
|
+
export interface EvaluationGroupDataset {
|
|
33
|
+
datasetID: string
|
|
34
|
+
version: string
|
|
35
|
+
/**
|
|
36
|
+
* What the set was drawn from: a corpus manifest, or the lineage of a probe render no corpus holds.
|
|
37
|
+
*/
|
|
38
|
+
drawnFrom: EvaluationGroupSource
|
|
39
|
+
/**
|
|
40
|
+
* The sha256 of the dataset manifest read.
|
|
41
|
+
*/
|
|
42
|
+
manifestSHA256: string
|
|
43
|
+
rows: number
|
|
44
|
+
groups: number
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The corpus manifest or render lineage a frozen set records as `drawnFrom`.
|
|
49
|
+
*/
|
|
50
|
+
export interface EvaluationGroupSource {
|
|
51
|
+
corpusVersion: string | null
|
|
52
|
+
sha256: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The committed file: every frozen group, sorted.
|
|
57
|
+
*
|
|
58
|
+
* Each set records its own `drawnFrom`, so one list can join sets drawn from a corpus
|
|
59
|
+
* with capability-probe sets rendered outside every corpus.
|
|
60
|
+
* `evaluation-groups.v0.8.18.json` predates that field and records one top-level
|
|
61
|
+
* `drawnFrom` for its two sets.
|
|
62
|
+
*
|
|
63
|
+
* It stays as written, because corpus v0.8.19's split policy hash records its sha256.
|
|
64
|
+
*/
|
|
65
|
+
export interface EvaluationGroupsFile {
|
|
66
|
+
attribute: typeof EVALUATION_GROUPS_ATTRIBUTE
|
|
67
|
+
datasets: EvaluationGroupDataset[]
|
|
68
|
+
groups: string[]
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The lookup a split applies, with the identity its policy hash records.
|
|
73
|
+
*/
|
|
74
|
+
export interface EvaluationGroups {
|
|
75
|
+
path: string
|
|
76
|
+
sha256: string
|
|
77
|
+
datasets: readonly EvaluationGroupDataset[]
|
|
78
|
+
groups: ReadonlySet<string>
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* What a split policy hash and a split record state about the group list applied.
|
|
83
|
+
*/
|
|
84
|
+
export interface EvaluationGroupsIdentity {
|
|
85
|
+
sha256: string
|
|
86
|
+
datasets: Array<Pick<EvaluationGroupDataset, "datasetID" | "version">>
|
|
87
|
+
groups: number
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The identity of a group list: its file's sha256, the frozen sets it names and its group count.
|
|
92
|
+
*/
|
|
93
|
+
export function evaluationGroupsIdentity(
|
|
94
|
+
groups: Pick<EvaluationGroups, "sha256" | "datasets" | "groups">
|
|
95
|
+
): EvaluationGroupsIdentity {
|
|
96
|
+
return {
|
|
97
|
+
sha256: groups.sha256,
|
|
98
|
+
datasets: groups.datasets.map(({ datasetID, version }) => ({ datasetID, version })),
|
|
99
|
+
groups: groups.groups.size,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The group of one corpus row: its `base_source_id` when it was derived from a base row,
|
|
105
|
+
* else its own `source_id`, read up to the last `#`.
|
|
106
|
+
*
|
|
107
|
+
* The held-out freeze (`heldoutRowGroup`) and the overlap audit key on the same value.
|
|
108
|
+
*/
|
|
109
|
+
export function evaluationGroupOf(row: { source_id: string; base_source_id?: string | null }): string {
|
|
110
|
+
// `??` as the audit's `coalesce(base_source_id, source_id)`.
|
|
111
|
+
return recordIDOf(row.base_source_id ?? row.source_id)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Builds the committed file from each frozen set's groups.
|
|
116
|
+
*/
|
|
117
|
+
export function buildEvaluationGroupsFile(input: {
|
|
118
|
+
datasets: ReadonlyArray<Omit<EvaluationGroupDataset, "groups"> & { groups: Iterable<string> }>
|
|
119
|
+
}): EvaluationGroupsFile {
|
|
120
|
+
const all = new Set<string>()
|
|
121
|
+
const datasets: EvaluationGroupDataset[] = []
|
|
122
|
+
|
|
123
|
+
for (const { groups, ...dataset } of input.datasets) {
|
|
124
|
+
const unique = new Set(groups)
|
|
125
|
+
|
|
126
|
+
for (const group of unique) {
|
|
127
|
+
all.add(group)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
datasets.push({ ...dataset, groups: unique.size })
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
attribute: EVALUATION_GROUPS_ATTRIBUTE,
|
|
135
|
+
datasets,
|
|
136
|
+
groups: [...all].toSorted(),
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Reads an evaluation-group file into the lookup a split applies.
|
|
142
|
+
*
|
|
143
|
+
* @throws When the file declares another attribute, names no frozen set or lists no group.
|
|
144
|
+
*/
|
|
145
|
+
export async function readEvaluationGroups(path: string): Promise<EvaluationGroups> {
|
|
146
|
+
const file = await readLocalJSONFile<EvaluationGroupsFile>(path)
|
|
147
|
+
|
|
148
|
+
if (file.attribute !== EVALUATION_GROUPS_ATTRIBUTE || !Array.isArray(file.groups)) {
|
|
149
|
+
throw new Error(`${path} is not an evaluation-group file`)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!Array.isArray(file.datasets) || !file.datasets.length) throw new Error(`${path} names no frozen set`)
|
|
153
|
+
|
|
154
|
+
if (!file.groups.length) throw new Error(`${path} lists no group`)
|
|
155
|
+
|
|
156
|
+
return { path, sha256: await sha256File(path), datasets: file.datasets, groups: new Set(file.groups) }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The committed group list of the v0.8.18 frozen sets (`heldout-dev-v0.8.18` and `heldout-confirm-v0.8.18`).
|
|
161
|
+
*/
|
|
162
|
+
export function evaluationGroupsV0818Path(): string {
|
|
163
|
+
return resolveModulePath("@mailwoman/corpus/data/holdout/evaluation-groups.v0.8.18.json")
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The committed group list of the v0.8.18 frozen sets and the v0.8.19 capability-probe
|
|
168
|
+
* sets (`heldout-dev-v0.8.19-probes-r2` and `heldout-confirm-v0.8.19-probes-r2`).
|
|
169
|
+
*/
|
|
170
|
+
export function evaluationGroupsV0819Path(): string {
|
|
171
|
+
return resolveModulePath("@mailwoman/corpus/data/holdout/evaluation-groups.v0.8.19.json")
|
|
172
|
+
}
|
package/lib/utils/split.ts
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Rows inside a held-out place go to val or test 50/50 by a hash of `source_id`;
|
|
9
9
|
* every other row goes to train.
|
|
10
|
+
* Under the evaluation-group policy only the groups the frozen evaluation sets drew from
|
|
11
|
+
* go to test, a per-country quota of the held-out places' groups goes to val, and the rest
|
|
12
|
+
* of those places trains (`#utils/evaluation-groups`, `#utils/validation-groups`).
|
|
10
13
|
*
|
|
11
14
|
* A holdout change takes effect at the next corpus rebuild.
|
|
12
15
|
* Each versioned corpus keeps the `SPLIT_MANIFEST.json` it was built with, because adding
|
|
@@ -25,7 +28,9 @@ import { JSONSpliterator } from "spliterator"
|
|
|
25
28
|
|
|
26
29
|
import { recordIDOf } from "#adapters/record-id"
|
|
27
30
|
import type { CanonicalRow, LabeledRow } from "#types"
|
|
31
|
+
import { type EvaluationGroups, evaluationGroupOf } from "#utils/evaluation-groups"
|
|
28
32
|
import { shapeKeyOf, type SplitRetention } from "#utils/retention"
|
|
33
|
+
import type { ValidationGroups } from "#utils/validation-groups"
|
|
29
34
|
|
|
30
35
|
/**
|
|
31
36
|
* The name of one corpus split.
|
|
@@ -835,6 +840,12 @@ type SplitInputRow = Pick<CanonicalRow, "source_id" | "country" | "components">
|
|
|
835
840
|
* A caller without them gets no retention lookup.
|
|
836
841
|
*/
|
|
837
842
|
span_tags?: readonly string[] | null
|
|
843
|
+
/**
|
|
844
|
+
* The id of the base row an augmented row was derived from.
|
|
845
|
+
*
|
|
846
|
+
* The evaluation-group policy keys on it, as the overlap audit does.
|
|
847
|
+
*/
|
|
848
|
+
base_source_id?: string | null
|
|
838
849
|
}
|
|
839
850
|
|
|
840
851
|
/**
|
|
@@ -846,13 +857,31 @@ type SplitInputRow = Pick<CanonicalRow, "source_id" | "country" | "components">
|
|
|
846
857
|
* A row of a combination the retention table covers below the floor returns `train`
|
|
847
858
|
* before the holdout is consulted (HOLDOUT_AND_EVALUATION section 5.1: training
|
|
848
859
|
* retention takes precedence over geographic integrity).
|
|
860
|
+
*
|
|
861
|
+
* With `evaluationGroups`, the split is the evaluation-group policy
|
|
862
|
+
* (HOLDOUT_AND_EVALUATION section 4.6), decided by the row's group and no other field:
|
|
863
|
+
* a frozen group returns `test`, a validation group `val`, and every other row `train`.
|
|
864
|
+
* The holdout, the trained places and the retention table are then not consulted,
|
|
865
|
+
* so no retained shape returns a frozen group's variant to train.
|
|
866
|
+
*
|
|
867
|
+
* The overlap audit reads `val` as training data, so `evaluationGroupPolicy`
|
|
868
|
+
* refuses a validation list that holds a frozen group.
|
|
849
869
|
*/
|
|
850
870
|
export function splitForRow(
|
|
851
|
-
row: Pick<SplitInputRow, "source_id" | "country" | "components" | "span_tags">,
|
|
871
|
+
row: Pick<SplitInputRow, "source_id" | "country" | "components" | "span_tags" | "base_source_id">,
|
|
852
872
|
holdouts: Record<string, CountryHoldout> = defaultHoldouts(),
|
|
853
873
|
trainedPlaces: Record<string, readonly string[]> = hashedHoldoutTrainedPlaces(),
|
|
854
|
-
retention?: SplitRetention
|
|
874
|
+
retention?: SplitRetention,
|
|
875
|
+
evaluationGroups?: { frozen: Pick<EvaluationGroups, "groups">; validation: Pick<ValidationGroups, "groups"> }
|
|
855
876
|
): SplitName {
|
|
877
|
+
if (evaluationGroups) {
|
|
878
|
+
const group = evaluationGroupOf(row)
|
|
879
|
+
|
|
880
|
+
if (evaluationGroups.frozen.groups.has(group)) return "test"
|
|
881
|
+
|
|
882
|
+
return evaluationGroups.validation.groups.has(group) ? "val" : "train"
|
|
883
|
+
}
|
|
884
|
+
|
|
856
885
|
if (retention && row.span_tags && retention.protectedShapes.has(shapeKeyOf(row.country, row.span_tags))) {
|
|
857
886
|
return "train"
|
|
858
887
|
}
|
|
@@ -932,10 +961,17 @@ export function splitRows(rows: Iterable<SplitInputRow>, opts: SplitOptions = {}
|
|
|
932
961
|
* of the SHA-256 digest read as a big-endian uint32.
|
|
933
962
|
*/
|
|
934
963
|
export function hashBucket(id: string, n: number): number {
|
|
964
|
+
return hashUint32(id) % n
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* The first four bytes of an id's SHA-256 digest read as a big-endian uint32,
|
|
969
|
+
* the value {@link hashBucket} reduces and the validation quota orders groups by.
|
|
970
|
+
*/
|
|
971
|
+
export function hashUint32(id: string): number {
|
|
935
972
|
const digest = createHash("sha256").update(id).digest()
|
|
936
|
-
const u = digest[0]! * 0x01_00_00_00 + digest[1]! * 0x01_00_00 + digest[2]! * 0x01_00 + digest[3]!
|
|
937
973
|
|
|
938
|
-
return
|
|
974
|
+
return digest[0]! * 0x01_00_00_00 + digest[1]! * 0x01_00_00 + digest[2]! * 0x01_00 + digest[3]!
|
|
939
975
|
}
|
|
940
976
|
|
|
941
977
|
/**
|
package/lib/utils/tokenize.ts
CHANGED
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
* The interface is deliberately minimal — only what alignment needs.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import type {
|
|
12
|
+
import type { TextFragment } from "@mailwoman/core/tokenization/Span"
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* A tokenizer that maps a string to a sequence of `
|
|
15
|
+
* A tokenizer that maps a string to a sequence of `TextFragment`s.
|
|
16
16
|
*/
|
|
17
17
|
export interface Tokenizer {
|
|
18
|
-
tokenize(text: string): readonly
|
|
18
|
+
tokenize(text: string): readonly TextFragment[]
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -29,8 +29,8 @@ export function whitespaceTokenizer(): Tokenizer {
|
|
|
29
29
|
const tokenRe = /[\p{L}\p{N}\p{M}'_-]+/gu
|
|
30
30
|
|
|
31
31
|
return {
|
|
32
|
-
tokenize(text: string): readonly
|
|
33
|
-
const out:
|
|
32
|
+
tokenize(text: string): readonly TextFragment[] {
|
|
33
|
+
const out: TextFragment[] = []
|
|
34
34
|
tokenRe.lastIndex = 0
|
|
35
35
|
let m: RegExpExecArray | null
|
|
36
36
|
|
|
@@ -63,8 +63,8 @@ export function cjkAwareTokenizer(): Tokenizer {
|
|
|
63
63
|
const base = whitespaceTokenizer()
|
|
64
64
|
|
|
65
65
|
return {
|
|
66
|
-
tokenize(text: string): readonly
|
|
67
|
-
const out:
|
|
66
|
+
tokenize(text: string): readonly TextFragment[] {
|
|
67
|
+
const out: TextFragment[] = []
|
|
68
68
|
|
|
69
69
|
for (const token of base.tokenize(text)) {
|
|
70
70
|
if (!HAN.test(token.text)) {
|