@mailwoman/registry 9.1.0 → 9.3.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 +2 -2
- 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} +12 -6
- package/{index.ts → lib/index.ts} +10 -10
- package/{ingest.ts → lib/ingest.ts} +77 -69
- package/{learned-scorer.ts → lib/learned-scorer.ts} +1 -1
- package/{map-html.ts → lib/map-html.ts} +10 -16
- package/{reconcile.ts → lib/reconcile.ts} +9 -24
- package/{resolve.ts → lib/resolve.ts} +31 -13
- package/{tools → lib/tools}/coverage-reconciliation.ts +13 -15
- package/{tools → lib/tools}/cross-dataset-correlation.ts +64 -139
- package/{tools → lib/tools}/cross-source-threshold-sweep.ts +21 -32
- package/{tools → lib/tools}/dedup-ceiling.ts +33 -144
- package/{tools → lib/tools}/eval-geocoder.ts +10 -11
- package/{tools → lib/tools}/geocoder-namesake-probe.ts +5 -12
- package/{tools → lib/tools}/geocoder-vs-provided-coords.ts +12 -11
- 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 +71 -260
- package/{tools → lib/tools}/learned-scorer-crossstate-eval.ts +62 -245
- package/{tools → lib/tools}/learned-scorer-eval.ts +64 -263
- package/{tools → lib/tools}/matcher-scale.ts +5 -5
- package/lib/tools/nppes/org-name.ts +23 -0
- package/lib/tools/nppes/overmerge-packet.ts +94 -0
- package/lib/tools/nppes/report.ts +373 -0
- package/lib/tools/nppes/sample.ts +245 -0
- package/lib/tools/nppes/scoring.ts +114 -0
- package/lib/tools/nppes/settings.ts +102 -0
- package/lib/tools/nppes/truth-grains.ts +161 -0
- package/lib/tools/nppes-dedup-benchmark.ts +408 -0
- package/lib/tools/shared.ts +763 -0
- package/lib/tools/train-cross-gbt.ts +209 -0
- package/{tools → lib/tools}/train-gbt.ts +38 -156
- package/lib/tools/train-org-cross-gbt.ts +179 -0
- package/{tools → lib/tools}/txhhsc-to-oarow.ts +10 -28
- package/lib/tools/viz/browser.ts +50 -0
- package/{tools → lib/tools}/viz/cross-dataset-map.ts +16 -39
- package/{tools → lib/tools}/viz/geocode-first-surface.ts +13 -39
- 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 +20 -39
- package/{tools → lib/tools}/viz/yardstick-figure.ts +6 -5
- package/{types.ts → lib/types.ts} +10 -1
- 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 +8 -5
- 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 +33 -46
- 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 +4 -4
- 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 +7 -21
- 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 +20 -6
- 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 +12 -12
- 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 +60 -111
- 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 -118
- package/out/tools/dedup-ceiling.js.map +1 -1
- package/out/tools/eval-geocoder.d.ts +9 -13
- 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 +11 -9
- 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 -121
- package/out/tools/gold-set-sample.js.map +1 -1
- package/out/tools/index.d.ts +24 -29
- package/out/tools/index.d.ts.map +1 -1
- package/out/tools/index.js +24 -29
- 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 +35 -170
- 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 +37 -173
- 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 +5 -5
- package/out/tools/matcher-scale.js.map +1 -1
- package/out/tools/nppes/org-name.d.ts +21 -0
- package/out/tools/nppes/org-name.d.ts.map +1 -0
- package/out/tools/nppes/org-name.js +13 -0
- package/out/tools/nppes/org-name.js.map +1 -0
- package/out/tools/nppes/overmerge-packet.d.ts +39 -0
- package/out/tools/nppes/overmerge-packet.d.ts.map +1 -0
- package/out/tools/nppes/overmerge-packet.js +55 -0
- package/out/tools/nppes/overmerge-packet.js.map +1 -0
- package/out/tools/nppes/report.d.ts +93 -0
- package/out/tools/nppes/report.d.ts.map +1 -0
- package/out/tools/nppes/report.js +186 -0
- package/out/tools/nppes/report.js.map +1 -0
- package/out/tools/nppes/sample.d.ts +90 -0
- package/out/tools/nppes/sample.d.ts.map +1 -0
- package/out/tools/nppes/sample.js +131 -0
- package/out/tools/nppes/sample.js.map +1 -0
- package/out/tools/nppes/scoring.d.ts +36 -0
- package/out/tools/nppes/scoring.d.ts.map +1 -0
- package/out/tools/nppes/scoring.js +80 -0
- package/out/tools/nppes/scoring.js.map +1 -0
- package/out/tools/nppes/settings.d.ts +38 -0
- package/out/tools/nppes/settings.d.ts.map +1 -0
- package/out/tools/nppes/settings.js +79 -0
- package/out/tools/nppes/settings.js.map +1 -0
- package/out/tools/nppes/truth-grains.d.ts +50 -0
- package/out/tools/nppes/truth-grains.d.ts.map +1 -0
- package/out/tools/nppes/truth-grains.js +123 -0
- package/out/tools/nppes/truth-grains.js.map +1 -0
- package/out/tools/nppes-dedup-benchmark.d.ts +7 -3
- package/out/tools/nppes-dedup-benchmark.d.ts.map +1 -1
- package/out/tools/nppes-dedup-benchmark.js +106 -673
- package/out/tools/nppes-dedup-benchmark.js.map +1 -1
- package/out/tools/shared.d.ts +244 -7
- package/out/tools/shared.d.ts.map +1 -1
- package/out/tools/shared.js +353 -21
- 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 +9 -23
- 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 +4 -25
- package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
- package/out/tools/viz/cross-dataset-map.js +12 -33
- package/out/tools/viz/cross-dataset-map.js.map +1 -1
- package/out/tools/viz/geocode-first-surface.d.ts +6 -35
- package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
- package/out/tools/viz/geocode-first-surface.js +10 -37
- 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 +4 -24
- package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
- package/out/tools/viz/source-provenance-map.js +12 -32
- 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 +11 -1
- package/out/types.d.ts.map +1 -1
- package/out/types.js.map +1 -1
- package/package.json +180 -11
- package/tools/gold-set-sample.ts +0 -252
- package/tools/index.ts +0 -36
- package/tools/nppes-dedup-benchmark.ts +0 -1180
- package/tools/shared.ts +0 -160
- package/tools/train-cross-gbt.ts +0 -358
- package/tools/train-org-cross-gbt.ts +0 -329
- 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
|
@@ -30,16 +30,15 @@
|
|
|
30
30
|
* [--out-md <md>]`
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
import {
|
|
34
|
-
|
|
35
|
-
import {
|
|
33
|
+
import { dataRootPath } from "@mailwoman/core/data-root"
|
|
34
|
+
import { writeLocalFile } from "@mailwoman/core/fs/writers"
|
|
35
|
+
import { formatPercent } from "@mailwoman/core/stats"
|
|
36
36
|
import { jaccard } from "@mailwoman/match"
|
|
37
|
-
import { addressFrequencyKey, streamRows } from "@mailwoman/registry"
|
|
38
37
|
|
|
39
|
-
import {
|
|
38
|
+
import { colocatedDistinctPairs, scanColocatedProviders, stateOption, type ColocatedProvider } from "#tools/shared"
|
|
40
39
|
|
|
41
40
|
/**
|
|
42
|
-
* Similarity at or above which a pair is a near-miss worth inspecting rather than
|
|
41
|
+
* Similarity at or above which a pair is a near-miss worth inspecting rather than unrelated.
|
|
43
42
|
*/
|
|
44
43
|
const WEAK_SIMILARITY_MIN = 0.3
|
|
45
44
|
|
|
@@ -69,58 +68,6 @@ export interface DedupCeilingOptions {
|
|
|
69
68
|
outMd?: string
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
/**
|
|
73
|
-
* Strip only corporate-form tokens + articles — KEEP domain words (health, medical, center…), which carry the
|
|
74
|
-
* distinguishing signal between two co-located providers.
|
|
75
|
-
*/
|
|
76
|
-
const STOP = new Set([
|
|
77
|
-
"llc",
|
|
78
|
-
"inc",
|
|
79
|
-
"incorporated",
|
|
80
|
-
"corp",
|
|
81
|
-
"corporation",
|
|
82
|
-
"co",
|
|
83
|
-
"ltd",
|
|
84
|
-
"pllc",
|
|
85
|
-
"pc",
|
|
86
|
-
"pa",
|
|
87
|
-
"lp",
|
|
88
|
-
"llp",
|
|
89
|
-
"the",
|
|
90
|
-
"of",
|
|
91
|
-
"and",
|
|
92
|
-
])
|
|
93
|
-
|
|
94
|
-
function orgTokens(s: string): Set<string> {
|
|
95
|
-
return new Set(
|
|
96
|
-
s
|
|
97
|
-
.toLowerCase()
|
|
98
|
-
.replaceAll(/[^a-z0-9 ]/g, " ")
|
|
99
|
-
.split(/\s+/)
|
|
100
|
-
.filter((t) => t && !STOP.has(t))
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const normPhone = (p?: string): string => {
|
|
105
|
-
const d = (p ?? "").replaceAll(/\D/g, "")
|
|
106
|
-
|
|
107
|
-
return d.length >= 10 ? d.slice(-10) : ""
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
interface Provider {
|
|
111
|
-
npi: string
|
|
112
|
-
tokens: Set<string>
|
|
113
|
-
phone: string
|
|
114
|
-
/**
|
|
115
|
-
* Authorized official (last + first), lowercased — same official ⇒ almost certainly one org.
|
|
116
|
-
*/
|
|
117
|
-
auth: string
|
|
118
|
-
/**
|
|
119
|
-
* Primary taxonomy (specialty) code — different specialty ⇒ likely a genuinely different provider.
|
|
120
|
-
*/
|
|
121
|
-
taxonomy: string
|
|
122
|
-
}
|
|
123
|
-
|
|
124
71
|
/**
|
|
125
72
|
* #625 ceiling measurement — see the module doc. Emits the markdown report to stdout.
|
|
126
73
|
*/
|
|
@@ -130,59 +77,14 @@ export async function dedupCeiling(
|
|
|
130
77
|
): Promise<{ markdown: string; pairs: number; collide: number }> {
|
|
131
78
|
const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
|
|
132
79
|
const CAP = options.cap ?? 50_000
|
|
133
|
-
const STATE = (options
|
|
80
|
+
const STATE = stateOption(options)
|
|
134
81
|
const TAU = options.tau ?? 0.7
|
|
135
82
|
const OUT_MD = options.outMd || ""
|
|
136
83
|
const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
|
|
137
84
|
|
|
138
85
|
// --- Stream TX type-2 (org) providers; one primary record per NPI at its practice address. ---
|
|
139
86
|
report?.(`[A] streaming ${STATE} org providers (cap ${CAP})…`)
|
|
140
|
-
const byAddr =
|
|
141
|
-
let kept = 0
|
|
142
|
-
let scanned = 0
|
|
143
|
-
|
|
144
|
-
for await (const r of streamRows(REGISTRY)) {
|
|
145
|
-
scanned++
|
|
146
|
-
|
|
147
|
-
if (norm(r["Entity Type Code"]) !== "2") continue
|
|
148
|
-
|
|
149
|
-
if (norm(r["Provider Business Practice Location Address State Name"]).toUpperCase() !== STATE) continue
|
|
150
|
-
const org = norm(r["Provider Organization Name (Legal Business Name)"])
|
|
151
|
-
|
|
152
|
-
if (!org) continue
|
|
153
|
-
const line1 = norm(r["Provider First Line Business Practice Location Address"])
|
|
154
|
-
const city = norm(r["Provider Business Practice Location Address City Name"])
|
|
155
|
-
const zip = norm(r["Provider Business Practice Location Address Postal Code"])
|
|
156
|
-
|
|
157
|
-
if (!line1) continue
|
|
158
|
-
const addrKey = addressFrequencyKey(`${line1}, ${city}, ${STATE} ${zip}`)
|
|
159
|
-
|
|
160
|
-
if (!addrKey) continue
|
|
161
|
-
const npi = norm(r["NPI"])
|
|
162
|
-
|
|
163
|
-
const auth = `${norm(r["Authorized Official Last Name"])} ${norm(r["Authorized Official First Name"])}`
|
|
164
|
-
.toLowerCase()
|
|
165
|
-
.trim()
|
|
166
|
-
|
|
167
|
-
const p: Provider = {
|
|
168
|
-
npi,
|
|
169
|
-
tokens: orgTokens(org),
|
|
170
|
-
phone: normPhone(r["Provider Business Practice Location Address Telephone Number"]),
|
|
171
|
-
auth: auth === "" ? "" : auth,
|
|
172
|
-
taxonomy: norm(r["Healthcare Provider Taxonomy Code_1"]),
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (!byAddr.has(addrKey)) {
|
|
176
|
-
byAddr.set(addrKey, [])
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
byAddr.get(addrKey)!.push(p)
|
|
180
|
-
|
|
181
|
-
kept++
|
|
182
|
-
|
|
183
|
-
if (kept >= CAP) break
|
|
184
|
-
}
|
|
185
|
-
|
|
87
|
+
const { byAddr, kept, scanned } = await scanColocatedProviders({ registryPath: REGISTRY, state: STATE, cap: CAP })
|
|
186
88
|
report?.(` scanned ${scanned} rows → ${kept} ${STATE} org providers at ${byAddr.size} distinct addresses`)
|
|
187
89
|
|
|
188
90
|
// --- Over co-located distinct-NPI pairs: the org-similarity distribution + collision rate. ---
|
|
@@ -201,52 +103,40 @@ export async function dedupCeiling(
|
|
|
201
103
|
|
|
202
104
|
// guard against a pathological mega-address (PO-box farms)
|
|
203
105
|
|
|
204
|
-
|
|
205
|
-
// distinct NPIs at this address
|
|
206
|
-
const distinct = new Map<string, Provider>()
|
|
106
|
+
let lastGroup: readonly ColocatedProvider[] | null = null
|
|
207
107
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
108
|
+
for (const { a, b, group } of colocatedDistinctPairs(byAddr)) {
|
|
109
|
+
if (group !== lastGroup) {
|
|
110
|
+
lastGroup = group
|
|
212
111
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
sharedAddresses++
|
|
218
|
-
providersAtSharedAddr += list.length
|
|
112
|
+
sharedAddresses++
|
|
113
|
+
providersAtSharedAddr += group.length
|
|
114
|
+
}
|
|
219
115
|
|
|
220
|
-
|
|
221
|
-
for (let j = i + 1; j < list.length; j++) {
|
|
222
|
-
if (pairs >= PAIR_BUDGET) break
|
|
116
|
+
if (pairs >= PAIR_BUDGET) continue
|
|
223
117
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const b = list[j]!
|
|
227
|
-
const sim = jaccard(a.tokens, b.tokens)
|
|
118
|
+
pairs++
|
|
119
|
+
const sim = jaccard(a.tokens, b.tokens)
|
|
228
120
|
|
|
229
|
-
|
|
230
|
-
|
|
121
|
+
if (sim >= TAU) {
|
|
122
|
+
collide++
|
|
231
123
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
124
|
+
if (a.phone && a.phone === b.phone) {
|
|
125
|
+
collideSharePhone++
|
|
126
|
+
}
|
|
235
127
|
|
|
236
|
-
|
|
237
|
-
|
|
128
|
+
const sameAuth = a.auth !== "" && a.auth === b.auth
|
|
129
|
+
const sameTax = a.taxonomy !== "" && a.taxonomy === b.taxonomy
|
|
238
130
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
} else if (sim >= WEAK_SIMILARITY_MIN) {
|
|
245
|
-
mid++
|
|
246
|
-
} else {
|
|
247
|
-
separable++
|
|
248
|
-
}
|
|
131
|
+
if (sameAuth) {
|
|
132
|
+
collideSameAuth++
|
|
133
|
+
} else if (!sameTax) {
|
|
134
|
+
collideDistinct++
|
|
249
135
|
}
|
|
136
|
+
} else if (sim >= WEAK_SIMILARITY_MIN) {
|
|
137
|
+
mid++
|
|
138
|
+
} else {
|
|
139
|
+
separable++
|
|
250
140
|
}
|
|
251
141
|
}
|
|
252
142
|
|
|
@@ -259,7 +149,6 @@ export async function dedupCeiling(
|
|
|
259
149
|
// of `mid`). Recall is NOT the binding constraint here (NPPES same-NPI records almost always share
|
|
260
150
|
// either address or org), so the F1 ceiling tracks the precision ceiling. ---
|
|
261
151
|
const pct = formatPercent
|
|
262
|
-
const collisionRate = pairs > 0 ? collide / pairs : 0
|
|
263
152
|
|
|
264
153
|
const lines: string[] = [
|
|
265
154
|
`# #625 — dedup ceiling: the irreducible over-merge of co-located providers`,
|
|
@@ -339,7 +228,7 @@ export async function dedupCeiling(
|
|
|
339
228
|
console.log(md)
|
|
340
229
|
|
|
341
230
|
if (OUT_MD) {
|
|
342
|
-
|
|
231
|
+
await writeLocalFile(md, OUT_MD)
|
|
343
232
|
report?.(`[written] ${OUT_MD}`)
|
|
344
233
|
}
|
|
345
234
|
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
6
|
* The injected-geocoder contract for the record-matcher tools. The registry package deliberately
|
|
7
|
-
* never imports the heavy runtime (neural parser, WOF resolver, per-state
|
|
7
|
+
* never imports the heavy runtime (neural parser, WOF resolver, per-state extracts) — `mailwoman`
|
|
8
8
|
* depends on `@mailwoman/registry`, so the reverse import would cycle the workspace graph. Instead
|
|
9
9
|
* each tool takes an {@linkcode EvalGeocoderFactory} the CLI command constructs from
|
|
10
10
|
* `mailwoman/geocode-core` (see `mailwoman/commands/registry/run.tsx`), mirroring the matcher's own
|
|
11
|
-
* `GeocodeAddress`
|
|
11
|
+
* `GeocodeAddress` interface philosophy: ingest never pins the runtime, the caller wires it.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import type { ColumnMapping, GeocodeAddress, SourceRecord } from "
|
|
14
|
+
import type { ColumnMapping, GeocodeAddress, SourceRecord } from "#index"
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* The raw single-address geocode surface (the probe tools) — mirrors `mailwoman/geocode-core`'s wire shape.
|
|
@@ -26,21 +26,20 @@ export interface EvalGeocodeResult {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
* A constructed geocoder: the matcher's ingest
|
|
29
|
+
* A constructed geocoder: the matcher's ingest interface, the raw geocode, and the handle release.
|
|
30
30
|
*/
|
|
31
|
-
export interface EvalGeocoder {
|
|
31
|
+
export interface EvalGeocoder extends Disposable {
|
|
32
32
|
/**
|
|
33
|
-
* The matcher's ingest
|
|
33
|
+
* The matcher's ingest interface (parse + geocode → `PostalAddress`), built via `geocodeAddressVia`.
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
geocodeAddress: GeocodeAddress
|
|
36
36
|
/**
|
|
37
37
|
* Raw single-address geocode — lat/lon + resolution tier.
|
|
38
38
|
*/
|
|
39
39
|
geocode: (address: string) => Promise<EvalGeocodeResult>
|
|
40
40
|
/**
|
|
41
|
-
* Release the DB handles (
|
|
41
|
+
* Release the DB handles (extracts + WOF lookup).
|
|
42
42
|
*/
|
|
43
|
-
close: () => void
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
/**
|
|
@@ -54,12 +53,12 @@ export interface EvalGeocoderInit {
|
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
/**
|
|
57
|
-
* Build a geocoder on demand — tools construct late and
|
|
56
|
+
* Build a geocoder on demand — tools construct late and dispose it as soon as geocoding is done.
|
|
58
57
|
*/
|
|
59
58
|
export type EvalGeocoderFactory = (init?: EvalGeocoderInit) => Promise<EvalGeocoder>
|
|
60
59
|
|
|
61
60
|
/**
|
|
62
|
-
* The threaded geocode surface (`mailwoman/geocode-stream` behind the
|
|
61
|
+
* The threaded geocode surface (`mailwoman/geocode-stream` behind the interface) for `nppes-dedup-benchmark
|
|
63
62
|
* --parallel-geocode`. Yields enriched records in completion order.
|
|
64
63
|
*/
|
|
65
64
|
export type EvalGeocodeStream = (
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
6
|
* Admin-tier wrong-region probe (#619 tail) — the geocoder-vs-provided-coords eval found an
|
|
7
|
-
* admin-tier tail to 11143 km (p99 2189 km). Hypothesis: when no street
|
|
7
|
+
* admin-tier tail to 11143 km (p99 2189 km). Hypothesis: when no street extract covers the address,
|
|
8
8
|
* the admin cascade resolves the locality by NAME and (when the region/postcode constraint is
|
|
9
9
|
* weak) picks the population-dominant FOREIGN namesake — Paris→France, Athens→Greece — instead of
|
|
10
10
|
* the in-state Texas city. This probes a curated set of TX namesake cities, with and without ZIP,
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
import { haversineKm } from "@mailwoman/spatial"
|
|
17
17
|
|
|
18
|
-
import type { EvalGeocoderFactory } from "
|
|
18
|
+
import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
|
|
19
|
+
import { inTXBBOX } from "#tools/shared"
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Options for {@linkcode geocoderNamesakeProbe}.
|
|
@@ -41,14 +42,6 @@ const CASES: Array<{ city: string; zip: string; tx: [number, number]; namesake:
|
|
|
41
42
|
{ city: "Odessa", zip: "79761", tx: [31.85, -102.37], namesake: "Odessa, Ukraine (46.48, 30.72)" },
|
|
42
43
|
]
|
|
43
44
|
|
|
44
|
-
/**
|
|
45
|
-
* Texas bounding box (generous).
|
|
46
|
-
*/
|
|
47
|
-
const TX_BBOX = { latMin: 25.8, latMax: 36.6, lonMin: -106.7, lonMax: -93.4 }
|
|
48
|
-
|
|
49
|
-
const inTexas = (lat: number, lon: number) =>
|
|
50
|
-
lat >= TX_BBOX.latMin && lat <= TX_BBOX.latMax && lon >= TX_BBOX.lonMin && lon <= TX_BBOX.lonMax
|
|
51
|
-
|
|
52
45
|
/**
|
|
53
46
|
* Admin-tier wrong-region probe (#619 tail) — see the module doc. Prints one line per variant to stdout.
|
|
54
47
|
*/
|
|
@@ -75,7 +68,7 @@ export async function geocoderNamesakeProbe(
|
|
|
75
68
|
continue
|
|
76
69
|
}
|
|
77
70
|
|
|
78
|
-
const ok =
|
|
71
|
+
const ok = inTXBBOX(g.lat, g.lon)
|
|
79
72
|
const km = haversineKm(c.tx[0], c.tx[1], g.lat, g.lon)
|
|
80
73
|
|
|
81
74
|
if (!ok) {
|
|
@@ -89,7 +82,7 @@ export async function geocoderNamesakeProbe(
|
|
|
89
82
|
}
|
|
90
83
|
}
|
|
91
84
|
|
|
92
|
-
geocoder.
|
|
85
|
+
geocoder[Symbol.dispose]()
|
|
93
86
|
|
|
94
87
|
console.log(`\n ${wrongRegion}/${total} variants resolved OUTSIDE Texas (wrong-region).`)
|
|
95
88
|
|
|
@@ -20,14 +20,15 @@
|
|
|
20
20
|
* [--data-root <dir>] [--out-md docs/articles/evals/resolver-geo/<date>-...md]`
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
import {
|
|
23
|
+
import { dataRootPath } from "@mailwoman/core/data-root"
|
|
24
|
+
import { writeLocalFile } from "@mailwoman/core/fs/writers"
|
|
25
|
+
import { isPresent } from "@mailwoman/core/objects"
|
|
26
|
+
import { percentile } from "@mailwoman/core/stats"
|
|
26
27
|
import { haversineKm } from "@mailwoman/match"
|
|
27
|
-
import { streamRows } from "@mailwoman/registry"
|
|
28
28
|
|
|
29
|
-
import
|
|
30
|
-
import {
|
|
29
|
+
import { streamRows } from "#index"
|
|
30
|
+
import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
|
|
31
|
+
import { norm } from "#tools/shared"
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* Largest absolute latitude in WGS-84 degrees.
|
|
@@ -133,7 +134,7 @@ export async function geocoderVsProvidedCoords(
|
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
scanned++
|
|
136
|
-
const address = [line, city, state, zip].filter(
|
|
137
|
+
const address = [line, city, state, zip].filter(isPresent).join(", ")
|
|
137
138
|
const g = await geocoder.geocode(address)
|
|
138
139
|
|
|
139
140
|
if (g.lat === null || g.lon === null) {
|
|
@@ -146,7 +147,7 @@ export async function geocoderVsProvidedCoords(
|
|
|
146
147
|
results.push({ deltaM, tier: g.resolution_tier ?? "unknown" })
|
|
147
148
|
}
|
|
148
149
|
|
|
149
|
-
geocoder.
|
|
150
|
+
geocoder[Symbol.dispose]()
|
|
150
151
|
|
|
151
152
|
// Overall + per-tier percentiles.
|
|
152
153
|
const all = results.map((r) => r.deltaM).toSorted((a, b) => a - b)
|
|
@@ -199,10 +200,10 @@ export async function geocoderVsProvidedCoords(
|
|
|
199
200
|
lines.push(
|
|
200
201
|
`Two regimes. **Street-tier placement is excellent** (the address_point + interpolated rows above) — ` +
|
|
201
202
|
`rooftop-to-segment medians, the precision that makes geo-first blocking and the distance evidence ` +
|
|
202
|
-
`trustworthy. The **admin (centroid) tier** is where no street
|
|
203
|
+
`trustworthy. The **admin (centroid) tier** is where no street extract covered the address: accuracy is ` +
|
|
203
204
|
`necessarily km-scale, and it carries a catastrophic tail (the p90/p99/max above) from wrong-region admin ` +
|
|
204
205
|
`resolutions and/or malformed provided coordinates — NOT street-tier error. Those extremes are a signal to ` +
|
|
205
|
-
`inspect, and they motivate wider street-
|
|
206
|
+
`inspect, and they motivate wider street-extract coverage for rural TX plus an admin-tier sanity bound. The ` +
|
|
206
207
|
`self-reported-vs-independent coordinate discrepancy is itself a data-quality column the reconciliation ` +
|
|
207
208
|
`surfaces (#621).`
|
|
208
209
|
)
|
|
@@ -214,7 +215,7 @@ export async function geocoderVsProvidedCoords(
|
|
|
214
215
|
console.log(md)
|
|
215
216
|
|
|
216
217
|
if (OUT_MD) {
|
|
217
|
-
|
|
218
|
+
await writeLocalFile(md, OUT_MD)
|
|
218
219
|
report?.(`\n[written] ${OUT_MD}`)
|
|
219
220
|
}
|
|
220
221
|
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Gold-set P3 (#625) — sample the HARD slice for adjudication. The programmatic entity truth
|
|
7
|
+
* (`nppes-dedup-benchmark.ts`) collapses only NPPES-FLAGGED subparts (Is-Subpart + parent
|
|
8
|
+
* LBN/TIN); it can't settle the genuinely-ambiguous co-located collisions: distinct NPIs at one
|
|
9
|
+
* address with near-identical names that are NOT flagged subparts of the same parent. Those are
|
|
10
|
+
* where NPI-truth and any programmatic rule disagree — exactly the pairs a frozen adjudicated
|
|
11
|
+
* gold set must cover.
|
|
12
|
+
*
|
|
13
|
+
* This finds them (over the full TX registry, geocode-free — the shared co-location scan
|
|
14
|
+
* `dedup-ceiling.ts` also runs) and writes each as a JSONL row carrying BOTH records' fields (org
|
|
15
|
+
* name, address, authorized official, taxonomy, subpart/parent flags) plus the programmatic
|
|
16
|
+
* verdict, so an adjudicator (human or LLM-as-judge, flagged as such) can label "same real-world
|
|
17
|
+
* entity? yes/no" and we can MEASURE how often the programmatic truth matches judgment.
|
|
18
|
+
*
|
|
19
|
+
* Run: `mailwoman registry gold-set-sample [--cap 200000] [--state TX] [--tau 0.7] [--n 300]
|
|
20
|
+
* [--out-jsonl <path>]`
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { dataRootPath } from "@mailwoman/core/data-root"
|
|
24
|
+
import { writeLocalTextFile } from "@mailwoman/core/fs/writers"
|
|
25
|
+
import { jaccard } from "@mailwoman/match"
|
|
26
|
+
|
|
27
|
+
import { colocatedDistinctPairs, scanColocatedProviders, stateOption } from "#tools/shared"
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Options for {@linkcode goldSetSample}.
|
|
31
|
+
*/
|
|
32
|
+
export interface GoldSetSampleOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Record-matcher sources directory. Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
|
|
35
|
+
*/
|
|
36
|
+
sources?: string
|
|
37
|
+
/**
|
|
38
|
+
* Providers sampled from the registry. Default 200000.
|
|
39
|
+
*/
|
|
40
|
+
cap?: number
|
|
41
|
+
/**
|
|
42
|
+
* State filter. Default TX.
|
|
43
|
+
*/
|
|
44
|
+
state?: string
|
|
45
|
+
/**
|
|
46
|
+
* Org-name Jaccard collision threshold. Default 0.7.
|
|
47
|
+
*/
|
|
48
|
+
tau?: number
|
|
49
|
+
/**
|
|
50
|
+
* Adjudication sample size. Default 300.
|
|
51
|
+
*/
|
|
52
|
+
n?: number
|
|
53
|
+
/**
|
|
54
|
+
* Write the sampled pairs here as JSONL (otherwise the first 10 print to stdout).
|
|
55
|
+
*/
|
|
56
|
+
outJSONL?: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface HardPair {
|
|
60
|
+
npiA: string
|
|
61
|
+
npiB: string
|
|
62
|
+
orgA: string
|
|
63
|
+
orgB: string
|
|
64
|
+
address: string
|
|
65
|
+
nameJaccard: number
|
|
66
|
+
sameAuthorizedOfficial: boolean
|
|
67
|
+
sameTaxonomy: boolean
|
|
68
|
+
bothSubpartSameParent: boolean
|
|
69
|
+
programmaticVerdict: "same-entity" | "distinct"
|
|
70
|
+
adjudication: null // ← to be filled: "same-entity" | "distinct"
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gold-set P3 (#625) — sample the HARD co-located name-collision slice for adjudication.
|
|
75
|
+
*/
|
|
76
|
+
export async function goldSetSample(
|
|
77
|
+
options: GoldSetSampleOptions = {},
|
|
78
|
+
report?: (line: string) => void
|
|
79
|
+
): Promise<{ hardPairs: number; sampled: number }> {
|
|
80
|
+
const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
|
|
81
|
+
const CAP = options.cap ?? 200_000
|
|
82
|
+
const STATE = stateOption(options)
|
|
83
|
+
const TAU = options.tau ?? 0.7
|
|
84
|
+
const N = options.n ?? 300
|
|
85
|
+
const OUT = options.outJSONL || ""
|
|
86
|
+
const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
|
|
87
|
+
|
|
88
|
+
report?.(`[A] streaming ${STATE} org providers (cap ${CAP})…`)
|
|
89
|
+
const { byAddr, kept } = await scanColocatedProviders({ registryPath: REGISTRY, state: STATE, cap: CAP })
|
|
90
|
+
report?.(` ${kept} providers at ${byAddr.size} addresses`)
|
|
91
|
+
|
|
92
|
+
// Hard pairs: co-located, name-similar (≥τ), DISTINCT NPIs that programmatic truth can't confidently
|
|
93
|
+
// collapse (NOT subparts of the same parent). Tag the programmatic verdict so adjudication can grade it.
|
|
94
|
+
const hard: HardPair[] = []
|
|
95
|
+
|
|
96
|
+
for (const { a, b } of colocatedDistinctPairs(byAddr)) {
|
|
97
|
+
const sim = jaccard(a.tokens, b.tokens)
|
|
98
|
+
|
|
99
|
+
if (sim < TAU) continue
|
|
100
|
+
const sameParent = a.subpart && b.subpart && a.parent === b.parent && a.parent !== "|"
|
|
101
|
+
|
|
102
|
+
if (sameParent) continue // programmatic truth already collapses these — not the hard slice
|
|
103
|
+
const sameAuth = a.auth !== "" && a.auth === b.auth
|
|
104
|
+
const sameTax = a.taxonomy !== "" && a.taxonomy === b.taxonomy
|
|
105
|
+
|
|
106
|
+
hard.push({
|
|
107
|
+
npiA: a.npi,
|
|
108
|
+
npiB: b.npi,
|
|
109
|
+
orgA: a.org,
|
|
110
|
+
orgB: b.org,
|
|
111
|
+
address: a.address,
|
|
112
|
+
nameJaccard: Number(sim.toFixed(3)),
|
|
113
|
+
sameAuthorizedOfficial: sameAuth,
|
|
114
|
+
sameTaxonomy: sameTax,
|
|
115
|
+
bothSubpartSameParent: false,
|
|
116
|
+
// Programmatic heuristic verdict (what an entity-level rule WOULD say, beyond the flagged
|
|
117
|
+
// subparts): same authorized official ⇒ likely one org; different official + different
|
|
118
|
+
// specialty ⇒ likely distinct. The whole point is to ADJUDICATE whether this is right.
|
|
119
|
+
programmaticVerdict: sameAuth ? "same-entity" : "distinct",
|
|
120
|
+
adjudication: null,
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
report?.(` ${hard.length} hard co-located name-collision pairs (non-flagged-subpart)`)
|
|
125
|
+
|
|
126
|
+
// Deterministic spread sample of N (stride, not head — avoid file-order bias, the dedup-ceiling lesson).
|
|
127
|
+
const stride = Math.max(1, Math.floor(hard.length / N))
|
|
128
|
+
const sample = hard.filter((_, i) => i % stride === 0).slice(0, N)
|
|
129
|
+
report?.(` sampling ${sample.length} (stride ${stride}) for adjudication`)
|
|
130
|
+
|
|
131
|
+
if (OUT) {
|
|
132
|
+
await writeLocalTextFile(sample.map((p) => JSON.stringify(p)).join("\n") + "\n", OUT)
|
|
133
|
+
report?.(`[written] ${OUT}`)
|
|
134
|
+
} else {
|
|
135
|
+
for (const p of sample.slice(0, 10)) {
|
|
136
|
+
console.log(JSON.stringify(p))
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return { hardPairs: hard.length, sampled: sample.length }
|
|
141
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Registry operator tool exports.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export * from "#tools/coverage-reconciliation"
|
|
10
|
+
export * from "#tools/cross-dataset-correlation"
|
|
11
|
+
export * from "#tools/cross-source-threshold-sweep"
|
|
12
|
+
export * from "#tools/dedup-ceiling"
|
|
13
|
+
export * from "#tools/eval-geocoder"
|
|
14
|
+
export * from "#tools/geocoder-namesake-probe"
|
|
15
|
+
export * from "#tools/geocoder-vs-provided-coords"
|
|
16
|
+
export * from "#tools/gold-set-sample"
|
|
17
|
+
export * from "#tools/learned-scorer-clustering-eval"
|
|
18
|
+
export * from "#tools/learned-scorer-crossstate-eval"
|
|
19
|
+
export * from "#tools/learned-scorer-eval"
|
|
20
|
+
export * from "#tools/matcher-scale"
|
|
21
|
+
export * from "#tools/nppes-dedup-benchmark"
|
|
22
|
+
export * from "#tools/train-cross-gbt"
|
|
23
|
+
export * from "#tools/train-gbt"
|
|
24
|
+
export * from "#tools/train-org-cross-gbt"
|
|
25
|
+
export * from "#tools/txhhsc-to-oarow"
|
|
26
|
+
export * from "#tools/viz/cross-dataset-map"
|
|
27
|
+
export * from "#tools/viz/geocode-first-surface"
|
|
28
|
+
export * from "#tools/viz/render-map"
|
|
29
|
+
export * from "#tools/viz/render"
|
|
30
|
+
export * from "#tools/viz/source-provenance-map"
|
|
31
|
+
export * from "#tools/viz/yardstick-figure"
|