@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
@@ -30,16 +30,15 @@
30
30
  * [--out-md <md>]`
31
31
  */
32
32
 
33
- import { writeFileSync } from "node:fs"
34
-
35
- import { dataRootPath, formatPercent } from "@mailwoman/core/utils"
33
+ import { dataRootPath } from "@mailwoman/core/data-root"
34
+ import { writeLocalFile } from "@mailwoman/core/fs/writers"
35
+ import { formatPercent } from "@mailwoman/core/stats"
36
36
  import { jaccard } from "@mailwoman/match"
37
- import { addressFrequencyKey, streamRows } from "@mailwoman/registry"
38
37
 
39
- import { norm } from "./shared.ts"
38
+ import { colocatedDistinctPairs, scanColocatedProviders, stateOption, type ColocatedProvider } from "#tools/shared"
40
39
 
41
40
  /**
42
- * Similarity at or above which a pair is a near-miss worth inspecting rather than plainly unrelated.
41
+ * Similarity at or above which a pair is a near-miss worth inspecting rather than unrelated.
43
42
  */
44
43
  const WEAK_SIMILARITY_MIN = 0.3
45
44
 
@@ -69,58 +68,6 @@ export interface DedupCeilingOptions {
69
68
  outMd?: string
70
69
  }
71
70
 
72
- /**
73
- * Strip only corporate-form tokens + articles — KEEP domain words (health, medical, center…), which carry the
74
- * distinguishing signal between two co-located providers.
75
- */
76
- const STOP = new Set([
77
- "llc",
78
- "inc",
79
- "incorporated",
80
- "corp",
81
- "corporation",
82
- "co",
83
- "ltd",
84
- "pllc",
85
- "pc",
86
- "pa",
87
- "lp",
88
- "llp",
89
- "the",
90
- "of",
91
- "and",
92
- ])
93
-
94
- function orgTokens(s: string): Set<string> {
95
- return new Set(
96
- s
97
- .toLowerCase()
98
- .replaceAll(/[^a-z0-9 ]/g, " ")
99
- .split(/\s+/)
100
- .filter((t) => t && !STOP.has(t))
101
- )
102
- }
103
-
104
- const normPhone = (p?: string): string => {
105
- const d = (p ?? "").replaceAll(/\D/g, "")
106
-
107
- return d.length >= 10 ? d.slice(-10) : ""
108
- }
109
-
110
- interface Provider {
111
- npi: string
112
- tokens: Set<string>
113
- phone: string
114
- /**
115
- * Authorized official (last + first), lowercased — same official ⇒ almost certainly one org.
116
- */
117
- auth: string
118
- /**
119
- * Primary taxonomy (specialty) code — different specialty ⇒ likely a genuinely different provider.
120
- */
121
- taxonomy: string
122
- }
123
-
124
71
  /**
125
72
  * #625 ceiling measurement — see the module doc. Emits the markdown report to stdout.
126
73
  */
@@ -130,59 +77,14 @@ export async function dedupCeiling(
130
77
  ): Promise<{ markdown: string; pairs: number; collide: number }> {
131
78
  const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
132
79
  const CAP = options.cap ?? 50_000
133
- const STATE = (options.state || "TX").toUpperCase()
80
+ const STATE = stateOption(options)
134
81
  const TAU = options.tau ?? 0.7
135
82
  const OUT_MD = options.outMd || ""
136
83
  const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
137
84
 
138
85
  // --- Stream TX type-2 (org) providers; one primary record per NPI at its practice address. ---
139
86
  report?.(`[A] streaming ${STATE} org providers (cap ${CAP})…`)
140
- const byAddr = new Map<string, Provider[]>()
141
- let kept = 0
142
- let scanned = 0
143
-
144
- for await (const r of streamRows(REGISTRY)) {
145
- scanned++
146
-
147
- if (norm(r["Entity Type Code"]) !== "2") continue
148
-
149
- if (norm(r["Provider Business Practice Location Address State Name"]).toUpperCase() !== STATE) continue
150
- const org = norm(r["Provider Organization Name (Legal Business Name)"])
151
-
152
- if (!org) continue
153
- const line1 = norm(r["Provider First Line Business Practice Location Address"])
154
- const city = norm(r["Provider Business Practice Location Address City Name"])
155
- const zip = norm(r["Provider Business Practice Location Address Postal Code"])
156
-
157
- if (!line1) continue
158
- const addrKey = addressFrequencyKey(`${line1}, ${city}, ${STATE} ${zip}`)
159
-
160
- if (!addrKey) continue
161
- const npi = norm(r["NPI"])
162
-
163
- const auth = `${norm(r["Authorized Official Last Name"])} ${norm(r["Authorized Official First Name"])}`
164
- .toLowerCase()
165
- .trim()
166
-
167
- const p: Provider = {
168
- npi,
169
- tokens: orgTokens(org),
170
- phone: normPhone(r["Provider Business Practice Location Address Telephone Number"]),
171
- auth: auth === "" ? "" : auth,
172
- taxonomy: norm(r["Healthcare Provider Taxonomy Code_1"]),
173
- }
174
-
175
- if (!byAddr.has(addrKey)) {
176
- byAddr.set(addrKey, [])
177
- }
178
-
179
- byAddr.get(addrKey)!.push(p)
180
-
181
- kept++
182
-
183
- if (kept >= CAP) break
184
- }
185
-
87
+ const { byAddr, kept, scanned } = await scanColocatedProviders({ registryPath: REGISTRY, state: STATE, cap: CAP })
186
88
  report?.(` scanned ${scanned} rows → ${kept} ${STATE} org providers at ${byAddr.size} distinct addresses`)
187
89
 
188
90
  // --- Over co-located distinct-NPI pairs: the org-similarity distribution + collision rate. ---
@@ -201,52 +103,40 @@ export async function dedupCeiling(
201
103
 
202
104
  // guard against a pathological mega-address (PO-box farms)
203
105
 
204
- for (const provs of byAddr.values()) {
205
- // distinct NPIs at this address
206
- const distinct = new Map<string, Provider>()
106
+ let lastGroup: readonly ColocatedProvider[] | null = null
207
107
 
208
- for (const p of provs)
209
- if (!distinct.has(p.npi)) {
210
- distinct.set(p.npi, p)
211
- }
108
+ for (const { a, b, group } of colocatedDistinctPairs(byAddr)) {
109
+ if (group !== lastGroup) {
110
+ lastGroup = group
212
111
 
213
- const list = [...distinct.values()]
214
-
215
- if (list.length < 2) continue
216
-
217
- sharedAddresses++
218
- providersAtSharedAddr += list.length
112
+ sharedAddresses++
113
+ providersAtSharedAddr += group.length
114
+ }
219
115
 
220
- for (let i = 0; i < list.length; i++) {
221
- for (let j = i + 1; j < list.length; j++) {
222
- if (pairs >= PAIR_BUDGET) break
116
+ if (pairs >= PAIR_BUDGET) continue
223
117
 
224
- pairs++
225
- const a = list[i]!
226
- const b = list[j]!
227
- const sim = jaccard(a.tokens, b.tokens)
118
+ pairs++
119
+ const sim = jaccard(a.tokens, b.tokens)
228
120
 
229
- if (sim >= TAU) {
230
- collide++
121
+ if (sim >= TAU) {
122
+ collide++
231
123
 
232
- if (a.phone && a.phone === b.phone) {
233
- collideSharePhone++
234
- }
124
+ if (a.phone && a.phone === b.phone) {
125
+ collideSharePhone++
126
+ }
235
127
 
236
- const sameAuth = a.auth !== "" && a.auth === b.auth
237
- const sameTax = a.taxonomy !== "" && a.taxonomy === b.taxonomy
128
+ const sameAuth = a.auth !== "" && a.auth === b.auth
129
+ const sameTax = a.taxonomy !== "" && a.taxonomy === b.taxonomy
238
130
 
239
- if (sameAuth) {
240
- collideSameAuth++
241
- } else if (!sameTax) {
242
- collideDistinct++
243
- }
244
- } else if (sim >= WEAK_SIMILARITY_MIN) {
245
- mid++
246
- } else {
247
- separable++
248
- }
131
+ if (sameAuth) {
132
+ collideSameAuth++
133
+ } else if (!sameTax) {
134
+ collideDistinct++
249
135
  }
136
+ } else if (sim >= WEAK_SIMILARITY_MIN) {
137
+ mid++
138
+ } else {
139
+ separable++
250
140
  }
251
141
  }
252
142
 
@@ -259,7 +149,6 @@ export async function dedupCeiling(
259
149
  // of `mid`). Recall is NOT the binding constraint here (NPPES same-NPI records almost always share
260
150
  // either address or org), so the F1 ceiling tracks the precision ceiling. ---
261
151
  const pct = formatPercent
262
- const collisionRate = pairs > 0 ? collide / pairs : 0
263
152
 
264
153
  const lines: string[] = [
265
154
  `# #625 — dedup ceiling: the irreducible over-merge of co-located providers`,
@@ -339,7 +228,7 @@ export async function dedupCeiling(
339
228
  console.log(md)
340
229
 
341
230
  if (OUT_MD) {
342
- writeFileSync(OUT_MD, md)
231
+ await writeLocalFile(md, OUT_MD)
343
232
  report?.(`[written] ${OUT_MD}`)
344
233
  }
345
234
 
@@ -4,14 +4,14 @@
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
6
  * The injected-geocoder contract for the record-matcher tools. The registry package deliberately
7
- * never imports the heavy runtime (neural parser, WOF resolver, per-state shards) — `mailwoman`
7
+ * never imports the heavy runtime (neural parser, WOF resolver, per-state extracts) — `mailwoman`
8
8
  * depends on `@mailwoman/registry`, so the reverse import would cycle the workspace graph. Instead
9
9
  * each tool takes an {@linkcode EvalGeocoderFactory} the CLI command constructs from
10
10
  * `mailwoman/geocode-core` (see `mailwoman/commands/registry/run.tsx`), mirroring the matcher's own
11
- * `GeocodeAddress` seam philosophy: ingest never pins the runtime, the caller wires it.
11
+ * `GeocodeAddress` interface philosophy: ingest never pins the runtime, the caller wires it.
12
12
  */
13
13
 
14
- import type { ColumnMapping, GeocodeAddress, SourceRecord } from "@mailwoman/registry"
14
+ import type { ColumnMapping, GeocodeAddress, SourceRecord } from "#index"
15
15
 
16
16
  /**
17
17
  * The raw single-address geocode surface (the probe tools) — mirrors `mailwoman/geocode-core`'s wire shape.
@@ -26,21 +26,20 @@ export interface EvalGeocodeResult {
26
26
  }
27
27
 
28
28
  /**
29
- * A constructed geocoder: the matcher's ingest seam, the raw geocode, and the handle release.
29
+ * A constructed geocoder: the matcher's ingest interface, the raw geocode, and the handle release.
30
30
  */
31
- export interface EvalGeocoder {
31
+ export interface EvalGeocoder extends Disposable {
32
32
  /**
33
- * The matcher's ingest seam (parse + geocode → `PostalAddress`), built via `geocodeAddressVia`.
33
+ * The matcher's ingest interface (parse + geocode → `PostalAddress`), built via `geocodeAddressVia`.
34
34
  */
35
- seam: GeocodeAddress
35
+ geocodeAddress: GeocodeAddress
36
36
  /**
37
37
  * Raw single-address geocode — lat/lon + resolution tier.
38
38
  */
39
39
  geocode: (address: string) => Promise<EvalGeocodeResult>
40
40
  /**
41
- * Release the DB handles (shards + WOF lookup).
41
+ * Release the DB handles (extracts + WOF lookup).
42
42
  */
43
- close: () => void
44
43
  }
45
44
 
46
45
  /**
@@ -54,12 +53,12 @@ export interface EvalGeocoderInit {
54
53
  }
55
54
 
56
55
  /**
57
- * Build a geocoder on demand — tools construct late and `close()` as soon as geocoding is done.
56
+ * Build a geocoder on demand — tools construct late and dispose it as soon as geocoding is done.
58
57
  */
59
58
  export type EvalGeocoderFactory = (init?: EvalGeocoderInit) => Promise<EvalGeocoder>
60
59
 
61
60
  /**
62
- * The threaded geocode surface (`mailwoman/geocode-stream` behind the seam) for `nppes-dedup-benchmark
61
+ * The threaded geocode surface (`mailwoman/geocode-stream` behind the interface) for `nppes-dedup-benchmark
63
62
  * --parallel-geocode`. Yields enriched records in completion order.
64
63
  */
65
64
  export type EvalGeocodeStream = (
@@ -4,7 +4,7 @@
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
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 shard covers the address,
7
+ * admin-tier tail to 11143 km (p99 2189 km). Hypothesis: when no street extract covers the address,
8
8
  * the admin cascade resolves the locality by NAME and (when the region/postcode constraint is
9
9
  * weak) picks the population-dominant FOREIGN namesake — Paris→France, Athens→Greece — instead of
10
10
  * the in-state Texas city. This probes a curated set of TX namesake cities, with and without ZIP,
@@ -15,7 +15,8 @@
15
15
 
16
16
  import { haversineKm } from "@mailwoman/spatial"
17
17
 
18
- import type { EvalGeocoderFactory } from "./eval-geocoder.ts"
18
+ import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
19
+ import { inTXBBOX } from "#tools/shared"
19
20
 
20
21
  /**
21
22
  * Options for {@linkcode geocoderNamesakeProbe}.
@@ -41,14 +42,6 @@ const CASES: Array<{ city: string; zip: string; tx: [number, number]; namesake:
41
42
  { city: "Odessa", zip: "79761", tx: [31.85, -102.37], namesake: "Odessa, Ukraine (46.48, 30.72)" },
42
43
  ]
43
44
 
44
- /**
45
- * Texas bounding box (generous).
46
- */
47
- const TX_BBOX = { latMin: 25.8, latMax: 36.6, lonMin: -106.7, lonMax: -93.4 }
48
-
49
- const inTexas = (lat: number, lon: number) =>
50
- lat >= TX_BBOX.latMin && lat <= TX_BBOX.latMax && lon >= TX_BBOX.lonMin && lon <= TX_BBOX.lonMax
51
-
52
45
  /**
53
46
  * Admin-tier wrong-region probe (#619 tail) — see the module doc. Prints one line per variant to stdout.
54
47
  */
@@ -75,7 +68,7 @@ export async function geocoderNamesakeProbe(
75
68
  continue
76
69
  }
77
70
 
78
- const ok = inTexas(g.lat, g.lon)
71
+ const ok = inTXBBOX(g.lat, g.lon)
79
72
  const km = haversineKm(c.tx[0], c.tx[1], g.lat, g.lon)
80
73
 
81
74
  if (!ok) {
@@ -89,7 +82,7 @@ export async function geocoderNamesakeProbe(
89
82
  }
90
83
  }
91
84
 
92
- geocoder.close()
85
+ geocoder[Symbol.dispose]()
93
86
 
94
87
  console.log(`\n ${wrongRegion}/${total} variants resolved OUTSIDE Texas (wrong-region).`)
95
88
 
@@ -20,14 +20,15 @@
20
20
  * [--data-root <dir>] [--out-md docs/articles/evals/resolver-geo/<date>-...md]`
21
21
  */
22
22
 
23
- import { writeFileSync } from "node:fs"
24
-
25
- import { dataRootPath, percentile } from "@mailwoman/core/utils"
23
+ import { dataRootPath } from "@mailwoman/core/data-root"
24
+ import { writeLocalFile } from "@mailwoman/core/fs/writers"
25
+ import { isPresent } from "@mailwoman/core/objects"
26
+ import { percentile } from "@mailwoman/core/stats"
26
27
  import { haversineKm } from "@mailwoman/match"
27
- import { streamRows } from "@mailwoman/registry"
28
28
 
29
- import type { EvalGeocoderFactory } from "./eval-geocoder.ts"
30
- import { norm } from "./shared.ts"
29
+ import { streamRows } from "#index"
30
+ import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
31
+ import { norm } from "#tools/shared"
31
32
 
32
33
  /**
33
34
  * Largest absolute latitude in WGS-84 degrees.
@@ -133,7 +134,7 @@ export async function geocoderVsProvidedCoords(
133
134
  }
134
135
 
135
136
  scanned++
136
- const address = [line, city, state, zip].filter(Boolean).join(", ")
137
+ const address = [line, city, state, zip].filter(isPresent).join(", ")
137
138
  const g = await geocoder.geocode(address)
138
139
 
139
140
  if (g.lat === null || g.lon === null) {
@@ -146,7 +147,7 @@ export async function geocoderVsProvidedCoords(
146
147
  results.push({ deltaM, tier: g.resolution_tier ?? "unknown" })
147
148
  }
148
149
 
149
- geocoder.close()
150
+ geocoder[Symbol.dispose]()
150
151
 
151
152
  // Overall + per-tier percentiles.
152
153
  const all = results.map((r) => r.deltaM).toSorted((a, b) => a - b)
@@ -199,10 +200,10 @@ export async function geocoderVsProvidedCoords(
199
200
  lines.push(
200
201
  `Two regimes. **Street-tier placement is excellent** (the address_point + interpolated rows above) — ` +
201
202
  `rooftop-to-segment medians, the precision that makes geo-first blocking and the distance evidence ` +
202
- `trustworthy. The **admin (centroid) tier** is where no street shard covered the address: accuracy is ` +
203
+ `trustworthy. The **admin (centroid) tier** is where no street extract covered the address: accuracy is ` +
203
204
  `necessarily km-scale, and it carries a catastrophic tail (the p90/p99/max above) from wrong-region admin ` +
204
205
  `resolutions and/or malformed provided coordinates — NOT street-tier error. Those extremes are a signal to ` +
205
- `inspect, and they motivate wider street-shard coverage for rural TX plus an admin-tier sanity bound. The ` +
206
+ `inspect, and they motivate wider street-extract coverage for rural TX plus an admin-tier sanity bound. The ` +
206
207
  `self-reported-vs-independent coordinate discrepancy is itself a data-quality column the reconciliation ` +
207
208
  `surfaces (#621).`
208
209
  )
@@ -214,7 +215,7 @@ export async function geocoderVsProvidedCoords(
214
215
  console.log(md)
215
216
 
216
217
  if (OUT_MD) {
217
- writeFileSync(OUT_MD, md)
218
+ await writeLocalFile(md, OUT_MD)
218
219
  report?.(`\n[written] ${OUT_MD}`)
219
220
  }
220
221
 
@@ -0,0 +1,141 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Gold-set P3 (#625) — sample the HARD slice for adjudication. The programmatic entity truth
7
+ * (`nppes-dedup-benchmark.ts`) collapses only NPPES-FLAGGED subparts (Is-Subpart + parent
8
+ * LBN/TIN); it can't settle the genuinely-ambiguous co-located collisions: distinct NPIs at one
9
+ * address with near-identical names that are NOT flagged subparts of the same parent. Those are
10
+ * where NPI-truth and any programmatic rule disagree — exactly the pairs a frozen adjudicated
11
+ * gold set must cover.
12
+ *
13
+ * This finds them (over the full TX registry, geocode-free — the shared co-location scan
14
+ * `dedup-ceiling.ts` also runs) and writes each as a JSONL row carrying BOTH records' fields (org
15
+ * name, address, authorized official, taxonomy, subpart/parent flags) plus the programmatic
16
+ * verdict, so an adjudicator (human or LLM-as-judge, flagged as such) can label "same real-world
17
+ * entity? yes/no" and we can MEASURE how often the programmatic truth matches judgment.
18
+ *
19
+ * Run: `mailwoman registry gold-set-sample [--cap 200000] [--state TX] [--tau 0.7] [--n 300]
20
+ * [--out-jsonl <path>]`
21
+ */
22
+
23
+ import { dataRootPath } from "@mailwoman/core/data-root"
24
+ import { writeLocalTextFile } from "@mailwoman/core/fs/writers"
25
+ import { jaccard } from "@mailwoman/match"
26
+
27
+ import { colocatedDistinctPairs, scanColocatedProviders, stateOption } from "#tools/shared"
28
+
29
+ /**
30
+ * Options for {@linkcode goldSetSample}.
31
+ */
32
+ export interface GoldSetSampleOptions {
33
+ /**
34
+ * Record-matcher sources directory. Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
35
+ */
36
+ sources?: string
37
+ /**
38
+ * Providers sampled from the registry. Default 200000.
39
+ */
40
+ cap?: number
41
+ /**
42
+ * State filter. Default TX.
43
+ */
44
+ state?: string
45
+ /**
46
+ * Org-name Jaccard collision threshold. Default 0.7.
47
+ */
48
+ tau?: number
49
+ /**
50
+ * Adjudication sample size. Default 300.
51
+ */
52
+ n?: number
53
+ /**
54
+ * Write the sampled pairs here as JSONL (otherwise the first 10 print to stdout).
55
+ */
56
+ outJSONL?: string
57
+ }
58
+
59
+ interface HardPair {
60
+ npiA: string
61
+ npiB: string
62
+ orgA: string
63
+ orgB: string
64
+ address: string
65
+ nameJaccard: number
66
+ sameAuthorizedOfficial: boolean
67
+ sameTaxonomy: boolean
68
+ bothSubpartSameParent: boolean
69
+ programmaticVerdict: "same-entity" | "distinct"
70
+ adjudication: null // ← to be filled: "same-entity" | "distinct"
71
+ }
72
+
73
+ /**
74
+ * Gold-set P3 (#625) — sample the HARD co-located name-collision slice for adjudication.
75
+ */
76
+ export async function goldSetSample(
77
+ options: GoldSetSampleOptions = {},
78
+ report?: (line: string) => void
79
+ ): Promise<{ hardPairs: number; sampled: number }> {
80
+ const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
81
+ const CAP = options.cap ?? 200_000
82
+ const STATE = stateOption(options)
83
+ const TAU = options.tau ?? 0.7
84
+ const N = options.n ?? 300
85
+ const OUT = options.outJSONL || ""
86
+ const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
87
+
88
+ report?.(`[A] streaming ${STATE} org providers (cap ${CAP})…`)
89
+ const { byAddr, kept } = await scanColocatedProviders({ registryPath: REGISTRY, state: STATE, cap: CAP })
90
+ report?.(` ${kept} providers at ${byAddr.size} addresses`)
91
+
92
+ // Hard pairs: co-located, name-similar (≥τ), DISTINCT NPIs that programmatic truth can't confidently
93
+ // collapse (NOT subparts of the same parent). Tag the programmatic verdict so adjudication can grade it.
94
+ const hard: HardPair[] = []
95
+
96
+ for (const { a, b } of colocatedDistinctPairs(byAddr)) {
97
+ const sim = jaccard(a.tokens, b.tokens)
98
+
99
+ if (sim < TAU) continue
100
+ const sameParent = a.subpart && b.subpart && a.parent === b.parent && a.parent !== "|"
101
+
102
+ if (sameParent) continue // programmatic truth already collapses these — not the hard slice
103
+ const sameAuth = a.auth !== "" && a.auth === b.auth
104
+ const sameTax = a.taxonomy !== "" && a.taxonomy === b.taxonomy
105
+
106
+ hard.push({
107
+ npiA: a.npi,
108
+ npiB: b.npi,
109
+ orgA: a.org,
110
+ orgB: b.org,
111
+ address: a.address,
112
+ nameJaccard: Number(sim.toFixed(3)),
113
+ sameAuthorizedOfficial: sameAuth,
114
+ sameTaxonomy: sameTax,
115
+ bothSubpartSameParent: false,
116
+ // Programmatic heuristic verdict (what an entity-level rule WOULD say, beyond the flagged
117
+ // subparts): same authorized official ⇒ likely one org; different official + different
118
+ // specialty ⇒ likely distinct. The whole point is to ADJUDICATE whether this is right.
119
+ programmaticVerdict: sameAuth ? "same-entity" : "distinct",
120
+ adjudication: null,
121
+ })
122
+ }
123
+
124
+ report?.(` ${hard.length} hard co-located name-collision pairs (non-flagged-subpart)`)
125
+
126
+ // Deterministic spread sample of N (stride, not head — avoid file-order bias, the dedup-ceiling lesson).
127
+ const stride = Math.max(1, Math.floor(hard.length / N))
128
+ const sample = hard.filter((_, i) => i % stride === 0).slice(0, N)
129
+ report?.(` sampling ${sample.length} (stride ${stride}) for adjudication`)
130
+
131
+ if (OUT) {
132
+ await writeLocalTextFile(sample.map((p) => JSON.stringify(p)).join("\n") + "\n", OUT)
133
+ report?.(`[written] ${OUT}`)
134
+ } else {
135
+ for (const p of sample.slice(0, 10)) {
136
+ console.log(JSON.stringify(p))
137
+ }
138
+ }
139
+
140
+ return { hardPairs: hard.length, sampled: sample.length }
141
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Registry operator tool exports.
7
+ */
8
+
9
+ export * from "#tools/coverage-reconciliation"
10
+ export * from "#tools/cross-dataset-correlation"
11
+ export * from "#tools/cross-source-threshold-sweep"
12
+ export * from "#tools/dedup-ceiling"
13
+ export * from "#tools/eval-geocoder"
14
+ export * from "#tools/geocoder-namesake-probe"
15
+ export * from "#tools/geocoder-vs-provided-coords"
16
+ export * from "#tools/gold-set-sample"
17
+ export * from "#tools/learned-scorer-clustering-eval"
18
+ export * from "#tools/learned-scorer-crossstate-eval"
19
+ export * from "#tools/learned-scorer-eval"
20
+ export * from "#tools/matcher-scale"
21
+ export * from "#tools/nppes-dedup-benchmark"
22
+ export * from "#tools/train-cross-gbt"
23
+ export * from "#tools/train-gbt"
24
+ export * from "#tools/train-org-cross-gbt"
25
+ export * from "#tools/txhhsc-to-oarow"
26
+ export * from "#tools/viz/cross-dataset-map"
27
+ export * from "#tools/viz/geocode-first-surface"
28
+ export * from "#tools/viz/render-map"
29
+ export * from "#tools/viz/render"
30
+ export * from "#tools/viz/source-provenance-map"
31
+ export * from "#tools/viz/yardstick-figure"