@mailwoman/registry 10.7.0 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (399) hide show
  1. package/README.md +93 -98
  2. package/data/manifests/artifacts.json +32 -0
  3. package/data/manifests/coverage.json +56 -0
  4. package/data/manifests/sources.lock.json +48 -0
  5. package/data/normalized/iata-airports.json +126749 -0
  6. package/data/normalized/iso3166-1.json +2035 -0
  7. package/definitions/namespaces.json +63 -0
  8. package/definitions/sections.json +73 -0
  9. package/docs/data-policy.md +81 -0
  10. package/docs/performance.md +146 -0
  11. package/docs/rgy1.md +144 -0
  12. package/lib/artifacts/country-airport-collision.ts +26 -0
  13. package/lib/artifacts/iata-airport/membership.ts +26 -0
  14. package/lib/artifacts/iata-airport/records.ts +26 -0
  15. package/lib/artifacts/iso3166-1/alpha2-membership.ts +26 -0
  16. package/lib/artifacts/iso3166-1/alpha3-membership.ts +26 -0
  17. package/lib/artifacts/iso3166-1/records.ts +26 -0
  18. package/lib/errors.ts +44 -0
  19. package/lib/iata/airports/records.ts +174 -0
  20. package/lib/iata/airports/validate.ts +49 -0
  21. package/lib/index.ts +25 -15
  22. package/lib/inspect.ts +56 -0
  23. package/lib/iso3166/alpha2.ts +48 -0
  24. package/lib/iso3166/alpha3.ts +51 -0
  25. package/lib/iso3166/records.ts +149 -0
  26. package/lib/iso3166/relations.ts +30 -0
  27. package/lib/key.ts +146 -0
  28. package/lib/normalize.ts +31 -0
  29. package/lib/overlap/country-airport.ts +108 -0
  30. package/lib/rgy1/base64.ts +24 -0
  31. package/lib/rgy1/reader.ts +316 -0
  32. package/lib/rgy1/sections.generated.ts +79 -0
  33. package/lib/rgy1/views.ts +267 -0
  34. package/lib/types.ts +88 -74
  35. package/lib/wasm.ts +285 -0
  36. package/out/artifacts/country-airport-collision.d.ts +15 -0
  37. package/out/artifacts/country-airport-collision.d.ts.map +1 -0
  38. package/out/artifacts/country-airport-collision.js +21 -0
  39. package/out/artifacts/country-airport-collision.js.map +1 -0
  40. package/out/artifacts/iata-airport/membership.d.ts +15 -0
  41. package/out/artifacts/iata-airport/membership.d.ts.map +1 -0
  42. package/out/artifacts/iata-airport/membership.js +21 -0
  43. package/out/artifacts/iata-airport/membership.js.map +1 -0
  44. package/out/artifacts/iata-airport/records.d.ts +15 -0
  45. package/out/artifacts/iata-airport/records.d.ts.map +1 -0
  46. package/out/artifacts/iata-airport/records.js +21 -0
  47. package/out/artifacts/iata-airport/records.js.map +1 -0
  48. package/out/artifacts/iso3166-1/alpha2-membership.d.ts +15 -0
  49. package/out/artifacts/iso3166-1/alpha2-membership.d.ts.map +1 -0
  50. package/out/artifacts/iso3166-1/alpha2-membership.js +21 -0
  51. package/out/artifacts/iso3166-1/alpha2-membership.js.map +1 -0
  52. package/out/artifacts/iso3166-1/alpha3-membership.d.ts +15 -0
  53. package/out/artifacts/iso3166-1/alpha3-membership.d.ts.map +1 -0
  54. package/out/artifacts/iso3166-1/alpha3-membership.js +21 -0
  55. package/out/artifacts/iso3166-1/alpha3-membership.js.map +1 -0
  56. package/out/artifacts/iso3166-1/records.d.ts +15 -0
  57. package/out/artifacts/iso3166-1/records.d.ts.map +1 -0
  58. package/out/artifacts/iso3166-1/records.js +21 -0
  59. package/out/artifacts/iso3166-1/records.js.map +1 -0
  60. package/out/errors.d.ts +38 -0
  61. package/out/errors.d.ts.map +1 -0
  62. package/out/errors.js +35 -0
  63. package/out/errors.js.map +1 -0
  64. package/out/iata/airports/records.d.ts +44 -0
  65. package/out/iata/airports/records.d.ts.map +1 -0
  66. package/out/iata/airports/records.js +137 -0
  67. package/out/iata/airports/records.js.map +1 -0
  68. package/out/iata/airports/validate.d.ts +27 -0
  69. package/out/iata/airports/validate.d.ts.map +1 -0
  70. package/out/iata/airports/validate.js +42 -0
  71. package/out/iata/airports/validate.js.map +1 -0
  72. package/out/index.d.ts +19 -15
  73. package/out/index.d.ts.map +1 -1
  74. package/out/index.js +14 -15
  75. package/out/index.js.map +1 -1
  76. package/out/inspect.d.ts +38 -0
  77. package/out/inspect.d.ts.map +1 -0
  78. package/out/inspect.js +33 -0
  79. package/out/inspect.js.map +1 -0
  80. package/out/iso3166/alpha2.d.ts +24 -0
  81. package/out/iso3166/alpha2.d.ts.map +1 -0
  82. package/out/iso3166/alpha2.js +41 -0
  83. package/out/iso3166/alpha2.js.map +1 -0
  84. package/out/iso3166/alpha3.d.ts +29 -0
  85. package/out/iso3166/alpha3.d.ts.map +1 -0
  86. package/out/iso3166/alpha3.js +44 -0
  87. package/out/iso3166/alpha3.js.map +1 -0
  88. package/out/iso3166/records.d.ts +38 -0
  89. package/out/iso3166/records.d.ts.map +1 -0
  90. package/out/iso3166/records.js +105 -0
  91. package/out/iso3166/records.js.map +1 -0
  92. package/out/iso3166/relations.d.ts +20 -0
  93. package/out/iso3166/relations.d.ts.map +1 -0
  94. package/out/iso3166/relations.js +27 -0
  95. package/out/iso3166/relations.js.map +1 -0
  96. package/out/key.d.ts +68 -0
  97. package/out/key.d.ts.map +1 -0
  98. package/out/key.js +122 -0
  99. package/out/key.js.map +1 -0
  100. package/out/normalize.d.ts +25 -0
  101. package/out/normalize.d.ts.map +1 -0
  102. package/out/normalize.js +21 -0
  103. package/out/normalize.js.map +1 -0
  104. package/out/overlap/country-airport.d.ts +57 -0
  105. package/out/overlap/country-airport.d.ts.map +1 -0
  106. package/out/overlap/country-airport.js +71 -0
  107. package/out/overlap/country-airport.js.map +1 -0
  108. package/out/rgy1/base64.d.ts +15 -0
  109. package/out/rgy1/base64.d.ts.map +1 -0
  110. package/out/rgy1/base64.js +22 -0
  111. package/out/rgy1/base64.js.map +1 -0
  112. package/out/rgy1/reader.d.ts +103 -0
  113. package/out/rgy1/reader.d.ts.map +1 -0
  114. package/out/rgy1/reader.js +230 -0
  115. package/out/rgy1/reader.js.map +1 -0
  116. package/out/rgy1/sections.generated.d.ts +54 -0
  117. package/out/rgy1/sections.generated.d.ts.map +1 -0
  118. package/out/rgy1/sections.generated.js +69 -0
  119. package/out/rgy1/sections.generated.js.map +1 -0
  120. package/out/rgy1/views.d.ts +96 -0
  121. package/out/rgy1/views.d.ts.map +1 -0
  122. package/out/rgy1/views.js +218 -0
  123. package/out/rgy1/views.js.map +1 -0
  124. package/out/sdk/fetch.d.ts +53 -0
  125. package/out/sdk/fetch.d.ts.map +1 -0
  126. package/out/sdk/fetch.js +107 -0
  127. package/out/sdk/fetch.js.map +1 -0
  128. package/out/sdk/fetch.run.d.ts +14 -0
  129. package/out/sdk/fetch.run.d.ts.map +1 -0
  130. package/out/sdk/fetch.run.js +20 -0
  131. package/out/sdk/fetch.run.js.map +1 -0
  132. package/out/sdk/sources.d.ts +111 -0
  133. package/out/sdk/sources.d.ts.map +1 -0
  134. package/out/sdk/sources.js +98 -0
  135. package/out/sdk/sources.js.map +1 -0
  136. package/out/tools/artifact-path.d.ts +10 -0
  137. package/out/tools/artifact-path.d.ts.map +1 -0
  138. package/out/tools/artifact-path.js +12 -0
  139. package/out/tools/artifact-path.js.map +1 -0
  140. package/out/tools/bench.run.d.ts +19 -0
  141. package/out/tools/bench.run.d.ts.map +1 -0
  142. package/out/tools/bench.run.js +204 -0
  143. package/out/tools/bench.run.js.map +1 -0
  144. package/out/tools/build-wasm.run.d.ts +18 -0
  145. package/out/tools/build-wasm.run.d.ts.map +1 -0
  146. package/out/tools/build-wasm.run.js +71 -0
  147. package/out/tools/build-wasm.run.js.map +1 -0
  148. package/out/tools/generate-sections.run.d.ts +13 -0
  149. package/out/tools/generate-sections.run.d.ts.map +1 -0
  150. package/out/tools/generate-sections.run.js +136 -0
  151. package/out/tools/generate-sections.run.js.map +1 -0
  152. package/out/tools/generate.run.d.ts +18 -0
  153. package/out/tools/generate.run.d.ts.map +1 -0
  154. package/out/tools/generate.run.js +118 -0
  155. package/out/tools/generate.run.js.map +1 -0
  156. package/out/tools/normalize.d.ts +155 -0
  157. package/out/tools/normalize.d.ts.map +1 -0
  158. package/out/tools/normalize.js +303 -0
  159. package/out/tools/normalize.js.map +1 -0
  160. package/out/tools/normalize.run.d.ts +14 -0
  161. package/out/tools/normalize.run.d.ts.map +1 -0
  162. package/out/tools/normalize.run.js +29 -0
  163. package/out/tools/normalize.run.js.map +1 -0
  164. package/out/types.d.ts +90 -76
  165. package/out/types.d.ts.map +1 -1
  166. package/out/types.js +20 -4
  167. package/out/types.js.map +1 -1
  168. package/out/wasm.d.ts +98 -0
  169. package/out/wasm.d.ts.map +1 -0
  170. package/out/wasm.js +137 -0
  171. package/out/wasm.js.map +1 -0
  172. package/package.json +49 -28
  173. package/sdk/fetch.run.ts +24 -0
  174. package/sdk/fetch.ts +146 -0
  175. package/sdk/sources.ts +162 -0
  176. package/tools/artifact-path.ts +12 -0
  177. package/tools/bench.run.ts +265 -0
  178. package/tools/build-wasm.run.ts +82 -0
  179. package/tools/generate-sections.run.ts +152 -0
  180. package/tools/generate.run.ts +146 -0
  181. package/tools/normalize.run.ts +36 -0
  182. package/tools/normalize.ts +474 -0
  183. package/wasm/registry-simd.wasm +0 -0
  184. package/wasm/registry.wasm +0 -0
  185. package/lib/address-key.ts +0 -46
  186. package/lib/geocode-handler.ts +0 -37
  187. package/lib/geojson.ts +0 -73
  188. package/lib/ingest.ts +0 -349
  189. package/lib/learned-scorer.ts +0 -134
  190. package/lib/map-html.ts +0 -287
  191. package/lib/models/crosssource-gbt-en-us.ts +0 -43
  192. package/lib/models/dedup-gbt-en-us.ts +0 -47
  193. package/lib/models/org-crosssource-gbt-en-us.ts +0 -43
  194. package/lib/reconcile.ts +0 -239
  195. package/lib/resolve.ts +0 -570
  196. package/out/address-key.d.ts +0 -34
  197. package/out/address-key.d.ts.map +0 -1
  198. package/out/address-key.js +0 -41
  199. package/out/address-key.js.map +0 -1
  200. package/out/geocode-handler.d.ts +0 -20
  201. package/out/geocode-handler.d.ts.map +0 -1
  202. package/out/geocode-handler.js +0 -29
  203. package/out/geocode-handler.js.map +0 -1
  204. package/out/geojson.d.ts +0 -28
  205. package/out/geojson.d.ts.map +0 -1
  206. package/out/geojson.js +0 -63
  207. package/out/geojson.js.map +0 -1
  208. package/out/ingest.d.ts +0 -173
  209. package/out/ingest.d.ts.map +0 -1
  210. package/out/ingest.js +0 -185
  211. package/out/ingest.js.map +0 -1
  212. package/out/learned-scorer.d.ts +0 -61
  213. package/out/learned-scorer.d.ts.map +0 -1
  214. package/out/learned-scorer.js +0 -91
  215. package/out/learned-scorer.js.map +0 -1
  216. package/out/map-html.d.ts +0 -39
  217. package/out/map-html.d.ts.map +0 -1
  218. package/out/map-html.js +0 -220
  219. package/out/map-html.js.map +0 -1
  220. package/out/models/crosssource-gbt-en-us.d.ts +0 -45
  221. package/out/models/crosssource-gbt-en-us.d.ts.map +0 -1
  222. package/out/models/crosssource-gbt-en-us.js +0 -40
  223. package/out/models/crosssource-gbt-en-us.js.map +0 -1
  224. package/out/models/dedup-gbt-en-us.d.ts +0 -44
  225. package/out/models/dedup-gbt-en-us.d.ts.map +0 -1
  226. package/out/models/dedup-gbt-en-us.js +0 -44
  227. package/out/models/dedup-gbt-en-us.js.map +0 -1
  228. package/out/models/org-crosssource-gbt-en-us.d.ts +0 -45
  229. package/out/models/org-crosssource-gbt-en-us.d.ts.map +0 -1
  230. package/out/models/org-crosssource-gbt-en-us.js +0 -40
  231. package/out/models/org-crosssource-gbt-en-us.js.map +0 -1
  232. package/out/reconcile.d.ts +0 -96
  233. package/out/reconcile.d.ts.map +0 -1
  234. package/out/reconcile.js +0 -127
  235. package/out/reconcile.js.map +0 -1
  236. package/out/resolve.d.ts +0 -264
  237. package/out/resolve.d.ts.map +0 -1
  238. package/out/resolve.js +0 -282
  239. package/out/resolve.js.map +0 -1
  240. package/out/tools/coverage-reconciliation.d.ts +0 -67
  241. package/out/tools/coverage-reconciliation.d.ts.map +0 -1
  242. package/out/tools/coverage-reconciliation.js +0 -113
  243. package/out/tools/coverage-reconciliation.js.map +0 -1
  244. package/out/tools/cross/dataset-correlation.d.ts +0 -61
  245. package/out/tools/cross/dataset-correlation.d.ts.map +0 -1
  246. package/out/tools/cross/dataset-correlation.js +0 -244
  247. package/out/tools/cross/dataset-correlation.js.map +0 -1
  248. package/out/tools/cross/source-threshold-sweep.d.ts +0 -60
  249. package/out/tools/cross/source-threshold-sweep.d.ts.map +0 -1
  250. package/out/tools/cross/source-threshold-sweep.js +0 -264
  251. package/out/tools/cross/source-threshold-sweep.js.map +0 -1
  252. package/out/tools/dedup-ceiling.d.ts +0 -62
  253. package/out/tools/dedup-ceiling.d.ts.map +0 -1
  254. package/out/tools/dedup-ceiling.js +0 -171
  255. package/out/tools/dedup-ceiling.js.map +0 -1
  256. package/out/tools/eval-geocoder.d.ts +0 -68
  257. package/out/tools/eval-geocoder.d.ts.map +0 -1
  258. package/out/tools/eval-geocoder.js +0 -13
  259. package/out/tools/eval-geocoder.js.map +0 -1
  260. package/out/tools/geocoder/namesake-probe.d.ts +0 -33
  261. package/out/tools/geocoder/namesake-probe.d.ts.map +0 -1
  262. package/out/tools/geocoder/namesake-probe.js +0 -60
  263. package/out/tools/geocoder/namesake-probe.js.map +0 -1
  264. package/out/tools/geocoder/vs-provided-coords.d.ts +0 -53
  265. package/out/tools/geocoder/vs-provided-coords.d.ts.map +0 -1
  266. package/out/tools/geocoder/vs-provided-coords.js +0 -161
  267. package/out/tools/geocoder/vs-provided-coords.js.map +0 -1
  268. package/out/tools/gold-set-sample.d.ts +0 -67
  269. package/out/tools/gold-set-sample.d.ts.map +0 -1
  270. package/out/tools/gold-set-sample.js +0 -81
  271. package/out/tools/gold-set-sample.js.map +0 -1
  272. package/out/tools/learned/scorer/clustering-eval.d.ts +0 -77
  273. package/out/tools/learned/scorer/clustering-eval.d.ts.map +0 -1
  274. package/out/tools/learned/scorer/clustering-eval.js +0 -207
  275. package/out/tools/learned/scorer/clustering-eval.js.map +0 -1
  276. package/out/tools/learned/scorer/crossstate-eval.d.ts +0 -65
  277. package/out/tools/learned/scorer/crossstate-eval.d.ts.map +0 -1
  278. package/out/tools/learned/scorer/crossstate-eval.js +0 -168
  279. package/out/tools/learned/scorer/crossstate-eval.js.map +0 -1
  280. package/out/tools/learned/scorer/eval.d.ts +0 -64
  281. package/out/tools/learned/scorer/eval.d.ts.map +0 -1
  282. package/out/tools/learned/scorer/eval.js +0 -275
  283. package/out/tools/learned/scorer/eval.js.map +0 -1
  284. package/out/tools/matcher-scale.d.ts +0 -40
  285. package/out/tools/matcher-scale.d.ts.map +0 -1
  286. package/out/tools/matcher-scale.js +0 -111
  287. package/out/tools/matcher-scale.js.map +0 -1
  288. package/out/tools/nppes/dedup-benchmark.d.ts +0 -82
  289. package/out/tools/nppes/dedup-benchmark.d.ts.map +0 -1
  290. package/out/tools/nppes/dedup-benchmark.js +0 -226
  291. package/out/tools/nppes/dedup-benchmark.js.map +0 -1
  292. package/out/tools/nppes/org-name.d.ts +0 -15
  293. package/out/tools/nppes/org-name.d.ts.map +0 -1
  294. package/out/tools/nppes/org-name.js +0 -6
  295. package/out/tools/nppes/org-name.js.map +0 -1
  296. package/out/tools/nppes/overmerge-packet.d.ts +0 -43
  297. package/out/tools/nppes/overmerge-packet.d.ts.map +0 -1
  298. package/out/tools/nppes/overmerge-packet.js +0 -54
  299. package/out/tools/nppes/overmerge-packet.js.map +0 -1
  300. package/out/tools/nppes/report.d.ts +0 -97
  301. package/out/tools/nppes/report.d.ts.map +0 -1
  302. package/out/tools/nppes/report.js +0 -178
  303. package/out/tools/nppes/report.js.map +0 -1
  304. package/out/tools/nppes/sample.d.ts +0 -101
  305. package/out/tools/nppes/sample.d.ts.map +0 -1
  306. package/out/tools/nppes/sample.js +0 -127
  307. package/out/tools/nppes/sample.js.map +0 -1
  308. package/out/tools/nppes/scoring.d.ts +0 -37
  309. package/out/tools/nppes/scoring.d.ts.map +0 -1
  310. package/out/tools/nppes/scoring.js +0 -81
  311. package/out/tools/nppes/scoring.js.map +0 -1
  312. package/out/tools/nppes/settings.d.ts +0 -41
  313. package/out/tools/nppes/settings.d.ts.map +0 -1
  314. package/out/tools/nppes/settings.js +0 -79
  315. package/out/tools/nppes/settings.js.map +0 -1
  316. package/out/tools/nppes/truth-grains.d.ts +0 -63
  317. package/out/tools/nppes/truth-grains.d.ts.map +0 -1
  318. package/out/tools/nppes/truth-grains.js +0 -139
  319. package/out/tools/nppes/truth-grains.js.map +0 -1
  320. package/out/tools/shared.d.ts +0 -325
  321. package/out/tools/shared.d.ts.map +0 -1
  322. package/out/tools/shared.js +0 -453
  323. package/out/tools/shared.js.map +0 -1
  324. package/out/tools/train/cross-gbt.d.ts +0 -89
  325. package/out/tools/train/cross-gbt.d.ts.map +0 -1
  326. package/out/tools/train/cross-gbt.js +0 -132
  327. package/out/tools/train/cross-gbt.js.map +0 -1
  328. package/out/tools/train/gbt.d.ts +0 -85
  329. package/out/tools/train/gbt.d.ts.map +0 -1
  330. package/out/tools/train/gbt.js +0 -155
  331. package/out/tools/train/gbt.js.map +0 -1
  332. package/out/tools/train/org-cross-gbt.d.ts +0 -85
  333. package/out/tools/train/org-cross-gbt.d.ts.map +0 -1
  334. package/out/tools/train/org-cross-gbt.js +0 -122
  335. package/out/tools/train/org-cross-gbt.js.map +0 -1
  336. package/out/tools/txhhsc-to-oarow.d.ts +0 -42
  337. package/out/tools/txhhsc-to-oarow.d.ts.map +0 -1
  338. package/out/tools/txhhsc-to-oarow.js +0 -78
  339. package/out/tools/txhhsc-to-oarow.js.map +0 -1
  340. package/out/tools/viz/browser.d.ts +0 -31
  341. package/out/tools/viz/browser.d.ts.map +0 -1
  342. package/out/tools/viz/browser.js +0 -26
  343. package/out/tools/viz/browser.js.map +0 -1
  344. package/out/tools/viz/cross-dataset-map.d.ts +0 -39
  345. package/out/tools/viz/cross-dataset-map.d.ts.map +0 -1
  346. package/out/tools/viz/cross-dataset-map.js +0 -84
  347. package/out/tools/viz/cross-dataset-map.js.map +0 -1
  348. package/out/tools/viz/geocode-first-surface.d.ts +0 -36
  349. package/out/tools/viz/geocode-first-surface.d.ts.map +0 -1
  350. package/out/tools/viz/geocode-first-surface.js +0 -234
  351. package/out/tools/viz/geocode-first-surface.js.map +0 -1
  352. package/out/tools/viz/render/map.d.ts +0 -42
  353. package/out/tools/viz/render/map.d.ts.map +0 -1
  354. package/out/tools/viz/render/map.js +0 -40
  355. package/out/tools/viz/render/map.js.map +0 -1
  356. package/out/tools/viz/render.d.ts +0 -46
  357. package/out/tools/viz/render.d.ts.map +0 -1
  358. package/out/tools/viz/render.js +0 -49
  359. package/out/tools/viz/render.js.map +0 -1
  360. package/out/tools/viz/source-provenance-map.d.ts +0 -57
  361. package/out/tools/viz/source-provenance-map.d.ts.map +0 -1
  362. package/out/tools/viz/source-provenance-map.js +0 -82
  363. package/out/tools/viz/source-provenance-map.js.map +0 -1
  364. package/out/tools/viz/yardstick-figure.d.ts +0 -22
  365. package/out/tools/viz/yardstick-figure.d.ts.map +0 -1
  366. package/out/tools/viz/yardstick-figure.js +0 -106
  367. package/out/tools/viz/yardstick-figure.js.map +0 -1
  368. package/tools/coverage-reconciliation.ts +0 -192
  369. package/tools/cross/dataset-correlation.ts +0 -380
  370. package/tools/cross/source-threshold-sweep.ts +0 -416
  371. package/tools/dedup-ceiling.ts +0 -225
  372. package/tools/eval-geocoder.ts +0 -77
  373. package/tools/geocoder/namesake-probe.ts +0 -91
  374. package/tools/geocoder/vs-provided-coords.ts +0 -232
  375. package/tools/gold-set-sample.ts +0 -147
  376. package/tools/learned/scorer/clustering-eval.ts +0 -349
  377. package/tools/learned/scorer/crossstate-eval.ts +0 -280
  378. package/tools/learned/scorer/eval.ts +0 -429
  379. package/tools/matcher-scale.ts +0 -185
  380. package/tools/nppes/dedup-benchmark.ts +0 -364
  381. package/tools/nppes/org-name.ts +0 -15
  382. package/tools/nppes/overmerge-packet.ts +0 -98
  383. package/tools/nppes/report.ts +0 -380
  384. package/tools/nppes/sample.ts +0 -250
  385. package/tools/nppes/scoring.ts +0 -115
  386. package/tools/nppes/settings.ts +0 -102
  387. package/tools/nppes/truth-grains.ts +0 -181
  388. package/tools/shared.ts +0 -743
  389. package/tools/train/cross-gbt.ts +0 -214
  390. package/tools/train/gbt.ts +0 -261
  391. package/tools/train/org-cross-gbt.ts +0 -189
  392. package/tools/txhhsc-to-oarow.ts +0 -118
  393. package/tools/viz/browser.ts +0 -41
  394. package/tools/viz/cross-dataset-map.ts +0 -133
  395. package/tools/viz/geocode-first-surface.ts +0 -305
  396. package/tools/viz/render/map.ts +0 -61
  397. package/tools/viz/render.ts +0 -103
  398. package/tools/viz/source-provenance-map.ts +0 -154
  399. package/tools/viz/yardstick-figure.ts +0 -197
@@ -1,380 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
6
-
7
- import type { TermFrequencyTable } from "@mailwoman/match"
8
-
9
- import type { ResolveResult } from "#index"
10
- import { ORG_TAU } from "#tools/nppes/org-name"
11
- import type { Score } from "#tools/nppes/scoring"
12
- import { COLOCATION_KM } from "#tools/nppes/truth-grains"
13
- import { pct } from "#tools/shared"
14
-
15
- const BLOCKING_PARITY_TOLERANCE = 0.015
16
-
17
- /**
18
- * One row of the setting progression, scored at the default threshold.
19
- */
20
- export interface SettingScore {
21
- label: string
22
- score: Score
23
- }
24
-
25
- /**
26
- * One arm of the link-threshold sweep.
27
- */
28
- export interface SweepArm {
29
- /**
30
- * The link threshold, in bits.
31
- */
32
- t: number
33
- res: Pick<ResolveResult, "candidatePairs" | "droppedBlocks">
34
- score: Score
35
- }
36
-
37
- /**
38
- * Inputs consumed by the report.
39
- */
40
- export interface NPPESReportInput {
41
- state: string
42
-
43
- /**
44
- * The number of sampled NPIs.
45
- * This is the true entity count at the NPI grain.
46
- */
47
- keptNpis: number
48
- recordCount: number
49
-
50
- /**
51
- * The number of records whose address was placed.
52
- */
53
- geocoded: number
54
- trainEM: boolean
55
-
56
- /**
57
- * The corpus-wide address-frequency table fed to the progression, of
58
- * which only `total` and `distinct` are reported.
59
- */
60
- addressFrequency: TermFrequencyTable
61
-
62
- /**
63
- * The setting progression from the bare baseline to the full stack.
64
- * The report requires at least four rows.
65
- */
66
- progression: readonly SettingScore[]
67
-
68
- /**
69
- * The zero-config `resolveEntities` score, reported apart because its input-scoped
70
- * frequency table is sparse on a sub-sample.
71
- */
72
- defaultOutOfBox: Score
73
- sweep: readonly SweepArm[]
74
-
75
- /**
76
- * The best-F1 arm.
77
- *
78
- * It must be an element of `sweep` because the table marks it by identity.
79
- */
80
- best: SweepArm
81
- entityCount: number
82
- orgCount: number
83
- orgCoordCount: number
84
- orgH3Count: number
85
- fsNPI: Score
86
- fsEntity: Score
87
- fsOrg: Score
88
- fsOrgCoord: Score
89
- gbtNPI: Score
90
- gbtEntity: Score
91
- gbtOrg: Score
92
- gbtOrgCoord: Score
93
- gbtOrgH3: Score
94
-
95
- /**
96
- * The optional `--candidate` A/B row, or `null` when no candidate was given.
97
- */
98
- candidate: { label: string; npi: Score; entity: Score } | null
99
- h3Res: number
100
-
101
- /**
102
- * The number of sampled NPIs whose primary practice address was placed.
103
- * This bounds what the coordinate grain can act on.
104
- */
105
- geocodedNpis: number
106
- }
107
-
108
- /**
109
- * Render the run's markdown report.
110
- */
111
- export function renderNPPESDedupReport(input: NPPESReportInput): string {
112
- const {
113
- state: STATE,
114
- keptNpis,
115
- recordCount: N,
116
- geocoded: geo,
117
- trainEM: TRAIN_EM,
118
- addressFrequency,
119
- progression,
120
- defaultOutOfBox,
121
- sweep,
122
- best,
123
- entityCount,
124
- orgCount,
125
- orgCoordCount,
126
- orgH3Count,
127
- fsNPI,
128
- fsEntity,
129
- fsOrg,
130
- fsOrgCoord,
131
- gbtNPI,
132
- gbtEntity,
133
- gbtOrg,
134
- gbtOrgCoord,
135
- gbtOrgH3,
136
- candidate: cand,
137
- h3Res: H3_RES,
138
- geocodedNpis,
139
- } = input
140
-
141
- const baseline = progression[0]!
142
-
143
- const fullStack = progression.at(-1)!
144
- const base = sweep[0]!
145
-
146
- const signed = (x: number) => `${x >= 0 ? "+" : ""}${x.toFixed(1)}pp`
147
-
148
- const lines: string[] = [
149
- `# NPPES NPI dedup benchmark (#617)`,
150
- "",
151
- `_Generated by \`mailwoman registry scorer-eval nppes-benchmark\`. Sample: ${keptNpis} ${STATE} NPIs with ≥1 ` +
152
- `alternate name → ${N} records (${(N / keptNpis).toFixed(1)}/NPI) from real registry + other-names + ` +
153
- `mailing-vs-practice variation. Matcher run BLIND to the NPI${TRAIN_EM ? ", EM-trained (label-free)" : ""}; ` +
154
- `geocoded ${pct(geo / N)}% of addresses. The NPI is held-out ground truth._`,
155
- "",
156
- `**Headline — org-name truth (the honest grain):** the shipped ` +
157
- `matcher resolves these records at **F1 ${pct(gbtOrg.f1)}%** against org-name entity-truth — not the NPI-level ` +
158
- `${pct(gbtNPI.f1)}%. It mostly measures NPI over-segmentation (one organization holds many subpart NPIs. Therefore, ` +
159
- `correct co-located merges are scored as errors). Same clusters, three rulers: ` +
160
- `**NPI ${pct(gbtNPI.f1)}% → site ${pct(gbtEntity.f1)}% → org-name ${pct(gbtOrg.f1)}%** ` +
161
- `(${keptNpis} NPI → ${entityCount} site → ${orgCount} org-name classes); the climb is the yardstick getting honest, ` +
162
- `not the model changing — gold-set validated (120/120 hard pairs = same org). Details in "Three truth grains" below.`,
163
- "",
164
- `## The comparison-model settings (each toggled on, at the default threshold)`,
165
- "",
166
- `| model | precision | recall | F1 | ΔF1 | ARI | over-merged |`,
167
- `|---|---:|---:|---:|---:|---:|---:|`,
168
- ]
169
-
170
- progression.forEach((p, i) => {
171
- const delta = i === 0 ? "—" : signed(100 * (p.score.f1 - progression[i - 1]!.score.f1))
172
- const bold = i === progression.length - 1
173
- const w = (s: string) => (bold ? `**${s}**` : s)
174
-
175
- lines.push(
176
- `| ${w(p.label)} | ${w(pct(p.score.precision) + "%")} | ${w(pct(p.score.recall) + "%")} | ${w(pct(p.score.f1) + "%")} | ${delta} | ${w(p.score.ari.toFixed(3))} | ${w(String(p.score.overMergedClusters))} |`
177
- )
178
- })
179
-
180
- lines.push("")
181
-
182
- lines.push(
183
- `Inverse-frequency weighting uses the corpus-wide table (${addressFrequency.distinct.toLocaleString()} distinct addresses ` +
184
- `over ${addressFrequency.total.toLocaleString()} providers) to down-weight a crowded shared address. One spatial signal (A1) that replaces the redundant ` +
185
- `address-key + distance comparisons removes the double-count that let a shared address ` +
186
- `over-vote a disagreeing name. The address-frequency + A1 baseline is F1 ${pct(progression[2]!.score.f1)}% at the ` +
187
- `default threshold; the **authorized-official discriminator** is roughly neutral there (${signed(100 * (progression[3]!.score.f1 - progression[2]!.score.f1))}) ` +
188
- `but enables a higher cutoff — it holds recall where the baseline without it collapses, reaching **${pct(best.score.f1)}%** at ` +
189
- `threshold ${best.t} (below), the first config past the baseline (#625).`
190
- )
191
-
192
- lines.push("")
193
-
194
- lines.push(
195
- `**Out-of-the-box (zero-config \`resolveEntities(records)\`, settings default-on #86):** F1 ` +
196
- `**${pct(defaultOutOfBox.f1)}%** on this sample — essentially the baseline. The default auto-computes the ` +
197
- `address-frequency table over the INPUT records, and this benchmark deliberately sub-samples ${N} records, so ` +
198
- `that table is too sparse to carry the inverse-frequency signal (a corpus statistic you can't synthesize from a ` +
199
- `sample). It's **not a regression**, because it meets the baseline without adding over-merges — it's the honest floor when the input isn't ` +
200
- `corpus-scale. Fed the corpus-wide table (the \`+ inverse-address-frequency\` row above, what the CLI builds from ` +
201
- `the full source files) the SAME default reaches the **${pct(progression[2]!.score.f1)}%** baseline. On a full-dataset ` +
202
- `dedup the input IS the corpus, so zero-config reaches the baseline on its own.`
203
- )
204
-
205
- lines.push("")
206
- lines.push(`## With all settings on, across the link threshold (the secondary setting)`)
207
- lines.push("")
208
- lines.push(`| link threshold (bits) | precision | recall | F1 | ARI | clusters | over-merged |`)
209
- lines.push(`|---:|---:|---:|---:|---:|---:|---:|`)
210
-
211
- for (const s of sweep) {
212
- const star = s === best ? " ⭐" : ""
213
-
214
- lines.push(
215
- `| ${s.t}${s.t === 0 ? " (default)" : ""} | ${pct(s.score.precision)}% | ${pct(s.score.recall)}% | **${pct(s.score.f1)}%**${star} | ${s.score.ari.toFixed(3)} | ${s.score.clusters} | ${s.score.overMergedClusters} |`
216
- )
217
- }
218
-
219
- lines.push("")
220
-
221
- lines.push(
222
- best.t === 0
223
- ? `Best F1 is at the **default threshold** (${pct(base.score.f1)}%): raising it only trades recall away faster ` +
224
- `than it provides precision. So the threshold knob alone can't separate co-located distinct providers — the ` +
225
- `over-merge is structural, in the comparison model, not the cutoff.`
226
- : `Best F1 **${pct(best.score.f1)}%** (ARI ${best.score.ari.toFixed(3)}) at threshold ${best.t}, vs **${pct(base.score.f1)}%** at the ` +
227
- `default — the threshold knob moves it ${(100 * (best.score.f1 - base.score.f1)).toFixed(0)}pp. Higher thresholds trade recall for precision.`
228
- )
229
-
230
- lines.push("")
231
- lines.push(`## Shape + where the errors are (at the default threshold)`)
232
- lines.push("")
233
- lines.push(`- records: ${N} · true entities (NPIs): ${keptNpis} · recovered clusters: ${base.score.clusters}`)
234
-
235
- lines.push(
236
- `- candidate pairs blocked: ${base.res.candidatePairs}${base.res.droppedBlocks.length ? ` · oversized blocks skipped: ${base.res.droppedBlocks.length}` : ""}`
237
- )
238
-
239
- lines.push(
240
- `- **Over-merge (precision):** ${base.score.overMergedClusters} clusters fuse ≥2 distinct NPIs (largest fuses ` +
241
- `${base.score.maxNpisFused}, ${base.score.recordsInOverMerged} records) — **co-located providers sharing a clinic / ` +
242
- `billing address**, linked by address agreement despite different names.`
243
- )
244
-
245
- lines.push(
246
- `- **Under-merge (recall):** ${base.score.splitNpis}/${keptNpis} NPIs split across >1 cluster — records at distant ` +
247
- `addresses (mailing vs practice) or with strong name drift the score didn't bridge.`
248
- )
249
-
250
- lines.push("")
251
- lines.push(`## Three truth grains — NPI → site → org-name (the over-segmentation correction)`)
252
- lines.push("")
253
-
254
- lines.push(
255
- `NPI-as-truth OVER-SEGMENTS: one org holds many NPIs, so the matcher's correct co-located merges are scored as ` +
256
- `errors. Three yardsticks, same clusters: **NPI** (one entity per registration), **site** (subpart-flagged ` +
257
- `collapse + split an NPI's distinct addresses), and **org-name** — the gold-set-validated truth: same NPI ⇒ ` +
258
- `same entity (recall preserved) PLUS collapse co-located NPIs whose primary org names match (Jaccard ≥ ${ORG_TAU}), ` +
259
- `with NO reliance on the subpart flag (the gold set showed it misses 37%). The same ${N} records carry ` +
260
- `**${keptNpis} NPI** → **${entityCount} site** → **${orgCount} org-name** classes. The org-name number is the ` +
261
- `honest one: it stops charging the matcher for the same-org merges the gold set proved are correct.`
262
- )
263
-
264
- lines.push("")
265
- lines.push(`| config | truth | precision | recall | F1 | ΔF1 vs NPI | ARI | over-merged |`)
266
- lines.push(`|---|---|---:|---:|---:|---:|---:|---:|`)
267
-
268
- const dualRow = (label: string, truth: string, s: Score, delta?: number) =>
269
- lines.push(
270
- `| ${label} | ${truth} | ${pct(s.precision)}% | ${pct(s.recall)}% | **${pct(s.f1)}%** | ${delta === undefined ? "—" : signed(100 * delta)} | ${s.ari.toFixed(3)} | ${s.overMergedClusters} |`
271
- )
272
-
273
- dualRow("FS full stack", "NPI", fsNPI)
274
- dualRow("FS full stack", "site", fsEntity, fsEntity.f1 - fsNPI.f1)
275
- dualRow("FS full stack", "**org-name**", fsOrg, fsOrg.f1 - fsNPI.f1)
276
- dualRow("FS full stack", "org-name (coord)", fsOrgCoord, fsOrgCoord.f1 - fsNPI.f1)
277
- dualRow("GBT (shipped default)", "NPI", gbtNPI)
278
- dualRow("GBT (shipped default)", "site", gbtEntity, gbtEntity.f1 - gbtNPI.f1)
279
- dualRow("GBT (shipped default)", "**org-name**", gbtOrg, gbtOrg.f1 - gbtNPI.f1)
280
- dualRow("GBT (shipped default)", "**org-name (coord)**", gbtOrgCoord, gbtOrgCoord.f1 - gbtNPI.f1)
281
- dualRow("GBT (shipped default)", `org-name (H3 res ${H3_RES})`, gbtOrgH3, gbtOrgH3.f1 - gbtNPI.f1)
282
-
283
- if (cand) {
284
- dualRow(cand.label, "NPI", cand.npi)
285
- dualRow(cand.label, "**entity**", cand.entity, cand.entity.f1 - cand.npi.f1)
286
- }
287
-
288
- lines.push("")
289
-
290
- lines.push(
291
- `The F1 **climbs as the yardstick gets honest**: GBT **${pct(gbtNPI.f1)}% (NPI) → ${pct(gbtEntity.f1)}% (site) → ` +
292
- `${pct(gbtOrg.f1)}% (org-name)**, the over-merge collapsing (${gbtNPI.overMergedClusters} → ${gbtOrg.overMergedClusters}) ` +
293
- `and precision rising (${pct(gbtNPI.precision)}% → ${pct(gbtOrg.precision)}%). The clusters are IDENTICAL across the three ` +
294
- `columns — the climb is purely the ruler ceasing to charge the matcher for the correct same-org merges the gold set proved ` +
295
- `(\`2026-06-16-dedup-gold-set-tx120.md\`: 120/120 same org, 0 genuine over-merges).`
296
- )
297
-
298
- lines.push("")
299
-
300
- lines.push(
301
- `**Tier 2D — tightening the org-name ruler with the geocode coordinate.** The org-name truth above blocks by the address ` +
302
- `STRING (\`addressFrequencyKey\`), so two records at one building whose text differs — \`1504 Taub LOOP\` vs ` +
303
- `\`1504 Taub LP STE 100\` — key apart and the merge is still charged as an error. Block by the GEOCODED BUILDING instead ` +
304
- `(union co-located NPIs within ${COLOCATION_KM * 1000} m whose org names agree, same Jaccard check) and the truth tightens ` +
305
- `further: GBT **org-name ${pct(gbtOrg.f1)}% → org-name-coord ${pct(gbtOrgCoord.f1)}%** ` +
306
- `(${signed(100 * (gbtOrgCoord.f1 - gbtOrg.f1))}), ${orgCount} → ${orgCoordCount} classes, over ${geocodedNpis}/${keptNpis} ` +
307
- `geocoded NPIs. The string org-name F1 is a conservative LOWER bound; the coordinate one is tighter (the Jaccard check ` +
308
- `still blocks distinct co-located orgs). Both are honest — the coordinate is the geocode-first key.`
309
- )
310
-
311
- lines.push("")
312
-
313
- lines.push(
314
- `**H3-cell robustness check (#109).** Re-keying the same building-grain co-location on an H3 cell ` +
315
- `(res ${H3_RES}) instead of the 50 m haversine radius — the deterministic, O(n) "geocode-first cell" the issue ` +
316
- `suggested — gives GBT **org-name-h3 ${pct(gbtOrgH3.f1)}%** (${orgH3Count} classes), vs the haversine ` +
317
- `${pct(gbtOrgCoord.f1)}% (${orgCoordCount}). ${
318
- Math.abs(gbtOrgH3.f1 - gbtOrgCoord.f1) < BLOCKING_PARITY_TOLERANCE
319
- ? "Within noise of the haversine grain — the ~" +
320
- pct(gbtOrgCoord.f1) +
321
- "% coord-grain F1 is robust to the co-location method, not an artifact of the 50 m threshold."
322
- : "The two co-location methods differ by " +
323
- signed(100 * (gbtOrgH3.f1 - gbtOrgCoord.f1)) +
324
- " — the cell-vs-radius boundary handling shifts the count (a hard H3 boundary can split a same-building pair into adjacent cells)."
325
- }`
326
- )
327
-
328
- lines.push("")
329
-
330
- lines.push(
331
- `**Takeaways:** (1) The dedup model's REAL quality is the **org-name F1 ~${pct(gbtOrg.f1)}%**, not the NPI-level ` +
332
- `${pct(gbtNPI.f1)}% — the difference was NPI over-segmentation, not model error. (2) The #625 setting was the YARDSTICK, ` +
333
- `not the scorer: the corroboration-feature experiment (reverted) couldn't move precision because the over-merge was ` +
334
- `mostly correct. (3) The remaining org-name over-merge (${gbtOrg.overMergedClusters} clusters) is the genuine frontier — ` +
335
- `small, approaching the ceiling's ~1.6% irreducible (\`2026-06-16-dedup-ceiling.md\`). (4) Trust the large eval: a 50-NPI ` +
336
- `smoke misled on the site delta (+5–7pp vs this run's ±2pp).`
337
- )
338
-
339
- lines.push("")
340
-
341
- lines.push(
342
- `Caveats: the programmatic site-truth is CONSERVATIVE (collapses only NPPES-flagged subparts, so unflagged same-org pairs still ` +
343
- `read as over-merge), so it understates the subpart correction. A hand-adjudicated gold set on the ambiguous co-located + ` +
344
- `two-site stratum is the next refinement (#625).`
345
- )
346
-
347
- lines.push("")
348
- lines.push(`## Reading`)
349
- lines.push("")
350
-
351
- lines.push(
352
- `The geocode-first **foundation works**: **${pct(geo / N)}%** of addresses placed, blocking + clustering clean — the ` +
353
- `geocoding (the Pelias/Nominatim-can't-do-this part) is not the bottleneck. The comparison-model settings reach the ` +
354
- `address-frequency + A1 baseline at F1 **${pct(progression[2]!.score.f1)}%** (${signed(100 * (progression[2]!.score.f1 - baseline.score.f1))} over baseline): ` +
355
- `inverse-frequency weighting restores full weight to a *rare* shared address (stitching a provider's name-drifted ` +
356
- `records together — mostly recall) while down-weighting a *crowded* one, and the collapsed spatial signal (A1) drops ` +
357
- `the address+distance double-count. What remains is **precision / over-merge** — ${fullStack.score.overMergedClusters} ` +
358
- `clusters still fuse distinct co-located providers, because even one down-weighted spatial agreement can outvote a ` +
359
- `disagreeing name. The setting search (#625) — two negatives, then the first positive: a name/org/phone ` +
360
- `**corroboration check** (A2/A3) — phone is an unreliable secondary identifier on NPPES (shared institutional ` +
361
- `switchboard lines), so it over-links and falsely corroborates co-phone distinct providers; and **average-linkage ` +
362
- `clustering** (A4) — the over-merged clusters are joined by STRONG shared-address edges, not weak bridges, so ` +
363
- `average-linkage can't split them and only trades away name-drift recall. The over-merge is a **scoring** problem ` +
364
- `this data can't resolve, not a clustering-topology one. The **authorized-official discriminator** is the first setting to beat the baseline — a reliable secondary identifier holds recall so a higher threshold separates the co-located providers; a still-more-distinctive identifier ` +
365
- `(taxonomy / license) or a learned scorer over the FS feature vector (#603) goes further. Config ` +
366
- `dominates the model (the pre-registered finding) — tracked as #625 / the selective-model work (#602 / #603).`
367
- )
368
-
369
- lines.push("")
370
-
371
- lines.push(
372
- `NPI-as-truth is **conservative**: a cluster fusing two NPIs is a candidate "same entity, two NPIs" surfaced for ` +
373
- `review, not an adjudicated error. An NPI split across genuinely-distant addresses is geo-first behaving correctly, ` +
374
- `counted here as a recall miss. We resolve and report; interpretation is the consumer's.`
375
- )
376
-
377
- lines.push("")
378
-
379
- return lines.join("\n")
380
- }
@@ -1,250 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * The NPPES benchmark's input sample: the variation-rich multi-record set per NPI, plus the
7
- * corpus-wide address-frequency table built in the same pass. One registry pass serves any number
8
- * of states, so the cross-state eval samples two at once.
9
- */
10
-
11
- import { isPresent } from "@mailwoman/core/objects"
12
- import type { TermFrequencyTable } from "@mailwoman/match"
13
-
14
- import { addressFrequencyKey, streamRows } from "#index"
15
- import type { NPIPrimary } from "#tools/nppes/org-name"
16
- import { orgTokens, addr, MIN_GROUP_SIZE, norm, NPPES_COLUMNS as C } from "#tools/shared"
17
-
18
- /**
19
- * One synthetic input row for the matcher.
20
- *
21
- * `npi` is the hidden NPI-level truth.
22
- * `entityID` is the site-level entity-level truth (subpart-collapsed).
23
- */
24
- export interface MessyRow extends Record<string, string> {
25
- npi: string
26
- name: string
27
- org: string
28
- address: string
29
- auth: string
30
- /**
31
- * Whitespace-joined taxonomy-code set, up to 15 slots, used as the code-set discriminator.
32
- */
33
- taxonomy: string
34
- entityID: string
35
- }
36
-
37
- /**
38
- * One state's share of the sample pass.
39
- */
40
- export interface NPPESStateSample {
41
- rows: MessyRow[]
42
- /**
43
- * The sampled NPIs.
44
- * Their count is the true-entity count at the NPI grain.
45
- */
46
- keptNpis: Set<string>
47
- /**
48
- * Per-NPI primary org name + practice address key, the basis for the org-name entity truths.
49
- */
50
- npiPrimary: Map<string, NPIPrimary>
51
- }
52
-
53
- /**
54
- * What the single-state sample pass yields.
55
- */
56
- export interface NPPESSample extends NPPESStateSample {
57
- /**
58
- * Corpus-wide address-frequency table, the inverse-frequency signal.
59
- *
60
- * Counted over every practice address in the registry rather than only the sample,
61
- * so the sharing structure is a corpus statistic rather than a sampling artifact.
62
- */
63
- addressFrequency: TermFrequencyTable
64
- }
65
-
66
- /**
67
- * Where the sample comes from and how much of it to take.
68
- */
69
- export interface NPPESSampleOptions {
70
- registryPath: string
71
- otherNamesPath: string
72
- /**
73
- * Already upper-cased.
74
- * Compared against the practice-location state column.
75
- */
76
- state: string
77
- maxNpis: number
78
- }
79
-
80
- /**
81
- * The multi-state shape of {@linkcode NPPESSampleOptions}, where one registry
82
- * pass fills every state's bucket.
83
- */
84
- export interface NPPESMultiSampleOptions {
85
- registryPath: string
86
- otherNamesPath: string
87
- /**
88
- * Already upper-cased.
89
- * Compared against the practice-location state column.
90
- */
91
- states: readonly string[]
92
- maxNpisPerState: number
93
- }
94
-
95
- /**
96
- * Build the benchmark's input records from the real registry, one bucket per requested state.
97
- *
98
- * Two passes read the two files.
99
- * The second pass cannot break early because the address-frequency table needs
100
- * every registry row even after the sample is full.
101
- *
102
- * The per-bucket `keptNpis.size < maxNpisPerState` test bounds only the sample branch.
103
- */
104
- export async function buildNPPESStateSamples(
105
- options: NPPESMultiSampleOptions,
106
- report?: (line: string) => void
107
- ): Promise<{ byState: Map<string, NPPESStateSample>; addressFrequency: TermFrequencyTable }> {
108
- const { registryPath, otherNamesPath, states, maxNpisPerState } = options
109
-
110
- report?.("[A] streaming other-names…")
111
- const altNames = new Map<string, string[]>()
112
-
113
- for await (const r of streamRows(otherNamesPath)) {
114
- const npi = norm(r[C.npi])
115
- const alt = norm(r[C.otherOrg])
116
-
117
- if (!npi || !alt) continue
118
- const list = altNames.get(npi) ?? []
119
-
120
- if (list.length < MIN_GROUP_SIZE) {
121
- list.push(alt)
122
- }
123
-
124
- // cap fan-out per NPI
125
- altNames.set(npi, list)
126
- }
127
-
128
- report?.(` ${altNames.size} NPIs with ≥1 alternate name`)
129
-
130
- // One full registry pass builds the global address-frequency table and collects every state's sample.
131
- // Each row contributes to the corpus-wide sharing structure, independent of the state sample.
132
- report?.(`[B] full registry pass: address-frequency table + ${maxNpisPerState} × ${states.join("/")} sample…`)
133
-
134
- const byState = new Map<string, NPPESStateSample>(
135
- states.map((state) => [state, { rows: [], keptNpis: new Set<string>(), npiPrimary: new Map<string, NPIPrimary>() }])
136
- )
137
-
138
- const addrCounts = new Map<string, number>()
139
- let addrTotal = 0
140
- let scanned = 0
141
- let keptTotal = 0
142
-
143
- for await (const r of streamRows(registryPath)) {
144
- if (++scanned % 1_000_000 === 0) {
145
- report?.(` scanned ${scanned / 1e6}M rows, kept ${keptTotal}`)
146
- }
147
-
148
- const practice = addr(r[C.pAddr]!, r[C.pCity]!, r[C.pState]!, r[C.pZip]!)
149
-
150
- if (practice) {
151
- const k = addressFrequencyKey(practice)
152
- addrCounts.set(k, (addrCounts.get(k) ?? 0) + 1)
153
-
154
- addrTotal++
155
- }
156
-
157
- // No early break here, since the table needs the full pass.
158
- const npi = norm(r[C.npi])
159
- const bucket = byState.get(norm(r[C.pState]).toUpperCase())
160
-
161
- if (
162
- bucket &&
163
- bucket.keptNpis.size < maxNpisPerState &&
164
- npi &&
165
- !bucket.keptNpis.has(npi) &&
166
- altNames.has(npi) &&
167
- practice
168
- ) {
169
- const isOrg = norm(r[C.entityType]) === "2"
170
- const primaryName = isOrg ? norm(r[C.orgLegal]) : `${norm(r[C.first])} ${norm(r[C.last])}`.trim()
171
-
172
- if (primaryName) {
173
- const org = isOrg ? norm(r[C.orgLegal]) : ""
174
- const auth = `${norm(r[C.authFirst])} ${norm(r[C.authLast])}`.trim()
175
-
176
- // The taxonomy-code set (up to 15 slots) is whitespace-joined and identical
177
- // across the NPI's records by construction, so it never splits one entity.
178
- // It only separates co-located distinct providers whose sets are disjoint.
179
- const taxonomy = C.taxonomy
180
- .map((col) => norm(r[col]))
181
- .filter(isPresent)
182
- .join(" ")
183
-
184
- // Entity-level (site) truth is the same org and the same physical address.
185
- // Subparts (NPPES "Is Organization Subpart" plus parent LBN/TIN) collapse to their parent,
186
- // so the matcher is not charged for correctly fusing one org's subpart-NPIs at a site.
187
- // An NPI's mailing and practice records stay distinct sites.
188
- // `orgKey` is the parent identity for a subpart, else the NPI,
189
- // so independent orgs sharing an address stay distinct.
190
- const isSubpart = norm(r[C.isSubpart]).toUpperCase() === "Y"
191
- const parentKey = `${norm(r[C.parentLBN])}|${norm(r[C.parentTIN])}`.toLowerCase()
192
- const orgKey = isSubpart && parentKey !== "|" ? `p:${parentKey}` : `n:${npi}`
193
- const eid = (a: string) => `${addressFrequencyKey(a)}|${orgKey}`
194
-
195
- if (org) {
196
- bucket.npiPrimary.set(npi, { tokens: orgTokens(org), addrKey: addressFrequencyKey(practice) })
197
- }
198
-
199
- bucket.keptNpis.add(npi)
200
-
201
- keptTotal++
202
- bucket.rows.push({ npi, name: primaryName, org, address: practice, auth, taxonomy, entityID: eid(practice) })
203
-
204
- for (const alt of altNames.get(npi)!) {
205
- bucket.rows.push({ npi, name: alt, org: alt, address: practice, auth, taxonomy, entityID: eid(practice) })
206
- }
207
-
208
- const mailing = addr(r[C.mAddr]!, r[C.mCity]!, r[C.mState]!, r[C.mZip]!)
209
-
210
- if (mailing && mailing !== practice) {
211
- bucket.rows.push({ npi, name: primaryName, org, address: mailing, auth, taxonomy, entityID: eid(mailing) })
212
- }
213
- }
214
- }
215
- }
216
-
217
- const addressFrequency: TermFrequencyTable = {
218
- total: addrTotal,
219
- distinct: addrCounts.size,
220
- frequency: (v: string) => (v ? (addrCounts.get(addressFrequencyKey(v)) ?? 0) / addrTotal : 0),
221
- }
222
-
223
- for (const [state, bucket] of byState) {
224
- report?.(` ${state}: ${bucket.keptNpis.size} NPIs → ${bucket.rows.length} records`)
225
- }
226
-
227
- report?.(` address table: ${addrCounts.size} distinct over ${addrTotal} rows`)
228
-
229
- return { byState, addressFrequency }
230
- }
231
-
232
- /**
233
- * Build one state's benchmark input records using {@linkcode buildNPPESStateSamples} with a single bucket.
234
- */
235
- export async function buildNPPESSample(
236
- options: NPPESSampleOptions,
237
- report?: (line: string) => void
238
- ): Promise<NPPESSample> {
239
- const { byState, addressFrequency } = await buildNPPESStateSamples(
240
- {
241
- registryPath: options.registryPath,
242
- otherNamesPath: options.otherNamesPath,
243
- states: [options.state],
244
- maxNpisPerState: options.maxNpis,
245
- },
246
- report
247
- )
248
-
249
- return { ...byState.get(options.state)!, addressFrequency }
250
- }