@mailwoman/registry 9.2.0 → 9.4.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 +1 -1
- package/{address-key.ts → lib/address-key.ts} +1 -1
- package/{geocode-handler.ts → lib/geocode-handler.ts} +7 -7
- package/{geojson.ts → lib/geojson.ts} +9 -4
- package/{index.ts → lib/index.ts} +10 -10
- package/{ingest.ts → lib/ingest.ts} +75 -68
- package/{learned-scorer.ts → lib/learned-scorer.ts} +1 -1
- package/{map-html.ts → lib/map-html.ts} +7 -13
- package/{reconcile.ts → lib/reconcile.ts} +7 -23
- package/{resolve.ts → lib/resolve.ts} +25 -12
- package/{tools → lib/tools}/coverage-reconciliation.ts +12 -14
- package/{tools → lib/tools}/cross-dataset-correlation.ts +60 -137
- package/{tools → lib/tools}/cross-source-threshold-sweep.ts +20 -31
- package/{tools → lib/tools}/dedup-ceiling.ts +33 -144
- package/{tools → lib/tools}/eval-geocoder.ts +9 -10
- package/{tools → lib/tools}/geocoder-namesake-probe.ts +5 -12
- package/{tools → lib/tools}/geocoder-vs-provided-coords.ts +9 -10
- package/lib/tools/gold-set-sample.ts +141 -0
- package/lib/tools/index.ts +31 -0
- package/{tools → lib/tools}/learned-scorer-clustering-eval.ts +68 -257
- package/{tools → lib/tools}/learned-scorer-crossstate-eval.ts +60 -243
- package/{tools → lib/tools}/learned-scorer-eval.ts +63 -257
- package/{tools → lib/tools}/matcher-scale.ts +4 -5
- package/lib/tools/nppes/org-name.ts +23 -0
- package/{tools → lib/tools}/nppes/overmerge-packet.ts +5 -7
- package/{tools → lib/tools}/nppes/report.ts +22 -25
- package/{tools → lib/tools}/nppes/sample.ts +80 -32
- package/{tools/nppes/levers.ts → lib/tools/nppes/settings.ts} +10 -10
- package/{tools → lib/tools}/nppes/truth-grains.ts +4 -44
- package/{tools → lib/tools}/nppes-dedup-benchmark.ts +42 -38
- package/lib/tools/shared.ts +761 -0
- package/lib/tools/train-cross-gbt.ts +209 -0
- package/{tools → lib/tools}/train-gbt.ts +35 -154
- package/lib/tools/train-org-cross-gbt.ts +179 -0
- package/{tools → lib/tools}/txhhsc-to-oarow.ts +9 -27
- package/lib/tools/viz/browser.ts +50 -0
- package/{tools → lib/tools}/viz/cross-dataset-map.ts +7 -8
- package/{tools → lib/tools}/viz/geocode-first-surface.ts +10 -8
- package/{tools → lib/tools}/viz/render-map.ts +10 -23
- package/lib/tools/viz/render.ts +98 -0
- package/{tools → lib/tools}/viz/source-provenance-map.ts +8 -10
- package/{tools → lib/tools}/viz/yardstick-figure.ts +6 -5
- package/out/address-key.d.ts +1 -1
- package/out/address-key.d.ts.map +1 -1
- package/out/address-key.js.map +1 -1
- package/out/geocode-handler.d.ts +6 -6
- package/out/geocode-handler.d.ts.map +1 -1
- package/out/geocode-handler.js +6 -6
- package/out/geocode-handler.js.map +1 -1
- package/out/geojson.d.ts +7 -2
- package/out/geojson.d.ts.map +1 -1
- package/out/geojson.js +5 -3
- package/out/geojson.js.map +1 -1
- package/out/index.d.ts +10 -10
- package/out/index.d.ts.map +1 -1
- package/out/index.js +10 -10
- package/out/index.js.map +1 -1
- package/out/ingest.d.ts +64 -46
- package/out/ingest.d.ts.map +1 -1
- package/out/ingest.js +31 -45
- package/out/ingest.js.map +1 -1
- package/out/learned-scorer.d.ts +1 -1
- package/out/learned-scorer.d.ts.map +1 -1
- package/out/learned-scorer.js.map +1 -1
- package/out/map-html.d.ts +3 -3
- package/out/map-html.d.ts.map +1 -1
- package/out/map-html.js +6 -11
- package/out/map-html.js.map +1 -1
- package/out/models/crosssource-gbt-en-us.d.ts.map +1 -1
- package/out/models/crosssource-gbt-en-us.js.map +1 -1
- package/out/models/dedup-gbt-en-us.d.ts.map +1 -1
- package/out/models/dedup-gbt-en-us.js.map +1 -1
- package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -1
- package/out/models/org-crosssource-gbt-en-us.js.map +1 -1
- package/out/reconcile.d.ts +6 -1
- package/out/reconcile.d.ts.map +1 -1
- package/out/reconcile.js +5 -20
- package/out/reconcile.js.map +1 -1
- package/out/resolve.d.ts +19 -7
- package/out/resolve.d.ts.map +1 -1
- package/out/resolve.js +16 -5
- package/out/resolve.js.map +1 -1
- package/out/tools/coverage-reconciliation.d.ts +1 -1
- package/out/tools/coverage-reconciliation.d.ts.map +1 -1
- package/out/tools/coverage-reconciliation.js +11 -11
- package/out/tools/coverage-reconciliation.js.map +1 -1
- package/out/tools/cross-dataset-correlation.d.ts +4 -4
- package/out/tools/cross-dataset-correlation.d.ts.map +1 -1
- package/out/tools/cross-dataset-correlation.js +57 -109
- package/out/tools/cross-dataset-correlation.js.map +1 -1
- package/out/tools/cross-source-threshold-sweep.d.ts +2 -2
- package/out/tools/cross-source-threshold-sweep.d.ts.map +1 -1
- package/out/tools/cross-source-threshold-sweep.js +19 -27
- package/out/tools/cross-source-threshold-sweep.js.map +1 -1
- package/out/tools/dedup-ceiling.d.ts.map +1 -1
- package/out/tools/dedup-ceiling.js +36 -117
- package/out/tools/dedup-ceiling.js.map +1 -1
- package/out/tools/eval-geocoder.d.ts +8 -12
- package/out/tools/eval-geocoder.d.ts.map +1 -1
- package/out/tools/eval-geocoder.js +2 -2
- package/out/tools/eval-geocoder.js.map +1 -1
- package/out/tools/geocoder-namesake-probe.d.ts +2 -2
- package/out/tools/geocoder-namesake-probe.d.ts.map +1 -1
- package/out/tools/geocoder-namesake-probe.js +4 -8
- package/out/tools/geocoder-namesake-probe.js.map +1 -1
- package/out/tools/geocoder-vs-provided-coords.d.ts +1 -1
- package/out/tools/geocoder-vs-provided-coords.d.ts.map +1 -1
- package/out/tools/geocoder-vs-provided-coords.js +8 -7
- package/out/tools/geocoder-vs-provided-coords.js.map +1 -1
- package/out/tools/gold-set-sample.d.ts +5 -5
- package/out/tools/gold-set-sample.d.ts.map +1 -1
- package/out/tools/gold-set-sample.js +37 -122
- package/out/tools/gold-set-sample.js.map +1 -1
- package/out/tools/index.d.ts +23 -23
- package/out/tools/index.d.ts.map +1 -1
- package/out/tools/index.js +23 -23
- package/out/tools/index.js.map +1 -1
- package/out/tools/learned-scorer-clustering-eval.d.ts +1 -1
- package/out/tools/learned-scorer-clustering-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-clustering-eval.js +36 -169
- package/out/tools/learned-scorer-clustering-eval.js.map +1 -1
- package/out/tools/learned-scorer-crossstate-eval.d.ts +5 -5
- package/out/tools/learned-scorer-crossstate-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-crossstate-eval.js +44 -166
- package/out/tools/learned-scorer-crossstate-eval.js.map +1 -1
- package/out/tools/learned-scorer-eval.d.ts +1 -1
- package/out/tools/learned-scorer-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-eval.js +38 -168
- package/out/tools/learned-scorer-eval.js.map +1 -1
- package/out/tools/matcher-scale.d.ts.map +1 -1
- package/out/tools/matcher-scale.js +4 -4
- package/out/tools/matcher-scale.js.map +1 -1
- package/out/tools/nppes/org-name.d.ts +2 -5
- package/out/tools/nppes/org-name.d.ts.map +1 -1
- package/out/tools/nppes/org-name.js +1 -30
- package/out/tools/nppes/org-name.js.map +1 -1
- package/out/tools/nppes/overmerge-packet.d.ts +3 -3
- package/out/tools/nppes/overmerge-packet.d.ts.map +1 -1
- package/out/tools/nppes/overmerge-packet.js +3 -3
- package/out/tools/nppes/overmerge-packet.js.map +1 -1
- package/out/tools/nppes/report.d.ts +5 -5
- package/out/tools/nppes/report.d.ts.map +1 -1
- package/out/tools/nppes/report.js +17 -19
- package/out/tools/nppes/report.js.map +1 -1
- package/out/tools/nppes/sample.d.ts +32 -6
- package/out/tools/nppes/sample.d.ts.map +1 -1
- package/out/tools/nppes/sample.js +44 -26
- package/out/tools/nppes/sample.js.map +1 -1
- package/out/tools/nppes/scoring.d.ts.map +1 -1
- package/out/tools/nppes/scoring.js.map +1 -1
- package/out/tools/nppes/{levers.d.ts → settings.d.ts} +8 -8
- package/out/tools/nppes/settings.d.ts.map +1 -0
- package/out/tools/nppes/{levers.js → settings.js} +8 -8
- package/out/tools/nppes/settings.js.map +1 -0
- package/out/tools/nppes/truth-grains.d.ts +2 -2
- package/out/tools/nppes/truth-grains.d.ts.map +1 -1
- package/out/tools/nppes/truth-grains.js +4 -29
- package/out/tools/nppes/truth-grains.js.map +1 -1
- package/out/tools/nppes-dedup-benchmark.d.ts +4 -4
- package/out/tools/nppes-dedup-benchmark.d.ts.map +1 -1
- package/out/tools/nppes-dedup-benchmark.js +40 -34
- package/out/tools/nppes-dedup-benchmark.js.map +1 -1
- package/out/tools/shared.d.ts +243 -7
- package/out/tools/shared.d.ts.map +1 -1
- package/out/tools/shared.js +348 -18
- package/out/tools/shared.js.map +1 -1
- package/out/tools/train-cross-gbt.d.ts +7 -7
- package/out/tools/train-cross-gbt.d.ts.map +1 -1
- package/out/tools/train-cross-gbt.js +47 -145
- package/out/tools/train-cross-gbt.js.map +1 -1
- package/out/tools/train-gbt.d.ts +7 -7
- package/out/tools/train-gbt.d.ts.map +1 -1
- package/out/tools/train-gbt.js +31 -111
- package/out/tools/train-gbt.js.map +1 -1
- package/out/tools/train-org-cross-gbt.d.ts +7 -5
- package/out/tools/train-org-cross-gbt.d.ts.map +1 -1
- package/out/tools/train-org-cross-gbt.js +45 -141
- package/out/tools/train-org-cross-gbt.js.map +1 -1
- package/out/tools/txhhsc-to-oarow.d.ts +2 -2
- package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
- package/out/tools/txhhsc-to-oarow.js +8 -22
- package/out/tools/txhhsc-to-oarow.js.map +1 -1
- package/out/tools/viz/browser.d.ts +34 -0
- package/out/tools/viz/browser.d.ts.map +1 -0
- package/out/tools/viz/browser.js +33 -0
- package/out/tools/viz/browser.js.map +1 -0
- package/out/tools/viz/cross-dataset-map.d.ts +2 -2
- package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
- package/out/tools/viz/cross-dataset-map.js +6 -6
- package/out/tools/viz/cross-dataset-map.js.map +1 -1
- package/out/tools/viz/geocode-first-surface.d.ts +4 -3
- package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
- package/out/tools/viz/geocode-first-surface.js +7 -5
- package/out/tools/viz/geocode-first-surface.js.map +1 -1
- package/out/tools/viz/render-map.d.ts +3 -6
- package/out/tools/viz/render-map.d.ts.map +1 -1
- package/out/tools/viz/render-map.js +9 -19
- package/out/tools/viz/render-map.js.map +1 -1
- package/out/tools/viz/render.d.ts +4 -9
- package/out/tools/viz/render.d.ts.map +1 -1
- package/out/tools/viz/render.js +24 -39
- package/out/tools/viz/render.js.map +1 -1
- package/out/tools/viz/source-provenance-map.d.ts +2 -2
- package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
- package/out/tools/viz/source-provenance-map.js +6 -7
- package/out/tools/viz/source-provenance-map.js.map +1 -1
- package/out/tools/viz/yardstick-figure.d.ts +2 -2
- package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
- package/out/tools/viz/yardstick-figure.js +5 -4
- package/out/tools/viz/yardstick-figure.js.map +1 -1
- package/out/types.d.ts.map +1 -1
- package/out/types.js.map +1 -1
- package/package.json +115 -15
- package/out/tools/nppes/levers.d.ts.map +0 -1
- package/out/tools/nppes/levers.js.map +0 -1
- package/tools/gold-set-sample.ts +0 -254
- package/tools/index.ts +0 -31
- package/tools/nppes/org-name.ts +0 -56
- package/tools/shared.ts +0 -162
- package/tools/train-cross-gbt.ts +0 -359
- package/tools/train-org-cross-gbt.ts +0 -330
- package/tools/viz/render.ts +0 -113
- /package/{models → lib/models}/crosssource-gbt-en-us.ts +0 -0
- /package/{models → lib/models}/dedup-gbt-en-us.ts +0 -0
- /package/{models → lib/models}/org-crosssource-gbt-en-us.ts +0 -0
- /package/{tools → lib/tools}/nppes/scoring.ts +0 -0
- /package/{types.ts → lib/types.ts} +0 -0
|
@@ -13,31 +13,28 @@
|
|
|
13
13
|
* to canonical entities, and report the entities whose members span ≥2 sources — those are the
|
|
14
14
|
* cross-dataset links. We surface the correlation; interpretation is the consumer's.
|
|
15
15
|
*
|
|
16
|
-
* Tractable
|
|
16
|
+
* Tractable slice: TX-scoped, capped per source. Streams the 4.8 GB NPPES registry via `streamRows`.
|
|
17
17
|
*
|
|
18
18
|
* Run: `mailwoman registry scorer-eval cross-dataset [--cap 300] [--wof <admin.db>]
|
|
19
19
|
* [--data-root <dir>] [--out-md docs/articles/evals/matcher-dedup/<date>-...md]`
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import {
|
|
23
|
-
|
|
22
|
+
import { dataRootPath } from "@mailwoman/core/data-root"
|
|
23
|
+
import { writeLocalFile, writeLocalJSONFile } from "@mailwoman/core/fs/writers"
|
|
24
24
|
import { isPresent } from "@mailwoman/core/objects"
|
|
25
|
-
import { dataRootPath } from "@mailwoman/core/utils"
|
|
26
25
|
|
|
27
26
|
import {
|
|
28
27
|
addressFrequencyKey,
|
|
29
28
|
ingestRows,
|
|
29
|
+
repName,
|
|
30
30
|
resolveEntities,
|
|
31
31
|
streamRows,
|
|
32
32
|
toGeoJSON,
|
|
33
|
-
type ColumnMapping,
|
|
34
33
|
type GeocodeAddress,
|
|
35
|
-
type ResolvedEntity,
|
|
36
34
|
type SourceRecord,
|
|
37
35
|
} from "#index"
|
|
38
|
-
|
|
39
|
-
import type
|
|
40
|
-
import { norm } from "./shared.ts"
|
|
36
|
+
import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
|
|
37
|
+
import { buildSpecs, norm, pct, stateOption, type SourceSpec } from "#tools/shared"
|
|
41
38
|
|
|
42
39
|
/**
|
|
43
40
|
* Distinct sources an entity needs to count toward the triple-corroborated tally.
|
|
@@ -65,9 +62,9 @@ export interface CrossDatasetCorrelationOptions {
|
|
|
65
62
|
*/
|
|
66
63
|
state?: string
|
|
67
64
|
/**
|
|
68
|
-
* The inverse-address-frequency
|
|
65
|
+
* The inverse-address-frequency change is a CORPUS statistic — it can't be synthesized from the geocoded sample. By
|
|
69
66
|
* default we scan the FULL files (cheap, parse-free) for an in-state corpus-wide frequency table and feed it to the
|
|
70
|
-
* matcher, so the proven #617
|
|
67
|
+
* matcher, so the proven #617 change actually bites on a sub-sampled run. The scan adds a full pass over the 4.8 GB
|
|
71
68
|
* NPPES file (~5 min); `--no-corpus-frequency` skips it and falls back to resolveEntities' zero-config input-scoped
|
|
72
69
|
* default (#86). Default true.
|
|
73
70
|
*/
|
|
@@ -83,8 +80,9 @@ export interface CrossDatasetCorrelationOptions {
|
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
/**
|
|
86
|
-
* Compose a row's address the
|
|
87
|
-
*
|
|
83
|
+
* Compose a row's address for the corpus-wide frequency table. {@link ingestRows} joins the mapped address columns with
|
|
84
|
+
* `", "` (the #694 flip) while this join uses a space — the two agree once `addressFrequencyKey` folds punctuation to
|
|
85
|
+
* spaces, so a frequency key built here matches the geocoded record's `address.raw`.
|
|
88
86
|
*/
|
|
89
87
|
function composeAddress(row: Record<string, string>, columns: string | string[] | undefined): string {
|
|
90
88
|
if (!columns) return ""
|
|
@@ -98,112 +96,46 @@ function composeAddress(row: Record<string, string>, columns: string | string[]
|
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
99
|
+
* FCC RHC funding commitments — TWO addressable entities per row (a Filing HCP and a Participating HCP), each exploded
|
|
100
|
+
* into its own record (the #618 B1 two-entity-per-row case). Composed after the shared {@link buildSpecs} trio, which
|
|
101
|
+
* this probe correlates against.
|
|
103
102
|
*/
|
|
104
|
-
|
|
105
|
-
source:
|
|
106
|
-
path:
|
|
107
|
-
mapping:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
inState: (row: Record<string, string>) => boolean
|
|
112
|
-
/**
|
|
113
|
-
* Optional: a row carries ≥1 addressable entity — yield each as its own row. Default identity.
|
|
114
|
-
*/
|
|
115
|
-
explode?: (row: Record<string, string>) => Record<string, string>[]
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const buildSpecs = (S: string, STATE: string): SourceSpec[] => [
|
|
119
|
-
{
|
|
120
|
-
// TX HHSC nursing facilities — facility name + physical address + a real coordinate.
|
|
121
|
-
source: "txhhsc-nursing",
|
|
122
|
-
path: `${S}/txhhsc_nursing-facilities_20260611.tsv`,
|
|
123
|
-
mapping: {
|
|
124
|
-
id: "Facility ID",
|
|
125
|
-
organization: "Facility Name",
|
|
126
|
-
address: ["Physical Address", "Physical Address CITY", "Physical Address State", "Physical Address Zipcode"],
|
|
127
|
-
phone: "Facility Phone Number",
|
|
128
|
-
source: "txhhsc-nursing",
|
|
129
|
-
},
|
|
130
|
-
inState: (r) => norm(r["Physical Address State"]).toUpperCase() === STATE,
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
// FCC Rural Health Care posted services — the funding/enrollment side; HCP name + site address.
|
|
134
|
-
source: "fcc-rhc",
|
|
135
|
-
path: `${S}/fcc-rhc_posted-services_form461-465_20260615.tsv`,
|
|
136
|
-
mapping: {
|
|
137
|
-
id: "HCP Number",
|
|
138
|
-
organization: "HCP Name",
|
|
139
|
-
address: ["Site Address Line 1", "Site City", "Site State", "Site ZIP Code"],
|
|
140
|
-
phone: "Contact Phone",
|
|
141
|
-
email: "Contact E-mail",
|
|
142
|
-
source: "fcc-rhc",
|
|
143
|
-
},
|
|
144
|
-
inState: (r) => norm(r["Site State"]).toUpperCase() === STATE,
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
// NPPES — organization NPIs (the eligibility side); legal business name + practice address.
|
|
148
|
-
source: "nppes",
|
|
149
|
-
path: `${S}/nppes_npi-registry_20260607.tsv`,
|
|
150
|
-
mapping: {
|
|
151
|
-
id: "NPI",
|
|
152
|
-
organization: "Provider Organization Name (Legal Business Name)",
|
|
153
|
-
address: [
|
|
154
|
-
"Provider First Line Business Practice Location Address",
|
|
155
|
-
"Provider Business Practice Location Address City Name",
|
|
156
|
-
"Provider Business Practice Location Address State Name",
|
|
157
|
-
"Provider Business Practice Location Address Postcode",
|
|
158
|
-
],
|
|
159
|
-
phone: "Provider Business Practice Location Address Telephone Number",
|
|
160
|
-
source: "nppes",
|
|
161
|
-
},
|
|
162
|
-
// Org-type NPIs in TX with a business name — the entities most likely to co-occur with facilities.
|
|
163
|
-
inState: (r) =>
|
|
164
|
-
norm(r["Provider Business Practice Location Address State Name"]).toUpperCase() === STATE &&
|
|
165
|
-
norm(r["Entity Type Code"]) === "2" &&
|
|
166
|
-
!!norm(r["Provider Organization Name (Legal Business Name)"]),
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
// FCC RHC funding commitments — TWO addressable entities per row (a Filing HCP and a Participating
|
|
170
|
-
// HCP). Explode each in-state HCP into its own record (the #618 B1 two-entity-per-row case).
|
|
103
|
+
const commitmentsSpec = (S: string, STATE: string): SourceSpec => ({
|
|
104
|
+
source: "fcc-rhc-commitments",
|
|
105
|
+
path: `${S}/fcc-rhc_commitments-disbursements_form462-466-466a_20260615.tsv`,
|
|
106
|
+
mapping: {
|
|
107
|
+
id: "hcpID",
|
|
108
|
+
organization: "hcpName",
|
|
109
|
+
address: ["hcpStreet", "hcpCity", "hcpState", "hcpZip"],
|
|
171
110
|
source: "fcc-rhc-commitments",
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
hcpName: norm(r[`${prefix} HCP Name`]),
|
|
192
|
-
hcpStreet: norm(r[`${prefix} HCP Street`]),
|
|
193
|
-
hcpCity: norm(r[`${prefix} HCP City`]),
|
|
194
|
-
hcpState: state,
|
|
195
|
-
hcpZip: norm(r[`${prefix} HCP Zip Code`]),
|
|
196
|
-
})
|
|
197
|
-
}
|
|
111
|
+
},
|
|
112
|
+
inState: (r) =>
|
|
113
|
+
norm(r["Filing HCP State"]).toUpperCase() === STATE || norm(r["Participating HCP State"]).toUpperCase() === STATE,
|
|
114
|
+
explode: (r) => {
|
|
115
|
+
const out: Record<string, string>[] = []
|
|
116
|
+
|
|
117
|
+
const add = (prefix: string, role: string): void => {
|
|
118
|
+
const id = norm(r[`${prefix} HCP`])
|
|
119
|
+
const state = norm(r[`${prefix} HCP State`]).toUpperCase()
|
|
120
|
+
|
|
121
|
+
if (id && state === STATE) {
|
|
122
|
+
out.push({
|
|
123
|
+
hcpID: `${role}-${id}`,
|
|
124
|
+
hcpName: norm(r[`${prefix} HCP Name`]),
|
|
125
|
+
hcpStreet: norm(r[`${prefix} HCP Street`]),
|
|
126
|
+
hcpCity: norm(r[`${prefix} HCP City`]),
|
|
127
|
+
hcpState: state,
|
|
128
|
+
hcpZip: norm(r[`${prefix} HCP Zip Code`]),
|
|
129
|
+
})
|
|
198
130
|
}
|
|
131
|
+
}
|
|
199
132
|
|
|
200
|
-
|
|
201
|
-
|
|
133
|
+
add("Filing", "filing")
|
|
134
|
+
add("Participating", "participating")
|
|
202
135
|
|
|
203
|
-
|
|
204
|
-
},
|
|
136
|
+
return out
|
|
205
137
|
},
|
|
206
|
-
|
|
138
|
+
})
|
|
207
139
|
|
|
208
140
|
/**
|
|
209
141
|
* Cross-dataset correlation (#618) — see the module doc. Emits the markdown report to stdout.
|
|
@@ -214,16 +146,16 @@ export async function crossDatasetCorrelation(
|
|
|
214
146
|
): Promise<{ markdown: string }> {
|
|
215
147
|
const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
|
|
216
148
|
const CAP = options.cap ?? 300 // rows kept per source for geocoding (state-scoped)
|
|
217
|
-
const STATE = (options
|
|
149
|
+
const STATE = stateOption(options)
|
|
218
150
|
const OUT_MD = options.outMd || ""
|
|
219
151
|
const OUT_GEOJSON = options.outGeojson || "" // the reconciliation artifact (FeatureCollection, QGIS-ready)
|
|
220
152
|
const CORPUS_FREQ = options.corpusFrequency ?? true
|
|
221
|
-
const SPECS = buildSpecs(`${SOURCES}`, STATE)
|
|
153
|
+
const SPECS = [...buildSpecs(`${SOURCES}`, STATE), commitmentsSpec(`${SOURCES}`, STATE)]
|
|
222
154
|
|
|
223
155
|
// --- Phase A: stream each source, TX-filter, explode → keep the first CAP rows for geocoding AND
|
|
224
156
|
// (when --corpus-frequency, the default) count EVERY in-state address into a corpus-wide table. The
|
|
225
157
|
// sample is the matched set; the frequency table reflects the full TX population, so the proven
|
|
226
|
-
// inverse-frequency
|
|
158
|
+
// inverse-frequency change down-weights a genuinely-crowded shared campus even when it appears once in
|
|
227
159
|
// the geocoded sample. ---
|
|
228
160
|
const rawBySource = new Map<string, Record<string, string>[]>()
|
|
229
161
|
const addrCounts = new Map<string, number>()
|
|
@@ -262,7 +194,7 @@ export async function crossDatasetCorrelation(
|
|
|
262
194
|
report?.(` ${spec.source}: ${kept.length} sampled`)
|
|
263
195
|
}
|
|
264
196
|
|
|
265
|
-
// The in-state corpus-wide address-frequency table (the #617
|
|
197
|
+
// The in-state corpus-wide address-frequency table (the #617 change, fed to the matcher below).
|
|
266
198
|
const addressFrequency = CORPUS_FREQ
|
|
267
199
|
? {
|
|
268
200
|
total: addrTotal,
|
|
@@ -282,9 +214,9 @@ export async function crossDatasetCorrelation(
|
|
|
282
214
|
let geo = 0
|
|
283
215
|
let total = 0
|
|
284
216
|
|
|
285
|
-
// Count placements at the
|
|
286
|
-
const
|
|
287
|
-
const g = await geocoder.
|
|
217
|
+
// Count placements at the boundary (parity with the retired in-script counter).
|
|
218
|
+
const geocodeForIngest: GeocodeAddress = async (raw) => {
|
|
219
|
+
const g = await geocoder.geocodeAddress(raw)
|
|
288
220
|
|
|
289
221
|
total++
|
|
290
222
|
|
|
@@ -301,11 +233,11 @@ export async function crossDatasetCorrelation(
|
|
|
301
233
|
|
|
302
234
|
for (const spec of SPECS) {
|
|
303
235
|
const rows = rawBySource.get(spec.source)!
|
|
304
|
-
// Per-source geocode-rate snapshot (#694 diagnostic): the
|
|
236
|
+
// Per-source geocode-rate snapshot (#694 diagnostic): the boundary counters are global, so delta
|
|
305
237
|
// them across each source to see WHERE nulls concentrate in the aggregate run.
|
|
306
238
|
const g0 = geo
|
|
307
239
|
const t0 = total
|
|
308
|
-
const recs = await ingestRows(rows, spec.mapping, { geocodeAddress:
|
|
240
|
+
const recs = await ingestRows(rows, spec.mapping, { geocodeAddress: geocodeForIngest })
|
|
309
241
|
const dg = geo - g0
|
|
310
242
|
const dt = total - t0
|
|
311
243
|
report?.(` ${spec.source}: geocoded ${dg}/${dt} (${dt ? ((100 * dg) / dt).toFixed(1) : "0"}%)`)
|
|
@@ -318,10 +250,10 @@ export async function crossDatasetCorrelation(
|
|
|
318
250
|
records.push(...recs)
|
|
319
251
|
}
|
|
320
252
|
|
|
321
|
-
geocoder.
|
|
253
|
+
geocoder[Symbol.dispose]()
|
|
322
254
|
report?.(` ${records.length} records; geocoded ${geo}/${total} (${((100 * geo) / total).toFixed(1)}%)`)
|
|
323
255
|
|
|
324
|
-
// --- Phase D: resolve to canonical entities. The proven
|
|
256
|
+
// --- Phase D: resolve to canonical entities. The proven changes are default-on (#86): collapsed
|
|
325
257
|
// spatial (A1) + inverse-address-frequency. We feed the corpus-wide table when we built one; otherwise
|
|
326
258
|
// resolveEntities auto-computes the input-scoped default. ---
|
|
327
259
|
report?.("[D] resolving across sources…")
|
|
@@ -360,22 +292,13 @@ export async function crossDatasetCorrelation(
|
|
|
360
292
|
}
|
|
361
293
|
}
|
|
362
294
|
|
|
363
|
-
const repName = (e: ResolvedEntity) =>
|
|
364
|
-
e.representative.organization?.canonical ??
|
|
365
|
-
[e.representative.name?.given, e.representative.name?.family].filter(isPresent).join(" ") ??
|
|
366
|
-
e.representative.id
|
|
367
|
-
|
|
368
295
|
// --- Report. ---
|
|
369
|
-
// NOTE(phase4): local pct keeps the fraction-in/no-%-suffix shape — not core formatPercent's
|
|
370
|
-
// numerator/denominator contract (call sites append their own "%").
|
|
371
|
-
const pct = (x: number) => (100 * x).toFixed(1)
|
|
372
|
-
|
|
373
296
|
const lines: string[] = [
|
|
374
297
|
`# Cross-dataset correlation (#618 / #87 real-data run)`,
|
|
375
298
|
"",
|
|
376
299
|
`_Generated by \`mailwoman registry scorer-eval cross-dataset\`. ${STATE}-scoped, ≤${CAP} rows per ` +
|
|
377
300
|
`source geocoded, resolved BLIND across sources (geo-first block → Fellegi-Sunter + EM → cluster) with the ` +
|
|
378
|
-
`proven
|
|
301
|
+
`proven changes default-on (#86). The sources share no key; an entity spanning ≥2 sources is a cross-dataset ` +
|
|
379
302
|
`link we surface for review — interpretation is the consumer's._`,
|
|
380
303
|
"",
|
|
381
304
|
`## Sources`,
|
|
@@ -407,7 +330,7 @@ export async function crossDatasetCorrelation(
|
|
|
407
330
|
|
|
408
331
|
lines.push(
|
|
409
332
|
addressFrequency
|
|
410
|
-
? `Matched with the proven
|
|
333
|
+
? `Matched with the proven changes default-on (#86): collapsed spatial (A1) + inverse-address-frequency, fed ` +
|
|
411
334
|
`a corpus-wide table built from the full source files (**${addressFrequency.distinct.toLocaleString()}** distinct ` +
|
|
412
335
|
`addresses over **${addressFrequency.total.toLocaleString()}** ${STATE} rows — a crowded shared campus is ` +
|
|
413
336
|
`down-weighted as weak identity evidence).`
|
|
@@ -478,7 +401,7 @@ export async function crossDatasetCorrelation(
|
|
|
478
401
|
console.log(md)
|
|
479
402
|
|
|
480
403
|
if (OUT_MD) {
|
|
481
|
-
|
|
404
|
+
await writeLocalFile(md, OUT_MD)
|
|
482
405
|
report?.(`\n[written] ${OUT_MD}`)
|
|
483
406
|
}
|
|
484
407
|
|
|
@@ -487,7 +410,7 @@ export async function crossDatasetCorrelation(
|
|
|
487
410
|
// and the geocode tier. QGIS-ready; this is the operator-verifiable output of the matcher. ---
|
|
488
411
|
if (OUT_GEOJSON) {
|
|
489
412
|
const fc = toGeoJSON(entities)
|
|
490
|
-
|
|
413
|
+
await writeLocalJSONFile(fc, OUT_GEOJSON)
|
|
491
414
|
report?.(`[written] ${OUT_GEOJSON} — ${fc.features.length} entity features (${crossSource.length} cross-source)`)
|
|
492
415
|
}
|
|
493
416
|
|
|
@@ -21,15 +21,17 @@
|
|
|
21
21
|
* the threshold fix (option 1) works → ship a cross-source threshold. If matching FS link count
|
|
22
22
|
* only comes with collapsing total entities and a LOWER phone-corrob (junk over-merges), the
|
|
23
23
|
* threshold is insufficient by construction → FS stays pinned / a cross-objective retrain (#655
|
|
24
|
-
* option 2) is the only
|
|
24
|
+
* option 2) is the only change.
|
|
25
25
|
*
|
|
26
26
|
* Run: `mailwoman registry scorer-eval threshold-sweep [--cap 2000] [--state TX]
|
|
27
27
|
* [--wof <admin.db>] [--data-root <dir>] [--out-md <md>]`
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
import {
|
|
30
|
+
import { dataRootPath } from "@mailwoman/core/data-root"
|
|
31
|
+
import { writeLocalFile } from "@mailwoman/core/fs/writers"
|
|
32
|
+
import { pathToFileURL } from "@mailwoman/core/module/file-url"
|
|
33
|
+
import { formatPercent } from "@mailwoman/core/stats"
|
|
34
|
+
import { resolvePath } from "path-ts"
|
|
33
35
|
|
|
34
36
|
import {
|
|
35
37
|
addressFrequencyKey,
|
|
@@ -38,15 +40,15 @@ import {
|
|
|
38
40
|
DEDUP_GBT_META,
|
|
39
41
|
DEDUP_GBT_MODEL,
|
|
40
42
|
ingestRows,
|
|
43
|
+
normalizePhoneStrict,
|
|
41
44
|
resolveEntities,
|
|
42
45
|
streamRows,
|
|
43
46
|
type GeocodeAddress,
|
|
44
47
|
type ResolvedEntity,
|
|
45
48
|
type SourceRecord,
|
|
46
49
|
} from "#index"
|
|
47
|
-
|
|
48
|
-
import
|
|
49
|
-
import { buildSpecs } from "./shared.ts"
|
|
50
|
+
import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
|
|
51
|
+
import { buildSpecs, stateOption } from "#tools/shared"
|
|
50
52
|
|
|
51
53
|
/**
|
|
52
54
|
* Independent sources that must agree before a cluster counts as cross-source corroborated.
|
|
@@ -90,16 +92,6 @@ export interface CrossSourceThresholdSweepOptions {
|
|
|
90
92
|
const entitySources = (e: ResolvedEntity): Set<string> =>
|
|
91
93
|
new Set(e.records.map((r) => r.source).filter((s): s is string => !!s))
|
|
92
94
|
|
|
93
|
-
/**
|
|
94
|
-
* Last-10-digit phone key (drops formatting / country code).
|
|
95
|
-
*/
|
|
96
|
-
const normPhone = (p?: string | null): string => {
|
|
97
|
-
if (!p) return ""
|
|
98
|
-
const d = p.replaceAll(/\D/g, "")
|
|
99
|
-
|
|
100
|
-
return d.length >= 10 ? d.slice(-10) : ""
|
|
101
|
-
}
|
|
102
|
-
|
|
103
95
|
/**
|
|
104
96
|
* Label-free precision proxy: does this cross-source entity carry the SAME phone in records from two DIFFERENT sources?
|
|
105
97
|
* (Phone isn't the join key, so a match is independent corroboration of same-facility.) Entities where no two
|
|
@@ -110,7 +102,7 @@ function phoneEvidence(e: ResolvedEntity): "corroborated" | "contradicted" | "un
|
|
|
110
102
|
const bySource = new Map<string, Set<string>>()
|
|
111
103
|
|
|
112
104
|
for (const r of e.records) {
|
|
113
|
-
const ph =
|
|
105
|
+
const ph = normalizePhoneStrict(r.phone)
|
|
114
106
|
|
|
115
107
|
if (!ph) continue
|
|
116
108
|
const s = r.source ?? "?"
|
|
@@ -149,7 +141,7 @@ interface ArmMetrics {
|
|
|
149
141
|
phoneCheckable: number
|
|
150
142
|
}
|
|
151
143
|
|
|
152
|
-
function measure(label: string, threshold: number | null, entities: ResolvedEntity[]): ArmMetrics {
|
|
144
|
+
async function measure(label: string, threshold: number | null, entities: ResolvedEntity[]): Promise<ArmMetrics> {
|
|
153
145
|
let crossSource = 0
|
|
154
146
|
let tripleSource = 0
|
|
155
147
|
let phoneCorrob = 0
|
|
@@ -201,7 +193,7 @@ export async function crossSourceThresholdSweep(
|
|
|
201
193
|
): Promise<{ markdown: string }> {
|
|
202
194
|
const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
|
|
203
195
|
const CAP = options.cap ?? 2000
|
|
204
|
-
const STATE = (options
|
|
196
|
+
const STATE = stateOption(options)
|
|
205
197
|
const OUT_MD = options.outMd || ""
|
|
206
198
|
const CANDIDATE = options.candidate || ""
|
|
207
199
|
const SPECS = buildSpecs(`${SOURCES}`, STATE)
|
|
@@ -226,13 +218,13 @@ export async function crossSourceThresholdSweep(
|
|
|
226
218
|
|
|
227
219
|
report?.("[B] building the geocoder…")
|
|
228
220
|
const geocoder = await options.createGeocoder()
|
|
229
|
-
const
|
|
221
|
+
const geocodeForIngest: GeocodeAddress = geocoder.geocodeAddress
|
|
230
222
|
|
|
231
223
|
report?.("[C] geocoding + ingesting…")
|
|
232
224
|
const records: SourceRecord[] = []
|
|
233
225
|
|
|
234
226
|
for (const spec of SPECS) {
|
|
235
|
-
const recs = await ingestRows(rawBySource.get(spec.source)!, spec.mapping, { geocodeAddress:
|
|
227
|
+
const recs = await ingestRows(rawBySource.get(spec.source)!, spec.mapping, { geocodeAddress: geocodeForIngest })
|
|
236
228
|
|
|
237
229
|
for (const r of recs) {
|
|
238
230
|
r.id = `${spec.source}:${r.id}`
|
|
@@ -241,7 +233,7 @@ export async function crossSourceThresholdSweep(
|
|
|
241
233
|
records.push(...recs)
|
|
242
234
|
}
|
|
243
235
|
|
|
244
|
-
geocoder.
|
|
236
|
+
geocoder[Symbol.dispose]()
|
|
245
237
|
const geocoded = records.filter((r) => r.address?.geocode).length
|
|
246
238
|
report?.(` ${records.length} records; geocoded ${geocoded}`)
|
|
247
239
|
|
|
@@ -268,7 +260,7 @@ export async function crossSourceThresholdSweep(
|
|
|
268
260
|
// --- Arm 1: the FS baseline (the recall-correct baseline cross-source flows currently pin). ---
|
|
269
261
|
report?.("[D] resolving — FS baseline baseline…")
|
|
270
262
|
|
|
271
|
-
const fs = measure(
|
|
263
|
+
const fs = await measure(
|
|
272
264
|
"FS baseline",
|
|
273
265
|
0,
|
|
274
266
|
resolveEntities(records, { trainEM: true, collapseSpatial: true, addressFrequency, learnedScorer: false }).entities
|
|
@@ -289,7 +281,7 @@ export async function crossSourceThresholdSweep(
|
|
|
289
281
|
threshold: t,
|
|
290
282
|
})
|
|
291
283
|
|
|
292
|
-
gbtArms.push(measure(`GBT @ ${t.toFixed(2)}`, t, entities))
|
|
284
|
+
gbtArms.push(await measure(`GBT @ ${t.toFixed(2)}`, t, entities))
|
|
293
285
|
}
|
|
294
286
|
|
|
295
287
|
// --- Verdict. The threshold fix WORKS only if some GBT arm dominates FS — more (or equal)
|
|
@@ -301,9 +293,6 @@ export async function crossSourceThresholdSweep(
|
|
|
301
293
|
const candidateArms: ArmMetrics[] = []
|
|
302
294
|
|
|
303
295
|
if (CANDIDATE) {
|
|
304
|
-
const { pathToFileURL } = await import("node:url")
|
|
305
|
-
const { resolve: resolvePath } = await import("node:path")
|
|
306
|
-
|
|
307
296
|
const mod = (await import(pathToFileURL(resolvePath(CANDIDATE)).href)) as {
|
|
308
297
|
CROSS_SOURCE_GBT_MODEL?: typeof DEDUP_GBT_MODEL
|
|
309
298
|
CROSS_SOURCE_GBT_META?: { recommendedThreshold?: number }
|
|
@@ -322,7 +311,7 @@ export async function crossSourceThresholdSweep(
|
|
|
322
311
|
|
|
323
312
|
for (const t of [t0 - 1, t0, t0 + 1]) {
|
|
324
313
|
candidateArms.push(
|
|
325
|
-
measure(
|
|
314
|
+
await measure(
|
|
326
315
|
`cross-GBT @ ${t.toFixed(2)}`,
|
|
327
316
|
t,
|
|
328
317
|
resolveEntities(records, {
|
|
@@ -418,7 +407,7 @@ export async function crossSourceThresholdSweep(
|
|
|
418
407
|
`threshold to admit more only over-merges (the over-merge features REPLACE the FS weight, so true ` +
|
|
419
408
|
`cross-source pairs share a logit band with genuine over-merges). Threshold alone (option 1) is ` +
|
|
420
409
|
`**INSUFFICIENT** — FS stays pinned (correct + best-precision for this objective); a cross-objective ` +
|
|
421
|
-
`retrain (option 2),
|
|
410
|
+
`retrain (option 2), conditioned on cross-source labels, is the only change. See #655.`
|
|
422
411
|
)
|
|
423
412
|
} else {
|
|
424
413
|
lines.push(
|
|
@@ -436,7 +425,7 @@ export async function crossSourceThresholdSweep(
|
|
|
436
425
|
console.log(md)
|
|
437
426
|
|
|
438
427
|
if (OUT_MD) {
|
|
439
|
-
|
|
428
|
+
await writeLocalFile(md, OUT_MD)
|
|
440
429
|
report?.(`[written] ${OUT_MD}`)
|
|
441
430
|
}
|
|
442
431
|
|