@mailwoman/core 9.1.0 → 9.3.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 (1086) hide show
  1. package/README.md +12 -12
  2. package/data/internal/dictionaries/languages.csv +184 -184
  3. package/data/libpostal/README.md +18 -12
  4. package/data/libpostal/dictionaries/README.md +4 -4
  5. package/data/libpostal/dictionaries/all/surnames.txt +6 -6
  6. package/{api → lib/api}/APIClient.ts +28 -23
  7. package/lib/api/arcgis.ts +69 -0
  8. package/lib/api/ckan.ts +141 -0
  9. package/{api → lib/api}/clock.ts +1 -1
  10. package/lib/api/defaults.ts +28 -0
  11. package/{api → lib/api}/disk-storage.ts +24 -28
  12. package/lib/api/host.ts +76 -0
  13. package/{api → lib/api}/index.ts +11 -6
  14. package/lib/api/ogc.ts +226 -0
  15. package/lib/api/paced-client.ts +67 -0
  16. package/{api → lib/api}/pacer.ts +8 -8
  17. package/{api → lib/api}/responses.ts +15 -3
  18. package/{api → lib/api}/retry.ts +12 -12
  19. package/{api → lib/api}/test-clocks.ts +6 -5
  20. package/{api → lib/api}/test-transport.ts +1 -1
  21. package/{coarse-placer → lib/coarse-placer}/coarse-placer.ts +32 -13
  22. package/{coarse-placer → lib/coarse-placer}/featurize.ts +11 -15
  23. package/lib/coarse-placer/fnv-hash.ts +24 -0
  24. package/lib/coarse-placer/math.ts +63 -0
  25. package/{coarse-placer → lib/coarse-placer}/tools/build-dataset.ts +26 -35
  26. package/{coarse-placer → lib/coarse-placer}/tools/build-outlier-exposure.ts +25 -21
  27. package/{coarse-placer → lib/coarse-placer}/tools/build-outlier-latin.ts +27 -53
  28. package/{coarse-placer → lib/coarse-placer}/tools/build-outlier-oa.ts +37 -63
  29. package/lib/coarse-placer/tools/country-sets.ts +47 -0
  30. package/{coarse-placer → lib/coarse-placer}/tools/eval-latin-offmap.ts +13 -43
  31. package/{coarse-placer → lib/coarse-placer}/tools/eval-openset.ts +22 -77
  32. package/{coarse-placer → lib/coarse-placer}/tools/eval-quant-compare.ts +17 -50
  33. package/{coarse-placer → lib/coarse-placer}/tools/eval.ts +23 -36
  34. package/lib/coarse-placer/tools/index.ts +24 -0
  35. package/lib/coarse-placer/tools/outlier-rows.ts +91 -0
  36. package/lib/coarse-placer/tools/paths.ts +78 -0
  37. package/{coarse-placer → lib/coarse-placer}/tools/probe-frontier.ts +13 -15
  38. package/{coarse-placer → lib/coarse-placer}/tools/quantize.ts +15 -21
  39. package/{coarse-placer → lib/coarse-placer}/tools/train.ts +32 -60
  40. package/lib/crypto/base64url.ts +42 -0
  41. package/lib/crypto/digest.ts +17 -0
  42. package/lib/crypto/ed25519.ts +118 -0
  43. package/{crypto → lib/crypto}/node.ts +3 -1
  44. package/lib/data-root.ts +193 -0
  45. package/{decoder → lib/decoder}/build-tree.ts +4 -4
  46. package/{decoder → lib/decoder}/calibration.ts +1 -1
  47. package/{decoder → lib/decoder}/containment.ts +12 -5
  48. package/lib/decoder/index.ts +19 -0
  49. package/lib/decoder/parse-diff.ts +347 -0
  50. package/{decoder → lib/decoder}/proposals-to-tree.ts +4 -4
  51. package/{decoder → lib/decoder}/resolve-proposal-overlaps.ts +3 -3
  52. package/lib/decoder/serialize-json.ts +120 -0
  53. package/{decoder → lib/decoder}/serialize-tuples.ts +29 -4
  54. package/{decoder → lib/decoder}/serialize-xml.ts +8 -4
  55. package/lib/decoder/tree-shape.ts +135 -0
  56. package/lib/decoder/tree-walk.ts +96 -0
  57. package/{decoder → lib/decoder}/types.ts +10 -2
  58. package/{decoder → lib/decoder}/unknown-spans.ts +3 -8
  59. package/{decoder → lib/decoder}/validate-tree.ts +18 -6
  60. package/lib/env/index.ts +90 -0
  61. package/lib/env/paths.ts +21 -0
  62. package/lib/env/schema.ts +100 -0
  63. package/lib/env/utils.ts +24 -0
  64. package/{errors → lib/errors}/schema.ts +10 -1
  65. package/lib/fs/compression.ts +65 -0
  66. package/lib/fs/formatters.ts +119 -0
  67. package/lib/fs/readers.ts +421 -0
  68. package/lib/fs/streams.ts +46 -0
  69. package/lib/fs/temporary.ts +85 -0
  70. package/lib/fs/writers.ts +288 -0
  71. package/{fs → lib/fs}/zip.ts +97 -81
  72. package/lib/git.ts +59 -0
  73. package/{utils → lib}/hash.ts +17 -8
  74. package/lib/html/document.ts +117 -0
  75. package/lib/html/tables.ts +154 -0
  76. package/lib/html/text.ts +123 -0
  77. package/lib/index.ts +16 -0
  78. package/lib/json.ts +85 -0
  79. package/lib/layers/coverage.ts +222 -0
  80. package/lib/layers/feature-count.ts +35 -0
  81. package/{layers → lib/layers}/index.ts +4 -2
  82. package/lib/layers/manifest.ts +455 -0
  83. package/{layers → lib/layers}/schema.ts +30 -5
  84. package/lib/license/configured.ts +29 -0
  85. package/lib/license/docs-site.ts +37 -0
  86. package/lib/license/index.ts +18 -0
  87. package/lib/license/key-file.ts +91 -0
  88. package/lib/license/key.ts +205 -0
  89. package/lib/license/obligations.ts +186 -0
  90. package/lib/license/publication.ts +91 -0
  91. package/lib/license/register.ts +110 -0
  92. package/lib/license/stamp.ts +94 -0
  93. package/lib/license/status.ts +125 -0
  94. package/lib/locale/index.ts +9 -0
  95. package/{locale → lib/locale}/locale.ts +2 -3
  96. package/{locale → lib/locale}/profiles/en-us.ts +1 -1
  97. package/{locale → lib/locale}/profiles/fr-fr.ts +1 -1
  98. package/lib/locale/profiles/index.ts +9 -0
  99. package/{locale → lib/locale}/profiles/ja-jp.ts +1 -1
  100. package/{locale → lib/locale}/registry.ts +2 -3
  101. package/lib/locale/zh-cn-units.ts +148 -0
  102. package/{logging → lib/logging}/index.ts +2 -2
  103. package/{logging → lib/logging}/shared.ts +39 -4
  104. package/lib/module/file-url.ts +29 -0
  105. package/lib/module/packaged-data.ts +31 -0
  106. package/lib/module/resolve-from.ts +100 -0
  107. package/lib/module/resolvers.ts +80 -0
  108. package/lib/module/runtime.ts +11 -0
  109. package/{utils/python-numeric.ts → lib/numeric.ts} +16 -2
  110. package/{objects.ts → lib/objects.ts} +24 -57
  111. package/lib/paths.ts +171 -0
  112. package/{pipeline → lib/pipeline}/index.ts +16 -18
  113. package/{pipeline → lib/pipeline}/runtime-pipeline.ts +66 -219
  114. package/{pipeline → lib/pipeline}/span-proposer.ts +1 -1
  115. package/{pipeline → lib/pipeline}/types.ts +83 -35
  116. package/{policy → lib/policy}/defaults.ts +2 -3
  117. package/lib/policy/index.ts +10 -0
  118. package/{policy → lib/policy}/policy.ts +2 -2
  119. package/{policy → lib/policy}/proposal-collection.ts +3 -3
  120. package/{policy → lib/policy}/registry.ts +3 -4
  121. package/lib/process.ts +219 -0
  122. package/lib/release-config.ts +106 -0
  123. package/lib/resolver/authoritative-provider.ts +180 -0
  124. package/lib/resolver/coverage-facts.ts +102 -0
  125. package/lib/resolver/fixture-authoritative-provider.ts +103 -0
  126. package/{resolver → lib/resolver}/index.ts +30 -4
  127. package/lib/resolver/lookup-types.ts +175 -0
  128. package/lib/resolver/placetype-map.ts +130 -0
  129. package/lib/resolver/postcode-format.ts +90 -0
  130. package/{resolver → lib/resolver}/referential.ts +1 -1
  131. package/{resolver → lib/resolver}/types.ts +360 -402
  132. package/lib/resources/git.ts +64 -0
  133. package/lib/resources/index.ts +13 -0
  134. package/{resources → lib/resources}/languages/index.ts +8 -3
  135. package/{resources → lib/resources}/languages/types.gen.ts +60 -0
  136. package/lib/resources/libpostal.ts +19 -0
  137. package/{resources → lib/resources}/set.ts +0 -38
  138. package/{resources → lib/resources}/whosonfirst/PlacetypeDataSource.ts +61 -19
  139. package/{resources → lib/resources}/whosonfirst/backoff.ts +5 -3
  140. package/lib/resources/whosonfirst/extract-repo.ts +116 -0
  141. package/lib/resources/whosonfirst/index.ts +9 -0
  142. package/{resources → lib/resources}/whosonfirst/placetypes/Placetype.ts +5 -6
  143. package/{resources → lib/resources}/whosonfirst/placetypes/admin.ts +12 -4
  144. package/{resources → lib/resources}/whosonfirst/placetypes/definition.ts +4 -3
  145. package/{resources → lib/resources}/whosonfirst/placetypes/graph.ts +0 -0
  146. package/lib/resources/whosonfirst/placetypes/index.ts +13 -0
  147. package/{resources → lib/resources}/whosonfirst/placetypes/mermaid.ts +2 -2
  148. package/lib/resources/whosonfirst/placetypes/specificity.ts +114 -0
  149. package/{resources → lib/resources}/whosonfirst/placetypes/tree.ts +2 -2
  150. package/{routing → lib/routing}/index.ts +3 -1
  151. package/lib/scripting/arguments.ts +70 -0
  152. package/lib/scripting/command.ts +55 -0
  153. package/{scripting → lib/scripting}/index.ts +4 -4
  154. package/lib/scripting/ingest-chunk-script.ts +90 -0
  155. package/{scripting → lib/scripting}/utils/index.ts +18 -26
  156. package/lib/stats.ts +63 -0
  157. package/{identifiers.ts → lib/strings/case.ts} +10 -1
  158. package/lib/strings/compare.ts +20 -0
  159. package/lib/strings/escape.ts +24 -0
  160. package/lib/strings/format.ts +14 -0
  161. package/{utils → lib/strings}/python-json.ts +8 -17
  162. package/lib/strings/regexp.ts +13 -0
  163. package/{tokenization → lib/tokenization}/Graph.ts +1 -1
  164. package/{tokenization → lib/tokenization}/Span.ts +5 -5
  165. package/lib/tokenization/index.ts +9 -0
  166. package/{tools → lib/tools}/download-libpostal-resources.ts +21 -28
  167. package/{tools → lib/tools}/download-ssl-address.ts +31 -15
  168. package/{tools → lib/tools}/generate-language-types.ts +42 -11
  169. package/{tools → lib/tools}/index.ts +4 -5
  170. package/lib/trust-policies.ts +120 -0
  171. package/{types → lib/types}/Classification.ts +3 -3
  172. package/{types → lib/types}/classifier.ts +2 -2
  173. package/{types → lib/types}/component.ts +17 -0
  174. package/lib/types/index.ts +10 -0
  175. package/{types → lib/types}/mapping.ts +2 -2
  176. package/lib/utils/chunk-process.ts +117 -0
  177. package/lib/utils/collections.ts +16 -0
  178. package/lib/utils/events.ts +10 -0
  179. package/lib/utils/geodatabase-archive.ts +97 -0
  180. package/lib/utils/index.ts +20 -0
  181. package/lib/utils/sleep.ts +15 -0
  182. package/lib/utils/sqlite-rows.ts +40 -0
  183. package/lib/utils/stream-to-disk.ts +122 -0
  184. package/lib/utils/system.ts +52 -0
  185. package/lib/utils/time.ts +30 -0
  186. package/lib/utils/union-find.ts +58 -0
  187. package/lib/vale.ts +47 -0
  188. package/out/api/APIClient.d.ts +19 -14
  189. package/out/api/APIClient.d.ts.map +1 -1
  190. package/out/api/APIClient.js +22 -22
  191. package/out/api/APIClient.js.map +1 -1
  192. package/out/api/arcgis.d.ts +33 -0
  193. package/out/api/arcgis.d.ts.map +1 -0
  194. package/out/api/arcgis.js +53 -0
  195. package/out/api/arcgis.js.map +1 -0
  196. package/out/api/ckan.d.ts +72 -0
  197. package/out/api/ckan.d.ts.map +1 -0
  198. package/out/api/ckan.js +64 -0
  199. package/out/api/ckan.js.map +1 -0
  200. package/out/api/clock.d.ts +1 -1
  201. package/out/api/clock.d.ts.map +1 -1
  202. package/out/api/clock.js +1 -1
  203. package/out/api/clock.js.map +1 -1
  204. package/out/api/defaults.d.ts +28 -0
  205. package/out/api/defaults.d.ts.map +1 -0
  206. package/out/api/defaults.js +28 -0
  207. package/out/api/defaults.js.map +1 -0
  208. package/out/api/disk-storage.d.ts +8 -7
  209. package/out/api/disk-storage.d.ts.map +1 -1
  210. package/out/api/disk-storage.js +20 -19
  211. package/out/api/disk-storage.js.map +1 -1
  212. package/out/api/headless.d.ts.map +1 -1
  213. package/out/api/headless.js.map +1 -1
  214. package/out/api/host.d.ts +43 -0
  215. package/out/api/host.d.ts.map +1 -0
  216. package/out/api/host.js +36 -0
  217. package/out/api/host.js.map +1 -0
  218. package/out/api/index.d.ts +11 -6
  219. package/out/api/index.d.ts.map +1 -1
  220. package/out/api/index.js +11 -6
  221. package/out/api/index.js.map +1 -1
  222. package/out/api/ogc.d.ts +78 -0
  223. package/out/api/ogc.d.ts.map +1 -0
  224. package/out/api/ogc.js +166 -0
  225. package/out/api/ogc.js.map +1 -0
  226. package/out/api/paced-client.d.ts +45 -0
  227. package/out/api/paced-client.d.ts.map +1 -0
  228. package/out/api/paced-client.js +32 -0
  229. package/out/api/paced-client.js.map +1 -0
  230. package/out/api/pacer.d.ts +8 -8
  231. package/out/api/pacer.d.ts.map +1 -1
  232. package/out/api/pacer.js +8 -8
  233. package/out/api/pacer.js.map +1 -1
  234. package/out/api/responses.d.ts +9 -0
  235. package/out/api/responses.d.ts.map +1 -1
  236. package/out/api/responses.js +14 -3
  237. package/out/api/responses.js.map +1 -1
  238. package/out/api/retry.d.ts +7 -7
  239. package/out/api/retry.d.ts.map +1 -1
  240. package/out/api/retry.js +12 -12
  241. package/out/api/retry.js.map +1 -1
  242. package/out/api/test-clocks.d.ts +8 -2
  243. package/out/api/test-clocks.d.ts.map +1 -1
  244. package/out/api/test-clocks.js +5 -4
  245. package/out/api/test-clocks.js.map +1 -1
  246. package/out/api/test-transport.d.ts +1 -1
  247. package/out/api/test-transport.d.ts.map +1 -1
  248. package/out/api/test-transport.js.map +1 -1
  249. package/out/coarse-placer/coarse-placer.d.ts +13 -1
  250. package/out/coarse-placer/coarse-placer.d.ts.map +1 -1
  251. package/out/coarse-placer/coarse-placer.js +29 -13
  252. package/out/coarse-placer/coarse-placer.js.map +1 -1
  253. package/out/coarse-placer/featurize.d.ts +11 -2
  254. package/out/coarse-placer/featurize.d.ts.map +1 -1
  255. package/out/coarse-placer/featurize.js +9 -10
  256. package/out/coarse-placer/featurize.js.map +1 -1
  257. package/out/coarse-placer/fnv-hash.d.ts +15 -0
  258. package/out/coarse-placer/fnv-hash.d.ts.map +1 -0
  259. package/out/coarse-placer/fnv-hash.js +22 -0
  260. package/out/coarse-placer/fnv-hash.js.map +1 -0
  261. package/out/coarse-placer/math.d.ts +25 -0
  262. package/out/coarse-placer/math.d.ts.map +1 -0
  263. package/out/coarse-placer/math.js +49 -0
  264. package/out/coarse-placer/math.js.map +1 -0
  265. package/out/coarse-placer/tools/build-dataset.d.ts +4 -3
  266. package/out/coarse-placer/tools/build-dataset.d.ts.map +1 -1
  267. package/out/coarse-placer/tools/build-dataset.js +21 -31
  268. package/out/coarse-placer/tools/build-dataset.js.map +1 -1
  269. package/out/coarse-placer/tools/build-outlier-exposure.d.ts +3 -5
  270. package/out/coarse-placer/tools/build-outlier-exposure.d.ts.map +1 -1
  271. package/out/coarse-placer/tools/build-outlier-exposure.js +12 -18
  272. package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
  273. package/out/coarse-placer/tools/build-outlier-latin.d.ts +3 -2
  274. package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -1
  275. package/out/coarse-placer/tools/build-outlier-latin.js +19 -46
  276. package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
  277. package/out/coarse-placer/tools/build-outlier-oa.d.ts +3 -2
  278. package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -1
  279. package/out/coarse-placer/tools/build-outlier-oa.js +22 -52
  280. package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
  281. package/out/coarse-placer/tools/country-sets.d.ts +28 -0
  282. package/out/coarse-placer/tools/country-sets.d.ts.map +1 -0
  283. package/out/coarse-placer/tools/country-sets.js +45 -0
  284. package/out/coarse-placer/tools/country-sets.js.map +1 -0
  285. package/out/coarse-placer/tools/eval-latin-offmap.d.ts +4 -3
  286. package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
  287. package/out/coarse-placer/tools/eval-latin-offmap.js +10 -34
  288. package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
  289. package/out/coarse-placer/tools/eval-openset.d.ts +3 -2
  290. package/out/coarse-placer/tools/eval-openset.d.ts.map +1 -1
  291. package/out/coarse-placer/tools/eval-openset.js +19 -56
  292. package/out/coarse-placer/tools/eval-openset.js.map +1 -1
  293. package/out/coarse-placer/tools/eval-quant-compare.d.ts +6 -5
  294. package/out/coarse-placer/tools/eval-quant-compare.d.ts.map +1 -1
  295. package/out/coarse-placer/tools/eval-quant-compare.js +13 -39
  296. package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
  297. package/out/coarse-placer/tools/eval.d.ts +3 -2
  298. package/out/coarse-placer/tools/eval.d.ts.map +1 -1
  299. package/out/coarse-placer/tools/eval.js +21 -23
  300. package/out/coarse-placer/tools/eval.js.map +1 -1
  301. package/out/coarse-placer/tools/index.d.ts +15 -14
  302. package/out/coarse-placer/tools/index.d.ts.map +1 -1
  303. package/out/coarse-placer/tools/index.js +15 -14
  304. package/out/coarse-placer/tools/index.js.map +1 -1
  305. package/out/coarse-placer/tools/outlier-rows.d.ts +38 -0
  306. package/out/coarse-placer/tools/outlier-rows.d.ts.map +1 -0
  307. package/out/coarse-placer/tools/outlier-rows.js +67 -0
  308. package/out/coarse-placer/tools/outlier-rows.js.map +1 -0
  309. package/out/coarse-placer/tools/paths.d.ts +34 -0
  310. package/out/coarse-placer/tools/paths.d.ts.map +1 -0
  311. package/out/coarse-placer/tools/paths.js +64 -0
  312. package/out/coarse-placer/tools/paths.js.map +1 -0
  313. package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
  314. package/out/coarse-placer/tools/probe-frontier.js +13 -14
  315. package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
  316. package/out/coarse-placer/tools/quantize.d.ts +3 -2
  317. package/out/coarse-placer/tools/quantize.d.ts.map +1 -1
  318. package/out/coarse-placer/tools/quantize.js +13 -14
  319. package/out/coarse-placer/tools/quantize.js.map +1 -1
  320. package/out/coarse-placer/tools/train.d.ts +3 -2
  321. package/out/coarse-placer/tools/train.d.ts.map +1 -1
  322. package/out/coarse-placer/tools/train.js +21 -36
  323. package/out/coarse-placer/tools/train.js.map +1 -1
  324. package/out/collections.d.ts.map +1 -1
  325. package/out/collections.js.map +1 -1
  326. package/out/crypto/base64url.d.ts +13 -0
  327. package/out/crypto/base64url.d.ts.map +1 -0
  328. package/out/crypto/base64url.js +34 -0
  329. package/out/crypto/base64url.js.map +1 -0
  330. package/out/crypto/digest.d.ts +12 -0
  331. package/out/crypto/digest.d.ts.map +1 -0
  332. package/out/crypto/digest.js +16 -0
  333. package/out/crypto/digest.js.map +1 -0
  334. package/out/crypto/ed25519.d.ts +35 -0
  335. package/out/crypto/ed25519.d.ts.map +1 -0
  336. package/out/crypto/ed25519.js +89 -0
  337. package/out/crypto/ed25519.js.map +1 -0
  338. package/out/crypto/node.d.ts.map +1 -1
  339. package/out/crypto/node.js +2 -1
  340. package/out/crypto/node.js.map +1 -1
  341. package/out/data-root.d.ts +131 -0
  342. package/out/data-root.d.ts.map +1 -0
  343. package/out/data-root.js +135 -0
  344. package/out/data-root.js.map +1 -0
  345. package/out/decoder/build-tree.d.ts +2 -2
  346. package/out/decoder/build-tree.d.ts.map +1 -1
  347. package/out/decoder/build-tree.js +1 -1
  348. package/out/decoder/build-tree.js.map +1 -1
  349. package/out/decoder/calibration.d.ts +1 -1
  350. package/out/decoder/calibration.d.ts.map +1 -1
  351. package/out/decoder/calibration.js +1 -1
  352. package/out/decoder/calibration.js.map +1 -1
  353. package/out/decoder/containment.d.ts +3 -3
  354. package/out/decoder/containment.d.ts.map +1 -1
  355. package/out/decoder/containment.js +10 -3
  356. package/out/decoder/containment.js.map +1 -1
  357. package/out/decoder/index.d.ts +13 -11
  358. package/out/decoder/index.d.ts.map +1 -1
  359. package/out/decoder/index.js +13 -11
  360. package/out/decoder/index.js.map +1 -1
  361. package/out/decoder/parse-diff.d.ts +125 -0
  362. package/out/decoder/parse-diff.d.ts.map +1 -0
  363. package/out/decoder/parse-diff.js +219 -0
  364. package/out/decoder/parse-diff.js.map +1 -0
  365. package/out/decoder/proposals-to-tree.d.ts +2 -2
  366. package/out/decoder/proposals-to-tree.d.ts.map +1 -1
  367. package/out/decoder/proposals-to-tree.js.map +1 -1
  368. package/out/decoder/resolve-proposal-overlaps.d.ts +3 -3
  369. package/out/decoder/resolve-proposal-overlaps.d.ts.map +1 -1
  370. package/out/decoder/resolve-proposal-overlaps.js +2 -2
  371. package/out/decoder/resolve-proposal-overlaps.js.map +1 -1
  372. package/out/decoder/serialize-json.d.ts +32 -3
  373. package/out/decoder/serialize-json.d.ts.map +1 -1
  374. package/out/decoder/serialize-json.js +25 -8
  375. package/out/decoder/serialize-json.js.map +1 -1
  376. package/out/decoder/serialize-tuples.d.ts +13 -2
  377. package/out/decoder/serialize-tuples.d.ts.map +1 -1
  378. package/out/decoder/serialize-tuples.js +24 -2
  379. package/out/decoder/serialize-tuples.js.map +1 -1
  380. package/out/decoder/serialize-xml.d.ts +2 -2
  381. package/out/decoder/serialize-xml.d.ts.map +1 -1
  382. package/out/decoder/serialize-xml.js +7 -3
  383. package/out/decoder/serialize-xml.js.map +1 -1
  384. package/out/decoder/tree-shape.d.ts +84 -0
  385. package/out/decoder/tree-shape.d.ts.map +1 -0
  386. package/out/decoder/tree-shape.js +93 -0
  387. package/out/decoder/tree-shape.js.map +1 -0
  388. package/out/decoder/tree-walk.d.ts +50 -0
  389. package/out/decoder/tree-walk.d.ts.map +1 -0
  390. package/out/decoder/tree-walk.js +78 -0
  391. package/out/decoder/tree-walk.js.map +1 -0
  392. package/out/decoder/types.d.ts +13 -2
  393. package/out/decoder/types.d.ts.map +1 -1
  394. package/out/decoder/types.js +1 -1
  395. package/out/decoder/types.js.map +1 -1
  396. package/out/decoder/unknown-spans.d.ts +1 -15
  397. package/out/decoder/unknown-spans.d.ts.map +1 -1
  398. package/out/decoder/unknown-spans.js +16 -6
  399. package/out/decoder/unknown-spans.js.map +1 -1
  400. package/out/decoder/validate-tree.d.ts +10 -2
  401. package/out/decoder/validate-tree.d.ts.map +1 -1
  402. package/out/decoder/validate-tree.js +5 -4
  403. package/out/decoder/validate-tree.js.map +1 -1
  404. package/out/env/index.d.ts +32 -89
  405. package/out/env/index.d.ts.map +1 -1
  406. package/out/env/index.js +57 -18
  407. package/out/env/index.js.map +1 -1
  408. package/out/env/paths.d.ts +7 -8
  409. package/out/env/paths.d.ts.map +1 -1
  410. package/out/env/paths.js +14 -30
  411. package/out/env/paths.js.map +1 -1
  412. package/out/env/schema.d.ts +20 -91
  413. package/out/env/schema.d.ts.map +1 -1
  414. package/out/env/schema.js +77 -164
  415. package/out/env/schema.js.map +1 -1
  416. package/out/env/utils.d.ts +21 -0
  417. package/out/env/utils.d.ts.map +1 -0
  418. package/out/env/utils.js +23 -0
  419. package/out/env/utils.js.map +1 -0
  420. package/out/errors/schema.d.ts +7 -0
  421. package/out/errors/schema.d.ts.map +1 -1
  422. package/out/errors/schema.js +7 -5
  423. package/out/errors/schema.js.map +1 -1
  424. package/out/fs/compression.d.ts +22 -0
  425. package/out/fs/compression.d.ts.map +1 -0
  426. package/out/fs/compression.js +50 -0
  427. package/out/fs/compression.js.map +1 -0
  428. package/out/fs/formatters.d.ts +69 -0
  429. package/out/fs/formatters.d.ts.map +1 -0
  430. package/out/fs/formatters.js +91 -0
  431. package/out/fs/formatters.js.map +1 -0
  432. package/out/fs/readers.d.ts +221 -0
  433. package/out/fs/readers.d.ts.map +1 -0
  434. package/out/fs/readers.js +349 -0
  435. package/out/fs/readers.js.map +1 -0
  436. package/out/fs/streams.d.ts +38 -0
  437. package/out/fs/streams.d.ts.map +1 -0
  438. package/out/fs/streams.js +37 -0
  439. package/out/fs/streams.js.map +1 -0
  440. package/out/fs/temporary.d.ts +54 -0
  441. package/out/fs/temporary.d.ts.map +1 -0
  442. package/out/fs/temporary.js +39 -0
  443. package/out/fs/temporary.js.map +1 -0
  444. package/out/fs/writers.d.ts +132 -0
  445. package/out/fs/writers.d.ts.map +1 -0
  446. package/out/fs/writers.js +203 -0
  447. package/out/fs/writers.js.map +1 -0
  448. package/out/fs/zip.d.ts +6 -2
  449. package/out/fs/zip.d.ts.map +1 -1
  450. package/out/fs/zip.js +80 -83
  451. package/out/fs/zip.js.map +1 -1
  452. package/out/git.d.ts +33 -0
  453. package/out/git.d.ts.map +1 -0
  454. package/out/git.js +48 -0
  455. package/out/git.js.map +1 -0
  456. package/out/{utils/hash.d.ts → hash.d.ts} +8 -4
  457. package/out/hash.d.ts.map +1 -0
  458. package/out/{utils/hash.js → hash.js} +12 -7
  459. package/out/hash.js.map +1 -0
  460. package/out/html/document.d.ts +57 -0
  461. package/out/html/document.d.ts.map +1 -0
  462. package/out/html/document.js +79 -0
  463. package/out/html/document.js.map +1 -0
  464. package/out/html/tables.d.ts +53 -0
  465. package/out/html/tables.d.ts.map +1 -0
  466. package/out/html/tables.js +117 -0
  467. package/out/html/tables.js.map +1 -0
  468. package/out/html/text.d.ts +40 -0
  469. package/out/html/text.d.ts.map +1 -0
  470. package/out/html/text.js +110 -0
  471. package/out/html/text.js.map +1 -0
  472. package/out/index.d.ts +10 -7
  473. package/out/index.d.ts.map +1 -1
  474. package/out/index.js +10 -7
  475. package/out/index.js.map +1 -1
  476. package/out/json.d.ts +43 -0
  477. package/out/json.d.ts.map +1 -0
  478. package/out/json.js +68 -0
  479. package/out/json.js.map +1 -0
  480. package/out/layers/coverage.d.ts +123 -0
  481. package/out/layers/coverage.d.ts.map +1 -0
  482. package/out/layers/coverage.js +132 -0
  483. package/out/layers/coverage.js.map +1 -0
  484. package/out/layers/feature-count.d.ts +29 -0
  485. package/out/layers/feature-count.d.ts.map +1 -0
  486. package/out/layers/feature-count.js +23 -0
  487. package/out/layers/feature-count.js.map +1 -0
  488. package/out/layers/index.d.ts +4 -2
  489. package/out/layers/index.d.ts.map +1 -1
  490. package/out/layers/index.js +4 -2
  491. package/out/layers/index.js.map +1 -1
  492. package/out/layers/manifest.d.ts +131 -7
  493. package/out/layers/manifest.d.ts.map +1 -1
  494. package/out/layers/manifest.js +183 -7
  495. package/out/layers/manifest.js.map +1 -1
  496. package/out/layers/schema.d.ts +23 -5
  497. package/out/layers/schema.d.ts.map +1 -1
  498. package/out/layers/schema.js +6 -0
  499. package/out/layers/schema.js.map +1 -1
  500. package/out/license/configured.d.ts +17 -0
  501. package/out/license/configured.d.ts.map +1 -0
  502. package/out/license/configured.js +27 -0
  503. package/out/license/configured.js.map +1 -0
  504. package/out/license/docs-site.d.ts +23 -0
  505. package/out/license/docs-site.d.ts.map +1 -0
  506. package/out/license/docs-site.js +32 -0
  507. package/out/license/docs-site.js.map +1 -0
  508. package/out/license/index.d.ts +18 -0
  509. package/out/license/index.d.ts.map +1 -0
  510. package/out/license/index.js +18 -0
  511. package/out/license/index.js.map +1 -0
  512. package/out/license/key-file.d.ts +36 -0
  513. package/out/license/key-file.d.ts.map +1 -0
  514. package/out/license/key-file.js +64 -0
  515. package/out/license/key-file.js.map +1 -0
  516. package/out/license/key.d.ts +96 -0
  517. package/out/license/key.d.ts.map +1 -0
  518. package/out/license/key.js +155 -0
  519. package/out/license/key.js.map +1 -0
  520. package/out/license/obligations.d.ts +87 -0
  521. package/out/license/obligations.d.ts.map +1 -0
  522. package/out/license/obligations.js +129 -0
  523. package/out/license/obligations.js.map +1 -0
  524. package/out/license/publication.d.ts +36 -0
  525. package/out/license/publication.d.ts.map +1 -0
  526. package/out/license/publication.js +61 -0
  527. package/out/license/publication.js.map +1 -0
  528. package/out/license/register.d.ts +63 -0
  529. package/out/license/register.d.ts.map +1 -0
  530. package/out/license/register.js +73 -0
  531. package/out/license/register.js.map +1 -0
  532. package/out/license/stamp.d.ts +55 -0
  533. package/out/license/stamp.d.ts.map +1 -0
  534. package/out/license/stamp.js +62 -0
  535. package/out/license/stamp.js.map +1 -0
  536. package/out/license/status.d.ts +54 -0
  537. package/out/license/status.d.ts.map +1 -0
  538. package/out/license/status.js +85 -0
  539. package/out/license/status.js.map +1 -0
  540. package/out/locale/index.d.ts +3 -3
  541. package/out/locale/index.d.ts.map +1 -1
  542. package/out/locale/index.js +3 -3
  543. package/out/locale/index.js.map +1 -1
  544. package/out/locale/locale.d.ts +2 -2
  545. package/out/locale/locale.d.ts.map +1 -1
  546. package/out/locale/locale.js.map +1 -1
  547. package/out/locale/profiles/en-us.d.ts +1 -1
  548. package/out/locale/profiles/en-us.d.ts.map +1 -1
  549. package/out/locale/profiles/en-us.js.map +1 -1
  550. package/out/locale/profiles/fr-fr.d.ts +1 -1
  551. package/out/locale/profiles/fr-fr.d.ts.map +1 -1
  552. package/out/locale/profiles/fr-fr.js.map +1 -1
  553. package/out/locale/profiles/index.d.ts +3 -3
  554. package/out/locale/profiles/index.d.ts.map +1 -1
  555. package/out/locale/profiles/index.js +3 -3
  556. package/out/locale/profiles/index.js.map +1 -1
  557. package/out/locale/profiles/ja-jp.d.ts +1 -1
  558. package/out/locale/profiles/ja-jp.d.ts.map +1 -1
  559. package/out/locale/profiles/ja-jp.js.map +1 -1
  560. package/out/locale/registry.d.ts +1 -1
  561. package/out/locale/registry.d.ts.map +1 -1
  562. package/out/locale/registry.js +1 -1
  563. package/out/locale/registry.js.map +1 -1
  564. package/out/locale/zh-cn-units.d.ts +67 -0
  565. package/out/locale/zh-cn-units.d.ts.map +1 -0
  566. package/out/locale/zh-cn-units.js +109 -0
  567. package/out/locale/zh-cn-units.js.map +1 -0
  568. package/out/logging/index.d.ts +2 -2
  569. package/out/logging/index.d.ts.map +1 -1
  570. package/out/logging/index.js +2 -2
  571. package/out/logging/index.js.map +1 -1
  572. package/out/logging/shared.d.ts +5 -3
  573. package/out/logging/shared.d.ts.map +1 -1
  574. package/out/logging/shared.js +28 -4
  575. package/out/logging/shared.js.map +1 -1
  576. package/out/logging/utils.d.ts.map +1 -1
  577. package/out/logging/utils.js.map +1 -1
  578. package/out/module/file-url.d.ts +21 -0
  579. package/out/module/file-url.d.ts.map +1 -0
  580. package/out/module/file-url.js +25 -0
  581. package/out/module/file-url.js.map +1 -0
  582. package/out/module/packaged-data.d.ts +19 -0
  583. package/out/module/packaged-data.d.ts.map +1 -0
  584. package/out/module/packaged-data.js +28 -0
  585. package/out/module/packaged-data.js.map +1 -0
  586. package/out/module/resolve-from.d.ts +52 -0
  587. package/out/module/resolve-from.d.ts.map +1 -0
  588. package/out/module/resolve-from.js +66 -0
  589. package/out/module/resolve-from.js.map +1 -0
  590. package/out/module/resolvers.d.ts +52 -0
  591. package/out/module/resolvers.d.ts.map +1 -0
  592. package/out/module/resolvers.js +74 -0
  593. package/out/module/resolvers.js.map +1 -0
  594. package/out/module/runtime.d.ts +11 -0
  595. package/out/module/runtime.d.ts.map +1 -0
  596. package/out/module/runtime.js +11 -0
  597. package/out/module/runtime.js.map +1 -0
  598. package/out/{utils/python-numeric.d.ts → numeric.d.ts} +6 -9
  599. package/out/numeric.d.ts.map +1 -0
  600. package/out/{utils/python-numeric.js → numeric.js} +15 -3
  601. package/out/numeric.js.map +1 -0
  602. package/out/objects.d.ts +13 -27
  603. package/out/objects.d.ts.map +1 -1
  604. package/out/objects.js +7 -37
  605. package/out/objects.js.map +1 -1
  606. package/out/{utils/repo.d.ts → paths.d.ts} +16 -2
  607. package/out/paths.d.ts.map +1 -0
  608. package/out/paths.js +134 -0
  609. package/out/paths.js.map +1 -0
  610. package/out/pipeline/index.d.ts +5 -9
  611. package/out/pipeline/index.d.ts.map +1 -1
  612. package/out/pipeline/index.js +3 -5
  613. package/out/pipeline/index.js.map +1 -1
  614. package/out/pipeline/runtime-pipeline.d.ts +66 -24
  615. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  616. package/out/pipeline/runtime-pipeline.js +63 -165
  617. package/out/pipeline/runtime-pipeline.js.map +1 -1
  618. package/out/pipeline/span-proposer.d.ts.map +1 -1
  619. package/out/pipeline/span-proposer.js +1 -1
  620. package/out/pipeline/span-proposer.js.map +1 -1
  621. package/out/pipeline/types.d.ts +78 -34
  622. package/out/pipeline/types.d.ts.map +1 -1
  623. package/out/pipeline/types.js +21 -3
  624. package/out/pipeline/types.js.map +1 -1
  625. package/out/policy/defaults.d.ts +2 -2
  626. package/out/policy/defaults.d.ts.map +1 -1
  627. package/out/policy/defaults.js +1 -1
  628. package/out/policy/defaults.js.map +1 -1
  629. package/out/policy/index.d.ts +4 -4
  630. package/out/policy/index.d.ts.map +1 -1
  631. package/out/policy/index.js +4 -4
  632. package/out/policy/index.js.map +1 -1
  633. package/out/policy/policy.d.ts +2 -2
  634. package/out/policy/policy.d.ts.map +1 -1
  635. package/out/policy/policy.js +1 -1
  636. package/out/policy/policy.js.map +1 -1
  637. package/out/policy/proposal-collection.d.ts +3 -3
  638. package/out/policy/proposal-collection.d.ts.map +1 -1
  639. package/out/policy/proposal-collection.js.map +1 -1
  640. package/out/policy/registry.d.ts +2 -2
  641. package/out/policy/registry.d.ts.map +1 -1
  642. package/out/policy/registry.js +1 -1
  643. package/out/policy/registry.js.map +1 -1
  644. package/out/process.d.ts +110 -0
  645. package/out/process.d.ts.map +1 -0
  646. package/out/process.js +72 -0
  647. package/out/process.js.map +1 -0
  648. package/out/{utils/python-random.d.ts → random.d.ts} +1 -1
  649. package/out/random.d.ts.map +1 -0
  650. package/out/{utils/python-random.js → random.js} +1 -1
  651. package/out/random.js.map +1 -0
  652. package/out/release-config.d.ts +84 -0
  653. package/out/release-config.d.ts.map +1 -0
  654. package/out/release-config.js +45 -0
  655. package/out/release-config.js.map +1 -0
  656. package/out/resolver/authoritative-provider.d.ts +171 -0
  657. package/out/resolver/authoritative-provider.d.ts.map +1 -0
  658. package/out/resolver/authoritative-provider.js +51 -0
  659. package/out/resolver/authoritative-provider.js.map +1 -0
  660. package/out/resolver/coverage-facts.d.ts +89 -0
  661. package/out/resolver/coverage-facts.d.ts.map +1 -0
  662. package/out/resolver/coverage-facts.js +22 -0
  663. package/out/resolver/coverage-facts.js.map +1 -0
  664. package/out/resolver/fixture-authoritative-provider.d.ts +48 -0
  665. package/out/resolver/fixture-authoritative-provider.d.ts.map +1 -0
  666. package/out/resolver/fixture-authoritative-provider.js +68 -0
  667. package/out/resolver/fixture-authoritative-provider.js.map +1 -0
  668. package/out/resolver/index.d.ts +8 -4
  669. package/out/resolver/index.d.ts.map +1 -1
  670. package/out/resolver/index.js +5 -2
  671. package/out/resolver/index.js.map +1 -1
  672. package/out/resolver/lookup-types.d.ts +179 -0
  673. package/out/resolver/lookup-types.d.ts.map +1 -0
  674. package/out/resolver/lookup-types.js +11 -0
  675. package/out/resolver/lookup-types.js.map +1 -0
  676. package/out/resolver/placetype-map.d.ts +76 -0
  677. package/out/resolver/placetype-map.d.ts.map +1 -0
  678. package/out/resolver/placetype-map.js +106 -0
  679. package/out/resolver/placetype-map.js.map +1 -0
  680. package/out/resolver/postcode-format.d.ts +39 -0
  681. package/out/resolver/postcode-format.d.ts.map +1 -0
  682. package/out/resolver/postcode-format.js +84 -0
  683. package/out/resolver/postcode-format.js.map +1 -0
  684. package/out/resolver/referential.d.ts +1 -1
  685. package/out/resolver/referential.d.ts.map +1 -1
  686. package/out/resolver/referential.js +1 -1
  687. package/out/resolver/referential.js.map +1 -1
  688. package/out/resolver/types.d.ts +338 -348
  689. package/out/resolver/types.d.ts.map +1 -1
  690. package/out/resolver/types.js +4 -97
  691. package/out/resolver/types.js.map +1 -1
  692. package/out/resources/debugging.d.ts.map +1 -1
  693. package/out/resources/debugging.js.map +1 -1
  694. package/out/resources/git.d.ts +8 -1
  695. package/out/resources/git.d.ts.map +1 -1
  696. package/out/resources/git.js +9 -10
  697. package/out/resources/git.js.map +1 -1
  698. package/out/resources/index.d.ts +7 -10
  699. package/out/resources/index.d.ts.map +1 -1
  700. package/out/resources/index.js +7 -10
  701. package/out/resources/index.js.map +1 -1
  702. package/out/resources/languages/index.d.ts +2 -2
  703. package/out/resources/languages/index.d.ts.map +1 -1
  704. package/out/resources/languages/index.js +2 -2
  705. package/out/resources/languages/index.js.map +1 -1
  706. package/out/resources/languages/types.gen.d.ts +1 -1
  707. package/out/resources/languages/types.gen.d.ts.map +1 -1
  708. package/out/resources/languages/types.gen.js +40 -0
  709. package/out/resources/languages/types.gen.js.map +1 -1
  710. package/out/resources/libpostal.d.ts +10 -29
  711. package/out/resources/libpostal.d.ts.map +1 -1
  712. package/out/resources/libpostal.js +6 -122
  713. package/out/resources/libpostal.js.map +1 -1
  714. package/out/resources/locale.d.ts.map +1 -1
  715. package/out/resources/locale.js.map +1 -1
  716. package/out/resources/set.d.ts +0 -13
  717. package/out/resources/set.d.ts.map +1 -1
  718. package/out/resources/set.js +0 -32
  719. package/out/resources/set.js.map +1 -1
  720. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +21 -4
  721. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
  722. package/out/resources/whosonfirst/PlacetypeDataSource.js +33 -11
  723. package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
  724. package/out/resources/whosonfirst/backoff.d.ts +2 -0
  725. package/out/resources/whosonfirst/backoff.d.ts.map +1 -1
  726. package/out/resources/whosonfirst/backoff.js +4 -2
  727. package/out/resources/whosonfirst/backoff.js.map +1 -1
  728. package/out/resources/whosonfirst/extract-repo.d.ts +55 -0
  729. package/out/resources/whosonfirst/extract-repo.d.ts.map +1 -0
  730. package/out/resources/whosonfirst/extract-repo.js +91 -0
  731. package/out/resources/whosonfirst/extract-repo.js.map +1 -0
  732. package/out/resources/whosonfirst/index.d.ts +3 -5
  733. package/out/resources/whosonfirst/index.d.ts.map +1 -1
  734. package/out/resources/whosonfirst/index.js +3 -5
  735. package/out/resources/whosonfirst/index.js.map +1 -1
  736. package/out/resources/whosonfirst/placetypes/Placetype.d.ts +1 -1
  737. package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
  738. package/out/resources/whosonfirst/placetypes/Placetype.js +5 -5
  739. package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
  740. package/out/resources/whosonfirst/placetypes/admin.d.ts +10 -2
  741. package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
  742. package/out/resources/whosonfirst/placetypes/admin.js +1 -1
  743. package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
  744. package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
  745. package/out/resources/whosonfirst/placetypes/definition.js +1 -1
  746. package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
  747. package/out/resources/whosonfirst/placetypes/graph.d.ts +2 -2
  748. package/out/resources/whosonfirst/placetypes/graph.d.ts.map +1 -1
  749. package/out/resources/whosonfirst/placetypes/graph.js +0 -0
  750. package/out/resources/whosonfirst/placetypes/graph.js.map +1 -1
  751. package/out/resources/whosonfirst/placetypes/index.d.ts +7 -6
  752. package/out/resources/whosonfirst/placetypes/index.d.ts.map +1 -1
  753. package/out/resources/whosonfirst/placetypes/index.js +7 -6
  754. package/out/resources/whosonfirst/placetypes/index.js.map +1 -1
  755. package/out/resources/whosonfirst/placetypes/mermaid.d.ts +2 -2
  756. package/out/resources/whosonfirst/placetypes/mermaid.d.ts.map +1 -1
  757. package/out/resources/whosonfirst/placetypes/mermaid.js +1 -1
  758. package/out/resources/whosonfirst/placetypes/mermaid.js.map +1 -1
  759. package/out/resources/whosonfirst/placetypes/specificity.d.ts +65 -0
  760. package/out/resources/whosonfirst/placetypes/specificity.d.ts.map +1 -0
  761. package/out/resources/whosonfirst/placetypes/specificity.js +101 -0
  762. package/out/resources/whosonfirst/placetypes/specificity.js.map +1 -0
  763. package/out/resources/whosonfirst/placetypes/tree.d.ts +2 -2
  764. package/out/resources/whosonfirst/placetypes/tree.d.ts.map +1 -1
  765. package/out/resources/whosonfirst/placetypes/tree.js.map +1 -1
  766. package/out/routing/index.d.ts.map +1 -1
  767. package/out/routing/index.js +2 -1
  768. package/out/routing/index.js.map +1 -1
  769. package/out/scripting/arguments.d.ts +43 -0
  770. package/out/scripting/arguments.d.ts.map +1 -0
  771. package/out/scripting/arguments.js +58 -0
  772. package/out/scripting/arguments.js.map +1 -0
  773. package/out/scripting/command.d.ts +28 -0
  774. package/out/scripting/command.d.ts.map +1 -0
  775. package/out/scripting/command.js +47 -0
  776. package/out/scripting/command.js.map +1 -0
  777. package/out/scripting/index.d.ts +1 -1
  778. package/out/scripting/index.d.ts.map +1 -1
  779. package/out/scripting/index.js +3 -3
  780. package/out/scripting/index.js.map +1 -1
  781. package/out/scripting/ingest-chunk-script.d.ts +63 -0
  782. package/out/scripting/ingest-chunk-script.d.ts.map +1 -0
  783. package/out/scripting/ingest-chunk-script.js +51 -0
  784. package/out/scripting/ingest-chunk-script.js.map +1 -0
  785. package/out/scripting/utils/index.d.ts +6 -12
  786. package/out/scripting/utils/index.d.ts.map +1 -1
  787. package/out/scripting/utils/index.js +14 -24
  788. package/out/scripting/utils/index.js.map +1 -1
  789. package/out/stats.d.ts +33 -0
  790. package/out/stats.d.ts.map +1 -0
  791. package/out/stats.js +53 -0
  792. package/out/stats.js.map +1 -0
  793. package/out/{identifiers.d.ts → strings/case.d.ts} +6 -2
  794. package/out/strings/case.d.ts.map +1 -0
  795. package/out/{identifiers.js → strings/case.js} +9 -2
  796. package/out/strings/case.js.map +1 -0
  797. package/out/strings/compare.d.ts +14 -0
  798. package/out/strings/compare.d.ts.map +1 -0
  799. package/out/strings/compare.js +20 -0
  800. package/out/strings/compare.js.map +1 -0
  801. package/out/strings/escape.d.ts +11 -0
  802. package/out/strings/escape.d.ts.map +1 -0
  803. package/out/strings/escape.js +23 -0
  804. package/out/strings/escape.js.map +1 -0
  805. package/out/strings/format.d.ts +12 -0
  806. package/out/strings/format.d.ts.map +1 -0
  807. package/out/strings/format.js +14 -0
  808. package/out/strings/format.js.map +1 -0
  809. package/out/{utils → strings}/python-json.d.ts +6 -7
  810. package/out/strings/python-json.d.ts.map +1 -0
  811. package/out/{utils → strings}/python-json.js +1 -8
  812. package/out/strings/python-json.js.map +1 -0
  813. package/out/strings/regexp.d.ts +11 -0
  814. package/out/strings/regexp.d.ts.map +1 -0
  815. package/out/strings/regexp.js +13 -0
  816. package/out/strings/regexp.js.map +1 -0
  817. package/out/tokenization/Graph.d.ts +1 -1
  818. package/out/tokenization/Graph.d.ts.map +1 -1
  819. package/out/tokenization/Graph.js +1 -1
  820. package/out/tokenization/Graph.js.map +1 -1
  821. package/out/tokenization/Span.d.ts +5 -5
  822. package/out/tokenization/Span.d.ts.map +1 -1
  823. package/out/tokenization/Span.js +2 -2
  824. package/out/tokenization/Span.js.map +1 -1
  825. package/out/tokenization/index.d.ts +3 -3
  826. package/out/tokenization/index.d.ts.map +1 -1
  827. package/out/tokenization/index.js +3 -3
  828. package/out/tokenization/index.js.map +1 -1
  829. package/out/tokenization/normalizer.d.ts.map +1 -1
  830. package/out/tokenization/normalizer.js.map +1 -1
  831. package/out/tools/download-libpostal-resources.d.ts.map +1 -1
  832. package/out/tools/download-libpostal-resources.js +20 -28
  833. package/out/tools/download-libpostal-resources.js.map +1 -1
  834. package/out/tools/download-ssl-address.d.ts +3 -3
  835. package/out/tools/download-ssl-address.d.ts.map +1 -1
  836. package/out/tools/download-ssl-address.js +30 -16
  837. package/out/tools/download-ssl-address.js.map +1 -1
  838. package/out/tools/generate-language-types.d.ts +16 -1
  839. package/out/tools/generate-language-types.d.ts.map +1 -1
  840. package/out/tools/generate-language-types.js +41 -9
  841. package/out/tools/generate-language-types.js.map +1 -1
  842. package/out/tools/index.d.ts +4 -5
  843. package/out/tools/index.d.ts.map +1 -1
  844. package/out/tools/index.js +4 -5
  845. package/out/tools/index.js.map +1 -1
  846. package/out/trust-policies.d.ts +58 -0
  847. package/out/trust-policies.d.ts.map +1 -0
  848. package/out/trust-policies.js +99 -0
  849. package/out/trust-policies.js.map +1 -0
  850. package/out/types/Classification.d.ts +4 -4
  851. package/out/types/Classification.d.ts.map +1 -1
  852. package/out/types/Classification.js.map +1 -1
  853. package/out/types/classifier.d.ts +2 -2
  854. package/out/types/classifier.d.ts.map +1 -1
  855. package/out/types/classifier.js.map +1 -1
  856. package/out/types/component.d.ts +7 -2
  857. package/out/types/component.d.ts.map +1 -1
  858. package/out/types/component.js +16 -0
  859. package/out/types/component.js.map +1 -1
  860. package/out/types/index.d.ts +4 -4
  861. package/out/types/index.d.ts.map +1 -1
  862. package/out/types/index.js +4 -4
  863. package/out/types/index.js.map +1 -1
  864. package/out/types/mapping.d.ts +2 -2
  865. package/out/types/mapping.d.ts.map +1 -1
  866. package/out/types/mapping.js.map +1 -1
  867. package/out/utils/chunk-process.d.ts +64 -0
  868. package/out/utils/chunk-process.d.ts.map +1 -0
  869. package/out/utils/chunk-process.js +78 -0
  870. package/out/utils/chunk-process.js.map +1 -0
  871. package/out/utils/collections.d.ts +12 -0
  872. package/out/utils/collections.d.ts.map +1 -0
  873. package/out/utils/collections.js +16 -0
  874. package/out/utils/collections.js.map +1 -0
  875. package/out/utils/events.d.ts +10 -0
  876. package/out/utils/events.d.ts.map +1 -0
  877. package/out/utils/events.js +10 -0
  878. package/out/utils/events.js.map +1 -0
  879. package/out/utils/geodatabase-archive.d.ts +58 -0
  880. package/out/utils/geodatabase-archive.d.ts.map +1 -0
  881. package/out/utils/geodatabase-archive.js +59 -0
  882. package/out/utils/geodatabase-archive.js.map +1 -0
  883. package/out/utils/index.d.ts +14 -9
  884. package/out/utils/index.d.ts.map +1 -1
  885. package/out/utils/index.js +14 -9
  886. package/out/utils/index.js.map +1 -1
  887. package/out/utils/sleep.d.ts +11 -0
  888. package/out/utils/sleep.d.ts.map +1 -0
  889. package/out/utils/sleep.js +14 -0
  890. package/out/utils/sleep.js.map +1 -0
  891. package/out/utils/sqlite-rows.d.ts +34 -0
  892. package/out/utils/sqlite-rows.d.ts.map +1 -0
  893. package/out/utils/sqlite-rows.js +37 -0
  894. package/out/utils/sqlite-rows.js.map +1 -0
  895. package/out/utils/stream-to-disk.d.ts +65 -0
  896. package/out/utils/stream-to-disk.d.ts.map +1 -0
  897. package/out/utils/stream-to-disk.js +73 -0
  898. package/out/utils/stream-to-disk.js.map +1 -0
  899. package/out/utils/system.d.ts +33 -0
  900. package/out/utils/system.d.ts.map +1 -0
  901. package/out/utils/system.js +46 -0
  902. package/out/utils/system.js.map +1 -0
  903. package/out/utils/time.d.ts +22 -0
  904. package/out/utils/time.d.ts.map +1 -0
  905. package/out/utils/time.js +28 -0
  906. package/out/utils/time.js.map +1 -0
  907. package/out/utils/union-find.d.ts +22 -0
  908. package/out/utils/union-find.d.ts.map +1 -0
  909. package/out/utils/union-find.js +38 -0
  910. package/out/utils/union-find.js.map +1 -0
  911. package/out/vale.d.ts +25 -0
  912. package/out/vale.d.ts.map +1 -0
  913. package/out/vale.js +25 -0
  914. package/out/vale.js.map +1 -0
  915. package/package.json +897 -64
  916. package/vitest.config.ts +13 -14
  917. package/coarse-placer/tools/fnv-hash.ts +0 -26
  918. package/coarse-placer/tools/index.ts +0 -23
  919. package/data/libpostal/dictionaries/all/chains.txt +0 -504
  920. package/data/whosonfirst/dictionaries/country/name:eng_x_preferred.txt +0 -220
  921. package/data/whosonfirst/dictionaries/country/wof:country.txt +0 -215
  922. package/data/whosonfirst/dictionaries/country/wof:country_alpha3.txt +0 -216
  923. package/data/whosonfirst/dictionaries/dependency/name:eng_x_preferred.txt +0 -42
  924. package/data/whosonfirst/dictionaries/dependency/wof:shortcode.txt +0 -34
  925. package/data/whosonfirst/dictionaries/locality/name:eng_x_preferred.txt +0 -261365
  926. package/data/whosonfirst/dictionaries/locality/name:fra_x_preferred.txt +0 -77631
  927. package/data/whosonfirst/dictionaries/region/abrv:eng_x_preferred.txt +0 -441
  928. package/data/whosonfirst/dictionaries/region/name:eng_x_preferred.txt +0 -4517
  929. package/data/whosonfirst/dictionaries/region/wof:shortcode.txt +0 -839
  930. package/db/schema.ts +0 -21
  931. package/decoder/index.ts +0 -17
  932. package/decoder/serialize-json.ts +0 -76
  933. package/env/index.ts +0 -42
  934. package/env/load.ts +0 -14
  935. package/env/paths.ts +0 -40
  936. package/env/schema.ts +0 -199
  937. package/errors/index.ts +0 -9
  938. package/fs/node.ts +0 -37
  939. package/index.ts +0 -13
  940. package/kysley/adapter.ts +0 -29
  941. package/kysley/client.ts +0 -30
  942. package/kysley/dialect-config.ts +0 -30
  943. package/kysley/dialect.ts +0 -67
  944. package/kysley/driver.ts +0 -175
  945. package/layers/manifest.ts +0 -169
  946. package/locale/index.ts +0 -9
  947. package/locale/profiles/index.ts +0 -9
  948. package/out/coarse-placer/tools/fnv-hash.d.ts +0 -17
  949. package/out/coarse-placer/tools/fnv-hash.d.ts.map +0 -1
  950. package/out/coarse-placer/tools/fnv-hash.js +0 -24
  951. package/out/coarse-placer/tools/fnv-hash.js.map +0 -1
  952. package/out/db/schema.d.ts +0 -21
  953. package/out/db/schema.d.ts.map +0 -1
  954. package/out/db/schema.js +0 -16
  955. package/out/db/schema.js.map +0 -1
  956. package/out/env/load.d.ts +0 -7
  957. package/out/env/load.d.ts.map +0 -1
  958. package/out/env/load.js +0 -13
  959. package/out/env/load.js.map +0 -1
  960. package/out/errors/index.d.ts +0 -9
  961. package/out/errors/index.d.ts.map +0 -1
  962. package/out/errors/index.js +0 -9
  963. package/out/errors/index.js.map +0 -1
  964. package/out/fs/node.d.ts +0 -19
  965. package/out/fs/node.d.ts.map +0 -1
  966. package/out/fs/node.js +0 -32
  967. package/out/fs/node.js.map +0 -1
  968. package/out/identifiers.d.ts.map +0 -1
  969. package/out/identifiers.js.map +0 -1
  970. package/out/kysley/adapter.d.ts +0 -13
  971. package/out/kysley/adapter.d.ts.map +0 -1
  972. package/out/kysley/adapter.js +0 -25
  973. package/out/kysley/adapter.js.map +0 -1
  974. package/out/kysley/client.d.ts +0 -19
  975. package/out/kysley/client.d.ts.map +0 -1
  976. package/out/kysley/client.js +0 -25
  977. package/out/kysley/client.js.map +0 -1
  978. package/out/kysley/dialect-config.d.ts +0 -27
  979. package/out/kysley/dialect-config.d.ts.map +0 -1
  980. package/out/kysley/dialect-config.js +0 -7
  981. package/out/kysley/dialect-config.js.map +0 -1
  982. package/out/kysley/dialect.d.ts +0 -39
  983. package/out/kysley/dialect.d.ts.map +0 -1
  984. package/out/kysley/dialect.js +0 -49
  985. package/out/kysley/dialect.js.map +0 -1
  986. package/out/kysley/driver.d.ts +0 -22
  987. package/out/kysley/driver.d.ts.map +0 -1
  988. package/out/kysley/driver.js +0 -114
  989. package/out/kysley/driver.js.map +0 -1
  990. package/out/pipeline/reconcile-lookups.d.ts +0 -39
  991. package/out/pipeline/reconcile-lookups.d.ts.map +0 -1
  992. package/out/pipeline/reconcile-lookups.js +0 -88
  993. package/out/pipeline/reconcile-lookups.js.map +0 -1
  994. package/out/pipeline/reconcile.d.ts +0 -153
  995. package/out/pipeline/reconcile.d.ts.map +0 -1
  996. package/out/pipeline/reconcile.js +0 -388
  997. package/out/pipeline/reconcile.js.map +0 -1
  998. package/out/pipeline/span-logit-aggregation.d.ts +0 -58
  999. package/out/pipeline/span-logit-aggregation.d.ts.map +0 -1
  1000. package/out/pipeline/span-logit-aggregation.js +0 -117
  1001. package/out/pipeline/span-logit-aggregation.js.map +0 -1
  1002. package/out/resources/LocaleIndex.d.ts +0 -53
  1003. package/out/resources/LocaleIndex.d.ts.map +0 -1
  1004. package/out/resources/LocaleIndex.js +0 -89
  1005. package/out/resources/LocaleIndex.js.map +0 -1
  1006. package/out/resources/ResourceMapCache.d.ts +0 -40
  1007. package/out/resources/ResourceMapCache.d.ts.map +0 -1
  1008. package/out/resources/ResourceMapCache.js +0 -75
  1009. package/out/resources/ResourceMapCache.js.map +0 -1
  1010. package/out/resources/libaddressinput.d.ts +0 -103
  1011. package/out/resources/libaddressinput.d.ts.map +0 -1
  1012. package/out/resources/libaddressinput.js +0 -30
  1013. package/out/resources/libaddressinput.js.map +0 -1
  1014. package/out/resources/whosonfirst/DataSourceCache.d.ts +0 -14
  1015. package/out/resources/whosonfirst/DataSourceCache.d.ts.map +0 -1
  1016. package/out/resources/whosonfirst/DataSourceCache.js +0 -33
  1017. package/out/resources/whosonfirst/DataSourceCache.js.map +0 -1
  1018. package/out/resources/whosonfirst/loader.d.ts +0 -55
  1019. package/out/resources/whosonfirst/loader.d.ts.map +0 -1
  1020. package/out/resources/whosonfirst/loader.js +0 -114
  1021. package/out/resources/whosonfirst/loader.js.map +0 -1
  1022. package/out/resources/whosonfirst/sharded-repo.d.ts +0 -28
  1023. package/out/resources/whosonfirst/sharded-repo.d.ts.map +0 -1
  1024. package/out/resources/whosonfirst/sharded-repo.js +0 -58
  1025. package/out/resources/whosonfirst/sharded-repo.js.map +0 -1
  1026. package/out/utils/data-root.d.ts +0 -45
  1027. package/out/utils/data-root.d.ts.map +0 -1
  1028. package/out/utils/data-root.js +0 -72
  1029. package/out/utils/data-root.js.map +0 -1
  1030. package/out/utils/hash.d.ts.map +0 -1
  1031. package/out/utils/hash.js.map +0 -1
  1032. package/out/utils/jsonl.d.ts +0 -36
  1033. package/out/utils/jsonl.d.ts.map +0 -1
  1034. package/out/utils/jsonl.js +0 -61
  1035. package/out/utils/jsonl.js.map +0 -1
  1036. package/out/utils/python-json.d.ts.map +0 -1
  1037. package/out/utils/python-json.js.map +0 -1
  1038. package/out/utils/python-numeric.d.ts.map +0 -1
  1039. package/out/utils/python-numeric.js.map +0 -1
  1040. package/out/utils/python-random.d.ts.map +0 -1
  1041. package/out/utils/python-random.js.map +0 -1
  1042. package/out/utils/repo.d.ts.map +0 -1
  1043. package/out/utils/repo.js +0 -114
  1044. package/out/utils/repo.js.map +0 -1
  1045. package/out/utils/sealed-db.d.ts +0 -36
  1046. package/out/utils/sealed-db.d.ts.map +0 -1
  1047. package/out/utils/sealed-db.js +0 -109
  1048. package/out/utils/sealed-db.js.map +0 -1
  1049. package/out/utils/stats.d.ts +0 -25
  1050. package/out/utils/stats.d.ts.map +0 -1
  1051. package/out/utils/stats.js +0 -36
  1052. package/out/utils/stats.js.map +0 -1
  1053. package/out/vitest.config.d.ts +0 -17
  1054. package/out/vitest.config.d.ts.map +0 -1
  1055. package/out/vitest.config.js +0 -52
  1056. package/out/vitest.config.js.map +0 -1
  1057. package/pipeline/reconcile-lookups.ts +0 -111
  1058. package/pipeline/reconcile.ts +0 -583
  1059. package/pipeline/span-logit-aggregation.ts +0 -156
  1060. package/policy/index.ts +0 -10
  1061. package/resources/LocaleIndex.ts +0 -124
  1062. package/resources/ResourceMapCache.ts +0 -127
  1063. package/resources/git.ts +0 -54
  1064. package/resources/index.ts +0 -16
  1065. package/resources/libaddressinput.ts +0 -105
  1066. package/resources/libpostal.ts +0 -186
  1067. package/resources/whosonfirst/DataSourceCache.ts +0 -50
  1068. package/resources/whosonfirst/index.ts +0 -11
  1069. package/resources/whosonfirst/loader.ts +0 -158
  1070. package/resources/whosonfirst/placetypes/index.ts +0 -12
  1071. package/resources/whosonfirst/sharded-repo.ts +0 -69
  1072. package/tokenization/index.ts +0 -9
  1073. package/types/index.ts +0 -10
  1074. package/utils/data-root.ts +0 -79
  1075. package/utils/index.ts +0 -15
  1076. package/utils/jsonl.ts +0 -70
  1077. package/utils/repo.ts +0 -144
  1078. package/utils/sealed-db.ts +0 -130
  1079. package/utils/stats.ts +0 -38
  1080. /package/{api → lib/api}/headless.ts +0 -0
  1081. /package/{collections.ts → lib/collections.ts} +0 -0
  1082. /package/{logging → lib/logging}/utils.ts +0 -0
  1083. /package/{utils/python-random.ts → lib/random.ts} +0 -0
  1084. /package/{resources → lib/resources}/debugging.ts +0 -0
  1085. /package/{resources → lib/resources}/locale.ts +0 -0
  1086. /package/{tokenization → lib/tokenization}/normalizer.ts +0 -0
@@ -13,14 +13,11 @@
13
13
  * Run: `mailwoman placer eval latin-offmap --model <dir> [--abstain 0.5]`
14
14
  */
15
15
 
16
- import { readFileSync } from "node:fs"
17
- import * as path from "node:path"
16
+ import { basename, type PathBuilderLike, resolvePath, resolvePathBuilder } from "path-ts"
18
17
 
19
- import { parseJSONStrict } from "@mailwoman/core/objects"
20
- import { dataRootPath, repoRootPath, formatPercent } from "@mailwoman/core/utils"
21
- import { JSONSpliterator } from "spliterator"
22
-
23
- import { CoarsePlacer, type CoarsePlacerMeta, type CoarsePrediction } from "../coarse-placer.ts"
18
+ import { CoarsePlacer, isOffMapHandled } from "#coarse-placer/coarse-placer"
19
+ import { defaultDataDir, defaultModelDir, readLatinOffmapRows } from "#coarse-placer/tools/paths"
20
+ import { formatPercent } from "#utils"
24
21
 
25
22
  /**
26
23
  * Samples a bucket needs before its off-map rate is reported rather than folded into the tail.
@@ -41,15 +38,15 @@ export interface EvalLatinOffmapOptions {
41
38
  /**
42
39
  * Model artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model`.
43
40
  */
44
- model?: string
41
+ model?: PathBuilderLike
45
42
  /**
46
43
  * Abstention threshold. Default 0.5.
47
44
  */
48
45
  abstain?: number
49
46
  /**
50
- * Dataset dir (`test-latin-offmap.jsonl`). Default `<repo>/data/coarse-placer`.
47
+ * Dataset dir holding the Latin off-map test sets. Default `<repo>/data/coarse-placer`.
51
48
  */
52
- data?: string
49
+ data?: PathBuilderLike
53
50
  }
54
51
 
55
52
  /**
@@ -64,41 +61,14 @@ export interface EvalLatinOffmapResult {
64
61
  * Coarse-placer Latin off-map handling eval — see the module doc. Emits the report to stdout.
65
62
  */
66
63
  export async function evalLatinOffmap(options: EvalLatinOffmapOptions = {}): Promise<EvalLatinOffmapResult> {
67
- const modelDir = options.model || dataRootPath("coarse-placer", "model")
64
+ const modelDir = resolvePathBuilder(options.model || defaultModelDir())
68
65
  const abstain = options.abstain ?? 0.5
69
- const dataDir = options.data || repoRootPath("data", "coarse-placer")
70
-
71
- const meta = parseJSONStrict<CoarsePlacerMeta>(readFileSync(path.join(modelDir, "meta.json"), "utf8"))
72
- const buf = readFileSync(path.join(modelDir, "weights.bin"))
73
- const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength)
74
- let weights: Float32Array
75
-
76
- if (meta.quantization === "int8-per-row") {
77
- const int8 = new Int8Array(ab)
78
- const C = meta.classes.length
79
- const dim = meta.featureDim
80
- const scales = meta.scales!
81
- weights = new Float32Array(C * dim)
82
-
83
- for (let c = 0; c < C; c++) {
84
- const s = scales[c]!
85
- const base = c * dim
86
-
87
- for (let i = 0; i < dim; i++) {
88
- weights[base + i] = int8[base + i]! * s
89
- }
90
- }
91
- } else {
92
- weights = new Float32Array(ab)
93
- }
66
+ const dataDir = options.data || defaultDataDir()
94
67
 
95
- const placer = new CoarsePlacer({ ...meta, weights }, { abstainBelow: abstain })
68
+ const placer = await CoarsePlacer.fromArtifactDir(resolvePath(modelDir), { abstainBelow: abstain })
96
69
 
97
- const rows = await Array.fromAsync(
98
- JSONSpliterator.fromAsync<OffMapRow>(path.join(dataDir, "test-latin-offmap.jsonl"))
99
- )
70
+ const rows = await readLatinOffmapRows<OffMapRow>(dataDir)
100
71
 
101
- const handled = (p: CoarsePrediction): boolean => p.abstained || p.country === "OTHER"
102
72
  const by: Record<string, { n: number; ok: number }> = {} // key → {n, ok}
103
73
  const missTo: Record<string, number> = {} // wrong country → count
104
74
  const bump = (k: string): { n: number; ok: number } => (by[k] ??= { n: 0, ok: 0 })
@@ -108,7 +78,7 @@ export async function evalLatinOffmap(options: EvalLatinOffmapOptions = {}): Pro
108
78
 
109
79
  for (const r of rows) {
110
80
  const p = placer.predict(r.raw)
111
- const h = handled(p)
81
+ const h = isOffMapHandled(p)
112
82
 
113
83
  n++
114
84
 
@@ -133,7 +103,7 @@ export async function evalLatinOffmap(options: EvalLatinOffmapOptions = {}): Pro
133
103
  }
134
104
  }
135
105
 
136
- console.log(`Latin off-map handling — model ${path.basename(modelDir)} (abstain ${abstain}, n=${n})`)
106
+ console.log(`Latin off-map handling — model ${basename(modelDir)} (abstain ${abstain}, n=${n})`)
137
107
  console.log(` OVERALL handled (OTHER-or-abstain): ${ok}/${n} (${formatPercent(ok, n)}) ← want ≥90%`)
138
108
  console.log(` by group:`)
139
109
 
@@ -33,15 +33,15 @@
33
33
  /* oxlint-disable sister-software/prefer-region-over-marks -- these markers label steps inside one
34
34
  procedure, not sections of declarations. A region there folds nothing a reader wants folded. */
35
35
 
36
- import { readFileSync, writeFileSync } from "node:fs"
37
- import * as path from "node:path"
38
-
39
- import { parseJSONStrict } from "@mailwoman/core/objects"
40
- import { dataRootPath, repoRootPath } from "@mailwoman/core/utils"
36
+ import { basename, type PathBuilderLike, resolvePath, resolvePathBuilder } from "path-ts"
41
37
  import { JSONSpliterator } from "spliterator"
42
38
 
43
- import type { CoarsePlacerMeta } from "../coarse-placer.ts"
44
- import { COARSE_CLASSES, featurize } from "../featurize.ts"
39
+ import { type CoarsePlacerMeta, readWeightsBin } from "#coarse-placer/coarse-placer"
40
+ import { COARSE_CLASSES, featurize } from "#coarse-placer/featurize"
41
+ import { logsumexp, softmaxInto } from "#coarse-placer/math"
42
+ import { defaultDataDir, defaultModelDir, readLatinOffmapRows } from "#coarse-placer/tools/paths"
43
+ import { readLocalJSONFile } from "#fs/readers"
44
+ import { writeLocalFile } from "#fs/writers"
45
45
 
46
46
  /**
47
47
  * Steps in the threshold sweep; finer than the reporting precision so the knee is not missed.
@@ -81,11 +81,11 @@ export interface EvalOpenSetOptions {
81
81
  /**
82
82
  * Model artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model`.
83
83
  */
84
- model?: string
84
+ model?: PathBuilderLike
85
85
  /**
86
86
  * Dataset dir. Default `<repo>/data/coarse-placer`.
87
87
  */
88
- data?: string
88
+ data?: PathBuilderLike
89
89
  /**
90
90
  * Mahalanobis fit rows per class. Default 2000.
91
91
  */
@@ -109,34 +109,6 @@ export interface EvalOpenSetResult {
109
109
  markdown: string
110
110
  }
111
111
 
112
- function logsumexp(xs: number[]): number {
113
- let m = -Infinity
114
-
115
- for (const x of xs)
116
- if (x > m) {
117
- m = x
118
- }
119
-
120
- let s = 0
121
-
122
- for (const x of xs) {
123
- s += Math.exp(x - m)
124
- }
125
-
126
- return m + Math.log(s)
127
- }
128
-
129
- /**
130
- * Per-class softmax prob over ALL 12 classes.
131
- */
132
- function softmax(z: Float64Array): Float64Array {
133
- const m = Math.max(...z)
134
- const e = z.map((x) => Math.exp(x - m))
135
- const s = e.reduce((a, b) => a + b, 0)
136
-
137
- return e.map((x) => x / s)
138
- }
139
-
140
112
  /**
141
113
  * Invert a symmetric positive-definite matrix via Gauss-Jordan.
142
114
  */
@@ -190,20 +162,12 @@ export async function evalOpenSet(
190
162
  options: EvalOpenSetOptions = {},
191
163
  report?: (line: string) => void
192
164
  ): Promise<EvalOpenSetResult> {
193
- const modelDir = options.model || dataRootPath("coarse-placer", "model")
194
- const dataDir = options.data || repoRootPath("data", "coarse-placer")
165
+ const modelDir = resolvePathBuilder(options.model || defaultModelDir())
166
+ const dataDir = options.data || defaultDataDir()
195
167
  const fitPerClass = options.fitPerClass ?? 2000
196
168
 
197
- const meta = parseJSONStrict<CoarsePlacerMeta>(readFileSync(path.join(modelDir, "meta.json"), "utf8"))
198
- const weightBytes = readFileSync(path.join(modelDir, "weights.bin"))
199
-
200
- // Read through the Buffer's own window: `readFileSync` serves files under 4 KiB out of a shared 8 KiB pool, so
201
- // `.buffer` alone would start at the pool's origin and run its full length — the wrong floats, and 2048 of them.
202
- const W = new Float32Array(
203
- weightBytes.buffer,
204
- weightBytes.byteOffset,
205
- weightBytes.byteLength / Float32Array.BYTES_PER_ELEMENT
206
- )
169
+ const meta = await readLocalJSONFile<CoarsePlacerMeta>(resolvePath(modelDir, "meta.json"))
170
+ const W = new Float32Array(await readWeightsBin(resolvePath(modelDir)))
207
171
 
208
172
  const bias = Float32Array.from(meta.bias)
209
173
  const C = meta.classes.length
@@ -241,7 +205,7 @@ export async function evalOpenSet(
241
205
  const inVec = (z: Float64Array): number[] => IN.map((c) => z[c]!)
242
206
 
243
207
  function load(file: string): Promise<DataRow[]> {
244
- return Array.fromAsync(JSONSpliterator.fromAsync<DataRow>(path.join(dataDir, file)))
208
+ return Array.fromAsync(JSONSpliterator.fromAsync<DataRow>(resolvePath(dataDir, file)))
245
209
  }
246
210
 
247
211
  // Fit the Mahalanobis params on IN-MAP TRAIN logits (no test leak): per-class
@@ -367,7 +331,9 @@ export async function evalOpenSet(
367
331
  */
368
332
  function scoreRow(raw: string, trueCountry: string | undefined): ScoredRow {
369
333
  const z = logits(raw)
370
- const probs = softmax(z)
334
+ const probs = new Float64Array(C)
335
+
336
+ softmaxInto(z, probs)
371
337
  const zin = inVec(z)
372
338
 
373
339
  // argmax over in-map classes (the FIXED routing).
@@ -396,7 +362,7 @@ export async function evalOpenSet(
396
362
  }
397
363
 
398
364
  const inmapTest = (await load("test.jsonl")).filter((r) => r.country !== "OTHER") // the 11 countries only
399
- const heldout = (await load("test-latin-offmap.jsonl")).filter((r) => r.group === "heldout")
365
+ const heldout = (await readLatinOffmapRows<DataRow>(dataDir)).filter((r) => r.group === "heldout")
400
366
 
401
367
  const inmapScored = inmapTest.map((r) => scoreRow(r.raw, r.country))
402
368
  const heldoutScored = heldout.map((r) => scoreRow(r.raw, undefined))
@@ -433,10 +399,8 @@ export async function evalOpenSet(
433
399
  // For each score: KEEP (route in-map) iff score >= threshold; else REJECT (→ OTHER).
434
400
  // in-map accuracy = keep & correctRoute. heldout caught = rejected.
435
401
  function paretoFor(scoreKey: ScoreKey) {
436
- const inVals = inmapScored.map((o) => ({ v: o.s[scoreKey], ok: o.correctRoute }))
437
- const heldVals = heldoutScored.map((o) => o.s[scoreKey])
438
402
  // Candidate thresholds: quantiles of the union of scores.
439
- const all = [...inVals.map((x) => x.v), ...heldVals].toSorted((a, b) => a - b)
403
+ const all = [...inmapScored, ...heldoutScored].map((o) => o.s[scoreKey]).toSorted((a, b) => a - b)
440
404
  const ts: number[] = []
441
405
 
442
406
  for (let q = 0; q <= QUANTILE_SWEEP_STEPS; q++) {
@@ -444,26 +408,7 @@ export async function evalOpenSet(
444
408
  }
445
409
 
446
410
  const uniq = [...new Set(ts)]
447
- const nInVals = inVals.length
448
- const nHeld = heldVals.length
449
-
450
- const pts: ParetoPoint[] = uniq.map((t) => {
451
- let keepCorrect = 0
452
-
453
- for (const x of inVals)
454
- if (x.v >= t && x.ok) {
455
- keepCorrect++
456
- }
457
-
458
- let caught = 0
459
-
460
- for (const v of heldVals)
461
- if (v < t) {
462
- caught++
463
- }
464
-
465
- return { t, inMapAcc: (100 * keepCorrect) / nInVals, heldCaught: (100 * caught) / nHeld }
466
- })
411
+ const pts: ParetoPoint[] = uniq.map((t) => pointAt(scoreKey, t, inmapScored, heldoutScored))
467
412
 
468
413
  // Summaries.
469
414
  let balanced: { val: number; pt: ParetoPoint | null } = { val: -1, pt: null } // max of min(inMapAcc, heldCaught) on the FULL probe
@@ -514,7 +459,7 @@ export async function evalOpenSet(
514
459
  const lines: string[] = [
515
460
  `# Coarse-placer M2 Phase 1 — post-hoc open-set score comparison (#244)`,
516
461
  "",
517
- `_Frozen shipped model (\`${path.basename(modelDir)}\`), NO retrain. In-map test ${inmapTest.length} rows ` +
462
+ `_Frozen shipped model (\`${basename(modelDir)}\`), NO retrain. In-map test ${inmapTest.length} rows ` +
518
463
  `(11 countries); off-map HELDOUT ${heldout.length} rows (never-trained families: baltic/oceania/middle-east). ` +
519
464
  `Mahalanobis fit on ≤${fitPerClass}/class in-map train logits. The 11-way routing is fixed; each score only ` +
520
465
  `changes the reject decision._`,
@@ -586,7 +531,7 @@ export async function evalOpenSet(
586
531
  console.log(md)
587
532
 
588
533
  if (options.outMd) {
589
- writeFileSync(options.outMd, md)
534
+ await writeLocalFile(md, options.outMd)
590
535
  report?.(`\n[written] ${options.outMd}`)
591
536
  }
592
537
 
@@ -5,20 +5,18 @@
5
5
  *
6
6
  * Accuracy cost of the #244 coarse-placer int8 quantization (milestone 3). Runs the held-out test
7
7
  * split through the fp32 model and the int8 model (dequantized inline) and reports overall + per-
8
- * class accuracy for each, the delta, prediction-agreement rate, and confidence MAE. Gate: int8
8
+ * class accuracy for each, the delta, prediction-agreement rate, and confidence MAE. Check: int8
9
9
  * within ~1pp of fp32 (the milestone target).
10
10
  *
11
11
  * Run: `mailwoman placer eval quant-compare [--fp32 <dir>] [--int8 <dir>] [--abstain 0.5]`
12
12
  */
13
13
 
14
- import { readFileSync } from "node:fs"
15
- import * as path from "node:path"
16
-
17
- import { parseJSONStrict } from "@mailwoman/core/objects"
18
- import { dataRootPath, repoRootPath } from "@mailwoman/core/utils"
14
+ import { type PathBuilderLike, resolvePath, resolvePathBuilder } from "path-ts"
19
15
  import { JSONSpliterator } from "spliterator"
20
16
 
21
- import { CoarsePlacer, type CoarsePlacerMeta } from "../coarse-placer.ts"
17
+ import { CoarsePlacer, type CoarsePlacerMeta } from "#coarse-placer/coarse-placer"
18
+ import { defaultDataDir, defaultInt8Dir, defaultModelDir } from "#coarse-placer/tools/paths"
19
+ import { readLocalJSONFile } from "#fs/readers"
22
20
 
23
21
  interface TestRow {
24
22
  raw: string
@@ -32,11 +30,11 @@ export interface EvalQuantCompareOptions {
32
30
  /**
33
31
  * Fp32 artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model`.
34
32
  */
35
- fp32?: string
33
+ fp32?: PathBuilderLike
36
34
  /**
37
35
  * Int8 artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model-int8`.
38
36
  */
39
- int8?: string
37
+ int8?: PathBuilderLike
40
38
  /**
41
39
  * Abstention threshold. Default 0.5.
42
40
  */
@@ -44,7 +42,7 @@ export interface EvalQuantCompareOptions {
44
42
  /**
45
43
  * Dataset dir (`test.jsonl`). Default `<repo>/data/coarse-placer`.
46
44
  */
47
- data?: string
45
+ data?: PathBuilderLike
48
46
  }
49
47
 
50
48
  /**
@@ -61,7 +59,7 @@ export interface EvalQuantCompareResult {
61
59
  */
62
60
  accInt8: number
63
61
  /**
64
- * Whether int8 is within 1pp of fp32 (the gate).
62
+ * Whether int8 is within 1pp of fp32 (the threshold).
65
63
  */
66
64
  pass: boolean
67
65
  }
@@ -70,48 +68,17 @@ export interface EvalQuantCompareResult {
70
68
  * Coarse-placer int8-vs-fp32 comparison — see the module doc. Emits the report to stdout.
71
69
  */
72
70
  export async function evalQuantCompare(options: EvalQuantCompareOptions = {}): Promise<EvalQuantCompareResult> {
73
- const fp32Dir = options.fp32 || dataRootPath("coarse-placer", "model")
74
- const int8Dir = options.int8 || dataRootPath("coarse-placer", "model-int8")
71
+ const fp32Dir = resolvePathBuilder(options.fp32 || defaultModelDir())
72
+ const int8Dir = resolvePathBuilder(options.int8 || defaultInt8Dir())
75
73
  const abstainBelow = options.abstain ?? 0.5
76
- const dataDir = options.data || repoRootPath("data", "coarse-placer")
77
-
78
- function loadFp32(dir: string): CoarsePlacer {
79
- const meta = parseJSONStrict<CoarsePlacerMeta>(readFileSync(path.join(dir, "meta.json"), "utf8"))
80
- const buf = readFileSync(path.join(dir, "weights.bin"))
81
- const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength)
82
- const weights = new Float32Array(ab)
83
-
84
- return new CoarsePlacer({ ...meta, weights }, { abstainBelow })
85
- }
86
-
87
- function loadInt8(dir: string): CoarsePlacer {
88
- const meta = parseJSONStrict<CoarsePlacerMeta>(readFileSync(path.join(dir, "meta.json"), "utf8"))
89
- const buf = readFileSync(path.join(dir, "weights.bin"))
90
- const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength)
91
- const int8 = new Int8Array(ab)
92
- const C = meta.classes.length
93
- const dim = meta.featureDim
94
- const scales = meta.scales!
95
- const weights = new Float32Array(C * dim)
96
-
97
- for (let c = 0; c < C; c++) {
98
- const s = scales[c]!
99
- const base = c * dim
100
-
101
- for (let i = 0; i < dim; i++) {
102
- weights[base + i] = int8[base + i]! * s
103
- }
104
- }
105
-
106
- return new CoarsePlacer({ ...meta, weights }, { abstainBelow })
107
- }
74
+ const dataDir = options.data || defaultDataDir()
108
75
 
109
- const fp32 = loadFp32(fp32Dir)
110
- const int8 = loadInt8(int8Dir)
76
+ const fp32 = await CoarsePlacer.fromArtifactDir(resolvePath(fp32Dir), { abstainBelow })
77
+ const int8 = await CoarsePlacer.fromArtifactDir(resolvePath(int8Dir), { abstainBelow })
111
78
 
112
- const test = await Array.fromAsync(JSONSpliterator.fromAsync<TestRow>(path.join(dataDir, "test.jsonl")))
79
+ const test = await Array.fromAsync(JSONSpliterator.fromAsync<TestRow>(resolvePath(dataDir, "test.jsonl")))
113
80
 
114
- const classes = parseJSONStrict<CoarsePlacerMeta>(readFileSync(path.join(fp32Dir, "meta.json"), "utf8")).classes
81
+ const classes = (await readLocalJSONFile<CoarsePlacerMeta>(resolvePath(fp32Dir, "meta.json"))).classes
115
82
  let okF = 0
116
83
  let okI = 0
117
84
  let agree = 0
@@ -174,7 +141,7 @@ export async function evalQuantCompare(options: EvalQuantCompareOptions = {}): P
174
141
 
175
142
  const pass = Math.abs(accI - accF) <= 1
176
143
 
177
- console.log(` gate: ${pass ? "PASS (within 1pp)" : "FAIL (>1pp drop)"}`)
144
+ console.log(` check: ${pass ? "PASS (within 1pp)" : "FAIL (>1pp drop)"}`)
178
145
 
179
146
  return { n: N, accFp32: accF, accInt8: accI, pass }
180
147
  }
@@ -11,14 +11,14 @@
11
11
  * Run: `mailwoman placer eval in-distribution [--model <dir>] [--abstain 0.5]`
12
12
  */
13
13
 
14
- import { readFileSync } from "node:fs"
15
- import * as path from "node:path"
16
-
17
- import { parseJSONStrict } from "@mailwoman/core/objects"
18
- import { dataRootPath, repoRootPath } from "@mailwoman/core/utils"
14
+ import { type PathBuilderLike, resolvePath, resolvePathBuilder } from "path-ts"
19
15
  import { JSONSpliterator } from "spliterator"
20
16
 
21
- import { CoarsePlacer, type CoarsePlacerMeta, type CoarsePrediction } from "../coarse-placer.ts"
17
+ import { CoarsePlacer, type CoarsePlacerMeta, isOffMapHandled } from "#coarse-placer/coarse-placer"
18
+ import { defaultDataDir, defaultModelDir } from "#coarse-placer/tools/paths"
19
+ import { errorMessage } from "#errors/schema"
20
+ import { readLocalJSONFile } from "#fs/readers"
21
+ import { formatPercent, repoRootPath } from "#utils"
22
22
 
23
23
  /**
24
24
  * Confusions below this count are individually uninteresting and are summarised instead.
@@ -48,7 +48,7 @@ export interface EvalCoarsePlacerOptions {
48
48
  /**
49
49
  * Model artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model`.
50
50
  */
51
- model?: string
51
+ model?: PathBuilderLike
52
52
  /**
53
53
  * Abstention threshold. Default 0.5.
54
54
  */
@@ -56,7 +56,7 @@ export interface EvalCoarsePlacerOptions {
56
56
  /**
57
57
  * Dataset dir (`test.jsonl`). Default `<repo>/data/coarse-placer`.
58
58
  */
59
- data?: string
59
+ data?: PathBuilderLike
60
60
  }
61
61
 
62
62
  /**
@@ -78,22 +78,12 @@ export interface EvalCoarsePlacerResult {
78
78
  * Coarse-placer in-distribution eval — see the module doc. Emits the report to stdout.
79
79
  */
80
80
  export async function evalCoarsePlacer(options: EvalCoarsePlacerOptions = {}): Promise<EvalCoarsePlacerResult> {
81
- const modelDir = options.model || dataRootPath("coarse-placer", "model")
81
+ const modelDir = resolvePathBuilder(options.model || defaultModelDir())
82
82
  const abstain = options.abstain ?? 0.5
83
- const dataDir = options.data || repoRootPath("data", "coarse-placer")
84
-
85
- const meta = parseJSONStrict<CoarsePlacerMeta>(readFileSync(path.join(modelDir, "meta.json"), "utf8"))
86
- const weightBytes = readFileSync(path.join(modelDir, "weights.bin"))
87
-
88
- // Read through the Buffer's own window: `readFileSync` serves files under 4 KiB out of a shared 8 KiB pool, so
89
- // `.buffer` alone would start at the pool's origin and run its full length — the wrong floats, and 2048 of them.
90
- const weights = new Float32Array(
91
- weightBytes.buffer,
92
- weightBytes.byteOffset,
93
- weightBytes.byteLength / Float32Array.BYTES_PER_ELEMENT
94
- )
83
+ const dataDir = options.data || defaultDataDir()
95
84
 
96
- const placer = new CoarsePlacer({ ...meta, weights }, { abstainBelow: abstain })
85
+ const meta = await readLocalJSONFile<CoarsePlacerMeta>(resolvePath(modelDir, "meta.json"))
86
+ const placer = await CoarsePlacer.fromArtifactDir(resolvePath(modelDir), { abstainBelow: abstain })
97
87
 
98
88
  // --- In-distribution test: accuracy + per-class + ECE ---
99
89
  let testN = 0
@@ -103,7 +93,7 @@ export async function evalCoarsePlacer(options: EvalCoarsePlacerOptions = {}): P
103
93
  const buckets = Array.from({ length: 10 }, () => ({ n: 0, ok: 0 }))
104
94
 
105
95
  // ECE deciles. The split streams: every figure below is an accumulator, so the rows never all need to be resident.
106
- for await (const r of JSONSpliterator.fromAsync<TestRow>(path.join(dataDir, "test.jsonl"))) {
96
+ for await (const r of JSONSpliterator.fromAsync<TestRow>(resolvePath(dataDir, "test.jsonl"))) {
107
97
  testN++
108
98
 
109
99
  const p = placer.predict(r.raw)
@@ -175,15 +165,12 @@ export async function evalCoarsePlacer(options: EvalCoarsePlacerOptions = {}): P
175
165
 
176
166
  try {
177
167
  const TRAINED_SCRIPTS = new Set(["latin", "cjk"]) // the only scripts among the 11 trained countries
178
- // With the OTHER class, an off-map input is HANDLED if it routes to OTHER or abstains — either way
179
- // it's not a confident mis-placement onto a wrong country.
180
- const handled = (p: CoarsePrediction): boolean => p.abstained || p.country === "OTHER"
181
168
 
182
- let msN = 0,
183
- offN = 0,
184
- offOk = 0,
185
- missN = 0,
186
- missOk = 0
169
+ let msN = 0
170
+ let offN = 0
171
+ let offOk = 0
172
+ let missN = 0
173
+ let missOk = 0
187
174
 
188
175
  const offMiss: string[] = []
189
176
 
@@ -196,7 +183,7 @@ export async function evalCoarsePlacer(options: EvalCoarsePlacerOptions = {}): P
196
183
  if (offMap) {
197
184
  offN++
198
185
 
199
- if (handled(p)) {
186
+ if (isOffMapHandled(p)) {
200
187
  offOk++
201
188
  } else if (offMiss.length < MAX_LISTED_MISSES) {
202
189
  offMiss.push(
@@ -206,7 +193,7 @@ export async function evalCoarsePlacer(options: EvalCoarsePlacerOptions = {}): P
206
193
  } else {
207
194
  missN++
208
195
 
209
- if (handled(p)) {
196
+ if (isOffMapHandled(p)) {
210
197
  missOk++
211
198
  } // a latin/cjk in-map input mis-routed to OTHER = a false abstention
212
199
  }
@@ -214,10 +201,10 @@ export async function evalCoarsePlacer(options: EvalCoarsePlacerOptions = {}): P
214
201
 
215
202
  console.log(`\nmulti-script off-map handling (n=${msN}):`)
216
203
  console.log(
217
- ` OFF-map scripts (Cyrillic/Arabic/Thai/…) routed to OTHER-or-abstain: ${offOk}/${offN} (${((100 * offOk) / Math.max(1, offN)).toFixed(0)}%) ← want HIGH`
204
+ ` OFF-map scripts (Cyrillic/Arabic/Thai/…) routed to OTHER-or-abstain: ${offOk}/${offN} (${formatPercent(offOk, offN, 0, { zero: "clamp" })}) ← want HIGH`
218
205
  )
219
206
  console.log(
220
- ` ON-map scripts (latin/cjk) wrongly OTHER-or-abstain: ${missOk}/${missN} (${((100 * missOk) / Math.max(1, missN)).toFixed(0)}%) ← want LOW`
207
+ ` ON-map scripts (latin/cjk) wrongly OTHER-or-abstain: ${missOk}/${missN} (${formatPercent(missOk, missN, 0, { zero: "clamp" })}) ← want LOW`
221
208
  )
222
209
 
223
210
  if (offMiss.length) {
@@ -225,7 +212,7 @@ export async function evalCoarsePlacer(options: EvalCoarsePlacerOptions = {}): P
225
212
  console.log(offMiss.join("\n"))
226
213
  }
227
214
  } catch (error) {
228
- console.log(`\n(multi-script set not found at ${msPath}: ${(error as Error).message})`)
215
+ console.log(`\n(multi-script set not found at ${msPath}: ${errorMessage(error)})`)
229
216
  }
230
217
 
231
218
  return { n: testN, accuracy: (100 * correct) / testN, ece }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Coarse-placer (#244) operator tools — the `run()`-style modules behind `mailwoman placer …`
7
+ * commands. No argv, no `process.exit`: commands own
8
+ * parsing, rendering, and exit codes. Heavy deps that are core devDependencies
9
+ * (`@duckdb/node-api`, `@mailwoman/codex`) are lazy-imported inside their entry fns. `country-sets.ts`,
10
+ * `paths.ts`, and `outlier-rows.ts` are deliberately NOT re-exported — they are internal to the tools;
11
+ * `fnv-hash.ts` lives at the coarse-placer root because `featurize` hashes through it.
12
+ */
13
+
14
+ export * from "#coarse-placer/tools/build-dataset"
15
+ export * from "#coarse-placer/tools/build-outlier-exposure"
16
+ export * from "#coarse-placer/tools/build-outlier-latin"
17
+ export * from "#coarse-placer/tools/build-outlier-oa"
18
+ export * from "#coarse-placer/tools/eval"
19
+ export * from "#coarse-placer/tools/eval-latin-offmap"
20
+ export * from "#coarse-placer/tools/eval-openset"
21
+ export * from "#coarse-placer/tools/eval-quant-compare"
22
+ export * from "#coarse-placer/tools/probe-frontier"
23
+ export * from "#coarse-placer/tools/quantize"
24
+ export * from "#coarse-placer/tools/train"
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Shared plumbing for the Latin off-map outlier builders (`build-outlier-latin.ts` — Overture,
7
+ * `build-outlier-oa.ts` — OpenAddresses): the address-string assembler and its shape variants,
8
+ * the dedup/cap loop, and the OTHER-row JSONL encoding. The builders differ only in where the
9
+ * locality comes from and in OA's PO-box guard, so both are parameters here.
10
+ */
11
+
12
+ import { hashFNV1a } from "#coarse-placer/fnv-hash"
13
+
14
+ /**
15
+ * Shortest raw string worth keeping as an outlier example; below it there is nothing to learn from.
16
+ */
17
+ const MIN_OUTLIER_LENGTH = 6
18
+
19
+ /**
20
+ * Address parts are joined positionally; an absent field arrives as the empty string and must not become a stray
21
+ * separator.
22
+ */
23
+ const nonEmpty = (part: string): boolean => part.length > 0
24
+
25
+ /**
26
+ * How {@link assembleOutlierRow} varies per source.
27
+ */
28
+ export interface AssembleOutlierOptions {
29
+ /**
30
+ * Derive the locality string from the source row (Overture: `postal_city` falling back to `address_levels`; OA:
31
+ * `city`).
32
+ */
33
+ locality: (row: Record<string, unknown>) => string
34
+ /**
35
+ * Drop raw-coord-only / PO-box-ish noise (the OA failure mode): without a street, the locality must carry a real word
36
+ * character.
37
+ */
38
+ requireLetterLocality?: boolean
39
+ }
40
+
41
+ /**
42
+ * Assemble a plausible address string from a source row. Deterministic shape variant by hash.
43
+ */
44
+ export function assembleOutlierRow(row: Record<string, unknown>, options: AssembleOutlierOptions): string | null {
45
+ const num = (row.number ?? "").toString().trim()
46
+ const street = (row.street ?? "").toString().trim()
47
+ const pc = (row.postcode ?? "").toString().trim()
48
+ const locality = options.locality(row)
49
+
50
+ // Nothing distinctive to learn from.
51
+ if (!street && !locality) return null
52
+
53
+ if (options.requireLetterLocality && !street && !/[a-z]/i.test(locality)) return null
54
+
55
+ const head = [num, street].filter(nonEmpty).join(" ")
56
+ const h = hashFNV1a(`${num}|${street}|${pc}|${locality}`)
57
+
58
+ switch (h % 3) {
59
+ case 0:
60
+ return [head, [pc, locality].filter(nonEmpty).join(" ")].filter(nonEmpty).join(", ")
61
+ case 1:
62
+ return [head, locality, pc].filter(nonEmpty).join(", ").trim()
63
+ default:
64
+ return [head, [locality, pc].filter(nonEmpty).join(" ")].filter(nonEmpty).join(", ")
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Dedup assembled rows, dropping nulls and strings under {@link MIN_OUTLIER_LENGTH}, keeping at most `cap`.
70
+ */
71
+ export function collectOutlierRows(candidates: Iterable<string | null>, cap = Infinity): string[] {
72
+ const seen = new Set<string>()
73
+ const out: string[] = []
74
+
75
+ for (const raw of candidates) {
76
+ if (!raw || raw.length < MIN_OUTLIER_LENGTH || seen.has(raw)) continue
77
+ seen.add(raw)
78
+ out.push(raw)
79
+
80
+ if (out.length >= cap) break
81
+ }
82
+
83
+ return out
84
+ }
85
+
86
+ /**
87
+ * Encode rows as `{raw, country: "OTHER"}` JSONL (trailing newline included).
88
+ */
89
+ export function otherRowsJSONL(rows: string[]): string {
90
+ return rows.map((raw) => JSON.stringify({ raw, country: "OTHER" })).join("\n") + "\n"
91
+ }