@mailwoman/registry 9.1.0 → 9.2.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/geojson.ts +3 -2
- package/ingest.ts +2 -1
- package/map-html.ts +4 -4
- package/out/geojson.d.ts.map +1 -1
- package/out/geojson.js +3 -2
- package/out/geojson.js.map +1 -1
- package/out/ingest.d.ts.map +1 -1
- package/out/ingest.js +2 -1
- package/out/ingest.js.map +1 -1
- package/out/map-html.d.ts +2 -2
- package/out/map-html.d.ts.map +1 -1
- package/out/map-html.js.map +1 -1
- package/out/reconcile.d.ts.map +1 -1
- package/out/reconcile.js +2 -1
- package/out/reconcile.js.map +1 -1
- package/out/resolve.d.ts.map +1 -1
- package/out/resolve.js +4 -1
- package/out/resolve.js.map +1 -1
- package/out/tools/coverage-reconciliation.js +2 -2
- package/out/tools/coverage-reconciliation.js.map +1 -1
- package/out/tools/cross-dataset-correlation.d.ts.map +1 -1
- package/out/tools/cross-dataset-correlation.js +6 -5
- package/out/tools/cross-dataset-correlation.js.map +1 -1
- package/out/tools/cross-source-threshold-sweep.js +2 -2
- 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 +2 -3
- package/out/tools/dedup-ceiling.js.map +1 -1
- package/out/tools/eval-geocoder.d.ts +1 -1
- package/out/tools/eval-geocoder.d.ts.map +1 -1
- package/out/tools/geocoder-vs-provided-coords.d.ts.map +1 -1
- package/out/tools/geocoder-vs-provided-coords.js +3 -2
- package/out/tools/geocoder-vs-provided-coords.js.map +1 -1
- package/out/tools/gold-set-sample.d.ts.map +1 -1
- package/out/tools/gold-set-sample.js +4 -3
- package/out/tools/gold-set-sample.js.map +1 -1
- package/out/tools/index.d.ts +1 -6
- package/out/tools/index.d.ts.map +1 -1
- package/out/tools/index.js +1 -6
- package/out/tools/index.js.map +1 -1
- package/out/tools/learned-scorer-clustering-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-clustering-eval.js +1 -2
- package/out/tools/learned-scorer-clustering-eval.js.map +1 -1
- package/out/tools/learned-scorer-crossstate-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-crossstate-eval.js +1 -1
- package/out/tools/learned-scorer-crossstate-eval.js.map +1 -1
- package/out/tools/learned-scorer-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-eval.js +1 -6
- 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 +1 -1
- package/out/tools/matcher-scale.js.map +1 -1
- package/out/tools/nppes/levers.d.ts +38 -0
- package/out/tools/nppes/levers.d.ts.map +1 -0
- package/out/tools/nppes/levers.js +79 -0
- package/out/tools/nppes/levers.js.map +1 -0
- package/out/tools/nppes/org-name.d.ts +24 -0
- package/out/tools/nppes/org-name.d.ts.map +1 -0
- package/out/tools/nppes/org-name.js +42 -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 +188 -0
- package/out/tools/nppes/report.js.map +1 -0
- package/out/tools/nppes/sample.d.ts +64 -0
- package/out/tools/nppes/sample.d.ts.map +1 -0
- package/out/tools/nppes/sample.js +113 -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/truth-grains.d.ts +50 -0
- package/out/tools/nppes/truth-grains.d.ts.map +1 -0
- package/out/tools/nppes/truth-grains.js +148 -0
- package/out/tools/nppes/truth-grains.js.map +1 -0
- package/out/tools/nppes-dedup-benchmark.d.ts +4 -0
- package/out/tools/nppes-dedup-benchmark.d.ts.map +1 -1
- package/out/tools/nppes-dedup-benchmark.js +79 -652
- package/out/tools/nppes-dedup-benchmark.js.map +1 -1
- package/out/tools/shared.d.ts.map +1 -1
- package/out/tools/shared.js +5 -4
- package/out/tools/shared.js.map +1 -1
- package/out/tools/train-cross-gbt.d.ts.map +1 -1
- package/out/tools/train-cross-gbt.js +2 -2
- package/out/tools/train-cross-gbt.js.map +1 -1
- package/out/tools/train-gbt.d.ts.map +1 -1
- package/out/tools/train-gbt.js +2 -2
- package/out/tools/train-gbt.js.map +1 -1
- package/out/tools/train-org-cross-gbt.d.ts.map +1 -1
- package/out/tools/train-org-cross-gbt.js +2 -2
- package/out/tools/train-org-cross-gbt.js.map +1 -1
- package/out/tools/txhhsc-to-oarow.js +2 -2
- package/out/tools/txhhsc-to-oarow.js.map +1 -1
- package/out/tools/viz/cross-dataset-map.d.ts +2 -23
- package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
- package/out/tools/viz/cross-dataset-map.js +7 -28
- package/out/tools/viz/cross-dataset-map.js.map +1 -1
- package/out/tools/viz/geocode-first-surface.d.ts +2 -32
- package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
- package/out/tools/viz/geocode-first-surface.js +4 -33
- package/out/tools/viz/geocode-first-surface.js.map +1 -1
- package/out/tools/viz/render.js +1 -1
- package/out/tools/viz/render.js.map +1 -1
- package/out/tools/viz/source-provenance-map.d.ts +2 -22
- package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
- package/out/tools/viz/source-provenance-map.js +7 -26
- package/out/tools/viz/source-provenance-map.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 +78 -9
- package/reconcile.ts +2 -1
- package/resolve.ts +6 -1
- package/tools/coverage-reconciliation.ts +3 -3
- package/tools/cross-dataset-correlation.ts +7 -5
- package/tools/cross-source-threshold-sweep.ts +3 -3
- package/tools/dedup-ceiling.ts +3 -3
- package/tools/eval-geocoder.ts +1 -1
- package/tools/geocoder-vs-provided-coords.ts +4 -2
- package/tools/gold-set-sample.ts +5 -3
- package/tools/index.ts +1 -6
- package/tools/learned-scorer-clustering-eval.ts +4 -4
- package/tools/learned-scorer-crossstate-eval.ts +4 -4
- package/tools/learned-scorer-eval.ts +4 -9
- package/tools/matcher-scale.ts +2 -1
- package/tools/nppes/levers.ts +102 -0
- package/tools/nppes/org-name.ts +56 -0
- package/tools/nppes/overmerge-packet.ts +96 -0
- package/tools/nppes/report.ts +376 -0
- package/tools/nppes/sample.ts +197 -0
- package/tools/nppes/scoring.ts +114 -0
- package/tools/nppes/truth-grains.ts +201 -0
- package/tools/nppes-dedup-benchmark.ts +92 -868
- package/tools/shared.ts +6 -4
- package/tools/train-cross-gbt.ts +6 -5
- package/tools/train-gbt.ts +5 -4
- package/tools/train-org-cross-gbt.ts +6 -5
- package/tools/txhhsc-to-oarow.ts +2 -2
- package/tools/viz/cross-dataset-map.ts +12 -34
- package/tools/viz/geocode-first-surface.ts +5 -33
- package/tools/viz/render.ts +1 -1
- package/tools/viz/source-provenance-map.ts +14 -31
- package/types.ts +10 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file The org-name entity-truth grains: union-find labellings that collapse co-located same-org NPIs, keyed three
|
|
6
|
+
* ways — the address string, a haversine co-location radius, and an H3 cell.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { haversineKm, jaccard, type LatLon } from "@mailwoman/match"
|
|
10
|
+
import { latLngToCell } from "h3-js"
|
|
11
|
+
|
|
12
|
+
import type { SourceRecord } from "#index"
|
|
13
|
+
|
|
14
|
+
import { ORG_TAU, type NPIPrimary } from "./org-name.ts"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Same-building distance for the coordinate grain — the `DEFAULT_DISTANCE_LEVELS` grain.
|
|
18
|
+
*/
|
|
19
|
+
export const COLOCATION_KM = 0.05
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A truth labelling: the entity class a record belongs to.
|
|
23
|
+
*/
|
|
24
|
+
export type TruthLabel = (rec: SourceRecord) => string
|
|
25
|
+
|
|
26
|
+
interface UnionFind {
|
|
27
|
+
find: (x: string) => string
|
|
28
|
+
union: (a: string, b: string) => void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function createUnionFind(): UnionFind {
|
|
32
|
+
const parent = new Map<string, string>()
|
|
33
|
+
|
|
34
|
+
const find = (x: string): string => {
|
|
35
|
+
if (!parent.has(x)) {
|
|
36
|
+
parent.set(x, x)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let root = x
|
|
40
|
+
|
|
41
|
+
while (parent.get(root)! !== root) {
|
|
42
|
+
root = parent.get(root)!
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
while (parent.get(x)! !== root) {
|
|
46
|
+
const next = parent.get(x)!
|
|
47
|
+
parent.set(x, root)
|
|
48
|
+
x = next
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return root
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const union = (a: string, b: string) => {
|
|
55
|
+
const ra = find(a)
|
|
56
|
+
const rb = find(b)
|
|
57
|
+
|
|
58
|
+
if (ra !== rb) {
|
|
59
|
+
parent.set(ra, rb)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return { find, union }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Union every pair in each block whose org names agree.
|
|
68
|
+
*
|
|
69
|
+
* Quadratic within a block, which is what keeps the gate honest: the Jaccard test is per PAIR, so a chain of
|
|
70
|
+
* near-matches cannot transitively fuse two genuinely distinct co-located orgs unless some pair actually agrees.
|
|
71
|
+
*/
|
|
72
|
+
function unionAgreeingPairs(
|
|
73
|
+
blocks: Iterable<readonly string[]>,
|
|
74
|
+
npiPrimary: Map<string, NPIPrimary>,
|
|
75
|
+
uf: UnionFind
|
|
76
|
+
): void {
|
|
77
|
+
for (const group of blocks) {
|
|
78
|
+
for (let i = 0; i < group.length; i++) {
|
|
79
|
+
for (let j = i + 1; j < group.length; j++) {
|
|
80
|
+
if (jaccard(npiPrimary.get(group[i]!)!.tokens, npiPrimary.get(group[j]!)!.tokens) >= ORG_TAU) {
|
|
81
|
+
uf.union(group[i]!, group[j]!)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* An NPI's primary practice coordinate — the FIRST geocoded record it owns, which is its primary row because the sample
|
|
90
|
+
* builder pushes that row before the alternate-name and mailing variants.
|
|
91
|
+
*/
|
|
92
|
+
export function collectPrimaryCoordinates(records: readonly SourceRecord[]): Map<string, LatLon> {
|
|
93
|
+
const npiCoord = new Map<string, LatLon>()
|
|
94
|
+
|
|
95
|
+
for (const rec of records) {
|
|
96
|
+
const c = rec.address?.geocode?.coordinate
|
|
97
|
+
|
|
98
|
+
if (c && !npiCoord.has(rec.id)) {
|
|
99
|
+
npiCoord.set(rec.id, c)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return npiCoord
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The string-keyed org-name truth: same NPI ⇒ same entity (so an NPI's records stay together and recall is preserved),
|
|
108
|
+
* PLUS union two NPIs at the same address KEY whose primary org names agree.
|
|
109
|
+
*
|
|
110
|
+
* Blocking on the address string is a conservative LOWER bound — `1504 Taub LOOP` and `1504 Taub LP STE 100` key apart
|
|
111
|
+
* even though they are one building, so a correct merge across them is still charged as an error. The coordinate grain
|
|
112
|
+
* below is the tighter reading. Neither relies on the NPPES subpart flag, which the gold set showed misses 37%.
|
|
113
|
+
*/
|
|
114
|
+
export function buildOrgNameGrain(npiPrimary: Map<string, NPIPrimary>): TruthLabel {
|
|
115
|
+
const uf = createUnionFind()
|
|
116
|
+
const byAddr = new Map<string, string[]>()
|
|
117
|
+
|
|
118
|
+
for (const [npi, info] of npiPrimary) {
|
|
119
|
+
uf.find(npi)
|
|
120
|
+
|
|
121
|
+
// seed
|
|
122
|
+
if (!info.addrKey) continue
|
|
123
|
+
|
|
124
|
+
if (!byAddr.has(info.addrKey)) {
|
|
125
|
+
byAddr.set(info.addrKey, [])
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
byAddr.get(info.addrKey)!.push(npi)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
unionAgreeingPairs(byAddr.values(), npiPrimary, uf)
|
|
132
|
+
|
|
133
|
+
return (rec) => (npiPrimary.has(rec.id) ? uf.find(rec.id) : rec.id)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The coordinate-keyed org-name truth: union same-org NPIs whose primary practice coordinates fall within
|
|
138
|
+
* {@linkcode COLOCATION_KM}. Blocking by the GEOCODED BUILDING catches the same-building pairs the address string keys
|
|
139
|
+
* apart, so this F1 is at or above the string grain's; the Jaccard gate still blocks distinct co-located orgs.
|
|
140
|
+
*
|
|
141
|
+
* Brute-force pairwise over the sampled NPIs — trivial at this scale, and unlike a cell key it has no boundary
|
|
142
|
+
* artifact.
|
|
143
|
+
*/
|
|
144
|
+
export function buildOrgNameCoordGrain(npiPrimary: Map<string, NPIPrimary>, npiCoord: Map<string, LatLon>): TruthLabel {
|
|
145
|
+
const uf = createUnionFind()
|
|
146
|
+
const coLocated = [...npiPrimary.keys()].filter((n) => npiCoord.has(n))
|
|
147
|
+
|
|
148
|
+
for (const n of npiPrimary.keys()) {
|
|
149
|
+
uf.find(n)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// seed every NPI (un-geocoded ones stay singletons)
|
|
153
|
+
for (let i = 0; i < coLocated.length; i++) {
|
|
154
|
+
for (let j = i + 1; j < coLocated.length; j++) {
|
|
155
|
+
const a = coLocated[i]!
|
|
156
|
+
const b = coLocated[j]!
|
|
157
|
+
|
|
158
|
+
if (haversineKm(npiCoord.get(a)!, npiCoord.get(b)!) > COLOCATION_KM) continue
|
|
159
|
+
|
|
160
|
+
if (jaccard(npiPrimary.get(a)!.tokens, npiPrimary.get(b)!.tokens) >= ORG_TAU) {
|
|
161
|
+
uf.union(a, b)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return (rec) => (npiPrimary.has(rec.id) ? uf.find(rec.id) : rec.id)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The H3-cell org-name truth — the same building grain keyed on a cell instead of a radius, so co-location blocking is
|
|
171
|
+
* O(n) rather than O(n²).
|
|
172
|
+
*
|
|
173
|
+
* A robustness check on the coordinate grain, not a replacement: a hard cell boundary can split a same-building pair
|
|
174
|
+
* into adjacent cells, so this slightly UNDER-counts relative to the radius. Coarser resolutions absorb more of that.
|
|
175
|
+
*/
|
|
176
|
+
export function buildOrgNameH3Grain(
|
|
177
|
+
npiPrimary: Map<string, NPIPrimary>,
|
|
178
|
+
npiCoord: Map<string, LatLon>,
|
|
179
|
+
h3Res: number
|
|
180
|
+
): TruthLabel {
|
|
181
|
+
const uf = createUnionFind()
|
|
182
|
+
const byCell = new Map<string, string[]>()
|
|
183
|
+
|
|
184
|
+
for (const n of npiPrimary.keys()) {
|
|
185
|
+
uf.find(n) // seed every NPI (un-geocoded ones stay singletons)
|
|
186
|
+
const c = npiCoord.get(n)
|
|
187
|
+
|
|
188
|
+
if (!c) continue
|
|
189
|
+
const cell = latLngToCell(c.latitude, c.longitude, h3Res)
|
|
190
|
+
|
|
191
|
+
if (!byCell.has(cell)) {
|
|
192
|
+
byCell.set(cell, [])
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
byCell.get(cell)!.push(n)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
unionAgreeingPairs(byCell.values(), npiPrimary, uf)
|
|
199
|
+
|
|
200
|
+
return (rec) => (npiPrimary.has(rec.id) ? uf.find(rec.id) : rec.id)
|
|
201
|
+
}
|