@mailwoman/registry 9.2.0 → 9.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/README.md +1 -1
  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} +9 -4
  5. package/{index.ts → lib/index.ts} +10 -10
  6. package/{ingest.ts → lib/ingest.ts} +75 -68
  7. package/{learned-scorer.ts → lib/learned-scorer.ts} +1 -1
  8. package/{map-html.ts → lib/map-html.ts} +7 -13
  9. package/{reconcile.ts → lib/reconcile.ts} +7 -23
  10. package/{resolve.ts → lib/resolve.ts} +25 -12
  11. package/{tools → lib/tools}/coverage-reconciliation.ts +12 -14
  12. package/{tools → lib/tools}/cross-dataset-correlation.ts +60 -137
  13. package/{tools → lib/tools}/cross-source-threshold-sweep.ts +20 -31
  14. package/{tools → lib/tools}/dedup-ceiling.ts +33 -144
  15. package/{tools → lib/tools}/eval-geocoder.ts +9 -10
  16. package/{tools → lib/tools}/geocoder-namesake-probe.ts +5 -12
  17. package/{tools → lib/tools}/geocoder-vs-provided-coords.ts +9 -10
  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 +68 -257
  21. package/{tools → lib/tools}/learned-scorer-crossstate-eval.ts +60 -243
  22. package/{tools → lib/tools}/learned-scorer-eval.ts +62 -256
  23. package/{tools → lib/tools}/matcher-scale.ts +4 -5
  24. package/lib/tools/nppes/org-name.ts +23 -0
  25. package/{tools → lib/tools}/nppes/overmerge-packet.ts +5 -7
  26. package/{tools → lib/tools}/nppes/report.ts +22 -25
  27. package/{tools → lib/tools}/nppes/sample.ts +80 -32
  28. package/{tools/nppes/levers.ts → lib/tools/nppes/settings.ts} +10 -10
  29. package/{tools → lib/tools}/nppes/truth-grains.ts +4 -44
  30. package/{tools → lib/tools}/nppes-dedup-benchmark.ts +42 -38
  31. package/lib/tools/shared.ts +763 -0
  32. package/lib/tools/train-cross-gbt.ts +209 -0
  33. package/{tools → lib/tools}/train-gbt.ts +35 -154
  34. package/lib/tools/train-org-cross-gbt.ts +179 -0
  35. package/{tools → lib/tools}/txhhsc-to-oarow.ts +9 -27
  36. package/lib/tools/viz/browser.ts +50 -0
  37. package/{tools → lib/tools}/viz/cross-dataset-map.ts +7 -8
  38. package/{tools → lib/tools}/viz/geocode-first-surface.ts +10 -8
  39. package/{tools → lib/tools}/viz/render-map.ts +10 -23
  40. package/lib/tools/viz/render.ts +98 -0
  41. package/{tools → lib/tools}/viz/source-provenance-map.ts +8 -10
  42. package/{tools → lib/tools}/viz/yardstick-figure.ts +6 -5
  43. package/out/address-key.d.ts +1 -1
  44. package/out/address-key.d.ts.map +1 -1
  45. package/out/address-key.js.map +1 -1
  46. package/out/geocode-handler.d.ts +6 -6
  47. package/out/geocode-handler.d.ts.map +1 -1
  48. package/out/geocode-handler.js +6 -6
  49. package/out/geocode-handler.js.map +1 -1
  50. package/out/geojson.d.ts +7 -2
  51. package/out/geojson.d.ts.map +1 -1
  52. package/out/geojson.js +5 -3
  53. package/out/geojson.js.map +1 -1
  54. package/out/index.d.ts +10 -10
  55. package/out/index.d.ts.map +1 -1
  56. package/out/index.js +10 -10
  57. package/out/index.js.map +1 -1
  58. package/out/ingest.d.ts +64 -46
  59. package/out/ingest.d.ts.map +1 -1
  60. package/out/ingest.js +31 -45
  61. package/out/ingest.js.map +1 -1
  62. package/out/learned-scorer.d.ts +1 -1
  63. package/out/learned-scorer.d.ts.map +1 -1
  64. package/out/learned-scorer.js.map +1 -1
  65. package/out/map-html.d.ts +3 -3
  66. package/out/map-html.d.ts.map +1 -1
  67. package/out/map-html.js +6 -11
  68. package/out/map-html.js.map +1 -1
  69. package/out/models/crosssource-gbt-en-us.d.ts.map +1 -1
  70. package/out/models/crosssource-gbt-en-us.js.map +1 -1
  71. package/out/models/dedup-gbt-en-us.d.ts.map +1 -1
  72. package/out/models/dedup-gbt-en-us.js.map +1 -1
  73. package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -1
  74. package/out/models/org-crosssource-gbt-en-us.js.map +1 -1
  75. package/out/reconcile.d.ts +6 -1
  76. package/out/reconcile.d.ts.map +1 -1
  77. package/out/reconcile.js +5 -20
  78. package/out/reconcile.js.map +1 -1
  79. package/out/resolve.d.ts +19 -7
  80. package/out/resolve.d.ts.map +1 -1
  81. package/out/resolve.js +16 -5
  82. package/out/resolve.js.map +1 -1
  83. package/out/tools/coverage-reconciliation.d.ts +1 -1
  84. package/out/tools/coverage-reconciliation.d.ts.map +1 -1
  85. package/out/tools/coverage-reconciliation.js +11 -11
  86. package/out/tools/coverage-reconciliation.js.map +1 -1
  87. package/out/tools/cross-dataset-correlation.d.ts +4 -4
  88. package/out/tools/cross-dataset-correlation.d.ts.map +1 -1
  89. package/out/tools/cross-dataset-correlation.js +57 -109
  90. package/out/tools/cross-dataset-correlation.js.map +1 -1
  91. package/out/tools/cross-source-threshold-sweep.d.ts +2 -2
  92. package/out/tools/cross-source-threshold-sweep.d.ts.map +1 -1
  93. package/out/tools/cross-source-threshold-sweep.js +19 -27
  94. package/out/tools/cross-source-threshold-sweep.js.map +1 -1
  95. package/out/tools/dedup-ceiling.d.ts.map +1 -1
  96. package/out/tools/dedup-ceiling.js +36 -117
  97. package/out/tools/dedup-ceiling.js.map +1 -1
  98. package/out/tools/eval-geocoder.d.ts +8 -12
  99. package/out/tools/eval-geocoder.d.ts.map +1 -1
  100. package/out/tools/eval-geocoder.js +2 -2
  101. package/out/tools/eval-geocoder.js.map +1 -1
  102. package/out/tools/geocoder-namesake-probe.d.ts +2 -2
  103. package/out/tools/geocoder-namesake-probe.d.ts.map +1 -1
  104. package/out/tools/geocoder-namesake-probe.js +4 -8
  105. package/out/tools/geocoder-namesake-probe.js.map +1 -1
  106. package/out/tools/geocoder-vs-provided-coords.d.ts +1 -1
  107. package/out/tools/geocoder-vs-provided-coords.d.ts.map +1 -1
  108. package/out/tools/geocoder-vs-provided-coords.js +8 -7
  109. package/out/tools/geocoder-vs-provided-coords.js.map +1 -1
  110. package/out/tools/gold-set-sample.d.ts +5 -5
  111. package/out/tools/gold-set-sample.d.ts.map +1 -1
  112. package/out/tools/gold-set-sample.js +37 -122
  113. package/out/tools/gold-set-sample.js.map +1 -1
  114. package/out/tools/index.d.ts +23 -23
  115. package/out/tools/index.d.ts.map +1 -1
  116. package/out/tools/index.js +23 -23
  117. package/out/tools/index.js.map +1 -1
  118. package/out/tools/learned-scorer-clustering-eval.d.ts +1 -1
  119. package/out/tools/learned-scorer-clustering-eval.d.ts.map +1 -1
  120. package/out/tools/learned-scorer-clustering-eval.js +35 -169
  121. package/out/tools/learned-scorer-clustering-eval.js.map +1 -1
  122. package/out/tools/learned-scorer-crossstate-eval.d.ts +5 -5
  123. package/out/tools/learned-scorer-crossstate-eval.d.ts.map +1 -1
  124. package/out/tools/learned-scorer-crossstate-eval.js +44 -166
  125. package/out/tools/learned-scorer-crossstate-eval.js.map +1 -1
  126. package/out/tools/learned-scorer-eval.d.ts +1 -1
  127. package/out/tools/learned-scorer-eval.d.ts.map +1 -1
  128. package/out/tools/learned-scorer-eval.js +37 -168
  129. package/out/tools/learned-scorer-eval.js.map +1 -1
  130. package/out/tools/matcher-scale.d.ts.map +1 -1
  131. package/out/tools/matcher-scale.js +4 -4
  132. package/out/tools/matcher-scale.js.map +1 -1
  133. package/out/tools/nppes/org-name.d.ts +2 -5
  134. package/out/tools/nppes/org-name.d.ts.map +1 -1
  135. package/out/tools/nppes/org-name.js +1 -30
  136. package/out/tools/nppes/org-name.js.map +1 -1
  137. package/out/tools/nppes/overmerge-packet.d.ts +3 -3
  138. package/out/tools/nppes/overmerge-packet.d.ts.map +1 -1
  139. package/out/tools/nppes/overmerge-packet.js +3 -3
  140. package/out/tools/nppes/overmerge-packet.js.map +1 -1
  141. package/out/tools/nppes/report.d.ts +5 -5
  142. package/out/tools/nppes/report.d.ts.map +1 -1
  143. package/out/tools/nppes/report.js +17 -19
  144. package/out/tools/nppes/report.js.map +1 -1
  145. package/out/tools/nppes/sample.d.ts +32 -6
  146. package/out/tools/nppes/sample.d.ts.map +1 -1
  147. package/out/tools/nppes/sample.js +44 -26
  148. package/out/tools/nppes/sample.js.map +1 -1
  149. package/out/tools/nppes/scoring.d.ts.map +1 -1
  150. package/out/tools/nppes/scoring.js.map +1 -1
  151. package/out/tools/nppes/{levers.d.ts → settings.d.ts} +8 -8
  152. package/out/tools/nppes/settings.d.ts.map +1 -0
  153. package/out/tools/nppes/{levers.js → settings.js} +8 -8
  154. package/out/tools/nppes/settings.js.map +1 -0
  155. package/out/tools/nppes/truth-grains.d.ts +2 -2
  156. package/out/tools/nppes/truth-grains.d.ts.map +1 -1
  157. package/out/tools/nppes/truth-grains.js +4 -29
  158. package/out/tools/nppes/truth-grains.js.map +1 -1
  159. package/out/tools/nppes-dedup-benchmark.d.ts +4 -4
  160. package/out/tools/nppes-dedup-benchmark.d.ts.map +1 -1
  161. package/out/tools/nppes-dedup-benchmark.js +40 -34
  162. package/out/tools/nppes-dedup-benchmark.js.map +1 -1
  163. package/out/tools/shared.d.ts +244 -7
  164. package/out/tools/shared.d.ts.map +1 -1
  165. package/out/tools/shared.js +349 -18
  166. package/out/tools/shared.js.map +1 -1
  167. package/out/tools/train-cross-gbt.d.ts +7 -7
  168. package/out/tools/train-cross-gbt.d.ts.map +1 -1
  169. package/out/tools/train-cross-gbt.js +47 -145
  170. package/out/tools/train-cross-gbt.js.map +1 -1
  171. package/out/tools/train-gbt.d.ts +7 -7
  172. package/out/tools/train-gbt.d.ts.map +1 -1
  173. package/out/tools/train-gbt.js +31 -111
  174. package/out/tools/train-gbt.js.map +1 -1
  175. package/out/tools/train-org-cross-gbt.d.ts +7 -5
  176. package/out/tools/train-org-cross-gbt.d.ts.map +1 -1
  177. package/out/tools/train-org-cross-gbt.js +45 -141
  178. package/out/tools/train-org-cross-gbt.js.map +1 -1
  179. package/out/tools/txhhsc-to-oarow.d.ts +2 -2
  180. package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
  181. package/out/tools/txhhsc-to-oarow.js +8 -22
  182. package/out/tools/txhhsc-to-oarow.js.map +1 -1
  183. package/out/tools/viz/browser.d.ts +34 -0
  184. package/out/tools/viz/browser.d.ts.map +1 -0
  185. package/out/tools/viz/browser.js +33 -0
  186. package/out/tools/viz/browser.js.map +1 -0
  187. package/out/tools/viz/cross-dataset-map.d.ts +2 -2
  188. package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
  189. package/out/tools/viz/cross-dataset-map.js +6 -6
  190. package/out/tools/viz/cross-dataset-map.js.map +1 -1
  191. package/out/tools/viz/geocode-first-surface.d.ts +4 -3
  192. package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
  193. package/out/tools/viz/geocode-first-surface.js +7 -5
  194. package/out/tools/viz/geocode-first-surface.js.map +1 -1
  195. package/out/tools/viz/render-map.d.ts +3 -6
  196. package/out/tools/viz/render-map.d.ts.map +1 -1
  197. package/out/tools/viz/render-map.js +9 -19
  198. package/out/tools/viz/render-map.js.map +1 -1
  199. package/out/tools/viz/render.d.ts +4 -9
  200. package/out/tools/viz/render.d.ts.map +1 -1
  201. package/out/tools/viz/render.js +24 -39
  202. package/out/tools/viz/render.js.map +1 -1
  203. package/out/tools/viz/source-provenance-map.d.ts +2 -2
  204. package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
  205. package/out/tools/viz/source-provenance-map.js +6 -7
  206. package/out/tools/viz/source-provenance-map.js.map +1 -1
  207. package/out/tools/viz/yardstick-figure.d.ts +2 -2
  208. package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
  209. package/out/tools/viz/yardstick-figure.js +5 -4
  210. package/out/tools/viz/yardstick-figure.js.map +1 -1
  211. package/out/types.d.ts.map +1 -1
  212. package/out/types.js.map +1 -1
  213. package/package.json +115 -15
  214. package/out/tools/nppes/levers.d.ts.map +0 -1
  215. package/out/tools/nppes/levers.js.map +0 -1
  216. package/tools/gold-set-sample.ts +0 -254
  217. package/tools/index.ts +0 -31
  218. package/tools/nppes/org-name.ts +0 -56
  219. package/tools/shared.ts +0 -162
  220. package/tools/train-cross-gbt.ts +0 -359
  221. package/tools/train-org-cross-gbt.ts +0 -330
  222. package/tools/viz/render.ts +0 -113
  223. /package/{models → lib/models}/crosssource-gbt-en-us.ts +0 -0
  224. /package/{models → lib/models}/dedup-gbt-en-us.ts +0 -0
  225. /package/{models → lib/models}/org-crosssource-gbt-en-us.ts +0 -0
  226. /package/{tools → lib/tools}/nppes/scoring.ts +0 -0
  227. /package/{types.ts → lib/types.ts} +0 -0
@@ -9,10 +9,10 @@
9
9
  import type { TermFrequencyTable } from "@mailwoman/match"
10
10
 
11
11
  import type { ResolveResult } from "#index"
12
-
13
- import { ORG_TAU } from "./org-name.ts"
14
- import type { Score } from "./scoring.ts"
15
- import { COLOCATION_KM } from "./truth-grains.ts"
12
+ import { ORG_TAU } from "#tools/nppes/org-name"
13
+ import type { Score } from "#tools/nppes/scoring"
14
+ import { COLOCATION_KM } from "#tools/nppes/truth-grains"
15
+ import { pct } from "#tools/shared"
16
16
 
17
17
  /**
18
18
  * F1 gap within which two blocking strategies are treated as equivalent.
@@ -20,9 +20,9 @@ import { COLOCATION_KM } from "./truth-grains.ts"
20
20
  const BLOCKING_PARITY_TOLERANCE = 0.015
21
21
 
22
22
  /**
23
- * One row of the lever progression, scored at the default threshold.
23
+ * One row of the setting progression, scored at the default threshold.
24
24
  */
25
- export interface LeverScore {
25
+ export interface SettingScore {
26
26
  label: string
27
27
  score: Score
28
28
  }
@@ -59,9 +59,9 @@ export interface NPPESReportInput {
59
59
  */
60
60
  addressFrequency: TermFrequencyTable
61
61
  /**
62
- * The lever progression in order. The first row is the bare baseline, the last the full stack.
62
+ * The setting progression in order. The first row is the bare baseline, the last the full stack.
63
63
  */
64
- progression: readonly LeverScore[]
64
+ progression: readonly SettingScore[]
65
65
  /**
66
66
  * Zero-config `resolveEntities(records)` — reported apart from the progression because its address-frequency table is
67
67
  * input-scoped, which on a sub-sample is intentionally sparse.
@@ -129,16 +129,13 @@ export function renderNPPESDedupReport(input: NPPESReportInput): string {
129
129
  geocodedNpis,
130
130
  } = input
131
131
 
132
- const baseline = progression[0]! // no levers — the prior-prior behaviour
132
+ const baseline = progression[0]! // no settings — the prior-prior behaviour
133
133
  // The LAST progression row — the whole A1–A5 stack, never compared on F1 against the others. Named for what it
134
- // is: a row called `best` invites reading a stack-wide delta as one lever's marginal effect, which is how the
135
- // authorized-official sentence below came to quote a five-lever number.
134
+ // is: a row called `best` invites reading a stack-wide delta as one setting's marginal effect, which is how the
135
+ // authorized-official sentence below came to quote a five-setting number.
136
136
  const fullStack = progression.at(-1)!
137
- const base = sweep[0]! // threshold 0, full lever stack
137
+ const base = sweep[0]! // threshold 0, full setting stack
138
138
 
139
- // NOTE(phase4): local pct keeps the fraction-in/no-%-suffix shape — not core formatPercent's
140
- // numerator/denominator contract (call sites append their own "%").
141
- const pct = (x: number) => (100 * x).toFixed(1)
142
139
  const signed = (x: number) => `${x >= 0 ? "+" : ""}${x.toFixed(1)}pp`
143
140
 
144
141
  const lines: string[] = [
@@ -157,7 +154,7 @@ export function renderNPPESDedupReport(input: NPPESReportInput): string {
157
154
  `(${keptNpis} NPI → ${entityCount} site → ${orgCount} org-name classes); the climb is the yardstick getting honest, ` +
158
155
  `not the model changing — gold-set validated (120/120 hard pairs = same org). Details in "Three truth grains" below.`,
159
156
  "",
160
- `## The comparison-model levers (each toggled on, at the default threshold)`,
157
+ `## The comparison-model settings (each toggled on, at the default threshold)`,
161
158
  "",
162
159
  `| model | precision | recall | F1 | ΔF1 | ARI | over-merged |`,
163
160
  `|---|---:|---:|---:|---:|---:|---:|`,
@@ -188,7 +185,7 @@ export function renderNPPESDedupReport(input: NPPESReportInput): string {
188
185
  lines.push("")
189
186
 
190
187
  lines.push(
191
- `**Out-of-the-box (zero-config \`resolveEntities(records)\`, levers default-on #86):** F1 ` +
188
+ `**Out-of-the-box (zero-config \`resolveEntities(records)\`, settings default-on #86):** F1 ` +
192
189
  `**${pct(defaultOutOfBox.f1)}%** on this sample — essentially the baseline. The default auto-computes the ` +
193
190
  `address-frequency table over the INPUT records, and this benchmark deliberately sub-samples ${N} records, so ` +
194
191
  `that table is too sparse to carry the inverse-frequency signal (a corpus statistic you can't synthesize from a ` +
@@ -199,7 +196,7 @@ export function renderNPPESDedupReport(input: NPPESReportInput): string {
199
196
  )
200
197
 
201
198
  lines.push("")
202
- lines.push(`## With all levers on, across the link threshold (the secondary lever)`)
199
+ lines.push(`## With all settings on, across the link threshold (the secondary setting)`)
203
200
  lines.push("")
204
201
  lines.push(`| link threshold (bits) | precision | recall | F1 | ARI | clusters | over-merged |`)
205
202
  lines.push(`|---:|---:|---:|---:|---:|---:|---:|`)
@@ -297,10 +294,10 @@ export function renderNPPESDedupReport(input: NPPESReportInput): string {
297
294
  `**Tier 2D — tightening the org-name ruler with the geocode coordinate.** The org-name truth above blocks by the address ` +
298
295
  `STRING (\`addressFrequencyKey\`), so two records at one building whose text differs — \`1504 Taub LOOP\` vs ` +
299
296
  `\`1504 Taub LP STE 100\` — key apart and the merge is still charged as an error. Block by the GEOCODED BUILDING instead ` +
300
- `(union co-located NPIs within ${COLOCATION_KM * 1000} m whose org names agree, same Jaccard gate) and the truth tightens ` +
297
+ `(union co-located NPIs within ${COLOCATION_KM * 1000} m whose org names agree, same Jaccard check) and the truth tightens ` +
301
298
  `further: GBT **org-name ${pct(gbtOrg.f1)}% → org-name-coord ${pct(gbtOrgCoord.f1)}%** ` +
302
299
  `(${signed(100 * (gbtOrgCoord.f1 - gbtOrg.f1))}), ${orgCount} → ${orgCoordCount} classes, over ${geocodedNpis}/${keptNpis} ` +
303
- `geocoded NPIs. The string org-name F1 is a conservative LOWER bound; the coordinate one is tighter (the Jaccard gate ` +
300
+ `geocoded NPIs. The string org-name F1 is a conservative LOWER bound; the coordinate one is tighter (the Jaccard check ` +
304
301
  `still blocks distinct co-located orgs). Both are honest — the coordinate is the geocode-first key.`
305
302
  )
306
303
 
@@ -325,7 +322,7 @@ export function renderNPPESDedupReport(input: NPPESReportInput): string {
325
322
 
326
323
  lines.push(
327
324
  `**Takeaways:** (1) The dedup model's REAL quality is the **org-name F1 ~${pct(gbtOrg.f1)}%**, not the NPI-level ` +
328
- `${pct(gbtNPI.f1)}% — the difference was NPI over-segmentation, not model error. (2) The #625 lever was the YARDSTICK, ` +
325
+ `${pct(gbtNPI.f1)}% — the difference was NPI over-segmentation, not model error. (2) The #625 setting was the YARDSTICK, ` +
329
326
  `not the scorer: the corroboration-feature experiment (reverted) couldn't move precision because the over-merge was ` +
330
327
  `mostly correct. (3) The remaining org-name over-merge (${gbtOrg.overMergedClusters} clusters) is the genuine frontier — ` +
331
328
  `small, approaching the ceiling's ~1.6% irreducible (\`2026-06-16-dedup-ceiling.md\`). (4) Trust the large eval: a 50-NPI ` +
@@ -346,18 +343,18 @@ export function renderNPPESDedupReport(input: NPPESReportInput): string {
346
343
 
347
344
  lines.push(
348
345
  `The geocode-first **foundation works**: **${pct(geo / N)}%** of addresses placed, blocking + clustering clean — the ` +
349
- `geocoding (the Pelias/Nominatim-can't-do-this part) is not the bottleneck. The comparison-model levers reach the ` +
346
+ `geocoding (the Pelias/Nominatim-can't-do-this part) is not the bottleneck. The comparison-model settings reach the ` +
350
347
  `address-frequency + A1 baseline at F1 **${pct(progression[2]!.score.f1)}%** (${signed(100 * (progression[2]!.score.f1 - baseline.score.f1))} over baseline): ` +
351
348
  `inverse-frequency weighting restores full weight to a *rare* shared address (stitching a provider's name-drifted ` +
352
349
  `records together — mostly recall) while down-weighting a *crowded* one, and the collapsed spatial signal (A1) drops ` +
353
350
  `the address+distance double-count. What remains is **precision / over-merge** — ${fullStack.score.overMergedClusters} ` +
354
351
  `clusters still fuse distinct co-located providers, because even one down-weighted spatial agreement can outvote a ` +
355
- `disagreeing name. The lever search (#625) — two negatives, then the first positive: a name/org/phone ` +
356
- `**corroboration gate** (A2/A3) — phone is an unreliable secondary identifier on NPPES (shared institutional ` +
352
+ `disagreeing name. The setting search (#625) — two negatives, then the first positive: a name/org/phone ` +
353
+ `**corroboration check** (A2/A3) — phone is an unreliable secondary identifier on NPPES (shared institutional ` +
357
354
  `switchboard lines), so it over-links and falsely corroborates co-phone distinct providers; and **average-linkage ` +
358
355
  `clustering** (A4) — the over-merged clusters are joined by STRONG shared-address edges, not weak bridges, so ` +
359
356
  `average-linkage can't split them and only trades away name-drift recall. The over-merge is a **scoring** problem ` +
360
- `this data can't resolve, not a clustering-topology one. The **authorized-official discriminator** is the first lever to beat the baseline — a reliable secondary identifier holds recall so a higher threshold separates the co-located providers; a still-more-distinctive identifier ` +
357
+ `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 ` +
361
358
  `(taxonomy / license) or a learned scorer over the FS feature vector (#603) goes further. Config ` +
362
359
  `dominates the model (the pre-registered finding) — tracked as #625 / the selective-model work (#602 / #603).`
363
360
  )
@@ -3,16 +3,16 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
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.
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.
7
8
  */
8
9
 
9
10
  import { isPresent } from "@mailwoman/core/objects"
10
11
  import type { TermFrequencyTable } from "@mailwoman/match"
11
12
 
12
13
  import { addressFrequencyKey, streamRows } from "#index"
13
-
14
- import { addr, MIN_GROUP_SIZE, norm, NPPES_COLUMNS as C } from "../shared.ts"
15
- import { orgTokens, type NPIPrimary } from "./org-name.ts"
14
+ import { orgTokens, type NPIPrimary } from "#tools/nppes/org-name"
15
+ import { addr, MIN_GROUP_SIZE, norm, NPPES_COLUMNS as C } from "#tools/shared"
16
16
 
17
17
  /**
18
18
  * One synthetic input row for the matcher; `npi` is the hidden NPI-level truth, `entityID` the site-level entity-level
@@ -32,9 +32,9 @@ export interface MessyRow extends Record<string, string> {
32
32
  }
33
33
 
34
34
  /**
35
- * What the sample pass yields.
35
+ * One state's slice of the sample pass.
36
36
  */
37
- export interface NPPESSample {
37
+ export interface NPPESStateSample {
38
38
  rows: MessyRow[]
39
39
  /**
40
40
  * The sampled NPIs — the true-entity count at the NPI grain.
@@ -44,6 +44,12 @@ export interface NPPESSample {
44
44
  * Per-NPI primary org name + practice address key, the basis for the org-name entity truths.
45
45
  */
46
46
  npiPrimary: Map<string, NPIPrimary>
47
+ }
48
+
49
+ /**
50
+ * What the single-state sample pass yields.
51
+ */
52
+ export interface NPPESSample extends NPPESStateSample {
47
53
  /**
48
54
  * Corpus-wide address-frequency table — the inverse-frequency signal. Counted over EVERY practice address in the
49
55
  * registry, not just the sample, so the sharing structure is a corpus statistic rather than a slice artifact.
@@ -65,16 +71,30 @@ export interface NPPESSampleOptions {
65
71
  }
66
72
 
67
73
  /**
68
- * Build the benchmark's input records from the real registry.
74
+ * The multi-state shape of {@linkcode NPPESSampleOptions} — one registry pass fills every state's bucket.
75
+ */
76
+ export interface NPPESMultiSampleOptions {
77
+ registryPath: string
78
+ otherNamesPath: string
79
+ /**
80
+ * Already upper-cased; compared against the practice-location state column.
81
+ */
82
+ states: readonly string[]
83
+ maxNpisPerState: number
84
+ }
85
+
86
+ /**
87
+ * Build the benchmark's input records from the real registry, one bucket per requested state.
69
88
  *
70
89
  * Two passes over two files, and the SECOND one cannot break early: the address-frequency table needs every registry
71
- * row even after the sample is full, so the `kept.size < maxNpis` test gates only the sample branch.
90
+ * row even after the sample is full, so the per-bucket `keptNpis.size < maxNpisPerState` test bounds only the sample
91
+ * branch.
72
92
  */
73
- export async function buildNPPESSample(
74
- options: NPPESSampleOptions,
93
+ export async function buildNPPESStateSamples(
94
+ options: NPPESMultiSampleOptions,
75
95
  report?: (line: string) => void
76
- ): Promise<NPPESSample> {
77
- const { registryPath, otherNamesPath, state, maxNpis } = options
96
+ ): Promise<{ byState: Map<string, NPPESStateSample>; addressFrequency: TermFrequencyTable }> {
97
+ const { registryPath, otherNamesPath, states, maxNpisPerState } = options
78
98
 
79
99
  // --- Phase A: the variation set — NPIs that carry ≥1 alternate organization name. ---
80
100
  report?.("[A] streaming other-names…")
@@ -98,19 +118,21 @@ export async function buildNPPESSample(
98
118
  report?.(` ${altNames.size} NPIs with ≥1 alternate name`)
99
119
 
100
120
  // --- Phase B: ONE full registry pass — build the GLOBAL address-frequency table (every practice
101
- // address, so the sharing structure is corpus-wide, not sample-biased) AND collect the sample. ---
102
- report?.(`[B] full registry pass: address-frequency table + ${maxNpis} ${state} sample…`)
103
- const rows: MessyRow[] = []
104
- const kept = new Set<string>()
105
- // Per-NPI primary org name + practice address key — the basis for the ORG-NAME entity-truth.
106
- const npiPrimary = new Map<string, NPIPrimary>()
121
+ // address, so the sharing structure is corpus-wide, not sample-biased) AND collect every state's sample. ---
122
+ report?.(`[B] full registry pass: address-frequency table + ${maxNpisPerState} × ${states.join("/")} sample…`)
123
+
124
+ const byState = new Map<string, NPPESStateSample>(
125
+ states.map((state) => [state, { rows: [], keptNpis: new Set<string>(), npiPrimary: new Map<string, NPIPrimary>() }])
126
+ )
127
+
107
128
  const addrCounts = new Map<string, number>()
108
129
  let addrTotal = 0
109
130
  let scanned = 0
131
+ let keptTotal = 0
110
132
 
111
133
  for await (const r of streamRows(registryPath)) {
112
134
  if (++scanned % 1_000_000 === 0) {
113
- report?.(` scanned ${scanned / 1e6}M rows, kept ${kept.size}`)
135
+ report?.(` scanned ${scanned / 1e6}M rows, kept ${keptTotal}`)
114
136
  }
115
137
 
116
138
  const practice = addr(r[C.pAddr]!, r[C.pCity]!, r[C.pState]!, r[C.pZip]!)
@@ -123,16 +145,18 @@ export async function buildNPPESSample(
123
145
  addrTotal++
124
146
  }
125
147
 
126
- // Sample: in-state NPIs with ≥1 alternate name, up to maxNpis — NO early break (the table needs the full pass).
148
+ // Sample: in-state NPIs with ≥1 alternate name, up to maxNpisPerState — NO early break (the table
149
+ // needs the full pass).
127
150
  const npi = norm(r[C.npi])
151
+ const bucket = byState.get(norm(r[C.pState]).toUpperCase())
128
152
 
129
153
  if (
130
- kept.size < maxNpis &&
154
+ bucket &&
155
+ bucket.keptNpis.size < maxNpisPerState &&
131
156
  npi &&
132
- !kept.has(npi) &&
157
+ !bucket.keptNpis.has(npi) &&
133
158
  altNames.has(npi) &&
134
- practice &&
135
- norm(r[C.pState]).toUpperCase() === state
159
+ practice
136
160
  ) {
137
161
  const isOrg = norm(r[C.entityType]) === "2"
138
162
  const primaryName = isOrg ? norm(r[C.orgLegal]) : `${norm(r[C.first])} ${norm(r[C.last])}`.trim()
@@ -161,22 +185,24 @@ export async function buildNPPESSample(
161
185
  const eid = (a: string) => `${addressFrequencyKey(a)}|${orgKey}`
162
186
 
163
187
  if (org) {
164
- npiPrimary.set(npi, { tokens: orgTokens(org), addrKey: addressFrequencyKey(practice) })
188
+ bucket.npiPrimary.set(npi, { tokens: orgTokens(org), addrKey: addressFrequencyKey(practice) })
165
189
  }
166
190
 
167
- kept.add(npi)
168
- rows.push({ npi, name: primaryName, org, address: practice, auth, taxonomy, entityID: eid(practice) })
191
+ bucket.keptNpis.add(npi)
192
+
193
+ keptTotal++
194
+ bucket.rows.push({ npi, name: primaryName, org, address: practice, auth, taxonomy, entityID: eid(practice) })
169
195
 
170
196
  // primary
171
197
  for (const alt of altNames.get(npi)!) {
172
- rows.push({ npi, name: alt, org: alt, address: practice, auth, taxonomy, entityID: eid(practice) })
198
+ bucket.rows.push({ npi, name: alt, org: alt, address: practice, auth, taxonomy, entityID: eid(practice) })
173
199
  }
174
200
 
175
201
  // name drift
176
202
  const mailing = addr(r[C.mAddr]!, r[C.mCity]!, r[C.mState]!, r[C.mZip]!)
177
203
 
178
204
  if (mailing && mailing !== practice) {
179
- rows.push({ npi, name: primaryName, org, address: mailing, auth, taxonomy, entityID: eid(mailing) })
205
+ bucket.rows.push({ npi, name: primaryName, org, address: mailing, auth, taxonomy, entityID: eid(mailing) })
180
206
  } // address variation
181
207
  }
182
208
  }
@@ -189,9 +215,31 @@ export async function buildNPPESSample(
189
215
  frequency: (v: string) => (v ? (addrCounts.get(addressFrequencyKey(v)) ?? 0) / addrTotal : 0),
190
216
  }
191
217
 
192
- report?.(
193
- ` ${kept.size} NPIs → ${rows.length} records; address table: ${addrCounts.size} distinct over ${addrTotal} rows`
218
+ for (const [state, bucket] of byState) {
219
+ report?.(` ${state}: ${bucket.keptNpis.size} NPIs → ${bucket.rows.length} records`)
220
+ }
221
+
222
+ report?.(` address table: ${addrCounts.size} distinct over ${addrTotal} rows`)
223
+
224
+ return { byState, addressFrequency }
225
+ }
226
+
227
+ /**
228
+ * Build one state's benchmark input records — {@linkcode buildNPPESStateSamples} with a single bucket.
229
+ */
230
+ export async function buildNPPESSample(
231
+ options: NPPESSampleOptions,
232
+ report?: (line: string) => void
233
+ ): Promise<NPPESSample> {
234
+ const { byState, addressFrequency } = await buildNPPESStateSamples(
235
+ {
236
+ registryPath: options.registryPath,
237
+ otherNamesPath: options.otherNamesPath,
238
+ states: [options.state],
239
+ maxNpisPerState: options.maxNpis,
240
+ },
241
+ report
194
242
  )
195
243
 
196
- return { rows, keptNpis: kept, npiPrimary, addressFrequency }
244
+ return { ...byState.get(options.state)!, addressFrequency }
197
245
  }
@@ -2,7 +2,7 @@
2
2
  * @copyright Sister Software
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
- * @file The comparison-model lever progression the NPPES benchmark walks — each row turns one lever on so its marginal
5
+ * @file The comparison-model setting progression the NPPES benchmark walks — each row turns one setting on so its marginal
6
6
  * effect is isolated.
7
7
  */
8
8
 
@@ -11,7 +11,7 @@ import type { TermFrequencyTable } from "@mailwoman/match"
11
11
  /**
12
12
  * The subset of `ResolveConfig` this progression varies.
13
13
  */
14
- export interface LeverConfig {
14
+ export interface SettingConfig {
15
15
  addressFrequency?: TermFrequencyTable | false
16
16
  collapseSpatial?: boolean
17
17
  discriminators?: string[]
@@ -24,24 +24,24 @@ export interface LeverConfig {
24
24
  /**
25
25
  * One row of the progression.
26
26
  */
27
- export interface Lever {
27
+ export interface Setting {
28
28
  label: string
29
- config: LeverConfig
29
+ config: SettingConfig
30
30
  }
31
31
 
32
32
  /**
33
33
  * Build the progression against a corpus-wide address-frequency table.
34
34
  *
35
- * Every row sets BOTH `collapseSpatial` and `addressFrequency` EXPLICITLY, because the proven levers are default-on in
36
- * `resolveEntities`: leave either implicit and the flipped default silently rides the `+ inverse-address-frequency`
35
+ * Every row sets BOTH `collapseSpatial` and `addressFrequency` EXPLICITLY, because the proven settings are default-on
36
+ * in `resolveEntities`: leave either implicit and the flipped default silently rides the `+ inverse-address-frequency`
37
37
  * row, making the A1 delta read as 0. Every row is fed the corpus-wide table — the realistic deployment, where the CLI
38
38
  * builds it from the full source files — so the zero-config default, whose input-scoped table is intentionally sparse
39
39
  * on a sub-sample, has to be measured separately.
40
40
  */
41
- export function buildLevers(addressFrequency: TermFrequencyTable): Lever[] {
41
+ export function buildSettings(addressFrequency: TermFrequencyTable): Setting[] {
42
42
  return [
43
43
  {
44
- label: "baseline (legacy: address-key + distance, levers OFF)",
44
+ label: "baseline (legacy: address-key + distance, settings OFF)",
45
45
  config: { collapseSpatial: false, addressFrequency: false },
46
46
  },
47
47
  { label: "+ inverse-address-frequency (#617, corpus-wide)", config: { collapseSpatial: false, addressFrequency } },
@@ -50,9 +50,9 @@ export function buildLevers(addressFrequency: TermFrequencyTable): Lever[] {
50
50
  label: "+ authorized-official discriminator (#625)",
51
51
  config: { collapseSpatial: true, addressFrequency, discriminators: ["authorizedOfficial"] },
52
52
  },
53
- // A2–A4 (#625): the built-but-unmeasured over-merge levers. Each builds on the A1 + discriminator
53
+ // A2–A4 (#625): the built-but-unmeasured over-merge settings. Each builds on the A1 + discriminator
54
54
  // stack so the marginal effect is isolated. A2 (require name/org corroboration) is the direct
55
- // over-merge precision lever; A3 (phone) is the recall-tail corroborator that should keep A2 from
55
+ // over-merge precision setting; A3 (phone) is the recall-tail corroborator that should keep A2 from
56
56
  // killing name-drift links; A4 (average-linkage) splits a component joined only by a weak bridge.
57
57
  {
58
58
  label: "+ require name/org corroboration (A2, #625)",
@@ -6,12 +6,12 @@
6
6
  * ways — the address string, a haversine co-location radius, and an H3 cell.
7
7
  */
8
8
 
9
+ import { createUnionFind, type UnionFind } from "@mailwoman/core/utils"
9
10
  import { haversineKm, jaccard, type LatLon } from "@mailwoman/match"
10
11
  import { latLngToCell } from "h3-js"
11
12
 
12
13
  import type { SourceRecord } from "#index"
13
-
14
- import { ORG_TAU, type NPIPrimary } from "./org-name.ts"
14
+ import { ORG_TAU, type NPIPrimary } from "#tools/nppes/org-name"
15
15
 
16
16
  /**
17
17
  * Same-building distance for the coordinate grain — the `DEFAULT_DISTANCE_LEVELS` grain.
@@ -23,50 +23,10 @@ export const COLOCATION_KM = 0.05
23
23
  */
24
24
  export type TruthLabel = (rec: SourceRecord) => string
25
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
26
  /**
67
27
  * Union every pair in each block whose org names agree.
68
28
  *
69
- * Quadratic within a block, which is what keeps the gate honest: the Jaccard test is per PAIR, so a chain of
29
+ * Quadratic within a block, which is what keeps the test honest: the Jaccard test is per PAIR, so a chain of
70
30
  * near-matches cannot transitively fuse two genuinely distinct co-located orgs unless some pair actually agrees.
71
31
  */
72
32
  function unionAgreeingPairs(
@@ -136,7 +96,7 @@ export function buildOrgNameGrain(npiPrimary: Map<string, NPIPrimary>): TruthLab
136
96
  /**
137
97
  * The coordinate-keyed org-name truth: union same-org NPIs whose primary practice coordinates fall within
138
98
  * {@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.
99
+ * apart, so this F1 is at or above the string grain's; the Jaccard test still blocks distinct co-located orgs.
140
100
  *
141
101
  * Brute-force pairwise over the sampled NPIs — trivial at this scale, and unlike a cell key it has no boundary
142
102
  * artifact.