@mailwoman/registry 9.0.0 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +1 -1
  2. package/geojson.ts +3 -2
  3. package/ingest.ts +2 -1
  4. package/map-html.ts +4 -4
  5. package/out/geojson.d.ts.map +1 -1
  6. package/out/geojson.js +3 -2
  7. package/out/geojson.js.map +1 -1
  8. package/out/ingest.d.ts.map +1 -1
  9. package/out/ingest.js +2 -1
  10. package/out/ingest.js.map +1 -1
  11. package/out/map-html.d.ts +2 -2
  12. package/out/map-html.d.ts.map +1 -1
  13. package/out/map-html.js.map +1 -1
  14. package/out/reconcile.d.ts.map +1 -1
  15. package/out/reconcile.js +2 -1
  16. package/out/reconcile.js.map +1 -1
  17. package/out/resolve.d.ts.map +1 -1
  18. package/out/resolve.js +4 -1
  19. package/out/resolve.js.map +1 -1
  20. package/out/tools/coverage-reconciliation.js +2 -2
  21. package/out/tools/coverage-reconciliation.js.map +1 -1
  22. package/out/tools/cross-dataset-correlation.d.ts.map +1 -1
  23. package/out/tools/cross-dataset-correlation.js +6 -5
  24. package/out/tools/cross-dataset-correlation.js.map +1 -1
  25. package/out/tools/cross-source-threshold-sweep.js +2 -2
  26. package/out/tools/cross-source-threshold-sweep.js.map +1 -1
  27. package/out/tools/dedup-ceiling.d.ts.map +1 -1
  28. package/out/tools/dedup-ceiling.js +2 -3
  29. package/out/tools/dedup-ceiling.js.map +1 -1
  30. package/out/tools/eval-geocoder.d.ts +1 -1
  31. package/out/tools/eval-geocoder.d.ts.map +1 -1
  32. package/out/tools/geocoder-vs-provided-coords.d.ts.map +1 -1
  33. package/out/tools/geocoder-vs-provided-coords.js +3 -2
  34. package/out/tools/geocoder-vs-provided-coords.js.map +1 -1
  35. package/out/tools/gold-set-sample.d.ts.map +1 -1
  36. package/out/tools/gold-set-sample.js +4 -3
  37. package/out/tools/gold-set-sample.js.map +1 -1
  38. package/out/tools/index.d.ts +1 -6
  39. package/out/tools/index.d.ts.map +1 -1
  40. package/out/tools/index.js +1 -6
  41. package/out/tools/index.js.map +1 -1
  42. package/out/tools/learned-scorer-clustering-eval.d.ts.map +1 -1
  43. package/out/tools/learned-scorer-clustering-eval.js +1 -2
  44. package/out/tools/learned-scorer-clustering-eval.js.map +1 -1
  45. package/out/tools/learned-scorer-crossstate-eval.d.ts.map +1 -1
  46. package/out/tools/learned-scorer-crossstate-eval.js +1 -1
  47. package/out/tools/learned-scorer-crossstate-eval.js.map +1 -1
  48. package/out/tools/learned-scorer-eval.d.ts.map +1 -1
  49. package/out/tools/learned-scorer-eval.js +1 -6
  50. package/out/tools/learned-scorer-eval.js.map +1 -1
  51. package/out/tools/matcher-scale.d.ts.map +1 -1
  52. package/out/tools/matcher-scale.js +1 -1
  53. package/out/tools/matcher-scale.js.map +1 -1
  54. package/out/tools/nppes/levers.d.ts +38 -0
  55. package/out/tools/nppes/levers.d.ts.map +1 -0
  56. package/out/tools/nppes/levers.js +79 -0
  57. package/out/tools/nppes/levers.js.map +1 -0
  58. package/out/tools/nppes/org-name.d.ts +24 -0
  59. package/out/tools/nppes/org-name.d.ts.map +1 -0
  60. package/out/tools/nppes/org-name.js +42 -0
  61. package/out/tools/nppes/org-name.js.map +1 -0
  62. package/out/tools/nppes/overmerge-packet.d.ts +39 -0
  63. package/out/tools/nppes/overmerge-packet.d.ts.map +1 -0
  64. package/out/tools/nppes/overmerge-packet.js +55 -0
  65. package/out/tools/nppes/overmerge-packet.js.map +1 -0
  66. package/out/tools/nppes/report.d.ts +93 -0
  67. package/out/tools/nppes/report.d.ts.map +1 -0
  68. package/out/tools/nppes/report.js +188 -0
  69. package/out/tools/nppes/report.js.map +1 -0
  70. package/out/tools/nppes/sample.d.ts +64 -0
  71. package/out/tools/nppes/sample.d.ts.map +1 -0
  72. package/out/tools/nppes/sample.js +113 -0
  73. package/out/tools/nppes/sample.js.map +1 -0
  74. package/out/tools/nppes/scoring.d.ts +36 -0
  75. package/out/tools/nppes/scoring.d.ts.map +1 -0
  76. package/out/tools/nppes/scoring.js +80 -0
  77. package/out/tools/nppes/scoring.js.map +1 -0
  78. package/out/tools/nppes/truth-grains.d.ts +50 -0
  79. package/out/tools/nppes/truth-grains.d.ts.map +1 -0
  80. package/out/tools/nppes/truth-grains.js +148 -0
  81. package/out/tools/nppes/truth-grains.js.map +1 -0
  82. package/out/tools/nppes-dedup-benchmark.d.ts +4 -0
  83. package/out/tools/nppes-dedup-benchmark.d.ts.map +1 -1
  84. package/out/tools/nppes-dedup-benchmark.js +79 -652
  85. package/out/tools/nppes-dedup-benchmark.js.map +1 -1
  86. package/out/tools/shared.d.ts.map +1 -1
  87. package/out/tools/shared.js +5 -4
  88. package/out/tools/shared.js.map +1 -1
  89. package/out/tools/train-cross-gbt.d.ts.map +1 -1
  90. package/out/tools/train-cross-gbt.js +2 -2
  91. package/out/tools/train-cross-gbt.js.map +1 -1
  92. package/out/tools/train-gbt.d.ts.map +1 -1
  93. package/out/tools/train-gbt.js +2 -2
  94. package/out/tools/train-gbt.js.map +1 -1
  95. package/out/tools/train-org-cross-gbt.d.ts.map +1 -1
  96. package/out/tools/train-org-cross-gbt.js +2 -2
  97. package/out/tools/train-org-cross-gbt.js.map +1 -1
  98. package/out/tools/txhhsc-to-oarow.js +2 -2
  99. package/out/tools/txhhsc-to-oarow.js.map +1 -1
  100. package/out/tools/viz/cross-dataset-map.d.ts +2 -23
  101. package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
  102. package/out/tools/viz/cross-dataset-map.js +7 -28
  103. package/out/tools/viz/cross-dataset-map.js.map +1 -1
  104. package/out/tools/viz/geocode-first-surface.d.ts +2 -32
  105. package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
  106. package/out/tools/viz/geocode-first-surface.js +4 -33
  107. package/out/tools/viz/geocode-first-surface.js.map +1 -1
  108. package/out/tools/viz/render.js +1 -1
  109. package/out/tools/viz/render.js.map +1 -1
  110. package/out/tools/viz/source-provenance-map.d.ts +2 -22
  111. package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
  112. package/out/tools/viz/source-provenance-map.js +7 -26
  113. package/out/tools/viz/source-provenance-map.js.map +1 -1
  114. package/out/types.d.ts +11 -1
  115. package/out/types.d.ts.map +1 -1
  116. package/out/types.js.map +1 -1
  117. package/package.json +78 -9
  118. package/reconcile.ts +2 -1
  119. package/resolve.ts +6 -1
  120. package/tools/coverage-reconciliation.ts +3 -3
  121. package/tools/cross-dataset-correlation.ts +7 -5
  122. package/tools/cross-source-threshold-sweep.ts +3 -3
  123. package/tools/dedup-ceiling.ts +3 -3
  124. package/tools/eval-geocoder.ts +1 -1
  125. package/tools/geocoder-vs-provided-coords.ts +4 -2
  126. package/tools/gold-set-sample.ts +5 -3
  127. package/tools/index.ts +1 -6
  128. package/tools/learned-scorer-clustering-eval.ts +4 -4
  129. package/tools/learned-scorer-crossstate-eval.ts +4 -4
  130. package/tools/learned-scorer-eval.ts +4 -9
  131. package/tools/matcher-scale.ts +2 -1
  132. package/tools/nppes/levers.ts +102 -0
  133. package/tools/nppes/org-name.ts +56 -0
  134. package/tools/nppes/overmerge-packet.ts +96 -0
  135. package/tools/nppes/report.ts +376 -0
  136. package/tools/nppes/sample.ts +197 -0
  137. package/tools/nppes/scoring.ts +114 -0
  138. package/tools/nppes/truth-grains.ts +201 -0
  139. package/tools/nppes-dedup-benchmark.ts +92 -868
  140. package/tools/shared.ts +6 -4
  141. package/tools/train-cross-gbt.ts +6 -5
  142. package/tools/train-gbt.ts +5 -4
  143. package/tools/train-org-cross-gbt.ts +6 -5
  144. package/tools/txhhsc-to-oarow.ts +2 -2
  145. package/tools/viz/cross-dataset-map.ts +12 -34
  146. package/tools/viz/geocode-first-surface.ts +5 -33
  147. package/tools/viz/render.ts +1 -1
  148. package/tools/viz/source-provenance-map.ts +14 -31
  149. package/types.ts +10 -1
@@ -22,9 +22,11 @@
22
22
 
23
23
  import { writeFileSync } from "node:fs"
24
24
 
25
+ import { isPresent } from "@mailwoman/core/objects"
25
26
  import { dataRootPath } from "@mailwoman/core/utils"
26
27
  import { jaccard } from "@mailwoman/match"
27
- import { addressFrequencyKey, streamRows } from "@mailwoman/registry"
28
+
29
+ import { addressFrequencyKey, streamRows } from "#index"
28
30
 
29
31
  import { norm } from "./shared.ts"
30
32
 
@@ -93,7 +95,7 @@ const C = {
93
95
  pAddr: "Provider First Line Business Practice Location Address",
94
96
  pCity: "Provider Business Practice Location Address City Name",
95
97
  pState: "Provider Business Practice Location Address State Name",
96
- pZip: "Provider Business Practice Location Address Postal Code",
98
+ pZip: "Provider Business Practice Location Address Postcode",
97
99
  authLast: "Authorized Official Last Name",
98
100
  authFirst: "Authorized Official First Name",
99
101
  taxonomy: "Healthcare Provider Taxonomy Code_1",
@@ -140,7 +142,7 @@ export async function goldSetSample(
140
142
  const line1 = norm(r[C.pAddr])
141
143
 
142
144
  if (!org || !line1) continue
143
- const address = [line1, norm(r[C.pCity]), STATE, norm(r[C.pZip])].filter(Boolean).join(", ")
145
+ const address = [line1, norm(r[C.pCity]), STATE, norm(r[C.pZip])].filter(isPresent).join(", ")
144
146
  const addrKey = addressFrequencyKey(address)
145
147
 
146
148
  if (!addrKey) continue
package/tools/index.ts CHANGED
@@ -3,12 +3,7 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Registry operator tools — the `run()`-style modules behind `mailwoman registry …` commands. No
7
- * argv, no `process.exit`: commands own parsing, rendering, and exit codes (see the 2026-07-09
8
- * scripts→Pastel spec). The heavy geocoder is INJECTED via {@link EvalGeocoderFactory} — the
9
- * registry package never imports the runtime (`mailwoman` depends on this package, so the reverse
10
- * import would cycle). Heavy render deps (playwright/Chromium) are lazy-imported inside their
11
- * entry fns.
6
+ * Registry operator tool exports.
12
7
  */
13
8
 
14
9
  export * from "./coverage-reconciliation.ts"
@@ -32,6 +32,7 @@ import { writeFileSync } from "node:fs"
32
32
 
33
33
  import { dataRootPath, makeLcg } from "@mailwoman/core/utils"
34
34
  import { block, gbtScore, trainGBT } from "@mailwoman/match"
35
+
35
36
  import {
36
37
  addressFrequencyKey,
37
38
  buildDefaultModel,
@@ -43,7 +44,7 @@ import {
43
44
  type ColumnMapping,
44
45
  type ResolvedEntity,
45
46
  type SourceRecord,
46
- } from "@mailwoman/registry"
47
+ } from "#index"
47
48
 
48
49
  import type { EvalGeocoderFactory } from "./eval-geocoder.ts"
49
50
  import {
@@ -99,7 +100,7 @@ export interface ScorerClusteringEvalOptions {
99
100
  outMd?: string
100
101
  }
101
102
 
102
- interface MessyRow {
103
+ interface MessyRow extends Record<string, string> {
103
104
  npi: string
104
105
  name: string
105
106
  org: string
@@ -253,7 +254,7 @@ export async function scorerClusteringEval(
253
254
  const geocoder = await options.createGeocoder()
254
255
  const mapping: ColumnMapping = { id: "npi", name: "name", organization: "org", address: "address", source: "nppes" }
255
256
 
256
- const records = await ingestRows(rows as unknown as Record<string, string>[], mapping, {
257
+ const records = await ingestRows(rows, mapping, {
257
258
  geocodeAddress: geocoder.seam,
258
259
  })
259
260
 
@@ -432,7 +433,6 @@ export async function scorerClusteringEval(
432
433
  }
433
434
 
434
435
  const fsF1 = results.map((r) => r.fs.f1)
435
- const lrF1 = results.map((r) => r.lr.f1)
436
436
  const gbtF1 = results.map((r) => r.gbt.f1)
437
437
  const dGbt = results.map((r) => r.gbt.f1 - r.fs.f1)
438
438
  const dLr = results.map((r) => r.lr.f1 - r.fs.f1)
@@ -25,6 +25,7 @@ import { writeFileSync } from "node:fs"
25
25
 
26
26
  import { dataRootPath } from "@mailwoman/core/utils"
27
27
  import { block, gbtScore, trainGBT } from "@mailwoman/match"
28
+
28
29
  import {
29
30
  addressFrequencyKey,
30
31
  buildDefaultModel,
@@ -38,7 +39,7 @@ import {
38
39
  type ColumnMapping,
39
40
  type ResolvedEntity,
40
41
  type SourceRecord,
41
- } from "@mailwoman/registry"
42
+ } from "#index"
42
43
 
43
44
  import type { EvalGeocoderFactory } from "./eval-geocoder.ts"
44
45
  import {
@@ -88,7 +89,7 @@ export interface ScorerCrossStateEvalOptions {
88
89
 
89
90
  const choose2 = (n: number) => (n * (n - 1)) / 2
90
91
 
91
- interface MessyRow {
92
+ interface MessyRow extends Record<string, string> {
92
93
  npi: string
93
94
  name: string
94
95
  org: string
@@ -242,8 +243,7 @@ export async function scorerCrossStateEval(
242
243
  const geocoder = await options.createGeocoder()
243
244
  const mapping: ColumnMapping = { id: "npi", name: "name", organization: "org", address: "address", source: "nppes" }
244
245
 
245
- const geocodeRows = (rows: MessyRow[]) =>
246
- ingestRows(rows as unknown as Record<string, string>[], mapping, { geocodeAddress: geocoder.seam })
246
+ const geocodeRows = (rows: MessyRow[]) => ingestRows(rows, mapping, { geocodeAddress: geocoder.seam })
247
247
 
248
248
  const trainRecords = await geocodeRows(samples[TRAIN_STATE]!.rows)
249
249
  const evalRecords = await geocodeRows(samples[EVAL_STATE]!.rows)
@@ -39,6 +39,7 @@ import { writeFileSync } from "node:fs"
39
39
 
40
40
  import { dataRootPath, makeLcg } from "@mailwoman/core/utils"
41
41
  import { agreementPattern, block, estimateParameters, gbtScore, scorePair, trainGBT } from "@mailwoman/match"
42
+
42
43
  import {
43
44
  addressFrequencyKey,
44
45
  buildDefaultModel,
@@ -47,7 +48,7 @@ import {
47
48
  streamRows,
48
49
  type ColumnMapping,
49
50
  type SourceRecord,
50
- } from "@mailwoman/registry"
51
+ } from "#index"
51
52
 
52
53
  import type { EvalGeocoderFactory } from "./eval-geocoder.ts"
53
54
  import { addr, MIN_GROUP_SIZE, norm, NPPES_COLUMNS as C, TRAINING_EPOCHS } from "./shared.ts"
@@ -77,11 +78,6 @@ const STRONG_EVIDENCE_Z = 3
77
78
  */
78
79
  const TRAIN_SPLIT_FRACTION = 0.67
79
80
 
80
- /**
81
- * Highest k swept when scanning cluster counts.
82
- */
83
- const MAX_K = 32
84
-
85
81
  /**
86
82
  * Options for {@linkcode scorerPairwiseEval}.
87
83
  */
@@ -116,7 +112,7 @@ export interface ScorerPairwiseEvalOptions {
116
112
  outMd?: string
117
113
  }
118
114
 
119
- interface MessyRow {
115
+ interface MessyRow extends Record<string, string> {
120
116
  npi: string
121
117
  name: string
122
118
  org: string
@@ -254,7 +250,7 @@ export async function scorerPairwiseEval(
254
250
  const geocoder = await options.createGeocoder()
255
251
  const mapping: ColumnMapping = { id: "npi", name: "name", organization: "org", address: "address", source: "nppes" }
256
252
 
257
- const records = await ingestRows(rows as unknown as Record<string, string>[], mapping, {
253
+ const records = await ingestRows(rows, mapping, {
258
254
  geocodeAddress: geocoder.seam,
259
255
  })
260
256
 
@@ -518,7 +514,6 @@ export async function scorerPairwiseEval(
518
514
  const gbtF1s = splits.map((r) => bestF1(r.gbtScored).f1)
519
515
  const gbtVsFs = splits.map((_, i) => gbtAucs[i]! - fsAucs[i]!)
520
516
  const gbtVsLr = splits.map((_, i) => gbtAucs[i]! - lrAucs[i]!)
521
- const gbtBeatsFs = gbtVsFs.filter((d) => d > 0).length
522
517
  const gbtBeatsLr = gbtVsLr.filter((d) => d > 0).length
523
518
  const meanGbtVsFs = mean(gbtVsFs)
524
519
  const meanGbtVsLr = mean(gbtVsLr)
@@ -19,7 +19,8 @@
19
19
  import { writeFileSync } from "node:fs"
20
20
 
21
21
  import { makeLcg } from "@mailwoman/core/utils"
22
- import { resolveEntities, type SourceRecord } from "@mailwoman/registry"
22
+
23
+ import { resolveEntities, type SourceRecord } from "#index"
23
24
 
24
25
  /**
25
26
  * Options for {@linkcode matcherScale}.
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
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
6
+ * effect is isolated.
7
+ */
8
+
9
+ import type { TermFrequencyTable } from "@mailwoman/match"
10
+
11
+ /**
12
+ * The subset of `ResolveConfig` this progression varies.
13
+ */
14
+ export interface LeverConfig {
15
+ addressFrequency?: TermFrequencyTable | false
16
+ collapseSpatial?: boolean
17
+ discriminators?: string[]
18
+ requireCorroboration?: boolean
19
+ usePhone?: boolean
20
+ linkage?: "single" | "average"
21
+ exactDiscriminators?: string[]
22
+ }
23
+
24
+ /**
25
+ * One row of the progression.
26
+ */
27
+ export interface Lever {
28
+ label: string
29
+ config: LeverConfig
30
+ }
31
+
32
+ /**
33
+ * Build the progression against a corpus-wide address-frequency table.
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`
37
+ * row, making the A1 delta read as 0. Every row is fed the corpus-wide table — the realistic deployment, where the CLI
38
+ * builds it from the full source files — so the zero-config default, whose input-scoped table is intentionally sparse
39
+ * on a sub-sample, has to be measured separately.
40
+ */
41
+ export function buildLevers(addressFrequency: TermFrequencyTable): Lever[] {
42
+ return [
43
+ {
44
+ label: "baseline (legacy: address-key + distance, levers OFF)",
45
+ config: { collapseSpatial: false, addressFrequency: false },
46
+ },
47
+ { label: "+ inverse-address-frequency (#617, corpus-wide)", config: { collapseSpatial: false, addressFrequency } },
48
+ { label: "+ collapsed spatial signal (A1, #625)", config: { collapseSpatial: true, addressFrequency } },
49
+ {
50
+ label: "+ authorized-official discriminator (#625)",
51
+ config: { collapseSpatial: true, addressFrequency, discriminators: ["authorizedOfficial"] },
52
+ },
53
+ // A2–A4 (#625): the built-but-unmeasured over-merge levers. Each builds on the A1 + discriminator
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
56
+ // killing name-drift links; A4 (average-linkage) splits a component joined only by a weak bridge.
57
+ {
58
+ label: "+ require name/org corroboration (A2, #625)",
59
+ config: {
60
+ collapseSpatial: true,
61
+ addressFrequency,
62
+ discriminators: ["authorizedOfficial"],
63
+ requireCorroboration: true,
64
+ },
65
+ },
66
+ {
67
+ label: "+ phone comparison (A3, #625)",
68
+ config: {
69
+ collapseSpatial: true,
70
+ addressFrequency,
71
+ discriminators: ["authorizedOfficial"],
72
+ requireCorroboration: true,
73
+ usePhone: true,
74
+ },
75
+ },
76
+ {
77
+ label: "+ average-linkage clustering (A4, #625, full A1–A4 stack)",
78
+ config: {
79
+ collapseSpatial: true,
80
+ addressFrequency,
81
+ discriminators: ["authorizedOfficial"],
82
+ requireCorroboration: true,
83
+ usePhone: true,
84
+ linkage: "average",
85
+ },
86
+ },
87
+ // A5 (#625): the taxonomy code-set discriminator — set-overlap agreement over the NPI's 15 taxonomy
88
+ // slots. The named "still-more-distinctive identifier" from the 2026-06-16 report: co-located
89
+ // DISTINCT providers usually have disjoint sets (the over-merge separator) while an entity's own
90
+ // records always share theirs (never splits). Stacked on the BEST prior classical config (A1 +
91
+ // authorized-official; A3 phone + A4 avg-linkage were measured neutral-to-negative and are left off).
92
+ {
93
+ label: "+ taxonomy code-set discriminator (A5, #625)",
94
+ config: {
95
+ collapseSpatial: true,
96
+ addressFrequency,
97
+ discriminators: ["authorizedOfficial"],
98
+ exactDiscriminators: ["taxonomy"],
99
+ },
100
+ },
101
+ ]
102
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file Org-name similarity primitives for the NPPES benchmark's org-name entity truth.
6
+ */
7
+
8
+ /**
9
+ * Corporate-form words and articles stripped before two organization names are compared. The gold-set rule is "same
10
+ * address + same org name ⇒ same entity", so the domain words carry the distinguishing signal while a legal-form suffix
11
+ * would inflate agreement between unrelated co-located companies.
12
+ */
13
+ const ORG_STOP = new Set([
14
+ "llc",
15
+ "inc",
16
+ "incorporated",
17
+ "corp",
18
+ "corporation",
19
+ "co",
20
+ "ltd",
21
+ "pllc",
22
+ "pc",
23
+ "pa",
24
+ "lp",
25
+ "llp",
26
+ "the",
27
+ "of",
28
+ "and",
29
+ ])
30
+
31
+ /**
32
+ * The comparable token set of an organization name.
33
+ */
34
+ export const orgTokens = (s: string): Set<string> =>
35
+ new Set(
36
+ s
37
+ .toLowerCase()
38
+ .replaceAll(/[^a-z0-9 ]/g, " ")
39
+ .split(/\s+/)
40
+ .filter((t) => t && !ORG_STOP.has(t))
41
+ )
42
+
43
+ /**
44
+ * Jaccard floor at or above which two {@linkcode orgTokens} sets count as the same organization — the gold-set
45
+ * threshold.
46
+ */
47
+ export const ORG_TAU = 0.7
48
+
49
+ /**
50
+ * An NPI's primary registry identity: the org-name token set plus the address key of its practice location. Every grain
51
+ * of the org-name truth blocks on a location and gates on the tokens.
52
+ */
53
+ export interface NPIPrimary {
54
+ tokens: Set<string>
55
+ addrKey: string
56
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file The gold-set adjudication packet — the org-name-grain over-merged clusters, with every matcher-visible field,
6
+ * formatted for human review.
7
+ */
8
+
9
+ import { writeFileSync } from "node:fs"
10
+
11
+ import { isPresent } from "@mailwoman/core/objects"
12
+
13
+ import type { ResolvedEntity, SourceRecord } from "#index"
14
+
15
+ import type { MessyRow } from "./sample.ts"
16
+ import type { TruthLabel } from "./truth-grains.ts"
17
+
18
+ /**
19
+ * Everything the packet reads.
20
+ */
21
+ export interface OvermergePacketInput {
22
+ /**
23
+ * The clusters to inspect — the SHIPPED config's, since the packet exists to adjudicate what production produces.
24
+ */
25
+ entities: readonly ResolvedEntity[]
26
+ /**
27
+ * The source rows, for the fields that ride as attributes rather than on the record face.
28
+ */
29
+ rows: readonly MessyRow[]
30
+ recordCount: number
31
+ maxNpis: number
32
+ /**
33
+ * The state the sample was drawn from, so the packet's own header names the run an adjudicator is holding.
34
+ */
35
+ state: string
36
+ orgNameLabel: TruthLabel
37
+ }
38
+
39
+ /**
40
+ * Write the packet and return the number of over-merged clusters it holds.
41
+ *
42
+ * A cluster qualifies when its members carry more than one org-name label — the matcher fused records the org-name
43
+ * truth says belong to different entities. Per-pair human adjudication is the only instrument that separates model
44
+ * error from yardstick error once the residual is near the measured irreducible ceiling.
45
+ */
46
+ export function writeOvermergePacket(path: string, input: OvermergePacketInput): number {
47
+ const { entities, rows, recordCount, maxNpis, state, orgNameLabel } = input
48
+ const rowByID = new Map(rows.map((r) => [r.npi, r]))
49
+
50
+ const out: string[] = [
51
+ "# #625 gold-set adjudication packet — org-name-grain over-merged clusters (GBT, shipped config)",
52
+ "",
53
+ `${state} --max-npis ${maxNpis} · ${recordCount} records · generated by \`registry scorer-eval nppes-benchmark --dump-overmerges\``,
54
+ "",
55
+ "For each cluster: the matcher fused records that the org-name truth says belong to DIFFERENT entities.",
56
+ "Adjudicate each: **[same]** one real-world entity (yardstick error — the truth under-collapsed) or",
57
+ "**[distinct]** genuinely different co-located providers (model over-merge). Mark inline and return.",
58
+ "",
59
+ ]
60
+
61
+ let n = 0
62
+
63
+ entities.forEach((e) => {
64
+ const byLabel = new Map<string, SourceRecord[]>()
65
+
66
+ for (const rec of e.records) {
67
+ const lbl = orgNameLabel(rec)
68
+ const list = byLabel.get(lbl) ?? []
69
+ list.push(rec)
70
+ byLabel.set(lbl, list)
71
+ }
72
+
73
+ if (byLabel.size <= 1) return
74
+
75
+ n++
76
+ out.push(`## Cluster ${n} — ${e.records.length} records, ${byLabel.size} org-name entities → verdict: [ ]`)
77
+
78
+ for (const [lbl, members] of byLabel) {
79
+ out.push(`- **entity ${lbl}**`)
80
+
81
+ for (const rec of members) {
82
+ const src = rowByID.get(rec.id)
83
+
84
+ out.push(
85
+ ` - npi=${rec.id} · name="${[rec.name?.given, rec.name?.family].filter(isPresent).join(" ")}" · org="${rec.organization?.canonical ?? ""}" · addr="${rec.address?.raw ?? ""}" · auth="${src?.auth ?? ""}" · taxonomy="${src?.taxonomy ?? ""}"`
86
+ )
87
+ }
88
+ }
89
+
90
+ out.push("")
91
+ })
92
+
93
+ writeFileSync(path, out.join("\n"))
94
+
95
+ return n
96
+ }