@mailwoman/registry 9.2.0 → 9.4.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 +1 -1
  2. package/{address-key.ts → lib/address-key.ts} +1 -1
  3. package/{geocode-handler.ts → lib/geocode-handler.ts} +7 -7
  4. package/{geojson.ts → lib/geojson.ts} +9 -4
  5. package/{index.ts → lib/index.ts} +10 -10
  6. package/{ingest.ts → lib/ingest.ts} +75 -68
  7. package/{learned-scorer.ts → lib/learned-scorer.ts} +1 -1
  8. package/{map-html.ts → lib/map-html.ts} +7 -13
  9. package/{reconcile.ts → lib/reconcile.ts} +7 -23
  10. package/{resolve.ts → lib/resolve.ts} +25 -12
  11. package/{tools → lib/tools}/coverage-reconciliation.ts +12 -14
  12. package/{tools → lib/tools}/cross-dataset-correlation.ts +60 -137
  13. package/{tools → lib/tools}/cross-source-threshold-sweep.ts +20 -31
  14. package/{tools → lib/tools}/dedup-ceiling.ts +33 -144
  15. package/{tools → lib/tools}/eval-geocoder.ts +9 -10
  16. package/{tools → lib/tools}/geocoder-namesake-probe.ts +5 -12
  17. package/{tools → lib/tools}/geocoder-vs-provided-coords.ts +9 -10
  18. package/lib/tools/gold-set-sample.ts +141 -0
  19. package/lib/tools/index.ts +31 -0
  20. package/{tools → lib/tools}/learned-scorer-clustering-eval.ts +68 -257
  21. package/{tools → lib/tools}/learned-scorer-crossstate-eval.ts +60 -243
  22. package/{tools → lib/tools}/learned-scorer-eval.ts +63 -257
  23. package/{tools → lib/tools}/matcher-scale.ts +4 -5
  24. package/lib/tools/nppes/org-name.ts +23 -0
  25. package/{tools → lib/tools}/nppes/overmerge-packet.ts +5 -7
  26. package/{tools → lib/tools}/nppes/report.ts +22 -25
  27. package/{tools → lib/tools}/nppes/sample.ts +80 -32
  28. package/{tools/nppes/levers.ts → lib/tools/nppes/settings.ts} +10 -10
  29. package/{tools → lib/tools}/nppes/truth-grains.ts +4 -44
  30. package/{tools → lib/tools}/nppes-dedup-benchmark.ts +42 -38
  31. package/lib/tools/shared.ts +761 -0
  32. package/lib/tools/train-cross-gbt.ts +209 -0
  33. package/{tools → lib/tools}/train-gbt.ts +35 -154
  34. package/lib/tools/train-org-cross-gbt.ts +179 -0
  35. package/{tools → lib/tools}/txhhsc-to-oarow.ts +9 -27
  36. package/lib/tools/viz/browser.ts +50 -0
  37. package/{tools → lib/tools}/viz/cross-dataset-map.ts +7 -8
  38. package/{tools → lib/tools}/viz/geocode-first-surface.ts +10 -8
  39. package/{tools → lib/tools}/viz/render-map.ts +10 -23
  40. package/lib/tools/viz/render.ts +98 -0
  41. package/{tools → lib/tools}/viz/source-provenance-map.ts +8 -10
  42. package/{tools → lib/tools}/viz/yardstick-figure.ts +6 -5
  43. package/out/address-key.d.ts +1 -1
  44. package/out/address-key.d.ts.map +1 -1
  45. package/out/address-key.js.map +1 -1
  46. package/out/geocode-handler.d.ts +6 -6
  47. package/out/geocode-handler.d.ts.map +1 -1
  48. package/out/geocode-handler.js +6 -6
  49. package/out/geocode-handler.js.map +1 -1
  50. package/out/geojson.d.ts +7 -2
  51. package/out/geojson.d.ts.map +1 -1
  52. package/out/geojson.js +5 -3
  53. package/out/geojson.js.map +1 -1
  54. package/out/index.d.ts +10 -10
  55. package/out/index.d.ts.map +1 -1
  56. package/out/index.js +10 -10
  57. package/out/index.js.map +1 -1
  58. package/out/ingest.d.ts +64 -46
  59. package/out/ingest.d.ts.map +1 -1
  60. package/out/ingest.js +31 -45
  61. package/out/ingest.js.map +1 -1
  62. package/out/learned-scorer.d.ts +1 -1
  63. package/out/learned-scorer.d.ts.map +1 -1
  64. package/out/learned-scorer.js.map +1 -1
  65. package/out/map-html.d.ts +3 -3
  66. package/out/map-html.d.ts.map +1 -1
  67. package/out/map-html.js +6 -11
  68. package/out/map-html.js.map +1 -1
  69. package/out/models/crosssource-gbt-en-us.d.ts.map +1 -1
  70. package/out/models/crosssource-gbt-en-us.js.map +1 -1
  71. package/out/models/dedup-gbt-en-us.d.ts.map +1 -1
  72. package/out/models/dedup-gbt-en-us.js.map +1 -1
  73. package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -1
  74. package/out/models/org-crosssource-gbt-en-us.js.map +1 -1
  75. package/out/reconcile.d.ts +6 -1
  76. package/out/reconcile.d.ts.map +1 -1
  77. package/out/reconcile.js +5 -20
  78. package/out/reconcile.js.map +1 -1
  79. package/out/resolve.d.ts +19 -7
  80. package/out/resolve.d.ts.map +1 -1
  81. package/out/resolve.js +16 -5
  82. package/out/resolve.js.map +1 -1
  83. package/out/tools/coverage-reconciliation.d.ts +1 -1
  84. package/out/tools/coverage-reconciliation.d.ts.map +1 -1
  85. package/out/tools/coverage-reconciliation.js +11 -11
  86. package/out/tools/coverage-reconciliation.js.map +1 -1
  87. package/out/tools/cross-dataset-correlation.d.ts +4 -4
  88. package/out/tools/cross-dataset-correlation.d.ts.map +1 -1
  89. package/out/tools/cross-dataset-correlation.js +57 -109
  90. package/out/tools/cross-dataset-correlation.js.map +1 -1
  91. package/out/tools/cross-source-threshold-sweep.d.ts +2 -2
  92. package/out/tools/cross-source-threshold-sweep.d.ts.map +1 -1
  93. package/out/tools/cross-source-threshold-sweep.js +19 -27
  94. package/out/tools/cross-source-threshold-sweep.js.map +1 -1
  95. package/out/tools/dedup-ceiling.d.ts.map +1 -1
  96. package/out/tools/dedup-ceiling.js +36 -117
  97. package/out/tools/dedup-ceiling.js.map +1 -1
  98. package/out/tools/eval-geocoder.d.ts +8 -12
  99. package/out/tools/eval-geocoder.d.ts.map +1 -1
  100. package/out/tools/eval-geocoder.js +2 -2
  101. package/out/tools/eval-geocoder.js.map +1 -1
  102. package/out/tools/geocoder-namesake-probe.d.ts +2 -2
  103. package/out/tools/geocoder-namesake-probe.d.ts.map +1 -1
  104. package/out/tools/geocoder-namesake-probe.js +4 -8
  105. package/out/tools/geocoder-namesake-probe.js.map +1 -1
  106. package/out/tools/geocoder-vs-provided-coords.d.ts +1 -1
  107. package/out/tools/geocoder-vs-provided-coords.d.ts.map +1 -1
  108. package/out/tools/geocoder-vs-provided-coords.js +8 -7
  109. package/out/tools/geocoder-vs-provided-coords.js.map +1 -1
  110. package/out/tools/gold-set-sample.d.ts +5 -5
  111. package/out/tools/gold-set-sample.d.ts.map +1 -1
  112. package/out/tools/gold-set-sample.js +37 -122
  113. package/out/tools/gold-set-sample.js.map +1 -1
  114. package/out/tools/index.d.ts +23 -23
  115. package/out/tools/index.d.ts.map +1 -1
  116. package/out/tools/index.js +23 -23
  117. package/out/tools/index.js.map +1 -1
  118. package/out/tools/learned-scorer-clustering-eval.d.ts +1 -1
  119. package/out/tools/learned-scorer-clustering-eval.d.ts.map +1 -1
  120. package/out/tools/learned-scorer-clustering-eval.js +36 -169
  121. package/out/tools/learned-scorer-clustering-eval.js.map +1 -1
  122. package/out/tools/learned-scorer-crossstate-eval.d.ts +5 -5
  123. package/out/tools/learned-scorer-crossstate-eval.d.ts.map +1 -1
  124. package/out/tools/learned-scorer-crossstate-eval.js +44 -166
  125. package/out/tools/learned-scorer-crossstate-eval.js.map +1 -1
  126. package/out/tools/learned-scorer-eval.d.ts +1 -1
  127. package/out/tools/learned-scorer-eval.d.ts.map +1 -1
  128. package/out/tools/learned-scorer-eval.js +38 -168
  129. package/out/tools/learned-scorer-eval.js.map +1 -1
  130. package/out/tools/matcher-scale.d.ts.map +1 -1
  131. package/out/tools/matcher-scale.js +4 -4
  132. package/out/tools/matcher-scale.js.map +1 -1
  133. package/out/tools/nppes/org-name.d.ts +2 -5
  134. package/out/tools/nppes/org-name.d.ts.map +1 -1
  135. package/out/tools/nppes/org-name.js +1 -30
  136. package/out/tools/nppes/org-name.js.map +1 -1
  137. package/out/tools/nppes/overmerge-packet.d.ts +3 -3
  138. package/out/tools/nppes/overmerge-packet.d.ts.map +1 -1
  139. package/out/tools/nppes/overmerge-packet.js +3 -3
  140. package/out/tools/nppes/overmerge-packet.js.map +1 -1
  141. package/out/tools/nppes/report.d.ts +5 -5
  142. package/out/tools/nppes/report.d.ts.map +1 -1
  143. package/out/tools/nppes/report.js +17 -19
  144. package/out/tools/nppes/report.js.map +1 -1
  145. package/out/tools/nppes/sample.d.ts +32 -6
  146. package/out/tools/nppes/sample.d.ts.map +1 -1
  147. package/out/tools/nppes/sample.js +44 -26
  148. package/out/tools/nppes/sample.js.map +1 -1
  149. package/out/tools/nppes/scoring.d.ts.map +1 -1
  150. package/out/tools/nppes/scoring.js.map +1 -1
  151. package/out/tools/nppes/{levers.d.ts → settings.d.ts} +8 -8
  152. package/out/tools/nppes/settings.d.ts.map +1 -0
  153. package/out/tools/nppes/{levers.js → settings.js} +8 -8
  154. package/out/tools/nppes/settings.js.map +1 -0
  155. package/out/tools/nppes/truth-grains.d.ts +2 -2
  156. package/out/tools/nppes/truth-grains.d.ts.map +1 -1
  157. package/out/tools/nppes/truth-grains.js +4 -29
  158. package/out/tools/nppes/truth-grains.js.map +1 -1
  159. package/out/tools/nppes-dedup-benchmark.d.ts +4 -4
  160. package/out/tools/nppes-dedup-benchmark.d.ts.map +1 -1
  161. package/out/tools/nppes-dedup-benchmark.js +40 -34
  162. package/out/tools/nppes-dedup-benchmark.js.map +1 -1
  163. package/out/tools/shared.d.ts +243 -7
  164. package/out/tools/shared.d.ts.map +1 -1
  165. package/out/tools/shared.js +348 -18
  166. package/out/tools/shared.js.map +1 -1
  167. package/out/tools/train-cross-gbt.d.ts +7 -7
  168. package/out/tools/train-cross-gbt.d.ts.map +1 -1
  169. package/out/tools/train-cross-gbt.js +47 -145
  170. package/out/tools/train-cross-gbt.js.map +1 -1
  171. package/out/tools/train-gbt.d.ts +7 -7
  172. package/out/tools/train-gbt.d.ts.map +1 -1
  173. package/out/tools/train-gbt.js +31 -111
  174. package/out/tools/train-gbt.js.map +1 -1
  175. package/out/tools/train-org-cross-gbt.d.ts +7 -5
  176. package/out/tools/train-org-cross-gbt.d.ts.map +1 -1
  177. package/out/tools/train-org-cross-gbt.js +45 -141
  178. package/out/tools/train-org-cross-gbt.js.map +1 -1
  179. package/out/tools/txhhsc-to-oarow.d.ts +2 -2
  180. package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
  181. package/out/tools/txhhsc-to-oarow.js +8 -22
  182. package/out/tools/txhhsc-to-oarow.js.map +1 -1
  183. package/out/tools/viz/browser.d.ts +34 -0
  184. package/out/tools/viz/browser.d.ts.map +1 -0
  185. package/out/tools/viz/browser.js +33 -0
  186. package/out/tools/viz/browser.js.map +1 -0
  187. package/out/tools/viz/cross-dataset-map.d.ts +2 -2
  188. package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
  189. package/out/tools/viz/cross-dataset-map.js +6 -6
  190. package/out/tools/viz/cross-dataset-map.js.map +1 -1
  191. package/out/tools/viz/geocode-first-surface.d.ts +4 -3
  192. package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
  193. package/out/tools/viz/geocode-first-surface.js +7 -5
  194. package/out/tools/viz/geocode-first-surface.js.map +1 -1
  195. package/out/tools/viz/render-map.d.ts +3 -6
  196. package/out/tools/viz/render-map.d.ts.map +1 -1
  197. package/out/tools/viz/render-map.js +9 -19
  198. package/out/tools/viz/render-map.js.map +1 -1
  199. package/out/tools/viz/render.d.ts +4 -9
  200. package/out/tools/viz/render.d.ts.map +1 -1
  201. package/out/tools/viz/render.js +24 -39
  202. package/out/tools/viz/render.js.map +1 -1
  203. package/out/tools/viz/source-provenance-map.d.ts +2 -2
  204. package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
  205. package/out/tools/viz/source-provenance-map.js +6 -7
  206. package/out/tools/viz/source-provenance-map.js.map +1 -1
  207. package/out/tools/viz/yardstick-figure.d.ts +2 -2
  208. package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
  209. package/out/tools/viz/yardstick-figure.js +5 -4
  210. package/out/tools/viz/yardstick-figure.js.map +1 -1
  211. package/out/types.d.ts.map +1 -1
  212. package/out/types.js.map +1 -1
  213. package/package.json +115 -15
  214. package/out/tools/nppes/levers.d.ts.map +0 -1
  215. package/out/tools/nppes/levers.js.map +0 -1
  216. package/tools/gold-set-sample.ts +0 -254
  217. package/tools/index.ts +0 -31
  218. package/tools/nppes/org-name.ts +0 -56
  219. package/tools/shared.ts +0 -162
  220. package/tools/train-cross-gbt.ts +0 -359
  221. package/tools/train-org-cross-gbt.ts +0 -330
  222. package/tools/viz/render.ts +0 -113
  223. /package/{models → lib/models}/crosssource-gbt-en-us.ts +0 -0
  224. /package/{models → lib/models}/dedup-gbt-en-us.ts +0 -0
  225. /package/{models → lib/models}/org-crosssource-gbt-en-us.ts +0 -0
  226. /package/{tools → lib/tools}/nppes/scoring.ts +0 -0
  227. /package/{types.ts → lib/types.ts} +0 -0
package/README.md CHANGED
@@ -95,7 +95,7 @@ mailwoman registry --sources tx-nppes.json --reconcile tx-fcc.json --resolve-db
95
95
  `$MAILWOMAN_CANDIDATE_DB` is set. `resolveWOFPath` throws before anything opens; `createResolverBackend`
96
96
  then prefers the candidate backend and never touches the WOF path (`run.tsx`'s own inline comment states
97
97
  this correctly: "`$MAILWOMAN_CANDIDATE_DB` → the demo-parity candidate backend; else FTS over wofPath").
98
- A nonexistent path passes the gate.
98
+ A nonexistent path satisfies that requirement.
99
99
 
100
100
  So: set `$MAILWOMAN_CANDIDATE_DB` and pass anything to `--resolve-db`. Do NOT pass `candidate.db` to
101
101
  `--resolve-db` with the environment variable unset — the flag is believed on that path, and the admin
@@ -17,7 +17,7 @@
17
17
  import { createPostalAddressID, type PostalAddressID } from "@mailwoman/address-id"
18
18
  import { type BlockingKey, exactKey } from "@mailwoman/match"
19
19
 
20
- import type { SourceRecord } from "./types.ts"
20
+ import type { SourceRecord } from "#types"
21
21
 
22
22
  /**
23
23
  * The stable address primary key for a record, or null when it isn't geocoded (no coordinate → no locality cell) or
@@ -3,21 +3,21 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * The per-record geocode step, factored out of the worker so it unit-tests against a fake seam (no
7
- * neural model / SQLite). `geocode-worker.ts` builds the real seam from config and wraps this.
6
+ * The per-record geocode step, factored out of the worker so it unit-tests against a fake geocoder (no
7
+ * neural model / SQLite). `geocode-worker.ts` builds the real geocoder from config and wraps this.
8
8
  */
9
9
 
10
- import { type ColumnMapping, type GeocodeAddress, pick } from "./ingest.ts"
11
- import type { SourceRecord } from "./types.ts"
10
+ import { type ColumnMapping, type GeocodeAddress, pick } from "#ingest"
11
+ import type { SourceRecord } from "#types"
12
12
 
13
13
  /**
14
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 `seam`, and attach the result.
15
+ * `mapping.address` (the worker can't receive the original closure), geocode it via `geocode`, and attach the result.
16
16
  * Records with no mapped address pass through untouched (no geocode call). The default separator matches
17
17
  * {@link ingestRow}'s `addressSeparator`.
18
18
  */
19
19
  export function makeGeocodeHandler(
20
- seam: GeocodeAddress,
20
+ geocode: GeocodeAddress,
21
21
  mapping: ColumnMapping,
22
22
  addressSeparator = ", "
23
23
  ): (record: SourceRecord) => Promise<SourceRecord> {
@@ -28,7 +28,7 @@ export function makeGeocodeHandler(
28
28
 
29
29
  if (!addressValue) return record
30
30
 
31
- const address = (await seam(addressValue)) ?? undefined
31
+ const address = (await geocode(addressValue)) ?? undefined
32
32
 
33
33
  return { ...record, address }
34
34
  }
@@ -13,7 +13,7 @@
13
13
  import { isPresent } from "@mailwoman/core/objects"
14
14
  import type { GeoFeature, GeoFeatureCollection, PointLiteral } from "@mailwoman/spatial"
15
15
 
16
- import type { EntityGeoData, ResolvedEntity, SourceRecord } from "./types.ts"
16
+ import type { EntityGeoData, ResolvedEntity, SourceRecord } from "#types"
17
17
 
18
18
  /**
19
19
  * Assemble a display name from a record's parsed person name, if any.
@@ -32,9 +32,13 @@ function displayName(record: SourceRecord): string | null {
32
32
  }
33
33
 
34
34
  /**
35
- * One entity → one GeoJSON Point feature.
35
+ * One entity → one GeoJSON Point feature. `extra` merges over (and may override) the standard properties — the
36
+ * reconciliation flow adds its `bucket` and swaps the display name for the representative's org-or-person form.
36
37
  */
37
- function toFeature(entity: ResolvedEntity): GeoFeature<PointLiteral, EntityGeoData> {
38
+ export function toFeature(
39
+ entity: ResolvedEntity,
40
+ extra?: Partial<EntityGeoData>
41
+ ): GeoFeature<PointLiteral, EntityGeoData> {
38
42
  const rep = entity.representative
39
43
 
40
44
  return {
@@ -55,6 +59,7 @@ function toFeature(entity: ResolvedEntity): GeoFeature<PointLiteral, EntityGeoDa
55
59
  organization: rep.organization?.canonical ?? null,
56
60
  address: rep.address?.formatted ?? null,
57
61
  geocodeTier: rep.address?.geocode?.tier ?? null,
62
+ ...extra,
58
63
  },
59
64
  }
60
65
  }
@@ -66,6 +71,6 @@ function toFeature(entity: ResolvedEntity): GeoFeature<PointLiteral, EntityGeoDa
66
71
  export function toGeoJSON(entities: readonly ResolvedEntity[]): GeoFeatureCollection<PointLiteral, EntityGeoData> {
67
72
  return {
68
73
  type: "FeatureCollection",
69
- features: entities.filter((entity) => entity.coordinate).map(toFeature),
74
+ features: entities.filter((entity) => entity.coordinate).map((entity) => toFeature(entity)),
70
75
  }
71
76
  }
@@ -11,13 +11,13 @@
11
11
  * for, finally standing on a calibrated, label-free matcher.
12
12
  */
13
13
 
14
- export * from "./address-key.ts"
15
- export * from "./geojson.ts"
16
- export * from "./ingest.ts"
17
- export * from "./geocode-handler.ts"
18
- export * from "./learned-scorer.ts"
19
- export * from "./map-html.ts"
20
- export * from "./models/dedup-gbt-en-us.ts"
21
- export * from "./reconcile.ts"
22
- export * from "./resolve.ts"
23
- export * from "./types.ts"
14
+ export * from "#address-key"
15
+ export * from "#geojson"
16
+ export * from "#ingest"
17
+ export * from "#geocode-handler"
18
+ export * from "#learned-scorer"
19
+ export * from "#map-html"
20
+ export * from "#models/dedup-gbt-en-us"
21
+ export * from "#reconcile"
22
+ export * from "#resolve"
23
+ export * from "#types"
@@ -12,9 +12,9 @@
12
12
  * hold the name, organization, address, phone, email; each row is normalized with
13
13
  * `@mailwoman/record` (parse the person name, canonicalize the org). This is deterministic
14
14
  * and testable with no heavy runtime.
15
- * 2. **Geocoding** (the heavy part) is an injected seam — a {@link GeocodeAddress} the caller provides.
16
- * Ingest never imports the neural parser, the resolver, or the shards; it just calls the
17
- * seam per address. {@link geocodeAddressVia} builds that seam from mailwoman's real parse +
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
18
  * geocode primitives (which the CLI constructs with the model + data in hand), so the wiring
19
19
  * is concrete and testable without pinning the heavy runtime into this package.
20
20
  *
@@ -25,19 +25,30 @@
25
25
  import { isPresent } from "@mailwoman/core/objects"
26
26
  import type { AddressGeocode, PostalAddress } from "@mailwoman/record"
27
27
  import { canonicalizeOrganizationName, parsePersonName, toPostalAddress, withGeocode } from "@mailwoman/record"
28
- import { CSVSpliterator, Delimiters } from "spliterator"
28
+ import { type AsyncSequence, CSVSpliterator, Delimiters } from "spliterator"
29
29
 
30
- import type { SourceRecord } from "./types.ts"
30
+ import type { SourceRecord } from "#types"
31
31
 
32
32
  /**
33
- * Resolve a raw address string into a {@link PostalAddress}. The seam to mailwoman's geocoder.
33
+ * Resolve a raw address string into a {@link PostalAddress}. The entry point to mailwoman's geocoder.
34
34
  */
35
35
  export type GeocodeAddress = (raw: string) => Promise<PostalAddress | null> | PostalAddress | null
36
36
 
37
+ /**
38
+ * The column delimiters a tabular source may declare, by name, each the spliterator's own byte.
39
+ *
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.
42
+ */
43
+ const COLUMN_DELIMITERS = {
44
+ comma: Delimiters.Comma,
45
+ tab: Delimiters.Tab,
46
+ } as const satisfies Partial<Record<Lowercase<keyof typeof Delimiters>, (typeof Delimiters)[keyof typeof Delimiters]>>
47
+
37
48
  /**
38
49
  * Column delimiter of a delimited source.
39
50
  */
40
- export type Delimiter = "comma" | "tab"
51
+ export type Delimiter = keyof typeof COLUMN_DELIMITERS
41
52
 
42
53
  /**
43
54
  * Infer the delimiter from a path's extension (`.tsv` → tab, else comma).
@@ -47,28 +58,20 @@ export function delimiterFor(path: string): Delimiter {
47
58
  }
48
59
 
49
60
  /**
50
- * Stream a delimited file's rows lazily as header-keyed objects — the same shape {@link parseCSV} returns, but
51
- * **without loading the file into memory**. A multi-GB source (the NPPES registry is ~4.8 GB / 9.6M rows — too big for
52
- * `readFileSync`, which throws `ERR_STRING_TOO_LONG`) streams line by line. Keys are the original header names
53
- * (`normalizeKeys: false`) so a {@link ColumnMapping} written against the source's headers matches. Filter/sample the
54
- * stream before {@link ingestRows} to keep only the rows you geocode.
61
+ * Stream a delimited file's rows lazily as header-keyed objects.
55
62
  *
56
- * `CSVSpliterator` (spliterator ≥ 3.2.0) handles the whole job: empty fields are preserved (a 330-column NPPES row
57
- * stays 330 columns), CRLF row terminators are normalized (RFC 4180 default), and `enableQuoteHandling` makes quoted
58
- * fields — embedded delimiters, embedded newlines, doubled-quote escapes — parse correctly while leaving unquoted files
59
- * untouched. (This replaced a manual `TextSpliterator` + `split` workaround written against the 3.1.0 column tokenizer,
60
- * which dropped empty fields and mis-parsed quotes.) Missing trailing fields land as `""`, matching the header
61
- * contract. For small in-memory parses {@link parseCSV} remains.
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.
62
67
  */
63
- export async function* streamRows(
68
+ export function streamRows(
64
69
  source: string,
65
70
  opts: { delimiter?: Delimiter } = {}
66
- ): AsyncGenerator<Record<string, string>> {
67
- const columnDelimiter = (opts.delimiter ?? delimiterFor(source)) === "tab" ? Delimiters.Tab : Delimiters.Comma
68
-
69
- yield* CSVSpliterator.fromAsync<Record<string, string>>(source, {
71
+ ): AsyncSequence<Record<string, string>> {
72
+ return CSVSpliterator.fromAsync<Record<string, string>>(source, {
70
73
  mode: "object",
71
- columnDelimiter,
74
+ columnDelimiter: COLUMN_DELIMITERS[opts.delimiter ?? delimiterFor(source)],
72
75
  normalizeKeys: false,
73
76
  enableQuoteHandling: true,
74
77
  })
@@ -169,7 +172,7 @@ export function inferMapping(header: readonly string[]): ColumnMapping {
169
172
  */
170
173
  export interface IngestOptions {
171
174
  /**
172
- * The geocoding seam. Without it, records carry name/org but no resolved address.
175
+ * The geocoding interface. Without it, records carry name/org but no resolved address.
173
176
  */
174
177
  geocodeAddress?: GeocodeAddress
175
178
  /**
@@ -184,19 +187,6 @@ export interface IngestOptions {
184
187
  addressSeparator?: string
185
188
  }
186
189
 
187
- /**
188
- * Parse a CSV string (with a header row) into row objects keyed by column name.
189
- *
190
- * Keys and values are trimmed, and keys keep the source's own header spelling so a {@link ColumnMapping} written against
191
- * those headers matches — the same contract {@link streamRows} holds for the streaming path.
192
- */
193
- export function parseCSV(text: string): Record<string, string>[] {
194
- return Array.from(
195
- CSVSpliterator.from(text, { mode: "object", normalizeKeys: false, enableQuoteHandling: true }),
196
- (row) => Object.fromEntries(Object.entries(row).map(([key, value]) => [key.trim(), String(value ?? "").trim()]))
197
- )
198
- }
199
-
200
190
  /**
201
191
  * Join the named column(s) of a row into a single trimmed string, or undefined if empty.
202
192
  */
@@ -216,7 +206,7 @@ export function pick(row: Record<string, string>, columns?: string | string[], s
216
206
  /**
217
207
  * Normalize one tabular row into a {@link SourceRecord} under a {@link ColumnMapping}: parse the person name,
218
208
  * canonicalize the org, and (if `opts.geocodeAddress` is provided) geocode the joined address. `id` falls back to the
219
- * caller-supplied row index. Pure aside from the optional geocode seam, so the deterministic normalization can run
209
+ * caller-supplied row index. Pure aside from the optional geocode interface, so the deterministic normalization can run
220
210
  * single-threaded (see {@link normalizeCSV}) while geocoding is offloaded (see `geocodeStream`).
221
211
  */
222
212
  export async function ingestRow(
@@ -256,8 +246,9 @@ export async function ingestRow(
256
246
  }
257
247
 
258
248
  /**
259
- * Normalize tabular rows into {@link SourceRecord}s under a {@link ColumnMapping}. Accepts a sync OR async iterable, so
260
- * {@link parseCSV} (in-memory) and {@link streamRows} (lazy, for huge files) both thread straight through.
249
+ * Normalize tabular rows into {@link SourceRecord}s under a {@link ColumnMapping}.
250
+ *
251
+ * @see {@link streamRows} for the streaming path, which is the preferred way to handle multi-GB files.
261
252
  */
262
253
  export async function ingestRows(
263
254
  rows: Iterable<Record<string, string>> | AsyncIterable<Record<string, string>>,
@@ -281,18 +272,15 @@ export async function ingestRows(
281
272
  * This is the single-threaded, "fast enough" ergonomic core: column mapping, name parsing, and org canonicalization for
282
273
  * a multi-GB file, line by line. Geocode separately by piping the output through `geocodeStream` (the only heavy step
283
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.
284
278
  */
285
- export async function* normalizeCSV(
279
+ export function normalizeCSV(
286
280
  source: string,
287
281
  opts: { mapping: ColumnMapping; delimiter?: Delimiter }
288
- ): AsyncGenerator<SourceRecord> {
289
- let index = 0
290
-
291
- for await (const row of streamRows(source, { delimiter: opts.delimiter })) {
292
- yield await ingestRow(row, opts.mapping, index)
293
-
294
- index++
295
- }
282
+ ): AsyncSequence<SourceRecord> {
283
+ return streamRows(source, { delimiter: opts.delimiter }).map((row, index) => ingestRow(row, opts.mapping, index))
296
284
  }
297
285
 
298
286
  /**
@@ -312,29 +300,48 @@ export interface RawGeocode {
312
300
  */
313
301
  type GeocodeComponents = Parameters<typeof toPostalAddress>[0]
314
302
 
303
+ /**
304
+ * What every shape of {@link geocodeAddressVia}'s dependencies carries.
305
+ */
306
+ export interface GeocodeDepsBase {
307
+ /**
308
+ * Country (ISO-2 or name) the address is formatted under. When omitted, {@link toPostalAddress} reads the parsed
309
+ * `country` component instead.
310
+ */
311
+ country?: string
312
+ }
313
+
314
+ /**
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.
317
+ */
318
+ export interface TwoStepGeocodeDeps extends GeocodeDepsBase {
319
+ parse: (raw: string) => Promise<GeocodeComponents> | GeocodeComponents
320
+ geocode: (raw: string) => Promise<RawGeocode | null> | RawGeocode | null
321
+ }
322
+
323
+ /**
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.
327
+ */
328
+ export interface OneStepGeocodeDeps extends GeocodeDepsBase {
329
+ parseAndGeocode: (raw: string) => Promise<{ components: GeocodeComponents; geo: RawGeocode | null }>
330
+ }
331
+
332
+ /**
333
+ * The dependencies {@link geocodeAddressVia} builds a {@link GeocodeAddress} from; `"parseAndGeocode" in deps` tells the
334
+ * two shapes apart.
335
+ */
336
+ export type GeocodeAddressViaDeps = TwoStepGeocodeDeps | OneStepGeocodeDeps
337
+
315
338
  /**
316
339
  * Build a {@link GeocodeAddress} from mailwoman's real parse + geocode primitives (injected — the CLI constructs the
317
- * neural parser, resolver, and shards and passes them in). Parse → components → {@link toPostalAddress} (which fills
340
+ * neural parser, resolver, and extracts and passes them in). Parse → components → {@link toPostalAddress} (which fills
318
341
  * the canonical key + formatted form) → attach the resolved coordinate. When geocoding can't place the address, the
319
342
  * parsed-but-unlocated address is still returned.
320
- *
321
- * Two shapes:
322
- *
323
- * - `{ parse, geocode }` — the original: two independent calls. mailwoman's `geocodeAddress` re-parses internally, so
324
- * this parses the address twice (fine when the two callbacks don't share a parser).
325
- * - `{ parseAndGeocode }` — parse the address ONCE and return both the components and the geocode. Use this when the
326
- * parse is the expensive step you'd rather not pay for twice (e.g. share `parseForGeocode`'s tree between the
327
- * PostalAddress and `geocodeAddress`'s `parsedTree`). ~1.3× over the two-call shape on a real geocode pipeline.
328
343
  */
329
- export function geocodeAddressVia(
330
- deps: { country?: string } & (
331
- | {
332
- parse: (raw: string) => Promise<GeocodeComponents> | GeocodeComponents
333
- geocode: (raw: string) => Promise<RawGeocode | null> | RawGeocode | null
334
- }
335
- | { parseAndGeocode: (raw: string) => Promise<{ components: GeocodeComponents; geo: RawGeocode | null }> }
336
- )
337
- ): GeocodeAddress {
344
+ export function geocodeAddressVia(deps: GeocodeAddressViaDeps): GeocodeAddress {
338
345
  return async (raw: string): Promise<PostalAddress | null> => {
339
346
  let components: GeocodeComponents
340
347
  let resolved: RawGeocode | null
@@ -32,7 +32,7 @@ import {
32
32
  type TermFrequencyTable,
33
33
  } from "@mailwoman/match"
34
34
 
35
- import type { SourceRecord } from "./types.ts"
35
+ import type { SourceRecord } from "#types"
36
36
 
37
37
  /**
38
38
  * Similarity at which two official names count as the same organisation. Set high because the feature is a near-exact
@@ -9,14 +9,14 @@
9
9
  *
10
10
  * It renders on the HOUSE stack: MapLibre GL + a Protomaps basemap (`@protomaps/basemaps` generates
11
11
  * the `layers()` for a named flavor) over the `basemap-v4` vector tiles served from R2 at
12
- * `tiles.sister.software` — the same basemap the demo uses. Each entity is a circle sized by
12
+ * `tiles.mailwoman.ai` — the same basemap the demo uses. Each entity is a circle sized by
13
13
  * records-merged and colored by cross-dataset-link status (≥2 sources stand out), or
14
14
  * categorically by `bucket` when the reconciliation output carries one. Pure: GeoJSON in, HTML
15
15
  * string out (the Protomaps layer specs are generated at this point and inlined). The generated
16
16
  * page fetches MapLibre, the basemap tiles, and glyphs/sprite over the network when opened (the
17
17
  * house infra).
18
18
  *
19
- * SERVE IT OVER LOCALHOST, don't open it as a file. The house tile server (`tiles.sister.software`)
19
+ * SERVE IT OVER LOCALHOST, don't open it as a file. The house tile server (`tiles.mailwoman.ai`)
20
20
  * CORS-restricts to localhost + the docs domains, so a `file://` page shows the (accurate)
21
21
  * markers on a blank basemap. `npx serve` / `python3 -m http.server` in the output directory is
22
22
  * enough; the page also surfaces a hint banner when it detects it's running from `file://`.
@@ -25,10 +25,11 @@
25
25
  * Bucket labels render verbatim from the data, never editorialized.
26
26
  */
27
27
 
28
+ import { escapeHTML } from "@mailwoman/core/strings/escape"
28
29
  import type { GeoFeatureCollection, PointLiteral } from "@mailwoman/spatial"
29
30
  import { layers, namedFlavor } from "@protomaps/basemaps"
30
31
 
31
- import type { MapFeatureData } from "./types.ts"
32
+ import type { MapFeatureData } from "#types"
32
33
 
33
34
  /**
34
35
  * MapLibre GL release the page pins (CDN + SRI). Matches the workspace's `maplibre-gl` major.
@@ -38,17 +39,17 @@ const MAPLIBRE_JS_SRI = "sha384-5+cfbwT0iiub6VsQAdn6yz16nr6sDiQoHx6tm4O8OVYXHYOx
38
39
  const MAPLIBRE_CSS_SRI = "sha384-uTttxo/aOKbdE5RlD/SPzSDoDmNvGlUYPjONi2MN/b7c9HPSvW07OIuyP7uL6jxK"
39
40
 
40
41
  /**
41
- * The house Protomaps basemap: `basemap-v4` PMTiles (tile-worker → R2 at `tiles.sister.software`, which sends CORS for
42
+ * The house Protomaps basemap: `basemap-v4` PMTiles (tile-worker → R2 at `tiles.mailwoman.ai`, which sends CORS for
42
43
  * localhost + the docs domains).
43
44
  *
44
45
  * Glyphs + sprite come from the UPSTREAM Protomaps assets (GitHub Pages, `ACAO: *`), not the house mirror at
45
- * `public.sister.software` — that bucket sends no CORS headers, so the mirror can't be fetched cross-origin
46
+ * `public.mailwoman.ai` — that bucket sends no CORS headers, so the mirror can't be fetched cross-origin
46
47
  * (`cartographer/base/composition.ts` flags the same: "Currently upstream URLs; we mirror these … but no public route
47
48
  * fronts that bucket yet"). The upstream assets target the v4 schema, matching the `basemap-v4` tiles. Swap to the
48
49
  * house mirror once it has a CORS-enabled route.
49
50
  */
50
51
  const BASEMAP_SOURCE_ID = "basemap-v4"
51
- const BASEMAP_TILEJSON_URL = "https://tiles.sister.software/basemap-v4.json"
52
+ const BASEMAP_TILEJSON_URL = "https://tiles.mailwoman.ai/basemap-v4.json"
52
53
  const GLYPHS_URL = "https://protomaps.github.io/basemaps-assets/fonts/{fontstack}/{range}.pbf"
53
54
  const SPRITE_URL = "https://protomaps.github.io/basemaps-assets/sprites/v4/light"
54
55
 
@@ -99,13 +100,6 @@ function safeJSONForScript(value: unknown): string {
99
100
  return JSON.stringify(value).replaceAll("<", "\\u003c").replaceAll(">", "\\u003e").replaceAll("&", "\\u0026")
100
101
  }
101
102
 
102
- /**
103
- * Escape text for the HTML document body (title/heading), not the inlined script.
104
- */
105
- function escapeHTML(text: string): string {
106
- return text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;")
107
- }
108
-
109
103
  function sourceCount(props: MapFeatureData): number {
110
104
  return Array.isArray(props["sources"]) ? props["sources"].length : 0
111
105
  }
@@ -28,9 +28,10 @@
28
28
  */
29
29
 
30
30
  import { isPresent } from "@mailwoman/core/objects"
31
- import type { GeoFeature, GeoFeatureCollection, PointLiteral } from "@mailwoman/spatial"
31
+ import type { GeoFeatureCollection, PointLiteral } from "@mailwoman/spatial"
32
32
 
33
- import type { EntityGeoData, ReconciliationBucket, ResolvedEntity } from "./types.ts"
33
+ import { toFeature } from "#geojson"
34
+ import type { EntityGeoData, ReconciliationBucket, ResolvedEntity } from "#types"
34
35
 
35
36
  /**
36
37
  * Which source labels denote eligibility vs funding/enrollment.
@@ -124,9 +125,10 @@ export function reconcileCoverage(entities: readonly ResolvedEntity[], config: R
124
125
  }
125
126
 
126
127
  /**
127
- * A display name for a reconciled entity's representative record.
128
+ * A display name for a reconciled entity's representative record — the organization's canonical form, else the person
129
+ * name, else the record id.
128
130
  */
129
- function repName(entity: ResolvedEntity): string {
131
+ export function repName(entity: ResolvedEntity): string {
130
132
  const rep = entity.representative
131
133
  const person = [rep.name?.given, rep.name?.family].filter(isPresent).join(" ")
132
134
 
@@ -142,25 +144,7 @@ export function reconciliationGeoJSON(result: ReconciliationResult): GeoFeatureC
142
144
  type: "FeatureCollection",
143
145
  features: result.reconciled
144
146
  .filter((c) => c.entity.coordinate)
145
- .map((c) => {
146
- const foo: GeoFeature<PointLiteral, EntityGeoData> = {
147
- type: "Feature" as const,
148
- id: undefined,
149
- geometry: {
150
- type: "Point" as const,
151
- coordinates: [c.entity.coordinate!.longitude, c.entity.coordinate!.latitude] as [number, number],
152
- },
153
- properties: {
154
- entityID: c.entity.id,
155
- bucket: c.bucket,
156
- sources: c.sources,
157
- name: repName(c.entity),
158
- recordCount: c.entity.records.length,
159
- },
160
- }
161
-
162
- return foo
163
- }),
147
+ .map((c) => toFeature(c.entity, { bucket: c.bucket, name: repName(c.entity) })),
164
148
  }
165
149
  }
166
150
 
@@ -41,9 +41,9 @@ import {
41
41
  withTermFrequency,
42
42
  } from "@mailwoman/match"
43
43
 
44
- import { createGBTScorer } from "./learned-scorer.ts"
45
- import { DEDUP_GBT_META, DEDUP_GBT_MODEL } from "./models/dedup-gbt-en-us.ts"
46
- import type { ResolvedEntity, SourceRecord } from "./types.ts"
44
+ import { createGBTScorer } from "#learned-scorer"
45
+ import { DEDUP_GBT_META, DEDUP_GBT_MODEL } from "#models/dedup-gbt-en-us"
46
+ import type { ResolvedEntity, SourceRecord } from "#types"
47
47
 
48
48
  /**
49
49
  * Cheap, parse-free normalization for the address-frequency key — uppercase, collapse whitespace, drop punctuation.
@@ -104,15 +104,28 @@ function codeSetOverlap(a: string, b: string): number {
104
104
  }
105
105
 
106
106
  /**
107
- * Last-10-digits normalization for phone agreement (drops country code, punctuation, extensions).
107
+ * Last-10-digits normalization for phone agreement (drops country code, punctuation, extensions). A shorter digit
108
+ * string is kept as-is — partial agreement still carries weight in the comparison model; `null` means no digits at
109
+ * all.
108
110
  */
109
- function normalizePhone(raw: string | null | undefined): string | null {
111
+ export function normalizePhone(raw: string | null | undefined): string | null {
110
112
  if (!raw) return null
111
113
  const digits = raw.replaceAll(/\D+/g, "")
112
114
 
113
115
  return digits.length >= 10 ? digits.slice(-10) : digits || null
114
116
  }
115
117
 
118
+ /**
119
+ * {@link normalizePhone} under the probes' stricter contract: only a FULL line counts — the last 10 digits when the
120
+ * input carries at least 10, `""` otherwise (never a partial digit string). Callers guard on truthiness, so `""` reads
121
+ * as "no comparable phone" rather than a weaker key.
122
+ */
123
+ export function normalizePhoneStrict(raw: string | null | undefined): string {
124
+ const digits = normalizePhone(raw)
125
+
126
+ return digits && digits.length === 10 ? digits : ""
127
+ }
128
+
116
129
  /**
117
130
  * The identity-corroborating comparisons (person name, organization, phone). A2 (#625,
118
131
  * {@link ResolveConfig.requireCorroboration}) requires at least one of these to _positively_ agree before a pair may
@@ -122,7 +135,7 @@ function normalizePhone(raw: string | null | undefined): string | null {
122
135
  const CORROBORATING_FIELDS = new Set(["given", "family", "organization", "phone"])
123
136
 
124
137
  /**
125
- * Options for {@link buildDefaultModel}. Each lever is default-off, so the base model is byte-stable.
138
+ * Options for {@link buildDefaultModel}. Each change is default-off, so the base model is byte-stable.
126
139
  */
127
140
  export interface DefaultModelOptions {
128
141
  /**
@@ -150,7 +163,7 @@ export interface DefaultModelOptions {
150
163
  */
151
164
  discriminators?: string[]
152
165
  /**
153
- * Closed-vocabulary CODE-SET discriminators drawn from {@link SourceRecord.attributes} (#625 taxonomy lever). The
166
+ * Closed-vocabulary CODE-SET discriminators drawn from {@link SourceRecord.attributes} (#625 taxonomy change). The
154
167
  * attribute value is a whitespace-joined set of codes (NPPES taxonomy codes, license numbers, …); agreement = ANY
155
168
  * shared code (set overlap, not string similarity — `207R00000X` vs `207Q00000X` are DIFFERENT specialties despite
156
169
  * near-identical text, exactly the case string similarity mis-scores). The over-merge separator: two co-located
@@ -336,17 +349,17 @@ export interface ResolveConfig {
336
349
  * FS baseline on the identical pipeline. The function is responsible for its own feature computation (e.g. the
337
350
  * agreement pattern, which is EM-independent, plus any corpus statistics it captured).
338
351
  *
339
- * INTERACTION with {@link requireCorroboration}: the two are independent and compose, but the corroboration gate is
352
+ * INTERACTION with {@link requireCorroboration}: the two are independent and compose, but the corroboration check is
340
353
  * still evaluated on the Fellegi-Sunter `contributions` (NOT the learned score) — so a learned-high pair with no
341
- * positive FS name/org/phone agreement is still gated out. A learned scorer is normally trained to subsume
342
- * corroboration, so use ONE or the other; combining them lets the FS gate veto the learned score, which is rarely
354
+ * positive FS name/org/phone agreement is still held out. A learned scorer is normally trained to subsume
355
+ * corroboration, so use ONE or the other; combining them lets the FS check veto the learned score, which is rarely
343
356
  * what you want.
344
357
  */
345
358
  scorer?: (a: SourceRecord, b: SourceRecord) => number
346
359
  /**
347
360
  * **#603: the LEARNED gradient-boosted-tree scorer — DEFAULT-ON.** Omitted or `true` uses the bundled
348
361
  * {@link DEDUP_GBT_MODEL} (trained on the NPPES NPI-truth set; beats the Fellegi-Sunter baseline ~+5pp dedup F1
349
- * held-out within a state and ~+22pp on states it never trained on, cutting the co-located over-merge). `false` opts
362
+ * held-out within a state and ~+22pp on states it never trained on, reducing the co-located over-merge). `false` opts
350
363
  * out to the pure FS baseline; pass your own {@link GBT} for a custom model. The scorer is built over the SAME
351
364
  * collapsed-spatial + address-frequency feature model as training (via the resolved {@link addressFrequency}),
352
365
  * independent of this call's comparison config. An explicit {@link scorer} takes precedence. When the bundled model
@@ -377,7 +390,7 @@ export interface ResolveResult {
377
390
  * record with no confident link is its own singleton entity).
378
391
  */
379
392
  export function resolveEntities(records: readonly SourceRecord[], config: ResolveConfig = {}): ResolveResult {
380
- // The proven levers are DEFAULT-ON (#625): the address-frequency down-weight (auto-computed over the
393
+ // The proven changes are DEFAULT-ON (#625): the address-frequency down-weight (auto-computed over the
381
394
  // input records when not supplied; `false` disables) + the collapsed spatial signal (A1). A new
382
395
  // caller gets the strong config out of the box; pass explicit values to override.
383
396
  const addressFrequency =
@@ -29,9 +29,8 @@
29
29
  * [--data-root <dir>] [--out-md <md>] [--out-geojson <geojson>]`
30
30
  */
31
31
 
32
- import { writeFileSync } from "node:fs"
33
-
34
- import { dataRootPath } from "@mailwoman/core/utils"
32
+ import { dataRootPath } from "@mailwoman/core/data-root"
33
+ import { writeLocalFile, writeLocalJSONFile } from "@mailwoman/core/fs/writers"
35
34
 
36
35
  import {
37
36
  ingestRows,
@@ -44,9 +43,8 @@ import {
44
43
  type ReconcileConfig,
45
44
  type SourceRecord,
46
45
  } from "#index"
47
-
48
- import type { EvalGeocoderFactory } from "./eval-geocoder.ts"
49
- import { buildSpecs } from "./shared.ts"
46
+ import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
47
+ import { buildSpecs, stateOption } from "#tools/shared"
50
48
 
51
49
  /**
52
50
  * Options for {@linkcode coverageReconciliation}.
@@ -93,7 +91,7 @@ export async function coverageReconciliation(
93
91
  ): Promise<{ markdown: string }> {
94
92
  const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
95
93
  const CAP = options.cap ?? 2000
96
- const STATE = (options.state || "TX").toUpperCase()
94
+ const STATE = stateOption(options)
97
95
  const OUT_MD = options.outMd || ""
98
96
  const OUT_GEOJSON = options.outGeojson || ""
99
97
  const SPECS = buildSpecs(`${SOURCES}`, STATE)
@@ -122,9 +120,9 @@ export async function coverageReconciliation(
122
120
  let geo = 0
123
121
  let total = 0
124
122
 
125
- // Count placements at the seam (parity with the retired in-script counter).
126
- const seam: GeocodeAddress = async (raw) => {
127
- const g = await geocoder.seam(raw)
123
+ // Count placements at the boundary (parity with the retired in-script counter).
124
+ const geocodeForIngest: GeocodeAddress = async (raw) => {
125
+ const g = await geocoder.geocodeAddress(raw)
128
126
 
129
127
  total++
130
128
 
@@ -139,7 +137,7 @@ export async function coverageReconciliation(
139
137
  const records: SourceRecord[] = []
140
138
 
141
139
  for (const spec of SPECS) {
142
- const recs = await ingestRows(rawBySource.get(spec.source)!, spec.mapping, { geocodeAddress: seam })
140
+ const recs = await ingestRows(rawBySource.get(spec.source)!, spec.mapping, { geocodeAddress: geocodeForIngest })
143
141
 
144
142
  for (const r of recs) {
145
143
  r.id = `${spec.source}:${r.id}`
@@ -148,7 +146,7 @@ export async function coverageReconciliation(
148
146
  records.push(...recs)
149
147
  }
150
148
 
151
- geocoder.close()
149
+ geocoder[Symbol.dispose]()
152
150
  report?.(` ${records.length} records; geocoded ${geo}/${total} (${((100 * geo) / total).toFixed(1)}%)`)
153
151
 
154
152
  report?.("[D] resolving + reconciling…")
@@ -184,12 +182,12 @@ export async function coverageReconciliation(
184
182
  console.log(md)
185
183
 
186
184
  if (OUT_MD) {
187
- writeFileSync(OUT_MD, md)
185
+ await writeLocalFile(md, OUT_MD)
188
186
  report?.(`[written] ${OUT_MD}`)
189
187
  }
190
188
 
191
189
  if (OUT_GEOJSON) {
192
- writeFileSync(OUT_GEOJSON, JSON.stringify(geojson))
190
+ await writeLocalJSONFile(geojson, OUT_GEOJSON)
193
191
  report?.(`[written] ${OUT_GEOJSON} (${geojson.features.length} features)`)
194
192
  }
195
193