@mailwoman/registry 10.8.0 → 11.0.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 +93 -98
- package/data/manifests/artifacts.json +32 -0
- package/data/manifests/coverage.json +56 -0
- package/data/manifests/sources.lock.json +48 -0
- package/data/normalized/iata-airports.json +126749 -0
- package/data/normalized/iso3166-1.json +2035 -0
- package/definitions/namespaces.json +63 -0
- package/definitions/sections.json +73 -0
- package/docs/data-policy.md +81 -0
- package/docs/performance.md +146 -0
- package/docs/rgy1.md +144 -0
- package/lib/artifacts/country-airport-collision.ts +26 -0
- package/lib/artifacts/iata-airport/membership.ts +26 -0
- package/lib/artifacts/iata-airport/records.ts +26 -0
- package/lib/artifacts/iso3166-1/alpha2-membership.ts +26 -0
- package/lib/artifacts/iso3166-1/alpha3-membership.ts +26 -0
- package/lib/artifacts/iso3166-1/records.ts +26 -0
- package/lib/errors.ts +44 -0
- package/lib/iata/airports/records.ts +174 -0
- package/lib/iata/airports/validate.ts +49 -0
- package/lib/index.ts +25 -15
- package/lib/inspect.ts +56 -0
- package/lib/iso3166/alpha2.ts +48 -0
- package/lib/iso3166/alpha3.ts +51 -0
- package/lib/iso3166/records.ts +149 -0
- package/lib/iso3166/relations.ts +30 -0
- package/lib/key.ts +146 -0
- package/lib/normalize.ts +31 -0
- package/lib/overlap/country-airport.ts +108 -0
- package/lib/rgy1/base64.ts +24 -0
- package/lib/rgy1/reader.ts +316 -0
- package/lib/rgy1/sections.generated.ts +79 -0
- package/lib/rgy1/views.ts +267 -0
- package/lib/types.ts +88 -74
- package/lib/wasm.ts +285 -0
- package/out/artifacts/country-airport-collision.d.ts +15 -0
- package/out/artifacts/country-airport-collision.d.ts.map +1 -0
- package/out/artifacts/country-airport-collision.js +21 -0
- package/out/artifacts/country-airport-collision.js.map +1 -0
- package/out/artifacts/iata-airport/membership.d.ts +15 -0
- package/out/artifacts/iata-airport/membership.d.ts.map +1 -0
- package/out/artifacts/iata-airport/membership.js +21 -0
- package/out/artifacts/iata-airport/membership.js.map +1 -0
- package/out/artifacts/iata-airport/records.d.ts +15 -0
- package/out/artifacts/iata-airport/records.d.ts.map +1 -0
- package/out/artifacts/iata-airport/records.js +21 -0
- package/out/artifacts/iata-airport/records.js.map +1 -0
- package/out/artifacts/iso3166-1/alpha2-membership.d.ts +15 -0
- package/out/artifacts/iso3166-1/alpha2-membership.d.ts.map +1 -0
- package/out/artifacts/iso3166-1/alpha2-membership.js +21 -0
- package/out/artifacts/iso3166-1/alpha2-membership.js.map +1 -0
- package/out/artifacts/iso3166-1/alpha3-membership.d.ts +15 -0
- package/out/artifacts/iso3166-1/alpha3-membership.d.ts.map +1 -0
- package/out/artifacts/iso3166-1/alpha3-membership.js +21 -0
- package/out/artifacts/iso3166-1/alpha3-membership.js.map +1 -0
- package/out/artifacts/iso3166-1/records.d.ts +15 -0
- package/out/artifacts/iso3166-1/records.d.ts.map +1 -0
- package/out/artifacts/iso3166-1/records.js +21 -0
- package/out/artifacts/iso3166-1/records.js.map +1 -0
- package/out/errors.d.ts +38 -0
- package/out/errors.d.ts.map +1 -0
- package/out/errors.js +35 -0
- package/out/errors.js.map +1 -0
- package/out/iata/airports/records.d.ts +44 -0
- package/out/iata/airports/records.d.ts.map +1 -0
- package/out/iata/airports/records.js +137 -0
- package/out/iata/airports/records.js.map +1 -0
- package/out/iata/airports/validate.d.ts +27 -0
- package/out/iata/airports/validate.d.ts.map +1 -0
- package/out/iata/airports/validate.js +42 -0
- package/out/iata/airports/validate.js.map +1 -0
- package/out/index.d.ts +19 -15
- package/out/index.d.ts.map +1 -1
- package/out/index.js +14 -15
- package/out/index.js.map +1 -1
- package/out/inspect.d.ts +38 -0
- package/out/inspect.d.ts.map +1 -0
- package/out/inspect.js +33 -0
- package/out/inspect.js.map +1 -0
- package/out/iso3166/alpha2.d.ts +24 -0
- package/out/iso3166/alpha2.d.ts.map +1 -0
- package/out/iso3166/alpha2.js +41 -0
- package/out/iso3166/alpha2.js.map +1 -0
- package/out/iso3166/alpha3.d.ts +29 -0
- package/out/iso3166/alpha3.d.ts.map +1 -0
- package/out/iso3166/alpha3.js +44 -0
- package/out/iso3166/alpha3.js.map +1 -0
- package/out/iso3166/records.d.ts +38 -0
- package/out/iso3166/records.d.ts.map +1 -0
- package/out/iso3166/records.js +105 -0
- package/out/iso3166/records.js.map +1 -0
- package/out/iso3166/relations.d.ts +20 -0
- package/out/iso3166/relations.d.ts.map +1 -0
- package/out/iso3166/relations.js +27 -0
- package/out/iso3166/relations.js.map +1 -0
- package/out/key.d.ts +68 -0
- package/out/key.d.ts.map +1 -0
- package/out/key.js +122 -0
- package/out/key.js.map +1 -0
- package/out/normalize.d.ts +25 -0
- package/out/normalize.d.ts.map +1 -0
- package/out/normalize.js +21 -0
- package/out/normalize.js.map +1 -0
- package/out/overlap/country-airport.d.ts +57 -0
- package/out/overlap/country-airport.d.ts.map +1 -0
- package/out/overlap/country-airport.js +71 -0
- package/out/overlap/country-airport.js.map +1 -0
- package/out/rgy1/base64.d.ts +15 -0
- package/out/rgy1/base64.d.ts.map +1 -0
- package/out/rgy1/base64.js +22 -0
- package/out/rgy1/base64.js.map +1 -0
- package/out/rgy1/reader.d.ts +103 -0
- package/out/rgy1/reader.d.ts.map +1 -0
- package/out/rgy1/reader.js +230 -0
- package/out/rgy1/reader.js.map +1 -0
- package/out/rgy1/sections.generated.d.ts +54 -0
- package/out/rgy1/sections.generated.d.ts.map +1 -0
- package/out/rgy1/sections.generated.js +69 -0
- package/out/rgy1/sections.generated.js.map +1 -0
- package/out/rgy1/views.d.ts +96 -0
- package/out/rgy1/views.d.ts.map +1 -0
- package/out/rgy1/views.js +218 -0
- package/out/rgy1/views.js.map +1 -0
- package/out/sdk/fetch.d.ts +53 -0
- package/out/sdk/fetch.d.ts.map +1 -0
- package/out/sdk/fetch.js +107 -0
- package/out/sdk/fetch.js.map +1 -0
- package/out/sdk/fetch.run.d.ts +14 -0
- package/out/sdk/fetch.run.d.ts.map +1 -0
- package/out/sdk/fetch.run.js +20 -0
- package/out/sdk/fetch.run.js.map +1 -0
- package/out/sdk/sources.d.ts +111 -0
- package/out/sdk/sources.d.ts.map +1 -0
- package/out/sdk/sources.js +98 -0
- package/out/sdk/sources.js.map +1 -0
- package/out/tools/artifact-path.d.ts +10 -0
- package/out/tools/artifact-path.d.ts.map +1 -0
- package/out/tools/artifact-path.js +12 -0
- package/out/tools/artifact-path.js.map +1 -0
- package/out/tools/bench.run.d.ts +19 -0
- package/out/tools/bench.run.d.ts.map +1 -0
- package/out/tools/bench.run.js +204 -0
- package/out/tools/bench.run.js.map +1 -0
- package/out/tools/build-wasm.run.d.ts +18 -0
- package/out/tools/build-wasm.run.d.ts.map +1 -0
- package/out/tools/build-wasm.run.js +71 -0
- package/out/tools/build-wasm.run.js.map +1 -0
- package/out/tools/generate-sections.run.d.ts +13 -0
- package/out/tools/generate-sections.run.d.ts.map +1 -0
- package/out/tools/generate-sections.run.js +136 -0
- package/out/tools/generate-sections.run.js.map +1 -0
- package/out/tools/generate.run.d.ts +18 -0
- package/out/tools/generate.run.d.ts.map +1 -0
- package/out/tools/generate.run.js +118 -0
- package/out/tools/generate.run.js.map +1 -0
- package/out/tools/normalize.d.ts +155 -0
- package/out/tools/normalize.d.ts.map +1 -0
- package/out/tools/normalize.js +303 -0
- package/out/tools/normalize.js.map +1 -0
- package/out/tools/normalize.run.d.ts +14 -0
- package/out/tools/normalize.run.d.ts.map +1 -0
- package/out/tools/normalize.run.js +29 -0
- package/out/tools/normalize.run.js.map +1 -0
- package/out/types.d.ts +90 -76
- package/out/types.d.ts.map +1 -1
- package/out/types.js +20 -4
- package/out/types.js.map +1 -1
- package/out/wasm.d.ts +98 -0
- package/out/wasm.d.ts.map +1 -0
- package/out/wasm.js +137 -0
- package/out/wasm.js.map +1 -0
- package/package.json +48 -27
- package/sdk/fetch.run.ts +24 -0
- package/sdk/fetch.ts +146 -0
- package/sdk/sources.ts +162 -0
- package/tools/artifact-path.ts +12 -0
- package/tools/bench.run.ts +265 -0
- package/tools/build-wasm.run.ts +82 -0
- package/tools/generate-sections.run.ts +152 -0
- package/tools/generate.run.ts +146 -0
- package/tools/normalize.run.ts +36 -0
- package/tools/normalize.ts +474 -0
- package/wasm/registry-simd.wasm +0 -0
- package/wasm/registry.wasm +0 -0
- package/lib/address-key.ts +0 -46
- package/lib/geocode-handler.ts +0 -37
- package/lib/geojson.ts +0 -72
- package/lib/ingest.ts +0 -349
- package/lib/learned-scorer.ts +0 -134
- package/lib/map-html.ts +0 -287
- package/lib/models/crosssource-gbt-en-us.ts +0 -43
- package/lib/models/dedup-gbt-en-us.ts +0 -47
- package/lib/models/org-crosssource-gbt-en-us.ts +0 -43
- package/lib/reconcile.ts +0 -239
- package/lib/resolve.ts +0 -569
- package/out/address-key.d.ts +0 -34
- package/out/address-key.d.ts.map +0 -1
- package/out/address-key.js +0 -41
- package/out/address-key.js.map +0 -1
- package/out/geocode-handler.d.ts +0 -20
- package/out/geocode-handler.d.ts.map +0 -1
- package/out/geocode-handler.js +0 -29
- package/out/geocode-handler.js.map +0 -1
- package/out/geojson.d.ts +0 -28
- package/out/geojson.d.ts.map +0 -1
- package/out/geojson.js +0 -62
- package/out/geojson.js.map +0 -1
- package/out/ingest.d.ts +0 -173
- package/out/ingest.d.ts.map +0 -1
- package/out/ingest.js +0 -185
- package/out/ingest.js.map +0 -1
- package/out/learned-scorer.d.ts +0 -61
- package/out/learned-scorer.d.ts.map +0 -1
- package/out/learned-scorer.js +0 -91
- package/out/learned-scorer.js.map +0 -1
- package/out/map-html.d.ts +0 -39
- package/out/map-html.d.ts.map +0 -1
- package/out/map-html.js +0 -220
- package/out/map-html.js.map +0 -1
- package/out/models/crosssource-gbt-en-us.d.ts +0 -45
- package/out/models/crosssource-gbt-en-us.d.ts.map +0 -1
- package/out/models/crosssource-gbt-en-us.js +0 -40
- package/out/models/crosssource-gbt-en-us.js.map +0 -1
- package/out/models/dedup-gbt-en-us.d.ts +0 -44
- package/out/models/dedup-gbt-en-us.d.ts.map +0 -1
- package/out/models/dedup-gbt-en-us.js +0 -44
- package/out/models/dedup-gbt-en-us.js.map +0 -1
- package/out/models/org-crosssource-gbt-en-us.d.ts +0 -45
- package/out/models/org-crosssource-gbt-en-us.d.ts.map +0 -1
- package/out/models/org-crosssource-gbt-en-us.js +0 -40
- package/out/models/org-crosssource-gbt-en-us.js.map +0 -1
- package/out/reconcile.d.ts +0 -96
- package/out/reconcile.d.ts.map +0 -1
- package/out/reconcile.js +0 -127
- package/out/reconcile.js.map +0 -1
- package/out/resolve.d.ts +0 -264
- package/out/resolve.d.ts.map +0 -1
- package/out/resolve.js +0 -282
- package/out/resolve.js.map +0 -1
- package/out/tools/coverage-reconciliation.d.ts +0 -67
- package/out/tools/coverage-reconciliation.d.ts.map +0 -1
- package/out/tools/coverage-reconciliation.js +0 -113
- package/out/tools/coverage-reconciliation.js.map +0 -1
- package/out/tools/cross/dataset-correlation.d.ts +0 -61
- package/out/tools/cross/dataset-correlation.d.ts.map +0 -1
- package/out/tools/cross/dataset-correlation.js +0 -244
- package/out/tools/cross/dataset-correlation.js.map +0 -1
- package/out/tools/cross/source-threshold-sweep.d.ts +0 -60
- package/out/tools/cross/source-threshold-sweep.d.ts.map +0 -1
- package/out/tools/cross/source-threshold-sweep.js +0 -264
- package/out/tools/cross/source-threshold-sweep.js.map +0 -1
- package/out/tools/dedup-ceiling.d.ts +0 -62
- package/out/tools/dedup-ceiling.d.ts.map +0 -1
- package/out/tools/dedup-ceiling.js +0 -171
- package/out/tools/dedup-ceiling.js.map +0 -1
- package/out/tools/eval-geocoder.d.ts +0 -68
- package/out/tools/eval-geocoder.d.ts.map +0 -1
- package/out/tools/eval-geocoder.js +0 -13
- package/out/tools/eval-geocoder.js.map +0 -1
- package/out/tools/geocoder/namesake-probe.d.ts +0 -33
- package/out/tools/geocoder/namesake-probe.d.ts.map +0 -1
- package/out/tools/geocoder/namesake-probe.js +0 -60
- package/out/tools/geocoder/namesake-probe.js.map +0 -1
- package/out/tools/geocoder/vs-provided-coords.d.ts +0 -53
- package/out/tools/geocoder/vs-provided-coords.d.ts.map +0 -1
- package/out/tools/geocoder/vs-provided-coords.js +0 -161
- package/out/tools/geocoder/vs-provided-coords.js.map +0 -1
- package/out/tools/gold-set-sample.d.ts +0 -67
- package/out/tools/gold-set-sample.d.ts.map +0 -1
- package/out/tools/gold-set-sample.js +0 -81
- package/out/tools/gold-set-sample.js.map +0 -1
- package/out/tools/learned/scorer/clustering-eval.d.ts +0 -77
- package/out/tools/learned/scorer/clustering-eval.d.ts.map +0 -1
- package/out/tools/learned/scorer/clustering-eval.js +0 -207
- package/out/tools/learned/scorer/clustering-eval.js.map +0 -1
- package/out/tools/learned/scorer/crossstate-eval.d.ts +0 -65
- package/out/tools/learned/scorer/crossstate-eval.d.ts.map +0 -1
- package/out/tools/learned/scorer/crossstate-eval.js +0 -168
- package/out/tools/learned/scorer/crossstate-eval.js.map +0 -1
- package/out/tools/learned/scorer/eval.d.ts +0 -64
- package/out/tools/learned/scorer/eval.d.ts.map +0 -1
- package/out/tools/learned/scorer/eval.js +0 -275
- package/out/tools/learned/scorer/eval.js.map +0 -1
- package/out/tools/matcher-scale.d.ts +0 -40
- package/out/tools/matcher-scale.d.ts.map +0 -1
- package/out/tools/matcher-scale.js +0 -111
- package/out/tools/matcher-scale.js.map +0 -1
- package/out/tools/nppes/dedup-benchmark.d.ts +0 -82
- package/out/tools/nppes/dedup-benchmark.d.ts.map +0 -1
- package/out/tools/nppes/dedup-benchmark.js +0 -226
- package/out/tools/nppes/dedup-benchmark.js.map +0 -1
- package/out/tools/nppes/org-name.d.ts +0 -15
- package/out/tools/nppes/org-name.d.ts.map +0 -1
- package/out/tools/nppes/org-name.js +0 -6
- package/out/tools/nppes/org-name.js.map +0 -1
- package/out/tools/nppes/overmerge-packet.d.ts +0 -43
- package/out/tools/nppes/overmerge-packet.d.ts.map +0 -1
- package/out/tools/nppes/overmerge-packet.js +0 -54
- package/out/tools/nppes/overmerge-packet.js.map +0 -1
- package/out/tools/nppes/report.d.ts +0 -97
- package/out/tools/nppes/report.d.ts.map +0 -1
- package/out/tools/nppes/report.js +0 -178
- package/out/tools/nppes/report.js.map +0 -1
- package/out/tools/nppes/sample.d.ts +0 -101
- package/out/tools/nppes/sample.d.ts.map +0 -1
- package/out/tools/nppes/sample.js +0 -127
- package/out/tools/nppes/sample.js.map +0 -1
- package/out/tools/nppes/scoring.d.ts +0 -37
- package/out/tools/nppes/scoring.d.ts.map +0 -1
- package/out/tools/nppes/scoring.js +0 -81
- package/out/tools/nppes/scoring.js.map +0 -1
- package/out/tools/nppes/settings.d.ts +0 -41
- package/out/tools/nppes/settings.d.ts.map +0 -1
- package/out/tools/nppes/settings.js +0 -79
- package/out/tools/nppes/settings.js.map +0 -1
- package/out/tools/nppes/truth-grains.d.ts +0 -63
- package/out/tools/nppes/truth-grains.d.ts.map +0 -1
- package/out/tools/nppes/truth-grains.js +0 -142
- package/out/tools/nppes/truth-grains.js.map +0 -1
- package/out/tools/shared.d.ts +0 -325
- package/out/tools/shared.d.ts.map +0 -1
- package/out/tools/shared.js +0 -453
- package/out/tools/shared.js.map +0 -1
- package/out/tools/train/cross-gbt.d.ts +0 -89
- package/out/tools/train/cross-gbt.d.ts.map +0 -1
- package/out/tools/train/cross-gbt.js +0 -132
- package/out/tools/train/cross-gbt.js.map +0 -1
- package/out/tools/train/gbt.d.ts +0 -85
- package/out/tools/train/gbt.d.ts.map +0 -1
- package/out/tools/train/gbt.js +0 -155
- package/out/tools/train/gbt.js.map +0 -1
- package/out/tools/train/org-cross-gbt.d.ts +0 -85
- package/out/tools/train/org-cross-gbt.d.ts.map +0 -1
- package/out/tools/train/org-cross-gbt.js +0 -122
- package/out/tools/train/org-cross-gbt.js.map +0 -1
- package/out/tools/txhhsc-to-oarow.d.ts +0 -42
- package/out/tools/txhhsc-to-oarow.d.ts.map +0 -1
- package/out/tools/txhhsc-to-oarow.js +0 -78
- package/out/tools/txhhsc-to-oarow.js.map +0 -1
- package/out/tools/viz/browser.d.ts +0 -31
- package/out/tools/viz/browser.d.ts.map +0 -1
- package/out/tools/viz/browser.js +0 -26
- package/out/tools/viz/browser.js.map +0 -1
- package/out/tools/viz/cross-dataset-map.d.ts +0 -39
- package/out/tools/viz/cross-dataset-map.d.ts.map +0 -1
- package/out/tools/viz/cross-dataset-map.js +0 -84
- package/out/tools/viz/cross-dataset-map.js.map +0 -1
- package/out/tools/viz/geocode-first-surface.d.ts +0 -36
- package/out/tools/viz/geocode-first-surface.d.ts.map +0 -1
- package/out/tools/viz/geocode-first-surface.js +0 -234
- package/out/tools/viz/geocode-first-surface.js.map +0 -1
- package/out/tools/viz/render/map.d.ts +0 -42
- package/out/tools/viz/render/map.d.ts.map +0 -1
- package/out/tools/viz/render/map.js +0 -40
- package/out/tools/viz/render/map.js.map +0 -1
- package/out/tools/viz/render.d.ts +0 -46
- package/out/tools/viz/render.d.ts.map +0 -1
- package/out/tools/viz/render.js +0 -49
- package/out/tools/viz/render.js.map +0 -1
- package/out/tools/viz/source-provenance-map.d.ts +0 -57
- package/out/tools/viz/source-provenance-map.d.ts.map +0 -1
- package/out/tools/viz/source-provenance-map.js +0 -82
- package/out/tools/viz/source-provenance-map.js.map +0 -1
- package/out/tools/viz/yardstick-figure.d.ts +0 -22
- package/out/tools/viz/yardstick-figure.d.ts.map +0 -1
- package/out/tools/viz/yardstick-figure.js +0 -106
- package/out/tools/viz/yardstick-figure.js.map +0 -1
- package/tools/coverage-reconciliation.ts +0 -192
- package/tools/cross/dataset-correlation.ts +0 -380
- package/tools/cross/source-threshold-sweep.ts +0 -416
- package/tools/dedup-ceiling.ts +0 -225
- package/tools/eval-geocoder.ts +0 -77
- package/tools/geocoder/namesake-probe.ts +0 -91
- package/tools/geocoder/vs-provided-coords.ts +0 -232
- package/tools/gold-set-sample.ts +0 -147
- package/tools/learned/scorer/clustering-eval.ts +0 -349
- package/tools/learned/scorer/crossstate-eval.ts +0 -280
- package/tools/learned/scorer/eval.ts +0 -429
- package/tools/matcher-scale.ts +0 -185
- package/tools/nppes/dedup-benchmark.ts +0 -364
- package/tools/nppes/org-name.ts +0 -15
- package/tools/nppes/overmerge-packet.ts +0 -98
- package/tools/nppes/report.ts +0 -380
- package/tools/nppes/sample.ts +0 -250
- package/tools/nppes/scoring.ts +0 -115
- package/tools/nppes/settings.ts +0 -102
- package/tools/nppes/truth-grains.ts +0 -185
- package/tools/shared.ts +0 -743
- package/tools/train/cross-gbt.ts +0 -214
- package/tools/train/gbt.ts +0 -261
- package/tools/train/org-cross-gbt.ts +0 -189
- package/tools/txhhsc-to-oarow.ts +0 -118
- package/tools/viz/browser.ts +0 -41
- package/tools/viz/cross-dataset-map.ts +0 -133
- package/tools/viz/geocode-first-surface.ts +0 -305
- package/tools/viz/render/map.ts +0 -61
- package/tools/viz/render.ts +0 -103
- package/tools/viz/source-provenance-map.ts +0 -154
- package/tools/viz/yardstick-figure.ts +0 -197
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Turns the pinned sources into the reviewable normalized JSON the compiler reads.
|
|
7
|
+
*
|
|
8
|
+
* Every record keeps the source's own identity (`entityID`), the code as the source spells it, and the source's
|
|
9
|
+
* status words. Each record comes from one source: a country record from Wikidata, an airport record from
|
|
10
|
+
* OurAirports. An airport's `country` is the alpha-2 string OurAirports states, with a status that records whether
|
|
11
|
+
* that string is an officially assigned ISO code, a source extension such as `XK`, or absent.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { readLocalJSONFile, readLocalTextFile } from "@mailwoman/core/fs/readers"
|
|
15
|
+
import { sha256File } from "@mailwoman/core/hash"
|
|
16
|
+
import { stringifyJSON } from "@mailwoman/core/json"
|
|
17
|
+
import { TextSpliterator } from "spliterator"
|
|
18
|
+
|
|
19
|
+
import { type SourceDefinition, type SourceLock, sourcePath, SOURCES } from "#sdk/sources"
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* One ISO 3166-1 entry.
|
|
23
|
+
*/
|
|
24
|
+
export interface CountryRecord {
|
|
25
|
+
/**
|
|
26
|
+
* The Wikidata item, such as `wikidata:Q408`.
|
|
27
|
+
*/
|
|
28
|
+
entityID: string
|
|
29
|
+
alpha2: string
|
|
30
|
+
alpha3: string
|
|
31
|
+
numeric: string
|
|
32
|
+
name: string
|
|
33
|
+
/**
|
|
34
|
+
* `officially-assigned` for a current entry.
|
|
35
|
+
* `formerly-used` when the source records a dissolution date.
|
|
36
|
+
*/
|
|
37
|
+
status: "officially-assigned" | "formerly-used"
|
|
38
|
+
/**
|
|
39
|
+
* The dissolution date the source states, for a `formerly-used` entry.
|
|
40
|
+
*/
|
|
41
|
+
dissolved?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* One OurAirports row that holds an IATA code.
|
|
46
|
+
*/
|
|
47
|
+
export interface AirportRecord {
|
|
48
|
+
/**
|
|
49
|
+
* The OurAirports row id, such as `ourairports:3632`.
|
|
50
|
+
*/
|
|
51
|
+
entityID: string
|
|
52
|
+
iata: string
|
|
53
|
+
/**
|
|
54
|
+
* The `icao_code` column, read as the ICAO assignment.
|
|
55
|
+
* `ident` and `gps_code` are other identifiers.
|
|
56
|
+
*/
|
|
57
|
+
icao: string | null
|
|
58
|
+
name: string
|
|
59
|
+
facility: string
|
|
60
|
+
scheduledService: boolean
|
|
61
|
+
latitude: number
|
|
62
|
+
longitude: number
|
|
63
|
+
/**
|
|
64
|
+
* The `iso_country` column as the source spells it, or null when empty.
|
|
65
|
+
*/
|
|
66
|
+
country: string | null
|
|
67
|
+
/**
|
|
68
|
+
* Whether `country` is an officially assigned ISO 3166-1 alpha-2 code, a source extension, or absent.
|
|
69
|
+
*/
|
|
70
|
+
countryStatus: "iso3166-1" | "source-extension" | "unstated"
|
|
71
|
+
isoRegion: string | null
|
|
72
|
+
municipality: string | null
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface NormalizedCountries {
|
|
76
|
+
profile: string
|
|
77
|
+
source: string
|
|
78
|
+
normalizationVersion: number
|
|
79
|
+
records: CountryRecord[]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface NormalizedAirports {
|
|
83
|
+
profile: string
|
|
84
|
+
source: string
|
|
85
|
+
normalizationVersion: number
|
|
86
|
+
records: AirportRecord[]
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The coverage a profile declares: what each namespace's artifact can and cannot answer.
|
|
91
|
+
*/
|
|
92
|
+
export interface CoverageDeclaration {
|
|
93
|
+
profile: string
|
|
94
|
+
namespaces: Record<
|
|
95
|
+
string,
|
|
96
|
+
{
|
|
97
|
+
source: string
|
|
98
|
+
count: number
|
|
99
|
+
statuses?: Record<string, number>
|
|
100
|
+
kinds?: string[]
|
|
101
|
+
unsupported?: string[]
|
|
102
|
+
missMeans: string
|
|
103
|
+
}
|
|
104
|
+
>
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The version of the normalization rules below.
|
|
109
|
+
*
|
|
110
|
+
* A change to a rule that moves a record's bytes moves this number.
|
|
111
|
+
*/
|
|
112
|
+
export const NORMALIZATION_VERSION = 1
|
|
113
|
+
|
|
114
|
+
interface SPARQLResults {
|
|
115
|
+
results: { bindings: Array<Record<string, { type: string; value: string }>> }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const ALPHA2 = /^[A-Z]{2}$/
|
|
119
|
+
const ALPHA3 = /^[A-Z]{3}$/
|
|
120
|
+
const NUMERIC = /^\d{3}$/
|
|
121
|
+
|
|
122
|
+
function sourceDefinition(id: SourceDefinition["id"]): SourceDefinition {
|
|
123
|
+
const found = SOURCES.find((candidate) => candidate.id === id)
|
|
124
|
+
|
|
125
|
+
if (!found) throw new Error(`no source ${id}`)
|
|
126
|
+
|
|
127
|
+
return found
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Reads the Wikidata answer into country records, sorted by alpha-2 then item id.
|
|
132
|
+
*
|
|
133
|
+
* A code outside its grammar is an error naming the item, because the compiler's key
|
|
134
|
+
* space cannot hold it and an omitted row would be a silent loss.
|
|
135
|
+
*/
|
|
136
|
+
export function normalizeCountries(results: SPARQLResults, profile: string): NormalizedCountries {
|
|
137
|
+
const records: CountryRecord[] = []
|
|
138
|
+
const seen = new Set<string>()
|
|
139
|
+
|
|
140
|
+
for (const binding of results.results.bindings) {
|
|
141
|
+
const qid = binding["item"]?.value.split("/").at(-1)
|
|
142
|
+
const alpha2 = binding["alpha2"]?.value
|
|
143
|
+
const alpha3 = binding["alpha3"]?.value
|
|
144
|
+
const numeric = binding["numeric"]?.value
|
|
145
|
+
|
|
146
|
+
if (!qid || !alpha2 || !alpha3 || !numeric) throw new Error(`incomplete binding: ${stringifyJSON(binding)}`)
|
|
147
|
+
|
|
148
|
+
if (!ALPHA2.test(alpha2) || !ALPHA3.test(alpha3) || !NUMERIC.test(numeric)) {
|
|
149
|
+
throw new Error(`${qid}: codes ${alpha2}/${alpha3}/${numeric} are outside the ISO 3166-1 grammars`)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// The dissolution date can repeat an item, and the first row keeps it.
|
|
153
|
+
if (seen.has(qid)) continue
|
|
154
|
+
|
|
155
|
+
seen.add(qid)
|
|
156
|
+
|
|
157
|
+
const dissolved = binding["dissolved"]?.value
|
|
158
|
+
|
|
159
|
+
records.push({
|
|
160
|
+
entityID: `wikidata:${qid}`,
|
|
161
|
+
alpha2,
|
|
162
|
+
alpha3,
|
|
163
|
+
numeric,
|
|
164
|
+
name: binding["itemLabel"]?.value ?? qid,
|
|
165
|
+
status: dissolved ? "formerly-used" : "officially-assigned",
|
|
166
|
+
...(dissolved ? { dissolved } : {}),
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const sorted = records.toSorted(
|
|
171
|
+
(a, b) => a.alpha2.localeCompare(b.alpha2, "en") || a.entityID.localeCompare(b.entityID, "en")
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
assertUniqueCurrent(sorted)
|
|
175
|
+
|
|
176
|
+
return { profile, source: "wikidata-iso3166-1", normalizationVersion: NORMALIZATION_VERSION, records: sorted }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Two current entries cannot share a code.
|
|
181
|
+
* Two historical entries, or one of each, can.
|
|
182
|
+
*/
|
|
183
|
+
function assertUniqueCurrent(records: readonly CountryRecord[]): void {
|
|
184
|
+
for (const field of ["alpha2", "alpha3", "numeric"] as const) {
|
|
185
|
+
const held = new Map<string, string>()
|
|
186
|
+
|
|
187
|
+
for (const record of records) {
|
|
188
|
+
if (record.status !== "officially-assigned") continue
|
|
189
|
+
|
|
190
|
+
const other = held.get(record[field])
|
|
191
|
+
|
|
192
|
+
if (other) throw new Error(`${field} ${record[field]} is held by ${other} and ${record.entityID}`)
|
|
193
|
+
|
|
194
|
+
held.set(record[field], record.entityID)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Splits one CSV line whose fields are all double-quoted, as OurAirports writes them,
|
|
201
|
+
* with `""` as an escaped quote.
|
|
202
|
+
*/
|
|
203
|
+
export function splitQuotedCSVLine(line: string): string[] {
|
|
204
|
+
const cells: string[] = []
|
|
205
|
+
let cell = ""
|
|
206
|
+
let quoted = false
|
|
207
|
+
|
|
208
|
+
for (let index = 0; index < line.length; index++) {
|
|
209
|
+
const char = line[index]!
|
|
210
|
+
|
|
211
|
+
if (quoted) {
|
|
212
|
+
if (char === '"') {
|
|
213
|
+
if (line[index + 1] === '"') {
|
|
214
|
+
cell += '"'
|
|
215
|
+
|
|
216
|
+
index++
|
|
217
|
+
} else {
|
|
218
|
+
quoted = false
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
cell += char
|
|
222
|
+
}
|
|
223
|
+
} else if (char === '"') {
|
|
224
|
+
quoted = true
|
|
225
|
+
} else if (char === ",") {
|
|
226
|
+
cells.push(cell)
|
|
227
|
+
cell = ""
|
|
228
|
+
} else {
|
|
229
|
+
cell += char
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
cells.push(cell)
|
|
234
|
+
|
|
235
|
+
return cells
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* The lines of a CSV text, with the header first and no empty line.
|
|
240
|
+
*/
|
|
241
|
+
function csvLines(csv: string): string[] {
|
|
242
|
+
return TextSpliterator.from(csv)
|
|
243
|
+
.filter((line) => line.length > 0)
|
|
244
|
+
.toArray()
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function columnIndex(header: readonly string[], name: string, file: string): number {
|
|
248
|
+
const index = header.indexOf(name)
|
|
249
|
+
|
|
250
|
+
if (index === -1) throw new Error(`${file} has no ${name} column. The header is ${header.join(",")}`)
|
|
251
|
+
|
|
252
|
+
return index
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Reads the OurAirports CSV into airport records: every row with an `iata_code`, sorted by code.
|
|
257
|
+
*
|
|
258
|
+
* `currentAlpha2` is the set of officially assigned alpha-2 codes,
|
|
259
|
+
* used only to label the row's country status.
|
|
260
|
+
*/
|
|
261
|
+
export function normalizeAirports(
|
|
262
|
+
csv: string,
|
|
263
|
+
currentAlpha2: ReadonlySet<string>,
|
|
264
|
+
profile: string
|
|
265
|
+
): NormalizedAirports {
|
|
266
|
+
const lines = csvLines(csv)
|
|
267
|
+
const header = splitQuotedCSVLine(lines[0]!)
|
|
268
|
+
const column = (name: string): number => columnIndex(header, name, "airports.csv")
|
|
269
|
+
|
|
270
|
+
const at = {
|
|
271
|
+
id: column("id"),
|
|
272
|
+
type: column("type"),
|
|
273
|
+
name: column("name"),
|
|
274
|
+
latitude: column("latitude_deg"),
|
|
275
|
+
longitude: column("longitude_deg"),
|
|
276
|
+
country: column("iso_country"),
|
|
277
|
+
region: column("iso_region"),
|
|
278
|
+
municipality: column("municipality"),
|
|
279
|
+
scheduled: column("scheduled_service"),
|
|
280
|
+
icao: column("icao_code"),
|
|
281
|
+
iata: column("iata_code"),
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const records: AirportRecord[] = []
|
|
285
|
+
const held = new Map<string, string>()
|
|
286
|
+
|
|
287
|
+
for (const line of lines.slice(1)) {
|
|
288
|
+
const cells = splitQuotedCSVLine(line)
|
|
289
|
+
|
|
290
|
+
if (cells.length !== header.length)
|
|
291
|
+
throw new Error(`airports.csv row has ${cells.length} cells: ${line.slice(0, 80)}`)
|
|
292
|
+
|
|
293
|
+
const iata = cells[at.iata]!
|
|
294
|
+
|
|
295
|
+
if (!iata) continue
|
|
296
|
+
|
|
297
|
+
if (!ALPHA3.test(iata)) throw new Error(`row ${cells[at.id]}: iata_code ${stringifyJSON(iata)} is outside [A-Z]{3}`)
|
|
298
|
+
|
|
299
|
+
const other = held.get(iata)
|
|
300
|
+
|
|
301
|
+
if (other) throw new Error(`iata ${iata} is held by rows ${other} and ${cells[at.id]}`)
|
|
302
|
+
|
|
303
|
+
held.set(iata, cells[at.id]!)
|
|
304
|
+
|
|
305
|
+
const latitude = Number(cells[at.latitude])
|
|
306
|
+
const longitude = Number(cells[at.longitude])
|
|
307
|
+
|
|
308
|
+
if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) {
|
|
309
|
+
throw new TypeError(`row ${cells[at.id]}: unreadable coordinate ${cells[at.latitude]},${cells[at.longitude]}`)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const country = cells[at.country] || null
|
|
313
|
+
const icao = cells[at.icao] || null
|
|
314
|
+
|
|
315
|
+
records.push({
|
|
316
|
+
entityID: `ourairports:${cells[at.id]}`,
|
|
317
|
+
iata,
|
|
318
|
+
icao,
|
|
319
|
+
name: cells[at.name]!,
|
|
320
|
+
facility: cells[at.type]!,
|
|
321
|
+
scheduledService: cells[at.scheduled] === "yes",
|
|
322
|
+
latitude,
|
|
323
|
+
longitude,
|
|
324
|
+
country,
|
|
325
|
+
countryStatus: country ? (currentAlpha2.has(country) ? "iso3166-1" : "source-extension") : "unstated",
|
|
326
|
+
isoRegion: cells[at.region] || null,
|
|
327
|
+
municipality: cells[at.municipality] || null,
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return {
|
|
332
|
+
profile,
|
|
333
|
+
source: "ourairports-airports",
|
|
334
|
+
normalizationVersion: NORMALIZATION_VERSION,
|
|
335
|
+
records: records.toSorted((a, b) => a.iata.localeCompare(b.iata, "en")),
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Checks the country set against OurAirports' own country list and reports each side's extras.
|
|
341
|
+
*
|
|
342
|
+
* The two sources disagree on purpose: OurAirports adds `XK`, `XP` and `ZZ` as extensions
|
|
343
|
+
* and lists no entry for a territory with no airport.
|
|
344
|
+
* The report goes in the coverage declaration rather than changing either dataset.
|
|
345
|
+
*/
|
|
346
|
+
export function compareCountryLists(
|
|
347
|
+
countries: readonly CountryRecord[],
|
|
348
|
+
countriesCSV: string
|
|
349
|
+
): { onlyOurAirports: string[]; onlyWikidata: string[] } {
|
|
350
|
+
const lines = csvLines(countriesCSV)
|
|
351
|
+
const header = splitQuotedCSVLine(lines[0]!)
|
|
352
|
+
const codeIndex = columnIndex(header, "code", "countries.csv")
|
|
353
|
+
const ourAirports = new Set(lines.slice(1).map((line) => splitQuotedCSVLine(line)[codeIndex]!))
|
|
354
|
+
|
|
355
|
+
const current = new Set(
|
|
356
|
+
countries.filter((record) => record.status === "officially-assigned").map((record) => record.alpha2)
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
onlyOurAirports: [...ourAirports].filter((code) => !current.has(code)).toSorted(),
|
|
361
|
+
onlyWikidata: [...current].filter((code) => !ourAirports.has(code)).toSorted(),
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* The coverage declaration for the open profile.
|
|
367
|
+
*/
|
|
368
|
+
export function declareCoverage(
|
|
369
|
+
countries: NormalizedCountries,
|
|
370
|
+
airports: NormalizedAirports,
|
|
371
|
+
comparison: ReturnType<typeof compareCountryLists>
|
|
372
|
+
): CoverageDeclaration {
|
|
373
|
+
const statuses: Record<string, number> = {}
|
|
374
|
+
|
|
375
|
+
for (const record of countries.records) {
|
|
376
|
+
statuses[record.status] = (statuses[record.status] ?? 0) + 1
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const current = countries.records.filter((record) => record.status === "officially-assigned").length
|
|
380
|
+
const airportCountryStatuses: Record<string, number> = {}
|
|
381
|
+
|
|
382
|
+
for (const record of airports.records) {
|
|
383
|
+
airportCountryStatuses[record.countryStatus] = (airportCountryStatuses[record.countryStatus] ?? 0) + 1
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const missMeans =
|
|
387
|
+
"not-found-in-snapshot: the source holds no such code, and the issuing authority may still have assigned it"
|
|
388
|
+
|
|
389
|
+
return {
|
|
390
|
+
profile: countries.profile,
|
|
391
|
+
namespaces: {
|
|
392
|
+
"iso3166-1-alpha2": { source: countries.source, count: current, statuses, missMeans },
|
|
393
|
+
"iso3166-1-alpha3": { source: countries.source, count: current, statuses, missMeans },
|
|
394
|
+
"iso3166-1-numeric": { source: countries.source, count: current, statuses, missMeans },
|
|
395
|
+
"iata-location": {
|
|
396
|
+
source: airports.source,
|
|
397
|
+
count: airports.records.length,
|
|
398
|
+
kinds: ["airport"],
|
|
399
|
+
unsupported: ["metropolitan", "intermodal", "rail", "bus"],
|
|
400
|
+
statuses: airportCountryStatuses,
|
|
401
|
+
missMeans,
|
|
402
|
+
},
|
|
403
|
+
"icao-location": {
|
|
404
|
+
source: airports.source,
|
|
405
|
+
count: airports.records.filter((record) => record.icao).length,
|
|
406
|
+
kinds: ["airport"],
|
|
407
|
+
unsupported: ["a location with no IATA code: the source rows without iata_code are left unread"],
|
|
408
|
+
missMeans,
|
|
409
|
+
},
|
|
410
|
+
$countryListComparison: {
|
|
411
|
+
source: "ourairports-countries",
|
|
412
|
+
count: comparison.onlyOurAirports.length + comparison.onlyWikidata.length,
|
|
413
|
+
kinds: [
|
|
414
|
+
`onlyOurAirports: ${comparison.onlyOurAirports.join(",")}`,
|
|
415
|
+
`onlyWikidata: ${comparison.onlyWikidata.join(",")}`,
|
|
416
|
+
],
|
|
417
|
+
missMeans: "a comparison rather than a namespace",
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Serializes a normalized collection with one record per line, so a source update diffs by record.
|
|
425
|
+
*
|
|
426
|
+
* The envelope keys come first, then `records`, each on its own line.
|
|
427
|
+
*/
|
|
428
|
+
export function formatNormalized(collection: NormalizedCountries | NormalizedAirports): string {
|
|
429
|
+
const { records, ...envelope } = collection
|
|
430
|
+
const head = stringifyJSON(envelope).slice(1, -1)
|
|
431
|
+
const body = records.map((record) => `\t\t${stringifyJSON(record)}`).join(",\n")
|
|
432
|
+
|
|
433
|
+
return `{${head},\n\t"records": [\n${body}\n\t]\n}\n`
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Reads the three pinned sources and normalizes them, refusing bytes the lock does not describe.
|
|
438
|
+
*/
|
|
439
|
+
export async function normalizeFromLock(lock: SourceLock): Promise<{
|
|
440
|
+
countries: NormalizedCountries
|
|
441
|
+
airports: NormalizedAirports
|
|
442
|
+
coverage: CoverageDeclaration
|
|
443
|
+
}> {
|
|
444
|
+
for (const definition of SOURCES.filter((candidate) => candidate.terms.elected)) {
|
|
445
|
+
const locked = lock.sources[definition.id]
|
|
446
|
+
const digest = await sha256File(sourcePath(definition))
|
|
447
|
+
|
|
448
|
+
if (!locked) throw new Error(`${definition.id} is outside the lock`)
|
|
449
|
+
|
|
450
|
+
if (digest !== locked.sha256) {
|
|
451
|
+
throw new Error(`${definition.id}: file digest ${digest} differs from the lock's ${locked.sha256}`)
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const results = await readLocalJSONFile<SPARQLResults>(sourcePath(sourceDefinition("wikidata-iso3166-1")))
|
|
456
|
+
const countries = normalizeCountries(results, lock.profile)
|
|
457
|
+
|
|
458
|
+
const current = new Set(
|
|
459
|
+
countries.records.filter((record) => record.status === "officially-assigned").map((record) => record.alpha2)
|
|
460
|
+
)
|
|
461
|
+
|
|
462
|
+
const airports = normalizeAirports(
|
|
463
|
+
await readLocalTextFile(sourcePath(sourceDefinition("ourairports-airports"))),
|
|
464
|
+
current,
|
|
465
|
+
lock.profile
|
|
466
|
+
)
|
|
467
|
+
|
|
468
|
+
const comparison = compareCountryLists(
|
|
469
|
+
countries.records,
|
|
470
|
+
await readLocalTextFile(sourcePath(sourceDefinition("ourairports-countries")))
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
return { countries, airports, coverage: declareCoverage(countries, airports, comparison) }
|
|
474
|
+
}
|
|
Binary file
|
|
Binary file
|
package/lib/address-key.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* The address-id consumer for the matcher. Derives a stable {@link PostalAddressID} from a
|
|
7
|
-
* resolved {@link SourceRecord} and exposes it as a blocking key, the deterministic
|
|
8
|
-
* exact-canonical-address complement to the fuzzy Fellegi-Sunter / GBT scoring. Two uses:
|
|
9
|
-
*
|
|
10
|
-
* - **As a pre-dedup / join key:** `group BY postalAddressID(record)` collapses records that resolve
|
|
11
|
-
* to the same place and share a canonical address with no scoring at all. That is the cheap,
|
|
12
|
-
* certain part of dedup before the matcher does the fuzzy rest.
|
|
13
|
-
* - **As a blocking key:** {@link addressIDBlockingKey} adds the address-id to the blocking union, so
|
|
14
|
-
* records sharing one are guaranteed to be compared.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { createPostalAddressID, type PostalAddressID } from "@mailwoman/address-id"
|
|
18
|
-
import { type BlockingKey, exactKey } from "@mailwoman/match"
|
|
19
|
-
|
|
20
|
-
import type { SourceRecord } from "#types"
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The stable address primary key for a record, or null when it is not geocoded
|
|
24
|
-
* (no coordinate means no locality cell) or includes no raw address to hash.
|
|
25
|
-
*
|
|
26
|
-
* The state prefix is plucked from the address when present.
|
|
27
|
-
*/
|
|
28
|
-
export function postalAddressID(record: SourceRecord): PostalAddressID | null {
|
|
29
|
-
const coordinate = record.address?.geocode?.coordinate
|
|
30
|
-
const address = record.address?.raw
|
|
31
|
-
|
|
32
|
-
if (!coordinate || !address) return null
|
|
33
|
-
|
|
34
|
-
return createPostalAddressID({ coordinate, address })
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* A blocking key on the {@link postalAddressID}.
|
|
39
|
-
*
|
|
40
|
-
* Records that resolve to the same place with the same canonical address block together.
|
|
41
|
-
*
|
|
42
|
-
* Add it to {@link defaultBlockingKeys}'s union when an exact address join should never be missed.
|
|
43
|
-
*/
|
|
44
|
-
export function addressIDBlockingKey(): BlockingKey<SourceRecord> {
|
|
45
|
-
return exactKey((record) => postalAddressID(record))
|
|
46
|
-
}
|
package/lib/geocode-handler.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* The per-record geocode step, factored out of the worker so it unit-tests against a fake geocoder (no
|
|
7
|
-
* neural model / SQLite). `geocode-worker.ts` builds the real geocoder from config and wraps this.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { type ColumnMapping, type GeocodeAddress, pick } from "#ingest"
|
|
11
|
-
import type { SourceRecord } from "#types"
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Build the handler `geocodeStream` runs per normalized record: recompute the joined address
|
|
15
|
-
* string from `record.raw` + `mapping.address` (the worker can't receive the original closure),
|
|
16
|
-
* geocode it via `geocode`, and attach the result.
|
|
17
|
-
*
|
|
18
|
-
* Records with no mapped address pass through untouched (no geocode call).
|
|
19
|
-
* The default separator matches {@link ingestRow}'s `addressSeparator`.
|
|
20
|
-
*/
|
|
21
|
-
export function makeGeocodeHandler(
|
|
22
|
-
geocode: GeocodeAddress,
|
|
23
|
-
mapping: ColumnMapping,
|
|
24
|
-
addressSeparator = ", "
|
|
25
|
-
): (record: SourceRecord) => Promise<SourceRecord> {
|
|
26
|
-
return async (record) => {
|
|
27
|
-
if (!record.raw) return record
|
|
28
|
-
|
|
29
|
-
const addressValue = pick(record.raw, mapping.address, addressSeparator)
|
|
30
|
-
|
|
31
|
-
if (!addressValue) return record
|
|
32
|
-
|
|
33
|
-
const address = (await geocode(addressValue)) ?? null
|
|
34
|
-
|
|
35
|
-
return { ...record, address }
|
|
36
|
-
}
|
|
37
|
-
}
|
package/lib/geojson.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Export resolved entities as GeoJSON — the bridge to QGIS and any web map. Each entity becomes a
|
|
7
|
-
* Point at its resolved coordinate, carrying the properties an analyst needs: the count of records
|
|
8
|
-
* merged into it, how tightly (cohesion), the canonical name/org/address and the geocode tier
|
|
9
|
-
* (so rooftop-precise entities can be styled apart from admin-centroid guesses). Entities without
|
|
10
|
-
* a coordinate are omitted (a Point feature needs one).
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { formatPersonName } from "@mailwoman/record/name"
|
|
14
|
-
import type { GeoFeature, GeoFeatureCollection, PointLiteral } from "@mailwoman/spatial"
|
|
15
|
-
|
|
16
|
-
import type { EntityGeoData, ResolvedEntity, SourceRecord } from "#types"
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Assemble a display name from a record's parsed person name, if any.
|
|
20
|
-
*/
|
|
21
|
-
function displayName(record: SourceRecord): string | null {
|
|
22
|
-
return formatPersonName(record.name ?? null) || null
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* One entity → one GeoJSON Point feature.
|
|
27
|
-
*
|
|
28
|
-
* `extra` merges over (and may override) the standard properties.
|
|
29
|
-
* The reconciliation flow adds its `bucket` and swaps the display name for the
|
|
30
|
-
* representative's org-or-person form.
|
|
31
|
-
*/
|
|
32
|
-
export function toFeature(
|
|
33
|
-
entity: ResolvedEntity,
|
|
34
|
-
extra?: Partial<EntityGeoData>
|
|
35
|
-
): GeoFeature<PointLiteral, EntityGeoData> {
|
|
36
|
-
const rep = entity.representative
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
type: "Feature",
|
|
40
|
-
geometry: {
|
|
41
|
-
type: "Point",
|
|
42
|
-
coordinates: [entity.coordinate!.longitude, entity.coordinate!.latitude],
|
|
43
|
-
},
|
|
44
|
-
properties: {
|
|
45
|
-
entityID: entity.id,
|
|
46
|
-
recordCount: entity.records.length,
|
|
47
|
-
cohesion: entity.cohesion,
|
|
48
|
-
sourceIDs: entity.records.map((r) => r.id),
|
|
49
|
-
// Distinct provenance labels the entity's records span.
|
|
50
|
-
// An entity with ≥2 is a cross-dataset link.
|
|
51
|
-
sources: [...new Set(entity.records.map((r) => r.source).filter((s): s is string => !!s))].toSorted(),
|
|
52
|
-
name: displayName(rep),
|
|
53
|
-
organization: rep.organization?.canonical ?? null,
|
|
54
|
-
address: rep.address?.formatted ?? null,
|
|
55
|
-
geocodeTier: rep.address?.geocode?.tier ?? null,
|
|
56
|
-
bucket: null,
|
|
57
|
-
...extra,
|
|
58
|
-
},
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Convert resolved entities into a GeoJSON `FeatureCollection` of points, ready for QGIS.
|
|
64
|
-
*
|
|
65
|
-
* Entities with no resolved coordinate are skipped.
|
|
66
|
-
*/
|
|
67
|
-
export function toGeoJSON(entities: readonly ResolvedEntity[]): GeoFeatureCollection<PointLiteral, EntityGeoData> {
|
|
68
|
-
return {
|
|
69
|
-
type: "FeatureCollection",
|
|
70
|
-
features: entities.filter((entity) => entity.coordinate).map((entity) => toFeature(entity)),
|
|
71
|
-
}
|
|
72
|
-
}
|