@mailwoman/registry 9.2.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 +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 +62 -256
- 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 +763 -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 +35 -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 +37 -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 +244 -7
- package/out/tools/shared.d.ts.map +1 -1
- package/out/tools/shared.js +349 -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
|
@@ -30,17 +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
37
|
|
|
38
|
-
import {
|
|
39
|
-
|
|
40
|
-
import { norm } from "./shared.ts"
|
|
38
|
+
import { colocatedDistinctPairs, scanColocatedProviders, stateOption, type ColocatedProvider } from "#tools/shared"
|
|
41
39
|
|
|
42
40
|
/**
|
|
43
|
-
* 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.
|
|
44
42
|
*/
|
|
45
43
|
const WEAK_SIMILARITY_MIN = 0.3
|
|
46
44
|
|
|
@@ -70,58 +68,6 @@ export interface DedupCeilingOptions {
|
|
|
70
68
|
outMd?: string
|
|
71
69
|
}
|
|
72
70
|
|
|
73
|
-
/**
|
|
74
|
-
* Strip only corporate-form tokens + articles — KEEP domain words (health, medical, center…), which carry the
|
|
75
|
-
* distinguishing signal between two co-located providers.
|
|
76
|
-
*/
|
|
77
|
-
const STOP = new Set([
|
|
78
|
-
"llc",
|
|
79
|
-
"inc",
|
|
80
|
-
"incorporated",
|
|
81
|
-
"corp",
|
|
82
|
-
"corporation",
|
|
83
|
-
"co",
|
|
84
|
-
"ltd",
|
|
85
|
-
"pllc",
|
|
86
|
-
"pc",
|
|
87
|
-
"pa",
|
|
88
|
-
"lp",
|
|
89
|
-
"llp",
|
|
90
|
-
"the",
|
|
91
|
-
"of",
|
|
92
|
-
"and",
|
|
93
|
-
])
|
|
94
|
-
|
|
95
|
-
function orgTokens(s: string): Set<string> {
|
|
96
|
-
return new Set(
|
|
97
|
-
s
|
|
98
|
-
.toLowerCase()
|
|
99
|
-
.replaceAll(/[^a-z0-9 ]/g, " ")
|
|
100
|
-
.split(/\s+/)
|
|
101
|
-
.filter((t) => t && !STOP.has(t))
|
|
102
|
-
)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const normPhone = (p?: string): string => {
|
|
106
|
-
const d = (p ?? "").replaceAll(/\D/g, "")
|
|
107
|
-
|
|
108
|
-
return d.length >= 10 ? d.slice(-10) : ""
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
interface Provider {
|
|
112
|
-
npi: string
|
|
113
|
-
tokens: Set<string>
|
|
114
|
-
phone: string
|
|
115
|
-
/**
|
|
116
|
-
* Authorized official (last + first), lowercased — same official ⇒ almost certainly one org.
|
|
117
|
-
*/
|
|
118
|
-
auth: string
|
|
119
|
-
/**
|
|
120
|
-
* Primary taxonomy (specialty) code — different specialty ⇒ likely a genuinely different provider.
|
|
121
|
-
*/
|
|
122
|
-
taxonomy: string
|
|
123
|
-
}
|
|
124
|
-
|
|
125
71
|
/**
|
|
126
72
|
* #625 ceiling measurement — see the module doc. Emits the markdown report to stdout.
|
|
127
73
|
*/
|
|
@@ -131,59 +77,14 @@ export async function dedupCeiling(
|
|
|
131
77
|
): Promise<{ markdown: string; pairs: number; collide: number }> {
|
|
132
78
|
const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
|
|
133
79
|
const CAP = options.cap ?? 50_000
|
|
134
|
-
const STATE = (options
|
|
80
|
+
const STATE = stateOption(options)
|
|
135
81
|
const TAU = options.tau ?? 0.7
|
|
136
82
|
const OUT_MD = options.outMd || ""
|
|
137
83
|
const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
|
|
138
84
|
|
|
139
85
|
// --- Stream TX type-2 (org) providers; one primary record per NPI at its practice address. ---
|
|
140
86
|
report?.(`[A] streaming ${STATE} org providers (cap ${CAP})…`)
|
|
141
|
-
const byAddr =
|
|
142
|
-
let kept = 0
|
|
143
|
-
let scanned = 0
|
|
144
|
-
|
|
145
|
-
for await (const r of streamRows(REGISTRY)) {
|
|
146
|
-
scanned++
|
|
147
|
-
|
|
148
|
-
if (norm(r["Entity Type Code"]) !== "2") continue
|
|
149
|
-
|
|
150
|
-
if (norm(r["Provider Business Practice Location Address State Name"]).toUpperCase() !== STATE) continue
|
|
151
|
-
const org = norm(r["Provider Organization Name (Legal Business Name)"])
|
|
152
|
-
|
|
153
|
-
if (!org) continue
|
|
154
|
-
const line1 = norm(r["Provider First Line Business Practice Location Address"])
|
|
155
|
-
const city = norm(r["Provider Business Practice Location Address City Name"])
|
|
156
|
-
const zip = norm(r["Provider Business Practice Location Address Postcode"])
|
|
157
|
-
|
|
158
|
-
if (!line1) continue
|
|
159
|
-
const addrKey = addressFrequencyKey(`${line1}, ${city}, ${STATE} ${zip}`)
|
|
160
|
-
|
|
161
|
-
if (!addrKey) continue
|
|
162
|
-
const npi = norm(r["NPI"])
|
|
163
|
-
|
|
164
|
-
const auth = `${norm(r["Authorized Official Last Name"])} ${norm(r["Authorized Official First Name"])}`
|
|
165
|
-
.toLowerCase()
|
|
166
|
-
.trim()
|
|
167
|
-
|
|
168
|
-
const p: Provider = {
|
|
169
|
-
npi,
|
|
170
|
-
tokens: orgTokens(org),
|
|
171
|
-
phone: normPhone(r["Provider Business Practice Location Address Telephone Number"]),
|
|
172
|
-
auth: auth === "" ? "" : auth,
|
|
173
|
-
taxonomy: norm(r["Healthcare Provider Taxonomy Code_1"]),
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (!byAddr.has(addrKey)) {
|
|
177
|
-
byAddr.set(addrKey, [])
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
byAddr.get(addrKey)!.push(p)
|
|
181
|
-
|
|
182
|
-
kept++
|
|
183
|
-
|
|
184
|
-
if (kept >= CAP) break
|
|
185
|
-
}
|
|
186
|
-
|
|
87
|
+
const { byAddr, kept, scanned } = await scanColocatedProviders({ registryPath: REGISTRY, state: STATE, cap: CAP })
|
|
187
88
|
report?.(` scanned ${scanned} rows → ${kept} ${STATE} org providers at ${byAddr.size} distinct addresses`)
|
|
188
89
|
|
|
189
90
|
// --- Over co-located distinct-NPI pairs: the org-similarity distribution + collision rate. ---
|
|
@@ -202,52 +103,40 @@ export async function dedupCeiling(
|
|
|
202
103
|
|
|
203
104
|
// guard against a pathological mega-address (PO-box farms)
|
|
204
105
|
|
|
205
|
-
|
|
206
|
-
// distinct NPIs at this address
|
|
207
|
-
const distinct = new Map<string, Provider>()
|
|
106
|
+
let lastGroup: readonly ColocatedProvider[] | null = null
|
|
208
107
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
108
|
+
for (const { a, b, group } of colocatedDistinctPairs(byAddr)) {
|
|
109
|
+
if (group !== lastGroup) {
|
|
110
|
+
lastGroup = group
|
|
213
111
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
sharedAddresses++
|
|
219
|
-
providersAtSharedAddr += list.length
|
|
112
|
+
sharedAddresses++
|
|
113
|
+
providersAtSharedAddr += group.length
|
|
114
|
+
}
|
|
220
115
|
|
|
221
|
-
|
|
222
|
-
for (let j = i + 1; j < list.length; j++) {
|
|
223
|
-
if (pairs >= PAIR_BUDGET) break
|
|
116
|
+
if (pairs >= PAIR_BUDGET) continue
|
|
224
117
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const b = list[j]!
|
|
228
|
-
const sim = jaccard(a.tokens, b.tokens)
|
|
118
|
+
pairs++
|
|
119
|
+
const sim = jaccard(a.tokens, b.tokens)
|
|
229
120
|
|
|
230
|
-
|
|
231
|
-
|
|
121
|
+
if (sim >= TAU) {
|
|
122
|
+
collide++
|
|
232
123
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
124
|
+
if (a.phone && a.phone === b.phone) {
|
|
125
|
+
collideSharePhone++
|
|
126
|
+
}
|
|
236
127
|
|
|
237
|
-
|
|
238
|
-
|
|
128
|
+
const sameAuth = a.auth !== "" && a.auth === b.auth
|
|
129
|
+
const sameTax = a.taxonomy !== "" && a.taxonomy === b.taxonomy
|
|
239
130
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
} else if (sim >= WEAK_SIMILARITY_MIN) {
|
|
246
|
-
mid++
|
|
247
|
-
} else {
|
|
248
|
-
separable++
|
|
249
|
-
}
|
|
131
|
+
if (sameAuth) {
|
|
132
|
+
collideSameAuth++
|
|
133
|
+
} else if (!sameTax) {
|
|
134
|
+
collideDistinct++
|
|
250
135
|
}
|
|
136
|
+
} else if (sim >= WEAK_SIMILARITY_MIN) {
|
|
137
|
+
mid++
|
|
138
|
+
} else {
|
|
139
|
+
separable++
|
|
251
140
|
}
|
|
252
141
|
}
|
|
253
142
|
|
|
@@ -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,11 +4,11 @@
|
|
|
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
14
|
import type { ColumnMapping, GeocodeAddress, SourceRecord } from "#index"
|
|
@@ -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,16 +20,15 @@
|
|
|
20
20
|
* [--data-root <dir>] [--out-md docs/articles/evals/resolver-geo/<date>-...md]`
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
import {
|
|
24
|
-
|
|
23
|
+
import { dataRootPath } from "@mailwoman/core/data-root"
|
|
24
|
+
import { writeLocalFile } from "@mailwoman/core/fs/writers"
|
|
25
25
|
import { isPresent } from "@mailwoman/core/objects"
|
|
26
|
-
import {
|
|
26
|
+
import { percentile } from "@mailwoman/core/stats"
|
|
27
27
|
import { haversineKm } from "@mailwoman/match"
|
|
28
28
|
|
|
29
29
|
import { streamRows } from "#index"
|
|
30
|
-
|
|
31
|
-
import
|
|
32
|
-
import { norm } from "./shared.ts"
|
|
30
|
+
import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
|
|
31
|
+
import { norm } from "#tools/shared"
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
34
|
* Largest absolute latitude in WGS-84 degrees.
|
|
@@ -148,7 +147,7 @@ export async function geocoderVsProvidedCoords(
|
|
|
148
147
|
results.push({ deltaM, tier: g.resolution_tier ?? "unknown" })
|
|
149
148
|
}
|
|
150
149
|
|
|
151
|
-
geocoder.
|
|
150
|
+
geocoder[Symbol.dispose]()
|
|
152
151
|
|
|
153
152
|
// Overall + per-tier percentiles.
|
|
154
153
|
const all = results.map((r) => r.deltaM).toSorted((a, b) => a - b)
|
|
@@ -201,10 +200,10 @@ export async function geocoderVsProvidedCoords(
|
|
|
201
200
|
lines.push(
|
|
202
201
|
`Two regimes. **Street-tier placement is excellent** (the address_point + interpolated rows above) — ` +
|
|
203
202
|
`rooftop-to-segment medians, the precision that makes geo-first blocking and the distance evidence ` +
|
|
204
|
-
`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 ` +
|
|
205
204
|
`necessarily km-scale, and it carries a catastrophic tail (the p90/p99/max above) from wrong-region admin ` +
|
|
206
205
|
`resolutions and/or malformed provided coordinates — NOT street-tier error. Those extremes are a signal to ` +
|
|
207
|
-
`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 ` +
|
|
208
207
|
`self-reported-vs-independent coordinate discrepancy is itself a data-quality column the reconciliation ` +
|
|
209
208
|
`surfaces (#621).`
|
|
210
209
|
)
|
|
@@ -216,7 +215,7 @@ export async function geocoderVsProvidedCoords(
|
|
|
216
215
|
console.log(md)
|
|
217
216
|
|
|
218
217
|
if (OUT_MD) {
|
|
219
|
-
|
|
218
|
+
await writeLocalFile(md, OUT_MD)
|
|
220
219
|
report?.(`\n[written] ${OUT_MD}`)
|
|
221
220
|
}
|
|
222
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"
|