@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
@@ -29,9 +29,9 @@
29
29
  * [--data-root <dir>] [--out-md <md>] [--out-geojson <geojson>]`
30
30
  */
31
31
 
32
- import { writeFileSync } from "node:fs"
32
+ import { dataRootPath } from "@mailwoman/core/data-root"
33
+ import { writeLocalFile, writeLocalJSONFile } from "@mailwoman/core/fs/writers"
33
34
 
34
- import { dataRootPath } from "@mailwoman/core/utils"
35
35
  import {
36
36
  ingestRows,
37
37
  reconcileCoverage,
@@ -39,14 +39,12 @@ import {
39
39
  reconciliationReport,
40
40
  resolveEntities,
41
41
  streamRows,
42
- type ColumnMapping,
43
42
  type GeocodeAddress,
44
43
  type ReconcileConfig,
45
44
  type SourceRecord,
46
- } from "@mailwoman/registry"
47
-
48
- import type { EvalGeocoderFactory } from "./eval-geocoder.ts"
49
- import { buildSpecs, norm, type SourceSpec } from "./shared.ts"
45
+ } from "#index"
46
+ import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
47
+ import { buildSpecs, stateOption } from "#tools/shared"
50
48
 
51
49
  /**
52
50
  * Options for {@linkcode coverageReconciliation}.
@@ -93,7 +91,7 @@ export async function coverageReconciliation(
93
91
  ): Promise<{ markdown: string }> {
94
92
  const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
95
93
  const CAP = options.cap ?? 2000
96
- const STATE = (options.state || "TX").toUpperCase()
94
+ const STATE = stateOption(options)
97
95
  const OUT_MD = options.outMd || ""
98
96
  const OUT_GEOJSON = options.outGeojson || ""
99
97
  const SPECS = buildSpecs(`${SOURCES}`, STATE)
@@ -122,9 +120,9 @@ export async function coverageReconciliation(
122
120
  let geo = 0
123
121
  let total = 0
124
122
 
125
- // Count placements at the seam (parity with the retired in-script counter).
126
- const seam: GeocodeAddress = async (raw) => {
127
- const g = await geocoder.seam(raw)
123
+ // Count placements at the boundary (parity with the retired in-script counter).
124
+ const geocodeForIngest: GeocodeAddress = async (raw) => {
125
+ const g = await geocoder.geocodeAddress(raw)
128
126
 
129
127
  total++
130
128
 
@@ -139,7 +137,7 @@ export async function coverageReconciliation(
139
137
  const records: SourceRecord[] = []
140
138
 
141
139
  for (const spec of SPECS) {
142
- const recs = await ingestRows(rawBySource.get(spec.source)!, spec.mapping, { geocodeAddress: seam })
140
+ const recs = await ingestRows(rawBySource.get(spec.source)!, spec.mapping, { geocodeAddress: geocodeForIngest })
143
141
 
144
142
  for (const r of recs) {
145
143
  r.id = `${spec.source}:${r.id}`
@@ -148,7 +146,7 @@ export async function coverageReconciliation(
148
146
  records.push(...recs)
149
147
  }
150
148
 
151
- geocoder.close()
149
+ geocoder[Symbol.dispose]()
152
150
  report?.(` ${records.length} records; geocoded ${geo}/${total} (${((100 * geo) / total).toFixed(1)}%)`)
153
151
 
154
152
  report?.("[D] resolving + reconciling…")
@@ -184,12 +182,12 @@ export async function coverageReconciliation(
184
182
  console.log(md)
185
183
 
186
184
  if (OUT_MD) {
187
- writeFileSync(OUT_MD, md)
185
+ await writeLocalFile(md, OUT_MD)
188
186
  report?.(`[written] ${OUT_MD}`)
189
187
  }
190
188
 
191
189
  if (OUT_GEOJSON) {
192
- writeFileSync(OUT_GEOJSON, JSON.stringify(geojson))
190
+ await writeLocalJSONFile(geojson, OUT_GEOJSON)
193
191
  report?.(`[written] ${OUT_GEOJSON} (${geojson.features.length} features)`)
194
192
  }
195
193
 
@@ -13,29 +13,28 @@
13
13
  * to canonical entities, and report the entities whose members span ≥2 sources — those are the
14
14
  * cross-dataset links. We surface the correlation; interpretation is the consumer's.
15
15
  *
16
- * Tractable cut: TX-scoped, capped per source. Streams the 4.8 GB NPPES registry via `streamRows`.
16
+ * Tractable slice: TX-scoped, capped per source. Streams the 4.8 GB NPPES registry via `streamRows`.
17
17
  *
18
18
  * Run: `mailwoman registry scorer-eval cross-dataset [--cap 300] [--wof <admin.db>]
19
19
  * [--data-root <dir>] [--out-md docs/articles/evals/matcher-dedup/<date>-...md]`
20
20
  */
21
21
 
22
- import { writeFileSync } from "node:fs"
22
+ import { dataRootPath } from "@mailwoman/core/data-root"
23
+ import { writeLocalFile, writeLocalJSONFile } from "@mailwoman/core/fs/writers"
24
+ import { isPresent } from "@mailwoman/core/objects"
23
25
 
24
- import { dataRootPath } from "@mailwoman/core/utils"
25
26
  import {
26
27
  addressFrequencyKey,
27
28
  ingestRows,
29
+ repName,
28
30
  resolveEntities,
29
31
  streamRows,
30
32
  toGeoJSON,
31
- type ColumnMapping,
32
33
  type GeocodeAddress,
33
- type ResolvedEntity,
34
34
  type SourceRecord,
35
- } from "@mailwoman/registry"
36
-
37
- import type { EvalGeocoderFactory } from "./eval-geocoder.ts"
38
- import { norm } from "./shared.ts"
35
+ } from "#index"
36
+ import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
37
+ import { buildSpecs, norm, pct, stateOption, type SourceSpec } from "#tools/shared"
39
38
 
40
39
  /**
41
40
  * Distinct sources an entity needs to count toward the triple-corroborated tally.
@@ -63,9 +62,9 @@ export interface CrossDatasetCorrelationOptions {
63
62
  */
64
63
  state?: string
65
64
  /**
66
- * The inverse-address-frequency lever is a CORPUS statistic — it can't be synthesized from the geocoded sample. By
65
+ * The inverse-address-frequency change is a CORPUS statistic — it can't be synthesized from the geocoded sample. By
67
66
  * default we scan the FULL files (cheap, parse-free) for an in-state corpus-wide frequency table and feed it to the
68
- * matcher, so the proven #617 lever actually bites on a sub-sampled run. The scan adds a full pass over the 4.8 GB
67
+ * matcher, so the proven #617 change actually bites on a sub-sampled run. The scan adds a full pass over the 4.8 GB
69
68
  * NPPES file (~5 min); `--no-corpus-frequency` skips it and falls back to resolveEntities' zero-config input-scoped
70
69
  * default (#86). Default true.
71
70
  */
@@ -81,8 +80,9 @@ export interface CrossDatasetCorrelationOptions {
81
80
  }
82
81
 
83
82
  /**
84
- * Compose a row's address the SAME way {@link ingestRows} does (`pick`: join the mapped columns with a space, drop
85
- * empties), so a frequency key built here matches the geocoded record's `address.raw`.
83
+ * Compose a row's address for the corpus-wide frequency table. {@link ingestRows} joins the mapped address columns with
84
+ * `", "` (the #694 flip) while this join uses a space — the two agree once `addressFrequencyKey` folds punctuation to
85
+ * spaces, so a frequency key built here matches the geocoded record's `address.raw`.
86
86
  */
87
87
  function composeAddress(row: Record<string, string>, columns: string | string[] | undefined): string {
88
88
  if (!columns) return ""
@@ -90,118 +90,52 @@ function composeAddress(row: Record<string, string>, columns: string | string[]
90
90
 
91
91
  return list
92
92
  .map((c) => norm(row[c]))
93
- .filter(Boolean)
93
+ .filter(isPresent)
94
94
  .join(" ")
95
95
  .trim()
96
96
  }
97
97
 
98
98
  /**
99
- * One source to ingest: where it lives, the column mapping, a TX filter, and an optional row "explode" for files that
100
- * carry two addressable entities per row (the FCC commitments Filing + Participating HCP).
99
+ * FCC RHC funding commitments — TWO addressable entities per row (a Filing HCP and a Participating HCP), each exploded
100
+ * into its own record (the #618 B1 two-entity-per-row case). Composed after the shared {@link buildSpecs} trio, which
101
+ * this probe correlates against.
101
102
  */
102
- interface SourceSpec {
103
- source: string
104
- path: string
105
- mapping: ColumnMapping
106
- /**
107
- * Keep only rows in-state (reads the row's state column).
108
- */
109
- inState: (row: Record<string, string>) => boolean
110
- /**
111
- * Optional: a row carries ≥1 addressable entity — yield each as its own row. Default identity.
112
- */
113
- explode?: (row: Record<string, string>) => Record<string, string>[]
114
- }
115
-
116
- const buildSpecs = (S: string, STATE: string): SourceSpec[] => [
117
- {
118
- // TX HHSC nursing facilities — facility name + physical address + a real coordinate.
119
- source: "txhhsc-nursing",
120
- path: `${S}/txhhsc_nursing-facilities_20260611.tsv`,
121
- mapping: {
122
- id: "Facility ID",
123
- organization: "Facility Name",
124
- address: ["Physical Address", "Physical Address CITY", "Physical Address State", "Physical Address Zipcode"],
125
- phone: "Facility Phone Number",
126
- source: "txhhsc-nursing",
127
- },
128
- inState: (r) => norm(r["Physical Address State"]).toUpperCase() === STATE,
129
- },
130
- {
131
- // FCC Rural Health Care posted services — the funding/enrollment side; HCP name + site address.
132
- source: "fcc-rhc",
133
- path: `${S}/fcc-rhc_posted-services_form461-465_20260615.tsv`,
134
- mapping: {
135
- id: "HCP Number",
136
- organization: "HCP Name",
137
- address: ["Site Address Line 1", "Site City", "Site State", "Site ZIP Code"],
138
- phone: "Contact Phone",
139
- email: "Contact E-mail",
140
- source: "fcc-rhc",
141
- },
142
- inState: (r) => norm(r["Site State"]).toUpperCase() === STATE,
143
- },
144
- {
145
- // NPPES — organization NPIs (the eligibility side); legal business name + practice address.
146
- source: "nppes",
147
- path: `${S}/nppes_npi-registry_20260607.tsv`,
148
- mapping: {
149
- id: "NPI",
150
- organization: "Provider Organization Name (Legal Business Name)",
151
- address: [
152
- "Provider First Line Business Practice Location Address",
153
- "Provider Business Practice Location Address City Name",
154
- "Provider Business Practice Location Address State Name",
155
- "Provider Business Practice Location Address Postal Code",
156
- ],
157
- phone: "Provider Business Practice Location Address Telephone Number",
158
- source: "nppes",
159
- },
160
- // Org-type NPIs in TX with a business name — the entities most likely to co-occur with facilities.
161
- inState: (r) =>
162
- norm(r["Provider Business Practice Location Address State Name"]).toUpperCase() === STATE &&
163
- norm(r["Entity Type Code"]) === "2" &&
164
- !!norm(r["Provider Organization Name (Legal Business Name)"]),
165
- },
166
- {
167
- // FCC RHC funding commitments — TWO addressable entities per row (a Filing HCP and a Participating
168
- // HCP). Explode each in-state HCP into its own record (the #618 B1 two-entity-per-row case).
103
+ const commitmentsSpec = (S: string, STATE: string): SourceSpec => ({
104
+ source: "fcc-rhc-commitments",
105
+ path: `${S}/fcc-rhc_commitments-disbursements_form462-466-466a_20260615.tsv`,
106
+ mapping: {
107
+ id: "hcpID",
108
+ organization: "hcpName",
109
+ address: ["hcpStreet", "hcpCity", "hcpState", "hcpZip"],
169
110
  source: "fcc-rhc-commitments",
170
- path: `${S}/fcc-rhc_commitments-disbursements_form462-466-466a_20260615.tsv`,
171
- mapping: {
172
- id: "hcpID",
173
- organization: "hcpName",
174
- address: ["hcpStreet", "hcpCity", "hcpState", "hcpZip"],
175
- source: "fcc-rhc-commitments",
176
- },
177
- inState: (r) =>
178
- norm(r["Filing HCP State"]).toUpperCase() === STATE || norm(r["Participating HCP State"]).toUpperCase() === STATE,
179
- explode: (r) => {
180
- const out: Record<string, string>[] = []
181
-
182
- const add = (prefix: string, role: string): void => {
183
- const id = norm(r[`${prefix} HCP`])
184
- const state = norm(r[`${prefix} HCP State`]).toUpperCase()
185
-
186
- if (id && state === STATE) {
187
- out.push({
188
- hcpID: `${role}-${id}`,
189
- hcpName: norm(r[`${prefix} HCP Name`]),
190
- hcpStreet: norm(r[`${prefix} HCP Street`]),
191
- hcpCity: norm(r[`${prefix} HCP City`]),
192
- hcpState: state,
193
- hcpZip: norm(r[`${prefix} HCP Zip Code`]),
194
- })
195
- }
111
+ },
112
+ inState: (r) =>
113
+ norm(r["Filing HCP State"]).toUpperCase() === STATE || norm(r["Participating HCP State"]).toUpperCase() === STATE,
114
+ explode: (r) => {
115
+ const out: Record<string, string>[] = []
116
+
117
+ const add = (prefix: string, role: string): void => {
118
+ const id = norm(r[`${prefix} HCP`])
119
+ const state = norm(r[`${prefix} HCP State`]).toUpperCase()
120
+
121
+ if (id && state === STATE) {
122
+ out.push({
123
+ hcpID: `${role}-${id}`,
124
+ hcpName: norm(r[`${prefix} HCP Name`]),
125
+ hcpStreet: norm(r[`${prefix} HCP Street`]),
126
+ hcpCity: norm(r[`${prefix} HCP City`]),
127
+ hcpState: state,
128
+ hcpZip: norm(r[`${prefix} HCP Zip Code`]),
129
+ })
196
130
  }
131
+ }
197
132
 
198
- add("Filing", "filing")
199
- add("Participating", "participating")
133
+ add("Filing", "filing")
134
+ add("Participating", "participating")
200
135
 
201
- return out
202
- },
136
+ return out
203
137
  },
204
- ]
138
+ })
205
139
 
206
140
  /**
207
141
  * Cross-dataset correlation (#618) — see the module doc. Emits the markdown report to stdout.
@@ -212,16 +146,16 @@ export async function crossDatasetCorrelation(
212
146
  ): Promise<{ markdown: string }> {
213
147
  const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
214
148
  const CAP = options.cap ?? 300 // rows kept per source for geocoding (state-scoped)
215
- const STATE = (options.state || "TX").toUpperCase()
149
+ const STATE = stateOption(options)
216
150
  const OUT_MD = options.outMd || ""
217
151
  const OUT_GEOJSON = options.outGeojson || "" // the reconciliation artifact (FeatureCollection, QGIS-ready)
218
152
  const CORPUS_FREQ = options.corpusFrequency ?? true
219
- const SPECS = buildSpecs(`${SOURCES}`, STATE)
153
+ const SPECS = [...buildSpecs(`${SOURCES}`, STATE), commitmentsSpec(`${SOURCES}`, STATE)]
220
154
 
221
155
  // --- Phase A: stream each source, TX-filter, explode → keep the first CAP rows for geocoding AND
222
156
  // (when --corpus-frequency, the default) count EVERY in-state address into a corpus-wide table. The
223
157
  // sample is the matched set; the frequency table reflects the full TX population, so the proven
224
- // inverse-frequency lever down-weights a genuinely-crowded shared campus even when it appears once in
158
+ // inverse-frequency change down-weights a genuinely-crowded shared campus even when it appears once in
225
159
  // the geocoded sample. ---
226
160
  const rawBySource = new Map<string, Record<string, string>[]>()
227
161
  const addrCounts = new Map<string, number>()
@@ -260,7 +194,7 @@ export async function crossDatasetCorrelation(
260
194
  report?.(` ${spec.source}: ${kept.length} sampled`)
261
195
  }
262
196
 
263
- // The in-state corpus-wide address-frequency table (the #617 lever, fed to the matcher below).
197
+ // The in-state corpus-wide address-frequency table (the #617 change, fed to the matcher below).
264
198
  const addressFrequency = CORPUS_FREQ
265
199
  ? {
266
200
  total: addrTotal,
@@ -280,9 +214,9 @@ export async function crossDatasetCorrelation(
280
214
  let geo = 0
281
215
  let total = 0
282
216
 
283
- // Count placements at the seam (parity with the retired in-script counter).
284
- const seam: GeocodeAddress = async (raw) => {
285
- const g = await geocoder.seam(raw)
217
+ // Count placements at the boundary (parity with the retired in-script counter).
218
+ const geocodeForIngest: GeocodeAddress = async (raw) => {
219
+ const g = await geocoder.geocodeAddress(raw)
286
220
 
287
221
  total++
288
222
 
@@ -299,11 +233,11 @@ export async function crossDatasetCorrelation(
299
233
 
300
234
  for (const spec of SPECS) {
301
235
  const rows = rawBySource.get(spec.source)!
302
- // Per-source geocode-rate snapshot (#694 diagnostic): the seam counters are global, so delta
236
+ // Per-source geocode-rate snapshot (#694 diagnostic): the boundary counters are global, so delta
303
237
  // them across each source to see WHERE nulls concentrate in the aggregate run.
304
238
  const g0 = geo
305
239
  const t0 = total
306
- const recs = await ingestRows(rows, spec.mapping, { geocodeAddress: seam })
240
+ const recs = await ingestRows(rows, spec.mapping, { geocodeAddress: geocodeForIngest })
307
241
  const dg = geo - g0
308
242
  const dt = total - t0
309
243
  report?.(` ${spec.source}: geocoded ${dg}/${dt} (${dt ? ((100 * dg) / dt).toFixed(1) : "0"}%)`)
@@ -316,10 +250,10 @@ export async function crossDatasetCorrelation(
316
250
  records.push(...recs)
317
251
  }
318
252
 
319
- geocoder.close()
253
+ geocoder[Symbol.dispose]()
320
254
  report?.(` ${records.length} records; geocoded ${geo}/${total} (${((100 * geo) / total).toFixed(1)}%)`)
321
255
 
322
- // --- Phase D: resolve to canonical entities. The proven levers are default-on (#86): collapsed
256
+ // --- Phase D: resolve to canonical entities. The proven changes are default-on (#86): collapsed
323
257
  // spatial (A1) + inverse-address-frequency. We feed the corpus-wide table when we built one; otherwise
324
258
  // resolveEntities auto-computes the input-scoped default. ---
325
259
  report?.("[D] resolving across sources…")
@@ -358,22 +292,13 @@ export async function crossDatasetCorrelation(
358
292
  }
359
293
  }
360
294
 
361
- const repName = (e: ResolvedEntity) =>
362
- e.representative.organization?.canonical ??
363
- [e.representative.name?.given, e.representative.name?.family].filter(Boolean).join(" ") ??
364
- e.representative.id
365
-
366
295
  // --- Report. ---
367
- // NOTE(phase4): local pct keeps the fraction-in/no-%-suffix shape — not core formatPercent's
368
- // numerator/denominator contract (call sites append their own "%").
369
- const pct = (x: number) => (100 * x).toFixed(1)
370
-
371
296
  const lines: string[] = [
372
297
  `# Cross-dataset correlation (#618 / #87 real-data run)`,
373
298
  "",
374
299
  `_Generated by \`mailwoman registry scorer-eval cross-dataset\`. ${STATE}-scoped, ≤${CAP} rows per ` +
375
300
  `source geocoded, resolved BLIND across sources (geo-first block → Fellegi-Sunter + EM → cluster) with the ` +
376
- `proven levers default-on (#86). The sources share no key; an entity spanning ≥2 sources is a cross-dataset ` +
301
+ `proven changes default-on (#86). The sources share no key; an entity spanning ≥2 sources is a cross-dataset ` +
377
302
  `link we surface for review — interpretation is the consumer's._`,
378
303
  "",
379
304
  `## Sources`,
@@ -405,7 +330,7 @@ export async function crossDatasetCorrelation(
405
330
 
406
331
  lines.push(
407
332
  addressFrequency
408
- ? `Matched with the proven levers default-on (#86): collapsed spatial (A1) + inverse-address-frequency, fed ` +
333
+ ? `Matched with the proven changes default-on (#86): collapsed spatial (A1) + inverse-address-frequency, fed ` +
409
334
  `a corpus-wide table built from the full source files (**${addressFrequency.distinct.toLocaleString()}** distinct ` +
410
335
  `addresses over **${addressFrequency.total.toLocaleString()}** ${STATE} rows — a crowded shared campus is ` +
411
336
  `down-weighted as weak identity evidence).`
@@ -476,16 +401,16 @@ export async function crossDatasetCorrelation(
476
401
  console.log(md)
477
402
 
478
403
  if (OUT_MD) {
479
- writeFileSync(OUT_MD, md)
404
+ await writeLocalFile(md, OUT_MD)
480
405
  report?.(`\n[written] ${OUT_MD}`)
481
406
  }
482
407
 
483
408
  // --- The reconciliation artifact: a GeoJSON FeatureCollection of every resolved entity. Each feature
484
- // carries `sources` + `sourceIds` (so an analyst filters the cross-dataset links by `sources` length ≥ 2)
409
+ // carries `sources` + `sourceIDs` (so an analyst filters the cross-dataset links by `sources` length ≥ 2)
485
410
  // and the geocode tier. QGIS-ready; this is the operator-verifiable output of the matcher. ---
486
411
  if (OUT_GEOJSON) {
487
412
  const fc = toGeoJSON(entities)
488
- writeFileSync(OUT_GEOJSON, JSON.stringify(fc, null, 2))
413
+ await writeLocalJSONFile(fc, OUT_GEOJSON)
489
414
  report?.(`[written] ${OUT_GEOJSON} — ${fc.features.length} entity features (${crossSource.length} cross-source)`)
490
415
  }
491
416
 
@@ -21,15 +21,18 @@
21
21
  * the threshold fix (option 1) works → ship a cross-source threshold. If matching FS link count
22
22
  * only comes with collapsing total entities and a LOWER phone-corrob (junk over-merges), the
23
23
  * threshold is insufficient by construction → FS stays pinned / a cross-objective retrain (#655
24
- * option 2) is the only lever.
24
+ * option 2) is the only change.
25
25
  *
26
26
  * Run: `mailwoman registry scorer-eval threshold-sweep [--cap 2000] [--state TX]
27
27
  * [--wof <admin.db>] [--data-root <dir>] [--out-md <md>]`
28
28
  */
29
29
 
30
- import { writeFileSync } from "node:fs"
30
+ import { dataRootPath } from "@mailwoman/core/data-root"
31
+ import { writeLocalFile } from "@mailwoman/core/fs/writers"
32
+ import { pathToFileURL } from "@mailwoman/core/module/file-url"
33
+ import { formatPercent } from "@mailwoman/core/stats"
34
+ import { resolvePath } from "path-ts"
31
35
 
32
- import { dataRootPath, formatPercent } from "@mailwoman/core/utils"
33
36
  import {
34
37
  addressFrequencyKey,
35
38
  buildDefaultModel,
@@ -37,16 +40,15 @@ import {
37
40
  DEDUP_GBT_META,
38
41
  DEDUP_GBT_MODEL,
39
42
  ingestRows,
43
+ normalizePhoneStrict,
40
44
  resolveEntities,
41
45
  streamRows,
42
- type ColumnMapping,
43
46
  type GeocodeAddress,
44
47
  type ResolvedEntity,
45
48
  type SourceRecord,
46
- } from "@mailwoman/registry"
47
-
48
- import type { EvalGeocoderFactory } from "./eval-geocoder.ts"
49
- import { buildSpecs, norm, type SourceSpec } from "./shared.ts"
49
+ } from "#index"
50
+ import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
51
+ import { buildSpecs, stateOption } from "#tools/shared"
50
52
 
51
53
  /**
52
54
  * Independent sources that must agree before a cluster counts as cross-source corroborated.
@@ -90,16 +92,6 @@ export interface CrossSourceThresholdSweepOptions {
90
92
  const entitySources = (e: ResolvedEntity): Set<string> =>
91
93
  new Set(e.records.map((r) => r.source).filter((s): s is string => !!s))
92
94
 
93
- /**
94
- * Last-10-digit phone key (drops formatting / country code).
95
- */
96
- const normPhone = (p?: string | null): string => {
97
- if (!p) return ""
98
- const d = p.replaceAll(/\D/g, "")
99
-
100
- return d.length >= 10 ? d.slice(-10) : ""
101
- }
102
-
103
95
  /**
104
96
  * Label-free precision proxy: does this cross-source entity carry the SAME phone in records from two DIFFERENT sources?
105
97
  * (Phone isn't the join key, so a match is independent corroboration of same-facility.) Entities where no two
@@ -110,7 +102,7 @@ function phoneEvidence(e: ResolvedEntity): "corroborated" | "contradicted" | "un
110
102
  const bySource = new Map<string, Set<string>>()
111
103
 
112
104
  for (const r of e.records) {
113
- const ph = normPhone(r.phone)
105
+ const ph = normalizePhoneStrict(r.phone)
114
106
 
115
107
  if (!ph) continue
116
108
  const s = r.source ?? "?"
@@ -149,7 +141,7 @@ interface ArmMetrics {
149
141
  phoneCheckable: number
150
142
  }
151
143
 
152
- function measure(label: string, threshold: number | null, entities: ResolvedEntity[]): ArmMetrics {
144
+ async function measure(label: string, threshold: number | null, entities: ResolvedEntity[]): Promise<ArmMetrics> {
153
145
  let crossSource = 0
154
146
  let tripleSource = 0
155
147
  let phoneCorrob = 0
@@ -201,7 +193,7 @@ export async function crossSourceThresholdSweep(
201
193
  ): Promise<{ markdown: string }> {
202
194
  const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
203
195
  const CAP = options.cap ?? 2000
204
- const STATE = (options.state || "TX").toUpperCase()
196
+ const STATE = stateOption(options)
205
197
  const OUT_MD = options.outMd || ""
206
198
  const CANDIDATE = options.candidate || ""
207
199
  const SPECS = buildSpecs(`${SOURCES}`, STATE)
@@ -226,13 +218,13 @@ export async function crossSourceThresholdSweep(
226
218
 
227
219
  report?.("[B] building the geocoder…")
228
220
  const geocoder = await options.createGeocoder()
229
- const seam: GeocodeAddress = geocoder.seam
221
+ const geocodeForIngest: GeocodeAddress = geocoder.geocodeAddress
230
222
 
231
223
  report?.("[C] geocoding + ingesting…")
232
224
  const records: SourceRecord[] = []
233
225
 
234
226
  for (const spec of SPECS) {
235
- const recs = await ingestRows(rawBySource.get(spec.source)!, spec.mapping, { geocodeAddress: seam })
227
+ const recs = await ingestRows(rawBySource.get(spec.source)!, spec.mapping, { geocodeAddress: geocodeForIngest })
236
228
 
237
229
  for (const r of recs) {
238
230
  r.id = `${spec.source}:${r.id}`
@@ -241,7 +233,7 @@ export async function crossSourceThresholdSweep(
241
233
  records.push(...recs)
242
234
  }
243
235
 
244
- geocoder.close()
236
+ geocoder[Symbol.dispose]()
245
237
  const geocoded = records.filter((r) => r.address?.geocode).length
246
238
  report?.(` ${records.length} records; geocoded ${geocoded}`)
247
239
 
@@ -268,7 +260,7 @@ export async function crossSourceThresholdSweep(
268
260
  // --- Arm 1: the FS baseline (the recall-correct baseline cross-source flows currently pin). ---
269
261
  report?.("[D] resolving — FS baseline baseline…")
270
262
 
271
- const fs = measure(
263
+ const fs = await measure(
272
264
  "FS baseline",
273
265
  0,
274
266
  resolveEntities(records, { trainEM: true, collapseSpatial: true, addressFrequency, learnedScorer: false }).entities
@@ -289,7 +281,7 @@ export async function crossSourceThresholdSweep(
289
281
  threshold: t,
290
282
  })
291
283
 
292
- gbtArms.push(measure(`GBT @ ${t.toFixed(2)}`, t, entities))
284
+ gbtArms.push(await measure(`GBT @ ${t.toFixed(2)}`, t, entities))
293
285
  }
294
286
 
295
287
  // --- Verdict. The threshold fix WORKS only if some GBT arm dominates FS — more (or equal)
@@ -301,9 +293,6 @@ export async function crossSourceThresholdSweep(
301
293
  const candidateArms: ArmMetrics[] = []
302
294
 
303
295
  if (CANDIDATE) {
304
- const { pathToFileURL } = await import("node:url")
305
- const { resolve: resolvePath } = await import("node:path")
306
-
307
296
  const mod = (await import(pathToFileURL(resolvePath(CANDIDATE)).href)) as {
308
297
  CROSS_SOURCE_GBT_MODEL?: typeof DEDUP_GBT_MODEL
309
298
  CROSS_SOURCE_GBT_META?: { recommendedThreshold?: number }
@@ -322,7 +311,7 @@ export async function crossSourceThresholdSweep(
322
311
 
323
312
  for (const t of [t0 - 1, t0, t0 + 1]) {
324
313
  candidateArms.push(
325
- measure(
314
+ await measure(
326
315
  `cross-GBT @ ${t.toFixed(2)}`,
327
316
  t,
328
317
  resolveEntities(records, {
@@ -418,7 +407,7 @@ export async function crossSourceThresholdSweep(
418
407
  `threshold to admit more only over-merges (the over-merge features REPLACE the FS weight, so true ` +
419
408
  `cross-source pairs share a logit band with genuine over-merges). Threshold alone (option 1) is ` +
420
409
  `**INSUFFICIENT** — FS stays pinned (correct + best-precision for this objective); a cross-objective ` +
421
- `retrain (option 2), gated on cross-source labels, is the only lever. See #655.`
410
+ `retrain (option 2), conditioned on cross-source labels, is the only change. See #655.`
422
411
  )
423
412
  } else {
424
413
  lines.push(
@@ -436,7 +425,7 @@ export async function crossSourceThresholdSweep(
436
425
  console.log(md)
437
426
 
438
427
  if (OUT_MD) {
439
- writeFileSync(OUT_MD, md)
428
+ await writeLocalFile(md, OUT_MD)
440
429
  report?.(`[written] ${OUT_MD}`)
441
430
  }
442
431