@mailwoman/registry 10.0.0 → 10.1.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 +10 -10
- package/lib/address-key.ts +14 -10
- package/lib/geocode-handler.ts +6 -4
- package/lib/geojson.ts +11 -6
- package/lib/ingest.ts +57 -83
- package/lib/learned-scorer.ts +38 -44
- package/lib/map-html.ts +24 -70
- package/lib/models/crosssource-gbt-en-us.ts +9 -7
- package/lib/models/dedup-gbt-en-us.ts +9 -8
- package/lib/models/org-crosssource-gbt-en-us.ts +10 -8
- package/lib/reconcile.ts +43 -53
- package/lib/resolve.ts +180 -124
- package/lib/types.ts +18 -12
- package/out/address-key.d.ts +14 -10
- package/out/address-key.d.ts.map +1 -1
- package/out/address-key.js +14 -10
- package/out/address-key.js.map +1 -1
- package/out/geocode-handler.d.ts +6 -4
- package/out/geocode-handler.d.ts.map +1 -1
- package/out/geocode-handler.js +6 -4
- package/out/geocode-handler.js.map +1 -1
- package/out/geojson.d.ts +9 -5
- package/out/geojson.d.ts.map +1 -1
- package/out/geojson.js +11 -6
- package/out/geojson.js.map +1 -1
- package/out/ingest.d.ts +46 -75
- package/out/ingest.d.ts.map +1 -1
- package/out/ingest.js +27 -54
- package/out/ingest.js.map +1 -1
- package/out/learned-scorer.d.ts +29 -26
- package/out/learned-scorer.d.ts.map +1 -1
- package/out/learned-scorer.js +31 -39
- package/out/learned-scorer.js.map +1 -1
- package/out/map-html.d.ts +13 -32
- package/out/map-html.d.ts.map +1 -1
- package/out/map-html.js +9 -62
- package/out/map-html.js.map +1 -1
- package/out/models/crosssource-gbt-en-us.d.ts +9 -7
- package/out/models/crosssource-gbt-en-us.d.ts.map +1 -1
- package/out/models/crosssource-gbt-en-us.js +9 -7
- package/out/models/crosssource-gbt-en-us.js.map +1 -1
- package/out/models/dedup-gbt-en-us.d.ts +9 -8
- package/out/models/dedup-gbt-en-us.d.ts.map +1 -1
- package/out/models/dedup-gbt-en-us.js +9 -8
- package/out/models/dedup-gbt-en-us.js.map +1 -1
- package/out/models/org-crosssource-gbt-en-us.d.ts +10 -8
- package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -1
- package/out/models/org-crosssource-gbt-en-us.js +10 -8
- package/out/models/org-crosssource-gbt-en-us.js.map +1 -1
- package/out/reconcile.d.ts +35 -50
- package/out/reconcile.d.ts.map +1 -1
- package/out/reconcile.js +17 -41
- package/out/reconcile.js.map +1 -1
- package/out/resolve.d.ts +150 -90
- package/out/resolve.d.ts.map +1 -1
- package/out/resolve.js +62 -63
- package/out/resolve.js.map +1 -1
- package/out/tools/coverage-reconciliation.d.ts +23 -23
- package/out/tools/coverage-reconciliation.d.ts.map +1 -1
- package/out/tools/coverage-reconciliation.js +15 -26
- package/out/tools/coverage-reconciliation.js.map +1 -1
- package/out/tools/cross/dataset-correlation.d.ts +20 -27
- package/out/tools/cross/dataset-correlation.d.ts.map +1 -1
- package/out/tools/cross/dataset-correlation.js +9 -61
- package/out/tools/cross/dataset-correlation.js.map +1 -1
- package/out/tools/cross/source-threshold-sweep.d.ts +20 -26
- package/out/tools/cross/source-threshold-sweep.d.ts.map +1 -1
- package/out/tools/cross/source-threshold-sweep.js +14 -40
- package/out/tools/cross/source-threshold-sweep.js.map +1 -1
- package/out/tools/dedup-ceiling.d.ts +23 -26
- package/out/tools/dedup-ceiling.d.ts.map +1 -1
- package/out/tools/dedup-ceiling.js +22 -41
- package/out/tools/dedup-ceiling.js.map +1 -1
- package/out/tools/eval-geocoder.d.ts +22 -15
- package/out/tools/eval-geocoder.d.ts.map +1 -1
- package/out/tools/eval-geocoder.js +5 -6
- package/out/tools/eval-geocoder.js.map +1 -1
- package/out/tools/geocoder/namesake-probe.d.ts +9 -8
- package/out/tools/geocoder/namesake-probe.d.ts.map +1 -1
- package/out/tools/geocoder/namesake-probe.js +6 -7
- package/out/tools/geocoder/namesake-probe.js.map +1 -1
- package/out/tools/geocoder/vs-provided-coords.d.ts +18 -15
- package/out/tools/geocoder/vs-provided-coords.d.ts.map +1 -1
- package/out/tools/geocoder/vs-provided-coords.js +30 -27
- package/out/tools/geocoder/vs-provided-coords.js.map +1 -1
- package/out/tools/gold-set-sample.d.ts +27 -18
- package/out/tools/gold-set-sample.d.ts.map +1 -1
- package/out/tools/gold-set-sample.js +18 -22
- package/out/tools/gold-set-sample.js.map +1 -1
- package/out/tools/learned/scorer/clustering-eval.d.ts +30 -27
- package/out/tools/learned/scorer/clustering-eval.d.ts.map +1 -1
- package/out/tools/learned/scorer/clustering-eval.js +28 -38
- package/out/tools/learned/scorer/clustering-eval.js.map +1 -1
- package/out/tools/learned/scorer/crossstate-eval.d.ts +24 -18
- package/out/tools/learned/scorer/crossstate-eval.d.ts.map +1 -1
- package/out/tools/learned/scorer/crossstate-eval.js +19 -25
- package/out/tools/learned/scorer/crossstate-eval.js.map +1 -1
- package/out/tools/learned/scorer/eval.d.ts +22 -39
- package/out/tools/learned/scorer/eval.d.ts.map +1 -1
- package/out/tools/learned/scorer/eval.js +11 -71
- package/out/tools/learned/scorer/eval.js.map +1 -1
- package/out/tools/matcher-scale.d.ts +12 -17
- package/out/tools/matcher-scale.d.ts.map +1 -1
- package/out/tools/matcher-scale.js +11 -29
- package/out/tools/matcher-scale.js.map +1 -1
- package/out/tools/nppes/dedup-benchmark.d.ts +21 -41
- package/out/tools/nppes/dedup-benchmark.d.ts.map +1 -1
- package/out/tools/nppes/dedup-benchmark.js +20 -66
- package/out/tools/nppes/dedup-benchmark.js.map +1 -1
- package/out/tools/nppes/org-name.d.ts +5 -4
- package/out/tools/nppes/org-name.d.ts.map +1 -1
- package/out/tools/nppes/org-name.js +2 -2
- package/out/tools/nppes/org-name.js.map +1 -1
- package/out/tools/nppes/overmerge-packet.d.ts +15 -11
- package/out/tools/nppes/overmerge-packet.d.ts.map +1 -1
- package/out/tools/nppes/overmerge-packet.js +5 -6
- package/out/tools/nppes/overmerge-packet.js.map +1 -1
- package/out/tools/nppes/report.d.ts +17 -13
- package/out/tools/nppes/report.d.ts.map +1 -1
- package/out/tools/nppes/report.js +6 -14
- package/out/tools/nppes/report.js.map +1 -1
- package/out/tools/nppes/sample.d.ts +28 -17
- package/out/tools/nppes/sample.d.ts.map +1 -1
- package/out/tools/nppes/sample.js +23 -26
- package/out/tools/nppes/sample.js.map +1 -1
- package/out/tools/nppes/scoring.d.ts +7 -6
- package/out/tools/nppes/scoring.d.ts.map +1 -1
- package/out/tools/nppes/scoring.js +6 -5
- package/out/tools/nppes/scoring.js.map +1 -1
- package/out/tools/nppes/settings.d.ts +10 -7
- package/out/tools/nppes/settings.d.ts.map +1 -1
- package/out/tools/nppes/settings.js +16 -16
- package/out/tools/nppes/settings.js.map +1 -1
- package/out/tools/nppes/truth-grains.d.ts +36 -23
- package/out/tools/nppes/truth-grains.d.ts.map +1 -1
- package/out/tools/nppes/truth-grains.js +36 -20
- package/out/tools/nppes/truth-grains.js.map +1 -1
- package/out/tools/shared.d.ts +63 -59
- package/out/tools/shared.d.ts.map +1 -1
- package/out/tools/shared.js +49 -66
- package/out/tools/shared.js.map +1 -1
- package/out/tools/train/cross-gbt.d.ts +36 -26
- package/out/tools/train/cross-gbt.d.ts.map +1 -1
- package/out/tools/train/cross-gbt.js +14 -25
- package/out/tools/train/cross-gbt.js.map +1 -1
- package/out/tools/train/gbt.d.ts +36 -20
- package/out/tools/train/gbt.d.ts.map +1 -1
- package/out/tools/train/gbt.js +27 -31
- package/out/tools/train/gbt.js.map +1 -1
- package/out/tools/train/org-cross-gbt.d.ts +37 -24
- package/out/tools/train/org-cross-gbt.d.ts.map +1 -1
- package/out/tools/train/org-cross-gbt.js +18 -22
- package/out/tools/train/org-cross-gbt.js.map +1 -1
- package/out/tools/txhhsc-to-oarow.d.ts +14 -9
- package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
- package/out/tools/txhhsc-to-oarow.js +16 -15
- package/out/tools/txhhsc-to-oarow.js.map +1 -1
- package/out/tools/viz/browser.d.ts +6 -5
- package/out/tools/viz/browser.d.ts.map +1 -1
- package/out/tools/viz/browser.js +6 -5
- package/out/tools/viz/browser.js.map +1 -1
- package/out/tools/viz/cross-dataset-map.d.ts +7 -4
- package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
- package/out/tools/viz/cross-dataset-map.js +9 -6
- package/out/tools/viz/cross-dataset-map.js.map +1 -1
- package/out/tools/viz/geocode-first-surface.d.ts +10 -5
- package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
- package/out/tools/viz/geocode-first-surface.js +16 -11
- package/out/tools/viz/geocode-first-surface.js.map +1 -1
- package/out/tools/viz/render/map.d.ts +5 -5
- package/out/tools/viz/render/map.d.ts.map +1 -1
- package/out/tools/viz/render/map.js +6 -5
- package/out/tools/viz/render/map.js.map +1 -1
- package/out/tools/viz/{render/index.d.ts → render.d.ts} +13 -9
- package/out/tools/viz/render.d.ts.map +1 -0
- package/out/tools/viz/{render/index.js → render.js} +9 -8
- package/out/tools/viz/render.js.map +1 -0
- package/out/tools/viz/source-provenance-map.d.ts +19 -7
- package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
- package/out/tools/viz/source-provenance-map.js +11 -8
- package/out/tools/viz/source-provenance-map.js.map +1 -1
- package/out/tools/viz/yardstick-figure.d.ts +2 -21
- package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
- package/out/tools/viz/yardstick-figure.js +3 -39
- package/out/tools/viz/yardstick-figure.js.map +1 -1
- package/out/types.d.ts +17 -11
- package/out/types.d.ts.map +1 -1
- package/out/types.js +2 -2
- package/out/types.js.map +1 -1
- package/package.json +41 -184
- package/{lib/tools → tools}/coverage-reconciliation.ts +27 -30
- package/{lib/tools → tools}/cross/dataset-correlation.ts +31 -72
- package/{lib/tools → tools}/cross/source-threshold-sweep.ts +29 -46
- package/{lib/tools → tools}/dedup-ceiling.ts +34 -45
- package/tools/eval-geocoder.ts +74 -0
- package/{lib/tools → tools}/geocoder/namesake-probe.ts +9 -8
- package/{lib/tools → tools}/geocoder/vs-provided-coords.ts +39 -30
- package/{lib/tools → tools}/gold-set-sample.ts +35 -29
- package/{lib/tools → tools}/learned/scorer/clustering-eval.ts +49 -45
- package/{lib/tools → tools}/learned/scorer/crossstate-eval.ts +34 -30
- package/{lib/tools → tools}/learned/scorer/eval.ts +35 -78
- package/{lib/tools → tools}/matcher-scale.ts +21 -33
- package/{lib/tools → tools}/nppes/dedup-benchmark.ts +37 -82
- package/{lib/tools → tools}/nppes/org-name.ts +5 -4
- package/{lib/tools → tools}/nppes/overmerge-packet.ts +15 -11
- package/{lib/tools → tools}/nppes/report.ts +32 -25
- package/{lib/tools → tools}/nppes/sample.ts +41 -36
- package/{lib/tools → tools}/nppes/scoring.ts +7 -6
- package/{lib/tools → tools}/nppes/settings.ts +16 -16
- package/{lib/tools → tools}/nppes/truth-grains.ts +46 -26
- package/{lib/tools → tools}/shared.ts +73 -83
- package/{lib/tools → tools}/train/cross-gbt.ts +38 -34
- package/{lib/tools → tools}/train/gbt.ts +55 -41
- package/{lib/tools → tools}/train/org-cross-gbt.ts +39 -30
- package/{lib/tools → tools}/txhhsc-to-oarow.ts +24 -18
- package/{lib/tools → tools}/viz/browser.ts +6 -5
- package/{lib/tools → tools}/viz/cross-dataset-map.ts +15 -9
- package/{lib/tools → tools}/viz/geocode-first-surface.ts +28 -17
- package/{lib/tools → tools}/viz/render/map.ts +7 -6
- package/{lib/tools/viz/render/index.ts → tools/viz/render.ts} +16 -11
- package/{lib/tools → tools}/viz/source-provenance-map.ts +30 -15
- package/{lib/tools → tools}/viz/yardstick-figure.ts +6 -43
- package/lib/tools/eval-geocoder.ts +0 -67
- package/lib/tools/index.ts +0 -31
- package/out/tools/index.d.ts +0 -31
- package/out/tools/index.d.ts.map +0 -1
- package/out/tools/index.js +0 -31
- package/out/tools/index.js.map +0 -1
- package/out/tools/viz/render/index.d.ts.map +0 -1
- package/out/tools/viz/render/index.js.map +0 -1
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
* @file
|
|
6
|
-
*
|
|
5
|
+
* @file Defines union-find truth labels that group co-located NPIs for one organization.
|
|
6
|
+
* One label uses address strings. Another uses a haversine radius. The third uses H3 cells.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { createUnionFind, type UnionFind } from "@mailwoman/core/utils"
|
|
10
|
-
import { haversineKm, jaccard
|
|
10
|
+
import { haversineKm, jaccard } from "@mailwoman/match"
|
|
11
|
+
import type { GeoCoordinate } from "@mailwoman/spatial"
|
|
11
12
|
import { latLngToCell } from "h3-js"
|
|
12
13
|
|
|
13
14
|
import type { SourceRecord } from "#index"
|
|
@@ -19,15 +20,18 @@ import { ORG_TAU, type NPIPrimary } from "#tools/nppes/org-name"
|
|
|
19
20
|
export const COLOCATION_KM = 0.05
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
|
-
* A truth
|
|
23
|
+
* A truth labeling: the entity class a record belongs to.
|
|
23
24
|
*/
|
|
24
25
|
export type TruthLabel = (rec: SourceRecord) => string
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Union every pair in each block whose org names agree.
|
|
28
29
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
30
|
+
* Checks every pair within a block.
|
|
31
|
+
* This preserves the per-pair Jaccard test.
|
|
32
|
+
*
|
|
33
|
+
* Therefore, a chain of near-matches cannot transitively fuse two genuinely distinct
|
|
34
|
+
* co-located orgs unless some pair actually agrees.
|
|
31
35
|
*/
|
|
32
36
|
function unionAgreeingPairs(
|
|
33
37
|
blocks: Iterable<readonly string[]>,
|
|
@@ -46,11 +50,13 @@ function unionAgreeingPairs(
|
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
/**
|
|
49
|
-
* An NPI's primary practice coordinate
|
|
50
|
-
*
|
|
53
|
+
* An NPI's primary practice coordinate.
|
|
54
|
+
*
|
|
55
|
+
* Returns the first geocoded record for the NPI.
|
|
56
|
+
* The sample builder adds this primary row before alternate-name and mailing variants.
|
|
51
57
|
*/
|
|
52
|
-
export function collectPrimaryCoordinates(records: readonly SourceRecord[]): Map<string,
|
|
53
|
-
const npiCoord = new Map<string,
|
|
58
|
+
export function collectPrimaryCoordinates(records: readonly SourceRecord[]): Map<string, GeoCoordinate> {
|
|
59
|
+
const npiCoord = new Map<string, GeoCoordinate>()
|
|
54
60
|
|
|
55
61
|
for (const rec of records) {
|
|
56
62
|
const c = rec.address?.geocode?.coordinate
|
|
@@ -64,12 +70,17 @@ export function collectPrimaryCoordinates(records: readonly SourceRecord[]): Map
|
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
/**
|
|
67
|
-
* The string-keyed org-name truth: same NPI ⇒ same entity
|
|
68
|
-
*
|
|
73
|
+
* The string-keyed org-name truth: same NPI ⇒ same entity
|
|
74
|
+
* (so an NPI's records stay together and recall is preserved), plus union two NPIs
|
|
75
|
+
* at the same address KEY whose primary org names agree.
|
|
69
76
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
77
|
+
* The address-string block provides a conservative lower bound.
|
|
78
|
+
* `1504 Taub loop` and `1504 Taub LP STE 100` key apart even though they are one building,
|
|
79
|
+
* so a correct merge across them is still charged as an error.
|
|
80
|
+
* The coordinate grain below is the tighter reading.
|
|
81
|
+
*
|
|
82
|
+
* Neither method uses the NPPES subpart flag.
|
|
83
|
+
* The gold set misses 37% of cases when grouped by that flag.
|
|
73
84
|
*/
|
|
74
85
|
export function buildOrgNameGrain(npiPrimary: Map<string, NPIPrimary>): TruthLabel {
|
|
75
86
|
const uf = createUnionFind()
|
|
@@ -94,14 +105,20 @@ export function buildOrgNameGrain(npiPrimary: Map<string, NPIPrimary>): TruthLab
|
|
|
94
105
|
}
|
|
95
106
|
|
|
96
107
|
/**
|
|
97
|
-
* The coordinate-keyed org-name truth: union same-org NPIs whose primary practice
|
|
98
|
-
* {@linkcode COLOCATION_KM}.
|
|
99
|
-
*
|
|
108
|
+
* The coordinate-keyed org-name truth: union same-org NPIs whose primary practice
|
|
109
|
+
* coordinates fall within {@linkcode COLOCATION_KM}.
|
|
110
|
+
*
|
|
111
|
+
* A geocoded-building block catches same-building pairs that the address string keys apart,
|
|
112
|
+
* so this F1 is at or above the string grain's.
|
|
113
|
+
* The Jaccard test still blocks distinct co-located orgs.
|
|
100
114
|
*
|
|
101
|
-
*
|
|
102
|
-
* artifact.
|
|
115
|
+
* Compares every sampled NPI pair.
|
|
116
|
+
* This is small enough for the sample and has no cell-boundary artifact.
|
|
103
117
|
*/
|
|
104
|
-
export function buildOrgNameCoordGrain(
|
|
118
|
+
export function buildOrgNameCoordGrain(
|
|
119
|
+
npiPrimary: Map<string, NPIPrimary>,
|
|
120
|
+
npiCoord: Map<string, GeoCoordinate>
|
|
121
|
+
): TruthLabel {
|
|
105
122
|
const uf = createUnionFind()
|
|
106
123
|
const coLocated = [...npiPrimary.keys()].filter((n) => npiCoord.has(n))
|
|
107
124
|
|
|
@@ -127,15 +144,18 @@ export function buildOrgNameCoordGrain(npiPrimary: Map<string, NPIPrimary>, npiC
|
|
|
127
144
|
}
|
|
128
145
|
|
|
129
146
|
/**
|
|
130
|
-
* The H3-cell org-name truth
|
|
131
|
-
*
|
|
147
|
+
* The H3-cell org-name truth.
|
|
148
|
+
*
|
|
149
|
+
* The same building grain keyed on a cell instead of a radius, so co-location
|
|
150
|
+
* blocking is O(n) rather than O(n²).
|
|
132
151
|
*
|
|
133
|
-
* A robustness check on the coordinate grain
|
|
134
|
-
* into adjacent cells, so this slightly
|
|
152
|
+
* A robustness check on the coordinate grain rather than a replacement: a hard cell boundary can split
|
|
153
|
+
* a same-building pair into adjacent cells, so this slightly under-counts relative to the radius.
|
|
154
|
+
* Coarser resolutions absorb more of that.
|
|
135
155
|
*/
|
|
136
156
|
export function buildOrgNameH3Grain(
|
|
137
157
|
npiPrimary: Map<string, NPIPrimary>,
|
|
138
|
-
npiCoord: Map<string,
|
|
158
|
+
npiCoord: Map<string, GeoCoordinate>,
|
|
139
159
|
h3Res: number
|
|
140
160
|
): TruthLabel {
|
|
141
161
|
const uf = createUnionFind()
|
|
@@ -3,13 +3,11 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* Shared helpers
|
|
7
|
-
*
|
|
8
|
-
* The rule: anything reused by two or more probes belongs here; anything a single probe needs
|
|
9
|
-
* stays with that probe.
|
|
6
|
+
* Shared helpers used by two or more probes in the `registry/tools` probe battery.
|
|
10
7
|
*/
|
|
11
8
|
|
|
12
9
|
import { makeDirectories, writeLocalFile } from "@mailwoman/core/fs/writers"
|
|
10
|
+
import { stringifyJSON } from "@mailwoman/core/json"
|
|
13
11
|
import { isPresent } from "@mailwoman/core/objects"
|
|
14
12
|
import { makeLcg } from "@mailwoman/core/random"
|
|
15
13
|
import { block, gbtScore, trainGBT, type TermFrequencyTable } from "@mailwoman/match"
|
|
@@ -30,7 +28,10 @@ import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
|
|
|
30
28
|
import type { Score } from "#tools/nppes/scoring"
|
|
31
29
|
|
|
32
30
|
/**
|
|
33
|
-
* One source a cross-source probe ingests
|
|
31
|
+
* One source a cross-source probe ingests.
|
|
32
|
+
*
|
|
33
|
+
* Its spec gives the path and column mapping.
|
|
34
|
+
* The spec also provides an in-state filter.
|
|
34
35
|
*/
|
|
35
36
|
export interface SourceSpec {
|
|
36
37
|
source: string
|
|
@@ -41,7 +42,8 @@ export interface SourceSpec {
|
|
|
41
42
|
*/
|
|
42
43
|
inState: (row: Record<string, string>) => boolean
|
|
43
44
|
/**
|
|
44
|
-
* Optional: a row
|
|
45
|
+
* Optional: a row carrying ≥1 addressable entity yields each as its own row.
|
|
46
|
+
* Default identity.
|
|
45
47
|
*/
|
|
46
48
|
explode?: (row: Record<string, string>) => Record<string, string>[]
|
|
47
49
|
}
|
|
@@ -52,8 +54,8 @@ export interface SourceSpec {
|
|
|
52
54
|
export const norm = (s: string | undefined): string => (s ?? "").trim()
|
|
53
55
|
|
|
54
56
|
/**
|
|
55
|
-
* Corporate-form suffixes and function words that
|
|
56
|
-
* tokens are compared, so the domain words
|
|
57
|
+
* Corporate-form suffixes and function words that add no identity — dropped from an organization name
|
|
58
|
+
* before its tokens are compared, so the domain words include the distinguishing signal.
|
|
57
59
|
*/
|
|
58
60
|
const ORGANIZATION_STOP_WORDS = new Set([
|
|
59
61
|
"llc",
|
|
@@ -74,11 +76,8 @@ const ORGANIZATION_STOP_WORDS = new Set([
|
|
|
74
76
|
])
|
|
75
77
|
|
|
76
78
|
/**
|
|
77
|
-
* The token set of an organization name
|
|
78
|
-
*
|
|
79
|
-
* NOT a canonical form — `@mailwoman/record`'s `canonicalizeOrganizationName` is the stronger canonical key
|
|
80
|
-
* (jurisdiction-aware designation stripping, a DBA split). This set serves the probes' cheap Jaccard overlap over raw
|
|
81
|
-
* registry names, never blocking or display.
|
|
79
|
+
* The token set of an organization name for the probes' cheap Jaccard overlap,
|
|
80
|
+
* never blocking or display — not a canonical form.
|
|
82
81
|
*/
|
|
83
82
|
export function orgTokens(s: string): Set<string> {
|
|
84
83
|
return new Set(
|
|
@@ -97,7 +96,8 @@ export const addr = (line: string, city: string, st: string, zip: string): strin
|
|
|
97
96
|
[norm(line), norm(city), norm(st), norm(zip)].filter(isPresent).join(", ")
|
|
98
97
|
|
|
99
98
|
/**
|
|
100
|
-
* Population standard deviation; `0` on an empty sample, because these feed
|
|
99
|
+
* Population standard deviation; `0` on an empty sample, because these feed
|
|
100
|
+
* report tables that print a number per row.
|
|
101
101
|
*/
|
|
102
102
|
export const std = (xs: readonly number[]): number => {
|
|
103
103
|
const m = xs.reduce((a, b) => a + b, 0) / Math.max(1, xs.length)
|
|
@@ -105,18 +105,21 @@ export const std = (xs: readonly number[]): number => {
|
|
|
105
105
|
return Math.sqrt(xs.map((x) => (x - m) ** 2).reduce((a, b) => a + b, 0) / Math.max(1, xs.length))
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Takes a fraction and omits the percent sign, unlike core `formatPercent`'s
|
|
110
|
+
* numerator/denominator interface.
|
|
111
|
+
* Call sites append their own `%`.
|
|
112
|
+
*/
|
|
110
113
|
export const pct = (x: number): string => (100 * x).toFixed(1)
|
|
111
114
|
|
|
112
115
|
/**
|
|
113
|
-
* Sign prefix for a signed delta
|
|
116
|
+
* Sign prefix for a signed delta: `"+"` for a non-negative value, since a negative one includes its sign.
|
|
114
117
|
*/
|
|
115
118
|
export const sgn = (x: number): string => (x >= 0 ? "+" : "")
|
|
116
119
|
|
|
117
120
|
/**
|
|
118
|
-
* Logistic function with the input clamped to
|
|
119
|
-
* silently becomes a no-op.
|
|
121
|
+
* Logistic function with the input clamped to ±30, past which `Math.exp` underflows to 0
|
|
122
|
+
* and the gradient step silently becomes a no-op.
|
|
120
123
|
*/
|
|
121
124
|
export const sigmoid = (z: number): number => 1 / (1 + Math.exp(-Math.max(-30, Math.min(30, z))))
|
|
122
125
|
|
|
@@ -137,14 +140,8 @@ export const inTXBBOX = (lat: number, lon: number): boolean =>
|
|
|
137
140
|
lat >= TX_BBOX.latMin && lat <= TX_BBOX.latMax && lon >= TX_BBOX.lonMin && lon <= TX_BBOX.lonMax
|
|
138
141
|
|
|
139
142
|
/**
|
|
140
|
-
* NPPES registry column headers, by the short name the probes read them under.
|
|
141
|
-
*
|
|
142
|
-
* The NPI registry export is a ~330-column TSV with headers this long, so every probe that touches it needs this map,
|
|
143
|
-
* and five of them had grown their own copy. The copies were a NESTED SUPERSET chain, not a disagreement -- each new
|
|
144
|
-
* probe took the previous one's map and appended what it additionally read -- so this is the widest of the five, and no
|
|
145
|
-
* consumer loses a column. Reading extra keys costs nothing: they are inert strings, and nothing enumerates this object
|
|
146
|
-
* (checked: no `Object.keys`/`values`/`entries`/spread over it anywhere in `tools/`), so adding a column can never
|
|
147
|
-
* change a probe's behavior.
|
|
143
|
+
* NPPES registry column headers, by the short name the probes read them under. no code
|
|
144
|
+
* enumerates this object, so adding a column cannot change a probe's behavior.
|
|
148
145
|
*/
|
|
149
146
|
export const NPPES_COLUMNS = {
|
|
150
147
|
npi: "NPI",
|
|
@@ -167,7 +164,8 @@ export const NPPES_COLUMNS = {
|
|
|
167
164
|
isSubpart: "Is Organization Subpart",
|
|
168
165
|
parentLBN: "Parent Organization LBN",
|
|
169
166
|
parentTIN: "Parent Organization TIN",
|
|
170
|
-
//
|
|
167
|
+
// The 15 taxonomy slots.
|
|
168
|
+
// Any shared code counts as agreement.
|
|
171
169
|
taxonomy: Array.from({ length: 15 }, (_, i) => `Healthcare Provider Taxonomy Code_${i + 1}`),
|
|
172
170
|
}
|
|
173
171
|
|
|
@@ -177,13 +175,14 @@ export const NPPES_COLUMNS = {
|
|
|
177
175
|
export const MIN_GROUP_SIZE = 5
|
|
178
176
|
|
|
179
177
|
/**
|
|
180
|
-
* Gradient-descent epochs for {@link trainLogisticRegression}
|
|
178
|
+
* Gradient-descent epochs for {@link trainLogisticRegression}, fixed
|
|
179
|
+
* rather than early-stopped so seeds stay comparable.
|
|
181
180
|
*/
|
|
182
181
|
export const TRAINING_EPOCHS = 400
|
|
183
182
|
|
|
184
183
|
/**
|
|
185
|
-
* Smallest mean F1 gap counted as a real difference between models rather than seed
|
|
186
|
-
* reported as a tie.
|
|
184
|
+
* Smallest mean F1 gap counted as a real difference between models rather than seed
|
|
185
|
+
* noise. verdicts inside ±this are reported as a tie.
|
|
187
186
|
*/
|
|
188
187
|
export const MIN_MEANINGFUL_F1_DELTA = 0.02
|
|
189
188
|
|
|
@@ -198,9 +197,9 @@ export const LR_LEARNING_RATE = 0.1
|
|
|
198
197
|
export const LR_L2 = 1e-3
|
|
199
198
|
|
|
200
199
|
/**
|
|
201
|
-
* L2-regularized logistic regression by batch gradient descent
|
|
202
|
-
*
|
|
203
|
-
*
|
|
200
|
+
* L2-regularized logistic regression by batch gradient descent over {@link TRAINING_EPOCHS}
|
|
201
|
+
* epochs, where `w` stores per-sample class weights, returning the logit rather than
|
|
202
|
+
* the probability so it is threshold-comparable across a fixed feature layout.
|
|
204
203
|
*/
|
|
205
204
|
export function trainLogisticRegression(
|
|
206
205
|
X: readonly (readonly number[])[],
|
|
@@ -250,9 +249,11 @@ export function trainLogisticRegression(
|
|
|
250
249
|
}
|
|
251
250
|
|
|
252
251
|
/**
|
|
253
|
-
* `n + 1` evenly-spaced order statistics of an already-sorted sample, de-duplicated
|
|
254
|
-
* GBT node considers
|
|
255
|
-
*
|
|
252
|
+
* `n + 1` evenly-spaced order statistics of an already-sorted sample, de-duplicated,
|
|
253
|
+
* that a GBT node considers as candidate splits.
|
|
254
|
+
*
|
|
255
|
+
* An empty sample yields `[0]` so a degenerate feature still yields one threshold
|
|
256
|
+
* rather than an empty split set.
|
|
256
257
|
*/
|
|
257
258
|
export function uniqueQuantiles(sorted: readonly number[], n: number): number[] {
|
|
258
259
|
if (!sorted.length) return [0]
|
|
@@ -265,14 +266,11 @@ export function uniqueQuantiles(sorted: readonly number[], n: number): number[]
|
|
|
265
266
|
return [...ts]
|
|
266
267
|
}
|
|
267
268
|
|
|
268
|
-
/**
|
|
269
|
-
* Quantile points swept per learned-scorer arm.
|
|
270
|
-
*/
|
|
271
269
|
const THRESHOLD_QUANTILE_POINTS = 32
|
|
272
270
|
|
|
273
271
|
/**
|
|
274
|
-
* Link-threshold candidates for a learned scorer: de-duplicated quantiles of the
|
|
275
|
-
* distribution across the 0.2–0.999
|
|
272
|
+
* Link-threshold candidates for a learned scorer: de-duplicated quantiles of the
|
|
273
|
+
* scorer's own eval-pair score distribution across the 0.2–0.999 band.
|
|
276
274
|
*/
|
|
277
275
|
export const quantileThresholds = (scores: readonly number[]): number[] => {
|
|
278
276
|
const sorted = [...scores].toSorted((p, q) => p - q)
|
|
@@ -323,19 +321,18 @@ export function bestOver(thresholds: readonly number[], scoreAt: (threshold: num
|
|
|
323
321
|
}
|
|
324
322
|
|
|
325
323
|
/**
|
|
326
|
-
* One organization provider at its practice address, as the geocode-free co-location probes read it
|
|
327
|
-
* `dedup-ceiling` and `gold-set-sample` each collect.
|
|
324
|
+
* One organization provider at its practice address, as the geocode-free co-location probes read it.
|
|
328
325
|
*/
|
|
329
326
|
export interface ColocatedProvider {
|
|
330
327
|
npi: string
|
|
331
328
|
org: string
|
|
332
329
|
tokens: Set<string>
|
|
333
330
|
/**
|
|
334
|
-
* The composed practice address ({@link addr})
|
|
331
|
+
* The composed practice address ({@link addr}).
|
|
335
332
|
*/
|
|
336
333
|
address: string
|
|
337
334
|
/**
|
|
338
|
-
* Strict last-10-digit phone key; `""` when the column
|
|
335
|
+
* Strict last-10-digit phone key; `""` when the column contains fewer than 10 digits.
|
|
339
336
|
*/
|
|
340
337
|
phone: string
|
|
341
338
|
/**
|
|
@@ -348,7 +345,7 @@ export interface ColocatedProvider {
|
|
|
348
345
|
taxonomy: string
|
|
349
346
|
subpart: boolean
|
|
350
347
|
/**
|
|
351
|
-
* `parentLBN|parentTIN`, lowercased
|
|
348
|
+
* `parentLBN|parentTIN`, lowercased; `"|"` when both are blank.
|
|
352
349
|
*/
|
|
353
350
|
parent: string
|
|
354
351
|
}
|
|
@@ -366,8 +363,9 @@ export interface ColocatedScan {
|
|
|
366
363
|
}
|
|
367
364
|
|
|
368
365
|
/**
|
|
369
|
-
* Stream in-state type-2 (organization) providers from the registry
|
|
370
|
-
*
|
|
366
|
+
* Stream in-state type-2 (organization) providers from the registry,
|
|
367
|
+
* one record per row at its practice address, grouped by `addressFrequencyKey`;
|
|
368
|
+
* geocode-free on purpose so it runs at large caps in seconds.
|
|
371
369
|
*/
|
|
372
370
|
export async function scanColocatedProviders(options: {
|
|
373
371
|
registryPath: string
|
|
@@ -428,15 +426,15 @@ export interface ColocatedPair {
|
|
|
428
426
|
a: ColocatedProvider
|
|
429
427
|
b: ColocatedProvider
|
|
430
428
|
/**
|
|
431
|
-
* The distinct-NPI providers at the shared address, length ≥ 2
|
|
432
|
-
* group
|
|
429
|
+
* The distinct-NPI providers at the shared address, length ≥ 2, one array reference
|
|
430
|
+
* per group so a consumer can detect the group boundary by identity.
|
|
433
431
|
*/
|
|
434
432
|
group: readonly ColocatedProvider[]
|
|
435
433
|
}
|
|
436
434
|
|
|
437
435
|
/**
|
|
438
|
-
* Every unordered pair of
|
|
439
|
-
*
|
|
436
|
+
* Every unordered pair of distinct NPIs sharing a practice-address key, de-duplicated
|
|
437
|
+
* per address by NPI (first record wins) so single-NPI addresses yield no pair.
|
|
440
438
|
*/
|
|
441
439
|
export function* colocatedDistinctPairs(
|
|
442
440
|
byAddr: ReadonlyMap<string, readonly ColocatedProvider[]>
|
|
@@ -462,8 +460,7 @@ export function* colocatedDistinctPairs(
|
|
|
462
460
|
}
|
|
463
461
|
|
|
464
462
|
/**
|
|
465
|
-
* The TX facility source specs the cross-source probes share.
|
|
466
|
-
* commitments spec (the exploded two-entity-per-row source).
|
|
463
|
+
* The TX facility source specs the cross-source probes share.
|
|
467
464
|
*/
|
|
468
465
|
export const buildSpecs = (S: string, STATE: string): SourceSpec[] => [
|
|
469
466
|
{
|
|
@@ -518,19 +515,15 @@ export interface GBTHyperparameters {
|
|
|
518
515
|
minLeaf: number
|
|
519
516
|
}
|
|
520
517
|
|
|
521
|
-
/**
|
|
522
|
-
* The compact pure-Node GBT configuration the cross-source trainers fit with.
|
|
523
|
-
*/
|
|
524
518
|
const CROSS_SOURCE_HYPERPARAMS: GBTHyperparameters = { rounds: 120, depth: 3, lr: 0.3, minLeaf: 20 }
|
|
525
519
|
|
|
526
|
-
/**
|
|
527
|
-
* Share of join keys assigned to fit during calibration; the rest are held out.
|
|
528
|
-
*/
|
|
529
520
|
const FIT_SPLIT_FRACTION = 0.8
|
|
530
521
|
|
|
531
522
|
/**
|
|
532
|
-
* One assembled input row for a cross-source trainer.
|
|
533
|
-
*
|
|
523
|
+
* One assembled input row for a cross-source trainer.
|
|
524
|
+
*
|
|
525
|
+
* Its `npi` field contains the cross-system join key (an NPI or a CCN).
|
|
526
|
+
* The trainer copies that key into `record.id` as the held-out label.
|
|
534
527
|
*/
|
|
535
528
|
export interface CrossSourceRow extends Record<string, string> {
|
|
536
529
|
npi: string
|
|
@@ -541,7 +534,7 @@ export interface CrossSourceRow extends Record<string, string> {
|
|
|
541
534
|
}
|
|
542
535
|
|
|
543
536
|
/**
|
|
544
|
-
* Every figure
|
|
537
|
+
* Every figure passed to {@link TrainCrossSourceModelOptions.meta}.
|
|
545
538
|
*/
|
|
546
539
|
export interface CrossSourceTrainingFigures {
|
|
547
540
|
records: number
|
|
@@ -563,11 +556,12 @@ export interface TrainCrossSourceModelOptions {
|
|
|
563
556
|
*/
|
|
564
557
|
createGeocoder: EvalGeocoderFactory
|
|
565
558
|
/**
|
|
566
|
-
* The assembled two-source rows
|
|
559
|
+
* The assembled two-source rows.
|
|
560
|
+
* The caller owns source loading.
|
|
567
561
|
*/
|
|
568
562
|
rows: readonly CrossSourceRow[]
|
|
569
563
|
/**
|
|
570
|
-
* The join keys present in
|
|
564
|
+
* The join keys present in both sources.
|
|
571
565
|
*/
|
|
572
566
|
joined: ReadonlySet<string>
|
|
573
567
|
addressFrequency: TermFrequencyTable
|
|
@@ -576,7 +570,7 @@ export interface TrainCrossSourceModelOptions {
|
|
|
576
570
|
*/
|
|
577
571
|
sources: readonly [string, string]
|
|
578
572
|
/**
|
|
579
|
-
*
|
|
573
|
+
* Max cross-source recall subject to this held-out pairwise precision.
|
|
580
574
|
*/
|
|
581
575
|
precisionBar: number
|
|
582
576
|
/**
|
|
@@ -592,31 +586,30 @@ export interface TrainCrossSourceModelOptions {
|
|
|
592
586
|
*/
|
|
593
587
|
exportPrefix: string
|
|
594
588
|
/**
|
|
595
|
-
* Assemble the emitted `<prefix>_META` object.
|
|
596
|
-
*
|
|
589
|
+
* Assemble the emitted `<prefix>_META` object.
|
|
590
|
+
*
|
|
591
|
+
* The caller owns field names and order so a retrain diffs cleanly against its committed module.
|
|
597
592
|
*/
|
|
598
593
|
meta: (figures: CrossSourceTrainingFigures) => Record<string, unknown>
|
|
599
594
|
report?: (line: string) => void
|
|
600
595
|
}
|
|
601
596
|
|
|
602
597
|
/**
|
|
603
|
-
*
|
|
604
|
-
*
|
|
605
|
-
* inference
|
|
606
|
-
* and emit
|
|
598
|
+
* Geocode and ingest each source under its own provenance label, block the union,
|
|
599
|
+
* keep only cross-source candidate pairs, featurize with `createMatchFeaturizer` so train
|
|
600
|
+
* and inference agree, calibrate the threshold on a held-out split of the join keys,
|
|
601
|
+
* then train and emit the shipped model as a committed TS module.
|
|
607
602
|
*/
|
|
608
603
|
export async function trainCrossSourceModel(
|
|
609
604
|
options: TrainCrossSourceModelOptions
|
|
610
605
|
): Promise<{ out: string; pairs: number; recommendedThreshold: number }> {
|
|
611
606
|
const { rows, joined, addressFrequency, sources, precisionBar, out, report } = options
|
|
612
607
|
|
|
613
|
-
// Geocode and ingest records, carrying the join-key label in record.id and source on the record.
|
|
614
|
-
// heavy geocoder is injected (see ./eval-geocoder.ts). ---
|
|
615
608
|
report?.("[C] geocoding…")
|
|
616
609
|
const geocoder = await options.createGeocoder()
|
|
617
610
|
|
|
618
|
-
//
|
|
619
|
-
//
|
|
611
|
+
// Ingest each source separately to retain its literal provenance label on every record.
|
|
612
|
+
// The cross-source filter uses that label.
|
|
620
613
|
const mappingFor = (source: string): ColumnMapping => ({
|
|
621
614
|
id: "npi",
|
|
622
615
|
name: "name",
|
|
@@ -640,7 +633,6 @@ export async function trainCrossSourceModel(
|
|
|
640
633
|
geocoder[Symbol.dispose]()
|
|
641
634
|
report?.(` ${records.length} records, ${records.filter((r) => r.address?.geocode).length} geocoded`)
|
|
642
635
|
|
|
643
|
-
// Block the union, retain cross-source pairs, generate features, and label by join key.
|
|
644
636
|
report?.("[D] blocking + featurizing (cross-source pairs only)…")
|
|
645
637
|
const comparisons = buildDefaultModel({ collapseSpatial: true, addressFrequency }).comparisons
|
|
646
638
|
const featurize = createMatchFeaturizer({ comparisons, addressFrequency })
|
|
@@ -655,7 +647,6 @@ export async function trainCrossSourceModel(
|
|
|
655
647
|
` ${allPairs.length} blocked pairs → ${pairs.length} cross-source (${(100 * posRate).toFixed(1)}% positive)`
|
|
656
648
|
)
|
|
657
649
|
|
|
658
|
-
// Calibrate the threshold against held-out pairs.
|
|
659
650
|
report?.("[E] held-out calibration…")
|
|
660
651
|
const rnd = makeLcg(655)
|
|
661
652
|
const split = new Map<string, "fit" | "holdout">()
|
|
@@ -705,7 +696,7 @@ export async function trainCrossSourceModel(
|
|
|
705
696
|
const recall = totalPos > 0 ? tp / totalPos : 0
|
|
706
697
|
const f1 = precision + recall > 0 ? (2 * precision * recall) / (precision + recall) : 0
|
|
707
698
|
|
|
708
|
-
// The
|
|
699
|
+
// The lowest threshold whose precision clears the bar, maximizing recall under it.
|
|
709
700
|
if (precision >= precisionBar && recall > barRecall) {
|
|
710
701
|
barRecall = recall
|
|
711
702
|
recommendedThreshold = t
|
|
@@ -725,7 +716,6 @@ export async function trainCrossSourceModel(
|
|
|
725
716
|
` held-out (${holdIdx.length} pairs, ${totalPos} pos): precision-bar ${precisionBar} → threshold ${recommendedThreshold.toFixed(3)} (recall ${(100 * barRecall).toFixed(1)}%); F1-max ${(100 * bestF1).toFixed(1)}% @ ${f1MaxThreshold.toFixed(3)}`
|
|
726
717
|
)
|
|
727
718
|
|
|
728
|
-
// Train the shipped model on all cross-source pairs and emit its committed module.
|
|
729
719
|
report?.("[F] training the shipped model on all pairs…")
|
|
730
720
|
const model = trainGBT(X, Y, W, CROSS_SOURCE_HYPERPARAMS)
|
|
731
721
|
|
|
@@ -749,9 +739,9 @@ export async function trainCrossSourceModel(
|
|
|
749
739
|
options.moduleDoc +
|
|
750
740
|
` */\n\n` +
|
|
751
741
|
`import type { GBT } from "@mailwoman/match"\n\n` +
|
|
752
|
-
`export const ${options.exportPrefix}_META = ${
|
|
742
|
+
`export const ${options.exportPrefix}_META = ${stringifyJSON(meta)} as const\n\n` +
|
|
753
743
|
`// prettier-ignore\n` +
|
|
754
|
-
`export const ${options.exportPrefix}_MODEL: GBT = ${
|
|
744
|
+
`export const ${options.exportPrefix}_MODEL: GBT = ${stringifyJSON(model)}\n`
|
|
755
745
|
|
|
756
746
|
await makeDirectories(dirname(out))
|
|
757
747
|
await writeLocalFile(moduleSource, out)
|