@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
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Cross-source threshold sweep. Resolve the sources once, then compare the Fellegi-Sunter
|
|
7
|
-
* baseline against the bundled GBT over a fine threshold sweep, scoring each arm on cross-source
|
|
8
|
-
* links, triple-source entities, total entities and phone corroboration.
|
|
9
|
-
*
|
|
10
|
-
* Run: `mailwoman registry scorer-eval threshold-sweep [--cap 2000] [--state TX]
|
|
11
|
-
* [--wof <admin.db>] [--data-root <dir>] [--out-md <md>]`
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { dataRootPath } from "@mailwoman/core/data-root"
|
|
15
|
-
import { writeLocalFile } from "@mailwoman/core/fs/writers"
|
|
16
|
-
import { pathToFileURL } from "@mailwoman/core/module/file-url"
|
|
17
|
-
import { formatPercent } from "@mailwoman/core/stats"
|
|
18
|
-
import { resolvePath } from "path-ts"
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
addressFrequencyKey,
|
|
22
|
-
buildDefaultModel,
|
|
23
|
-
createGBTScorer,
|
|
24
|
-
DEDUP_GBT_META,
|
|
25
|
-
DEDUP_GBT_MODEL,
|
|
26
|
-
ingestRows,
|
|
27
|
-
normalizePhoneStrict,
|
|
28
|
-
resolveEntities,
|
|
29
|
-
streamRows,
|
|
30
|
-
type GeocodeAddress,
|
|
31
|
-
type ResolvedEntity,
|
|
32
|
-
type SourceRecord,
|
|
33
|
-
} from "#index"
|
|
34
|
-
import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
|
|
35
|
-
import { buildSpecs, stateOption } from "#tools/shared"
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Independent sources that must agree before a cluster counts as cross-source corroborated.
|
|
39
|
-
*/
|
|
40
|
-
const MIN_CROSS_SOURCE_AGREEMENT = 3
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Options for {@linkcode crossSourceThresholdSweep}.
|
|
44
|
-
*/
|
|
45
|
-
export interface CrossSourceThresholdSweepOptions {
|
|
46
|
-
/**
|
|
47
|
-
* The injected geocoder factory.
|
|
48
|
-
*
|
|
49
|
-
* The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
|
|
50
|
-
*/
|
|
51
|
-
createGeocoder: EvalGeocoderFactory
|
|
52
|
-
/**
|
|
53
|
-
* Record-matcher sources directory.
|
|
54
|
-
*
|
|
55
|
-
* @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
|
|
56
|
-
*/
|
|
57
|
-
sources?: string
|
|
58
|
-
/**
|
|
59
|
-
* Rows kept per source.
|
|
60
|
-
*
|
|
61
|
-
* @defaultValue `2000`
|
|
62
|
-
*/
|
|
63
|
-
cap?: number
|
|
64
|
-
/**
|
|
65
|
-
* State filter.
|
|
66
|
-
*
|
|
67
|
-
* @defaultValue TX.
|
|
68
|
-
*/
|
|
69
|
-
state?: string
|
|
70
|
-
/**
|
|
71
|
-
* A trained cross-source GBT module (exports CROSS_SOURCE_GBT_MODEL + _META) to
|
|
72
|
-
* grade as a third arm at its recommended threshold.
|
|
73
|
-
* This is the model `registry train-scorer cross-gbt` emits.
|
|
74
|
-
*/
|
|
75
|
-
candidate?: string
|
|
76
|
-
/**
|
|
77
|
-
* Also write the markdown report here.
|
|
78
|
-
*/
|
|
79
|
-
outMd?: string
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const entitySources = (e: ResolvedEntity): Set<string> =>
|
|
83
|
-
new Set(e.records.map((r) => r.source).filter((s): s is string => !!s))
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Label-free precision proxy: does this cross-source entity have the same phone
|
|
87
|
-
* in records from two different sources?
|
|
88
|
-
*
|
|
89
|
-
* Phone is not the join key, so a match is independent corroboration of one facility.
|
|
90
|
-
* Entities without phone numbers on two cross-source records are unknown.
|
|
91
|
-
* Only checkable entities count.
|
|
92
|
-
*/
|
|
93
|
-
function phoneEvidence(e: ResolvedEntity): "corroborated" | "contradicted" | "unknown" {
|
|
94
|
-
const bySource = new Map<string, Set<string>>()
|
|
95
|
-
|
|
96
|
-
for (const r of e.records) {
|
|
97
|
-
const ph = normalizePhoneStrict(r.phone)
|
|
98
|
-
|
|
99
|
-
if (!ph) continue
|
|
100
|
-
const s = r.source ?? "?"
|
|
101
|
-
|
|
102
|
-
if (!bySource.has(s)) {
|
|
103
|
-
bySource.set(s, new Set())
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
bySource.get(s)!.add(ph)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const sources = [...bySource.keys()]
|
|
110
|
-
|
|
111
|
-
if (sources.length < 2) return "unknown"
|
|
112
|
-
let any = false
|
|
113
|
-
|
|
114
|
-
for (let i = 0; i < sources.length; i++) {
|
|
115
|
-
for (let j = i + 1; j < sources.length; j++) {
|
|
116
|
-
any = true
|
|
117
|
-
|
|
118
|
-
for (const ph of bySource.get(sources[i]!)!) if (bySource.get(sources[j]!)!.has(ph)) return "corroborated"
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return any ? "contradicted" : "unknown"
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
interface ArmMetrics {
|
|
126
|
-
label: string
|
|
127
|
-
threshold: number | null
|
|
128
|
-
entities: number
|
|
129
|
-
crossSource: number
|
|
130
|
-
tripleSource: number
|
|
131
|
-
phoneCorrob: number
|
|
132
|
-
phoneContradict: number
|
|
133
|
-
phoneCheckable: number
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async function measure(label: string, threshold: number | null, entities: ResolvedEntity[]): Promise<ArmMetrics> {
|
|
137
|
-
let crossSource = 0
|
|
138
|
-
let tripleSource = 0
|
|
139
|
-
let phoneCorrob = 0
|
|
140
|
-
let phoneContradict = 0
|
|
141
|
-
let phoneCheckable = 0
|
|
142
|
-
|
|
143
|
-
for (const e of entities) {
|
|
144
|
-
const n = entitySources(e).size
|
|
145
|
-
|
|
146
|
-
if (n < 2) continue
|
|
147
|
-
|
|
148
|
-
crossSource++
|
|
149
|
-
|
|
150
|
-
if (n >= MIN_CROSS_SOURCE_AGREEMENT) {
|
|
151
|
-
tripleSource++
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const ev = phoneEvidence(e)
|
|
155
|
-
|
|
156
|
-
if (ev === "corroborated") {
|
|
157
|
-
phoneCorrob++
|
|
158
|
-
|
|
159
|
-
phoneCheckable++
|
|
160
|
-
} else if (ev === "contradicted") {
|
|
161
|
-
phoneContradict++
|
|
162
|
-
|
|
163
|
-
phoneCheckable++
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return {
|
|
168
|
-
label,
|
|
169
|
-
threshold,
|
|
170
|
-
entities: entities.length,
|
|
171
|
-
crossSource,
|
|
172
|
-
tripleSource,
|
|
173
|
-
phoneCorrob,
|
|
174
|
-
phoneContradict,
|
|
175
|
-
phoneCheckable,
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Compare the FS baseline against bundled GBT over a threshold sweep.
|
|
181
|
-
* Emit the markdown report to stdout.
|
|
182
|
-
*/
|
|
183
|
-
export async function crossSourceThresholdSweep(
|
|
184
|
-
options: CrossSourceThresholdSweepOptions,
|
|
185
|
-
report?: (line: string) => void
|
|
186
|
-
): Promise<{ markdown: string }> {
|
|
187
|
-
const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
|
|
188
|
-
const CAP = options.cap ?? 2000
|
|
189
|
-
const STATE = stateOption(options)
|
|
190
|
-
const OUT_MD = options.outMd || ""
|
|
191
|
-
const CANDIDATE = options.candidate || ""
|
|
192
|
-
const SPECS = buildSpecs(`${SOURCES}`, STATE)
|
|
193
|
-
|
|
194
|
-
const rawBySource = new Map<string, Record<string, string>[]>()
|
|
195
|
-
|
|
196
|
-
for (const spec of SPECS) {
|
|
197
|
-
report?.(`[A] ${spec.source}: streaming + ${STATE} filter (cap ${CAP})…`)
|
|
198
|
-
const kept: Record<string, string>[] = []
|
|
199
|
-
|
|
200
|
-
for await (const row of streamRows(spec.path)) {
|
|
201
|
-
if (!spec.inState(row)) continue
|
|
202
|
-
kept.push(row)
|
|
203
|
-
|
|
204
|
-
if (kept.length >= CAP) break
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
rawBySource.set(spec.source, kept)
|
|
208
|
-
report?.(` ${spec.source}: ${kept.length} rows`)
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
report?.("[B] building the geocoder…")
|
|
212
|
-
const geocoder = await options.createGeocoder()
|
|
213
|
-
const geocodeForIngest: GeocodeAddress = geocoder.geocodeAddress
|
|
214
|
-
|
|
215
|
-
report?.("[C] geocoding + ingesting…")
|
|
216
|
-
const records: SourceRecord[] = []
|
|
217
|
-
|
|
218
|
-
for (const spec of SPECS) {
|
|
219
|
-
const recs = await ingestRows(rawBySource.get(spec.source)!, spec.mapping, { geocodeAddress: geocodeForIngest })
|
|
220
|
-
|
|
221
|
-
for (const r of recs) {
|
|
222
|
-
r.id = `${spec.source}:${r.id}`
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
records.push(...recs)
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
geocoder[Symbol.dispose]()
|
|
229
|
-
const geocoded = records.filter((r) => r.address?.geocode).length
|
|
230
|
-
report?.(` ${records.length} records; geocoded ${geocoded}`)
|
|
231
|
-
|
|
232
|
-
const addrCounts = new Map<string, number>()
|
|
233
|
-
let addrTotal = 0
|
|
234
|
-
|
|
235
|
-
for (const r of records) {
|
|
236
|
-
if (!r.address?.raw) continue
|
|
237
|
-
addrCounts.set(addressFrequencyKey(r.address.raw), (addrCounts.get(addressFrequencyKey(r.address.raw)) ?? 0) + 1)
|
|
238
|
-
|
|
239
|
-
addrTotal++
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const addressFrequency = {
|
|
243
|
-
total: addrTotal,
|
|
244
|
-
distinct: addrCounts.size,
|
|
245
|
-
frequency: (v: string) => (v ? (addrCounts.get(addressFrequencyKey(v)) ?? 0) / addrTotal : 0),
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const comparisons = buildDefaultModel({ collapseSpatial: true, addressFrequency }).comparisons
|
|
249
|
-
const gbtScorer = createGBTScorer({ model: DEDUP_GBT_MODEL, comparisons, addressFrequency })
|
|
250
|
-
|
|
251
|
-
report?.("[D] resolving — FS baseline baseline…")
|
|
252
|
-
|
|
253
|
-
const fs = await measure(
|
|
254
|
-
"FS baseline",
|
|
255
|
-
0,
|
|
256
|
-
resolveEntities(records, { trainEM: true, collapseSpatial: true, addressFrequency, learnedScorer: false }).entities
|
|
257
|
-
)
|
|
258
|
-
|
|
259
|
-
const SWEEP = [-8, -6, -5, -4, -3, -2, -1, 0, 1, 2, DEDUP_GBT_META.recommendedThreshold]
|
|
260
|
-
const gbtArms: ArmMetrics[] = []
|
|
261
|
-
|
|
262
|
-
for (const t of SWEEP) {
|
|
263
|
-
report?.(`[D] resolving — GBT @ threshold ${t}…`)
|
|
264
|
-
|
|
265
|
-
const { entities } = resolveEntities(records, {
|
|
266
|
-
collapseSpatial: true,
|
|
267
|
-
addressFrequency,
|
|
268
|
-
scorer: gbtScorer,
|
|
269
|
-
threshold: t,
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
gbtArms.push(await measure(`GBT @ ${t.toFixed(2)}`, t, entities))
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// A GBT arm dominates only when it matches FS cross-source links at no lower phone corroboration and
|
|
276
|
-
// keeps at least 90% of FS entities, since a collapse means giant-blob artifacts rather than links.
|
|
277
|
-
const pct = (n: number, d: number) => formatPercent(n, d, 0)
|
|
278
|
-
const candidateArms: ArmMetrics[] = []
|
|
279
|
-
|
|
280
|
-
if (CANDIDATE) {
|
|
281
|
-
const mod = (await import(pathToFileURL(resolvePath(CANDIDATE)).href)) as {
|
|
282
|
-
CROSS_SOURCE_GBT_MODEL?: typeof DEDUP_GBT_MODEL
|
|
283
|
-
CROSS_SOURCE_GBT_META?: { recommendedThreshold?: number }
|
|
284
|
-
ORG_CROSS_SOURCE_GBT_MODEL?: typeof DEDUP_GBT_MODEL
|
|
285
|
-
ORG_CROSS_SOURCE_GBT_META?: { recommendedThreshold?: number }
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
const candModel = mod.CROSS_SOURCE_GBT_MODEL ?? mod.ORG_CROSS_SOURCE_GBT_MODEL
|
|
289
|
-
|
|
290
|
-
if (!candModel)
|
|
291
|
-
throw new Error(`--candidate module exports neither CROSS_SOURCE_GBT_MODEL nor ORG_CROSS_SOURCE_GBT_MODEL`)
|
|
292
|
-
|
|
293
|
-
const t0 = (mod.CROSS_SOURCE_GBT_META ?? mod.ORG_CROSS_SOURCE_GBT_META)?.recommendedThreshold ?? 0
|
|
294
|
-
const candScorer = createGBTScorer({ model: candModel, comparisons, addressFrequency })
|
|
295
|
-
report?.(`[E] resolving — cross-source GBT candidate @ ${t0.toFixed(3)} (±)…`)
|
|
296
|
-
|
|
297
|
-
for (const t of [t0 - 1, t0, t0 + 1]) {
|
|
298
|
-
candidateArms.push(
|
|
299
|
-
await measure(
|
|
300
|
-
`cross-GBT @ ${t.toFixed(2)}`,
|
|
301
|
-
t,
|
|
302
|
-
resolveEntities(records, {
|
|
303
|
-
trainEM: true,
|
|
304
|
-
collapseSpatial: true,
|
|
305
|
-
addressFrequency,
|
|
306
|
-
scorer: candScorer,
|
|
307
|
-
threshold: t,
|
|
308
|
-
}).entities
|
|
309
|
-
)
|
|
310
|
-
)
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const rate = (a: ArmMetrics) => (a.phoneCheckable > 0 ? a.phoneCorrob / a.phoneCheckable : 0)
|
|
315
|
-
const fsCorrobRate = rate(fs)
|
|
316
|
-
const minEntities = Math.floor(fs.entities * 0.9)
|
|
317
|
-
|
|
318
|
-
const dominating = gbtArms.find(
|
|
319
|
-
(a) => a.crossSource >= fs.crossSource && rate(a) >= fsCorrobRate && a.entities >= minEntities
|
|
320
|
-
)
|
|
321
|
-
|
|
322
|
-
// The candidate gets its own verdict scan, separate from the option-1 verdict for the dedup GBT.
|
|
323
|
-
const candidateDominating = candidateArms.find(
|
|
324
|
-
(a) => a.crossSource >= fs.crossSource && rate(a) >= fsCorrobRate && a.entities >= minEntities
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
let candidateBest: ArmMetrics | null = null
|
|
328
|
-
|
|
329
|
-
for (const arm of candidateArms) {
|
|
330
|
-
if (arm.entities >= minEntities && arm.crossSource > (candidateBest?.crossSource ?? -1)) {
|
|
331
|
-
candidateBest = arm
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
const rows = [fs, ...gbtArms, ...candidateArms]
|
|
336
|
-
|
|
337
|
-
const lines: string[] = [
|
|
338
|
-
`# #655 — cross-source threshold sweep: can a re-thresholded GBT beat FS?`,
|
|
339
|
-
"",
|
|
340
|
-
`_TX-scoped, ≤${CAP} rows/source (NPPES org + TX HHSC nursing = eligibility-ish; FCC-RHC = funding), ` +
|
|
341
|
-
`geocoded once then resolved per arm. **Phone-corrob** = of the cross-source entities whose records carry ` +
|
|
342
|
-
`a phone in ≥2 different sources, the fraction where those phones MATCH — a label-free precision proxy ` +
|
|
343
|
-
`(phone is not the join key). Higher cross-source + higher phone-corrob = better._`,
|
|
344
|
-
"",
|
|
345
|
-
`| arm | threshold | total entities | cross-source links | triple-source | phone-corrob (of checkable) |`,
|
|
346
|
-
`|---|---:|---:|---:|---:|---|`,
|
|
347
|
-
]
|
|
348
|
-
|
|
349
|
-
for (const r of rows) {
|
|
350
|
-
lines.push(
|
|
351
|
-
`| ${r.label} | ${r.threshold === null ? "—" : r.threshold} | ${r.entities} | ${r.crossSource} | ` +
|
|
352
|
-
`${r.tripleSource} | ${r.phoneCorrob}/${r.phoneCheckable} (${pct(r.phoneCorrob, r.phoneCheckable)}) |`
|
|
353
|
-
)
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
lines.push("")
|
|
357
|
-
lines.push(`## Verdict`)
|
|
358
|
-
|
|
359
|
-
if (CANDIDATE) {
|
|
360
|
-
const c = candidateDominating ?? candidateBest
|
|
361
|
-
lines.push("")
|
|
362
|
-
|
|
363
|
-
if (candidateDominating) {
|
|
364
|
-
lines.push(
|
|
365
|
-
`**The --candidate model DOMINATES FS**: ${candidateDominating.crossSource} cross-source links (FS ${fs.crossSource}) at phone-corrob ${(100 * rate(candidateDominating)).toFixed(0)}% ≥ FS ${(100 * fsCorrobRate).toFixed(0)}%, entities ${candidateDominating.entities} (no collapse). Un-pinning FS for this objective is supported by this run.`
|
|
366
|
-
)
|
|
367
|
-
} else if (c) {
|
|
368
|
-
lines.push(
|
|
369
|
-
`**--candidate (best non-collapsing arm)**: ${c.crossSource} cross-source links vs FS ${fs.crossSource}, phone-corrob ${(100 * rate(c)).toFixed(0)}% vs FS ${(100 * fsCorrobRate).toFixed(0)}%, entities ${c.entities}. Does not STRICTLY dominate — judge the margins (the phone proxy is one-link noisy at this n).`
|
|
370
|
-
)
|
|
371
|
-
} else {
|
|
372
|
-
lines.push(`**--candidate**: no non-collapsing arm (every threshold fell below the entity floor).`)
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
lines.push("")
|
|
377
|
-
|
|
378
|
-
lines.push(
|
|
379
|
-
`FS baseline: **${fs.crossSource}** cross-source links (${fs.tripleSource} triple), ` +
|
|
380
|
-
`phone-corrob ${pct(fs.phoneCorrob, fs.phoneCheckable)} (${fs.phoneCorrob}/${fs.phoneCheckable}).`
|
|
381
|
-
)
|
|
382
|
-
|
|
383
|
-
lines.push("")
|
|
384
|
-
|
|
385
|
-
if (!dominating) {
|
|
386
|
-
lines.push(
|
|
387
|
-
`**No GBT threshold dominates FS** — none matches FS's ${fs.crossSource} cross-source links at ≥ its ` +
|
|
388
|
-
`${pct(fs.phoneCorrob, fs.phoneCheckable)} phone-corrob without over-merging (entity count collapsing below ` +
|
|
389
|
-
`${minEntities}). At its dedup threshold the GBT finds FEWER cross-source links than FS; lowering the ` +
|
|
390
|
-
`threshold to admit more only over-merges (the over-merge features REPLACE the FS weight, so true ` +
|
|
391
|
-
`cross-source pairs share a logit band with genuine over-merges). Threshold alone (option 1) is ` +
|
|
392
|
-
`**INSUFFICIENT** — FS stays pinned (correct + best-precision for this objective); a cross-objective ` +
|
|
393
|
-
`retrain (option 2), conditioned on cross-source labels, is the only change. See #655.`
|
|
394
|
-
)
|
|
395
|
-
} else {
|
|
396
|
-
lines.push(
|
|
397
|
-
`**GBT @ ${dominating.threshold} dominates FS**: ${dominating.crossSource} links (vs ${fs.crossSource}) at ` +
|
|
398
|
-
`${pct(dominating.phoneCorrob, dominating.phoneCheckable)} phone-corrob (vs ${pct(fs.phoneCorrob, fs.phoneCheckable)}), ` +
|
|
399
|
-
`${dominating.entities} entities (vs ${fs.entities}). The threshold fix (option 1) WORKS: ship a cross-source ` +
|
|
400
|
-
`threshold ≈ ${dominating.threshold}.`
|
|
401
|
-
)
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
lines.push("")
|
|
405
|
-
|
|
406
|
-
const md = lines.join("\n")
|
|
407
|
-
|
|
408
|
-
console.log(md)
|
|
409
|
-
|
|
410
|
-
if (OUT_MD) {
|
|
411
|
-
await writeLocalFile(md, OUT_MD)
|
|
412
|
-
report?.(`[written] ${OUT_MD}`)
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
return { markdown: md }
|
|
416
|
-
}
|
package/tools/dedup-ceiling.ts
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Dedup ceiling measurement, answering how good is good enough for dedup from the data rather
|
|
7
|
-
* than from a round number. The residual dedup error is over-merge: distinct co-located providers
|
|
8
|
-
* (different NPIs at one address) fused because a shared address outvotes a disagreeing name. The
|
|
9
|
-
* irreducible part is the set of co-located distinct-NPI pairs whose name text is also near
|
|
10
|
-
* identical, so no name or organization feature can separate them.
|
|
11
|
-
*
|
|
12
|
-
* This measures that floor directly and without labels, using NPI as the distinctness truth. It
|
|
13
|
-
* is geocode-free on purpose, so it can run at large N in seconds. "Same address" uses the
|
|
14
|
-
* matcher's own `addressFrequencyKey`, and "same name" uses a normalized token Jaccard over the
|
|
15
|
-
* legal business name.
|
|
16
|
-
*
|
|
17
|
-
* Run: `mailwoman registry dedup-ceiling [--cap 50000] [--state TX] [--sources <dir>] [--tau 0.7]
|
|
18
|
-
* [--out-md <md>]`
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import { dataRootPath } from "@mailwoman/core/data-root"
|
|
22
|
-
import { writeLocalFile } from "@mailwoman/core/fs/writers"
|
|
23
|
-
import { formatPercent } from "@mailwoman/core/stats"
|
|
24
|
-
import { jaccard } from "@mailwoman/match"
|
|
25
|
-
|
|
26
|
-
import { colocatedDistinctPairs, scanColocatedProviders, stateOption, type ColocatedProvider } from "#tools/shared"
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Similarity at or above which a pair is a near-miss for a reviewer to inspect rather than unrelated.
|
|
30
|
-
*/
|
|
31
|
-
const WEAK_SIMILARITY_MIN = 0.3
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Options for {@linkcode dedupCeiling}.
|
|
35
|
-
*/
|
|
36
|
-
export interface DedupCeilingOptions {
|
|
37
|
-
/**
|
|
38
|
-
* Record-matcher sources directory.
|
|
39
|
-
*
|
|
40
|
-
* @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
|
|
41
|
-
*/
|
|
42
|
-
sources?: string
|
|
43
|
-
/**
|
|
44
|
-
* Providers sampled from the registry.
|
|
45
|
-
*
|
|
46
|
-
* @defaultValue `50000`
|
|
47
|
-
*/
|
|
48
|
-
cap?: number
|
|
49
|
-
/**
|
|
50
|
-
* State filter.
|
|
51
|
-
*
|
|
52
|
-
* @defaultValue TX.
|
|
53
|
-
*/
|
|
54
|
-
state?: string
|
|
55
|
-
/**
|
|
56
|
-
* Org-name Jaccard collision threshold.
|
|
57
|
-
*
|
|
58
|
-
* @defaultValue `0.7`
|
|
59
|
-
*/
|
|
60
|
-
tau?: number
|
|
61
|
-
/**
|
|
62
|
-
* Also write the markdown report here.
|
|
63
|
-
*/
|
|
64
|
-
outMd?: string
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Measure the irreducible over-merge of co-located providers.
|
|
69
|
-
* Emit the markdown report to stdout.
|
|
70
|
-
*/
|
|
71
|
-
export async function dedupCeiling(
|
|
72
|
-
options: DedupCeilingOptions = {},
|
|
73
|
-
report?: (line: string) => void
|
|
74
|
-
): Promise<{ markdown: string; pairs: number; collide: number }> {
|
|
75
|
-
const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
|
|
76
|
-
const CAP = options.cap ?? 50_000
|
|
77
|
-
const STATE = stateOption(options)
|
|
78
|
-
const TAU = options.tau ?? 0.7
|
|
79
|
-
const OUT_MD = options.outMd || ""
|
|
80
|
-
const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
|
|
81
|
-
|
|
82
|
-
report?.(`[A] streaming ${STATE} org providers (cap ${CAP})…`)
|
|
83
|
-
const { byAddr, kept, scanned } = await scanColocatedProviders({ registryPath: REGISTRY, state: STATE, cap: CAP })
|
|
84
|
-
report?.(` scanned ${scanned} rows → ${kept} ${STATE} org providers at ${byAddr.size} distinct addresses`)
|
|
85
|
-
|
|
86
|
-
let sharedAddresses = 0
|
|
87
|
-
let providersAtSharedAddr = 0
|
|
88
|
-
let pairs = 0
|
|
89
|
-
let collide = 0
|
|
90
|
-
let mid = 0
|
|
91
|
-
let separable = 0
|
|
92
|
-
let collideSharePhone = 0
|
|
93
|
-
let collideSameAuth = 0
|
|
94
|
-
let collideDistinct = 0
|
|
95
|
-
const PAIR_BUDGET = 5_000_000
|
|
96
|
-
|
|
97
|
-
// guard against a pathological mega-address (PO-box farms)
|
|
98
|
-
|
|
99
|
-
let lastGroup: readonly ColocatedProvider[] | null = null
|
|
100
|
-
|
|
101
|
-
for (const { a, b, group } of colocatedDistinctPairs(byAddr)) {
|
|
102
|
-
if (group !== lastGroup) {
|
|
103
|
-
lastGroup = group
|
|
104
|
-
|
|
105
|
-
sharedAddresses++
|
|
106
|
-
providersAtSharedAddr += group.length
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (pairs >= PAIR_BUDGET) continue
|
|
110
|
-
|
|
111
|
-
pairs++
|
|
112
|
-
const sim = jaccard(a.tokens, b.tokens)
|
|
113
|
-
|
|
114
|
-
if (sim >= TAU) {
|
|
115
|
-
collide++
|
|
116
|
-
|
|
117
|
-
if (a.phone && a.phone === b.phone) {
|
|
118
|
-
collideSharePhone++
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const sameAuth = a.auth !== "" && a.auth === b.auth
|
|
122
|
-
const sameTax = a.taxonomy !== "" && a.taxonomy === b.taxonomy
|
|
123
|
-
|
|
124
|
-
if (sameAuth) {
|
|
125
|
-
collideSameAuth++
|
|
126
|
-
} else if (!sameTax) {
|
|
127
|
-
collideDistinct++
|
|
128
|
-
}
|
|
129
|
-
} else if (sim >= WEAK_SIMILARITY_MIN) {
|
|
130
|
-
mid++
|
|
131
|
-
} else {
|
|
132
|
-
separable++
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// The irreducible false-merge rate among co-located distinct pairs is collide/pairs.
|
|
137
|
-
// Report the collision rate directly with a precision-ceiling band: optimistic counts
|
|
138
|
-
// only `collide`, and conservative counts `collide` plus half of `mid`.
|
|
139
|
-
// Recall is not binding here, so the F1 ceiling tracks the precision ceiling.
|
|
140
|
-
const pct = formatPercent
|
|
141
|
-
|
|
142
|
-
const lines: string[] = [
|
|
143
|
-
`# #625 — dedup ceiling: the irreducible over-merge of co-located providers`,
|
|
144
|
-
"",
|
|
145
|
-
`_Generated by \`registry/tools/dedup-ceiling.ts\`. ${STATE}, ${kept} type-2 (org) providers ` +
|
|
146
|
-
`(cap ${CAP}), geocode-free: "same address" = the matcher's \`addressFrequencyKey\`; "same name" = ` +
|
|
147
|
-
`normalized token Jaccard over the legal business name (corporate suffixes + articles stripped, domain ` +
|
|
148
|
-
`words kept). NPI is the distinctness truth (different NPI = different provider). τ = ${TAU}._`,
|
|
149
|
-
"",
|
|
150
|
-
`## Co-location prevalence`,
|
|
151
|
-
"",
|
|
152
|
-
`- **${sharedAddresses}** addresses host ≥2 distinct NPIs (${pct(sharedAddresses, byAddr.size)} of ${byAddr.size} addresses).`,
|
|
153
|
-
`- **${providersAtSharedAddr}** providers sit at a shared address (${pct(providersAtSharedAddr, kept)} of ${kept}).`,
|
|
154
|
-
`- **${pairs}** co-located distinct-NPI pairs (the over-merge population)${pairs >= PAIR_BUDGET ? ` — capped at the ${PAIR_BUDGET} pair budget` : ""}.`,
|
|
155
|
-
"",
|
|
156
|
-
`## Name separability of co-located distinct providers`,
|
|
157
|
-
"",
|
|
158
|
-
`| org-name Jaccard | pairs | share | meaning |`,
|
|
159
|
-
`|---|---:|---:|---|`,
|
|
160
|
-
`| ≥ ${TAU} (collision) | ${collide} | ${pct(collide, pairs)} | ~identical names → **irreducible over-merge** |`,
|
|
161
|
-
`| ${0.3}–${TAU} | ${mid} | ${pct(mid, pairs)} | partial — separable with a good model |`,
|
|
162
|
-
`| < 0.3 | ${separable} | ${pct(separable, pairs)} | clearly different names → separable |`,
|
|
163
|
-
"",
|
|
164
|
-
`Of the ${collide} collision pairs, **${collideSharePhone}** (${pct(collideSharePhone, collide)}) also share a phone — ` +
|
|
165
|
-
`so phone (a shared institutional switchboard) does NOT separate them either. If anything it over-links. This is ` +
|
|
166
|
-
`why the benchmark found phone an unreliable secondary identifier.`,
|
|
167
|
-
"",
|
|
168
|
-
`## Splitting the collisions: NPI over-segmentation vs genuinely distinct providers`,
|
|
169
|
-
"",
|
|
170
|
-
`A collision (same address, ~same name, often same phone) with DIFFERENT NPIs is usually one organization holding ` +
|
|
171
|
-
`multiple NPIs (subparts / departments) — where merging is **correct** and NPI-as-truth is **over-segmenting**, ` +
|
|
172
|
-
`not a model error. NPPES's own fields separate the two cases:`,
|
|
173
|
-
"",
|
|
174
|
-
`| collision pair is… | pairs | share of collisions | merging it is… |`,
|
|
175
|
-
`|---|---:|---:|---|`,
|
|
176
|
-
`| same authorized official | ${collideSameAuth} | ${pct(collideSameAuth, collide)} | **correct** — one org, many NPIs (NPI over-segments) |`,
|
|
177
|
-
`| different official AND different specialty | ${collideDistinct} | ${pct(collideDistinct, collide)} | a **genuine** distinct co-located provider — true over-merge |`,
|
|
178
|
-
`| (remainder: different official, same specialty) | ${collide - collideSameAuth - collideDistinct} | ${pct(collide - collideSameAuth - collideDistinct, collide)} | ambiguous — needs adjudication |`,
|
|
179
|
-
"",
|
|
180
|
-
`## The ceiling`,
|
|
181
|
-
"",
|
|
182
|
-
`The raw collision rate is **${pct(collide, pairs)}** of co-located distinct-NPI pairs — but only **${pct(collideDistinct, pairs)}** ` +
|
|
183
|
-
`of co-located pairs are *genuinely* distinct providers indistinguishable by name (different official + specialty). ` +
|
|
184
|
-
`Most collisions are **NPI over-segmentation** (${pct(collideSameAuth, collide)} share an authorized official), where ` +
|
|
185
|
-
`a merge is correct and NPI-truth penalizes it wrongly.`,
|
|
186
|
-
"",
|
|
187
|
-
`**This is the answer to "how good is good enough," and it has two parts:**`,
|
|
188
|
-
`1. Measured against **NPI-as-truth**, F1 is capped well below 0.85 — ~${pct(collide, pairs)} of co-located pairs are ` +
|
|
189
|
-
`unseparable, and NPI-truth scores most of them as errors even though merging is correct. The round **0.85 target ` +
|
|
190
|
-
`is unreachable under this yardstick and should be dropped.**`,
|
|
191
|
-
`2. The *real* irreducible over-merge — genuinely distinct co-located providers with identical names — is only ` +
|
|
192
|
-
`~**${pct(collideDistinct, pairs)}** of the co-located population. Against an **entity-level truth** (subpart-aware), ` +
|
|
193
|
-
`the achievable ceiling is much higher. But that ceiling can only be MEASURED with an entity-level / adjudicated ` +
|
|
194
|
-
`gold set — NPI-truth alone can't tell a correct subpart-merge from a true over-merge. **This is why the gold set ` +
|
|
195
|
-
`(the "second comparison") is necessary, not optional.**`,
|
|
196
|
-
"",
|
|
197
|
-
`Recommendation: drop 0.85. Set the bar against a subpart-aware / adjudicated entity truth, report NPI-level AND ` +
|
|
198
|
-
`entity-level side by side, and target "separate the ~${pct(collideDistinct, pairs)} genuinely-distinct co-located ` +
|
|
199
|
-
`pairs the GBT can still reach" rather than a round F1. The GBT's corroboration-feature work (#625 revised) ` +
|
|
200
|
-
`attacks exactly that separable subset.`,
|
|
201
|
-
"",
|
|
202
|
-
`## Caveats`,
|
|
203
|
-
"",
|
|
204
|
-
`- **Geocode-free + exact address key.** "Co-located" here is an exact normalized-address match. A geocoded key would ` +
|
|
205
|
-
`add near-but-not-exact neighbors (suite splits, slightly different formatting), which can only RAISE the ` +
|
|
206
|
-
`collision count. So this is a LOWER bound on the irreducible over-merge.`,
|
|
207
|
-
`- **Recall side under-measured.** NPPES same-NPI records almost always share an address or the org name, so the ` +
|
|
208
|
-
`recall floor looks ~1.0 here. Real-world feeds with distant + name-drifted same-entity records would lower it. ` +
|
|
209
|
-
`The F1 ceiling reported tracks the PRECISION constraint, which is the binding one for the over-merge problem.`,
|
|
210
|
-
`- **Token-Jaccard ≠ the model's name comparison.** It is a proxy for separability. The GBT uses the FS agreement ` +
|
|
211
|
-
`levels. The collision SET (sim ≥ τ + shared phone) is robust to the exact similarity metric.`,
|
|
212
|
-
"",
|
|
213
|
-
]
|
|
214
|
-
|
|
215
|
-
const md = lines.join("\n")
|
|
216
|
-
|
|
217
|
-
console.log(md)
|
|
218
|
-
|
|
219
|
-
if (OUT_MD) {
|
|
220
|
-
await writeLocalFile(md, OUT_MD)
|
|
221
|
-
report?.(`[written] ${OUT_MD}`)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return { markdown: md, pairs, collide }
|
|
225
|
-
}
|