@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 @@
1
+ {"version":3,"file":"address-key.d.ts","sourceRoot":"","sources":["../lib/address-key.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACnF,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,kBAAkB,CAAA;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAE1C;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,eAAe,GAAG,IAAI,CAO5E;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,WAAW,CAAC,YAAY,CAAC,CAEhE"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
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
+ * exact-canonical-address complement to the fuzzy Fellegi-Sunter / GBT scoring. Two uses:
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. That is the cheap,
12
+ * certain part of dedup before the matcher does the fuzzy rest.
13
+ * - **As a blocking key:** {@link addressIDBlockingKey} adds the address-id to the blocking union, so
14
+ * records sharing one are guaranteed to be compared.
15
+ */
16
+ import { createPostalAddressID } from "@mailwoman/address-id";
17
+ import { exactKey } from "@mailwoman/match";
18
+ /**
19
+ * The stable address primary key for a record, or null when it is not geocoded
20
+ * (no coordinate means no locality cell) or includes no raw address to hash.
21
+ *
22
+ * The state prefix is plucked from the address when present.
23
+ */
24
+ export function postalAddressID(record) {
25
+ const coordinate = record.address?.geocode?.coordinate;
26
+ const address = record.address?.raw;
27
+ if (!coordinate || !address)
28
+ return null;
29
+ return createPostalAddressID({ coordinate, address });
30
+ }
31
+ /**
32
+ * A blocking key on the {@link postalAddressID}.
33
+ *
34
+ * Records that resolve to the same place with the same canonical address block together.
35
+ *
36
+ * Add it to {@link defaultBlockingKeys}'s union when an exact address join should never be missed.
37
+ */
38
+ export function addressIDBlockingKey() {
39
+ return exactKey((record) => postalAddressID(record));
40
+ }
41
+ //# sourceMappingURL=address-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address-key.js","sourceRoot":"","sources":["../lib/address-key.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,qBAAqB,EAAwB,MAAM,uBAAuB,CAAA;AACnF,OAAO,EAAoB,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAI7D;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,MAAoB;IACnD,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAA;IACtD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,GAAG,CAAA;IAEnC,IAAI,CAAC,UAAU,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAA;IAExC,OAAO,qBAAqB,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAA;AACtD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB;IACnC,OAAO,QAAQ,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAA;AACrD,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
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
+ */
9
+ import { type ColumnMapping, type GeocodeAddress } from "#ingest";
10
+ import type { SourceRecord } from "#types";
11
+ /**
12
+ * Build the handler `geocodeStream` runs per normalized record: recompute the joined address
13
+ * string from `record.raw` + `mapping.address` (the worker can't receive the original closure),
14
+ * geocode it via `geocode`, and attach the result.
15
+ *
16
+ * Records with no mapped address pass through untouched (no geocode call).
17
+ * The default separator matches {@link ingestRow}'s `addressSeparator`.
18
+ */
19
+ export declare function makeGeocodeHandler(geocode: GeocodeAddress, mapping: ColumnMapping, addressSeparator?: string): (record: SourceRecord) => Promise<SourceRecord>;
20
+ //# sourceMappingURL=geocode-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geocode-handler.d.ts","sourceRoot":"","sources":["../lib/geocode-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,cAAc,EAAQ,MAAM,SAAS,CAAA;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAE1C;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,aAAa,EACtB,gBAAgB,SAAO,GACrB,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,YAAY,CAAC,CAYjD"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
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
+ */
9
+ import { pick } from "#ingest";
10
+ /**
11
+ * Build the handler `geocodeStream` runs per normalized record: recompute the joined address
12
+ * string from `record.raw` + `mapping.address` (the worker can't receive the original closure),
13
+ * geocode it via `geocode`, and attach the result.
14
+ *
15
+ * Records with no mapped address pass through untouched (no geocode call).
16
+ * The default separator matches {@link ingestRow}'s `addressSeparator`.
17
+ */
18
+ export function makeGeocodeHandler(geocode, mapping, addressSeparator = ", ") {
19
+ return async (record) => {
20
+ if (!record.raw)
21
+ return record;
22
+ const addressValue = pick(record.raw, mapping.address, addressSeparator);
23
+ if (!addressValue)
24
+ return record;
25
+ const address = (await geocode(addressValue)) ?? null;
26
+ return { ...record, address };
27
+ };
28
+ }
29
+ //# sourceMappingURL=geocode-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geocode-handler.js","sourceRoot":"","sources":["../lib/geocode-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAA2C,IAAI,EAAE,MAAM,SAAS,CAAA;AAGvE;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CACjC,OAAuB,EACvB,OAAsB,EACtB,gBAAgB,GAAG,IAAI;IAEvB,OAAO,KAAK,EAAE,MAAM,EAAE,EAAE;QACvB,IAAI,CAAC,MAAM,CAAC,GAAG;YAAE,OAAO,MAAM,CAAA;QAE9B,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAA;QAExE,IAAI,CAAC,YAAY;YAAE,OAAO,MAAM,CAAA;QAEhC,MAAM,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC,IAAI,IAAI,CAAA;QAErD,OAAO,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAA;IAC9B,CAAC,CAAA;AACF,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Export resolved entities as GeoJSON — the bridge to QGIS and any web map. Each entity becomes a
7
+ * Point at its resolved coordinate, carrying the properties an analyst needs: the count of records
8
+ * merged into it, how tightly (cohesion), the canonical name/org/address and the geocode tier
9
+ * (so rooftop-precise entities can be styled apart from admin-centroid guesses). Entities without
10
+ * a coordinate are omitted (a Point feature needs one).
11
+ */
12
+ import type { GeoFeature, GeoFeatureCollection, PointLiteral } from "@mailwoman/spatial";
13
+ import type { EntityGeoData, ResolvedEntity } from "#types";
14
+ /**
15
+ * One entity → one GeoJSON Point feature.
16
+ *
17
+ * `extra` merges over (and may override) the standard properties.
18
+ * The reconciliation flow adds its `bucket` and swaps the display name for the
19
+ * representative's org-or-person form.
20
+ */
21
+ export declare function toFeature(entity: ResolvedEntity, extra?: Partial<EntityGeoData>): GeoFeature<PointLiteral, EntityGeoData>;
22
+ /**
23
+ * Convert resolved entities into a GeoJSON `FeatureCollection` of points, ready for QGIS.
24
+ *
25
+ * Entities with no resolved coordinate are skipped.
26
+ */
27
+ export declare function toGeoJSON(entities: readonly ResolvedEntity[]): GeoFeatureCollection<PointLiteral, EntityGeoData>;
28
+ //# sourceMappingURL=geojson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geojson.d.ts","sourceRoot":"","sources":["../lib/geojson.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAExF,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAgB,MAAM,QAAQ,CAAA;AASzE;;;;;;GAMG;AACH,wBAAgB,SAAS,CACxB,MAAM,EAAE,cAAc,EACtB,KAAK,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAC5B,UAAU,CAAC,YAAY,EAAE,aAAa,CAAC,CAyBzC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,GAAG,oBAAoB,CAAC,YAAY,EAAE,aAAa,CAAC,CAKhH"}
package/out/geojson.js ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Export resolved entities as GeoJSON — the bridge to QGIS and any web map. Each entity becomes a
7
+ * Point at its resolved coordinate, carrying the properties an analyst needs: the count of records
8
+ * merged into it, how tightly (cohesion), the canonical name/org/address and the geocode tier
9
+ * (so rooftop-precise entities can be styled apart from admin-centroid guesses). Entities without
10
+ * a coordinate are omitted (a Point feature needs one).
11
+ */
12
+ import { formatPersonName } from "@mailwoman/record/name";
13
+ /**
14
+ * Assemble a display name from a record's parsed person name, if any.
15
+ */
16
+ function displayName(record) {
17
+ return formatPersonName(record.name ?? null) || null;
18
+ }
19
+ /**
20
+ * One entity → one GeoJSON Point feature.
21
+ *
22
+ * `extra` merges over (and may override) the standard properties.
23
+ * The reconciliation flow adds its `bucket` and swaps the display name for the
24
+ * representative's org-or-person form.
25
+ */
26
+ export function toFeature(entity, extra) {
27
+ const rep = entity.representative;
28
+ return {
29
+ type: "Feature",
30
+ geometry: {
31
+ type: "Point",
32
+ coordinates: [entity.coordinate.longitude, entity.coordinate.latitude],
33
+ },
34
+ properties: {
35
+ entityID: entity.id,
36
+ recordCount: entity.records.length,
37
+ cohesion: entity.cohesion,
38
+ sourceIDs: entity.records.map((r) => r.id),
39
+ // Distinct provenance labels the entity's records span.
40
+ // An entity with ≥2 is a cross-dataset link.
41
+ sources: [...new Set(entity.records.map((r) => r.source).filter((s) => !!s))].toSorted(),
42
+ name: displayName(rep),
43
+ organization: rep.organization?.canonical ?? null,
44
+ address: rep.address?.formatted ?? null,
45
+ geocodeTier: rep.address?.geocode?.tier ?? null,
46
+ bucket: null,
47
+ ...extra,
48
+ },
49
+ };
50
+ }
51
+ /**
52
+ * Convert resolved entities into a GeoJSON `FeatureCollection` of points, ready for QGIS.
53
+ *
54
+ * Entities with no resolved coordinate are skipped.
55
+ */
56
+ export function toGeoJSON(entities) {
57
+ return {
58
+ type: "FeatureCollection",
59
+ features: entities.filter((entity) => entity.coordinate).map((entity) => toFeature(entity)),
60
+ };
61
+ }
62
+ //# sourceMappingURL=geojson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geojson.js","sourceRoot":"","sources":["../lib/geojson.ts"],"names":[],"mappings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AE,OAAO,EAAE,IAAI,IAAI,IAAI;YAC/C,MAAM,EAAE,IAAI;YACZ,GAAG,KAAK;SACR;KACD,CAAA;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,QAAmC;IAC5D,OAAO;QACN,IAAI,EAAE,mBAAmB;QACzB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;KAC3F,CAAA;AACF,CAAC"}
package/out/index.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * `@mailwoman/entity-resolution` — the geocode-first record-matching application.
7
+ *
8
+ * {@link resolveEntities} runs the whole matcher (block → score → cluster) over normalized
9
+ * contact/organization {@link SourceRecord}s and returns canonical {@link ResolvedEntity entities};
10
+ * {@link toGeoJSON} exports them for QGIS. This is the clinic-funding use case mailwoman was built
11
+ * for, finally standing on a calibrated, label-free matcher.
12
+ */
13
+ export * from "#address-key";
14
+ export * from "#geojson";
15
+ export * from "#ingest";
16
+ export * from "#geocode-handler";
17
+ export * from "#learned-scorer";
18
+ export * from "#map-html";
19
+ export * from "#models/dedup-gbt-en-us";
20
+ export * from "#reconcile";
21
+ export * from "#resolve";
22
+ export * from "#types";
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,yBAAyB,CAAA;AACvC,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA"}
package/out/index.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * `@mailwoman/entity-resolution` — the geocode-first record-matching application.
7
+ *
8
+ * {@link resolveEntities} runs the whole matcher (block → score → cluster) over normalized
9
+ * contact/organization {@link SourceRecord}s and returns canonical {@link ResolvedEntity entities};
10
+ * {@link toGeoJSON} exports them for QGIS. This is the clinic-funding use case mailwoman was built
11
+ * for, finally standing on a calibrated, label-free matcher.
12
+ */
13
+ export * from "#address-key";
14
+ export * from "#geojson";
15
+ export * from "#ingest";
16
+ export * from "#geocode-handler";
17
+ export * from "#learned-scorer";
18
+ export * from "#map-html";
19
+ export * from "#models/dedup-gbt-en-us";
20
+ export * from "#reconcile";
21
+ export * from "#resolve";
22
+ export * from "#types";
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,yBAAyB,CAAA;AACvC,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA"}
@@ -0,0 +1,173 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Column mapping and normalization are pure. The caller injects geocoding, so this package never imports the neural parser, resolver, or extracts.
7
+ */
8
+ import type { AddressGeocode, PostalAddress } from "@mailwoman/record";
9
+ import { toPostalAddress } from "@mailwoman/record";
10
+ import type { PathBuilderLike } from "path-ts";
11
+ import { type AsyncSequence } from "spliterator";
12
+ import type { SourceRecord } from "#types";
13
+ /**
14
+ * Resolve a raw address string into a {@link PostalAddress}, the entry point to mailwoman's geocoder.
15
+ */
16
+ export type GeocodeAddress = (raw: string) => Promise<PostalAddress | null> | PostalAddress | null;
17
+ /**
18
+ * The column delimiters a tabular source may declare, by name, each the spliterator's own byte.
19
+ *
20
+ * The `satisfies` clause makes a delimiter name spliterator no longer ships a compile error
21
+ * rather than a silently parallel vocabulary.
22
+ */
23
+ declare const COLUMN_DELIMITERS: {
24
+ readonly comma: 44;
25
+ readonly tab: 9;
26
+ };
27
+ /**
28
+ * Column delimiter of a delimited source.
29
+ */
30
+ export type Delimiter = keyof typeof COLUMN_DELIMITERS;
31
+ /**
32
+ * Infer the delimiter from a path's extension (`.tsv` → tab, else comma).
33
+ */
34
+ export declare function delimiterFor(path: string): Delimiter;
35
+ /**
36
+ * Stream a delimited file's rows lazily as header-keyed objects.
37
+ *
38
+ * @returns The spliterator's own {@linkcode AsyncSequence}, whose `map`/`filter`
39
+ * fuse into the same pull loop.
40
+ * An `async function*` wrapper would add an async frame per row and remove those operators.
41
+ */
42
+ export declare function streamRows(source: PathBuilderLike, opts?: {
43
+ delimiter?: Delimiter;
44
+ }): AsyncSequence<Record<string, string>>;
45
+ /**
46
+ * Maps dataset columns to record fields, where a field may draw from several columns joined with spaces.
47
+ */
48
+ export interface ColumnMapping {
49
+ /**
50
+ * Column holding a stable row id, falling back to the row index.
51
+ */
52
+ id?: string;
53
+ /**
54
+ * A literal provenance label for every row (not a column).
55
+ */
56
+ source?: string;
57
+ name?: string | string[];
58
+ organization?: string | string[];
59
+ address?: string | string[];
60
+ phone?: string;
61
+ email?: string;
62
+ /**
63
+ * Extra secondary-identifier fields mapped to the column(s) to draw each from, landing
64
+ * on `SourceRecord.attributes` under the same key for the matcher's `discriminators`.
65
+ */
66
+ attributes?: Record<string, string | string[]>;
67
+ }
68
+ /**
69
+ * Best-effort {@link ColumnMapping} inferred from a header row, the "point it at any CSV" convenience.
70
+ */
71
+ export declare function inferMapping(header: readonly string[]): ColumnMapping;
72
+ /**
73
+ * Options for {@link ingestRows}.
74
+ */
75
+ export interface IngestOptions {
76
+ /**
77
+ * The geocoding interface.
78
+ *
79
+ * Without it records include name/org but have no resolved address.
80
+ */
81
+ geocodeAddress?: GeocodeAddress;
82
+ /**
83
+ * Separator for joining a multi-column address mapping, comma-join giving the parser
84
+ * delimited input rather than a concatenated run (name/org always join with a space).
85
+ *
86
+ * @defaultValue `", "`
87
+ */
88
+ addressSeparator?: string;
89
+ }
90
+ /**
91
+ * Join the selected columns of a row into a single trimmed string, or null if empty.
92
+ */
93
+ export declare function pick(row: Record<string, string>, columns?: string | string[], separator?: string): string | null;
94
+ /**
95
+ * Normalize one tabular row into a {@link SourceRecord} under a {@link ColumnMapping},
96
+ * pure aside from the optional geocode interface so the deterministic normalization
97
+ * can run single-threaded while geocoding is offloaded.
98
+ */
99
+ export declare function ingestRow(row: Record<string, string>, mapping: ColumnMapping, index: number, opts?: IngestOptions): Promise<SourceRecord>;
100
+ /**
101
+ * Normalize tabular rows into {@link SourceRecord}s under a {@link ColumnMapping}.
102
+ *
103
+ * @see {@link streamRows} for the streaming path. It is preferred for multi-GB files.
104
+ */
105
+ export declare function ingestRows(rows: Iterable<Record<string, string>> | AsyncIterable<Record<string, string>>, mapping: ColumnMapping, opts?: IngestOptions): Promise<SourceRecord[]>;
106
+ /**
107
+ * Stream a delimited file as normalized {@link SourceRecord}s in file order with no geocoding.
108
+ * Geocode separately through `geocodeStream`.
109
+ */
110
+ export declare function normalizeCSV(source: PathBuilderLike, opts: {
111
+ mapping: ColumnMapping;
112
+ delimiter?: Delimiter;
113
+ }): AsyncSequence<SourceRecord>;
114
+ /**
115
+ * The subset of mailwoman's `GeocodeResult` the adapter consumes, kept structural
116
+ * so this package never imports the heavy geocoder.
117
+ */
118
+ export interface RawGeocode {
119
+ lat: number | null;
120
+ lon: number | null;
121
+ resolution_tier: AddressGeocode["tier"];
122
+ uncertainty_m: number | null;
123
+ hierarchy?: AddressGeocode["hierarchy"];
124
+ }
125
+ /**
126
+ * The component map {@link toPostalAddress} consumes
127
+ * (kept structural so this package never imports the geocoder).
128
+ */
129
+ type GeocodeComponents = Parameters<typeof toPostalAddress>[0];
130
+ /**
131
+ * What every shape of {@link geocodeAddressVia}'s dependencies includes.
132
+ */
133
+ export interface GeocodeDepsBase {
134
+ /**
135
+ * Country (ISO-2 or name) the address is formatted under.
136
+ *
137
+ * When omitted, {@link toPostalAddress} reads the parsed `country` component instead.
138
+ */
139
+ country?: string;
140
+ }
141
+ /**
142
+ * Two independent calls: parse the address, then geocode it.
143
+ *
144
+ * Mailwoman's `geocodeAddress` re-parses internally, so the address is read twice
145
+ * unless the two callbacks share a parser.
146
+ */
147
+ export interface TwoStepGeocodeDeps extends GeocodeDepsBase {
148
+ parse: (raw: string) => Promise<GeocodeComponents> | GeocodeComponents;
149
+ geocode: (raw: string) => Promise<RawGeocode | null> | RawGeocode | null;
150
+ }
151
+ /**
152
+ * Parse the address once and answer both the components and the geocode, for
153
+ * when the parse is the expensive step you'd rather not pay for twice.
154
+ */
155
+ export interface OneStepGeocodeDeps extends GeocodeDepsBase {
156
+ parseAndGeocode: (raw: string) => Promise<{
157
+ components: GeocodeComponents;
158
+ geo: RawGeocode | null;
159
+ }>;
160
+ }
161
+ /**
162
+ * The dependencies {@link geocodeAddressVia} builds a {@link GeocodeAddress} from;
163
+ * `"parseAndGeocode" in deps` tells the two shapes apart.
164
+ */
165
+ export type GeocodeAddressViaDeps = TwoStepGeocodeDeps | OneStepGeocodeDeps;
166
+ /**
167
+ * Build a {@link GeocodeAddress} from injected parse and geocode primitives.
168
+ *
169
+ * When geocoding can't place the address, the parsed-but-unlocated address is still returned.
170
+ */
171
+ export declare function geocodeAddressVia(deps: GeocodeAddressViaDeps): GeocodeAddress;
172
+ export {};
173
+ //# sourceMappingURL=ingest.d.ts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normalization are pure. The caller injects geocoding, so this package never imports the neural parser, resolver, or extracts.
7
+ */
8
+ import { isPresent } from "@mailwoman/core/objects";
9
+ import { canonicalizeOrganizationName, parsePersonName, toPostalAddress, withGeocode } from "@mailwoman/record";
10
+ import { CSVSpliterator, Delimiters } from "spliterator";
11
+ /**
12
+ * The column delimiters a tabular source may declare, by name, each the spliterator's own byte.
13
+ *
14
+ * The `satisfies` clause makes a delimiter name spliterator no longer ships a compile error
15
+ * rather than a silently parallel vocabulary.
16
+ */
17
+ const COLUMN_DELIMITERS = {
18
+ comma: Delimiters.Comma,
19
+ tab: Delimiters.Tab,
20
+ };
21
+ /**
22
+ * Infer the delimiter from a path's extension (`.tsv` → tab, else comma).
23
+ */
24
+ export function delimiterFor(path) {
25
+ return /\.tsv$/i.test(path) ? "tab" : "comma";
26
+ }
27
+ /**
28
+ * Stream a delimited file's rows lazily as header-keyed objects.
29
+ *
30
+ * @returns The spliterator's own {@linkcode AsyncSequence}, whose `map`/`filter`
31
+ * fuse into the same pull loop.
32
+ * An `async function*` wrapper would add an async frame per row and remove those operators.
33
+ */
34
+ export function streamRows(source, opts = {}) {
35
+ const path = source.toString();
36
+ return CSVSpliterator.fromAsync(path, {
37
+ columnDelimiter: COLUMN_DELIMITERS[opts.delimiter ?? delimiterFor(path)],
38
+ // A {@linkcode ColumnMapping} holds columns in the publisher's spelling rather than a
39
+ // normalized key such as `facility_name`, so the keys must arrive as the file writes them.
40
+ // The reader's default normalizes.
41
+ normalizeKeys: false,
42
+ });
43
+ }
44
+ /**
45
+ * Best-effort {@link ColumnMapping} inferred from a header row, the "point it at any CSV" convenience.
46
+ */
47
+ export function inferMapping(header) {
48
+ // Pad to whole-token boundaries so "state" doesn't match inside "statement".
49
+ const tok = (h) => ` ${h
50
+ .toLowerCase()
51
+ .replaceAll(/[^a-z0-9]+/g, " ")
52
+ .trim()} `;
53
+ const mapping = {};
54
+ const name = [];
55
+ const address = [];
56
+ for (const column of header) {
57
+ const h = tok(column);
58
+ const has = (...words) => words.some((w) => h.includes(` ${w} `));
59
+ if (!mapping.email && has("email", "e mail")) {
60
+ mapping.email = column;
61
+ }
62
+ else if (!mapping.phone && has("phone", "telephone", "tel", "mobile", "cell")) {
63
+ mapping.phone = column;
64
+ }
65
+ else if (!mapping.id && has("id", "npi", "ein", "frn", "spin", "uuid", "guid", "key")) {
66
+ mapping.id = column;
67
+ }
68
+ else if (has("org", "organization", "organisation", "company", "business", "facility", "agency", "employer")) {
69
+ mapping.organization ??= column;
70
+ }
71
+ else if (has("street", "address", "addr", "city", "town", "state", "province", "zip", "zipcode", "postal", "postcode", "county")) {
72
+ address.push(column);
73
+ }
74
+ else if (has("name", "first", "last", "given", "family", "middle", "surname", "fullname", "contact")) {
75
+ name.push(column);
76
+ }
77
+ }
78
+ if (name.length) {
79
+ mapping.name = name.length === 1 ? name[0] : name;
80
+ }
81
+ if (address.length) {
82
+ mapping.address = address;
83
+ }
84
+ return mapping;
85
+ }
86
+ /**
87
+ * Join the selected columns of a row into a single trimmed string, or null if empty.
88
+ */
89
+ export function pick(row, columns, separator = " ") {
90
+ if (!columns)
91
+ return null;
92
+ const list = Array.isArray(columns) ? columns : [columns];
93
+ const value = list
94
+ .map((c) => row[c])
95
+ .filter(isPresent)
96
+ .join(separator)
97
+ .trim();
98
+ return value || null;
99
+ }
100
+ /**
101
+ * Normalize one tabular row into a {@link SourceRecord} under a {@link ColumnMapping},
102
+ * pure aside from the optional geocode interface so the deterministic normalization
103
+ * can run single-threaded while geocoding is offloaded.
104
+ */
105
+ export async function ingestRow(row, mapping, index, opts = {}) {
106
+ const id = (mapping.id ? row[mapping.id] : "") || String(index);
107
+ const nameValue = pick(row, mapping.name);
108
+ const orgValue = pick(row, mapping.organization);
109
+ const addressValue = pick(row, mapping.address, opts.addressSeparator ?? ", ");
110
+ let attributes = null;
111
+ if (mapping.attributes) {
112
+ for (const [key, columns] of Object.entries(mapping.attributes)) {
113
+ const value = pick(row, columns);
114
+ if (value) {
115
+ ;
116
+ (attributes ??= {})[key] = value;
117
+ }
118
+ }
119
+ }
120
+ return {
121
+ id,
122
+ source: mapping.source ?? null,
123
+ name: nameValue ? parsePersonName(nameValue) : null,
124
+ organization: orgValue ? canonicalizeOrganizationName(orgValue) : null,
125
+ phone: (mapping.phone && row[mapping.phone]) || null,
126
+ email: (mapping.email && row[mapping.email]?.toLowerCase()) || null,
127
+ address: addressValue && opts.geocodeAddress ? ((await opts.geocodeAddress(addressValue)) ?? null) : null,
128
+ attributes,
129
+ raw: row,
130
+ };
131
+ }
132
+ /**
133
+ * Normalize tabular rows into {@link SourceRecord}s under a {@link ColumnMapping}.
134
+ *
135
+ * @see {@link streamRows} for the streaming path. It is preferred for multi-GB files.
136
+ */
137
+ export async function ingestRows(rows, mapping, opts = {}) {
138
+ const records = [];
139
+ let index = 0;
140
+ for await (const row of rows) {
141
+ records.push(await ingestRow(row, mapping, index, opts));
142
+ index++;
143
+ }
144
+ return records;
145
+ }
146
+ /**
147
+ * Stream a delimited file as normalized {@link SourceRecord}s in file order with no geocoding.
148
+ * Geocode separately through `geocodeStream`.
149
+ */
150
+ export function normalizeCSV(source, opts) {
151
+ return streamRows(source, { delimiter: opts.delimiter }).map((row, index) => ingestRow(row, opts.mapping, index));
152
+ }
153
+ /**
154
+ * Build a {@link GeocodeAddress} from injected parse and geocode primitives.
155
+ *
156
+ * When geocoding can't place the address, the parsed-but-unlocated address is still returned.
157
+ */
158
+ export function geocodeAddressVia(deps) {
159
+ return async (raw) => {
160
+ let components;
161
+ let resolved;
162
+ if ("parseAndGeocode" in deps) {
163
+ const r = await deps.parseAndGeocode(raw);
164
+ components = r.components;
165
+ resolved = r.geo;
166
+ }
167
+ else {
168
+ components = await deps.parse(raw);
169
+ resolved = await deps.geocode(raw);
170
+ }
171
+ const base = toPostalAddress(components, { country: deps.country, raw });
172
+ if (!resolved || resolved.lat === null || resolved.lon === null)
173
+ return base;
174
+ const geocode = {
175
+ coordinate: { latitude: resolved.lat, longitude: resolved.lon },
176
+ tier: resolved.resolution_tier,
177
+ uncertaintyMeters: resolved.uncertainty_m,
178
+ hierarchy: resolved.hierarchy ?? null,
179
+ poBox: null,
180
+ multiUnit: null,
181
+ };
182
+ return withGeocode(base, geocode);
183
+ };
184
+ }
185
+ //# sourceMappingURL=ingest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest.js","sourceRoot":"","sources":["../lib/ingest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnD,OAAO,EAAE,4BAA4B,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/G,OAAO,EAAsB,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAS5E;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG;IACzB,KAAK,EAAE,UAAU,CAAC,KAAK;IACvB,GAAG,EAAE,UAAU,CAAC,GAAG;CACkG,CAAA;AAOtH;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACxC,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAA;AAC9C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACzB,MAAuB,EACvB,IAAI,GAA8B,EAAE;IAEpC,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAA;IAE9B,OAAO,cAAc,CAAC,SAAS,CAAyB,IAAI,EAAE;QAC7D,eAAe,EAAE,iBAAiB,CAAC,IAAI,CAAC,SAAS,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;QACxE,sFAAsF;QACtF,2FAA2F;QAC3F,mCAAmC;QACnC,aAAa,EAAE,KAAK;KACpB,CAAC,CAAA;AACH,CAAC;AA0BD;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAAyB;IACrD,6EAA6E;IAC7E,MAAM,GA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