@mailwoman/core 8.1.0 → 8.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 (407) hide show
  1. package/api/APIClient.ts +3 -4
  2. package/api/responses.ts +6 -3
  3. package/coarse-placer/coarse-placer.ts +26 -11
  4. package/coarse-placer/featurize.ts +25 -16
  5. package/coarse-placer/tools/build-dataset.ts +42 -18
  6. package/coarse-placer/tools/build-outlier-exposure.ts +51 -18
  7. package/coarse-placer/tools/build-outlier-latin.ts +48 -22
  8. package/coarse-placer/tools/build-outlier-oa.ts +52 -20
  9. package/coarse-placer/tools/eval-latin-offmap.ts +37 -12
  10. package/coarse-placer/tools/eval-openset.ts +104 -37
  11. package/coarse-placer/tools/eval-quant-compare.ts +41 -11
  12. package/coarse-placer/tools/eval.ts +51 -13
  13. package/coarse-placer/tools/fnv-hash.ts +5 -3
  14. package/coarse-placer/tools/probe-frontier.ts +63 -32
  15. package/coarse-placer/tools/quantize.ts +30 -8
  16. package/coarse-placer/tools/train.ts +63 -17
  17. package/collections.ts +2 -2
  18. package/decoder/build-tree.ts +16 -3
  19. package/decoder/calibration.ts +23 -7
  20. package/decoder/containment.ts +3 -1
  21. package/decoder/proposals-to-tree.ts +2 -0
  22. package/decoder/resolve-proposal-overlaps.ts +5 -1
  23. package/decoder/serialize-json.ts +8 -2
  24. package/decoder/serialize-tuples.ts +7 -2
  25. package/decoder/serialize-xml.ts +29 -11
  26. package/decoder/types.ts +34 -12
  27. package/decoder/unknown-spans.ts +14 -5
  28. package/decoder/validate-tree.ts +6 -1
  29. package/env/index.ts +1 -1
  30. package/env/load.ts +1 -1
  31. package/env/paths.ts +1 -1
  32. package/env/schema.ts +12 -4
  33. package/errors/schema.ts +1 -1
  34. package/fs/node.ts +9 -10
  35. package/identifiers.ts +3 -3
  36. package/kysley/adapter.ts +1 -1
  37. package/layers/manifest.ts +22 -8
  38. package/layers/schema.ts +59 -19
  39. package/locale/locale.ts +6 -2
  40. package/locale/profiles/en-us.ts +3 -0
  41. package/locale/profiles/fr-fr.ts +3 -0
  42. package/locale/profiles/ja-jp.ts +6 -0
  43. package/locale/registry.ts +3 -1
  44. package/logging/shared.ts +1 -0
  45. package/logging/utils.ts +1 -1
  46. package/objects.ts +7 -2
  47. package/out/api/APIClient.d.ts +1 -1
  48. package/out/api/APIClient.d.ts.map +1 -1
  49. package/out/api/APIClient.js +3 -2
  50. package/out/api/APIClient.js.map +1 -1
  51. package/out/api/responses.d.ts.map +1 -1
  52. package/out/api/responses.js +3 -3
  53. package/out/api/responses.js.map +1 -1
  54. package/out/coarse-placer/coarse-placer.d.ts +19 -9
  55. package/out/coarse-placer/coarse-placer.d.ts.map +1 -1
  56. package/out/coarse-placer/coarse-placer.js +6 -4
  57. package/out/coarse-placer/coarse-placer.js.map +1 -1
  58. package/out/coarse-placer/featurize.d.ts.map +1 -1
  59. package/out/coarse-placer/featurize.js +20 -16
  60. package/out/coarse-placer/featurize.js.map +1 -1
  61. package/out/coarse-placer/tools/build-dataset.d.ts +15 -5
  62. package/out/coarse-placer/tools/build-dataset.d.ts.map +1 -1
  63. package/out/coarse-placer/tools/build-dataset.js +19 -14
  64. package/out/coarse-placer/tools/build-dataset.js.map +1 -1
  65. package/out/coarse-placer/tools/build-outlier-exposure.d.ts +21 -7
  66. package/out/coarse-placer/tools/build-outlier-exposure.d.ts.map +1 -1
  67. package/out/coarse-placer/tools/build-outlier-exposure.js +24 -12
  68. package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
  69. package/out/coarse-placer/tools/build-outlier-latin.d.ts +18 -6
  70. package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -1
  71. package/out/coarse-placer/tools/build-outlier-latin.js +27 -17
  72. package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
  73. package/out/coarse-placer/tools/build-outlier-oa.d.ts +18 -6
  74. package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -1
  75. package/out/coarse-placer/tools/build-outlier-oa.js +29 -15
  76. package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
  77. package/out/coarse-placer/tools/eval-latin-offmap.d.ts +18 -6
  78. package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
  79. package/out/coarse-placer/tools/eval-latin-offmap.js +13 -7
  80. package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
  81. package/out/coarse-placer/tools/eval-openset.d.ts +24 -8
  82. package/out/coarse-placer/tools/eval-openset.d.ts.map +1 -1
  83. package/out/coarse-placer/tools/eval-openset.js +52 -31
  84. package/out/coarse-placer/tools/eval-openset.js.map +1 -1
  85. package/out/coarse-placer/tools/eval-quant-compare.d.ts +30 -10
  86. package/out/coarse-placer/tools/eval-quant-compare.d.ts.map +1 -1
  87. package/out/coarse-placer/tools/eval-quant-compare.js +4 -2
  88. package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
  89. package/out/coarse-placer/tools/eval.d.ts +24 -8
  90. package/out/coarse-placer/tools/eval.d.ts.map +1 -1
  91. package/out/coarse-placer/tools/eval.js +16 -6
  92. package/out/coarse-placer/tools/eval.js.map +1 -1
  93. package/out/coarse-placer/tools/fnv-hash.d.ts +3 -1
  94. package/out/coarse-placer/tools/fnv-hash.d.ts.map +1 -1
  95. package/out/coarse-placer/tools/fnv-hash.js +5 -3
  96. package/out/coarse-placer/tools/fnv-hash.js.map +1 -1
  97. package/out/coarse-placer/tools/probe-frontier.d.ts +18 -6
  98. package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
  99. package/out/coarse-placer/tools/probe-frontier.js +39 -23
  100. package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
  101. package/out/coarse-placer/tools/quantize.d.ts +15 -5
  102. package/out/coarse-placer/tools/quantize.d.ts.map +1 -1
  103. package/out/coarse-placer/tools/quantize.js +11 -4
  104. package/out/coarse-placer/tools/quantize.js.map +1 -1
  105. package/out/coarse-placer/tools/train.d.ts +24 -8
  106. package/out/coarse-placer/tools/train.d.ts.map +1 -1
  107. package/out/coarse-placer/tools/train.js +24 -10
  108. package/out/coarse-placer/tools/train.js.map +1 -1
  109. package/out/collections.js +2 -2
  110. package/out/collections.js.map +1 -1
  111. package/out/decoder/build-tree.d.ts.map +1 -1
  112. package/out/decoder/build-tree.js +9 -3
  113. package/out/decoder/build-tree.js.map +1 -1
  114. package/out/decoder/calibration.d.ts +17 -3
  115. package/out/decoder/calibration.d.ts.map +1 -1
  116. package/out/decoder/calibration.js +12 -4
  117. package/out/decoder/calibration.js.map +1 -1
  118. package/out/decoder/containment.d.ts +3 -1
  119. package/out/decoder/containment.d.ts.map +1 -1
  120. package/out/decoder/containment.js +3 -1
  121. package/out/decoder/containment.js.map +1 -1
  122. package/out/decoder/proposals-to-tree.d.ts.map +1 -1
  123. package/out/decoder/proposals-to-tree.js.map +1 -1
  124. package/out/decoder/resolve-proposal-overlaps.d.ts.map +1 -1
  125. package/out/decoder/resolve-proposal-overlaps.js +5 -1
  126. package/out/decoder/resolve-proposal-overlaps.js.map +1 -1
  127. package/out/decoder/serialize-json.d.ts +6 -2
  128. package/out/decoder/serialize-json.d.ts.map +1 -1
  129. package/out/decoder/serialize-json.js.map +1 -1
  130. package/out/decoder/serialize-tuples.d.ts +6 -2
  131. package/out/decoder/serialize-tuples.d.ts.map +1 -1
  132. package/out/decoder/serialize-tuples.js.map +1 -1
  133. package/out/decoder/serialize-xml.d.ts +21 -7
  134. package/out/decoder/serialize-xml.d.ts.map +1 -1
  135. package/out/decoder/serialize-xml.js +7 -5
  136. package/out/decoder/serialize-xml.js.map +1 -1
  137. package/out/decoder/types.d.ts +34 -12
  138. package/out/decoder/types.d.ts.map +1 -1
  139. package/out/decoder/types.js +1 -1
  140. package/out/decoder/types.js.map +1 -1
  141. package/out/decoder/unknown-spans.d.ts +9 -3
  142. package/out/decoder/unknown-spans.d.ts.map +1 -1
  143. package/out/decoder/unknown-spans.js +4 -2
  144. package/out/decoder/unknown-spans.js.map +1 -1
  145. package/out/decoder/validate-tree.d.ts +3 -1
  146. package/out/decoder/validate-tree.d.ts.map +1 -1
  147. package/out/decoder/validate-tree.js +3 -1
  148. package/out/decoder/validate-tree.js.map +1 -1
  149. package/out/env/index.js +0 -1
  150. package/out/env/index.js.map +1 -1
  151. package/out/env/load.js +1 -1
  152. package/out/env/load.js.map +1 -1
  153. package/out/env/paths.js +1 -1
  154. package/out/env/paths.js.map +1 -1
  155. package/out/env/schema.d.ts.map +1 -1
  156. package/out/env/schema.js +12 -4
  157. package/out/env/schema.js.map +1 -1
  158. package/out/errors/schema.js +1 -1
  159. package/out/errors/schema.js.map +1 -1
  160. package/out/fs/node.d.ts +1 -2
  161. package/out/fs/node.d.ts.map +1 -1
  162. package/out/fs/node.js +7 -8
  163. package/out/fs/node.js.map +1 -1
  164. package/out/identifiers.js +3 -3
  165. package/out/identifiers.js.map +1 -1
  166. package/out/kysley/adapter.d.ts +1 -1
  167. package/out/kysley/adapter.d.ts.map +1 -1
  168. package/out/kysley/adapter.js +1 -1
  169. package/out/kysley/adapter.js.map +1 -1
  170. package/out/layers/manifest.d.ts +18 -6
  171. package/out/layers/manifest.d.ts.map +1 -1
  172. package/out/layers/manifest.js +8 -4
  173. package/out/layers/manifest.js.map +1 -1
  174. package/out/layers/schema.d.ts +57 -19
  175. package/out/layers/schema.d.ts.map +1 -1
  176. package/out/layers/schema.js +24 -8
  177. package/out/layers/schema.js.map +1 -1
  178. package/out/locale/locale.d.ts +6 -2
  179. package/out/locale/locale.d.ts.map +1 -1
  180. package/out/locale/profiles/en-us.d.ts +3 -0
  181. package/out/locale/profiles/en-us.d.ts.map +1 -1
  182. package/out/locale/profiles/en-us.js +3 -0
  183. package/out/locale/profiles/en-us.js.map +1 -1
  184. package/out/locale/profiles/fr-fr.d.ts +3 -0
  185. package/out/locale/profiles/fr-fr.d.ts.map +1 -1
  186. package/out/locale/profiles/fr-fr.js +3 -0
  187. package/out/locale/profiles/fr-fr.js.map +1 -1
  188. package/out/locale/profiles/ja-jp.d.ts +3 -0
  189. package/out/locale/profiles/ja-jp.d.ts.map +1 -1
  190. package/out/locale/profiles/ja-jp.js +6 -0
  191. package/out/locale/profiles/ja-jp.js.map +1 -1
  192. package/out/locale/registry.d.ts +3 -1
  193. package/out/locale/registry.d.ts.map +1 -1
  194. package/out/locale/registry.js +3 -1
  195. package/out/locale/registry.js.map +1 -1
  196. package/out/logging/shared.d.ts.map +1 -1
  197. package/out/logging/shared.js +1 -0
  198. package/out/logging/shared.js.map +1 -1
  199. package/out/logging/utils.js +1 -1
  200. package/out/logging/utils.js.map +1 -1
  201. package/out/objects.d.ts.map +1 -1
  202. package/out/objects.js +2 -2
  203. package/out/objects.js.map +1 -1
  204. package/out/pipeline/index.d.ts +2 -2
  205. package/out/pipeline/index.d.ts.map +1 -1
  206. package/out/pipeline/index.js +1 -1
  207. package/out/pipeline/index.js.map +1 -1
  208. package/out/pipeline/reconcile-lookups.d.ts.map +1 -1
  209. package/out/pipeline/reconcile-lookups.js.map +1 -1
  210. package/out/pipeline/reconcile.d.ts +30 -10
  211. package/out/pipeline/reconcile.d.ts.map +1 -1
  212. package/out/pipeline/reconcile.js +12 -9
  213. package/out/pipeline/reconcile.js.map +1 -1
  214. package/out/pipeline/runtime-pipeline.d.ts +18 -0
  215. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  216. package/out/pipeline/runtime-pipeline.js +73 -46
  217. package/out/pipeline/runtime-pipeline.js.map +1 -1
  218. package/out/pipeline/span-logit-aggregation.d.ts.map +1 -1
  219. package/out/pipeline/span-logit-aggregation.js +5 -2
  220. package/out/pipeline/span-logit-aggregation.js.map +1 -1
  221. package/out/pipeline/span-proposer.d.ts +19 -9
  222. package/out/pipeline/span-proposer.d.ts.map +1 -1
  223. package/out/pipeline/span-proposer.js +42 -22
  224. package/out/pipeline/span-proposer.js.map +1 -1
  225. package/out/pipeline/types.d.ts +77 -19
  226. package/out/pipeline/types.d.ts.map +1 -1
  227. package/out/pipeline/types.js +16 -0
  228. package/out/pipeline/types.js.map +1 -1
  229. package/out/policy/proposal-collection.d.ts +1 -1
  230. package/out/policy/proposal-collection.d.ts.map +1 -1
  231. package/out/policy/proposal-collection.js +2 -3
  232. package/out/policy/proposal-collection.js.map +1 -1
  233. package/out/policy/registry.d.ts +9 -3
  234. package/out/policy/registry.d.ts.map +1 -1
  235. package/out/policy/registry.js +9 -3
  236. package/out/policy/registry.js.map +1 -1
  237. package/out/resolver/index.d.ts.map +1 -1
  238. package/out/resolver/types.d.ts +94 -30
  239. package/out/resolver/types.d.ts.map +1 -1
  240. package/out/resolver/types.js +7 -1
  241. package/out/resolver/types.js.map +1 -1
  242. package/out/resources/LocaleIndex.d.ts +1 -1
  243. package/out/resources/LocaleIndex.d.ts.map +1 -1
  244. package/out/resources/LocaleIndex.js +1 -2
  245. package/out/resources/LocaleIndex.js.map +1 -1
  246. package/out/resources/ResourceMapCache.d.ts.map +1 -1
  247. package/out/resources/ResourceMapCache.js +1 -1
  248. package/out/resources/ResourceMapCache.js.map +1 -1
  249. package/out/resources/collections.d.ts.map +1 -1
  250. package/out/resources/collections.js +3 -1
  251. package/out/resources/collections.js.map +1 -1
  252. package/out/resources/languages/index.d.ts +1 -1
  253. package/out/resources/languages/index.d.ts.map +1 -1
  254. package/out/resources/languages/index.js +1 -1
  255. package/out/resources/languages/index.js.map +1 -1
  256. package/out/resources/libpostal.d.ts +1 -1
  257. package/out/resources/libpostal.d.ts.map +1 -1
  258. package/out/resources/libpostal.js +7 -5
  259. package/out/resources/libpostal.js.map +1 -1
  260. package/out/resources/set.js +6 -6
  261. package/out/resources/set.js.map +1 -1
  262. package/out/resources/whosonfirst/DataSourceCache.d.ts +1 -4
  263. package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
  264. package/out/resources/whosonfirst/DataSourceCache.js +1 -20
  265. package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
  266. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +1 -1
  267. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
  268. package/out/resources/whosonfirst/PlacetypeDataSource.js +2 -2
  269. package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
  270. package/out/resources/whosonfirst/backoff.d.ts +19 -0
  271. package/out/resources/whosonfirst/backoff.d.ts.map +1 -0
  272. package/out/resources/whosonfirst/backoff.js +35 -0
  273. package/out/resources/whosonfirst/backoff.js.map +1 -0
  274. package/out/resources/whosonfirst/loader.d.ts +1 -1
  275. package/out/resources/whosonfirst/loader.d.ts.map +1 -1
  276. package/out/resources/whosonfirst/loader.js +0 -1
  277. package/out/resources/whosonfirst/loader.js.map +1 -1
  278. package/out/resources/whosonfirst/placetypes/Placetype.d.ts +4 -1
  279. package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
  280. package/out/resources/whosonfirst/placetypes/Placetype.js +8 -6
  281. package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
  282. package/out/resources/whosonfirst/placetypes/admin.d.ts +6 -4
  283. package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
  284. package/out/resources/whosonfirst/placetypes/admin.js +8 -4
  285. package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
  286. package/out/resources/whosonfirst/placetypes/definition.d.ts +5 -6
  287. package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
  288. package/out/resources/whosonfirst/placetypes/definition.js +3 -0
  289. package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
  290. package/out/resources/whosonfirst/placetypes/graph.d.ts +4 -2
  291. package/out/resources/whosonfirst/placetypes/graph.d.ts.map +1 -1
  292. package/out/resources/whosonfirst/placetypes/graph.js +0 -0
  293. package/out/resources/whosonfirst/placetypes/graph.js.map +1 -1
  294. package/out/resources/whosonfirst/placetypes/mermaid.d.ts +4 -2
  295. package/out/resources/whosonfirst/placetypes/mermaid.d.ts.map +1 -1
  296. package/out/resources/whosonfirst/placetypes/mermaid.js +0 -1
  297. package/out/resources/whosonfirst/placetypes/mermaid.js.map +1 -1
  298. package/out/resources/whosonfirst/placetypes/tree.d.ts +1 -1
  299. package/out/resources/whosonfirst/placetypes/tree.d.ts.map +1 -1
  300. package/out/resources/whosonfirst/placetypes/tree.js +0 -1
  301. package/out/resources/whosonfirst/placetypes/tree.js.map +1 -1
  302. package/out/routing/index.d.ts.map +1 -1
  303. package/out/routing/index.js +1 -1
  304. package/out/routing/index.js.map +1 -1
  305. package/out/scripting/utils/index.d.ts +3 -1
  306. package/out/scripting/utils/index.d.ts.map +1 -1
  307. package/out/scripting/utils/index.js +3 -1
  308. package/out/scripting/utils/index.js.map +1 -1
  309. package/out/tokenization/Span.js.map +1 -1
  310. package/out/tokenization/normalizer.js +11 -11
  311. package/out/tokenization/normalizer.js.map +1 -1
  312. package/out/tools/download-libpostal-resources.d.ts.map +1 -1
  313. package/out/tools/download-libpostal-resources.js.map +1 -1
  314. package/out/tools/download-ssl-address.d.ts +9 -3
  315. package/out/tools/download-ssl-address.d.ts.map +1 -1
  316. package/out/tools/download-ssl-address.js +8 -4
  317. package/out/tools/download-ssl-address.js.map +1 -1
  318. package/out/tools/generate-language-types.d.ts +12 -4
  319. package/out/tools/generate-language-types.d.ts.map +1 -1
  320. package/out/tools/generate-language-types.js +3 -1
  321. package/out/tools/generate-language-types.js.map +1 -1
  322. package/out/types/Classification.d.ts.map +1 -1
  323. package/out/types/Classification.js.map +1 -1
  324. package/out/types/classifier.d.ts +27 -9
  325. package/out/types/classifier.d.ts.map +1 -1
  326. package/out/types/component.d.ts +8 -4
  327. package/out/types/component.d.ts.map +1 -1
  328. package/out/types/component.js +3 -3
  329. package/out/types/component.js.map +1 -1
  330. package/out/utils/data-root.d.ts +3 -1
  331. package/out/utils/data-root.d.ts.map +1 -1
  332. package/out/utils/data-root.js +3 -1
  333. package/out/utils/data-root.js.map +1 -1
  334. package/out/utils/hash.d.ts +6 -2
  335. package/out/utils/hash.d.ts.map +1 -1
  336. package/out/utils/hash.js +6 -2
  337. package/out/utils/hash.js.map +1 -1
  338. package/out/utils/jsonl.d.ts +9 -3
  339. package/out/utils/jsonl.d.ts.map +1 -1
  340. package/out/utils/jsonl.js +9 -3
  341. package/out/utils/jsonl.js.map +1 -1
  342. package/out/utils/python-json.d.ts +6 -2
  343. package/out/utils/python-json.d.ts.map +1 -1
  344. package/out/utils/python-json.js +9 -3
  345. package/out/utils/python-json.js.map +1 -1
  346. package/out/utils/python-random.d.ts +15 -5
  347. package/out/utils/python-random.d.ts.map +1 -1
  348. package/out/utils/python-random.js +17 -7
  349. package/out/utils/python-random.js.map +1 -1
  350. package/out/utils/repo.d.ts +4 -0
  351. package/out/utils/repo.d.ts.map +1 -1
  352. package/out/utils/repo.js +4 -0
  353. package/out/utils/repo.js.map +1 -1
  354. package/out/utils/sealed-db.d.ts +6 -2
  355. package/out/utils/sealed-db.d.ts.map +1 -1
  356. package/out/utils/sealed-db.js +6 -2
  357. package/out/utils/sealed-db.js.map +1 -1
  358. package/out/utils/stats.d.ts +9 -3
  359. package/out/utils/stats.d.ts.map +1 -1
  360. package/out/utils/stats.js +11 -5
  361. package/out/utils/stats.js.map +1 -1
  362. package/package.json +2 -2
  363. package/pipeline/index.ts +5 -1
  364. package/pipeline/reconcile-lookups.ts +3 -0
  365. package/pipeline/reconcile.ts +65 -24
  366. package/pipeline/runtime-pipeline.ts +95 -46
  367. package/pipeline/span-logit-aggregation.ts +7 -2
  368. package/pipeline/span-proposer.ts +95 -34
  369. package/pipeline/types.ts +88 -19
  370. package/policy/proposal-collection.ts +4 -3
  371. package/policy/registry.ts +13 -3
  372. package/resolver/index.ts +1 -0
  373. package/resolver/types.ts +95 -30
  374. package/resources/LocaleIndex.ts +2 -2
  375. package/resources/ResourceMapCache.ts +3 -2
  376. package/resources/collections.ts +4 -1
  377. package/resources/languages/index.ts +2 -1
  378. package/resources/libpostal.ts +6 -3
  379. package/resources/set.ts +6 -6
  380. package/resources/whosonfirst/DataSourceCache.ts +2 -24
  381. package/resources/whosonfirst/PlacetypeDataSource.ts +2 -2
  382. package/resources/whosonfirst/backoff.ts +39 -0
  383. package/resources/whosonfirst/loader.ts +2 -1
  384. package/resources/whosonfirst/placetypes/Placetype.ts +9 -6
  385. package/resources/whosonfirst/placetypes/admin.ts +12 -7
  386. package/resources/whosonfirst/placetypes/definition.ts +6 -6
  387. package/resources/whosonfirst/placetypes/graph.ts +0 -0
  388. package/resources/whosonfirst/placetypes/mermaid.ts +5 -2
  389. package/resources/whosonfirst/placetypes/tree.ts +1 -1
  390. package/routing/index.ts +5 -1
  391. package/scripting/utils/index.ts +3 -1
  392. package/tokenization/Span.ts +1 -1
  393. package/tokenization/normalizer.ts +11 -11
  394. package/tools/download-libpostal-resources.ts +1 -0
  395. package/tools/download-ssl-address.ts +19 -7
  396. package/tools/generate-language-types.ts +12 -4
  397. package/types/Classification.ts +5 -0
  398. package/types/classifier.ts +27 -9
  399. package/types/component.ts +9 -5
  400. package/utils/data-root.ts +3 -1
  401. package/utils/hash.ts +6 -2
  402. package/utils/jsonl.ts +11 -3
  403. package/utils/python-json.ts +13 -4
  404. package/utils/python-random.ts +17 -7
  405. package/utils/repo.ts +8 -0
  406. package/utils/sealed-db.ts +10 -2
  407. package/utils/stats.ts +11 -5
package/api/APIClient.ts CHANGED
@@ -16,7 +16,7 @@ import {
16
16
 
17
17
  import { delegateAxiosError } from "./responses.ts"
18
18
 
19
- export type { IRuntimeLogger }
19
+ export { type IRuntimeLogger } from "@mailwoman/core/logging"
20
20
 
21
21
  /**
22
22
  * Configuration for an API client.
@@ -78,6 +78,7 @@ export class APIClient<C extends APIClientConfig = APIClientConfig> extends Even
78
78
  ...config.axios,
79
79
  })
80
80
 
81
+ // oxlint-disable-next-line unicorn/prefer-ternary -- the branches are multi-line client constructions
81
82
  if (config.caching) {
82
83
  this.axios = setupCache(axiosInstance, {
83
84
  debug: (msg) => {
@@ -102,7 +103,7 @@ export class APIClient<C extends APIClientConfig = APIClientConfig> extends Even
102
103
 
103
104
  this.axios.interceptors.response.use(undefined, delegateAxiosError)
104
105
 
105
- this.#requestInterval = typeof config.requestsPerMinute === "number" ? 60000 / config.requestsPerMinute : 0
106
+ this.#requestInterval = typeof config.requestsPerMinute === "number" ? 60_000 / config.requestsPerMinute : 0
106
107
 
107
108
  if (this.#requestInterval) {
108
109
  this.axios.interceptors.response.use(this.updateCooldownAfterResponse)
@@ -165,8 +166,6 @@ export class APIClient<C extends APIClientConfig = APIClientConfig> extends Even
165
166
  if (isAsyncDisposable(storedCache)) {
166
167
  await storedCache[Symbol.asyncDispose]()
167
168
  }
168
-
169
- return Promise.resolve()
170
169
  }
171
170
 
172
171
  public override toString() {
package/api/responses.ts CHANGED
@@ -31,6 +31,7 @@ export type ExtractResponseData<T> = T extends ResponseContainer<infer Body> ? B
31
31
 
32
32
  function isResponseContainer<Body>(responseContainer: ResponseLike<Body>): responseContainer is ResponseContainer<Body>
33
33
  function isResponseContainer<Body>(body: Body): body is Body
34
+
34
35
  function isResponseContainer<Body>(input: ResponseLike<Body>): input is ResponseContainer<Body> {
35
36
  return typeof input === "object" && input !== null && "data" in input
36
37
  }
@@ -40,6 +41,7 @@ function isResponseContainer<Body>(input: ResponseLike<Body>): input is Response
40
41
  */
41
42
  function pluckResponseBody<Body>(responseContainer: ResponseContainer<Body>): Body
42
43
  function pluckResponseBody<Body>(rawBody: Body): Body
44
+
43
45
  function pluckResponseBody<Body>(input: ResponseContainer<Body> | Body): Body {
44
46
  if (isResponseContainer(input)) return input.data
45
47
 
@@ -67,6 +69,7 @@ export type ExtractResponseBodyData<Body> = Body extends {
67
69
  * @internal
68
70
  */
69
71
  export function pluckResponseData<Body>(responseContainer: ResponseContainer<Body>): ExtractResponseBodyData<Body>
72
+
70
73
  export function pluckResponseData<Body>(input: ResponseContainer<Body> | Body): ExtractResponseBodyData<Body> {
71
74
  const body = pluckResponseBody(input)
72
75
 
@@ -92,7 +95,7 @@ export function checkConnectivity(
92
95
  */
93
96
  export async function delegateAxiosError(error: unknown): Promise<unknown> {
94
97
  {
95
- if (!isAxiosError(error)) return Promise.reject(error)
98
+ if (!isAxiosError(error)) throw error
96
99
 
97
100
  const { response, code: networkErrorCode } = error
98
101
 
@@ -125,11 +128,11 @@ export async function delegateAxiosError(error: unknown): Promise<unknown> {
125
128
  case AxiosError.ERR_CANCELED:
126
129
  case AxiosError.ECONNABORTED:
127
130
  case AxiosError.ETIMEDOUT:
128
- return Promise.resolve()
131
+ return
129
132
  default:
130
133
  ConsoleLogger.warn(`Unhandled network error: ${networkErrorCode}`)
131
134
  }
132
135
 
133
- return Promise.reject(error)
136
+ throw error
134
137
  }
135
138
  }
@@ -11,9 +11,10 @@
11
11
  */
12
12
 
13
13
  import { $public } from "../env/index.ts"
14
- import { COARSE_CLASSES, FEATURE_DIM, featurize } from "./featurize.ts"
14
+ import { featurize } from "./featurize.ts"
15
+
16
+ export { COARSE_CLASSES, FEATURE_DIM, featurize } from "./featurize.ts"
15
17
 
16
- /** Serialized model: metadata in JSON, the dense `weights` (row-major [class][feature]) alongside. */
17
18
  export interface CoarsePlacerArtifact {
18
19
  /**
19
20
  * The coarse placer's classes (the country/region codes it routes to).
@@ -47,7 +48,9 @@ export interface CoarsePlacerMeta {
47
48
  temperature: number
48
49
  bias: number[]
49
50
  quantization?: "int8-per-row"
50
- /** Per-class dequantization scale; present iff `quantization === "int8-per-row"`. */
51
+ /**
52
+ * Per-class dequantization scale; present iff `quantization === "int8-per-row"`.
53
+ */
51
54
  scales?: number[]
52
55
  }
53
56
 
@@ -82,17 +85,25 @@ export function dequantizeInt8Weights(
82
85
  }
83
86
 
84
87
  export interface CoarsePrediction {
85
- /** The predicted class, or `null` when the model abstained (confidence below the threshold). */
88
+ /**
89
+ * The predicted class, or `null` when the model abstained (confidence below the threshold).
90
+ */
86
91
  country: string | null
87
- /** Calibrated probability of the top class (the abstention signal). */
92
+ /**
93
+ * Calibrated probability of the top class (the abstention signal).
94
+ */
88
95
  confidence: number
89
96
  abstained: boolean
90
- /** The full calibrated class distribution. */
97
+ /**
98
+ * The full calibrated class distribution.
99
+ */
91
100
  probs: Record<string, number>
92
101
  }
93
102
 
94
103
  export interface CoarsePlacerOpts {
95
- /** Abstain when the calibrated top-class confidence is below this (default 0.5). */
104
+ /**
105
+ * Abstain when the calibrated top-class confidence is below this (default 0.5).
106
+ */
96
107
  abstainBelow?: number
97
108
  /**
98
109
  * Open-set reject rule (#244 M2). When `true`, the ABSTAIN decision uses the total IN-MAP probability mass `1 -
@@ -189,8 +200,10 @@ export class CoarsePlacer {
189
200
  for (const i of feats) {
190
201
  s += this.#weights[base + i]!
191
202
  }
203
+
192
204
  logits[c] = s / this.#temp
193
205
  }
206
+
194
207
  // Numerically-stable softmax.
195
208
  let maxLogit = -Infinity
196
209
 
@@ -198,6 +211,7 @@ export class CoarsePlacer {
198
211
  if (logits[c]! > maxLogit) {
199
212
  maxLogit = logits[c]!
200
213
  }
214
+
201
215
  let sum = 0
202
216
  const probs = new Float32Array(C)
203
217
 
@@ -206,6 +220,7 @@ export class CoarsePlacer {
206
220
  probs[c] = e
207
221
  sum += e
208
222
  }
223
+
209
224
  let topIdx = 0
210
225
  let topProb = -1
211
226
  let otherProb = 0
@@ -293,14 +308,16 @@ export function inMapPosterior(
293
308
 
294
309
  // The argmax always survives (it is ≥ every other marginal; if even it fell below the floor the
295
310
  // prediction would have abstained upstream) — but guard anyway so the posterior is never empty.
296
- if (Object.keys(posterior).length === 0) {
311
+ if (!Object.keys(posterior).length) {
297
312
  posterior[prediction.country] = prediction.confidence
298
313
  }
299
314
 
300
315
  return posterior
301
316
  }
302
317
 
303
- /** Load a coarse-placer from a JSON metadata file + a sibling `.weights.bin` (Float32). */
318
+ /**
319
+ * Load a coarse-placer from a JSON metadata file + a sibling `.weights.bin` (Float32).
320
+ */
304
321
  export async function loadCoarsePlacer(
305
322
  metaJson: { classes: string[]; featureDim: number; temperature: number; bias: number[] },
306
323
  weights: Float32Array,
@@ -308,5 +325,3 @@ export async function loadCoarsePlacer(
308
325
  ): Promise<CoarsePlacer> {
309
326
  return new CoarsePlacer({ ...metaJson, weights }, opts)
310
327
  }
311
-
312
- export { COARSE_CLASSES, FEATURE_DIM, featurize }
@@ -64,6 +64,7 @@ export const COARSE_CLASSES = [
64
64
  "AU",
65
65
  "OTHER",
66
66
  ] as const
67
+
67
68
  export type CoarseClass = (typeof COARSE_CLASSES)[number]
68
69
 
69
70
  /**
@@ -72,7 +73,9 @@ export type CoarseClass = (typeof COARSE_CLASSES)[number]
72
73
  */
73
74
  export const FEATURE_DIM = 1 << 16
74
75
 
75
- /** Coarse Unicode-script buckets — strong priors the n-grams refine. */
76
+ /**
77
+ * Coarse Unicode-script buckets — strong priors the n-grams refine.
78
+ */
76
79
  const SCRIPTS = [
77
80
  "latin",
78
81
  "cjk",
@@ -85,43 +88,47 @@ const SCRIPTS = [
85
88
  "digit",
86
89
  "other",
87
90
  ] as const
91
+
88
92
  type Script = (typeof SCRIPTS)[number]
89
93
 
90
94
  function scriptOf(cp: number): Script {
91
95
  if (cp >= 0x30 && cp <= 0x39) return "digit"
92
96
 
93
- if ((cp >= 0x41 && cp <= 0x5a) || (cp >= 0x61 && cp <= 0x7a) || (cp >= 0xc0 && cp <= 0x24f)) return "latin"
97
+ if ((cp >= 0x41 && cp <= 0x5a) || (cp >= 0x61 && cp <= 0x7a) || (cp >= 0xc0 && cp <= 0x2_4f)) return "latin"
94
98
 
95
99
  if (
96
- (cp >= 0x3040 && cp <= 0x30ff) ||
97
- (cp >= 0x4e00 && cp <= 0x9fff) ||
98
- (cp >= 0xac00 && cp <= 0xd7af) ||
99
- (cp >= 0x3400 && cp <= 0x4dbf)
100
+ (cp >= 0x30_40 && cp <= 0x30_ff) ||
101
+ (cp >= 0x4e_00 && cp <= 0x9f_ff) ||
102
+ (cp >= 0xac_00 && cp <= 0xd7_af) ||
103
+ (cp >= 0x34_00 && cp <= 0x4d_bf)
100
104
  )
101
105
  return "cjk"
102
106
 
103
- if ((cp >= 0x400 && cp <= 0x52f) || (cp >= 0x2de0 && cp <= 0x2dff)) return "cyrillic"
107
+ if ((cp >= 0x4_00 && cp <= 0x5_2f) || (cp >= 0x2d_e0 && cp <= 0x2d_ff)) return "cyrillic"
104
108
 
105
- if ((cp >= 0x600 && cp <= 0x6ff) || (cp >= 0x750 && cp <= 0x77f) || (cp >= 0xfb50 && cp <= 0xfeff)) return "arabic"
109
+ if ((cp >= 0x6_00 && cp <= 0x6_ff) || (cp >= 0x7_50 && cp <= 0x7_7f) || (cp >= 0xfb_50 && cp <= 0xfe_ff))
110
+ return "arabic"
106
111
 
107
- if (cp >= 0x370 && cp <= 0x3ff) return "greek"
112
+ if (cp >= 0x3_70 && cp <= 0x3_ff) return "greek"
108
113
 
109
- if (cp >= 0x590 && cp <= 0x5ff) return "hebrew"
114
+ if (cp >= 0x5_90 && cp <= 0x5_ff) return "hebrew"
110
115
 
111
- if (cp >= 0x900 && cp <= 0x97f) return "devanagari"
116
+ if (cp >= 0x9_00 && cp <= 0x9_7f) return "devanagari"
112
117
 
113
- if (cp >= 0xe00 && cp <= 0xe7f) return "thai"
118
+ if (cp >= 0xe_00 && cp <= 0xe_7f) return "thai"
114
119
 
115
120
  return "other"
116
121
  }
117
122
 
118
- /** FNV-1a → a feature bucket in [0, FEATURE_DIM). */
123
+ /**
124
+ * FNV-1a → a feature bucket in [0, FEATURE_DIM).
125
+ */
119
126
  function bucket(s: string, salt: number): number {
120
- let h = (2166136261 ^ salt) >>> 0
127
+ let h = (2_166_136_261 ^ salt) >>> 0
121
128
 
122
129
  for (let i = 0; i < s.length; i++) {
123
130
  h ^= s.charCodeAt(i)
124
- h = Math.imul(h, 16777619)
131
+ h = Math.imul(h, 16_777_619)
125
132
  }
126
133
 
127
134
  return (h >>> 0) % FEATURE_DIM
@@ -133,7 +140,7 @@ function bucket(s: string, salt: number): number {
133
140
  * PRESERVED (lowercasing only touches cased scripts).
134
141
  */
135
142
  export function featurize(text: string): number[] {
136
- const norm = text.toLowerCase().replace(/\s+/g, " ").trim()
143
+ const norm = text.toLowerCase().replaceAll(/\s+/g, " ").trim()
137
144
 
138
145
  if (!norm) return []
139
146
  const active = new Set<number>()
@@ -145,6 +152,7 @@ export function featurize(text: string): number[] {
145
152
  const sc = scriptOf(ch.codePointAt(0)!)
146
153
  counts.set(sc, (counts.get(sc) ?? 0) + 1)
147
154
  }
155
+
148
156
  let dominant: Script = "other"
149
157
  let max = -1
150
158
 
@@ -156,6 +164,7 @@ export function featurize(text: string): number[] {
156
164
  dominant = sc
157
165
  }
158
166
  }
167
+
159
168
  active.add(bucket(`__dom_${dominant}`, 2))
160
169
 
161
170
  // Char n-grams (3,4,5) over the boundary-marked string.
@@ -30,15 +30,23 @@ interface DatasetRow {
30
30
  country: string
31
31
  }
32
32
 
33
- /** Options for {@linkcode buildDataset}. */
33
+ /**
34
+ * Options for {@linkcode buildDataset}.
35
+ */
34
36
  export interface BuildDatasetOptions {
35
- /** Rows sampled per country. Default 50000. */
37
+ /**
38
+ * Rows sampled per country. Default 50000.
39
+ */
36
40
  perCountry?: number
37
- /** Dataset output dir. Default `<repo>/data/coarse-placer`. */
41
+ /**
42
+ * Dataset output dir. Default `<repo>/data/coarse-placer`.
43
+ */
38
44
  data?: string
39
45
  }
40
46
 
41
- /** Result of {@linkcode buildDataset}. */
47
+ /**
48
+ * Result of {@linkcode buildDataset}.
49
+ */
42
50
  export interface BuildDatasetResult {
43
51
  outDir: string
44
52
  train: number
@@ -51,17 +59,20 @@ const TEST_FRAC = 0.1
51
59
 
52
60
  const COUNTRIES = ["US", "FR", "GB", "CN", "NL", "IT", "DE", "JP", "ES", "KR", "TW"]
53
61
 
54
- // #743: the EU expansion. The v0.5.0 corpus carries zero rows for these locales, so they're drawn
55
- // from the Overture per-country addresses theme (the same source build-eu-eval-set.ts uses). They
56
- // were previously OTHER outlier exposure (PL/PT/CZ) or simply unrepresentable; here they become
57
- // first-class in-map countries so the soft country prior can pin them.
62
+ /**
63
+ * #743: the EU expansion. The v0.5.0 corpus carries zero rows for these locales, so they're drawn from the Overture
64
+ * per-country addresses theme (the same source build-eu-eval-set.ts uses). They were previously OTHER outlier exposure
65
+ * (PL/PT/CZ) or simply unrepresentable; here they become first-class in-map countries so the soft country prior can pin
66
+ * them.
67
+ */
58
68
  const NEW_EU = ["AT", "BE", "CH", "CZ", "DK", "EE", "FI", "HR", "LT", "LU", "LV", "NO", "PL", "PT", "SI", "SK"]
59
- // #743 in-map dilution fix: DE/ES/IT/NL are already in COUNTRIES (corpus format), but the eu-eval
60
- // sets + every NEW_EU country are Overture format. Without an Overture sample of their OWN, their
61
- // Overture-format eval rows scatter to the Overture-trained neighbours (measured: only 63% of ES
62
- // eval rows routed ES, ~26% leaked to CH/PT/HR/IT/FR/CZ). SUPPLEMENT their corpus rows with an
63
- // Overture sample so each owns its own format shape; the format then stops being discriminative and
64
- // the model falls back to the linguistic n-grams. GB excluded — its Overture parquet is empty.
69
+ /**
70
+ * #743 in-map dilution fix: DE/ES/IT/NL are already in COUNTRIES (corpus format), but the eu-eval sets + every NEW_EU
71
+ * country are Overture format. Without an Overture sample of their OWN, their Overture-format eval rows scatter to the
72
+ * Overture-trained neighbours (measured: only 63% of ES eval rows routed ES, ~26% leaked to CH/PT/HR/IT/FR/CZ).
73
+ * SUPPLEMENT their corpus rows with an Overture sample so each owns its own format shape; the format then stops being
74
+ * discriminative and the model falls back to the linguistic n-grams. GB excluded — its Overture parquet is empty.
75
+ */
65
76
  const IN_MAP_EU = ["DE", "ES", "IT", "NL"]
66
77
 
67
78
  // #743 EU expansion: draw the new in-map countries from the Overture per-country addresses theme.
@@ -86,15 +97,18 @@ function formatEu(street: unknown, number: unknown, postcode: unknown, loc: stri
86
97
  }
87
98
  }
88
99
 
89
- /** Coarse-placer dataset builder — see the module doc. */
100
+ /**
101
+ * Coarse-placer dataset builder — see the module doc.
102
+ */
90
103
  export async function buildDataset(
91
104
  options: BuildDatasetOptions = {},
92
105
  report?: (line: string) => void
93
106
  ): Promise<BuildDatasetResult> {
94
- const PER = options.perCountry ?? 50000
107
+ const PER = options.perCountry ?? 50_000
95
108
  const OUT_DIR = options.data || repoRootPath("data", "coarse-placer")
96
109
 
97
110
  const TRAIN_GLOB = dataRootPath("corpus", "versioned", "v0.5.0", "corpus-v0.5.0", "train", "*.parquet")
111
+
98
112
  // #244/#928 AU expansion: the v0.5.0 pin carries only ~5.9k AU rows; the v0.9.2 G-NAF shard carries
99
113
  // 150k real Australian addresses. AU rides the SAME corpus sampling path as COUNTRIES, just from its
100
114
  // own glob — the (country, glob) pairs below unify the two.
@@ -106,6 +120,7 @@ export async function buildDataset(
106
120
  "train",
107
121
  "*.parquet"
108
122
  )
123
+
109
124
  const OVERTURE_DIR = dataRootPath("overture", "2026-06-17.0")
110
125
  mkdirSync(OUT_DIR, { recursive: true })
111
126
 
@@ -128,6 +143,7 @@ export async function buildDataset(
128
143
  const q = `SELECT raw FROM (
129
144
  SELECT raw FROM read_parquet('${glob}') WHERE country = '${country}' AND nullif(trim(raw), '') IS NOT NULL
130
145
  ) USING SAMPLE ${Math.ceil(PER * 1.3)} ROWS`
146
+
131
147
  const res = await duck.runAndReadAll(q)
132
148
  const seen = new Set<string>()
133
149
  const rows: string[] = []
@@ -140,6 +156,7 @@ export async function buildDataset(
140
156
  seen.add(raw)
141
157
  rows.push(raw)
142
158
  }
159
+
143
160
  const nVal = Math.floor(rows.length * VAL_FRAC)
144
161
  const nTest = Math.floor(rows.length * TEST_FRAC)
145
162
  const valRows = rows.slice(0, nVal)
@@ -157,24 +174,29 @@ export async function buildDataset(
157
174
  for (const raw of testRows) {
158
175
  test.push({ raw, country })
159
176
  }
177
+
160
178
  report?.(` ${country}: train ${trainRows.length} val ${valRows.length} test ${testRows.length}`)
161
179
  }
162
180
 
163
181
  for (const country of [...NEW_EU, ...IN_MAP_EU]) {
164
182
  const parquet = `${OVERTURE_DIR}/addresses-${country.toLowerCase()}.parquet`
183
+
165
184
  const q = `SELECT street, number, postcode,
166
185
  COALESCE(NULLIF(trim(postal_city), ''), address_levels[len(address_levels)].value) AS loc
167
186
  FROM read_parquet('${parquet}')
168
187
  WHERE street IS NOT NULL AND trim(street) <> ''
169
188
  USING SAMPLE ${Math.ceil(PER * 1.4)} ROWS`
189
+
170
190
  let res
171
191
 
172
192
  try {
173
193
  res = await duck.runAndReadAll(q)
174
- } catch (e) {
175
- report?.(` ${country}: SKIPPED — ${(e as Error).message}`)
194
+ } catch (error) {
195
+ report?.(` ${country}: SKIPPED — ${(error as Error).message}`)
196
+
176
197
  continue
177
198
  }
199
+
178
200
  const seen = new Set<string>()
179
201
  const rows: string[] = []
180
202
 
@@ -189,6 +211,7 @@ export async function buildDataset(
189
211
  seen.add(raw)
190
212
  rows.push(raw)
191
213
  }
214
+
192
215
  const nVal = Math.floor(rows.length * VAL_FRAC)
193
216
  const nTest = Math.floor(rows.length * TEST_FRAC)
194
217
 
@@ -203,6 +226,7 @@ export async function buildDataset(
203
226
  for (const raw of rows.slice(nVal + nTest)) {
204
227
  train.push({ raw, country })
205
228
  }
229
+
206
230
  report?.(` ${country} (overture): train ${rows.length - nVal - nTest} val ${nVal} test ${nTest}`)
207
231
  }
208
232
 
@@ -24,23 +24,42 @@ import { dataRootPath } from "../../utils/data-root.ts"
24
24
  import { repoRootPath } from "../../utils/repo.ts"
25
25
  import { hashFNV1a } from "./fnv-hash.ts"
26
26
 
27
- /** Options for {@linkcode buildOutlierExposure}. */
27
+ /**
28
+ * Share of a bucket that must be off-map before it is treated as an exposure case rather than noise.
29
+ */
30
+ const OFFMAP_DOMINANCE = 0.6
31
+
32
+ /**
33
+ * Options for {@linkcode buildOutlierExposure}.
34
+ */
28
35
  export interface BuildOutlierExposureOptions {
29
- /** Names sampled per off-map language. Default 2500. */
36
+ /**
37
+ * Names sampled per off-map language. Default 2500.
38
+ */
30
39
  perLang?: number
31
- /** WOF admin SQLite path. Default `$MAILWOMAN_DATA_ROOT/wof/admin-global-priority.db`. */
40
+ /**
41
+ * WOF admin SQLite path. Default `$MAILWOMAN_DATA_ROOT/wof/admin-global-priority.db`.
42
+ */
32
43
  wof?: string
33
- /** Dataset dir the OTHER rows append to. Default `<repo>/data/coarse-placer`. */
44
+ /**
45
+ * Dataset dir the OTHER rows append to. Default `<repo>/data/coarse-placer`.
46
+ */
34
47
  data?: string
35
48
  }
36
49
 
37
- /** Result of {@linkcode buildOutlierExposure}. */
50
+ /**
51
+ * Result of {@linkcode buildOutlierExposure}.
52
+ */
38
53
  export interface BuildOutlierExposureResult {
39
- /** Total OTHER pool size (names + address-shaped variants). */
54
+ /**
55
+ * Total OTHER pool size (names + address-shaped variants).
56
+ */
40
57
  total: number
41
58
  }
42
59
 
43
- // Off-map languages whose `names` are written in a NON-Latin, NON-CJK script (CJK = the in-map CN/JP/KR/TW).
60
+ /**
61
+ * Off-map languages whose `names` are written in a NON-Latin, NON-CJK script (CJK = the in-map CN/JP/KR/TW).
62
+ */
44
63
  const OFF_MAP_LANGS = [
45
64
  "rus",
46
65
  "ukr",
@@ -75,7 +94,9 @@ const OFF_MAP_LANGS = [
75
94
  "amh", // Georgian / Armenian / Ethiopic
76
95
  ]
77
96
 
78
- /** Dominant script must be off-map: has chars in a non-Latin, non-CJK, non-digit block. */
97
+ /**
98
+ * Dominant script must be off-map: has chars in a non-Latin, non-CJK, non-digit block.
99
+ */
79
100
  function isOffMapScript(s: string): boolean {
80
101
  let off = 0
81
102
  let total = 0
@@ -83,21 +104,24 @@ function isOffMapScript(s: string): boolean {
83
104
  for (const ch of s) {
84
105
  const cp = ch.codePointAt(0)!
85
106
 
86
- if (cp <= 0x40 || (cp >= 0x5b && cp <= 0x60) || cp === 0x20) continue // punct/space/digits
107
+ if (cp <= 0x40 || (cp >= 0x5b && cp <= 0x60) || cp === 0x20) continue
108
+
109
+ // punct/space/digits
87
110
  total++
88
- const latin = (cp >= 0x41 && cp <= 0x5a) || (cp >= 0x61 && cp <= 0x7a) || (cp >= 0xc0 && cp <= 0x24f)
111
+ const latin = (cp >= 0x41 && cp <= 0x5a) || (cp >= 0x61 && cp <= 0x7a) || (cp >= 0xc0 && cp <= 0x2_4f)
112
+
89
113
  const cjk =
90
- (cp >= 0x3040 && cp <= 0x30ff) ||
91
- (cp >= 0x4e00 && cp <= 0x9fff) ||
92
- (cp >= 0xac00 && cp <= 0xd7af) ||
93
- (cp >= 0x3400 && cp <= 0x4dbf)
114
+ (cp >= 0x30_40 && cp <= 0x30_ff) ||
115
+ (cp >= 0x4e_00 && cp <= 0x9f_ff) ||
116
+ (cp >= 0xac_00 && cp <= 0xd7_af) ||
117
+ (cp >= 0x34_00 && cp <= 0x4d_bf)
94
118
 
95
- if (!latin && !cjk && cp > 0x2ff) {
119
+ if (!latin && !cjk && cp > 0x2_ff) {
96
120
  off++
97
121
  }
98
122
  }
99
123
 
100
- return total > 0 && off / total > 0.6
124
+ return total > 0 && off / total > OFFMAP_DOMINANCE
101
125
  }
102
126
 
103
127
  // Mimic a real off-map ADDRESS: a pure-script place name isn't what we see at inference (those carry
@@ -118,7 +142,9 @@ function addressVariant(name: string, h: number): string {
118
142
  }
119
143
  }
120
144
 
121
- /** Coarse-placer non-Latin outlier-exposure builder — see the module doc. */
145
+ /**
146
+ * Coarse-placer non-Latin outlier-exposure builder — see the module doc.
147
+ */
122
148
  export async function buildOutlierExposure(
123
149
  options: BuildOutlierExposureOptions = {},
124
150
  report?: (line: string) => void
@@ -135,6 +161,7 @@ export async function buildOutlierExposure(
135
161
  const rows = db
136
162
  .prepare(`SELECT name FROM names WHERE language = ? AND length(name) >= 4 LIMIT ?`)
137
163
  .all(lang, PER * 2)
164
+
138
165
  let kept = 0
139
166
 
140
167
  for (const r of rows) {
@@ -144,17 +171,22 @@ export async function buildOutlierExposure(
144
171
  if (!name || seen.has(name) || !isOffMapScript(name)) continue
145
172
  seen.add(name)
146
173
  pool.push(name)
147
- pool.push(addressVariant(name, hashFNV1a(name))) // address-shaped sibling
174
+ pool.push(addressVariant(name, hashFNV1a(name)))
175
+
176
+ // address-shaped sibling
148
177
  kept++
149
178
  }
179
+
150
180
  report?.(` ${lang}: ${kept}`)
151
181
  }
182
+
152
183
  db.close()
153
184
 
154
185
  // Deterministic shuffle (FNV hash sort) + split 80/10/10, append as OTHER.
155
186
  pool.sort((a, b) => hashFNV1a(a) - hashFNV1a(b))
156
187
  const nVal = Math.floor(pool.length * 0.1)
157
188
  const nTest = Math.floor(pool.length * 0.1)
189
+
158
190
  const splits: Record<string, string[]> = {
159
191
  val: pool.slice(0, nVal),
160
192
  test: pool.slice(nVal, nVal + nTest),
@@ -166,6 +198,7 @@ export async function buildOutlierExposure(
166
198
  appendFileSync(path.join(dataDir, `${split}.jsonl`), lines)
167
199
  report?.(`appended ${names.length} OTHER → ${split}.jsonl`)
168
200
  }
201
+
169
202
  report?.(`total OTHER pool: ${pool.length}`)
170
203
 
171
204
  return { total: pool.length }