@mailwoman/entity-resolution 0.0.0-stage → 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 (227) hide show
  1. package/README.md +114 -2
  2. package/lib/address-key.ts +46 -0
  3. package/lib/geocode-handler.ts +37 -0
  4. package/lib/geojson.ts +72 -0
  5. package/lib/index.ts +23 -0
  6. package/lib/ingest.ts +349 -0
  7. package/lib/learned-scorer.ts +134 -0
  8. package/lib/map-html.ts +287 -0
  9. package/lib/models/crosssource-gbt-en-us.ts +43 -0
  10. package/lib/models/dedup-gbt-en-us.ts +47 -0
  11. package/lib/models/org-crosssource-gbt-en-us.ts +43 -0
  12. package/lib/reconcile.ts +239 -0
  13. package/lib/resolve.ts +569 -0
  14. package/lib/types.ts +110 -0
  15. package/out/address-key.d.ts +34 -0
  16. package/out/address-key.d.ts.map +1 -0
  17. package/out/address-key.js +41 -0
  18. package/out/address-key.js.map +1 -0
  19. package/out/geocode-handler.d.ts +20 -0
  20. package/out/geocode-handler.d.ts.map +1 -0
  21. package/out/geocode-handler.js +29 -0
  22. package/out/geocode-handler.js.map +1 -0
  23. package/out/geojson.d.ts +28 -0
  24. package/out/geojson.d.ts.map +1 -0
  25. package/out/geojson.js +62 -0
  26. package/out/geojson.js.map +1 -0
  27. package/out/index.d.ts +23 -0
  28. package/out/index.d.ts.map +1 -0
  29. package/out/index.js +23 -0
  30. package/out/index.js.map +1 -0
  31. package/out/ingest.d.ts +173 -0
  32. package/out/ingest.d.ts.map +1 -0
  33. package/out/ingest.js +185 -0
  34. package/out/ingest.js.map +1 -0
  35. package/out/learned-scorer.d.ts +61 -0
  36. package/out/learned-scorer.d.ts.map +1 -0
  37. package/out/learned-scorer.js +91 -0
  38. package/out/learned-scorer.js.map +1 -0
  39. package/out/map-html.d.ts +39 -0
  40. package/out/map-html.d.ts.map +1 -0
  41. package/out/map-html.js +220 -0
  42. package/out/map-html.js.map +1 -0
  43. package/out/models/crosssource-gbt-en-us.d.ts +45 -0
  44. package/out/models/crosssource-gbt-en-us.d.ts.map +1 -0
  45. package/out/models/crosssource-gbt-en-us.js +40 -0
  46. package/out/models/crosssource-gbt-en-us.js.map +1 -0
  47. package/out/models/dedup-gbt-en-us.d.ts +44 -0
  48. package/out/models/dedup-gbt-en-us.d.ts.map +1 -0
  49. package/out/models/dedup-gbt-en-us.js +44 -0
  50. package/out/models/dedup-gbt-en-us.js.map +1 -0
  51. package/out/models/org-crosssource-gbt-en-us.d.ts +45 -0
  52. package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -0
  53. package/out/models/org-crosssource-gbt-en-us.js +40 -0
  54. package/out/models/org-crosssource-gbt-en-us.js.map +1 -0
  55. package/out/reconcile.d.ts +96 -0
  56. package/out/reconcile.d.ts.map +1 -0
  57. package/out/reconcile.js +127 -0
  58. package/out/reconcile.js.map +1 -0
  59. package/out/resolve.d.ts +264 -0
  60. package/out/resolve.d.ts.map +1 -0
  61. package/out/resolve.js +282 -0
  62. package/out/resolve.js.map +1 -0
  63. package/out/tools/coverage-reconciliation.d.ts +67 -0
  64. package/out/tools/coverage-reconciliation.d.ts.map +1 -0
  65. package/out/tools/coverage-reconciliation.js +113 -0
  66. package/out/tools/coverage-reconciliation.js.map +1 -0
  67. package/out/tools/cross/dataset-correlation.d.ts +61 -0
  68. package/out/tools/cross/dataset-correlation.d.ts.map +1 -0
  69. package/out/tools/cross/dataset-correlation.js +244 -0
  70. package/out/tools/cross/dataset-correlation.js.map +1 -0
  71. package/out/tools/cross/source-threshold-sweep.d.ts +60 -0
  72. package/out/tools/cross/source-threshold-sweep.d.ts.map +1 -0
  73. package/out/tools/cross/source-threshold-sweep.js +264 -0
  74. package/out/tools/cross/source-threshold-sweep.js.map +1 -0
  75. package/out/tools/dedup-ceiling.d.ts +62 -0
  76. package/out/tools/dedup-ceiling.d.ts.map +1 -0
  77. package/out/tools/dedup-ceiling.js +171 -0
  78. package/out/tools/dedup-ceiling.js.map +1 -0
  79. package/out/tools/eval-geocoder.d.ts +68 -0
  80. package/out/tools/eval-geocoder.d.ts.map +1 -0
  81. package/out/tools/eval-geocoder.js +13 -0
  82. package/out/tools/eval-geocoder.js.map +1 -0
  83. package/out/tools/geocoder/namesake-probe.d.ts +33 -0
  84. package/out/tools/geocoder/namesake-probe.d.ts.map +1 -0
  85. package/out/tools/geocoder/namesake-probe.js +60 -0
  86. package/out/tools/geocoder/namesake-probe.js.map +1 -0
  87. package/out/tools/geocoder/vs-provided-coords.d.ts +53 -0
  88. package/out/tools/geocoder/vs-provided-coords.d.ts.map +1 -0
  89. package/out/tools/geocoder/vs-provided-coords.js +161 -0
  90. package/out/tools/geocoder/vs-provided-coords.js.map +1 -0
  91. package/out/tools/gold-set-sample.d.ts +67 -0
  92. package/out/tools/gold-set-sample.d.ts.map +1 -0
  93. package/out/tools/gold-set-sample.js +81 -0
  94. package/out/tools/gold-set-sample.js.map +1 -0
  95. package/out/tools/learned/scorer/clustering-eval.d.ts +77 -0
  96. package/out/tools/learned/scorer/clustering-eval.d.ts.map +1 -0
  97. package/out/tools/learned/scorer/clustering-eval.js +207 -0
  98. package/out/tools/learned/scorer/clustering-eval.js.map +1 -0
  99. package/out/tools/learned/scorer/crossstate-eval.d.ts +65 -0
  100. package/out/tools/learned/scorer/crossstate-eval.d.ts.map +1 -0
  101. package/out/tools/learned/scorer/crossstate-eval.js +168 -0
  102. package/out/tools/learned/scorer/crossstate-eval.js.map +1 -0
  103. package/out/tools/learned/scorer/eval.d.ts +64 -0
  104. package/out/tools/learned/scorer/eval.d.ts.map +1 -0
  105. package/out/tools/learned/scorer/eval.js +275 -0
  106. package/out/tools/learned/scorer/eval.js.map +1 -0
  107. package/out/tools/matcher-scale.d.ts +40 -0
  108. package/out/tools/matcher-scale.d.ts.map +1 -0
  109. package/out/tools/matcher-scale.js +111 -0
  110. package/out/tools/matcher-scale.js.map +1 -0
  111. package/out/tools/nppes/dedup-benchmark.d.ts +82 -0
  112. package/out/tools/nppes/dedup-benchmark.d.ts.map +1 -0
  113. package/out/tools/nppes/dedup-benchmark.js +226 -0
  114. package/out/tools/nppes/dedup-benchmark.js.map +1 -0
  115. package/out/tools/nppes/org-name.d.ts +15 -0
  116. package/out/tools/nppes/org-name.d.ts.map +1 -0
  117. package/out/tools/nppes/org-name.js +6 -0
  118. package/out/tools/nppes/org-name.js.map +1 -0
  119. package/out/tools/nppes/overmerge-packet.d.ts +43 -0
  120. package/out/tools/nppes/overmerge-packet.d.ts.map +1 -0
  121. package/out/tools/nppes/overmerge-packet.js +54 -0
  122. package/out/tools/nppes/overmerge-packet.js.map +1 -0
  123. package/out/tools/nppes/report.d.ts +97 -0
  124. package/out/tools/nppes/report.d.ts.map +1 -0
  125. package/out/tools/nppes/report.js +178 -0
  126. package/out/tools/nppes/report.js.map +1 -0
  127. package/out/tools/nppes/sample.d.ts +101 -0
  128. package/out/tools/nppes/sample.d.ts.map +1 -0
  129. package/out/tools/nppes/sample.js +127 -0
  130. package/out/tools/nppes/sample.js.map +1 -0
  131. package/out/tools/nppes/scoring.d.ts +37 -0
  132. package/out/tools/nppes/scoring.d.ts.map +1 -0
  133. package/out/tools/nppes/scoring.js +81 -0
  134. package/out/tools/nppes/scoring.js.map +1 -0
  135. package/out/tools/nppes/settings.d.ts +41 -0
  136. package/out/tools/nppes/settings.d.ts.map +1 -0
  137. package/out/tools/nppes/settings.js +79 -0
  138. package/out/tools/nppes/settings.js.map +1 -0
  139. package/out/tools/nppes/truth-grains.d.ts +63 -0
  140. package/out/tools/nppes/truth-grains.d.ts.map +1 -0
  141. package/out/tools/nppes/truth-grains.js +142 -0
  142. package/out/tools/nppes/truth-grains.js.map +1 -0
  143. package/out/tools/shared.d.ts +325 -0
  144. package/out/tools/shared.d.ts.map +1 -0
  145. package/out/tools/shared.js +453 -0
  146. package/out/tools/shared.js.map +1 -0
  147. package/out/tools/train/cross-gbt.d.ts +89 -0
  148. package/out/tools/train/cross-gbt.d.ts.map +1 -0
  149. package/out/tools/train/cross-gbt.js +132 -0
  150. package/out/tools/train/cross-gbt.js.map +1 -0
  151. package/out/tools/train/gbt.d.ts +85 -0
  152. package/out/tools/train/gbt.d.ts.map +1 -0
  153. package/out/tools/train/gbt.js +155 -0
  154. package/out/tools/train/gbt.js.map +1 -0
  155. package/out/tools/train/org-cross-gbt.d.ts +85 -0
  156. package/out/tools/train/org-cross-gbt.d.ts.map +1 -0
  157. package/out/tools/train/org-cross-gbt.js +122 -0
  158. package/out/tools/train/org-cross-gbt.js.map +1 -0
  159. package/out/tools/txhhsc-to-oarow.d.ts +42 -0
  160. package/out/tools/txhhsc-to-oarow.d.ts.map +1 -0
  161. package/out/tools/txhhsc-to-oarow.js +78 -0
  162. package/out/tools/txhhsc-to-oarow.js.map +1 -0
  163. package/out/tools/viz/browser.d.ts +31 -0
  164. package/out/tools/viz/browser.d.ts.map +1 -0
  165. package/out/tools/viz/browser.js +26 -0
  166. package/out/tools/viz/browser.js.map +1 -0
  167. package/out/tools/viz/cross-dataset-map.d.ts +39 -0
  168. package/out/tools/viz/cross-dataset-map.d.ts.map +1 -0
  169. package/out/tools/viz/cross-dataset-map.js +84 -0
  170. package/out/tools/viz/cross-dataset-map.js.map +1 -0
  171. package/out/tools/viz/geocode-first-surface.d.ts +36 -0
  172. package/out/tools/viz/geocode-first-surface.d.ts.map +1 -0
  173. package/out/tools/viz/geocode-first-surface.js +234 -0
  174. package/out/tools/viz/geocode-first-surface.js.map +1 -0
  175. package/out/tools/viz/render/map.d.ts +42 -0
  176. package/out/tools/viz/render/map.d.ts.map +1 -0
  177. package/out/tools/viz/render/map.js +40 -0
  178. package/out/tools/viz/render/map.js.map +1 -0
  179. package/out/tools/viz/render.d.ts +46 -0
  180. package/out/tools/viz/render.d.ts.map +1 -0
  181. package/out/tools/viz/render.js +49 -0
  182. package/out/tools/viz/render.js.map +1 -0
  183. package/out/tools/viz/source-provenance-map.d.ts +57 -0
  184. package/out/tools/viz/source-provenance-map.d.ts.map +1 -0
  185. package/out/tools/viz/source-provenance-map.js +82 -0
  186. package/out/tools/viz/source-provenance-map.js.map +1 -0
  187. package/out/tools/viz/yardstick-figure.d.ts +22 -0
  188. package/out/tools/viz/yardstick-figure.d.ts.map +1 -0
  189. package/out/tools/viz/yardstick-figure.js +106 -0
  190. package/out/tools/viz/yardstick-figure.js.map +1 -0
  191. package/out/types.d.ts +108 -0
  192. package/out/types.d.ts.map +1 -0
  193. package/out/types.js +11 -0
  194. package/out/types.js.map +1 -0
  195. package/package.json +113 -3
  196. package/tools/coverage-reconciliation.ts +192 -0
  197. package/tools/cross/dataset-correlation.ts +380 -0
  198. package/tools/cross/source-threshold-sweep.ts +416 -0
  199. package/tools/dedup-ceiling.ts +225 -0
  200. package/tools/eval-geocoder.ts +77 -0
  201. package/tools/geocoder/namesake-probe.ts +91 -0
  202. package/tools/geocoder/vs-provided-coords.ts +232 -0
  203. package/tools/gold-set-sample.ts +147 -0
  204. package/tools/learned/scorer/clustering-eval.ts +349 -0
  205. package/tools/learned/scorer/crossstate-eval.ts +280 -0
  206. package/tools/learned/scorer/eval.ts +429 -0
  207. package/tools/matcher-scale.ts +185 -0
  208. package/tools/nppes/dedup-benchmark.ts +364 -0
  209. package/tools/nppes/org-name.ts +15 -0
  210. package/tools/nppes/overmerge-packet.ts +98 -0
  211. package/tools/nppes/report.ts +380 -0
  212. package/tools/nppes/sample.ts +250 -0
  213. package/tools/nppes/scoring.ts +115 -0
  214. package/tools/nppes/settings.ts +102 -0
  215. package/tools/nppes/truth-grains.ts +185 -0
  216. package/tools/shared.ts +743 -0
  217. package/tools/train/cross-gbt.ts +214 -0
  218. package/tools/train/gbt.ts +261 -0
  219. package/tools/train/org-cross-gbt.ts +189 -0
  220. package/tools/txhhsc-to-oarow.ts +118 -0
  221. package/tools/viz/browser.ts +41 -0
  222. package/tools/viz/cross-dataset-map.ts +133 -0
  223. package/tools/viz/geocode-first-surface.ts +305 -0
  224. package/tools/viz/render/map.ts +61 -0
  225. package/tools/viz/render.ts +103 -0
  226. package/tools/viz/source-provenance-map.ts +154 -0
  227. package/tools/viz/yardstick-figure.ts +197 -0
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Dedup ceiling measurement, answering how good is good enough for dedup from the data rather
7
+ * than from a round number. The residual dedup error is over-merge: distinct co-located providers
8
+ * (different NPIs at one address) fused because a shared address outvotes a disagreeing name. The
9
+ * irreducible part is the set of co-located distinct-NPI pairs whose name text is also near
10
+ * identical, so no name or organization feature can separate them.
11
+ *
12
+ * This measures that floor directly and without labels, using NPI as the distinctness truth. It
13
+ * is geocode-free on purpose, so it can run at large N in seconds. "Same address" uses the
14
+ * matcher's own `addressFrequencyKey`, and "same name" uses a normalized token Jaccard over the
15
+ * legal business name.
16
+ *
17
+ * Run: `mailwoman registry dedup-ceiling [--cap 50000] [--state TX] [--sources <dir>] [--tau 0.7]
18
+ * [--out-md <md>]`
19
+ */
20
+ /**
21
+ * Options for {@linkcode dedupCeiling}.
22
+ */
23
+ export interface DedupCeilingOptions {
24
+ /**
25
+ * Record-matcher sources directory.
26
+ *
27
+ * @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
28
+ */
29
+ sources?: string;
30
+ /**
31
+ * Providers sampled from the registry.
32
+ *
33
+ * @defaultValue `50000`
34
+ */
35
+ cap?: number;
36
+ /**
37
+ * State filter.
38
+ *
39
+ * @defaultValue TX.
40
+ */
41
+ state?: string;
42
+ /**
43
+ * Org-name Jaccard collision threshold.
44
+ *
45
+ * @defaultValue `0.7`
46
+ */
47
+ tau?: number;
48
+ /**
49
+ * Also write the markdown report here.
50
+ */
51
+ outMd?: string;
52
+ }
53
+ /**
54
+ * Measure the irreducible over-merge of co-located providers.
55
+ * Emit the markdown report to stdout.
56
+ */
57
+ export declare function dedupCeiling(options?: DedupCeilingOptions, report?: (line: string) => void): Promise<{
58
+ markdown: string;
59
+ pairs: number;
60
+ collide: number;
61
+ }>;
62
+ //# sourceMappingURL=dedup-ceiling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dedup-ceiling.d.ts","sourceRoot":"","sources":["../../tools/dedup-ceiling.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAcH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IACnC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;;GAGG;AACH,wBAAsB,YAAY,CACjC,OAAO,GAAE,mBAAwB,EACjC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC7B,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAuJ/D"}
@@ -0,0 +1,171 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Dedup ceiling measurement, answering how good is good enough for dedup from the data rather
7
+ * than from a round number. The residual dedup error is over-merge: distinct co-located providers
8
+ * (different NPIs at one address) fused because a shared address outvotes a disagreeing name. The
9
+ * irreducible part is the set of co-located distinct-NPI pairs whose name text is also near
10
+ * identical, so no name or organization feature can separate them.
11
+ *
12
+ * This measures that floor directly and without labels, using NPI as the distinctness truth. It
13
+ * is geocode-free on purpose, so it can run at large N in seconds. "Same address" uses the
14
+ * matcher's own `addressFrequencyKey`, and "same name" uses a normalized token Jaccard over the
15
+ * legal business name.
16
+ *
17
+ * Run: `mailwoman registry dedup-ceiling [--cap 50000] [--state TX] [--sources <dir>] [--tau 0.7]
18
+ * [--out-md <md>]`
19
+ */
20
+ import { dataRootPath } from "@mailwoman/core/data-root";
21
+ import { writeLocalFile } from "@mailwoman/core/fs/writers";
22
+ import { formatPercent } from "@mailwoman/core/stats";
23
+ import { jaccard } from "@mailwoman/match";
24
+ import { colocatedDistinctPairs, scanColocatedProviders, stateOption } from "#tools/shared";
25
+ /**
26
+ * Similarity at or above which a pair is a near-miss for a reviewer to inspect rather than unrelated.
27
+ */
28
+ const WEAK_SIMILARITY_MIN = 0.3;
29
+ /**
30
+ * Measure the irreducible over-merge of co-located providers.
31
+ * Emit the markdown report to stdout.
32
+ */
33
+ export async function dedupCeiling(options = {}, report) {
34
+ const SOURCES = options.sources || dataRootPath("record-matcher", "sources");
35
+ const CAP = options.cap ?? 50_000;
36
+ const STATE = stateOption(options);
37
+ const TAU = options.tau ?? 0.7;
38
+ const OUT_MD = options.outMd || "";
39
+ const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`;
40
+ report?.(`[A] streaming ${STATE} org providers (cap ${CAP})…`);
41
+ const { byAddr, kept, scanned } = await scanColocatedProviders({ registryPath: REGISTRY, state: STATE, cap: CAP });
42
+ report?.(` scanned ${scanned} rows → ${kept} ${STATE} org providers at ${byAddr.size} distinct addresses`);
43
+ let sharedAddresses = 0;
44
+ let providersAtSharedAddr = 0;
45
+ let pairs = 0;
46
+ let collide = 0;
47
+ let mid = 0;
48
+ let separable = 0;
49
+ let collideSharePhone = 0;
50
+ let collideSameAuth = 0;
51
+ let collideDistinct = 0;
52
+ const PAIR_BUDGET = 5_000_000;
53
+ // guard against a pathological mega-address (PO-box farms)
54
+ let lastGroup = null;
55
+ for (const { a, b, group } of colocatedDistinctPairs(byAddr)) {
56
+ if (group !== lastGroup) {
57
+ lastGroup = group;
58
+ sharedAddresses++;
59
+ providersAtSharedAddr += group.length;
60
+ }
61
+ if (pairs >= PAIR_BUDGET)
62
+ continue;
63
+ pairs++;
64
+ const sim = jaccard(a.tokens, b.tokens);
65
+ if (sim >= TAU) {
66
+ collide++;
67
+ if (a.phone && a.phone === b.phone) {
68
+ collideSharePhone++;
69
+ }
70
+ const sameAuth = a.auth !== "" && a.auth === b.auth;
71
+ const sameTax = a.taxonomy !== "" && a.taxonomy === b.taxonomy;
72
+ if (sameAuth) {
73
+ collideSameAuth++;
74
+ }
75
+ else if (!sameTax) {
76
+ collideDistinct++;
77
+ }
78
+ }
79
+ else if (sim >= WEAK_SIMILARITY_MIN) {
80
+ mid++;
81
+ }
82
+ else {
83
+ separable++;
84
+ }
85
+ }
86
+ // The irreducible false-merge rate among co-located distinct pairs is collide/pairs.
87
+ // Report the collision rate directly with a precision-ceiling band: optimistic counts
88
+ // only `collide`, and conservative counts `collide` plus half of `mid`.
89
+ // Recall is not binding here, so the F1 ceiling tracks the precision ceiling.
90
+ const pct = formatPercent;
91
+ const lines = [
92
+ `# #625 — dedup ceiling: the irreducible over-merge of co-located providers`,
93
+ "",
94
+ `_Generated by \`registry/tools/dedup-ceiling.ts\`. ${STATE}, ${kept} type-2 (org) providers ` +
95
+ `(cap ${CAP}), geocode-free: "same address" = the matcher's \`addressFrequencyKey\`; "same name" = ` +
96
+ `normalized token Jaccard over the legal business name (corporate suffixes + articles stripped, domain ` +
97
+ `words kept). NPI is the distinctness truth (different NPI = different provider). τ = ${TAU}._`,
98
+ "",
99
+ `## Co-location prevalence`,
100
+ "",
101
+ `- **${sharedAddresses}** addresses host ≥2 distinct NPIs (${pct(sharedAddresses, byAddr.size)} of ${byAddr.size} addresses).`,
102
+ `- **${providersAtSharedAddr}** providers sit at a shared address (${pct(providersAtSharedAddr, kept)} of ${kept}).`,
103
+ `- **${pairs}** co-located distinct-NPI pairs (the over-merge population)${pairs >= PAIR_BUDGET ? ` — capped at the ${PAIR_BUDGET} pair budget` : ""}.`,
104
+ "",
105
+ `## Name separability of co-located distinct providers`,
106
+ "",
107
+ `| org-name Jaccard | pairs | share | meaning |`,
108
+ `|---|---:|---:|---|`,
109
+ `| ≥ ${TAU} (collision) | ${collide} | ${pct(collide, pairs)} | ~identical names → **irreducible over-merge** |`,
110
+ `| ${0.3}–${TAU} | ${mid} | ${pct(mid, pairs)} | partial — separable with a good model |`,
111
+ `| < 0.3 | ${separable} | ${pct(separable, pairs)} | clearly different names → separable |`,
112
+ "",
113
+ `Of the ${collide} collision pairs, **${collideSharePhone}** (${pct(collideSharePhone, collide)}) also share a phone — ` +
114
+ `so phone (a shared institutional switchboard) does NOT separate them either. If anything it over-links. This is ` +
115
+ `why the benchmark found phone an unreliable secondary identifier.`,
116
+ "",
117
+ `## Splitting the collisions: NPI over-segmentation vs genuinely distinct providers`,
118
+ "",
119
+ `A collision (same address, ~same name, often same phone) with DIFFERENT NPIs is usually one organization holding ` +
120
+ `multiple NPIs (subparts / departments) — where merging is **correct** and NPI-as-truth is **over-segmenting**, ` +
121
+ `not a model error. NPPES's own fields separate the two cases:`,
122
+ "",
123
+ `| collision pair is… | pairs | share of collisions | merging it is… |`,
124
+ `|---|---:|---:|---|`,
125
+ `| same authorized official | ${collideSameAuth} | ${pct(collideSameAuth, collide)} | **correct** — one org, many NPIs (NPI over-segments) |`,
126
+ `| different official AND different specialty | ${collideDistinct} | ${pct(collideDistinct, collide)} | a **genuine** distinct co-located provider — true over-merge |`,
127
+ `| (remainder: different official, same specialty) | ${collide - collideSameAuth - collideDistinct} | ${pct(collide - collideSameAuth - collideDistinct, collide)} | ambiguous — needs adjudication |`,
128
+ "",
129
+ `## The ceiling`,
130
+ "",
131
+ `The raw collision rate is **${pct(collide, pairs)}** of co-located distinct-NPI pairs — but only **${pct(collideDistinct, pairs)}** ` +
132
+ `of co-located pairs are *genuinely* distinct providers indistinguishable by name (different official + specialty). ` +
133
+ `Most collisions are **NPI over-segmentation** (${pct(collideSameAuth, collide)} share an authorized official), where ` +
134
+ `a merge is correct and NPI-truth penalizes it wrongly.`,
135
+ "",
136
+ `**This is the answer to "how good is good enough," and it has two parts:**`,
137
+ `1. Measured against **NPI-as-truth**, F1 is capped well below 0.85 — ~${pct(collide, pairs)} of co-located pairs are ` +
138
+ `unseparable, and NPI-truth scores most of them as errors even though merging is correct. The round **0.85 target ` +
139
+ `is unreachable under this yardstick and should be dropped.**`,
140
+ `2. The *real* irreducible over-merge — genuinely distinct co-located providers with identical names — is only ` +
141
+ `~**${pct(collideDistinct, pairs)}** of the co-located population. Against an **entity-level truth** (subpart-aware), ` +
142
+ `the achievable ceiling is much higher. But that ceiling can only be MEASURED with an entity-level / adjudicated ` +
143
+ `gold set — NPI-truth alone can't tell a correct subpart-merge from a true over-merge. **This is why the gold set ` +
144
+ `(the "second comparison") is necessary, not optional.**`,
145
+ "",
146
+ `Recommendation: drop 0.85. Set the bar against a subpart-aware / adjudicated entity truth, report NPI-level AND ` +
147
+ `entity-level side by side, and target "separate the ~${pct(collideDistinct, pairs)} genuinely-distinct co-located ` +
148
+ `pairs the GBT can still reach" rather than a round F1. The GBT's corroboration-feature work (#625 revised) ` +
149
+ `attacks exactly that separable subset.`,
150
+ "",
151
+ `## Caveats`,
152
+ "",
153
+ `- **Geocode-free + exact address key.** "Co-located" here is an exact normalized-address match. A geocoded key would ` +
154
+ `add near-but-not-exact neighbors (suite splits, slightly different formatting), which can only RAISE the ` +
155
+ `collision count. So this is a LOWER bound on the irreducible over-merge.`,
156
+ `- **Recall side under-measured.** NPPES same-NPI records almost always share an address or the org name, so the ` +
157
+ `recall floor looks ~1.0 here. Real-world feeds with distant + name-drifted same-entity records would lower it. ` +
158
+ `The F1 ceiling reported tracks the PRECISION constraint, which is the binding one for the over-merge problem.`,
159
+ `- **Token-Jaccard ≠ the model's name comparison.** It is a proxy for separability. The GBT uses the FS agreement ` +
160
+ `levels. The collision SET (sim ≥ τ + shared phone) is robust to the exact similarity metric.`,
161
+ "",
162
+ ];
163
+ const md = lines.join("\n");
164
+ console.log(md);
165
+ if (OUT_MD) {
166
+ await writeLocalFile(md, OUT_MD);
167
+ report?.(`[written] ${OUT_MD}`);
168
+ }
169
+ return { markdown: md, pairs, collide };
170
+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G,0EAA0E;QAC3E,kHAAkH;YACjH,iHAAiH;YACjH,+GAA+G;QAChH,mHAAmH;YAClH,8FAA8F;QAC/F,EAAE;KACF,CAAA;IAED,MAAM,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAE3B,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAEf,IAAI,MAAM,EAAE,CAAC;QACZ,MAAM,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;QAChC,MAAM,EAAE,CAAC,aAAa,MAAM,EAAE,CAAC,CAAA;IAChC,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;AACxC,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * The injected-geocoder interface for the record-matcher tools. The registry package never imports
7
+ * the heavy runtime (neural parser, WOF resolver, per-state extracts), since `mailwoman` depends on
8
+ * `@mailwoman/entity-resolution` and the reverse import would cycle the workspace graph. Each tool instead
9
+ * takes an {@linkcode EvalGeocoderFactory} the CLI command constructs from
10
+ * `mailwoman/geocode-core` (see `mailwoman/commands/registry/run.tsx`).
11
+ */
12
+ import type { CaseNormalization } from "@mailwoman/core/pipeline";
13
+ import type { ColumnMapping, GeocodeAddress, SourceRecord } from "#index";
14
+ /**
15
+ * The raw single-address geocode surface used by the probe tools, mirroring
16
+ * `mailwoman/geocode-core`'s wire shape.
17
+ */
18
+ export interface EvalGeocodeResult {
19
+ lat: number | null;
20
+ lon: number | null;
21
+ /**
22
+ * Wire key that mirrors `GeocodeResult.resolution_tier`.
23
+ */
24
+ resolution_tier?: string | null;
25
+ }
26
+ /**
27
+ * A constructed geocoder: the matcher's ingest interface, the raw geocode and the handle release.
28
+ */
29
+ export interface EvalGeocoder extends Disposable {
30
+ /**
31
+ * The matcher's ingest interface (parse and geocode to `PostalAddress`),
32
+ * built through `geocodeAddressVia`.
33
+ */
34
+ geocodeAddress: GeocodeAddress;
35
+ /**
36
+ * Raw single-address geocode returning lat, lon and resolution tier.
37
+ */
38
+ geocode: (address: string) => Promise<EvalGeocodeResult>;
39
+ }
40
+ /**
41
+ * Per-construction toggles a tool may need to control (the command owns model/WOF/data-root wiring).
42
+ */
43
+ export interface EvalGeocoderInit {
44
+ /**
45
+ * All-caps case normalization.
46
+ *
47
+ * `nppes-benchmark --legacy-join` passes `"preserve"` for the A/B.
48
+ *
49
+ * @defaultValue `"title-case"`
50
+ */
51
+ caseNormalization?: CaseNormalization;
52
+ }
53
+ /**
54
+ * Build a geocoder on demand.
55
+ *
56
+ * Tools construct it late and dispose it as soon as geocoding is done.
57
+ */
58
+ export type EvalGeocoderFactory = (init?: EvalGeocoderInit) => Promise<EvalGeocoder>;
59
+ /**
60
+ * The threaded geocode surface (`mailwoman/geocode-stream` behind the interface)
61
+ * for `nppes-dedup-benchmark --parallel-geocode`.
62
+ * It yields enriched records in completion order.
63
+ */
64
+ export type EvalGeocodeStream = (records: SourceRecord[], opts: {
65
+ mapping: ColumnMapping;
66
+ concurrency: number;
67
+ }) => AsyncIterable<SourceRecord>;
68
+ //# sourceMappingURL=eval-geocoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eval-geocoder.d.ts","sourceRoot":"","sources":["../../tools/eval-geocoder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAEzE;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IACjC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,UAAU;IAC/C;;;OAGG;IACH,cAAc,EAAE,cAAc,CAAA;IAC9B;;OAEG;IACH,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAA;CAIxD;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;CACrC;AAED;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,YAAY,CAAC,CAAA;AAEpF;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC/B,OAAO,EAAE,YAAY,EAAE,EACvB,IAAI,EAAE;IAAE,OAAO,EAAE,aAAa,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,KACjD,aAAa,CAAC,YAAY,CAAC,CAAA"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * The injected-geocoder interface for the record-matcher tools. The registry package never imports
7
+ * the heavy runtime (neural parser, WOF resolver, per-state extracts), since `mailwoman` depends on
8
+ * `@mailwoman/entity-resolution` and the reverse import would cycle the workspace graph. Each tool instead
9
+ * takes an {@linkcode EvalGeocoderFactory} the CLI command constructs from
10
+ * `mailwoman/geocode-core` (see `mailwoman/commands/registry/run.tsx`).
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=eval-geocoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eval-geocoder.js","sourceRoot":"","sources":["../../tools/eval-geocoder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Admin-tier wrong-region probe. When no street extract covers an address, the admin cascade can
7
+ * resolve the locality by name and, when the region or postcode constraint is weak, pick the
8
+ * population-dominant foreign namesake instead of the in-state Texas city. This probes a curated
9
+ * set of TX namesake cities, with and without ZIP. It flags any result outside the Texas bounding
10
+ * box.
11
+ *
12
+ * Run: `mailwoman registry scorer-eval namesake-probe`
13
+ */
14
+ import type { EvalGeocoderFactory } from "#tools/eval-geocoder";
15
+ /**
16
+ * Options for {@linkcode geocoderNamesakeProbe}.
17
+ */
18
+ export interface GeocoderNamesakeProbeOptions {
19
+ /**
20
+ * The injected geocoder factory.
21
+ *
22
+ * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
23
+ */
24
+ createGeocoder: EvalGeocoderFactory;
25
+ }
26
+ /**
27
+ * Probe a curated set of TX namesake cities and print one line per variant to stdout.
28
+ */
29
+ export declare function geocoderNamesakeProbe(options: GeocoderNamesakeProbeOptions, report?: (line: string) => void): Promise<{
30
+ wrongRegion: number;
31
+ total: number;
32
+ }>;
33
+ //# sourceMappingURL=namesake-probe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namesake-probe.d.ts","sourceRoot":"","sources":["../../../tools/geocoder/namesake-probe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAG/D;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC5C;;;;OAIG;IACH,cAAc,EAAE,mBAAmB,CAAA;CACnC;AAgBD;;GAEG;AACH,wBAAsB,qBAAqB,CAC1C,OAAO,EAAE,4BAA4B,EACrC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC7B,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAuCjD"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Admin-tier wrong-region probe. When no street extract covers an address, the admin cascade can
7
+ * resolve the locality by name and, when the region or postcode constraint is weak, pick the
8
+ * population-dominant foreign namesake instead of the in-state Texas city. This probes a curated
9
+ * set of TX namesake cities, with and without ZIP. It flags any result outside the Texas bounding
10
+ * box.
11
+ *
12
+ * Run: `mailwoman registry scorer-eval namesake-probe`
13
+ */
14
+ import { haversine } from "@mailwoman/spatial/geometries/point/distance";
15
+ import { inTXBBOX } from "#tools/shared";
16
+ /**
17
+ * TX namesake cities with their real Texas coordinates + the famous foreign/other namesake to watch for.
18
+ */
19
+ const CASES = [
20
+ { city: "Paris", zip: "75460", tx: [33.66, -95.55], namesake: "Paris, France (48.85, 2.35)" },
21
+ { city: "Athens", zip: "75751", tx: [32.2, -95.85], namesake: "Athens, Greece (37.98, 23.72)" },
22
+ { city: "Palestine", zip: "75801", tx: [31.76, -95.63], namesake: "Palestine, Levant (31.9, 35.2)" },
23
+ { city: "Italy", zip: "76651", tx: [32.18, -96.88], namesake: "Italy, the country (~42, 12)" },
24
+ { city: "Naples", zip: "75568", tx: [33.2, -94.68], namesake: "Naples, Italy (40.85, 14.27)" },
25
+ { city: "Dublin", zip: "76446", tx: [32.08, -98.34], namesake: "Dublin, Ireland (53.35, -6.26)" },
26
+ { city: "Nazareth", zip: "79063", tx: [34.54, -102.1], namesake: "Nazareth, Israel (32.7, 35.3)" },
27
+ { city: "Odessa", zip: "79761", tx: [31.85, -102.37], namesake: "Odessa, Ukraine (46.48, 30.72)" },
28
+ ];
29
+ /**
30
+ * Probe a curated set of TX namesake cities and print one line per variant to stdout.
31
+ */
32
+ export async function geocoderNamesakeProbe(options, report) {
33
+ report?.("[A] building the geocoder…");
34
+ const geocoder = await options.createGeocoder();
35
+ const geo = geocoder.geocode;
36
+ report?.("[B] probing TX namesake cities (with ZIP / without ZIP)…\n");
37
+ let wrongRegion = 0;
38
+ let total = 0;
39
+ for (const c of CASES) {
40
+ for (const variant of [`${c.city}, TX ${c.zip}`, `${c.city}, TX`, `${c.city}, Texas`]) {
41
+ total++;
42
+ const g = await geo(variant);
43
+ if (g.lat === null || g.lon === null) {
44
+ console.log(` ✗ "${variant}" → UNPLACED`);
45
+ continue;
46
+ }
47
+ const ok = inTXBBOX(g.lat, g.lon);
48
+ const km = haversine(c.tx[0], c.tx[1], g.lat, g.lon);
49
+ if (!ok) {
50
+ wrongRegion++;
51
+ }
52
+ console.log(` ${ok ? "✓" : "✗ WRONG-REGION"} "${variant}" → ${g.lat.toFixed(3)},${g.lon.toFixed(3)} ` +
53
+ `[${g.resolution_tier ?? "?"}] ${km > 100 ? `${km.toFixed(0)}km off TX (cf ${c.namesake})` : `${(km * 1000).toFixed(0)}m off`}`);
54
+ }
55
+ }
56
+ geocoder[Symbol.dispose]();
57
+ console.log(`\n ${wrongRegion}/${total} variants resolved OUTSIDE Texas (wrong-region).`);
58
+ return { wrongRegion, total };
59
+ }
60
+ //# sourceMappingURL=namesake-probe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namesake-probe.js","sourceRoot":"","sources":["../../../tools/geocoder/namesake-probe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,8CAA8C,CAAA;AAGxE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAcxC;;GAEG;AACH,MAAM,KAAK,GAAiF;IAC3F,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,6BAA6B,EAAE;IAC7F,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,+BAA+B,EAAE;IAC/F,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,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AAC,OAAO,EAAE,CACjI,CAAA;QACF,CAAC;IACF,CAAC;IAED,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAA;IAE1B,OAAO,CAAC,GAAG,CAAC,OAAO,WAAW,IAAI,KAAK,kDAAkD,CAAC,CAAA;IAE1F,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAA;AAC9B,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Geocoder validation against provided coordinates. TX HHSC's nursing-facilities registry ships
7
+ * a `Geo Location` (`lat,lon`) per facility alongside its physical address. Geocode the address
8
+ * with mailwoman's parser and resolver, then measure the great-circle delta to the provided point,
9
+ * broken down by resolution tier.
10
+ *
11
+ * The provided coordinate is treated as ground truth for this eval, with the caveat that it is
12
+ * itself a third-party geocode of unknown provenance. A large delta is a discrepancy to inspect
13
+ * rather than automatically our error.
14
+ *
15
+ * Run: `mailwoman registry scorer-eval vs-provided-coords [--max 1176] [--wof <admin.db>]
16
+ * [--data-root <dir>] [--out-md docs/articles/evals/resolver-geo/<date>-...md]`
17
+ */
18
+ import type { EvalGeocoderFactory } from "#tools/eval-geocoder";
19
+ /**
20
+ * Options for {@linkcode geocoderVsProvidedCoords}.
21
+ */
22
+ export interface GeocoderVsProvidedCoordsOptions {
23
+ /**
24
+ * The injected geocoder factory.
25
+ *
26
+ * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
27
+ */
28
+ createGeocoder: EvalGeocoderFactory;
29
+ /**
30
+ * Record-matcher sources directory.
31
+ *
32
+ * @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
33
+ */
34
+ sources?: string;
35
+ /**
36
+ * Facilities geocoded.
37
+ *
38
+ * @defaultValue `2000`
39
+ */
40
+ max?: number;
41
+ /**
42
+ * Also write the markdown report here.
43
+ */
44
+ outMd?: string;
45
+ }
46
+ /**
47
+ * Geocode each facility's physical address and measure the delta to its provided
48
+ * coordinate, then emit the report to stdout.
49
+ */
50
+ export declare function geocoderVsProvidedCoords(options: GeocoderVsProvidedCoordsOptions, report?: (line: string) => void): Promise<{
51
+ markdown: string;
52
+ }>;
53
+ //# sourceMappingURL=vs-provided-coords.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vs-provided-coords.d.ts","sourceRoot":"","sources":["../../../tools/geocoder/vs-provided-coords.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAUH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAa/D;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC/C;;;;OAIG;IACH,cAAc,EAAE,mBAAmB,CAAA;IACnC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAqCD;;;GAGG;AACH,wBAAsB,wBAAwB,CAC7C,OAAO,EAAE,+BAA+B,EACxC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC7B,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CA0H/B"}