@mailwoman/registry 10.0.0 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/README.md +11 -14
  2. package/lib/address-key.ts +14 -10
  3. package/lib/geocode-handler.ts +7 -5
  4. package/lib/geojson.ts +13 -7
  5. package/lib/ingest.ts +70 -92
  6. package/lib/learned-scorer.ts +38 -44
  7. package/lib/map-html.ts +26 -72
  8. package/lib/models/crosssource-gbt-en-us.ts +9 -7
  9. package/lib/models/dedup-gbt-en-us.ts +9 -8
  10. package/lib/models/org-crosssource-gbt-en-us.ts +10 -8
  11. package/lib/reconcile.ts +45 -54
  12. package/lib/resolve.ts +187 -130
  13. package/lib/types.ts +35 -29
  14. package/out/address-key.d.ts +14 -10
  15. package/out/address-key.d.ts.map +1 -1
  16. package/out/address-key.js +14 -10
  17. package/out/address-key.js.map +1 -1
  18. package/out/geocode-handler.d.ts +6 -4
  19. package/out/geocode-handler.d.ts.map +1 -1
  20. package/out/geocode-handler.js +7 -5
  21. package/out/geocode-handler.js.map +1 -1
  22. package/out/geojson.d.ts +9 -5
  23. package/out/geojson.d.ts.map +1 -1
  24. package/out/geojson.js +13 -7
  25. package/out/geojson.js.map +1 -1
  26. package/out/ingest.d.ts +49 -76
  27. package/out/ingest.d.ts.map +1 -1
  28. package/out/ingest.js +37 -62
  29. package/out/ingest.js.map +1 -1
  30. package/out/learned-scorer.d.ts +29 -26
  31. package/out/learned-scorer.d.ts.map +1 -1
  32. package/out/learned-scorer.js +31 -39
  33. package/out/learned-scorer.js.map +1 -1
  34. package/out/map-html.d.ts +13 -32
  35. package/out/map-html.d.ts.map +1 -1
  36. package/out/map-html.js +11 -64
  37. package/out/map-html.js.map +1 -1
  38. package/out/models/crosssource-gbt-en-us.d.ts +9 -7
  39. package/out/models/crosssource-gbt-en-us.d.ts.map +1 -1
  40. package/out/models/crosssource-gbt-en-us.js +9 -7
  41. package/out/models/crosssource-gbt-en-us.js.map +1 -1
  42. package/out/models/dedup-gbt-en-us.d.ts +9 -8
  43. package/out/models/dedup-gbt-en-us.d.ts.map +1 -1
  44. package/out/models/dedup-gbt-en-us.js +9 -8
  45. package/out/models/dedup-gbt-en-us.js.map +1 -1
  46. package/out/models/org-crosssource-gbt-en-us.d.ts +10 -8
  47. package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -1
  48. package/out/models/org-crosssource-gbt-en-us.js +10 -8
  49. package/out/models/org-crosssource-gbt-en-us.js.map +1 -1
  50. package/out/reconcile.d.ts +36 -50
  51. package/out/reconcile.d.ts.map +1 -1
  52. package/out/reconcile.js +18 -42
  53. package/out/reconcile.js.map +1 -1
  54. package/out/resolve.d.ts +152 -91
  55. package/out/resolve.d.ts.map +1 -1
  56. package/out/resolve.js +67 -68
  57. package/out/resolve.js.map +1 -1
  58. package/out/tools/coverage-reconciliation.d.ts +23 -23
  59. package/out/tools/coverage-reconciliation.d.ts.map +1 -1
  60. package/out/tools/coverage-reconciliation.js +15 -26
  61. package/out/tools/coverage-reconciliation.js.map +1 -1
  62. package/out/tools/cross/dataset-correlation.d.ts +23 -27
  63. package/out/tools/cross/dataset-correlation.d.ts.map +1 -1
  64. package/out/tools/cross/dataset-correlation.js +9 -61
  65. package/out/tools/cross/dataset-correlation.js.map +1 -1
  66. package/out/tools/cross/source-threshold-sweep.d.ts +20 -26
  67. package/out/tools/cross/source-threshold-sweep.d.ts.map +1 -1
  68. package/out/tools/cross/source-threshold-sweep.js +14 -40
  69. package/out/tools/cross/source-threshold-sweep.js.map +1 -1
  70. package/out/tools/dedup-ceiling.d.ts +23 -26
  71. package/out/tools/dedup-ceiling.d.ts.map +1 -1
  72. package/out/tools/dedup-ceiling.js +22 -41
  73. package/out/tools/dedup-ceiling.js.map +1 -1
  74. package/out/tools/eval-geocoder.d.ts +25 -16
  75. package/out/tools/eval-geocoder.d.ts.map +1 -1
  76. package/out/tools/eval-geocoder.js +5 -6
  77. package/out/tools/eval-geocoder.js.map +1 -1
  78. package/out/tools/geocoder/namesake-probe.d.ts +9 -8
  79. package/out/tools/geocoder/namesake-probe.d.ts.map +1 -1
  80. package/out/tools/geocoder/namesake-probe.js +6 -7
  81. package/out/tools/geocoder/namesake-probe.js.map +1 -1
  82. package/out/tools/geocoder/vs-provided-coords.d.ts +18 -15
  83. package/out/tools/geocoder/vs-provided-coords.d.ts.map +1 -1
  84. package/out/tools/geocoder/vs-provided-coords.js +30 -27
  85. package/out/tools/geocoder/vs-provided-coords.js.map +1 -1
  86. package/out/tools/gold-set-sample.d.ts +27 -18
  87. package/out/tools/gold-set-sample.d.ts.map +1 -1
  88. package/out/tools/gold-set-sample.js +18 -22
  89. package/out/tools/gold-set-sample.js.map +1 -1
  90. package/out/tools/learned/scorer/clustering-eval.d.ts +30 -27
  91. package/out/tools/learned/scorer/clustering-eval.d.ts.map +1 -1
  92. package/out/tools/learned/scorer/clustering-eval.js +28 -38
  93. package/out/tools/learned/scorer/clustering-eval.js.map +1 -1
  94. package/out/tools/learned/scorer/crossstate-eval.d.ts +24 -18
  95. package/out/tools/learned/scorer/crossstate-eval.d.ts.map +1 -1
  96. package/out/tools/learned/scorer/crossstate-eval.js +19 -25
  97. package/out/tools/learned/scorer/crossstate-eval.js.map +1 -1
  98. package/out/tools/learned/scorer/eval.d.ts +26 -39
  99. package/out/tools/learned/scorer/eval.d.ts.map +1 -1
  100. package/out/tools/learned/scorer/eval.js +11 -71
  101. package/out/tools/learned/scorer/eval.js.map +1 -1
  102. package/out/tools/matcher-scale.d.ts +12 -17
  103. package/out/tools/matcher-scale.d.ts.map +1 -1
  104. package/out/tools/matcher-scale.js +11 -29
  105. package/out/tools/matcher-scale.js.map +1 -1
  106. package/out/tools/nppes/dedup-benchmark.d.ts +22 -41
  107. package/out/tools/nppes/dedup-benchmark.d.ts.map +1 -1
  108. package/out/tools/nppes/dedup-benchmark.js +21 -67
  109. package/out/tools/nppes/dedup-benchmark.js.map +1 -1
  110. package/out/tools/nppes/org-name.d.ts +5 -11
  111. package/out/tools/nppes/org-name.d.ts.map +1 -1
  112. package/out/tools/nppes/org-name.js +2 -9
  113. package/out/tools/nppes/org-name.js.map +1 -1
  114. package/out/tools/nppes/overmerge-packet.d.ts +15 -11
  115. package/out/tools/nppes/overmerge-packet.d.ts.map +1 -1
  116. package/out/tools/nppes/overmerge-packet.js +6 -7
  117. package/out/tools/nppes/overmerge-packet.js.map +1 -1
  118. package/out/tools/nppes/report.d.ts +17 -13
  119. package/out/tools/nppes/report.d.ts.map +1 -1
  120. package/out/tools/nppes/report.js +6 -14
  121. package/out/tools/nppes/report.js.map +1 -1
  122. package/out/tools/nppes/sample.d.ts +29 -18
  123. package/out/tools/nppes/sample.d.ts.map +1 -1
  124. package/out/tools/nppes/sample.js +24 -28
  125. package/out/tools/nppes/sample.js.map +1 -1
  126. package/out/tools/nppes/scoring.d.ts +7 -6
  127. package/out/tools/nppes/scoring.d.ts.map +1 -1
  128. package/out/tools/nppes/scoring.js +6 -5
  129. package/out/tools/nppes/scoring.js.map +1 -1
  130. package/out/tools/nppes/settings.d.ts +10 -7
  131. package/out/tools/nppes/settings.d.ts.map +1 -1
  132. package/out/tools/nppes/settings.js +16 -16
  133. package/out/tools/nppes/settings.js.map +1 -1
  134. package/out/tools/nppes/truth-grains.d.ts +36 -23
  135. package/out/tools/nppes/truth-grains.d.ts.map +1 -1
  136. package/out/tools/nppes/truth-grains.js +36 -20
  137. package/out/tools/nppes/truth-grains.js.map +1 -1
  138. package/out/tools/shared.d.ts +68 -72
  139. package/out/tools/shared.d.ts.map +1 -1
  140. package/out/tools/shared.js +50 -67
  141. package/out/tools/shared.js.map +1 -1
  142. package/out/tools/train/cross-gbt.d.ts +37 -26
  143. package/out/tools/train/cross-gbt.d.ts.map +1 -1
  144. package/out/tools/train/cross-gbt.js +14 -25
  145. package/out/tools/train/cross-gbt.js.map +1 -1
  146. package/out/tools/train/gbt.d.ts +36 -20
  147. package/out/tools/train/gbt.d.ts.map +1 -1
  148. package/out/tools/train/gbt.js +27 -31
  149. package/out/tools/train/gbt.js.map +1 -1
  150. package/out/tools/train/org-cross-gbt.d.ts +38 -24
  151. package/out/tools/train/org-cross-gbt.d.ts.map +1 -1
  152. package/out/tools/train/org-cross-gbt.js +18 -22
  153. package/out/tools/train/org-cross-gbt.js.map +1 -1
  154. package/out/tools/txhhsc-to-oarow.d.ts +14 -9
  155. package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
  156. package/out/tools/txhhsc-to-oarow.js +16 -15
  157. package/out/tools/txhhsc-to-oarow.js.map +1 -1
  158. package/out/tools/viz/browser.d.ts +6 -5
  159. package/out/tools/viz/browser.d.ts.map +1 -1
  160. package/out/tools/viz/browser.js +6 -5
  161. package/out/tools/viz/browser.js.map +1 -1
  162. package/out/tools/viz/cross-dataset-map.d.ts +7 -4
  163. package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
  164. package/out/tools/viz/cross-dataset-map.js +9 -6
  165. package/out/tools/viz/cross-dataset-map.js.map +1 -1
  166. package/out/tools/viz/geocode-first-surface.d.ts +11 -5
  167. package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
  168. package/out/tools/viz/geocode-first-surface.js +16 -11
  169. package/out/tools/viz/geocode-first-surface.js.map +1 -1
  170. package/out/tools/viz/render/map.d.ts +5 -5
  171. package/out/tools/viz/render/map.d.ts.map +1 -1
  172. package/out/tools/viz/render/map.js +6 -5
  173. package/out/tools/viz/render/map.js.map +1 -1
  174. package/out/tools/viz/{render/index.d.ts → render.d.ts} +13 -9
  175. package/out/tools/viz/render.d.ts.map +1 -0
  176. package/out/tools/viz/{render/index.js → render.js} +9 -8
  177. package/out/tools/viz/render.js.map +1 -0
  178. package/out/tools/viz/source-provenance-map.d.ts +19 -7
  179. package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
  180. package/out/tools/viz/source-provenance-map.js +11 -8
  181. package/out/tools/viz/source-provenance-map.js.map +1 -1
  182. package/out/tools/viz/yardstick-figure.d.ts +2 -21
  183. package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
  184. package/out/tools/viz/yardstick-figure.js +3 -39
  185. package/out/tools/viz/yardstick-figure.js.map +1 -1
  186. package/out/types.d.ts +35 -29
  187. package/out/types.d.ts.map +1 -1
  188. package/out/types.js +2 -2
  189. package/out/types.js.map +1 -1
  190. package/package.json +42 -185
  191. package/{lib/tools → tools}/coverage-reconciliation.ts +27 -30
  192. package/{lib/tools → tools}/cross/dataset-correlation.ts +35 -73
  193. package/{lib/tools → tools}/cross/source-threshold-sweep.ts +29 -46
  194. package/{lib/tools → tools}/dedup-ceiling.ts +34 -45
  195. package/tools/eval-geocoder.ts +77 -0
  196. package/{lib/tools → tools}/geocoder/namesake-probe.ts +9 -8
  197. package/{lib/tools → tools}/geocoder/vs-provided-coords.ts +40 -31
  198. package/{lib/tools → tools}/gold-set-sample.ts +35 -29
  199. package/{lib/tools → tools}/learned/scorer/clustering-eval.ts +49 -45
  200. package/{lib/tools → tools}/learned/scorer/crossstate-eval.ts +34 -30
  201. package/{lib/tools → tools}/learned/scorer/eval.ts +39 -78
  202. package/{lib/tools → tools}/matcher-scale.ts +21 -33
  203. package/{lib/tools → tools}/nppes/dedup-benchmark.ts +39 -83
  204. package/tools/nppes/org-name.ts +15 -0
  205. package/{lib/tools → tools}/nppes/overmerge-packet.ts +16 -12
  206. package/{lib/tools → tools}/nppes/report.ts +32 -25
  207. package/{lib/tools → tools}/nppes/sample.ts +43 -38
  208. package/{lib/tools → tools}/nppes/scoring.ts +7 -6
  209. package/{lib/tools → tools}/nppes/settings.ts +16 -16
  210. package/{lib/tools → tools}/nppes/truth-grains.ts +46 -26
  211. package/{lib/tools → tools}/shared.ts +79 -98
  212. package/{lib/tools → tools}/train/cross-gbt.ts +39 -34
  213. package/{lib/tools → tools}/train/gbt.ts +55 -41
  214. package/{lib/tools → tools}/train/org-cross-gbt.ts +40 -30
  215. package/{lib/tools → tools}/txhhsc-to-oarow.ts +24 -18
  216. package/{lib/tools → tools}/viz/browser.ts +6 -5
  217. package/{lib/tools → tools}/viz/cross-dataset-map.ts +15 -9
  218. package/{lib/tools → tools}/viz/geocode-first-surface.ts +29 -17
  219. package/{lib/tools → tools}/viz/render/map.ts +7 -6
  220. package/{lib/tools/viz/render/index.ts → tools/viz/render.ts} +16 -11
  221. package/{lib/tools → tools}/viz/source-provenance-map.ts +30 -15
  222. package/{lib/tools → tools}/viz/yardstick-figure.ts +6 -43
  223. package/lib/tools/eval-geocoder.ts +0 -67
  224. package/lib/tools/index.ts +0 -31
  225. package/lib/tools/nppes/org-name.ts +0 -23
  226. package/out/tools/index.d.ts +0 -31
  227. package/out/tools/index.d.ts.map +0 -1
  228. package/out/tools/index.js +0 -31
  229. package/out/tools/index.js.map +0 -1
  230. package/out/tools/viz/render/index.d.ts.map +0 -1
  231. package/out/tools/viz/render/index.js.map +0 -1
package/README.md CHANGED
@@ -10,7 +10,7 @@ calibrated, label-free matcher.
10
10
  ```ts
11
11
  import { ingestRows, resolveEntities, toGeoJSON } from "@mailwoman/registry"
12
12
 
13
- // 1. Ingest — rows → normalized SourceRecords. The mapping is POSITIONAL (arg 2), not a field of the
13
+ // 1. Ingest — rows → normalized SourceRecords. The mapping is POSITIONAL (arg 2) rather than a field of the
14
14
  // options object, and `geocodeAddress` belongs here: each address is resolved as it is ingested.
15
15
  const records = await ingestRows(
16
16
  rows,
@@ -19,7 +19,7 @@ const records = await ingestRows(
19
19
  )
20
20
 
21
21
  // 2. Resolve — block → score → cluster with geo-first defaults. SYNCHRONOUS, and it returns a
22
- // ResolveResult, not a bare array: `entities` alongside the pair counts blocking produced.
22
+ // ResolveResult rather than a bare array: `entities` alongside the pair counts blocking produced.
23
23
  const { entities, candidatePairs, droppedBlocks } = resolveEntities(records)
24
24
 
25
25
  // 3. Export — GeoJSON for QGIS. Entities with no resolved coordinate are skipped, so the feature
@@ -47,7 +47,6 @@ import { inferMapping, ingestRows, normalizeCSV, parseCSV } from "@mailwoman/reg
47
47
  // parseCSV(text): Record<string, string>[]
48
48
  // inferMapping(header): ColumnMapping
49
49
  // normalizeCSV(path, { mapping, delimiter? }): AsyncGenerator<SourceRecord> — streams, does NOT geocode
50
-
51
50
  // Resolve — run the full matcher pipeline
52
51
  import { resolveEntities } from "@mailwoman/registry"
53
52
  // resolveEntities(records, config?): ResolveResult
@@ -55,27 +54,25 @@ import { resolveEntities } from "@mailwoman/registry"
55
54
  // config: { model?, blockingKeys?, threshold?, maxBlockSize?, trainEM?, addressFrequency?,
56
55
  // collapseSpatial?, requireCorroboration?, usePhone?, linkage?, discriminators?,
57
56
  // exactDiscriminators?, scorer?, learnedScorer? }
58
-
59
57
  // Export — GeoJSON, MapLibre HTML, reconciliation reports
60
58
  import { reconcile, toGeoJSON, toMapHTML } from "@mailwoman/registry"
61
-
62
59
  // Learned scorer — pre-trained GBT for single-dataset dedup, default-on
63
60
  import { DEDUP_GBT_META, DEDUP_GBT_MODEL } from "@mailwoman/registry"
64
61
  ```
65
62
 
66
- `geocodeAddress` is an `ingestRows` option, not a `resolveEntities` one — coordinates have to exist
63
+ `geocodeAddress` is an `ingestRows` option rather than a `resolveEntities` one — coordinates have to exist
67
64
  before blocking can use them.
68
65
 
69
66
  ## Default configuration
70
67
 
71
68
  `resolveEntities` ships with these defaults:
72
69
 
73
- - **Blocking keys:** geo-cell on the resolved coordinate (0.05°, neighbours expanded) + canonical
70
+ - **The blocking keys:** geo-cell on the resolved coordinate (0.05°, neighbors expanded) + canonical
74
71
  address + phone + email
75
- - **Scoring model:** Fellegi-Sunter with label-free EM, term frequency adjustment
72
+ - **The scoring model:** Fellegi-Sunter with label-free EM, term frequency adjustment
76
73
  - **Learned scorer:** the bundled `DEDUP_GBT_MODEL`, on by default for single-dataset dedup
77
74
  - **Threshold:** `DEDUP_GBT_META.recommendedThreshold` (2.8324) while the bundled model is active,
78
- otherwise 0. The unit is the GBT's own logit, not a Fellegi-Sunter match weight in bits and not a
75
+ otherwise 0. The unit is the GBT's own logit rather than a Fellegi-Sunter match weight in bits and not a
79
76
  probability, so a 0-to-1 value is a category error here. Higher is stricter.
80
77
  - **Linkage:** single (connected components), with average linkage available for the over-merge case
81
78
 
@@ -92,16 +89,16 @@ mailwoman registry --sources tx-nppes.json --reconcile tx-fcc.json --resolve-db
92
89
  ```
93
90
 
94
91
  `--resolve-db` (or `$MAILWOMAN_WOF_DB`) is required to BOOT, and is then ignored whenever
95
- `$MAILWOMAN_CANDIDATE_DB` is set. `resolveWOFPath` throws before anything opens; `createResolverBackend`
92
+ `$MAILWOMAN_CANDIDATE_DB` is set. `requireCommandWOFPath` throws before anything opens; `createResolverBackend`
96
93
  then prefers the candidate backend and never touches the WOF path (`run.tsx`'s own inline comment states
97
94
  this correctly: "`$MAILWOMAN_CANDIDATE_DB` → the demo-parity candidate backend; else FTS over wofPath").
98
95
  A nonexistent path satisfies that requirement.
99
96
 
100
- So: set `$MAILWOMAN_CANDIDATE_DB` and pass anything to `--resolve-db`. Do NOT pass `candidate.db` to
101
- `--resolve-db` with the environment variable unset — the flag is believed on that path, and the admin
97
+ So: set `$MAILWOMAN_CANDIDATE_DB` and pass anything to `--resolve-db`. Do not pass `candidate.db` to
98
+ `--resolve-db` with the environment variable unset. The flag is believed on that path, and the admin
102
99
  backend queries `place_search`/`spr`, which a candidate gazetteer does not have.
103
100
 
104
- Requiring an argument in order to discard it is a defect in this command. Documented rather than fixed.
101
+ An argument required only to discard it is a defect in this command. Documented rather than fixed.
105
102
 
106
103
  Two CLI defaults differ from the library defaults: `--threshold` defaults to `0`, which is the
107
104
  Fellegi-Sunter baseline rather than the bundled model's calibrated 2.8324, and `--train-em` is on.
@@ -115,4 +112,4 @@ Fellegi-Sunter baseline rather than the bundled model's calibrated 2.8324, and `
115
112
 
116
113
  ## License
117
114
 
118
- [AGPL-3.0-only](https://www.gnu.org/licenses/agpl-3.0.html)
115
+ [AGPL-3.0-only](https://www.gnu.org/licenses/AGPL-3.0.html)
@@ -3,13 +3,13 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * The address-id consumer for the matcher (#259). Derives a stable {@link PostalAddressID} from a
7
- * resolved {@link SourceRecord} and exposes it as a blocking key — the deterministic,
6
+ * The address-id consumer for the matcher. Derives a stable {@link PostalAddressID} from a
7
+ * resolved {@link SourceRecord} and exposes it as a blocking key, the deterministic
8
8
  * exact-canonical-address complement to the fuzzy Fellegi-Sunter / GBT scoring. Two uses:
9
9
  *
10
- * - **As a pre-dedup / join key:** `GROUP BY postalAddressID(record)` collapses records that resolve
11
- * to the same place AND share a canonical address with NO scoring at all — the cheap, certain
12
- * slice of dedup before the matcher does the fuzzy rest.
10
+ * - **As a pre-dedup / join key:** `group BY postalAddressID(record)` collapses records that resolve
11
+ * to the same place and share a canonical address with no scoring at all. That is the cheap,
12
+ * certain part of dedup before the matcher does the fuzzy rest.
13
13
  * - **As a blocking key:** {@link addressIDBlockingKey} adds the address-id to the blocking union, so
14
14
  * records sharing one are guaranteed to be compared.
15
15
  */
@@ -20,9 +20,10 @@ import { type BlockingKey, exactKey } from "@mailwoman/match"
20
20
  import type { SourceRecord } from "#types"
21
21
 
22
22
  /**
23
- * The stable address primary key for a record, or null when it isn't geocoded (no coordinate → no locality cell) or
24
- * carries no raw address to hash. Uses the resolved coordinate + the raw address; the state prefix is plucked from the
25
- * address when present.
23
+ * The stable address primary key for a record, or null when it is not geocoded
24
+ * (no coordinate means no locality cell) or includes no raw address to hash.
25
+ *
26
+ * The state prefix is plucked from the address when present.
26
27
  */
27
28
  export function postalAddressID(record: SourceRecord): PostalAddressID | null {
28
29
  const coordinate = record.address?.geocode?.coordinate
@@ -34,8 +35,11 @@ export function postalAddressID(record: SourceRecord): PostalAddressID | null {
34
35
  }
35
36
 
36
37
  /**
37
- * A blocking key on the {@link postalAddressID} — records that resolve to the same place with the same canonical address
38
- * block together. Add it to {@link defaultBlockingKeys}'s union when an exact address join should never be missed.
38
+ * A blocking key on the {@link postalAddressID}.
39
+ *
40
+ * Records that resolve to the same place with the same canonical address block together.
41
+ *
42
+ * Add it to {@link defaultBlockingKeys}'s union when an exact address join should never be missed.
39
43
  */
40
44
  export function addressIDBlockingKey(): BlockingKey<SourceRecord> {
41
45
  return exactKey((record) => postalAddressID(record))
@@ -11,10 +11,12 @@ import { type ColumnMapping, type GeocodeAddress, pick } from "#ingest"
11
11
  import type { SourceRecord } from "#types"
12
12
 
13
13
  /**
14
- * Build the handler `geocodeStream` runs per normalized record: recompute the joined address string from `record.raw` +
15
- * `mapping.address` (the worker can't receive the original closure), geocode it via `geocode`, and attach the result.
16
- * Records with no mapped address pass through untouched (no geocode call). The default separator matches
17
- * {@link ingestRow}'s `addressSeparator`.
14
+ * Build the handler `geocodeStream` runs per normalized record: recompute the joined address
15
+ * string from `record.raw` + `mapping.address` (the worker can't receive the original closure),
16
+ * geocode it via `geocode`, and attach the result.
17
+ *
18
+ * Records with no mapped address pass through untouched (no geocode call).
19
+ * The default separator matches {@link ingestRow}'s `addressSeparator`.
18
20
  */
19
21
  export function makeGeocodeHandler(
20
22
  geocode: GeocodeAddress,
@@ -28,7 +30,7 @@ export function makeGeocodeHandler(
28
30
 
29
31
  if (!addressValue) return record
30
32
 
31
- const address = (await geocode(addressValue)) ?? undefined
33
+ const address = (await geocode(addressValue)) ?? null
32
34
 
33
35
  return { ...record, address }
34
36
  }
package/lib/geojson.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * Export resolved entities as GeoJSON — the bridge to QGIS and any web map. Each entity becomes a
7
7
  * Point at its resolved coordinate, carrying the properties an analyst needs: how many records
8
- * merged into it, how tightly (cohesion), the canonical name/org/address, and the geocode tier
8
+ * merged into it, how tightly (cohesion), the canonical name/org/address and the geocode tier
9
9
  * (so rooftop-precise entities can be styled apart from admin-centroid guesses). Entities without
10
10
  * a coordinate are omitted (a Point feature needs one).
11
11
  */
@@ -19,12 +19,15 @@ import type { EntityGeoData, ResolvedEntity, SourceRecord } from "#types"
19
19
  * Assemble a display name from a record's parsed person name, if any.
20
20
  */
21
21
  function displayName(record: SourceRecord): string | null {
22
- return formatPersonName(record.name) || null
22
+ return formatPersonName(record.name ?? null) || null
23
23
  }
24
24
 
25
25
  /**
26
- * One entity → one GeoJSON Point feature. `extra` merges over (and may override) the standard properties — the
27
- * reconciliation flow adds its `bucket` and swaps the display name for the representative's org-or-person form.
26
+ * One entity → one GeoJSON Point feature.
27
+ *
28
+ * `extra` merges over (and may override) the standard properties.
29
+ * The reconciliation flow adds its `bucket` and swaps the display name for the
30
+ * representative's org-or-person form.
28
31
  */
29
32
  export function toFeature(
30
33
  entity: ResolvedEntity,
@@ -44,20 +47,23 @@ export function toFeature(
44
47
  recordCount: entity.records.length,
45
48
  cohesion: entity.cohesion,
46
49
  sourceIDs: entity.records.map((r) => r.id),
47
- // Distinct provenance labels the entity's records span — an entity with ≥2 is a cross-dataset link.
50
+ // Distinct provenance labels the entity's records span.
51
+ // An entity with ≥2 is a cross-dataset link.
48
52
  sources: [...new Set(entity.records.map((r) => r.source).filter((s): s is string => !!s))].toSorted(),
49
53
  name: displayName(rep),
50
54
  organization: rep.organization?.canonical ?? null,
51
55
  address: rep.address?.formatted ?? null,
52
56
  geocodeTier: rep.address?.geocode?.tier ?? null,
57
+ bucket: null,
53
58
  ...extra,
54
59
  },
55
60
  }
56
61
  }
57
62
 
58
63
  /**
59
- * Convert resolved entities into a GeoJSON `FeatureCollection` of points, ready for QGIS. Entities with no resolved
60
- * coordinate are skipped.
64
+ * Convert resolved entities into a GeoJSON `FeatureCollection` of points, ready for QGIS.
65
+ *
66
+ * Entities with no resolved coordinate are skipped.
61
67
  */
62
68
  export function toGeoJSON(entities: readonly ResolvedEntity[]): GeoFeatureCollection<PointLiteral, EntityGeoData> {
63
69
  return {
package/lib/ingest.ts CHANGED
@@ -3,42 +3,27 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Ingest — turn messy tabular data (CSV, SQLite, hand-keyed spreadsheets) into normalized
7
- * {@link SourceRecord}s, the front of the cascade.
8
- *
9
- * Two concerns, kept separate:
10
- *
11
- * 1. **Column mapping + normalization** (this is pure): a {@link ColumnMapping} says which column(s)
12
- * hold the name, organization, address, phone, email; each row is normalized with
13
- * `@mailwoman/record` (parse the person name, canonicalize the org). This is deterministic
14
- * and testable with no heavy runtime.
15
- * 2. **Geocoding** (the heavy part) is an injected dependency — a {@link GeocodeAddress} the caller provides.
16
- * Ingest never imports the neural parser, the resolver, or the extracts; it just calls the
17
- * call per address. {@link geocodeAddressVia} builds that geocoder from mailwoman's real parse +
18
- * geocode primitives (which the CLI constructs with the model + data in hand), so the wiring
19
- * is concrete and testable without pinning the heavy runtime into this package.
20
- *
21
- * LLM-assisted column mapping (infer the mapping from a header + samples) is a documented
22
- * fast-follow; the mapping is an explicit input here.
6
+ * Column mapping and normalization are pure. The caller injects geocoding, so this package never imports the neural parser, resolver, or extracts.
23
7
  */
24
8
 
25
9
  import { isPresent } from "@mailwoman/core/objects"
26
10
  import type { AddressGeocode, PostalAddress } from "@mailwoman/record"
27
11
  import { canonicalizeOrganizationName, parsePersonName, toPostalAddress, withGeocode } from "@mailwoman/record"
12
+ import type { PathBuilderLike } from "path-ts"
28
13
  import { type AsyncSequence, CSVSpliterator, Delimiters } from "spliterator"
29
14
 
30
15
  import type { SourceRecord } from "#types"
31
16
 
32
17
  /**
33
- * Resolve a raw address string into a {@link PostalAddress}. The entry point to mailwoman's geocoder.
18
+ * Resolve a raw address string into a {@link PostalAddress}, the entry point to mailwoman's geocoder.
34
19
  */
35
20
  export type GeocodeAddress = (raw: string) => Promise<PostalAddress | null> | PostalAddress | null
36
21
 
37
22
  /**
38
23
  * The column delimiters a tabular source may declare, by name, each the spliterator's own byte.
39
24
  *
40
- * The `satisfies` clause keys every name to a member of spliterator's `Delimiters` const, so a delimiter this map names
41
- * that spliterator no longer ships is a compile error rather than a silently parallel vocabulary.
25
+ * The `satisfies` clause makes a delimiter name spliterator no longer ships a compile error
26
+ * rather than a silently parallel vocabulary.
42
27
  */
43
28
  const COLUMN_DELIMITERS = {
44
29
  comma: Delimiters.Comma,
@@ -60,29 +45,31 @@ export function delimiterFor(path: string): Delimiter {
60
45
  /**
61
46
  * Stream a delimited file's rows lazily as header-keyed objects.
62
47
  *
63
- * Returns the spliterator's own {@linkcode AsyncSequence}: nothing is opened until something iterates, a `take` that is
64
- * satisfied (or a `break` out of `for await`) closes the file handle, and any `map`/`filter` a caller composes fuses
65
- * into the same pull loop. Wrapping this in an `async function*` would cost an async frame per row and take those
66
- * operators away.
48
+ * @returns The spliterator's own {@linkcode AsyncSequence}, whose `map`/`filter`
49
+ * fuse into the same pull loop.
50
+ * An `async function*` wrapper would add an async frame per row and remove those operators.
67
51
  */
68
52
  export function streamRows(
69
- source: string,
53
+ source: PathBuilderLike,
70
54
  opts: { delimiter?: Delimiter } = {}
71
55
  ): AsyncSequence<Record<string, string>> {
72
- return CSVSpliterator.fromAsync<Record<string, string>>(source, {
73
- columnDelimiter: COLUMN_DELIMITERS[opts.delimiter ?? delimiterFor(source)],
74
- // A {@linkcode ColumnMapping} names columns in the PUBLISHER's spelling — `Facility Name`, not
75
- // `facility_name` — so the keys must arrive as the file writes them. The reader's default normalizes.
56
+ const path = source.toString()
57
+
58
+ return CSVSpliterator.fromAsync<Record<string, string>>(path, {
59
+ columnDelimiter: COLUMN_DELIMITERS[opts.delimiter ?? delimiterFor(path)],
60
+ // A {@linkcode ColumnMapping} holds columns in the publisher's spelling rather than a
61
+ // normalized key such as `facility_name`, so the keys must arrive as the file writes them.
62
+ // The reader's default normalizes.
76
63
  normalizeKeys: false,
77
64
  })
78
65
  }
79
66
 
80
67
  /**
81
- * Maps dataset columns to record fields. A field may draw from several columns (joined with spaces).
68
+ * Maps dataset columns to record fields, where a field may draw from several columns joined with spaces.
82
69
  */
83
70
  export interface ColumnMapping {
84
71
  /**
85
- * Column holding a stable row id. Falls back to the row index.
72
+ * Column holding a stable row id, falling back to the row index.
86
73
  */
87
74
  id?: string
88
75
  /**
@@ -95,20 +82,14 @@ export interface ColumnMapping {
95
82
  phone?: string
96
83
  email?: string
97
84
  /**
98
- * Extra secondary-identifier fields → the column(s) to draw each from (joined with spaces). Land on
99
- * `SourceRecord.attributes` under the same key, for the matcher's `discriminators` (authorized-official name,
100
- * taxonomy, license…).
85
+ * Extra secondary-identifier fields mapped to the column(s) to draw each from, landing
86
+ * on `SourceRecord.attributes` under the same key for the matcher's `discriminators`.
101
87
  */
102
88
  attributes?: Record<string, string | string[]>
103
89
  }
104
90
 
105
91
  /**
106
- * Best-effort {@link ColumnMapping} inferred from a header row — the "point it at any CSV" convenience. Each column name
107
- * is matched (case- and punctuation-insensitive, on whole tokens) to a field by keyword, in a precedence that resolves
108
- * the common ambiguities: a dedicated id / phone / email column is claimed before the generic sweep, an org / facility
109
- * column beats a person "name", and address columns (street / city / state / zip…) collect into one multi-column field.
110
- * Imperfect on bespoke headers (an explicit mapping or the LLM-assisted inference #603 is the answer there), but it
111
- * nails tidy and semi-tidy files with no hand-mapping. Unmatched columns are left out.
92
+ * Best-effort {@link ColumnMapping} inferred from a header row, the "point it at any CSV" convenience.
112
93
  */
113
94
  export function inferMapping(header: readonly string[]): ColumnMapping {
114
95
  // Pad to whole-token boundaries so "state" doesn't match inside "statement".
@@ -172,42 +153,40 @@ export function inferMapping(header: readonly string[]): ColumnMapping {
172
153
  */
173
154
  export interface IngestOptions {
174
155
  /**
175
- * The geocoding interface. Without it, records carry name/org but no resolved address.
156
+ * The geocoding interface.
157
+ *
158
+ * Without it records include name/org but have no resolved address.
176
159
  */
177
160
  geocodeAddress?: GeocodeAddress
178
161
  /**
179
- * Separator for joining a multi-column ADDRESS mapping (name/org always join with a space). Default `" "`. Pass `",
180
- * "` to give the parser delimited input (`"214 Main St, Austin, TX 78701"`) instead of a concatenated run (`"214 Main
181
- * St Austin TX 78701"`) — the latter strips the parser's segmentation boundaries and is partly OOD (it also breaks
182
- * all-caps case-normalization; #694). **Default `", "` (#694 flip, validated).** Comma-join is the correct shape for
183
- * an address built from separate columns, and #700 measured it at +15% cross-dataset rooftop (579→667) with no
184
- * comma-less crater. The dedup GBT was trained on the old space-joined coords, so this flip is paired with a GBT
185
- * re-validation (#694). Pass `" "` to restore the legacy space-join for a byte-stable A/B.
162
+ * Separator for joining a multi-column address mapping, comma-join giving the parser
163
+ * delimited input rather than a concatenated run (name/org always join with a space).
164
+ *
165
+ * @defaultValue `", "`
186
166
  */
187
167
  addressSeparator?: string
188
168
  }
189
169
 
190
170
  /**
191
- * Join the named column(s) of a row into a single trimmed string, or undefined if empty.
171
+ * Join the selected columns of a row into a single trimmed string, or null if empty.
192
172
  */
193
- export function pick(row: Record<string, string>, columns?: string | string[], separator = " "): string | undefined {
194
- if (!columns) return undefined
173
+ export function pick(row: Record<string, string>, columns?: string | string[], separator = " "): string | null {
174
+ if (!columns) return null
195
175
  const list = Array.isArray(columns) ? columns : [columns]
196
176
 
197
177
  const value = list
198
- .map((c) => row[c]?.trim())
178
+ .map((c) => row[c])
199
179
  .filter(isPresent)
200
180
  .join(separator)
201
181
  .trim()
202
182
 
203
- return value || undefined
183
+ return value || null
204
184
  }
205
185
 
206
186
  /**
207
- * Normalize one tabular row into a {@link SourceRecord} under a {@link ColumnMapping}: parse the person name,
208
- * canonicalize the org, and (if `opts.geocodeAddress` is provided) geocode the joined address. `id` falls back to the
209
- * caller-supplied row index. Pure aside from the optional geocode interface, so the deterministic normalization can run
210
- * single-threaded (see {@link normalizeCSV}) while geocoding is offloaded (see `geocodeStream`).
187
+ * Normalize one tabular row into a {@link SourceRecord} under a {@link ColumnMapping},
188
+ * pure aside from the optional geocode interface so the deterministic normalization
189
+ * can run single-threaded while geocoding is offloaded.
211
190
  */
212
191
  export async function ingestRow(
213
192
  row: Record<string, string>,
@@ -215,12 +194,12 @@ export async function ingestRow(
215
194
  index: number,
216
195
  opts: IngestOptions = {}
217
196
  ): Promise<SourceRecord> {
218
- const id = (mapping.id ? row[mapping.id]?.trim() : "") || String(index)
197
+ const id = (mapping.id ? row[mapping.id] : "") || String(index)
219
198
  const nameValue = pick(row, mapping.name)
220
199
  const orgValue = pick(row, mapping.organization)
221
200
  const addressValue = pick(row, mapping.address, opts.addressSeparator ?? ", ")
222
201
 
223
- let attributes: Record<string, string> | undefined
202
+ let attributes: Record<string, string> | null = null
224
203
 
225
204
  if (mapping.attributes) {
226
205
  for (const [key, columns] of Object.entries(mapping.attributes)) {
@@ -234,12 +213,12 @@ export async function ingestRow(
234
213
 
235
214
  return {
236
215
  id,
237
- source: mapping.source,
238
- name: nameValue ? parsePersonName(nameValue) : undefined,
239
- organization: orgValue ? canonicalizeOrganizationName(orgValue) : undefined,
240
- phone: (mapping.phone && row[mapping.phone]?.trim()) || undefined,
241
- email: (mapping.email && row[mapping.email]?.trim()?.toLowerCase()) || undefined,
242
- address: addressValue && opts.geocodeAddress ? ((await opts.geocodeAddress(addressValue)) ?? undefined) : undefined,
216
+ source: mapping.source ?? null,
217
+ name: nameValue ? parsePersonName(nameValue) : null,
218
+ organization: orgValue ? canonicalizeOrganizationName(orgValue) : null,
219
+ phone: (mapping.phone && row[mapping.phone]) || null,
220
+ email: (mapping.email && row[mapping.email]?.toLowerCase()) || null,
221
+ address: addressValue && opts.geocodeAddress ? ((await opts.geocodeAddress(addressValue)) ?? null) : null,
243
222
  attributes,
244
223
  raw: row,
245
224
  }
@@ -248,7 +227,7 @@ export async function ingestRow(
248
227
  /**
249
228
  * Normalize tabular rows into {@link SourceRecord}s under a {@link ColumnMapping}.
250
229
  *
251
- * @see {@link streamRows} for the streaming path, which is the preferred way to handle multi-GB files.
230
+ * @see {@link streamRows} for the streaming path. It is preferred for multi-GB files.
252
231
  */
253
232
  export async function ingestRows(
254
233
  rows: Iterable<Record<string, string>> | AsyncIterable<Record<string, string>>,
@@ -268,24 +247,19 @@ export async function ingestRows(
268
247
  }
269
248
 
270
249
  /**
271
- * Stream a delimited file as normalized {@link SourceRecord}s — `streamRows` + {@link ingestRow} with **no geocoding**.
272
- * This is the single-threaded, "fast enough" ergonomic core: column mapping, name parsing, and org canonicalization for
273
- * a multi-GB file, line by line. Geocode separately by piping the output through `geocodeStream` (the only heavy step
274
- * worth threading); for a light file (e.g. one that already carries geo cells) just consume this and stop.
275
- *
276
- * Records come out in file order: the sequence's `map` settles each row before pulling the next, and its counter is the
277
- * row's index — the id a row without a mapped `id` column falls back to.
250
+ * Stream a delimited file as normalized {@link SourceRecord}s in file order with no geocoding.
251
+ * Geocode separately through `geocodeStream`.
278
252
  */
279
253
  export function normalizeCSV(
280
- source: string,
254
+ source: PathBuilderLike,
281
255
  opts: { mapping: ColumnMapping; delimiter?: Delimiter }
282
256
  ): AsyncSequence<SourceRecord> {
283
257
  return streamRows(source, { delimiter: opts.delimiter }).map((row, index) => ingestRow(row, opts.mapping, index))
284
258
  }
285
259
 
286
260
  /**
287
- * The subset of mailwoman's `GeocodeResult` the adapter consumes — kept structural so this package never imports the
288
- * heavy geocoder, yet a real `GeocodeResult` maps straight in.
261
+ * The subset of mailwoman's `GeocodeResult` the adapter consumes, kept structural
262
+ * so this package never imports the heavy geocoder.
289
263
  */
290
264
  export interface RawGeocode {
291
265
  lat: number | null
@@ -296,24 +270,28 @@ export interface RawGeocode {
296
270
  }
297
271
 
298
272
  /**
299
- * The component map {@link toPostalAddress} consumes (kept structural so this package never imports the geocoder).
273
+ * The component map {@link toPostalAddress} consumes
274
+ * (kept structural so this package never imports the geocoder).
300
275
  */
301
276
  type GeocodeComponents = Parameters<typeof toPostalAddress>[0]
302
277
 
303
278
  /**
304
- * What every shape of {@link geocodeAddressVia}'s dependencies carries.
279
+ * What every shape of {@link geocodeAddressVia}'s dependencies includes.
305
280
  */
306
281
  export interface GeocodeDepsBase {
307
282
  /**
308
- * Country (ISO-2 or name) the address is formatted under. When omitted, {@link toPostalAddress} reads the parsed
309
- * `country` component instead.
283
+ * Country (ISO-2 or name) the address is formatted under.
284
+ *
285
+ * When omitted, {@link toPostalAddress} reads the parsed `country` component instead.
310
286
  */
311
287
  country?: string
312
288
  }
313
289
 
314
290
  /**
315
- * Two independent calls: parse the address, then geocode it. mailwoman's `geocodeAddress` re-parses internally, so this
316
- * shape parses the address twice — fine when the two callbacks don't share a parser.
291
+ * Two independent calls: parse the address, then geocode it.
292
+ *
293
+ * Mailwoman's `geocodeAddress` re-parses internally, so the address is read twice
294
+ * unless the two callbacks share a parser.
317
295
  */
318
296
  export interface TwoStepGeocodeDeps extends GeocodeDepsBase {
319
297
  parse: (raw: string) => Promise<GeocodeComponents> | GeocodeComponents
@@ -321,25 +299,23 @@ export interface TwoStepGeocodeDeps extends GeocodeDepsBase {
321
299
  }
322
300
 
323
301
  /**
324
- * Parse the address ONCE and answer both the components and the geocode. Use this when the parse is the expensive step
325
- * you'd rather not pay for twice (e.g. share `parseForGeocode`'s tree between the PostalAddress and `geocodeAddress`'s
326
- * `parsedTree`). ~1.3× over the two-call shape on a real geocode pipeline.
302
+ * Parse the address once and answer both the components and the geocode, for
303
+ * when the parse is the expensive step you'd rather not pay for twice.
327
304
  */
328
305
  export interface OneStepGeocodeDeps extends GeocodeDepsBase {
329
306
  parseAndGeocode: (raw: string) => Promise<{ components: GeocodeComponents; geo: RawGeocode | null }>
330
307
  }
331
308
 
332
309
  /**
333
- * The dependencies {@link geocodeAddressVia} builds a {@link GeocodeAddress} from; `"parseAndGeocode" in deps` tells the
334
- * two shapes apart.
310
+ * The dependencies {@link geocodeAddressVia} builds a {@link GeocodeAddress} from;
311
+ * `"parseAndGeocode" in deps` tells the two shapes apart.
335
312
  */
336
313
  export type GeocodeAddressViaDeps = TwoStepGeocodeDeps | OneStepGeocodeDeps
337
314
 
338
315
  /**
339
- * Build a {@link GeocodeAddress} from mailwoman's real parse + geocode primitives (injected — the CLI constructs the
340
- * neural parser, resolver, and extracts and passes them in). Parse → components → {@link toPostalAddress} (which fills
341
- * the canonical key + formatted form) → attach the resolved coordinate. When geocoding can't place the address, the
342
- * parsed-but-unlocated address is still returned.
316
+ * Build a {@link GeocodeAddress} from injected parse and geocode primitives.
317
+ *
318
+ * When geocoding can't place the address, the parsed-but-unlocated address is still returned.
343
319
  */
344
320
  export function geocodeAddressVia(deps: GeocodeAddressViaDeps): GeocodeAddress {
345
321
  return async (raw: string): Promise<PostalAddress | null> => {
@@ -363,7 +339,9 @@ export function geocodeAddressVia(deps: GeocodeAddressViaDeps): GeocodeAddress {
363
339
  coordinate: { latitude: resolved.lat, longitude: resolved.lon },
364
340
  tier: resolved.resolution_tier,
365
341
  uncertaintyMeters: resolved.uncertainty_m,
366
- hierarchy: resolved.hierarchy,
342
+ hierarchy: resolved.hierarchy ?? null,
343
+ poBox: null,
344
+ multiUnit: null,
367
345
  }
368
346
 
369
347
  return withGeocode(base, geocode)