@mailwoman/registry 8.5.0 → 9.0.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 (98) hide show
  1. package/README.md +62 -36
  2. package/ingest.ts +7 -2
  3. package/learned-scorer.ts +2 -2
  4. package/models/dedup-gbt-en-us.ts +1 -1
  5. package/out/ingest.d.ts +3 -0
  6. package/out/ingest.d.ts.map +1 -1
  7. package/out/ingest.js +4 -2
  8. package/out/ingest.js.map +1 -1
  9. package/out/learned-scorer.d.ts +2 -2
  10. package/out/learned-scorer.js +2 -2
  11. package/out/models/dedup-gbt-en-us.d.ts +1 -1
  12. package/out/models/dedup-gbt-en-us.js +1 -1
  13. package/out/resolve.js +2 -2
  14. package/out/tools/coverage-reconciliation.d.ts.map +1 -1
  15. package/out/tools/coverage-reconciliation.js +1 -47
  16. package/out/tools/coverage-reconciliation.js.map +1 -1
  17. package/out/tools/cross-dataset-correlation.d.ts.map +1 -1
  18. package/out/tools/cross-dataset-correlation.js +1 -1
  19. package/out/tools/cross-dataset-correlation.js.map +1 -1
  20. package/out/tools/cross-source-threshold-sweep.d.ts.map +1 -1
  21. package/out/tools/cross-source-threshold-sweep.js +4 -50
  22. package/out/tools/cross-source-threshold-sweep.js.map +1 -1
  23. package/out/tools/dedup-ceiling.d.ts.map +1 -1
  24. package/out/tools/dedup-ceiling.js +2 -11
  25. package/out/tools/dedup-ceiling.js.map +1 -1
  26. package/out/tools/geocoder-vs-provided-coords.d.ts.map +1 -1
  27. package/out/tools/geocoder-vs-provided-coords.js +12 -1
  28. package/out/tools/geocoder-vs-provided-coords.js.map +1 -1
  29. package/out/tools/gold-set-sample.d.ts +1 -1
  30. package/out/tools/gold-set-sample.d.ts.map +1 -1
  31. package/out/tools/gold-set-sample.js +3 -12
  32. package/out/tools/gold-set-sample.js.map +1 -1
  33. package/out/tools/learned-scorer-clustering-eval.d.ts.map +1 -1
  34. package/out/tools/learned-scorer-clustering-eval.js +3 -44
  35. package/out/tools/learned-scorer-clustering-eval.js.map +1 -1
  36. package/out/tools/learned-scorer-crossstate-eval.d.ts.map +1 -1
  37. package/out/tools/learned-scorer-crossstate-eval.js +3 -34
  38. package/out/tools/learned-scorer-crossstate-eval.js.map +1 -1
  39. package/out/tools/learned-scorer-eval.d.ts.map +1 -1
  40. package/out/tools/learned-scorer-eval.js +3 -38
  41. package/out/tools/learned-scorer-eval.js.map +1 -1
  42. package/out/tools/matcher-scale.d.ts.map +1 -1
  43. package/out/tools/matcher-scale.js +2 -11
  44. package/out/tools/matcher-scale.js.map +1 -1
  45. package/out/tools/nppes-dedup-benchmark.d.ts.map +1 -1
  46. package/out/tools/nppes-dedup-benchmark.js +8 -46
  47. package/out/tools/nppes-dedup-benchmark.js.map +1 -1
  48. package/out/tools/shared.d.ts +92 -0
  49. package/out/tools/shared.d.ts.map +1 -0
  50. package/out/tools/shared.js +139 -0
  51. package/out/tools/shared.js.map +1 -0
  52. package/out/tools/train-cross-gbt.d.ts.map +1 -1
  53. package/out/tools/train-cross-gbt.js +4 -99
  54. package/out/tools/train-cross-gbt.js.map +1 -1
  55. package/out/tools/train-gbt.d.ts.map +1 -1
  56. package/out/tools/train-gbt.js +4 -49
  57. package/out/tools/train-gbt.js.map +1 -1
  58. package/out/tools/train-org-cross-gbt.d.ts.map +1 -1
  59. package/out/tools/train-org-cross-gbt.js +6 -92
  60. package/out/tools/train-org-cross-gbt.js.map +1 -1
  61. package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
  62. package/out/tools/txhhsc-to-oarow.js +20 -11
  63. package/out/tools/txhhsc-to-oarow.js.map +1 -1
  64. package/out/tools/viz/cross-dataset-map.d.ts +2 -2
  65. package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
  66. package/out/tools/viz/cross-dataset-map.js +4 -3
  67. package/out/tools/viz/cross-dataset-map.js.map +1 -1
  68. package/out/tools/viz/geocode-first-surface.d.ts +2 -2
  69. package/out/tools/viz/geocode-first-surface.js +2 -2
  70. package/out/tools/viz/source-provenance-map.d.ts +2 -2
  71. package/out/tools/viz/source-provenance-map.js +3 -3
  72. package/out/tools/viz/source-provenance-map.js.map +1 -1
  73. package/out/tools/viz/yardstick-figure.d.ts +6 -6
  74. package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
  75. package/out/tools/viz/yardstick-figure.js +6 -5
  76. package/out/tools/viz/yardstick-figure.js.map +1 -1
  77. package/package.json +9 -10
  78. package/resolve.ts +2 -2
  79. package/tools/coverage-reconciliation.ts +1 -57
  80. package/tools/cross-dataset-correlation.ts +1 -2
  81. package/tools/cross-source-threshold-sweep.ts +4 -60
  82. package/tools/dedup-ceiling.ts +3 -14
  83. package/tools/geocoder-vs-provided-coords.ts +12 -2
  84. package/tools/gold-set-sample.ts +5 -16
  85. package/tools/learned-scorer-clustering-eval.ts +11 -54
  86. package/tools/learned-scorer-crossstate-eval.ts +11 -41
  87. package/tools/learned-scorer-eval.ts +3 -47
  88. package/tools/matcher-scale.ts +2 -14
  89. package/tools/nppes-dedup-benchmark.ts +8 -53
  90. package/tools/shared.ts +160 -0
  91. package/tools/train-cross-gbt.ts +4 -114
  92. package/tools/train-gbt.ts +4 -59
  93. package/tools/train-org-cross-gbt.ts +6 -105
  94. package/tools/txhhsc-to-oarow.ts +23 -13
  95. package/tools/viz/cross-dataset-map.ts +7 -6
  96. package/tools/viz/geocode-first-surface.ts +4 -4
  97. package/tools/viz/source-provenance-map.ts +5 -5
  98. package/tools/viz/yardstick-figure.ts +9 -8
@@ -28,7 +28,7 @@
28
28
  import { mkdirSync, writeFileSync } from "node:fs"
29
29
  import { dirname } from "node:path"
30
30
 
31
- import { dataRootPath } from "@mailwoman/core/utils"
31
+ import { dataRootPath, makeLcg } from "@mailwoman/core/utils"
32
32
  import { block, gbtScore, trainGBT } from "@mailwoman/match"
33
33
  import {
34
34
  addressFrequencyKey,
@@ -36,12 +36,13 @@ import {
36
36
  createMatchFeaturizer,
37
37
  defaultBlockingKeys,
38
38
  ingestRows,
39
+ streamRows,
39
40
  type ColumnMapping,
40
41
  type SourceRecord,
41
42
  } from "@mailwoman/registry"
42
- import { TextSpliterator } from "spliterator"
43
43
 
44
44
  import type { EvalGeocoderFactory } from "./eval-geocoder.ts"
45
+ import { addr, norm, uniqueQuantiles } from "./shared.ts"
45
46
 
46
47
  /**
47
48
  * Share of entities assigned to fit; the rest are held out.
@@ -82,11 +83,6 @@ export interface TrainOrgCrossSourceGBTOptions {
82
83
  date?: string
83
84
  }
84
85
 
85
- const norm = (s: string | undefined) => (s ?? "").trim()
86
-
87
- const addr = (line: string, city: string, st: string, zip: string) =>
88
- [norm(line), norm(city), norm(st), norm(zip)].filter(Boolean).join(", ")
89
-
90
86
  interface MessyRow {
91
87
  /**
92
88
  * The CCN — the cross-system facility key; rides `record.id` as the held-out label.
@@ -98,101 +94,6 @@ interface MessyRow {
98
94
  source: string
99
95
  }
100
96
 
101
- /**
102
- * Deterministic LCG (no Math.random — reproducible split + commit).
103
- */
104
- function lcg(seed: number): () => number {
105
- let s = seed >>> 0 || 1
106
-
107
- return () => {
108
- s = (Math.imul(s, 1_664_525) + 1_013_904_223) >>> 0
109
-
110
- return s / 0x1_00_00_00_00
111
- }
112
- }
113
-
114
- /**
115
- * Up to `n` unique sorted-quantile values from a sorted score array — link-threshold candidates.
116
- */
117
- function uniqueQuantiles(sorted: number[], n: number): number[] {
118
- if (!sorted.length) return [0]
119
- const ts = new Set<number>()
120
-
121
- for (let k = 0; k <= n; k++) {
122
- ts.add(sorted[Math.floor((k / n) * (sorted.length - 1))]!)
123
- }
124
-
125
- return [...ts]
126
- }
127
-
128
- /**
129
- * Stream a comma CSV with quoted fields (the OP profile format) as header-keyed rows.
130
- */
131
- async function* streamCSV(path: string): AsyncGenerator<Record<string, string>> {
132
- // spliterator owns the line layer (crlf is load-bearing here: the CMS POS file IS CRLF, and the
133
- // last column ZIP_CD + the header keys would otherwise carry a stray \r); the manual quote/pending
134
- // re-join + tokenizer below stays deliberately — spliterator ≥ 3.2.0 CAN do quote handling
135
- // end-to-end, but this parse feeds model training, so its byte-for-byte behavior is pinned until a
136
- // re-validation run signs off a swap. Default skipEmpty drops truly-empty lines, so a trailing
137
- // newline can't inject a spurious empty row.
138
- let header: string[] | null = null
139
- let pending = ""
140
-
141
- for await (const rawLine of TextSpliterator.fromAsync(path, { crlf: true })) {
142
- // Re-join physical lines until quotes balance (quoted fields may contain newlines).
143
- pending = pending ? `${pending}\n${rawLine}` : rawLine
144
- const quotes = (pending.match(/"/g) ?? []).length
145
-
146
- if (quotes % 2 === 1) continue
147
- const line = pending
148
- pending = ""
149
- const cells: string[] = []
150
- let cur = ""
151
- let inQ = false
152
-
153
- for (let i = 0; i < line.length; i++) {
154
- const ch = line[i]!
155
-
156
- if (inQ) {
157
- if (ch === '"') {
158
- if (line[i + 1] === '"') {
159
- cur += '"'
160
-
161
- i++
162
- } else {
163
- inQ = false
164
- }
165
- } else {
166
- cur += ch
167
- }
168
- } else if (ch === '"') {
169
- inQ = true
170
- } else if (ch === ",") {
171
- cells.push(cur)
172
- cur = ""
173
- } else {
174
- cur += ch
175
- }
176
- }
177
-
178
- cells.push(cur)
179
-
180
- if (!header) {
181
- header = cells
182
-
183
- continue
184
- }
185
-
186
- const row: Record<string, string> = {}
187
-
188
- for (let i = 0; i < header.length; i++) {
189
- row[header[i]!] = cells[i] ?? ""
190
- }
191
-
192
- yield row
193
- }
194
- }
195
-
196
97
  /**
197
98
  * Train + emit the org-level cross-source link GBT — see the module doc.
198
99
  */
@@ -215,7 +116,7 @@ export async function trainOrgCrossSourceGBT(
215
116
  report?.("[A] streaming Care Compare…")
216
117
  const ccByID = new Map<string, MessyRow>()
217
118
 
218
- for await (const r of streamCSV(CARE_COMPARE)) {
119
+ for await (const r of streamRows(CARE_COMPARE)) {
219
120
  if (ccByID.size >= CAP) break
220
121
  const ccn = norm(r["Facility ID"])
221
122
  const name = norm(r["Facility Name"])
@@ -234,7 +135,7 @@ export async function trainOrgCrossSourceGBT(
234
135
  const addrCounts = new Map<string, number>()
235
136
  let addrTotal = 0
236
137
 
237
- for await (const r of streamCSV(POS)) {
138
+ for await (const r of streamRows(POS)) {
238
139
  const address = addr(r["ST_ADR"]!, r["CITY_NAME"]!, r["STATE_CD"]!, r["ZIP_CD"]!)
239
140
 
240
141
  if (address) {
@@ -314,7 +215,7 @@ export async function trainOrgCrossSourceGBT(
314
215
  // --- Phase E: held-out-NPI calibration — the #655 threshold rule. ---
315
216
  report?.("[E] held-out calibration…")
316
217
  const hyperparams = { rounds: 120, depth: 3, lr: 0.3, minLeaf: 20 }
317
- const rnd = lcg(655)
218
+ const rnd = makeLcg(655)
318
219
  const split = new Map<string, "fit" | "holdout">()
319
220
 
320
221
  for (const ccn of joined) {
@@ -17,6 +17,7 @@
17
17
  import { readFileSync, writeFileSync } from "node:fs"
18
18
 
19
19
  import { dataRootPath } from "@mailwoman/core/utils"
20
+ import { TSVSpliterator } from "spliterator"
20
21
 
21
22
  /**
22
23
  * Texas bounding box, used to reject rows whose coordinates landed in the wrong state.
@@ -64,22 +65,31 @@ export function convertTXHHSC(
64
65
  const src = options.src || String(dataRootPath("record-matcher", "sources", "txhhsc_nursing-facilities_20260611.tsv"))
65
66
  const out = options.out || "/tmp/txhhsc-oarow.jsonl"
66
67
 
67
- const lines = readFileSync(src, "utf8")
68
- .split("\n")
69
- .filter((l) => l.trim())
70
-
71
- const header = lines[0]!.split("\t")
72
- const col = (name: string) => header.indexOf(name)
73
- const cAddr = col("Physical Address")
74
- const cCity = col("Physical Address CITY")
75
- const cZip = col("Physical Address Zipcode")
76
- const cGeo = col("Geo Location")
77
-
78
68
  const records: string[] = []
79
69
  let skipped = 0
80
70
 
81
- for (const line of lines.slice(1)) {
82
- const f = line.split("\t")
71
+ // Column indices, captured from the first non-blank row. `header: false` keeps that row in the stream so the
72
+ // blank-row guard below applies to it too.
73
+ let cAddr = -1
74
+ let cCity = -1
75
+ let cZip = -1
76
+ let cGeo = -1
77
+ let sawHeader = false
78
+
79
+ for (const f of TSVSpliterator.from(readFileSync(src, "utf8"), { header: false })) {
80
+ if (f.every((value) => !value.trim())) continue
81
+
82
+ if (!sawHeader) {
83
+ sawHeader = true
84
+ const col = (name: string) => f.indexOf(name)
85
+ cAddr = col("Physical Address")
86
+ cCity = col("Physical Address CITY")
87
+ cZip = col("Physical Address Zipcode")
88
+ cGeo = col("Geo Location")
89
+
90
+ continue
91
+ }
92
+
83
93
  const addr = (f[cAddr] ?? "").trim()
84
94
  const city = (f[cCity] ?? "").trim()
85
95
  const zip = (f[cZip] ?? "").trim()
@@ -30,6 +30,7 @@
30
30
 
31
31
  import { readFileSync, writeFileSync } from "node:fs"
32
32
 
33
+ import { parseJSONStrict } from "@mailwoman/core/objects"
33
34
  import { dataRootPath } from "@mailwoman/core/utils"
34
35
  import { toMapHTML } from "@mailwoman/registry"
35
36
 
@@ -50,7 +51,7 @@ export interface CrossDatasetMapOptions {
50
51
  /**
51
52
  * Output HTML path. Default `/tmp/cross-dataset-map.html`.
52
53
  */
53
- outHtml?: string
54
+ outHTML?: string
54
55
  /**
55
56
  * Keep only entities whose sources span >1 agency (the two FCC datasets count as one).
56
57
  */
@@ -90,15 +91,15 @@ const sourcesOf = (f: { properties: Record<string, unknown> | null }) =>
90
91
  export function crossDatasetMap(
91
92
  options: CrossDatasetMapOptions = {},
92
93
  report?: (line: string) => void
93
- ): { outHtml: string; kept: number; total: number; triple: number } {
94
+ ): { outHTML: string; kept: number; total: number; triple: number } {
94
95
  const IN = options.in || dataRootPath("record-matcher", "2026-06-16-cross-dataset-links.geojson")
95
- const OUT = options.outHtml || "/tmp/cross-dataset-map.html"
96
+ const OUT = options.outHTML || "/tmp/cross-dataset-map.html"
96
97
  const CROSS_AGENCY_ONLY = options.crossAgencyOnly ?? false
97
98
 
98
- const parsed = JSON.parse(readFileSync(IN, "utf8")) as {
99
+ const parsed = parseJSONStrict<{
99
100
  type: "FeatureCollection"
100
101
  features: Array<{ properties: Record<string, unknown> | null }>
101
- }
102
+ }>(readFileSync(IN, "utf8"))
102
103
 
103
104
  const total = parsed.features.length
104
105
 
@@ -145,5 +146,5 @@ export function crossDatasetMap(
145
146
 
146
147
  report?.(` spanning all three agencies: ${triple}`)
147
148
 
148
- return { outHtml: OUT, kept, total, triple }
149
+ return { outHTML: OUT, kept, total, triple }
149
150
  }
@@ -51,7 +51,7 @@ export interface GeocodeFirstSurfaceOptions {
51
51
  /**
52
52
  * Output HTML path. Default `/tmp/geocode-first-surface.html`.
53
53
  */
54
- outHtml?: string
54
+ outHTML?: string
55
55
  }
56
56
 
57
57
  // ── Real Bayes-factor weights, transcribed from source (values kept in sync by comment, not import,
@@ -113,9 +113,9 @@ function distanceWeight(km: number): number {
113
113
  export function geocodeFirstSurface(
114
114
  options: GeocodeFirstSurfaceOptions = {},
115
115
  report?: (line: string) => void
116
- ): { outHtml: string } {
116
+ ): { outHTML: string } {
117
117
  const LAMBDA = options.lambda ?? 0.02
118
- const OUT_HTML = options.outHtml || "/tmp/geocode-first-surface.html"
118
+ const OUT_HTML = options.outHTML || "/tmp/geocode-first-surface.html"
119
119
 
120
120
  const PRIOR = priorWeight(LAMBDA)
121
121
 
@@ -315,5 +315,5 @@ document.getElementByID("cap").innerHTML =
315
315
  )
316
316
  }
317
317
 
318
- return { outHtml: OUT_HTML }
318
+ return { outHTML: OUT_HTML }
319
319
  }
@@ -48,7 +48,7 @@ export interface SourceProvenanceMapOptions {
48
48
  /**
49
49
  * Output HTML path. Default `/tmp/source-provenance.html`.
50
50
  */
51
- outHtml?: string
51
+ outHTML?: string
52
52
  /**
53
53
  * Keep ~1/N of NAD points. Default 700.
54
54
  */
@@ -90,10 +90,10 @@ type Row = { lat: number; lon: number; source: string; number: string | null; st
90
90
  export function sourceProvenanceMap(
91
91
  options: SourceProvenanceMapOptions = {},
92
92
  report?: (line: string) => void
93
- ): { outHtml: string; points: number } {
93
+ ): { outHTML: string; points: number } {
94
94
  const STATE = (options.state || "ny").toLowerCase()
95
- const DB = options.db || `${dataRootPath("address-points")}/address-points-us-${STATE}.db`
96
- const OUT = options.outHtml || "/tmp/source-provenance.html"
95
+ const DB = options.db || String(dataRootPath("address-points", `address-points-us-${STATE}.db`))
96
+ const OUT = options.outHTML || "/tmp/source-provenance.html"
97
97
  const NAD_MOD = options.nadMod ?? 700 // keep ~1/700 of NAD points
98
98
  const OA_MOD = options.oaMod ?? 120 // keep ~1/120 of OpenAddresses points
99
99
  const CAP = options.cap ?? 7000 // per-source marker cap
@@ -154,5 +154,5 @@ export function sourceProvenanceMap(
154
154
  report?.(` ${n.toString().padStart(5)} ${bucket}`)
155
155
  }
156
156
 
157
- return { outHtml: OUT, points: features.length }
157
+ return { outHTML: OUT, points: features.length }
158
158
  }
@@ -15,13 +15,13 @@
15
15
  *
16
16
  * A slope chart over four rulers (NPI → site → org-name → org-name-coord) for the shipped GBT
17
17
  * scorer and the FS baseline. Numbers are the committed measurement in
18
- * `docs/articles/evals/matcher-dedup/2026-06-16-dedup-dual-level-benchmark.md` (1000 TX NPIs → 2757 records).
18
+ * `docs/records/evals/matcher-dedup/2026-06-16-dedup-dual-level-benchmark.md` (1000 TX NPIs → 2757 records).
19
19
  *
20
20
  * Emits a self-contained SVG (the docs' committed-chart-asset convention — see
21
- * `docs/articles/evals/charts/*.svg`), no browser required.
21
+ * `docs/records/evals/charts/*.svg`), no browser required.
22
22
  *
23
23
  * Run: `mailwoman registry viz yardstick-figure
24
- * [--out-svg docs/articles/evals/charts/dedup-yardstick.svg]`
24
+ * [--out-svg docs/records/evals/charts/dedup-yardstick.svg]`
25
25
  */
26
26
 
27
27
  import { writeFileSync } from "node:fs"
@@ -31,9 +31,9 @@ import { writeFileSync } from "node:fs"
31
31
  */
32
32
  export interface YardstickFigureOptions {
33
33
  /**
34
- * Output SVG path. Default `docs/articles/evals/charts/dedup-yardstick.svg` (relative to cwd).
34
+ * Output SVG path. Default `docs/records/evals/charts/dedup-yardstick.svg` (relative to cwd).
35
35
  */
36
- outSvg?: string
36
+ outSVG?: string
37
37
  }
38
38
 
39
39
  // ── The committed measurement (2026-06-16-dedup-dual-level-benchmark.md). ────────────────────────
@@ -101,8 +101,8 @@ const esc = (s: string) => s.replaceAll("&", "&amp;").replaceAll("<", "&lt;").re
101
101
  export function yardstickFigure(
102
102
  options: YardstickFigureOptions = {},
103
103
  report?: (line: string) => void
104
- ): { outSvg: string } {
105
- const OUT = options.outSvg || "docs/articles/evals/charts/dedup-yardstick.svg"
104
+ ): { outSVG: string } {
105
+ const OUT = options.outSVG || "docs/records/evals/charts/dedup-yardstick.svg"
106
106
 
107
107
  const parts: string[] = []
108
108
  const push = (s: string) => parts.push(s)
@@ -151,6 +151,7 @@ export function yardstickFigure(
151
151
  `<text x="${x.toFixed(1)}" y="${plotB + 36}" text-anchor="middle" font-size="10" fill="#6b7280">${g.classes} classes</text>`
152
152
  )
153
153
 
154
+ // oxlint-disable-next-line mailwoman/prefer-spliterator -- `g.note` is a literal label from the MODELS table, not a file.
154
155
  g.note.split("\n").forEach((line, k) => {
155
156
  push(
156
157
  `<text x="${x.toFixed(1)}" y="${plotB + 50 + k * 12}" text-anchor="middle" font-size="9" fill="#9ca3af">${esc(line)}</text>`
@@ -228,5 +229,5 @@ export function yardstickFigure(
228
229
 
229
230
  report?.(` over-merge: ${OVERMERGE.GBT!.join(" → ")}`)
230
231
 
231
- return { outSvg: OUT }
232
+ return { outSVG: OUT }
232
233
  }