@mailwoman/registry 10.0.0 → 10.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 (231) hide show
  1. package/README.md +11 -14
  2. package/lib/address-key.ts +14 -10
  3. package/lib/geocode-handler.ts +7 -5
  4. package/lib/geojson.ts +13 -7
  5. package/lib/ingest.ts +70 -92
  6. package/lib/learned-scorer.ts +38 -44
  7. package/lib/map-html.ts +26 -72
  8. package/lib/models/crosssource-gbt-en-us.ts +9 -7
  9. package/lib/models/dedup-gbt-en-us.ts +9 -8
  10. package/lib/models/org-crosssource-gbt-en-us.ts +10 -8
  11. package/lib/reconcile.ts +45 -54
  12. package/lib/resolve.ts +187 -130
  13. package/lib/types.ts +35 -29
  14. package/out/address-key.d.ts +14 -10
  15. package/out/address-key.d.ts.map +1 -1
  16. package/out/address-key.js +14 -10
  17. package/out/address-key.js.map +1 -1
  18. package/out/geocode-handler.d.ts +6 -4
  19. package/out/geocode-handler.d.ts.map +1 -1
  20. package/out/geocode-handler.js +7 -5
  21. package/out/geocode-handler.js.map +1 -1
  22. package/out/geojson.d.ts +9 -5
  23. package/out/geojson.d.ts.map +1 -1
  24. package/out/geojson.js +13 -7
  25. package/out/geojson.js.map +1 -1
  26. package/out/ingest.d.ts +49 -76
  27. package/out/ingest.d.ts.map +1 -1
  28. package/out/ingest.js +37 -62
  29. package/out/ingest.js.map +1 -1
  30. package/out/learned-scorer.d.ts +29 -26
  31. package/out/learned-scorer.d.ts.map +1 -1
  32. package/out/learned-scorer.js +31 -39
  33. package/out/learned-scorer.js.map +1 -1
  34. package/out/map-html.d.ts +13 -32
  35. package/out/map-html.d.ts.map +1 -1
  36. package/out/map-html.js +11 -64
  37. package/out/map-html.js.map +1 -1
  38. package/out/models/crosssource-gbt-en-us.d.ts +9 -7
  39. package/out/models/crosssource-gbt-en-us.d.ts.map +1 -1
  40. package/out/models/crosssource-gbt-en-us.js +9 -7
  41. package/out/models/crosssource-gbt-en-us.js.map +1 -1
  42. package/out/models/dedup-gbt-en-us.d.ts +9 -8
  43. package/out/models/dedup-gbt-en-us.d.ts.map +1 -1
  44. package/out/models/dedup-gbt-en-us.js +9 -8
  45. package/out/models/dedup-gbt-en-us.js.map +1 -1
  46. package/out/models/org-crosssource-gbt-en-us.d.ts +10 -8
  47. package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -1
  48. package/out/models/org-crosssource-gbt-en-us.js +10 -8
  49. package/out/models/org-crosssource-gbt-en-us.js.map +1 -1
  50. package/out/reconcile.d.ts +36 -50
  51. package/out/reconcile.d.ts.map +1 -1
  52. package/out/reconcile.js +18 -42
  53. package/out/reconcile.js.map +1 -1
  54. package/out/resolve.d.ts +152 -91
  55. package/out/resolve.d.ts.map +1 -1
  56. package/out/resolve.js +67 -68
  57. package/out/resolve.js.map +1 -1
  58. package/out/tools/coverage-reconciliation.d.ts +23 -23
  59. package/out/tools/coverage-reconciliation.d.ts.map +1 -1
  60. package/out/tools/coverage-reconciliation.js +15 -26
  61. package/out/tools/coverage-reconciliation.js.map +1 -1
  62. package/out/tools/cross/dataset-correlation.d.ts +23 -27
  63. package/out/tools/cross/dataset-correlation.d.ts.map +1 -1
  64. package/out/tools/cross/dataset-correlation.js +9 -61
  65. package/out/tools/cross/dataset-correlation.js.map +1 -1
  66. package/out/tools/cross/source-threshold-sweep.d.ts +20 -26
  67. package/out/tools/cross/source-threshold-sweep.d.ts.map +1 -1
  68. package/out/tools/cross/source-threshold-sweep.js +14 -40
  69. package/out/tools/cross/source-threshold-sweep.js.map +1 -1
  70. package/out/tools/dedup-ceiling.d.ts +23 -26
  71. package/out/tools/dedup-ceiling.d.ts.map +1 -1
  72. package/out/tools/dedup-ceiling.js +22 -41
  73. package/out/tools/dedup-ceiling.js.map +1 -1
  74. package/out/tools/eval-geocoder.d.ts +25 -16
  75. package/out/tools/eval-geocoder.d.ts.map +1 -1
  76. package/out/tools/eval-geocoder.js +5 -6
  77. package/out/tools/eval-geocoder.js.map +1 -1
  78. package/out/tools/geocoder/namesake-probe.d.ts +9 -8
  79. package/out/tools/geocoder/namesake-probe.d.ts.map +1 -1
  80. package/out/tools/geocoder/namesake-probe.js +6 -7
  81. package/out/tools/geocoder/namesake-probe.js.map +1 -1
  82. package/out/tools/geocoder/vs-provided-coords.d.ts +18 -15
  83. package/out/tools/geocoder/vs-provided-coords.d.ts.map +1 -1
  84. package/out/tools/geocoder/vs-provided-coords.js +30 -27
  85. package/out/tools/geocoder/vs-provided-coords.js.map +1 -1
  86. package/out/tools/gold-set-sample.d.ts +27 -18
  87. package/out/tools/gold-set-sample.d.ts.map +1 -1
  88. package/out/tools/gold-set-sample.js +18 -22
  89. package/out/tools/gold-set-sample.js.map +1 -1
  90. package/out/tools/learned/scorer/clustering-eval.d.ts +30 -27
  91. package/out/tools/learned/scorer/clustering-eval.d.ts.map +1 -1
  92. package/out/tools/learned/scorer/clustering-eval.js +28 -38
  93. package/out/tools/learned/scorer/clustering-eval.js.map +1 -1
  94. package/out/tools/learned/scorer/crossstate-eval.d.ts +24 -18
  95. package/out/tools/learned/scorer/crossstate-eval.d.ts.map +1 -1
  96. package/out/tools/learned/scorer/crossstate-eval.js +19 -25
  97. package/out/tools/learned/scorer/crossstate-eval.js.map +1 -1
  98. package/out/tools/learned/scorer/eval.d.ts +26 -39
  99. package/out/tools/learned/scorer/eval.d.ts.map +1 -1
  100. package/out/tools/learned/scorer/eval.js +11 -71
  101. package/out/tools/learned/scorer/eval.js.map +1 -1
  102. package/out/tools/matcher-scale.d.ts +12 -17
  103. package/out/tools/matcher-scale.d.ts.map +1 -1
  104. package/out/tools/matcher-scale.js +11 -29
  105. package/out/tools/matcher-scale.js.map +1 -1
  106. package/out/tools/nppes/dedup-benchmark.d.ts +22 -41
  107. package/out/tools/nppes/dedup-benchmark.d.ts.map +1 -1
  108. package/out/tools/nppes/dedup-benchmark.js +21 -67
  109. package/out/tools/nppes/dedup-benchmark.js.map +1 -1
  110. package/out/tools/nppes/org-name.d.ts +5 -11
  111. package/out/tools/nppes/org-name.d.ts.map +1 -1
  112. package/out/tools/nppes/org-name.js +2 -9
  113. package/out/tools/nppes/org-name.js.map +1 -1
  114. package/out/tools/nppes/overmerge-packet.d.ts +15 -11
  115. package/out/tools/nppes/overmerge-packet.d.ts.map +1 -1
  116. package/out/tools/nppes/overmerge-packet.js +6 -7
  117. package/out/tools/nppes/overmerge-packet.js.map +1 -1
  118. package/out/tools/nppes/report.d.ts +17 -13
  119. package/out/tools/nppes/report.d.ts.map +1 -1
  120. package/out/tools/nppes/report.js +6 -14
  121. package/out/tools/nppes/report.js.map +1 -1
  122. package/out/tools/nppes/sample.d.ts +29 -18
  123. package/out/tools/nppes/sample.d.ts.map +1 -1
  124. package/out/tools/nppes/sample.js +24 -28
  125. package/out/tools/nppes/sample.js.map +1 -1
  126. package/out/tools/nppes/scoring.d.ts +7 -6
  127. package/out/tools/nppes/scoring.d.ts.map +1 -1
  128. package/out/tools/nppes/scoring.js +6 -5
  129. package/out/tools/nppes/scoring.js.map +1 -1
  130. package/out/tools/nppes/settings.d.ts +10 -7
  131. package/out/tools/nppes/settings.d.ts.map +1 -1
  132. package/out/tools/nppes/settings.js +16 -16
  133. package/out/tools/nppes/settings.js.map +1 -1
  134. package/out/tools/nppes/truth-grains.d.ts +36 -23
  135. package/out/tools/nppes/truth-grains.d.ts.map +1 -1
  136. package/out/tools/nppes/truth-grains.js +36 -20
  137. package/out/tools/nppes/truth-grains.js.map +1 -1
  138. package/out/tools/shared.d.ts +68 -72
  139. package/out/tools/shared.d.ts.map +1 -1
  140. package/out/tools/shared.js +50 -67
  141. package/out/tools/shared.js.map +1 -1
  142. package/out/tools/train/cross-gbt.d.ts +37 -26
  143. package/out/tools/train/cross-gbt.d.ts.map +1 -1
  144. package/out/tools/train/cross-gbt.js +14 -25
  145. package/out/tools/train/cross-gbt.js.map +1 -1
  146. package/out/tools/train/gbt.d.ts +36 -20
  147. package/out/tools/train/gbt.d.ts.map +1 -1
  148. package/out/tools/train/gbt.js +27 -31
  149. package/out/tools/train/gbt.js.map +1 -1
  150. package/out/tools/train/org-cross-gbt.d.ts +38 -24
  151. package/out/tools/train/org-cross-gbt.d.ts.map +1 -1
  152. package/out/tools/train/org-cross-gbt.js +18 -22
  153. package/out/tools/train/org-cross-gbt.js.map +1 -1
  154. package/out/tools/txhhsc-to-oarow.d.ts +14 -9
  155. package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
  156. package/out/tools/txhhsc-to-oarow.js +16 -15
  157. package/out/tools/txhhsc-to-oarow.js.map +1 -1
  158. package/out/tools/viz/browser.d.ts +6 -5
  159. package/out/tools/viz/browser.d.ts.map +1 -1
  160. package/out/tools/viz/browser.js +6 -5
  161. package/out/tools/viz/browser.js.map +1 -1
  162. package/out/tools/viz/cross-dataset-map.d.ts +7 -4
  163. package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
  164. package/out/tools/viz/cross-dataset-map.js +9 -6
  165. package/out/tools/viz/cross-dataset-map.js.map +1 -1
  166. package/out/tools/viz/geocode-first-surface.d.ts +11 -5
  167. package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
  168. package/out/tools/viz/geocode-first-surface.js +16 -11
  169. package/out/tools/viz/geocode-first-surface.js.map +1 -1
  170. package/out/tools/viz/render/map.d.ts +5 -5
  171. package/out/tools/viz/render/map.d.ts.map +1 -1
  172. package/out/tools/viz/render/map.js +6 -5
  173. package/out/tools/viz/render/map.js.map +1 -1
  174. package/out/tools/viz/{render/index.d.ts → render.d.ts} +13 -9
  175. package/out/tools/viz/render.d.ts.map +1 -0
  176. package/out/tools/viz/{render/index.js → render.js} +9 -8
  177. package/out/tools/viz/render.js.map +1 -0
  178. package/out/tools/viz/source-provenance-map.d.ts +19 -7
  179. package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
  180. package/out/tools/viz/source-provenance-map.js +11 -8
  181. package/out/tools/viz/source-provenance-map.js.map +1 -1
  182. package/out/tools/viz/yardstick-figure.d.ts +2 -21
  183. package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
  184. package/out/tools/viz/yardstick-figure.js +3 -39
  185. package/out/tools/viz/yardstick-figure.js.map +1 -1
  186. package/out/types.d.ts +35 -29
  187. package/out/types.d.ts.map +1 -1
  188. package/out/types.js +2 -2
  189. package/out/types.js.map +1 -1
  190. package/package.json +42 -185
  191. package/{lib/tools → tools}/coverage-reconciliation.ts +27 -30
  192. package/{lib/tools → tools}/cross/dataset-correlation.ts +35 -73
  193. package/{lib/tools → tools}/cross/source-threshold-sweep.ts +29 -46
  194. package/{lib/tools → tools}/dedup-ceiling.ts +34 -45
  195. package/tools/eval-geocoder.ts +77 -0
  196. package/{lib/tools → tools}/geocoder/namesake-probe.ts +9 -8
  197. package/{lib/tools → tools}/geocoder/vs-provided-coords.ts +40 -31
  198. package/{lib/tools → tools}/gold-set-sample.ts +35 -29
  199. package/{lib/tools → tools}/learned/scorer/clustering-eval.ts +49 -45
  200. package/{lib/tools → tools}/learned/scorer/crossstate-eval.ts +34 -30
  201. package/{lib/tools → tools}/learned/scorer/eval.ts +39 -78
  202. package/{lib/tools → tools}/matcher-scale.ts +21 -33
  203. package/{lib/tools → tools}/nppes/dedup-benchmark.ts +39 -83
  204. package/tools/nppes/org-name.ts +15 -0
  205. package/{lib/tools → tools}/nppes/overmerge-packet.ts +16 -12
  206. package/{lib/tools → tools}/nppes/report.ts +32 -25
  207. package/{lib/tools → tools}/nppes/sample.ts +43 -38
  208. package/{lib/tools → tools}/nppes/scoring.ts +7 -6
  209. package/{lib/tools → tools}/nppes/settings.ts +16 -16
  210. package/{lib/tools → tools}/nppes/truth-grains.ts +46 -26
  211. package/{lib/tools → tools}/shared.ts +79 -98
  212. package/{lib/tools → tools}/train/cross-gbt.ts +39 -34
  213. package/{lib/tools → tools}/train/gbt.ts +55 -41
  214. package/{lib/tools → tools}/train/org-cross-gbt.ts +40 -30
  215. package/{lib/tools → tools}/txhhsc-to-oarow.ts +24 -18
  216. package/{lib/tools → tools}/viz/browser.ts +6 -5
  217. package/{lib/tools → tools}/viz/cross-dataset-map.ts +15 -9
  218. package/{lib/tools → tools}/viz/geocode-first-surface.ts +29 -17
  219. package/{lib/tools → tools}/viz/render/map.ts +7 -6
  220. package/{lib/tools/viz/render/index.ts → tools/viz/render.ts} +16 -11
  221. package/{lib/tools → tools}/viz/source-provenance-map.ts +30 -15
  222. package/{lib/tools → tools}/viz/yardstick-figure.ts +6 -43
  223. package/lib/tools/eval-geocoder.ts +0 -67
  224. package/lib/tools/index.ts +0 -31
  225. package/lib/tools/nppes/org-name.ts +0 -23
  226. package/out/tools/index.d.ts +0 -31
  227. package/out/tools/index.d.ts.map +0 -1
  228. package/out/tools/index.js +0 -31
  229. package/out/tools/index.js.map +0 -1
  230. package/out/tools/viz/render/index.d.ts.map +0 -1
  231. package/out/tools/viz/render/index.js.map +0 -1
@@ -3,25 +3,9 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * #655 measurement — can a RE-THRESHOLDED dedup GBT beat the FS baseline on the cross-SOURCE link
7
- * discovery objective? The dedup GBT (#603) is pinned OFF for cross-dataset flows because its
8
- * over-merge features (`spatial-exact × name/org-disagree`) push true "same facility, different
9
- * operational name across sources" pairs NEGATIVE — and the GBT logit REPLACES the FS weight, so
10
- * a threshold can't trivially separate them. This quantifies that.
11
- *
12
- * Geocode the three sources ONCE (NPPES + FCC-RHC + TX HHSC, TX-scoped), then resolve repeatedly:
13
- * the FS baseline (the recall-correct baseline) and the bundled GBT at a fine threshold sweep.
14
- * For each arm, report cross-source links (entities spanning ≥2 sources), triple-source entities,
15
- * total entities (an over-merge proxy — fewer = more collapsing), and a LABEL-FREE precision
16
- * proxy: PHONE corroboration — the fraction of cross-source entities in which two records from
17
- * DIFFERENT sources carry the same phone number (strong same-facility evidence the scorer didn't
18
- * directly use as the join key).
19
- *
20
- * Verdict logic: if some GBT threshold matches FS's cross-source link count at ≥ FS phone-corrob,
21
- * the threshold fix (option 1) works → ship a cross-source threshold. If matching FS link count
22
- * only comes with collapsing total entities and a LOWER phone-corrob (junk over-merges), the
23
- * threshold is insufficient by construction → FS stays pinned / a cross-objective retrain (#655
24
- * option 2) is the only change.
6
+ * Cross-source threshold sweep. Resolve the sources once, then compare the Fellegi-Sunter
7
+ * baseline against the bundled GBT over a fine threshold sweep, scoring each arm on cross-source
8
+ * links, triple-source entities, total entities and phone corroboration.
25
9
  *
26
10
  * Run: `mailwoman registry scorer-eval threshold-sweep [--cap 2000] [--state TX]
27
11
  * [--wof <admin.db>] [--data-root <dir>] [--out-md <md>]`
@@ -60,24 +44,33 @@ const MIN_CROSS_SOURCE_AGREEMENT = 3
60
44
  */
61
45
  export interface CrossSourceThresholdSweepOptions {
62
46
  /**
63
- * The injected geocoder factory (the command wires `mailwoman/geocode-core`; see `./eval-geocoder.ts`).
47
+ * The injected geocoder factory.
48
+ *
49
+ * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
64
50
  */
65
51
  createGeocoder: EvalGeocoderFactory
66
52
  /**
67
- * Record-matcher sources directory. Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
53
+ * Record-matcher sources directory.
54
+ *
55
+ * @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
68
56
  */
69
57
  sources?: string
70
58
  /**
71
- * Rows kept per source. Default 2000.
59
+ * Rows kept per source.
60
+ *
61
+ * @defaultValue `2000`
72
62
  */
73
63
  cap?: number
74
64
  /**
75
- * State filter. Default TX.
65
+ * State filter.
66
+ *
67
+ * @defaultValue TX.
76
68
  */
77
69
  state?: string
78
70
  /**
79
- * #655 option 2: a trained CROSS-SOURCE GBT module (exports CROSS_SOURCE_GBT_MODEL + _META) to grade as a third arm
80
- * at its recommended threshold — the model `registry train-scorer cross-gbt` emits.
71
+ * A trained cross-source GBT module (exports CROSS_SOURCE_GBT_MODEL + _META) to
72
+ * grade as a third arm at its recommended threshold.
73
+ * This is the model `registry train-scorer cross-gbt` emits.
81
74
  */
82
75
  candidate?: string
83
76
  /**
@@ -86,17 +79,16 @@ export interface CrossSourceThresholdSweepOptions {
86
79
  outMd?: string
87
80
  }
88
81
 
89
- /**
90
- * Distinct provenance labels an entity's records span.
91
- */
92
82
  const entitySources = (e: ResolvedEntity): Set<string> =>
93
83
  new Set(e.records.map((r) => r.source).filter((s): s is string => !!s))
94
84
 
95
85
  /**
96
- * Label-free precision proxy: does this cross-source entity carry the SAME phone in records from two DIFFERENT sources?
97
- * (Phone isn't the join key, so a match is independent corroboration of same-facility.) Entities where no two
98
- * cross-source records both have a phone are "unknown" — we only count corroborated / contradicted among those that CAN
99
- * be checked.
86
+ * Label-free precision proxy: does this cross-source entity have the same phone
87
+ * in records from two different sources?
88
+ *
89
+ * Phone is not the join key, so a match is independent corroboration of one facility.
90
+ * Entities without phone numbers on two cross-source records are unknown.
91
+ * Only checkable entities count.
100
92
  */
101
93
  function phoneEvidence(e: ResolvedEntity): "corroborated" | "contradicted" | "unknown" {
102
94
  const bySource = new Map<string, Set<string>>()
@@ -185,7 +177,8 @@ async function measure(label: string, threshold: number | null, entities: Resolv
185
177
  }
186
178
 
187
179
  /**
188
- * #655 cross-source threshold sweep — see the module doc. Emits the markdown report to stdout.
180
+ * Compare the FS baseline against bundled GBT over a threshold sweep.
181
+ * Emit the markdown report to stdout.
189
182
  */
190
183
  export async function crossSourceThresholdSweep(
191
184
  options: CrossSourceThresholdSweepOptions,
@@ -198,7 +191,6 @@ export async function crossSourceThresholdSweep(
198
191
  const CANDIDATE = options.candidate || ""
199
192
  const SPECS = buildSpecs(`${SOURCES}`, STATE)
200
193
 
201
- // Ingest and geocode each source once before sweeping thresholds.
202
194
  const rawBySource = new Map<string, Record<string, string>[]>()
203
195
 
204
196
  for (const spec of SPECS) {
@@ -237,7 +229,6 @@ export async function crossSourceThresholdSweep(
237
229
  const geocoded = records.filter((r) => r.address?.geocode).length
238
230
  report?.(` ${records.length} records; geocoded ${geocoded}`)
239
231
 
240
- // Score with the bundled GBT over the input-scoped address-frequency basis.
241
232
  const addrCounts = new Map<string, number>()
242
233
  let addrTotal = 0
243
234
 
@@ -257,7 +248,6 @@ export async function crossSourceThresholdSweep(
257
248
  const comparisons = buildDefaultModel({ collapseSpatial: true, addressFrequency }).comparisons
258
249
  const gbtScorer = createGBTScorer({ model: DEDUP_GBT_MODEL, comparisons, addressFrequency })
259
250
 
260
- // Evaluate the FS recall-correct baseline.
261
251
  report?.("[D] resolving — FS baseline baseline…")
262
252
 
263
253
  const fs = await measure(
@@ -266,8 +256,6 @@ export async function crossSourceThresholdSweep(
266
256
  resolveEntities(records, { trainEM: true, collapseSpatial: true, addressFrequency, learnedScorer: false }).entities
267
257
  )
268
258
 
269
- // Evaluate the bundled GBT over a fine threshold sweep.
270
- // cross-source pairs sit at strongly NEGATIVE logits). ---
271
259
  const SWEEP = [-8, -6, -5, -4, -3, -2, -1, 0, 1, 2, DEDUP_GBT_META.recommendedThreshold]
272
260
  const gbtArms: ArmMetrics[] = []
273
261
 
@@ -284,12 +272,9 @@ export async function crossSourceThresholdSweep(
284
272
  gbtArms.push(await measure(`GBT @ ${t.toFixed(2)}`, t, entities))
285
273
  }
286
274
 
287
- // The threshold fix passes only when a GBT arm dominates FS.
288
- // cross-source links at ≥ FS phone-corroboration WITHOUT over-merging (entity count must not
289
- // collapse below ~90% of FS, else the "links" are giant-blob artifacts). Otherwise FS is on the
290
- // frontier and threshold alone is insufficient. ---
275
+ // A GBT arm dominates only when it matches FS cross-source links at no lower phone corroboration and
276
+ // keeps at least 90% of FS entities, since a collapse means giant-blob artifacts rather than links.
291
277
  const pct = (n: number, d: number) => formatPercent(n, d, 0)
292
- // Evaluate the cross-source-trained GBT at its recommended threshold.
293
278
  const candidateArms: ArmMetrics[] = []
294
279
 
295
280
  if (CANDIDATE) {
@@ -334,13 +319,11 @@ export async function crossSourceThresholdSweep(
334
319
  (a) => a.crossSource >= fs.crossSource && rate(a) >= fsCorrobRate && a.entities >= minEntities
335
320
  )
336
321
 
337
- // The candidate (#655 option-2 models) gets its own verdict scan — the hardcoded option-1 verdict
338
- // below is about the DEDUP GBT and must not silently absorb (or ignore) a candidate arm.
322
+ // The candidate gets its own verdict scan, separate from the option-1 verdict for the dedup GBT.
339
323
  const candidateDominating = candidateArms.find(
340
324
  (a) => a.crossSource >= fs.crossSource && rate(a) >= fsCorrobRate && a.entities >= minEntities
341
325
  )
342
326
 
343
- // Best cross-source rate among arms that still retain enough entities to be meaningful.
344
327
  let candidateBest: ArmMetrics | null = null
345
328
 
346
329
  for (const arm of candidateArms) {
@@ -3,28 +3,16 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * #625 ceiling measurement — "how good is good enough" for dedup, derived from the data instead of
7
- * asserted as a round number (DeepSeek consult, issue #625). The residual dedup error is
8
- * OVER-MERGE: distinct co-located providers (different NPIs at one clinic/billing address) fused
9
- * because a shared address outvotes a disagreeing name. The irreducible part of that — the
10
- * **Bayes error** — is the set of co-located distinct-NPI pairs whose NAMES are also ~identical:
11
- * no name/org feature can separate them, so any address-aware matcher over-merges them. That
12
- * floor caps PRECISION.
6
+ * Dedup ceiling measurement, answering how good is good enough for dedup from the data rather
7
+ * than from a round number. The residual dedup error is over-merge: distinct co-located providers
8
+ * (different NPIs at one address) fused because a shared address outvotes a disagreeing name. The
9
+ * irreducible part is the set of co-located distinct-NPI pairs whose name text is also near
10
+ * identical, so no name or organization feature can separate them.
13
11
  *
14
- * This measures it directly and label-free, using NPI as the distinctness truth (different NPI =
15
- * different provider). Geocode-free on purpose: the question is the DATA's separability, not the
16
- * geocoder — so we can run at large N (tens of thousands of TX providers) in seconds. We key
17
- * "same address" with the matcher's own `addressFrequencyKey`, and "same name" with a normalized
18
- * token Jaccard over the legal business name.
19
- *
20
- * Reports, over co-located distinct-NPI pairs (the over-merge population):
21
- *
22
- * - Co-location prevalence (addresses hosting ≥2 distinct NPIs; providers at shared addresses)
23
- * - The org-name-similarity distribution of those pairs
24
- * - The COLLISION rate: fraction with org-sim ≥ τ (irreducible over-merge) — the precision floor
25
- * - Whether a shared phone would help (it doesn't: institutional switchboards) — among collisions,
26
- * how often the two distinct NPIs ALSO share a phone (so phone over-links, can't separate)
27
- * …and derives a precision/F1 CEILING under stated assumptions, with the caveats called out.
12
+ * This measures that floor directly and without labels, using NPI as the distinctness truth. It
13
+ * is geocode-free on purpose, so it can run at large N in seconds. "Same address" uses the
14
+ * matcher's own `addressFrequencyKey`, and "same name" uses a normalized token Jaccard over the
15
+ * legal business name.
28
16
  *
29
17
  * Run: `mailwoman registry dedup-ceiling [--cap 50000] [--state TX] [--sources <dir>] [--tau 0.7]
30
18
  * [--out-md <md>]`
@@ -47,19 +35,27 @@ const WEAK_SIMILARITY_MIN = 0.3
47
35
  */
48
36
  export interface DedupCeilingOptions {
49
37
  /**
50
- * Record-matcher sources directory. Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
38
+ * Record-matcher sources directory.
39
+ *
40
+ * @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
51
41
  */
52
42
  sources?: string
53
43
  /**
54
- * Providers sampled from the registry. Default 50000.
44
+ * Providers sampled from the registry.
45
+ *
46
+ * @defaultValue `50000`
55
47
  */
56
48
  cap?: number
57
49
  /**
58
- * State filter. Default TX.
50
+ * State filter.
51
+ *
52
+ * @defaultValue TX.
59
53
  */
60
54
  state?: string
61
55
  /**
62
- * Org-name Jaccard collision threshold. Default 0.7.
56
+ * Org-name Jaccard collision threshold.
57
+ *
58
+ * @defaultValue `0.7`
63
59
  */
64
60
  tau?: number
65
61
  /**
@@ -69,7 +65,8 @@ export interface DedupCeilingOptions {
69
65
  }
70
66
 
71
67
  /**
72
- * #625 ceiling measurement — see the module doc. Emits the markdown report to stdout.
68
+ * Measure the irreducible over-merge of co-located providers.
69
+ * Emit the markdown report to stdout.
73
70
  */
74
71
  export async function dedupCeiling(
75
72
  options: DedupCeilingOptions = {},
@@ -82,23 +79,19 @@ export async function dedupCeiling(
82
79
  const OUT_MD = options.outMd || ""
83
80
  const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
84
81
 
85
- // Stream Texas organization providers, retaining one primary practice-address record per NPI.
86
82
  report?.(`[A] streaming ${STATE} org providers (cap ${CAP})…`)
87
83
  const { byAddr, kept, scanned } = await scanColocatedProviders({ registryPath: REGISTRY, state: STATE, cap: CAP })
88
84
  report?.(` scanned ${scanned} rows → ${kept} ${STATE} org providers at ${byAddr.size} distinct addresses`)
89
85
 
90
- // Measure organization similarity and collision rate for co-located distinct-NPI pairs.
91
86
  let sharedAddresses = 0
92
87
  let providersAtSharedAddr = 0
93
88
  let pairs = 0
94
- let collide = 0 // org-sim ≥ τ — name-indistinguishable co-located distinct NPIs
95
- let mid = 0 // τ > sim ≥ 0.3 — partially separable
96
- let separable = 0 // sim < 0.3 — clearly different names
97
- let collideSharePhone = 0 // of collisions, also share a phone (phone can't separate either)
98
- // Of the collisions, split NPI-over-segmentation (one org, many NPIs — merge is CORRECT) from
99
- // genuinely-distinct co-located providers (the TRUE irreducible over-merge):
100
- let collideSameAuth = 0 // share an authorized official ⇒ one org, multiple NPIs ⇒ correct to merge
101
- let collideDistinct = 0 // different official AND different specialty ⇒ genuinely different providers
89
+ let collide = 0
90
+ let mid = 0
91
+ let separable = 0
92
+ let collideSharePhone = 0
93
+ let collideSameAuth = 0
94
+ let collideDistinct = 0
102
95
  const PAIR_BUDGET = 5_000_000
103
96
 
104
97
  // guard against a pathological mega-address (PO-box farms)
@@ -140,14 +133,10 @@ export async function dedupCeiling(
140
133
  }
141
134
  }
142
135
 
143
- // Derive the precision ceiling from co-located distinct-NPI records.
144
- // pairs, either merge (wrong) or hold them apart using name/org. It CAN separate the `separable`
145
- // (and most `mid`) pairs but NOT the `collide` ones. So the irreducible false-merge rate among
146
- // co-located distinct pairs is collide/pairs; an oracle's precision on the co-located decision is
147
- // bounded by how many merges it makes that are correct. We report the collision rate directly and
148
- // a precision-ceiling BAND (optimistic: only `collide` over-merge; conservative: `collide` + half
149
- // of `mid`). Recall is NOT the binding constraint here (NPPES same-NPI records almost always share
150
- // either address or org), so the F1 ceiling tracks the precision ceiling. ---
136
+ // The irreducible false-merge rate among co-located distinct pairs is collide/pairs.
137
+ // Report the collision rate directly with a precision-ceiling band: optimistic counts
138
+ // only `collide`, and conservative counts `collide` plus half of `mid`.
139
+ // Recall is not binding here, so the F1 ceiling tracks the precision ceiling.
151
140
  const pct = formatPercent
152
141
 
153
142
  const lines: string[] = [
@@ -208,7 +197,7 @@ export async function dedupCeiling(
208
197
  `Recommendation: drop 0.85. Set the bar against a subpart-aware / adjudicated entity truth, report NPI-level AND ` +
209
198
  `entity-level side by side, and target "separate the ~${pct(collideDistinct, pairs)} genuinely-distinct co-located ` +
210
199
  `pairs the GBT can still reach" rather than a round F1. The GBT's corroboration-feature work (#625 revised) ` +
211
- `attacks exactly that separable slice.`,
200
+ `attacks exactly that separable subset.`,
212
201
  "",
213
202
  `## Caveats`,
214
203
  "",
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * The injected-geocoder interface for the record-matcher tools. The registry package never imports
7
+ * the heavy runtime (neural parser, WOF resolver, per-state extracts), since `mailwoman` depends on
8
+ * `@mailwoman/registry` and the reverse import would cycle the workspace graph. Each tool instead
9
+ * takes an {@linkcode EvalGeocoderFactory} the CLI command constructs from
10
+ * `mailwoman/geocode-core` (see `mailwoman/commands/registry/run.tsx`).
11
+ */
12
+
13
+ import type { CaseNormalization } from "@mailwoman/core/pipeline"
14
+
15
+ import type { ColumnMapping, GeocodeAddress, SourceRecord } from "#index"
16
+
17
+ /**
18
+ * The raw single-address geocode surface used by the probe tools, mirroring
19
+ * `mailwoman/geocode-core`'s wire shape.
20
+ */
21
+ export interface EvalGeocodeResult {
22
+ lat: number | null
23
+ lon: number | null
24
+ /**
25
+ * Wire key that mirrors `GeocodeResult.resolution_tier`.
26
+ */
27
+ resolution_tier?: string | null
28
+ }
29
+
30
+ /**
31
+ * A constructed geocoder: the matcher's ingest interface, the raw geocode and the handle release.
32
+ */
33
+ export interface EvalGeocoder extends Disposable {
34
+ /**
35
+ * The matcher's ingest interface (parse and geocode to `PostalAddress`),
36
+ * built through `geocodeAddressVia`.
37
+ */
38
+ geocodeAddress: GeocodeAddress
39
+ /**
40
+ * Raw single-address geocode returning lat, lon and resolution tier.
41
+ */
42
+ geocode: (address: string) => Promise<EvalGeocodeResult>
43
+ /**
44
+ * Release the DB handles (extracts + WOF lookup).
45
+ */
46
+ }
47
+
48
+ /**
49
+ * Per-construction toggles a tool may need to control (the command owns model/WOF/data-root wiring).
50
+ */
51
+ export interface EvalGeocoderInit {
52
+ /**
53
+ * All-caps case normalization.
54
+ *
55
+ * `nppes-benchmark --legacy-join` passes `"preserve"` for the A/B.
56
+ *
57
+ * @defaultValue `"title-case"`
58
+ */
59
+ caseNormalization?: CaseNormalization
60
+ }
61
+
62
+ /**
63
+ * Build a geocoder on demand.
64
+ *
65
+ * Tools construct it late and dispose it as soon as geocoding is done.
66
+ */
67
+ export type EvalGeocoderFactory = (init?: EvalGeocoderInit) => Promise<EvalGeocoder>
68
+
69
+ /**
70
+ * The threaded geocode surface (`mailwoman/geocode-stream` behind the interface)
71
+ * for `nppes-dedup-benchmark --parallel-geocode`.
72
+ * It yields enriched records in completion order.
73
+ */
74
+ export type EvalGeocodeStream = (
75
+ records: SourceRecord[],
76
+ opts: { mapping: ColumnMapping; concurrency: number }
77
+ ) => AsyncIterable<SourceRecord>
@@ -3,12 +3,11 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Admin-tier wrong-region probe (#619 tail) — the geocoder-vs-provided-coords eval found an
7
- * admin-tier tail to 11143 km (p99 2189 km). Hypothesis: when no street extract covers the address,
8
- * the admin cascade resolves the locality by NAME and (when the region/postcode constraint is
9
- * weak) picks the population-dominant FOREIGN namesake — Paris→France, Athens→Greece — instead of
10
- * the in-state Texas city. This probes a curated set of TX namesake cities, with and without ZIP,
11
- * and flags any result outside the Texas bounding box.
6
+ * Admin-tier wrong-region probe. When no street extract covers an address, the admin cascade can
7
+ * resolve the locality by name and, when the region or postcode constraint is weak, pick the
8
+ * population-dominant foreign namesake instead of the in-state Texas city. This probes a curated
9
+ * set of TX namesake cities, with and without ZIP. It flags any result outside the Texas bounding
10
+ * box.
12
11
  *
13
12
  * Run: `mailwoman registry scorer-eval namesake-probe`
14
13
  */
@@ -23,7 +22,9 @@ import { inTXBBOX } from "#tools/shared"
23
22
  */
24
23
  export interface GeocoderNamesakeProbeOptions {
25
24
  /**
26
- * The injected geocoder factory (the command wires `mailwoman/geocode-core`; see `./eval-geocoder.ts`).
25
+ * The injected geocoder factory.
26
+ *
27
+ * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
27
28
  */
28
29
  createGeocoder: EvalGeocoderFactory
29
30
  }
@@ -43,7 +44,7 @@ const CASES: Array<{ city: string; zip: string; tx: [number, number]; namesake:
43
44
  ]
44
45
 
45
46
  /**
46
- * Admin-tier wrong-region probe (#619 tail) — see the module doc. Prints one line per variant to stdout.
47
+ * Probe a curated set of TX namesake cities and print one line per variant to stdout.
47
48
  */
48
49
  export async function geocoderNamesakeProbe(
49
50
  options: GeocoderNamesakeProbeOptions,
@@ -3,18 +3,14 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Geocoder validation against provided coordinates (#619) — a free, honest, real-world accuracy
7
- * eval.
6
+ * Geocoder validation against provided coordinates. TX HHSC's nursing-facilities registry ships
7
+ * a `Geo Location` (`lat,lon`) per facility alongside its physical address. Geocode the address
8
+ * with mailwoman's parser and resolver, then measure the great-circle delta to the provided point,
9
+ * broken down by resolution tier.
8
10
  *
9
- * TX HHSC's nursing-facilities registry ships a `Geo Location` (`lat,lon`) per facility alongside
10
- * its physical address. We geocode the address with mailwoman's real parser + resolver and
11
- * measure the great-circle delta to the provided point — p50 / p90, broken down by the resolution
12
- * tier we assign (address_point / interpolated / admin). This is an independent check of the
13
- * geocoder on real facility addresses; it does not touch the matcher.
14
- *
15
- * The provided coordinate is treated as ground truth for _this_ eval, with the honest caveat that
16
- * it is itself a third-party geocode of unknown provenance — a large delta is a discrepancy to
17
- * inspect, not automatically our error.
11
+ * The provided coordinate is treated as ground truth for this eval, with the caveat that it is
12
+ * itself a third-party geocode of unknown provenance. A large delta is a discrepancy to inspect
13
+ * rather than automatically our error.
18
14
  *
19
15
  * Run: `mailwoman registry scorer-eval vs-provided-coords [--max 1176] [--wof <admin.db>]
20
16
  * [--data-root <dir>] [--out-md docs/articles/evals/resolver-geo/<date>-...md]`
@@ -25,6 +21,7 @@ import { writeLocalFile } from "@mailwoman/core/fs/writers"
25
21
  import { isPresent } from "@mailwoman/core/objects"
26
22
  import { percentile } from "@mailwoman/core/stats"
27
23
  import { haversineKm } from "@mailwoman/match"
24
+ import { TextSpliterator } from "spliterator"
28
25
 
29
26
  import { streamRows } from "#index"
30
27
  import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
@@ -45,15 +42,21 @@ const MAX_ABS_LONGITUDE = 180
45
42
  */
46
43
  export interface GeocoderVsProvidedCoordsOptions {
47
44
  /**
48
- * The injected geocoder factory (the command wires `mailwoman/geocode-core`; see `./eval-geocoder.ts`).
45
+ * The injected geocoder factory.
46
+ *
47
+ * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
49
48
  */
50
49
  createGeocoder: EvalGeocoderFactory
51
50
  /**
52
- * Record-matcher sources directory. Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
51
+ * Record-matcher sources directory.
52
+ *
53
+ * @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
53
54
  */
54
55
  sources?: string
55
56
  /**
56
- * Facilities geocoded. Default 2000.
57
+ * Facilities geocoded.
58
+ *
59
+ * @defaultValue `2000`
57
60
  */
58
61
  max?: number
59
62
  /**
@@ -63,22 +66,28 @@ export interface GeocoderVsProvidedCoordsOptions {
63
66
  }
64
67
 
65
68
  /**
66
- * Parse a `lat,lon` string into a coordinate, or null if malformed / out of range.
69
+ * Parse a `lat,lon` string into a coordinate, or null if malformed or out of range.
70
+ *
71
+ * Deliberately strict and deliberately not `GeoPoint.from()`.
72
+ * The provided coordinate is this eval's ground truth, so a row that cannot be read exactly
73
+ * is dropped (counted in `noCoord`) rather than repaired into something plausible.
74
+ *
75
+ * A silently repaired coordinate lands in the delta distribution as geocoder error.
76
+ *
77
+ * This source writes `latitude,longitude`, while `GeoPoint` reads GeoJSON `[longitude, latitude]`,
78
+ * so `31.5,-89.5` is a Mississippi row here and a South-Atlantic point there.
79
+ * `GeoPoint.from` also maps 0,0 to null.
80
+ *
81
+ * This moves Null Island out of the measured outliers and into the skipped bucket.
82
+ *
83
+ * The report attributes part of its p99/max tail to malformed provided coordinates,
84
+ * so those rows have to stay rejected or measured as-is, never rewritten.
67
85
  *
68
- * Deliberately strict, and deliberately not `GeoPoint.from()`. The provided coordinate is this eval's ground truth, so
69
- * a row we cannot read exactly has to be _dropped_ (counted in `noCoord`) rather than repaired into something plausible
70
- * — a silently repaired coordinate lands in the delta distribution as geocoder error. Two of the three divergences that
71
- * originally justified this parser were defects in `GeoPoint` and were fixed on 2026-08-05: it no longer guesses axis
72
- * order from the magnitudes, and an out-of-range value is now rejected instead of accepted (`200,-97.74` used to become
73
- * a point). What remains is not a defect and not negotiable. This source writes `latitude,longitude`; `GeoPoint` reads
74
- * GeoJSON `[longitude, latitude]`, so `31.5,-89.5` is a Mississippi row here and a South-Atlantic point there — and
75
- * `GeoPoint.from` maps 0,0 to null, which moves Null Island out of the measured outliers and into the skipped bucket.
76
- * The report below attributes part of its p99/max tail to malformed provided coordinates, so those rows have to stay
77
- * rejected or measured as-is, never rewritten. Strictness is the measurement, not an unfinished migration.
86
+ * Strictness is the measurement rather than an unfinished migration.
78
87
  */
79
- function parseLatLon(raw: string | undefined): { latitude: number; longitude: number } | null {
88
+ function parseLatLon(raw: string | null | undefined): { latitude: number; longitude: number } | null {
80
89
  if (!raw) return null
81
- const [a, b] = raw.split(",").map((x) => Number(x.trim()))
90
+ const [a, b] = TextSpliterator.from(raw, { delimiter: "," }).map(Number).toArray()
82
91
 
83
92
  if (!Number.isFinite(a) || !Number.isFinite(b)) return null
84
93
 
@@ -87,12 +96,13 @@ function parseLatLon(raw: string | undefined): { latitude: number; longitude: nu
87
96
  return { latitude: a!, longitude: b! }
88
97
  }
89
98
 
90
- // The core nearest-rank `percentile` (q in [0,100]) replaces the retired local `quantile(sorted, q)`
91
- // — byte-identical semantics (floor index, clamped); `?? NaN` preserves the empty-sample behavior.
99
+ // The core nearest-rank `percentile` (q in [0,100]) uses a floor index and clamping.
100
+ // `?? NaN` returns NaN when the percentile helper returns null for an empty sample.
92
101
  const quantile = (xs: number[], q: number): number => percentile(xs, q * 100) ?? Number.NaN
93
102
 
94
103
  /**
95
- * Geocoder validation against provided coordinates (#619) — see the module doc. Emits the report to stdout.
104
+ * Geocode each facility's physical address and measure the delta to its provided
105
+ * coordinate, then emit the report to stdout.
96
106
  */
97
107
  export async function geocoderVsProvidedCoords(
98
108
  options: GeocoderVsProvidedCoordsOptions,
@@ -149,7 +159,6 @@ export async function geocoderVsProvidedCoords(
149
159
 
150
160
  geocoder[Symbol.dispose]()
151
161
 
152
- // Overall + per-tier percentiles.
153
162
  const all = results.map((r) => r.deltaM).toSorted((a, b) => a - b)
154
163
  const byTier = new Map<string, number[]>()
155
164