@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,214 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * Train the cross-source link scorer. The dedup GBT is trained on within-NPPES labels, so its
7
- * strongest feature (`spatial-exact × name-disagree`) rejects the prototypical cross-source pair,
8
- * the same provider under different operational text across registries.
9
- * CMS Open Payments joins NPPES by NPI. That join provides ground-truth positive pairs labeled by a key the matcher never sees.
10
- *
11
- * The pipeline assembles NPPES and Open Payments TX records for the same NPI population, then the
12
- * shared `trainCrossSourceModel` geocodes through the standard ingest and blocks the union. It keeps only
13
- * cross-source candidate pairs. It trains the shipped model into
14
- * `registry/models/crosssource-gbt-en-us.ts`.
15
- *
16
- * Sources (both public domain, `.notes/data-sources.md`):
17
- *
18
- * - `nppes_npi-registry_*.tsv`: the practice-location and primary-name records.
19
- * - `openpayments_covered-recipient-profile_*.csv`: the OP profile supplement (NPI, profile
20
- * first/last, profile practice address).
21
- *
22
- * Run: `mailwoman registry train-scorer cross-gbt [--state TX] [--npis 2000]
23
- * [--precision-bar 0.95] [--wof <admin.db>] [--data-root <dir>]
24
- * [--out registry/models/crosssource-gbt-en-us.ts]`
25
- */
26
-
27
- import { dataRootPath } from "@mailwoman/core/data-root"
28
- import { isoDate } from "@mailwoman/core/utils"
29
- import { resolvePath, type PathBuilderLike } from "path-ts"
30
-
31
- import { addressFrequencyKey, streamRows } from "#index"
32
- import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
33
- import { addr, norm, NPPES_COLUMNS as N, stateOption, trainCrossSourceModel, type CrossSourceRow } from "#tools/shared"
34
-
35
- /**
36
- * Options for {@linkcode trainCrossSourceGBT}.
37
- */
38
- export interface TrainCrossSourceGBTOptions {
39
- /**
40
- * The injected geocoder factory.
41
- *
42
- * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
43
- */
44
- createGeocoder: EvalGeocoderFactory
45
- /**
46
- * Record-matcher sources directory.
47
- *
48
- * @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
49
- */
50
- sources?: PathBuilderLike
51
- /**
52
- * State filter.
53
- *
54
- * @defaultValue TX.
55
- */
56
- state?: string
57
- /**
58
- * NPIs sampled.
59
- *
60
- * @defaultValue `2000`
61
- */
62
- npis?: number
63
- /**
64
- * Output TS module path.
65
- *
66
- * @defaultValue `registry/models/crosssource-gbt-en-us.ts`
67
- */
68
- out?: string
69
- /**
70
- * Locale recorded in the model meta.
71
- *
72
- * @defaultValue `"en-US"`
73
- */
74
- locale?: string
75
- /**
76
- * Max cross-source recall subject to this held-out pairwise precision.
77
- *
78
- * @defaultValue `0.95`
79
- */
80
- precisionBar?: number
81
- /**
82
- * The metadata stores this training date.
83
- *
84
- * @defaultValue today.
85
- */
86
- date?: string
87
- }
88
-
89
- /**
90
- * Train and emit the cross-source link GBT.
91
- */
92
- export async function trainCrossSourceGBT(
93
- options: TrainCrossSourceGBTOptions,
94
- report?: (line: string) => void
95
- ): Promise<{ out: string; pairs: number; recommendedThreshold: number }> {
96
- const SOURCES = resolvePath(options.sources ?? dataRootPath("record-matcher", "sources"))
97
- const STATE = stateOption(options)
98
- const NPIS = options.npis ?? 2000
99
- const OUT = options.out || "packages/registry/lib/models/crosssource-gbt-en-us.ts"
100
- const LOCALE = options.locale || "en-US"
101
- // Max cross-source recall subject to this held-out pairwise precision.
102
- const PRECISION_BAR = options.precisionBar ?? 0.95
103
- const TRAIN_DATE = options.date || isoDate()
104
-
105
- const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
106
- const OP_PROFILE = `${SOURCES}/openpayments_covered-recipient-profile_20260603.csv`
107
-
108
- report?.(`[A] streaming the OP profile supplement (${STATE})…`)
109
- const opByNPI = new Map<string, CrossSourceRow>()
110
-
111
- for await (const r of streamRows(OP_PROFILE)) {
112
- if (opByNPI.size >= NPIS) break
113
- const npi = norm(r["Covered_Recipient_NPI"])
114
- const st = norm(r["Covered_Recipient_Profile_State"]).toUpperCase()
115
-
116
- if (!npi || st !== STATE || opByNPI.has(npi)) continue
117
-
118
- const name =
119
- `${norm(r["Covered_Recipient_Profile_First_Name"])} ${norm(r["Covered_Recipient_Profile_Last_Name"])}`.trim()
120
-
121
- const address = addr(
122
- r["Covered_Recipient_Profile_Address_Line_1"]!,
123
- r["Covered_Recipient_Profile_City"]!,
124
- st,
125
- r["Covered_Recipient_Profile_Zipcode"]!
126
- )
127
-
128
- if (!name || !address) continue
129
- opByNPI.set(npi, { npi, name, org: "", address, source: "openpayments" })
130
- }
131
-
132
- report?.(` ${opByNPI.size} OP ${STATE} practitioners`)
133
-
134
- report?.("[B] full registry pass: address-frequency table + the NPI-joined NPPES rows…")
135
- const rows: CrossSourceRow[] = []
136
- const joined = new Set<string>()
137
- const addrCounts = new Map<string, number>()
138
- let addrTotal = 0
139
- let scanned = 0
140
-
141
- for await (const r of streamRows(REGISTRY)) {
142
- if (++scanned % 1_000_000 === 0) {
143
- report?.(` scanned ${scanned / 1e6}M, joined ${joined.size}`)
144
- }
145
-
146
- const practice = addr(r[N.pAddr]!, r[N.pCity]!, r[N.pState]!, r[N.pZip]!)
147
-
148
- if (practice) {
149
- const k = addressFrequencyKey(practice)
150
- addrCounts.set(k, (addrCounts.get(k) ?? 0) + 1)
151
-
152
- addrTotal++
153
- }
154
-
155
- const npi = norm(r[N.npi])
156
-
157
- if (!npi || !opByNPI.has(npi) || joined.has(npi) || !practice) continue
158
-
159
- // Practitioner-level matching: OP covered recipients are individuals (entity type 1).
160
- if (norm(r[N.entityType]) !== "1") continue
161
- const name = `${norm(r[N.first])} ${norm(r[N.last])}`.trim()
162
-
163
- if (!name) continue
164
- joined.add(npi)
165
- rows.push({ npi, name, org: "", address: practice, source: "nppes" })
166
- }
167
-
168
- for (const npi of joined) {
169
- rows.push(opByNPI.get(npi)!)
170
- }
171
-
172
- const addressFrequency = {
173
- total: addrTotal,
174
- distinct: addrCounts.size,
175
- frequency: (v: string) => (v ? (addrCounts.get(addressFrequencyKey(v)) ?? 0) / addrTotal : 0),
176
- }
177
-
178
- report?.(` ${joined.size} NPI-joined pairs → ${rows.length} records`)
179
-
180
- return trainCrossSourceModel({
181
- createGeocoder: options.createGeocoder,
182
- rows,
183
- joined,
184
- addressFrequency,
185
- sources: ["nppes", "openpayments"],
186
- precisionBar: PRECISION_BAR,
187
- out: OUT,
188
- exportPrefix: "CROSS_SOURCE_GBT",
189
- moduleDoc:
190
- ` * The CROSS-SOURCE link scorer (#655 option 2) — trained on NPI-joined NPPES ↔ Open Payments\n` +
191
- ` * pairs (the non-circular cross-registry anchor; both public domain). Scores "same provider,\n` +
192
- ` * different registry text" links the dedup GBT rejects by construction. Generated by\n` +
193
- ` * \`mailwoman registry train-scorer cross-gbt\` (registry/tools/train-cross-gbt.ts) — retrain + re-run rather than editing.\n`,
194
- meta: (figures) => ({
195
- version: "1.0.0",
196
- objective: "cross-source-link",
197
- locale: LOCALE,
198
- trainedOn: TRAIN_DATE,
199
- state: STATE,
200
- npis: joined.size,
201
- records: figures.records,
202
- pairs: figures.pairs,
203
- posRate: figures.posRate,
204
- precisionBar: PRECISION_BAR,
205
- holdoutBarRecall: figures.barRecall,
206
- holdoutF1Max: figures.f1Max,
207
- hyperparams: figures.hyperparams,
208
- recommendedThreshold: figures.recommendedThreshold,
209
- features: figures.features,
210
- sources: ["nppes", "openpayments"],
211
- }),
212
- report,
213
- })
214
- }
@@ -1,261 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * Trains the production learned-scorer model. `buildNPPESSample` creates the same NPI-keyed records used by
7
- * the dedup benchmark and clustering A/B. The sample uses the real registry and includes name drift plus address variation.
8
- * The trainer geocodes records and groups them into candidate pairs. It featurizes each pair with
9
- * `createMatchFeaturizer`. It labels pairs by NPI and fits a gradient-boosted tree model.
10
- * It writes the model to the committed package module `registry/models/dedup-gbt-en-us.ts`.
11
- *
12
- * Unlike the eval, this trains on all sampled NPIs with no held-out split, since the held-out F1
13
- * is the eval's job.
14
- *
15
- * Run: `mailwoman registry train-scorer gbt [--state TX] [--npis 3000] [--wof <admin.db>]
16
- * [--data-root <dir>] [--out registry/models/dedup-gbt-en-us.ts]`
17
- */
18
-
19
- import { dataRootPath } from "@mailwoman/core/data-root"
20
- import { makeDirectories, writeLocalFile } from "@mailwoman/core/fs/writers"
21
- import { prettyJSON, stringifyJSON } from "@mailwoman/core/json"
22
- import { makeLcg } from "@mailwoman/core/random"
23
- import { isoDate } from "@mailwoman/core/utils"
24
- import { block, gbtScore, trainGBT } from "@mailwoman/match"
25
- import { dirname } from "path-ts"
26
-
27
- import {
28
- buildDefaultModel,
29
- createMatchFeaturizer,
30
- defaultBlockingKeys,
31
- ingestRows,
32
- resolveEntities,
33
- type ColumnMapping,
34
- type SourceRecord,
35
- } from "#index"
36
- import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
37
- import { buildNPPESSample } from "#tools/nppes/sample"
38
- import { scoreEntities } from "#tools/nppes/scoring"
39
- import { stateOption, uniqueQuantiles } from "#tools/shared"
40
-
41
- /**
42
- * Share of entities assigned to fit.
43
- * The rest are held out.
44
- */
45
- const FIT_SPLIT_FRACTION = 0.8
46
-
47
- /**
48
- * Options for {@linkcode trainDedupGBT}.
49
- */
50
- export interface TrainDedupGBTOptions {
51
- /**
52
- * The injected geocoder factory.
53
- *
54
- * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
55
- */
56
- createGeocoder: EvalGeocoderFactory
57
- /**
58
- * Record-matcher sources directory.
59
- *
60
- * @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
61
- */
62
- sources?: string
63
- /**
64
- * State filter.
65
- *
66
- * @defaultValue TX.
67
- */
68
- state?: string
69
- /**
70
- * NPIs sampled.
71
- *
72
- * @defaultValue `3000`
73
- */
74
- npis?: number
75
- /**
76
- * Output TS module path.
77
- *
78
- * @defaultValue `registry/models/dedup-gbt-en-us.ts`
79
- */
80
- out?: string
81
- /**
82
- * Locale recorded in the model meta (the command's factory loads the matching weights).
83
- *
84
- * @defaultValue `"en-US"`
85
- */
86
- locale?: string
87
- /**
88
- * Cost-sensitive training: up-weight the negative (distinct-pair) class by this factor
89
- * so the model is more conservative about merging.
90
- *
91
- * It trades recall for precision to reduce over-merge.
92
- * `1` is the symmetric class-balanced default.
93
- *
94
- * A value above 1 penalizes a false merge more than a missed merge.
95
- */
96
- cost?: number
97
- /**
98
- * The training date stored in the metadata (overridable for reproducible commits).
99
- *
100
- * @defaultValue today.
101
- */
102
- date?: string
103
- }
104
-
105
- /**
106
- * Train and emit the production dedup GBT.
107
- */
108
- export async function trainDedupGBT(
109
- options: TrainDedupGBTOptions,
110
- report?: (line: string) => void
111
- ): Promise<{ out: string; pairs: number; recommendedThreshold: number; heldOutF1: number }> {
112
- const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
113
- const STATE = stateOption(options)
114
- const NPIS = options.npis ?? 3000
115
- const OUT = options.out || "packages/registry/lib/models/dedup-gbt-en-us.ts"
116
- const LOCALE = options.locale || "en-US"
117
- const COST = options.cost ?? 1
118
- const TRAIN_DATE = options.date || isoDate()
119
-
120
- const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
121
- const OTHER_NAMES = `${SOURCES}/nppes_other-names_20260607.tsv`
122
-
123
- const { rows, keptNpis, addressFrequency } = await buildNPPESSample(
124
- { registryPath: REGISTRY, otherNamesPath: OTHER_NAMES, state: STATE, maxNpis: NPIS },
125
- report
126
- )
127
-
128
- // The geocoder is injected, since the registry package never imports the runtime.
129
- report?.("[C] geocoding…")
130
- const geocoder = await options.createGeocoder()
131
-
132
- // `record.id` supplies the NPI label.
133
- // Multiple records can share an NPI as ground truth.
134
- const mapping: ColumnMapping = {
135
- id: "npi",
136
- name: "name",
137
- organization: "org",
138
- address: "address",
139
- attributes: { authorizedOfficial: "auth" },
140
- }
141
-
142
- const records: SourceRecord[] = await ingestRows(rows, mapping, {
143
- geocodeAddress: geocoder.geocodeAddress,
144
- })
145
-
146
- geocoder[Symbol.dispose]()
147
- const geocoded = records.filter((r) => r.address?.geocode).length
148
- report?.(` ${records.length} records, ${geocoded} geocoded`)
149
-
150
- report?.("[D] blocking + featurizing…")
151
- const comparisons = buildDefaultModel({ collapseSpatial: true, addressFrequency }).comparisons
152
- const featurize = createMatchFeaturizer({ comparisons, addressFrequency })
153
- const { pairs } = block(records, defaultBlockingKeys())
154
- const X = pairs.map(([a, b]) => featurize(a, b))
155
- const Y = pairs.map(([a, b]) => (a.id === b.id ? 1 : 0))
156
- const posRate = Y.reduce<number>((s, v) => s + v, 0) / Math.max(1, Y.length)
157
- const W = Y.map((y) => (y === 1 ? 1 - posRate : posRate * COST))
158
- const hyperparams = { rounds: 120, depth: 3, lr: 0.3, minLeaf: 20 }
159
-
160
- if (COST !== 1) {
161
- report?.(` cost-sensitive: negative class weighted ×${COST} (penalize over-merge)`)
162
- }
163
-
164
- // Calibrate the default link threshold.
165
- // The GBT logit uses no Fellegi-Sunter weight units.
166
- // With class-balanced weights, logit 0 ignores the roughly 1% match base rate and over-merges.
167
- // The threshold is swept on a held-out 20% of NPIs.
168
- // The shipped full-data model has near-identical logit calibration, so the threshold transfers.
169
- report?.("[E] calibrating the default link threshold on a held-out NPI split…")
170
- const rnd = makeLcg(20_260_615)
171
- const split = new Map<string, "fit" | "holdout">()
172
-
173
- for (const npi of keptNpis) {
174
- split.set(npi, rnd() < FIT_SPLIT_FRACTION ? "fit" : "holdout")
175
- }
176
-
177
- const fitPairs = pairs.filter(([a, b]) => split.get(a.id) === "fit" && split.get(b.id) === "fit")
178
-
179
- const calibGbt = trainGBT(
180
- fitPairs.map(([a, b]) => featurize(a, b)),
181
- fitPairs.map(([a, b]) => (a.id === b.id ? 1 : 0)),
182
- fitPairs.map(([a, b]) => (a.id === b.id ? 1 - posRate : posRate * COST)),
183
- hyperparams
184
- )
185
-
186
- const calibScorer = (a: SourceRecord, b: SourceRecord) => gbtScore(calibGbt, featurize(a, b))
187
- const holdoutRecords = records.filter((r) => split.get(r.id) === "holdout")
188
- const { pairs: holdoutPairs } = block(holdoutRecords, defaultBlockingKeys())
189
- const holdoutScores = holdoutPairs.map(([a, b]) => calibScorer(a, b)).toSorted((p, q) => p - q)
190
- const npiLabel = (rec: SourceRecord) => rec.id
191
- let recommendedThreshold = 0
192
- let bestF1 = -1
193
-
194
- for (const t of uniqueQuantiles(holdoutScores, 40)) {
195
- const { entities } = resolveEntities(holdoutRecords, {
196
- addressFrequency,
197
- collapseSpatial: true,
198
- scorer: calibScorer,
199
- threshold: t,
200
- })
201
-
202
- const f1 = scoreEntities(entities, npiLabel, holdoutRecords.length).f1
203
-
204
- if (f1 > bestF1) {
205
- bestF1 = f1
206
- recommendedThreshold = t
207
- }
208
- }
209
-
210
- report?.(
211
- ` recommended link threshold ${recommendedThreshold.toFixed(3)} (held-out clustering F1 ${(100 * bestF1).toFixed(1)}%)`
212
- )
213
-
214
- report?.("[F] training the shipped model on all pairs…")
215
- const model = trainGBT(X, Y, W, hyperparams)
216
- report?.(` ${pairs.length} pairs (${(100 * posRate).toFixed(1)}% positive), ${model.trees.length} trees`)
217
-
218
- // Emit the model as a committed TypeScript module with a prettier-stable literal,
219
- // so a retrain produces a clean one-line diff.
220
- const meta = {
221
- version: "1.0.0",
222
- locale: LOCALE,
223
- trainedOn: TRAIN_DATE,
224
- state: STATE,
225
- npis: keptNpis.size,
226
- records: records.length,
227
- pairs: pairs.length,
228
- posRate: Number(posRate.toFixed(4)),
229
- costNegative: COST,
230
- hyperparams,
231
- recommendedThreshold: Number(recommendedThreshold.toFixed(4)),
232
- features: X[0]?.length ?? 0,
233
- addressFrequencyDistinct: addressFrequency.distinct,
234
- addressFrequencyTotal: addressFrequency.total,
235
- }
236
-
237
- const moduleSource =
238
- `/**\n` +
239
- ` * @copyright Sister Software\n` +
240
- ` * @license AGPL-3.0\n` +
241
- ` * @author Teffen Ellis, et al.\n` +
242
- ` *\n` +
243
- ` * GENERATED by \`mailwoman registry train-scorer gbt\` (registry/tools/train-gbt.ts) — DO NOT edit by hand; retrain to update.\n` +
244
- ` *\n` +
245
- ` * The default learned-scorer model (#603): a gradient-boosted-tree dedup scorer trained on the\n` +
246
- ` * NPPES NPI-truth set (${STATE}, ${keptNpis.size} NPIs → ${pairs.length} candidate pairs). Validated to\n` +
247
- ` * generalize across states by learned-scorer-crossstate-eval.ts. Used by resolveEntities'\n` +
248
- ` * opt-in learnedScorer hook via createGBTScorer. The trained {@link GBT} is plain data.\n` +
249
- ` */\n\n` +
250
- `import type { GBT } from "@mailwoman/match"\n\n` +
251
- `/** Provenance for the bundled model — what it was trained on. */\n` +
252
- `export const DEDUP_GBT_META = ${prettyJSON(meta)} as const\n\n` +
253
- `// prettier-ignore\n` +
254
- `export const DEDUP_GBT_MODEL: GBT = ${stringifyJSON(model)}\n`
255
-
256
- await makeDirectories(dirname(OUT))
257
- await writeLocalFile(moduleSource, OUT)
258
- report?.(`[written] ${OUT} (${(moduleSource.length / 1024).toFixed(0)} KB)`)
259
-
260
- return { out: OUT, pairs: pairs.length, recommendedThreshold, heldOutF1: bestF1 }
261
- }
@@ -1,189 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * Train the organization-level cross-source link scorer. The practitioner cross-source GBT does
7
- * not transfer to organization records because its person-name features go dark. The organization
8
- * cross-dataset flows therefore pin the FS baseline. CMS Provider of Services joins Care Compare
9
- * by CCN. Each system represents the same facility and maintains its name and address separately.
10
- *
11
- * The pipeline runs a national CCN join into one record per source per facility, then the shared
12
- * `trainCrossSourceModel` geocodes the rows and blocks the union. It keeps cross-source pairs.
13
- * It featurizes them with the shared featurizer and labels them by CCN.
14
- * Calibration uses held-out CCNs.
15
- * The function emits `registry/models/org-crosssource-gbt-en-us.ts`.
16
- *
17
- * Sources (both public domain, direct CSVs):
18
- *
19
- * - `cms-pos_hospital-other_*.csv`: Provider of Services (PRVDR_NUM, FAC_NAME, ST_ADR…).
20
- * - `cms-carecompare_hospital-general_*.csv`: Care Compare (Facility ID, Facility Name, Address…).
21
- *
22
- * Run: `mailwoman registry train-scorer org-cross-gbt [--cap 6000] [--precision-bar 0.95]
23
- * [--wof <admin.db>] [--data-root <dir>] [--out registry/models/org-crosssource-gbt-en-us.ts]`
24
- */
25
-
26
- import { dataRootPath } from "@mailwoman/core/data-root"
27
- import { isoDate } from "@mailwoman/core/utils"
28
- import { resolvePath, type PathBuilderLike } from "path-ts"
29
-
30
- import { addressFrequencyKey, streamRows } from "#index"
31
- import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
32
- import { addr, norm, trainCrossSourceModel, type CrossSourceRow } from "#tools/shared"
33
-
34
- /**
35
- * Options for {@linkcode trainOrgCrossSourceGBT}.
36
- */
37
- export interface TrainOrgCrossSourceGBTOptions {
38
- /**
39
- * The injected geocoder factory.
40
- *
41
- * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
42
- */
43
- createGeocoder: EvalGeocoderFactory
44
- /**
45
- * Record-matcher sources directory.
46
- *
47
- * @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
48
- */
49
- sources?: PathBuilderLike
50
- /**
51
- * Care Compare facilities sampled.
52
- *
53
- * @defaultValue `6000`
54
- */
55
- cap?: number
56
- /**
57
- * Output TS module path.
58
- *
59
- * @defaultValue `registry/models/org-crosssource-gbt-en-us.ts`
60
- */
61
- out?: string
62
- /**
63
- * Locale recorded in the model meta.
64
- *
65
- * @defaultValue `"en-US"`
66
- */
67
- locale?: string
68
- /**
69
- * Max cross-source recall subject to this held-out pairwise precision.
70
- *
71
- * @defaultValue `0.95`
72
- */
73
- precisionBar?: number
74
- /**
75
- * The metadata stores this training date.
76
- *
77
- * @defaultValue today.
78
- */
79
- date?: string
80
- }
81
-
82
- /**
83
- * Train and emit the org-level cross-source link GBT.
84
- *
85
- * The CCN is the cross-system facility key.
86
- * It is stored in {@link CrossSourceRow.npi} and copied to `record.id` as the held-out label.
87
- */
88
- export async function trainOrgCrossSourceGBT(
89
- options: TrainOrgCrossSourceGBTOptions,
90
- report?: (line: string) => void
91
- ): Promise<{ out: string; pairs: number; recommendedThreshold: number }> {
92
- const SOURCES = resolvePath(options.sources ?? dataRootPath("record-matcher", "sources"))
93
- const CAP = options.cap ?? 6000
94
- const OUT = options.out || "packages/registry/lib/models/org-crosssource-gbt-en-us.ts"
95
- const LOCALE = options.locale || "en-US"
96
- // Max cross-source recall subject to this held-out pairwise precision.
97
- const PRECISION_BAR = options.precisionBar ?? 0.95
98
- const TRAIN_DATE = options.date || isoDate()
99
-
100
- const POS = `${SOURCES}/cms-pos_hospital-other_2026q1.csv`
101
- const CARE_COMPARE = `${SOURCES}/cms-carecompare_hospital-general_20260706.csv`
102
-
103
- report?.("[A] streaming Care Compare…")
104
- const ccByID = new Map<string, CrossSourceRow>()
105
-
106
- for await (const r of streamRows(CARE_COMPARE)) {
107
- if (ccByID.size >= CAP) break
108
- const ccn = norm(r["Facility ID"])
109
- const name = norm(r["Facility Name"])
110
- const address = addr(r["Address"]!, r["City/Town"]!, r["State"]!, r["ZIP Code"]!)
111
-
112
- if (!ccn || !name || !address) continue
113
- ccByID.set(ccn, { npi: ccn, name, org: name, address, source: "care-compare" })
114
- }
115
-
116
- report?.(` ${ccByID.size} Care Compare facilities`)
117
-
118
- report?.("[B] streaming POS + building the frequency table…")
119
- const rows: CrossSourceRow[] = []
120
- const joined = new Set<string>()
121
- const addrCounts = new Map<string, number>()
122
- let addrTotal = 0
123
-
124
- for await (const r of streamRows(POS)) {
125
- const address = addr(r["ST_ADR"]!, r["CITY_NAME"]!, r["STATE_CD"]!, r["ZIP_CD"]!)
126
-
127
- if (address) {
128
- const k = addressFrequencyKey(address)
129
- addrCounts.set(k, (addrCounts.get(k) ?? 0) + 1)
130
-
131
- addrTotal++
132
- }
133
-
134
- const ccn = norm(r["PRVDR_NUM"])
135
-
136
- if (!ccn || !ccByID.has(ccn) || joined.has(ccn) || !address) continue
137
- const name = norm(r["FAC_NAME"])
138
-
139
- if (!name) continue
140
- joined.add(ccn)
141
- rows.push({ npi: ccn, name, org: name, address, source: "cms-pos" })
142
- }
143
-
144
- for (const ccn of joined) {
145
- rows.push(ccByID.get(ccn)!)
146
- }
147
-
148
- const addressFrequency = {
149
- total: addrTotal,
150
- distinct: addrCounts.size,
151
- frequency: (v: string) => (v ? (addrCounts.get(addressFrequencyKey(v)) ?? 0) / addrTotal : 0),
152
- }
153
-
154
- report?.(` ${joined.size} CCN-joined facilities → ${rows.length} records`)
155
-
156
- return trainCrossSourceModel({
157
- createGeocoder: options.createGeocoder,
158
- rows,
159
- joined,
160
- addressFrequency,
161
- sources: ["cms-pos", "care-compare"],
162
- precisionBar: PRECISION_BAR,
163
- out: OUT,
164
- exportPrefix: "ORG_CROSS_SOURCE_GBT",
165
- moduleDoc:
166
- ` * The ORG-LEVEL cross-source link scorer (#655 follow-on) — trained on CCN-joined CMS POS ↔\n` +
167
- ` * Care Compare facility pairs (both public domain). Scores "same facility, different registry\n` +
168
- ` * text" links for org-level cross-dataset flows. Generated by\n` +
169
- ` * \`mailwoman registry train-scorer org-cross-gbt\` (registry/tools/train-org-cross-gbt.ts) — retrain rather than editing.\n`,
170
- meta: (figures) => ({
171
- version: "1.0.0",
172
- objective: "org-cross-source-link",
173
- locale: LOCALE,
174
- trainedOn: TRAIN_DATE,
175
- facilities: joined.size,
176
- records: figures.records,
177
- pairs: figures.pairs,
178
- posRate: figures.posRate,
179
- precisionBar: PRECISION_BAR,
180
- holdoutBarRecall: figures.barRecall,
181
- holdoutF1Max: figures.f1Max,
182
- hyperparams: figures.hyperparams,
183
- recommendedThreshold: figures.recommendedThreshold,
184
- features: figures.features,
185
- sources: ["cms-pos", "care-compare"],
186
- }),
187
- report,
188
- })
189
- }