@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.
Files changed (228) hide show
  1. package/README.md +2 -2
  2. package/{address-key.ts → lib/address-key.ts} +1 -1
  3. package/{geocode-handler.ts → lib/geocode-handler.ts} +7 -7
  4. package/{geojson.ts → lib/geojson.ts} +12 -6
  5. package/{index.ts → lib/index.ts} +10 -10
  6. package/{ingest.ts → lib/ingest.ts} +77 -69
  7. package/{learned-scorer.ts → lib/learned-scorer.ts} +1 -1
  8. package/{map-html.ts → lib/map-html.ts} +10 -16
  9. package/{reconcile.ts → lib/reconcile.ts} +9 -24
  10. package/{resolve.ts → lib/resolve.ts} +31 -13
  11. package/{tools → lib/tools}/coverage-reconciliation.ts +13 -15
  12. package/{tools → lib/tools}/cross-dataset-correlation.ts +64 -139
  13. package/{tools → lib/tools}/cross-source-threshold-sweep.ts +21 -32
  14. package/{tools → lib/tools}/dedup-ceiling.ts +33 -144
  15. package/{tools → lib/tools}/eval-geocoder.ts +10 -11
  16. package/{tools → lib/tools}/geocoder-namesake-probe.ts +5 -12
  17. package/{tools → lib/tools}/geocoder-vs-provided-coords.ts +12 -11
  18. package/lib/tools/gold-set-sample.ts +141 -0
  19. package/lib/tools/index.ts +31 -0
  20. package/{tools → lib/tools}/learned-scorer-clustering-eval.ts +71 -260
  21. package/{tools → lib/tools}/learned-scorer-crossstate-eval.ts +62 -245
  22. package/{tools → lib/tools}/learned-scorer-eval.ts +64 -263
  23. package/{tools → lib/tools}/matcher-scale.ts +5 -5
  24. package/lib/tools/nppes/org-name.ts +23 -0
  25. package/lib/tools/nppes/overmerge-packet.ts +94 -0
  26. package/lib/tools/nppes/report.ts +373 -0
  27. package/lib/tools/nppes/sample.ts +245 -0
  28. package/lib/tools/nppes/scoring.ts +114 -0
  29. package/lib/tools/nppes/settings.ts +102 -0
  30. package/lib/tools/nppes/truth-grains.ts +161 -0
  31. package/lib/tools/nppes-dedup-benchmark.ts +408 -0
  32. package/lib/tools/shared.ts +763 -0
  33. package/lib/tools/train-cross-gbt.ts +209 -0
  34. package/{tools → lib/tools}/train-gbt.ts +38 -156
  35. package/lib/tools/train-org-cross-gbt.ts +179 -0
  36. package/{tools → lib/tools}/txhhsc-to-oarow.ts +10 -28
  37. package/lib/tools/viz/browser.ts +50 -0
  38. package/{tools → lib/tools}/viz/cross-dataset-map.ts +16 -39
  39. package/{tools → lib/tools}/viz/geocode-first-surface.ts +13 -39
  40. package/{tools → lib/tools}/viz/render-map.ts +10 -23
  41. package/lib/tools/viz/render.ts +98 -0
  42. package/{tools → lib/tools}/viz/source-provenance-map.ts +20 -39
  43. package/{tools → lib/tools}/viz/yardstick-figure.ts +6 -5
  44. package/{types.ts → lib/types.ts} +10 -1
  45. package/out/address-key.d.ts +1 -1
  46. package/out/address-key.d.ts.map +1 -1
  47. package/out/address-key.js.map +1 -1
  48. package/out/geocode-handler.d.ts +6 -6
  49. package/out/geocode-handler.d.ts.map +1 -1
  50. package/out/geocode-handler.js +6 -6
  51. package/out/geocode-handler.js.map +1 -1
  52. package/out/geojson.d.ts +7 -2
  53. package/out/geojson.d.ts.map +1 -1
  54. package/out/geojson.js +8 -5
  55. package/out/geojson.js.map +1 -1
  56. package/out/index.d.ts +10 -10
  57. package/out/index.d.ts.map +1 -1
  58. package/out/index.js +10 -10
  59. package/out/index.js.map +1 -1
  60. package/out/ingest.d.ts +64 -46
  61. package/out/ingest.d.ts.map +1 -1
  62. package/out/ingest.js +33 -46
  63. package/out/ingest.js.map +1 -1
  64. package/out/learned-scorer.d.ts +1 -1
  65. package/out/learned-scorer.d.ts.map +1 -1
  66. package/out/learned-scorer.js.map +1 -1
  67. package/out/map-html.d.ts +4 -4
  68. package/out/map-html.d.ts.map +1 -1
  69. package/out/map-html.js +6 -11
  70. package/out/map-html.js.map +1 -1
  71. package/out/models/crosssource-gbt-en-us.d.ts.map +1 -1
  72. package/out/models/crosssource-gbt-en-us.js.map +1 -1
  73. package/out/models/dedup-gbt-en-us.d.ts.map +1 -1
  74. package/out/models/dedup-gbt-en-us.js.map +1 -1
  75. package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -1
  76. package/out/models/org-crosssource-gbt-en-us.js.map +1 -1
  77. package/out/reconcile.d.ts +6 -1
  78. package/out/reconcile.d.ts.map +1 -1
  79. package/out/reconcile.js +7 -21
  80. package/out/reconcile.js.map +1 -1
  81. package/out/resolve.d.ts +19 -7
  82. package/out/resolve.d.ts.map +1 -1
  83. package/out/resolve.js +20 -6
  84. package/out/resolve.js.map +1 -1
  85. package/out/tools/coverage-reconciliation.d.ts +1 -1
  86. package/out/tools/coverage-reconciliation.d.ts.map +1 -1
  87. package/out/tools/coverage-reconciliation.js +12 -12
  88. package/out/tools/coverage-reconciliation.js.map +1 -1
  89. package/out/tools/cross-dataset-correlation.d.ts +4 -4
  90. package/out/tools/cross-dataset-correlation.d.ts.map +1 -1
  91. package/out/tools/cross-dataset-correlation.js +60 -111
  92. package/out/tools/cross-dataset-correlation.js.map +1 -1
  93. package/out/tools/cross-source-threshold-sweep.d.ts +2 -2
  94. package/out/tools/cross-source-threshold-sweep.d.ts.map +1 -1
  95. package/out/tools/cross-source-threshold-sweep.js +19 -27
  96. package/out/tools/cross-source-threshold-sweep.js.map +1 -1
  97. package/out/tools/dedup-ceiling.d.ts.map +1 -1
  98. package/out/tools/dedup-ceiling.js +36 -118
  99. package/out/tools/dedup-ceiling.js.map +1 -1
  100. package/out/tools/eval-geocoder.d.ts +9 -13
  101. package/out/tools/eval-geocoder.d.ts.map +1 -1
  102. package/out/tools/eval-geocoder.js +2 -2
  103. package/out/tools/eval-geocoder.js.map +1 -1
  104. package/out/tools/geocoder-namesake-probe.d.ts +2 -2
  105. package/out/tools/geocoder-namesake-probe.d.ts.map +1 -1
  106. package/out/tools/geocoder-namesake-probe.js +4 -8
  107. package/out/tools/geocoder-namesake-probe.js.map +1 -1
  108. package/out/tools/geocoder-vs-provided-coords.d.ts +1 -1
  109. package/out/tools/geocoder-vs-provided-coords.d.ts.map +1 -1
  110. package/out/tools/geocoder-vs-provided-coords.js +11 -9
  111. package/out/tools/geocoder-vs-provided-coords.js.map +1 -1
  112. package/out/tools/gold-set-sample.d.ts +5 -5
  113. package/out/tools/gold-set-sample.d.ts.map +1 -1
  114. package/out/tools/gold-set-sample.js +37 -121
  115. package/out/tools/gold-set-sample.js.map +1 -1
  116. package/out/tools/index.d.ts +24 -29
  117. package/out/tools/index.d.ts.map +1 -1
  118. package/out/tools/index.js +24 -29
  119. package/out/tools/index.js.map +1 -1
  120. package/out/tools/learned-scorer-clustering-eval.d.ts +1 -1
  121. package/out/tools/learned-scorer-clustering-eval.d.ts.map +1 -1
  122. package/out/tools/learned-scorer-clustering-eval.js +35 -170
  123. package/out/tools/learned-scorer-clustering-eval.js.map +1 -1
  124. package/out/tools/learned-scorer-crossstate-eval.d.ts +5 -5
  125. package/out/tools/learned-scorer-crossstate-eval.d.ts.map +1 -1
  126. package/out/tools/learned-scorer-crossstate-eval.js +44 -166
  127. package/out/tools/learned-scorer-crossstate-eval.js.map +1 -1
  128. package/out/tools/learned-scorer-eval.d.ts +1 -1
  129. package/out/tools/learned-scorer-eval.d.ts.map +1 -1
  130. package/out/tools/learned-scorer-eval.js +37 -173
  131. package/out/tools/learned-scorer-eval.js.map +1 -1
  132. package/out/tools/matcher-scale.d.ts.map +1 -1
  133. package/out/tools/matcher-scale.js +5 -5
  134. package/out/tools/matcher-scale.js.map +1 -1
  135. package/out/tools/nppes/org-name.d.ts +21 -0
  136. package/out/tools/nppes/org-name.d.ts.map +1 -0
  137. package/out/tools/nppes/org-name.js +13 -0
  138. package/out/tools/nppes/org-name.js.map +1 -0
  139. package/out/tools/nppes/overmerge-packet.d.ts +39 -0
  140. package/out/tools/nppes/overmerge-packet.d.ts.map +1 -0
  141. package/out/tools/nppes/overmerge-packet.js +55 -0
  142. package/out/tools/nppes/overmerge-packet.js.map +1 -0
  143. package/out/tools/nppes/report.d.ts +93 -0
  144. package/out/tools/nppes/report.d.ts.map +1 -0
  145. package/out/tools/nppes/report.js +186 -0
  146. package/out/tools/nppes/report.js.map +1 -0
  147. package/out/tools/nppes/sample.d.ts +90 -0
  148. package/out/tools/nppes/sample.d.ts.map +1 -0
  149. package/out/tools/nppes/sample.js +131 -0
  150. package/out/tools/nppes/sample.js.map +1 -0
  151. package/out/tools/nppes/scoring.d.ts +36 -0
  152. package/out/tools/nppes/scoring.d.ts.map +1 -0
  153. package/out/tools/nppes/scoring.js +80 -0
  154. package/out/tools/nppes/scoring.js.map +1 -0
  155. package/out/tools/nppes/settings.d.ts +38 -0
  156. package/out/tools/nppes/settings.d.ts.map +1 -0
  157. package/out/tools/nppes/settings.js +79 -0
  158. package/out/tools/nppes/settings.js.map +1 -0
  159. package/out/tools/nppes/truth-grains.d.ts +50 -0
  160. package/out/tools/nppes/truth-grains.d.ts.map +1 -0
  161. package/out/tools/nppes/truth-grains.js +123 -0
  162. package/out/tools/nppes/truth-grains.js.map +1 -0
  163. package/out/tools/nppes-dedup-benchmark.d.ts +7 -3
  164. package/out/tools/nppes-dedup-benchmark.d.ts.map +1 -1
  165. package/out/tools/nppes-dedup-benchmark.js +106 -673
  166. package/out/tools/nppes-dedup-benchmark.js.map +1 -1
  167. package/out/tools/shared.d.ts +244 -7
  168. package/out/tools/shared.d.ts.map +1 -1
  169. package/out/tools/shared.js +353 -21
  170. package/out/tools/shared.js.map +1 -1
  171. package/out/tools/train-cross-gbt.d.ts +7 -7
  172. package/out/tools/train-cross-gbt.d.ts.map +1 -1
  173. package/out/tools/train-cross-gbt.js +47 -145
  174. package/out/tools/train-cross-gbt.js.map +1 -1
  175. package/out/tools/train-gbt.d.ts +7 -7
  176. package/out/tools/train-gbt.d.ts.map +1 -1
  177. package/out/tools/train-gbt.js +31 -111
  178. package/out/tools/train-gbt.js.map +1 -1
  179. package/out/tools/train-org-cross-gbt.d.ts +7 -5
  180. package/out/tools/train-org-cross-gbt.d.ts.map +1 -1
  181. package/out/tools/train-org-cross-gbt.js +45 -141
  182. package/out/tools/train-org-cross-gbt.js.map +1 -1
  183. package/out/tools/txhhsc-to-oarow.d.ts +2 -2
  184. package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
  185. package/out/tools/txhhsc-to-oarow.js +9 -23
  186. package/out/tools/txhhsc-to-oarow.js.map +1 -1
  187. package/out/tools/viz/browser.d.ts +34 -0
  188. package/out/tools/viz/browser.d.ts.map +1 -0
  189. package/out/tools/viz/browser.js +33 -0
  190. package/out/tools/viz/browser.js.map +1 -0
  191. package/out/tools/viz/cross-dataset-map.d.ts +4 -25
  192. package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
  193. package/out/tools/viz/cross-dataset-map.js +12 -33
  194. package/out/tools/viz/cross-dataset-map.js.map +1 -1
  195. package/out/tools/viz/geocode-first-surface.d.ts +6 -35
  196. package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
  197. package/out/tools/viz/geocode-first-surface.js +10 -37
  198. package/out/tools/viz/geocode-first-surface.js.map +1 -1
  199. package/out/tools/viz/render-map.d.ts +3 -6
  200. package/out/tools/viz/render-map.d.ts.map +1 -1
  201. package/out/tools/viz/render-map.js +9 -19
  202. package/out/tools/viz/render-map.js.map +1 -1
  203. package/out/tools/viz/render.d.ts +4 -9
  204. package/out/tools/viz/render.d.ts.map +1 -1
  205. package/out/tools/viz/render.js +24 -39
  206. package/out/tools/viz/render.js.map +1 -1
  207. package/out/tools/viz/source-provenance-map.d.ts +4 -24
  208. package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
  209. package/out/tools/viz/source-provenance-map.js +12 -32
  210. package/out/tools/viz/source-provenance-map.js.map +1 -1
  211. package/out/tools/viz/yardstick-figure.d.ts +2 -2
  212. package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
  213. package/out/tools/viz/yardstick-figure.js +5 -4
  214. package/out/tools/viz/yardstick-figure.js.map +1 -1
  215. package/out/types.d.ts +11 -1
  216. package/out/types.d.ts.map +1 -1
  217. package/out/types.js.map +1 -1
  218. package/package.json +180 -11
  219. package/tools/gold-set-sample.ts +0 -252
  220. package/tools/index.ts +0 -36
  221. package/tools/nppes-dedup-benchmark.ts +0 -1180
  222. package/tools/shared.ts +0 -160
  223. package/tools/train-cross-gbt.ts +0 -358
  224. package/tools/train-org-cross-gbt.ts +0 -329
  225. package/tools/viz/render.ts +0 -113
  226. /package/{models → lib/models}/crosssource-gbt-en-us.ts +0 -0
  227. /package/{models → lib/models}/dedup-gbt-en-us.ts +0 -0
  228. /package/{models → lib/models}/org-crosssource-gbt-en-us.ts +0 -0
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file The NPPES dedup benchmark's markdown report. Pure: every figure comes from the input, because eval figures are
6
+ * never hand-typed into docs.
7
+ */
8
+ import type { TermFrequencyTable } from "@mailwoman/match";
9
+ import type { ResolveResult } from "#index";
10
+ import type { Score } from "#tools/nppes/scoring";
11
+ /**
12
+ * One row of the setting progression, scored at the default threshold.
13
+ */
14
+ export interface SettingScore {
15
+ label: string;
16
+ score: Score;
17
+ }
18
+ /**
19
+ * One arm of the link-threshold sweep.
20
+ */
21
+ export interface SweepArm {
22
+ /**
23
+ * Link threshold, in bits.
24
+ */
25
+ t: number;
26
+ res: Pick<ResolveResult, "candidatePairs" | "droppedBlocks">;
27
+ score: Score;
28
+ }
29
+ /**
30
+ * Everything the report reads.
31
+ */
32
+ export interface NPPESReportInput {
33
+ state: string;
34
+ /**
35
+ * Sampled NPIs — the true-entity count at the NPI grain.
36
+ */
37
+ keptNpis: number;
38
+ recordCount: number;
39
+ /**
40
+ * Records whose address placed.
41
+ */
42
+ geocoded: number;
43
+ trainEM: boolean;
44
+ /**
45
+ * The corpus-wide table the progression was fed; only its `total`/`distinct` are reported.
46
+ */
47
+ addressFrequency: TermFrequencyTable;
48
+ /**
49
+ * The setting progression in order. The first row is the bare baseline, the last the full stack.
50
+ */
51
+ progression: readonly SettingScore[];
52
+ /**
53
+ * Zero-config `resolveEntities(records)` — reported apart from the progression because its address-frequency table is
54
+ * input-scoped, which on a sub-sample is intentionally sparse.
55
+ */
56
+ defaultOutOfBox: Score;
57
+ sweep: readonly SweepArm[];
58
+ /**
59
+ * The best-F1 arm. Must be an element of {@linkcode sweep} — the table stars it by identity.
60
+ */
61
+ best: SweepArm;
62
+ entityCount: number;
63
+ orgCount: number;
64
+ orgCoordCount: number;
65
+ orgH3Count: number;
66
+ fsNPI: Score;
67
+ fsEntity: Score;
68
+ fsOrg: Score;
69
+ fsOrgCoord: Score;
70
+ gbtNPI: Score;
71
+ gbtEntity: Score;
72
+ gbtOrg: Score;
73
+ gbtOrgCoord: Score;
74
+ gbtOrgH3: Score;
75
+ /**
76
+ * The optional `--candidate` A/B row.
77
+ */
78
+ candidate: {
79
+ label: string;
80
+ npi: Score;
81
+ entity: Score;
82
+ } | null;
83
+ h3Res: number;
84
+ /**
85
+ * Sampled NPIs whose primary practice address placed — the population the coordinate grain can act on.
86
+ */
87
+ geocodedNpis: number;
88
+ }
89
+ /**
90
+ * Render the run's markdown report.
91
+ */
92
+ export declare function renderNPPESDedupReport(input: NPPESReportInput): string;
93
+ //# sourceMappingURL=report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../lib/tools/nppes/report.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAE1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAE3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AASjD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,KAAK,CAAA;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB;;OAEG;IACH,CAA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,EAAE,gBAAgB,GAAG,MAAM,CA+QtE"}
@@ -0,0 +1,186 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file The NPPES dedup benchmark's markdown report. Pure: every figure comes from the input, because eval figures are
6
+ * never hand-typed into docs.
7
+ */
8
+ import { ORG_TAU } from "#tools/nppes/org-name";
9
+ import { COLOCATION_KM } from "#tools/nppes/truth-grains";
10
+ import { pct } from "#tools/shared";
11
+ /**
12
+ * F1 gap within which two blocking strategies are treated as equivalent.
13
+ */
14
+ const BLOCKING_PARITY_TOLERANCE = 0.015;
15
+ /**
16
+ * Render the run's markdown report.
17
+ */
18
+ export function renderNPPESDedupReport(input) {
19
+ const { state: STATE, keptNpis, recordCount: N, geocoded: geo, trainEM: TRAIN_EM, addressFrequency, progression, defaultOutOfBox, sweep, best, entityCount, orgCount, orgCoordCount, orgH3Count, fsNPI, fsEntity, fsOrg, fsOrgCoord, gbtNPI, gbtEntity, gbtOrg, gbtOrgCoord, gbtOrgH3, candidate: cand, h3Res: H3_RES, geocodedNpis, } = input;
20
+ const baseline = progression[0]; // no settings — the prior-prior behaviour
21
+ // The LAST progression row — the whole A1–A5 stack, never compared on F1 against the others. Named for what it
22
+ // is: a row called `best` invites reading a stack-wide delta as one setting's marginal effect, which is how the
23
+ // authorized-official sentence below came to quote a five-setting number.
24
+ const fullStack = progression.at(-1);
25
+ const base = sweep[0]; // threshold 0, full setting stack
26
+ const signed = (x) => `${x >= 0 ? "+" : ""}${x.toFixed(1)}pp`;
27
+ const lines = [
28
+ `# NPPES NPI dedup benchmark (#617)`,
29
+ "",
30
+ `_Generated by \`mailwoman registry scorer-eval nppes-benchmark\`. Sample: ${keptNpis} ${STATE} NPIs with ≥1 ` +
31
+ `alternate name → ${N} records (${(N / keptNpis).toFixed(1)}/NPI) from real registry + other-names + ` +
32
+ `mailing-vs-practice variation. Matcher run BLIND to the NPI${TRAIN_EM ? ", EM-trained (label-free)" : ""}; ` +
33
+ `geocoded ${pct(geo / N)}% of addresses. The NPI is held-out ground truth._`,
34
+ "",
35
+ `**Headline — org-name truth (the honest grain):** the shipped ` +
36
+ `matcher resolves these records at **F1 ${pct(gbtOrg.f1)}%** against org-name entity-truth — not the NPI-level ` +
37
+ `${pct(gbtNPI.f1)}%, which mostly measures NPI over-segmentation (one organization holds many subpart NPIs, so ` +
38
+ `correct co-located merges are scored as errors). Same clusters, three rulers: ` +
39
+ `**NPI ${pct(gbtNPI.f1)}% → site ${pct(gbtEntity.f1)}% → org-name ${pct(gbtOrg.f1)}%** ` +
40
+ `(${keptNpis} NPI → ${entityCount} site → ${orgCount} org-name classes); the climb is the yardstick getting honest, ` +
41
+ `not the model changing — gold-set validated (120/120 hard pairs = same org). Details in "Three truth grains" below.`,
42
+ "",
43
+ `## The comparison-model settings (each toggled on, at the default threshold)`,
44
+ "",
45
+ `| model | precision | recall | F1 | ΔF1 | ARI | over-merged |`,
46
+ `|---|---:|---:|---:|---:|---:|---:|`,
47
+ ];
48
+ progression.forEach((p, i) => {
49
+ const delta = i === 0 ? "—" : signed(100 * (p.score.f1 - progression[i - 1].score.f1));
50
+ const bold = i === progression.length - 1;
51
+ const w = (s) => (bold ? `**${s}**` : s);
52
+ lines.push(`| ${w(p.label)} | ${w(pct(p.score.precision) + "%")} | ${w(pct(p.score.recall) + "%")} | ${w(pct(p.score.f1) + "%")} | ${delta} | ${w(p.score.ari.toFixed(3))} | ${w(String(p.score.overMergedClusters))} |`);
53
+ });
54
+ lines.push("");
55
+ lines.push(`Inverse-frequency weighting uses the corpus-wide table (${addressFrequency.distinct.toLocaleString()} distinct addresses ` +
56
+ `over ${addressFrequency.total.toLocaleString()} providers) to down-weight a crowded shared address; collapsing the redundant ` +
57
+ `address-key + distance comparisons into one spatial signal (A1) removes the double-count that let a shared address ` +
58
+ `over-vote a disagreeing name. The address-frequency + A1 baseline is F1 ${pct(progression[2].score.f1)}% at the ` +
59
+ `default threshold; the **authorized-official discriminator** is roughly neutral there (${signed(100 * (progression[3].score.f1 - progression[2].score.f1))}) ` +
60
+ `but enables a higher cutoff — it holds recall where the baseline alone collapses, reaching **${pct(best.score.f1)}%** at ` +
61
+ `threshold ${best.t} (below), the first config past the baseline (#625).`);
62
+ lines.push("");
63
+ lines.push(`**Out-of-the-box (zero-config \`resolveEntities(records)\`, settings default-on #86):** F1 ` +
64
+ `**${pct(defaultOutOfBox.f1)}%** on this sample — essentially the baseline. The default auto-computes the ` +
65
+ `address-frequency table over the INPUT records, and this benchmark deliberately sub-samples ${N} records, so ` +
66
+ `that table is too sparse to carry the inverse-frequency signal (a corpus statistic you can't synthesize from a ` +
67
+ `slice). It's **not a regression** (≥ baseline, no over-merge added) — it's the honest floor when the input isn't ` +
68
+ `corpus-scale. Fed the corpus-wide table (the \`+ inverse-address-frequency\` row above, what the CLI builds from ` +
69
+ `the full source files) the SAME default reaches the **${pct(progression[2].score.f1)}%** baseline. On a full-dataset ` +
70
+ `dedup the input IS the corpus, so zero-config reaches the baseline on its own.`);
71
+ lines.push("");
72
+ lines.push(`## With all settings on, across the link threshold (the secondary setting)`);
73
+ lines.push("");
74
+ lines.push(`| link threshold (bits) | precision | recall | F1 | ARI | clusters | over-merged |`);
75
+ lines.push(`|---:|---:|---:|---:|---:|---:|---:|`);
76
+ for (const s of sweep) {
77
+ const star = s === best ? " ⭐" : "";
78
+ lines.push(`| ${s.t}${s.t === 0 ? " (default)" : ""} | ${pct(s.score.precision)}% | ${pct(s.score.recall)}% | **${pct(s.score.f1)}%**${star} | ${s.score.ari.toFixed(3)} | ${s.score.clusters} | ${s.score.overMergedClusters} |`);
79
+ }
80
+ lines.push("");
81
+ lines.push(best.t === 0
82
+ ? `Best F1 is at the **default threshold** (${pct(base.score.f1)}%): raising it only trades recall away faster ` +
83
+ `than it buys precision. So the threshold knob alone can't separate co-located distinct providers — the ` +
84
+ `over-merge is structural, in the comparison model, not the cutoff.`
85
+ : `Best F1 **${pct(best.score.f1)}%** (ARI ${best.score.ari.toFixed(3)}) at threshold ${best.t}, vs **${pct(base.score.f1)}%** at the ` +
86
+ `default — the threshold knob moves it ${(100 * (best.score.f1 - base.score.f1)).toFixed(0)}pp. Higher thresholds trade recall for precision.`);
87
+ lines.push("");
88
+ lines.push(`## Shape + where the errors are (at the default threshold)`);
89
+ lines.push("");
90
+ lines.push(`- records: ${N} · true entities (NPIs): ${keptNpis} · recovered clusters: ${base.score.clusters}`);
91
+ lines.push(`- candidate pairs blocked: ${base.res.candidatePairs}${base.res.droppedBlocks.length ? ` · oversized blocks skipped: ${base.res.droppedBlocks.length}` : ""}`);
92
+ lines.push(`- **Over-merge (precision):** ${base.score.overMergedClusters} clusters fuse ≥2 distinct NPIs (largest fuses ` +
93
+ `${base.score.maxNpisFused}; ${base.score.recordsInOverMerged} records) — **co-located providers sharing a clinic / ` +
94
+ `billing address**, linked by address agreement despite different names.`);
95
+ lines.push(`- **Under-merge (recall):** ${base.score.splitNpis}/${keptNpis} NPIs split across >1 cluster — records at distant ` +
96
+ `addresses (mailing vs practice) or with strong name drift the score didn't bridge.`);
97
+ lines.push("");
98
+ lines.push(`## Three truth grains — NPI → site → org-name (the over-segmentation correction)`);
99
+ lines.push("");
100
+ lines.push(`NPI-as-truth OVER-SEGMENTS: one org holds many NPIs, so the matcher's correct co-located merges are scored as ` +
101
+ `errors. Three yardsticks, same clusters: **NPI** (one entity per registration), **site** (subpart-flagged ` +
102
+ `collapse + split an NPI's distinct addresses), and **org-name** — the gold-set-validated truth: same NPI ⇒ ` +
103
+ `same entity (recall preserved) PLUS collapse co-located NPIs whose primary org names match (Jaccard ≥ ${ORG_TAU}), ` +
104
+ `with NO reliance on the subpart flag (the gold set showed it misses 37%). The same ${N} records carry ` +
105
+ `**${keptNpis} NPI** → **${entityCount} site** → **${orgCount} org-name** classes. The org-name number is the ` +
106
+ `honest one: it stops charging the matcher for the same-org merges the gold set proved are correct.`);
107
+ lines.push("");
108
+ lines.push(`| config | truth | precision | recall | F1 | ΔF1 vs NPI | ARI | over-merged |`);
109
+ lines.push(`|---|---|---:|---:|---:|---:|---:|---:|`);
110
+ const dualRow = (label, truth, s, delta) => lines.push(`| ${label} | ${truth} | ${pct(s.precision)}% | ${pct(s.recall)}% | **${pct(s.f1)}%** | ${delta === undefined ? "—" : signed(100 * delta)} | ${s.ari.toFixed(3)} | ${s.overMergedClusters} |`);
111
+ dualRow("FS full stack", "NPI", fsNPI);
112
+ dualRow("FS full stack", "site", fsEntity, fsEntity.f1 - fsNPI.f1);
113
+ dualRow("FS full stack", "**org-name**", fsOrg, fsOrg.f1 - fsNPI.f1);
114
+ dualRow("FS full stack", "org-name (coord)", fsOrgCoord, fsOrgCoord.f1 - fsNPI.f1);
115
+ dualRow("GBT (shipped default)", "NPI", gbtNPI);
116
+ dualRow("GBT (shipped default)", "site", gbtEntity, gbtEntity.f1 - gbtNPI.f1);
117
+ dualRow("GBT (shipped default)", "**org-name**", gbtOrg, gbtOrg.f1 - gbtNPI.f1);
118
+ dualRow("GBT (shipped default)", "**org-name (coord)**", gbtOrgCoord, gbtOrgCoord.f1 - gbtNPI.f1);
119
+ dualRow("GBT (shipped default)", `org-name (H3 res ${H3_RES})`, gbtOrgH3, gbtOrgH3.f1 - gbtNPI.f1);
120
+ if (cand) {
121
+ dualRow(cand.label, "NPI", cand.npi);
122
+ dualRow(cand.label, "**entity**", cand.entity, cand.entity.f1 - cand.npi.f1);
123
+ }
124
+ lines.push("");
125
+ lines.push(`The F1 **climbs as the yardstick gets honest**: GBT **${pct(gbtNPI.f1)}% (NPI) → ${pct(gbtEntity.f1)}% (site) → ` +
126
+ `${pct(gbtOrg.f1)}% (org-name)**, the over-merge collapsing (${gbtNPI.overMergedClusters} → ${gbtOrg.overMergedClusters}) ` +
127
+ `and precision rising (${pct(gbtNPI.precision)}% → ${pct(gbtOrg.precision)}%). The clusters are IDENTICAL across the three ` +
128
+ `columns — the climb is purely the ruler ceasing to charge the matcher for the correct same-org merges the gold set proved ` +
129
+ `(\`2026-06-16-dedup-gold-set-tx120.md\`: 120/120 same org, 0 genuine over-merges).`);
130
+ lines.push("");
131
+ lines.push(`**Tier 2D — tightening the org-name ruler with the geocode coordinate.** The org-name truth above blocks by the address ` +
132
+ `STRING (\`addressFrequencyKey\`), so two records at one building whose text differs — \`1504 Taub LOOP\` vs ` +
133
+ `\`1504 Taub LP STE 100\` — key apart and the merge is still charged as an error. Block by the GEOCODED BUILDING instead ` +
134
+ `(union co-located NPIs within ${COLOCATION_KM * 1000} m whose org names agree, same Jaccard check) and the truth tightens ` +
135
+ `further: GBT **org-name ${pct(gbtOrg.f1)}% → org-name-coord ${pct(gbtOrgCoord.f1)}%** ` +
136
+ `(${signed(100 * (gbtOrgCoord.f1 - gbtOrg.f1))}), ${orgCount} → ${orgCoordCount} classes, over ${geocodedNpis}/${keptNpis} ` +
137
+ `geocoded NPIs. The string org-name F1 is a conservative LOWER bound; the coordinate one is tighter (the Jaccard check ` +
138
+ `still blocks distinct co-located orgs). Both are honest — the coordinate is the geocode-first key.`);
139
+ lines.push("");
140
+ lines.push(`**H3-cell robustness check (#109).** Re-keying the same building-grain co-location on an H3 cell ` +
141
+ `(res ${H3_RES}) instead of the 50 m haversine radius — the deterministic, O(n) "geocode-first cell" the issue ` +
142
+ `suggested — gives GBT **org-name-h3 ${pct(gbtOrgH3.f1)}%** (${orgH3Count} classes), vs the haversine ` +
143
+ `${pct(gbtOrgCoord.f1)}% (${orgCoordCount}). ${Math.abs(gbtOrgH3.f1 - gbtOrgCoord.f1) < BLOCKING_PARITY_TOLERANCE
144
+ ? "Within noise of the haversine grain — the ~" +
145
+ pct(gbtOrgCoord.f1) +
146
+ "% coord-grain F1 is robust to the co-location method, not an artifact of the 50 m threshold."
147
+ : "The two co-location methods differ by " +
148
+ signed(100 * (gbtOrgH3.f1 - gbtOrgCoord.f1)) +
149
+ " — the cell-vs-radius boundary handling shifts the count (a hard H3 boundary can split a same-building pair into adjacent cells)."}`);
150
+ lines.push("");
151
+ lines.push(`**Takeaways:** (1) The dedup model's REAL quality is the **org-name F1 ~${pct(gbtOrg.f1)}%**, not the NPI-level ` +
152
+ `${pct(gbtNPI.f1)}% — the difference was NPI over-segmentation, not model error. (2) The #625 setting was the YARDSTICK, ` +
153
+ `not the scorer: the corroboration-feature experiment (reverted) couldn't move precision because the over-merge was ` +
154
+ `mostly correct. (3) The remaining org-name over-merge (${gbtOrg.overMergedClusters} clusters) is the genuine frontier — ` +
155
+ `small, approaching the ceiling's ~1.6% irreducible (\`2026-06-16-dedup-ceiling.md\`). (4) Trust the large eval: a 50-NPI ` +
156
+ `smoke misled on the site delta (+5–7pp vs this run's ±2pp).`);
157
+ lines.push("");
158
+ lines.push(`Caveats: the programmatic site-truth is CONSERVATIVE (collapses only NPPES-flagged subparts; unflagged same-org pairs still ` +
159
+ `read as over-merge), so it understates the subpart correction. A hand-adjudicated gold set on the ambiguous co-located + ` +
160
+ `two-site slice is the next refinement (#625).`);
161
+ lines.push("");
162
+ lines.push(`## Reading`);
163
+ lines.push("");
164
+ lines.push(`The geocode-first **foundation works**: **${pct(geo / N)}%** of addresses placed, blocking + clustering clean — the ` +
165
+ `geocoding (the Pelias/Nominatim-can't-do-this part) is not the bottleneck. The comparison-model settings reach the ` +
166
+ `address-frequency + A1 baseline at F1 **${pct(progression[2].score.f1)}%** (${signed(100 * (progression[2].score.f1 - baseline.score.f1))} over baseline): ` +
167
+ `inverse-frequency weighting restores full weight to a *rare* shared address (stitching a provider's name-drifted ` +
168
+ `records together — mostly recall) while down-weighting a *crowded* one, and the collapsed spatial signal (A1) drops ` +
169
+ `the address+distance double-count. What remains is **precision / over-merge** — ${fullStack.score.overMergedClusters} ` +
170
+ `clusters still fuse distinct co-located providers, because even one down-weighted spatial agreement can outvote a ` +
171
+ `disagreeing name. The setting search (#625) — two negatives, then the first positive: a name/org/phone ` +
172
+ `**corroboration check** (A2/A3) — phone is an unreliable secondary identifier on NPPES (shared institutional ` +
173
+ `switchboard lines), so it over-links and falsely corroborates co-phone distinct providers; and **average-linkage ` +
174
+ `clustering** (A4) — the over-merged clusters are joined by STRONG shared-address edges, not weak bridges, so ` +
175
+ `average-linkage can't split them and only trades away name-drift recall. The over-merge is a **scoring** problem ` +
176
+ `this data can't resolve, not a clustering-topology one. The **authorized-official discriminator** is the first setting to beat the baseline — a reliable secondary identifier holds recall so a higher threshold separates the co-located providers; a still-more-distinctive identifier ` +
177
+ `(taxonomy / license) or a learned scorer over the FS feature vector (#603) goes further. Config ` +
178
+ `dominates the model (the pre-registered finding) — tracked as #625 / the selective-model work (#602 / #603).`);
179
+ lines.push("");
180
+ lines.push(`NPI-as-truth is **conservative**: a cluster fusing two NPIs is a candidate "same entity, two NPIs" surfaced for ` +
181
+ `review, not an adjudicated error; an NPI split across genuinely-distant addresses is geo-first behaving correctly, ` +
182
+ `counted here as a recall miss. We resolve and report; interpretation is the consumer's.`);
183
+ lines.push("");
184
+ return lines.join("\n");
185
+ }
186
+ //# sourceMappingURL=report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.js","sourceRoot":"","sources":["../../../lib/tools/nppes/report.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAEnC;;GAEG;AACH,MAAM,yBAAyB,GAAG,KAAK,CAAA;AA+EvC;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAuB;IAC7D,MAAM,EACL,KAAK,EAAE,KAAK,EACZ,QAAQ,EACR,WAAW,EAAE,CAAC,EACd,QAAQ,EAAE,GAAG,EACb,OAAO,EAAE,QAAQ,EACjB,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,KAAK,EACL,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,aAAa,EACb,UAAU,EACV,KAAK,EACL,QAAQ,EACR,KAAK,EACL,UAAU,EACV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AAqH;QACrH,2CAA2C,GAAG,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,MAAM,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,KAAK,CAAC,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,mBAAmB;QAC/J,mHAAmH;QACnH,sHAAsH;QACtH,mFAAmF,SAAS,CAAC,KAAK,CAAC,kBAAkB,GAAG;QACxH,oHAAoH;QACpH,yGAAyG;QACzG,+GAA+G;QAC/G,mHAAmH;QACnH,+GAA+G;QAC/G,mHAAmH;QACnH,2RAA2R;QAC3R,kGAAkG;QAClG,8GAA8G,CAC/G,CAAA;IAED,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAEd,KAAK,CAAC,IAAI,CACT,kHAAkH;QACjH,qHAAqH;QACrH,yFAAyF,CAC1F,CAAA;IAED,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAEd,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACxB,CAAC"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file The NPPES benchmark's input sample: the variation-rich multi-record set per NPI, plus the corpus-wide
6
+ * address-frequency table built in the same pass. One registry pass serves any number of states — the cross-state
7
+ * eval samples two at once.
8
+ */
9
+ import type { TermFrequencyTable } from "@mailwoman/match";
10
+ import { type NPIPrimary } from "#tools/nppes/org-name";
11
+ /**
12
+ * One synthetic input row for the matcher; `npi` is the hidden NPI-level truth, `entityID` the site-level entity-level
13
+ * truth (subpart-collapsed).
14
+ */
15
+ export interface MessyRow extends Record<string, string> {
16
+ npi: string;
17
+ name: string;
18
+ org: string;
19
+ address: string;
20
+ auth: string;
21
+ /**
22
+ * Whitespace-joined taxonomy-code set (up to 15 slots) — the #625 code-set discriminator.
23
+ */
24
+ taxonomy: string;
25
+ entityID: string;
26
+ }
27
+ /**
28
+ * One state's slice of the sample pass.
29
+ */
30
+ export interface NPPESStateSample {
31
+ rows: MessyRow[];
32
+ /**
33
+ * The sampled NPIs — the true-entity count at the NPI grain.
34
+ */
35
+ keptNpis: Set<string>;
36
+ /**
37
+ * Per-NPI primary org name + practice address key, the basis for the org-name entity truths.
38
+ */
39
+ npiPrimary: Map<string, NPIPrimary>;
40
+ }
41
+ /**
42
+ * What the single-state sample pass yields.
43
+ */
44
+ export interface NPPESSample extends NPPESStateSample {
45
+ /**
46
+ * Corpus-wide address-frequency table — the inverse-frequency signal. Counted over EVERY practice address in the
47
+ * registry, not just the sample, so the sharing structure is a corpus statistic rather than a slice artifact.
48
+ */
49
+ addressFrequency: TermFrequencyTable;
50
+ }
51
+ /**
52
+ * Where the sample comes from and how much of it to take.
53
+ */
54
+ export interface NPPESSampleOptions {
55
+ registryPath: string;
56
+ otherNamesPath: string;
57
+ /**
58
+ * Already upper-cased; compared against the practice-location state column.
59
+ */
60
+ state: string;
61
+ maxNpis: number;
62
+ }
63
+ /**
64
+ * The multi-state shape of {@linkcode NPPESSampleOptions} — one registry pass fills every state's bucket.
65
+ */
66
+ export interface NPPESMultiSampleOptions {
67
+ registryPath: string;
68
+ otherNamesPath: string;
69
+ /**
70
+ * Already upper-cased; compared against the practice-location state column.
71
+ */
72
+ states: readonly string[];
73
+ maxNpisPerState: number;
74
+ }
75
+ /**
76
+ * Build the benchmark's input records from the real registry, one bucket per requested state.
77
+ *
78
+ * Two passes over two files, and the SECOND one cannot break early: the address-frequency table needs every registry
79
+ * row even after the sample is full, so the per-bucket `keptNpis.size < maxNpisPerState` test bounds only the sample
80
+ * branch.
81
+ */
82
+ export declare function buildNPPESStateSamples(options: NPPESMultiSampleOptions, report?: (line: string) => void): Promise<{
83
+ byState: Map<string, NPPESStateSample>;
84
+ addressFrequency: TermFrequencyTable;
85
+ }>;
86
+ /**
87
+ * Build one state's benchmark input records — {@linkcode buildNPPESStateSamples} with a single bucket.
88
+ */
89
+ export declare function buildNPPESSample(options: NPPESSampleOptions, report?: (line: string) => void): Promise<NPPESSample>;
90
+ //# sourceMappingURL=sample.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample.d.ts","sourceRoot":"","sources":["../../../lib/tools/nppes/sample.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAG1D,OAAO,EAAa,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAGlE;;;GAGG;AACH,MAAM,WAAW,QAAS,SAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IACvD,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,QAAQ,EAAE,CAAA;IAChB;;OAEG;IACH,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACrB;;OAEG;IACH,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,gBAAgB;IACpD;;;OAGG;IACH,gBAAgB,EAAE,kBAAkB,CAAA;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;CACf;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;IACzB,eAAe,EAAE,MAAM,CAAA;CACvB;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC3C,OAAO,EAAE,uBAAuB,EAChC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC7B,OAAO,CAAC;IAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAAC,gBAAgB,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAiI3F;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACrC,OAAO,EAAE,kBAAkB,EAC3B,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC7B,OAAO,CAAC,WAAW,CAAC,CAYtB"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file The NPPES benchmark's input sample: the variation-rich multi-record set per NPI, plus the corpus-wide
6
+ * address-frequency table built in the same pass. One registry pass serves any number of states — the cross-state
7
+ * eval samples two at once.
8
+ */
9
+ import { isPresent } from "@mailwoman/core/objects";
10
+ import { addressFrequencyKey, streamRows } from "#index";
11
+ import { orgTokens } from "#tools/nppes/org-name";
12
+ import { addr, MIN_GROUP_SIZE, norm, NPPES_COLUMNS as C } from "#tools/shared";
13
+ /**
14
+ * Build the benchmark's input records from the real registry, one bucket per requested state.
15
+ *
16
+ * Two passes over two files, and the SECOND one cannot break early: the address-frequency table needs every registry
17
+ * row even after the sample is full, so the per-bucket `keptNpis.size < maxNpisPerState` test bounds only the sample
18
+ * branch.
19
+ */
20
+ export async function buildNPPESStateSamples(options, report) {
21
+ const { registryPath, otherNamesPath, states, maxNpisPerState } = options;
22
+ // --- Phase A: the variation set — NPIs that carry ≥1 alternate organization name. ---
23
+ report?.("[A] streaming other-names…");
24
+ const altNames = new Map();
25
+ for await (const r of streamRows(otherNamesPath)) {
26
+ const npi = norm(r[C.npi]);
27
+ const alt = norm(r[C.otherOrg]);
28
+ if (!npi || !alt)
29
+ continue;
30
+ const list = altNames.get(npi) ?? [];
31
+ if (list.length < MIN_GROUP_SIZE) {
32
+ list.push(alt);
33
+ }
34
+ // cap fan-out per NPI
35
+ altNames.set(npi, list);
36
+ }
37
+ report?.(` ${altNames.size} NPIs with ≥1 alternate name`);
38
+ // --- Phase B: ONE full registry pass — build the GLOBAL address-frequency table (every practice
39
+ // address, so the sharing structure is corpus-wide, not sample-biased) AND collect every state's sample. ---
40
+ report?.(`[B] full registry pass: address-frequency table + ${maxNpisPerState} × ${states.join("/")} sample…`);
41
+ const byState = new Map(states.map((state) => [state, { rows: [], keptNpis: new Set(), npiPrimary: new Map() }]));
42
+ const addrCounts = new Map();
43
+ let addrTotal = 0;
44
+ let scanned = 0;
45
+ let keptTotal = 0;
46
+ for await (const r of streamRows(registryPath)) {
47
+ if (++scanned % 1_000_000 === 0) {
48
+ report?.(` scanned ${scanned / 1e6}M rows, kept ${keptTotal}`);
49
+ }
50
+ const practice = addr(r[C.pAddr], r[C.pCity], r[C.pState], r[C.pZip]);
51
+ // Global address-frequency: count every practice address (one row ≈ one distinct NPI).
52
+ if (practice) {
53
+ const k = addressFrequencyKey(practice);
54
+ addrCounts.set(k, (addrCounts.get(k) ?? 0) + 1);
55
+ addrTotal++;
56
+ }
57
+ // Sample: in-state NPIs with ≥1 alternate name, up to maxNpisPerState — NO early break (the table
58
+ // needs the full pass).
59
+ const npi = norm(r[C.npi]);
60
+ const bucket = byState.get(norm(r[C.pState]).toUpperCase());
61
+ if (bucket &&
62
+ bucket.keptNpis.size < maxNpisPerState &&
63
+ npi &&
64
+ !bucket.keptNpis.has(npi) &&
65
+ altNames.has(npi) &&
66
+ practice) {
67
+ const isOrg = norm(r[C.entityType]) === "2";
68
+ const primaryName = isOrg ? norm(r[C.orgLegal]) : `${norm(r[C.first])} ${norm(r[C.last])}`.trim();
69
+ if (primaryName) {
70
+ const org = isOrg ? norm(r[C.orgLegal]) : "";
71
+ const auth = `${norm(r[C.authFirst])} ${norm(r[C.authLast])}`.trim();
72
+ // the NPI's registrant — shared across its records
73
+ // #625: the taxonomy-code set (up to 15 slots), whitespace-joined — identical across the NPI's
74
+ // records by construction (it's a per-NPI registry attribute), so it NEVER splits one entity;
75
+ // it only separates co-located DISTINCT providers whose sets are disjoint.
76
+ const taxonomy = C.taxonomy
77
+ .map((col) => norm(r[col]))
78
+ .filter(isPresent)
79
+ .join(" ");
80
+ // Entity-level (site) truth: same org + same physical address. Subparts (NPPES
81
+ // "Is Organization Subpart" + parent LBN/TIN) collapse to their PARENT, so the matcher isn't
82
+ // charged for correctly fusing one org's many subpart-NPIs at a site; an NPI's mailing-vs-
83
+ // practice records stay DISTINCT sites. orgKey = parent identity for subparts, else the NPI
84
+ // (independent orgs sharing an address stay distinct — the conservative choice).
85
+ const isSubpart = norm(r[C.isSubpart]).toUpperCase() === "Y";
86
+ const parentKey = `${norm(r[C.parentLBN])}|${norm(r[C.parentTIN])}`.toLowerCase();
87
+ const orgKey = isSubpart && parentKey !== "|" ? `p:${parentKey}` : `n:${npi}`;
88
+ const eid = (a) => `${addressFrequencyKey(a)}|${orgKey}`;
89
+ if (org) {
90
+ bucket.npiPrimary.set(npi, { tokens: orgTokens(org), addrKey: addressFrequencyKey(practice) });
91
+ }
92
+ bucket.keptNpis.add(npi);
93
+ keptTotal++;
94
+ bucket.rows.push({ npi, name: primaryName, org, address: practice, auth, taxonomy, entityID: eid(practice) });
95
+ // primary
96
+ for (const alt of altNames.get(npi)) {
97
+ bucket.rows.push({ npi, name: alt, org: alt, address: practice, auth, taxonomy, entityID: eid(practice) });
98
+ }
99
+ // name drift
100
+ const mailing = addr(r[C.mAddr], r[C.mCity], r[C.mState], r[C.mZip]);
101
+ if (mailing && mailing !== practice) {
102
+ bucket.rows.push({ npi, name: primaryName, org, address: mailing, auth, taxonomy, entityID: eid(mailing) });
103
+ } // address variation
104
+ }
105
+ }
106
+ }
107
+ // Corpus-wide address-frequency table — the inverse-frequency signal (#617 fix per the DeepSeek consult).
108
+ const addressFrequency = {
109
+ total: addrTotal,
110
+ distinct: addrCounts.size,
111
+ frequency: (v) => (v ? (addrCounts.get(addressFrequencyKey(v)) ?? 0) / addrTotal : 0),
112
+ };
113
+ for (const [state, bucket] of byState) {
114
+ report?.(` ${state}: ${bucket.keptNpis.size} NPIs → ${bucket.rows.length} records`);
115
+ }
116
+ report?.(` address table: ${addrCounts.size} distinct over ${addrTotal} rows`);
117
+ return { byState, addressFrequency };
118
+ }
119
+ /**
120
+ * Build one state's benchmark input records — {@linkcode buildNPPESStateSamples} with a single bucket.
121
+ */
122
+ export async function buildNPPESSample(options, report) {
123
+ const { byState, addressFrequency } = await buildNPPESStateSamples({
124
+ registryPath: options.registryPath,
125
+ otherNamesPath: options.otherNamesPath,
126
+ states: [options.state],
127
+ maxNpisPerState: options.maxNpis,
128
+ }, report);
129
+ return { ...byState.get(options.state), addressFrequency };
130
+ }
131
+ //# sourceMappingURL=sample.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample.js","sourceRoot":"","sources":["../../../lib/tools/nppes/sample.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGnD,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACxD,OAAO,EAAE,SAAS,EAAmB,MAAM,uBAAuB,CAAA;AAClE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,IAAI,CAAC,EAAE,MAAM,eAAe,CAAA;AAuE9E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC3C,OAAgC,EAChC,MAA+B;IAE/B,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,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,gBAAgB,CACrC,OAA2B,EAC3B,MAA+B;IAE/B,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG,MAAM,sBAAsB,CACjE;QACC,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;QACvB,eAAe,EAAE,OAAO,CAAC,OAAO;KAChC,EACD,MAAM,CACN,CAAA;IAED,OAAO,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAE,EAAE,gBAAgB,EAAE,CAAA;AAC5D,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file Pairwise cluster scoring for the NPPES benchmark — precision/recall/F1 and adjusted Rand of recovered clusters
6
+ * against a truth labelling, plus the over-merge / under-merge shape counts.
7
+ */
8
+ import type { ResolvedEntity, SourceRecord } from "#index";
9
+ /**
10
+ * Pairs within a group of `n`.
11
+ */
12
+ export declare const choose2: (n: number) => number;
13
+ /**
14
+ * One clustering scored against one truth labelling.
15
+ */
16
+ export interface Score {
17
+ precision: number;
18
+ recall: number;
19
+ f1: number;
20
+ ari: number;
21
+ clusters: number;
22
+ singletons: number;
23
+ overMergedClusters: number;
24
+ recordsInOverMerged: number;
25
+ maxNpisFused: number;
26
+ splitNpis: number;
27
+ }
28
+ /**
29
+ * Score recovered clusters against a truth labelling.
30
+ *
31
+ * Pairwise, not set-matching: a true pair is two records carrying the same `labelOf`, a predicted pair is two records
32
+ * in the same entity. `totalRecords` is the labelled population and only feeds the adjusted-Rand expectation, so it
33
+ * must be the whole record set rather than the clustered subset — a smaller value inflates ARI.
34
+ */
35
+ export declare function scoreEntities(entities: readonly ResolvedEntity[], labelOf: (rec: SourceRecord) => string, totalRecords: number): Score;
36
+ //# sourceMappingURL=scoring.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoring.d.ts","sourceRoot":"","sources":["../../../lib/tools/nppes/scoring.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAE1D;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,GAAG,MAAM,KAAG,MAA2B,CAAA;AAE/D;;GAEG;AACH,MAAM,WAAW,KAAK;IACrB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,mBAAmB,EAAE,MAAM,CAAA;IAC3B,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC5B,QAAQ,EAAE,SAAS,cAAc,EAAE,EACnC,OAAO,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,EACtC,YAAY,EAAE,MAAM,GAClB,KAAK,CAuEP"}