@mailwoman/resolver-wof-sqlite 11.2.0 → 11.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 (452) hide show
  1. package/lib/address/duplicate.ts +1 -1
  2. package/lib/address/keys/attribution.ts +6 -1
  3. package/lib/address/keys/build.ts +1 -1
  4. package/lib/address/keys/layout.ts +27 -1
  5. package/lib/address/keys/lookup.ts +2 -2
  6. package/lib/address/keys/point-lookup.ts +2 -2
  7. package/lib/address/number-forms.ts +4 -6
  8. package/lib/address/point/interpolation.ts +11 -3
  9. package/lib/address/point/schema.ts +1 -1
  10. package/lib/address/point.ts +15 -14
  11. package/lib/address/record.ts +1 -1
  12. package/lib/build/candidate.ts +136 -40
  13. package/lib/build/slim.ts +4 -1
  14. package/lib/build/sources.ts +50 -0
  15. package/lib/candidate/alias-bags.ts +22 -8
  16. package/lib/candidate/ancestors/schema.ts +1 -1
  17. package/lib/candidate/ancestors/sidecar.ts +13 -2
  18. package/lib/candidate/bare-admin-names.ts +1 -1
  19. package/lib/{capital-schema.ts → candidate/capital-schema.ts} +3 -3
  20. package/lib/{capitals.ts → candidate/capitals.ts} +1 -1
  21. package/lib/candidate/country-display-names.ts +1 -1
  22. package/lib/candidate/{extract-fold.ts → extract-rows.ts} +7 -4
  23. package/lib/candidate/importance.ts +86 -8
  24. package/lib/candidate/key-fold.ts +1 -1
  25. package/lib/candidate/lookup.ts +79 -48
  26. package/lib/candidate/name-roles.ts +1 -1
  27. package/lib/candidate/nickname-namesakes.ts +8 -1
  28. package/lib/candidate/overture-twins.ts +83 -0
  29. package/lib/candidate/place-attrs.ts +2 -2
  30. package/lib/candidate/postcode-browse.ts +173 -0
  31. package/lib/candidate/schema.ts +43 -2
  32. package/lib/candidate/scoring.ts +4 -4
  33. package/lib/convention.ts +1 -1
  34. package/lib/env.ts +15 -3
  35. package/lib/fst/builder.ts +8 -6
  36. package/lib/fst/deserialize-web.ts +1 -1
  37. package/lib/fst/freshness.ts +2 -2
  38. package/lib/fst/serialize.ts +1 -1
  39. package/lib/fts/query.ts +1 -1
  40. package/lib/{search-fetch.ts → fts/search-fetch.ts} +2 -2
  41. package/lib/geonames/aliases.ts +37 -33
  42. package/lib/geonames/postal.ts +3 -3
  43. package/lib/index.ts +20 -17
  44. package/lib/{postal/city → labels/locality/postal-city}/alias/lookup.ts +1 -1
  45. package/lib/{postal/city → labels/locality/postal-city}/candidate-schema.ts +1 -1
  46. package/lib/labels/locality.ts +6 -0
  47. package/lib/{region-keys.ts → labels/region.ts} +5 -2
  48. package/lib/{street → labels/street}/centroid/schema.ts +1 -1
  49. package/lib/{street → labels/street}/centroid.ts +7 -7
  50. package/lib/{interpolation.ts → labels/street/interpolation.ts} +12 -4
  51. package/lib/labels/street/locale.ts +117 -0
  52. package/lib/{street → labels/street}/morphology/fst/loader.ts +1 -1
  53. package/lib/{street → labels/street}/name-lookup.ts +2 -0
  54. package/lib/{street → labels/street}/normalize.ts +242 -133
  55. package/lib/{street → labels/street}/segment-schema.ts +1 -1
  56. package/lib/{street → labels/street}/table.ts +1 -1
  57. package/lib/labels/street.ts +11 -0
  58. package/lib/landmark/rows.ts +1 -1
  59. package/lib/lookup/browse.ts +304 -0
  60. package/lib/{extracts.ts → lookup/extracts.ts} +1 -1
  61. package/lib/lookup/former-divisions.ts +183 -0
  62. package/lib/{postcode-point-lookup.ts → lookup/postcode-point.ts} +5 -0
  63. package/lib/{reverse.ts → lookup/reverse.ts} +4 -4
  64. package/lib/{types.ts → lookup/types.ts} +10 -0
  65. package/lib/lookup.ts +21 -31
  66. package/lib/poi/schema.ts +1 -1
  67. package/lib/{primary-preference.ts → ranking/primary-preference.ts} +5 -0
  68. package/lib/schema/overture-match.ts +79 -0
  69. package/lib/{place-importance-schema.ts → schema/place-importance.ts} +86 -0
  70. package/lib/schema.ts +3 -3
  71. package/lib/sqlite/convention-source.ts +1 -1
  72. package/lib/uprn/existence.ts +2 -0
  73. package/lib/{weights-overlay-linker.ts → weights/overlay-linker.ts} +244 -103
  74. package/out/address/duplicate.js +1 -1
  75. package/out/address/duplicate.js.map +1 -1
  76. package/out/address/keys/attribution.d.ts +4 -0
  77. package/out/address/keys/attribution.d.ts.map +1 -1
  78. package/out/address/keys/attribution.js +5 -1
  79. package/out/address/keys/attribution.js.map +1 -1
  80. package/out/address/keys/build.d.ts.map +1 -1
  81. package/out/address/keys/build.js +1 -1
  82. package/out/address/keys/build.js.map +1 -1
  83. package/out/address/keys/layout.d.ts +18 -1
  84. package/out/address/keys/layout.d.ts.map +1 -1
  85. package/out/address/keys/layout.js +23 -1
  86. package/out/address/keys/layout.js.map +1 -1
  87. package/out/address/keys/lookup.js +2 -2
  88. package/out/address/keys/lookup.js.map +1 -1
  89. package/out/address/keys/point-lookup.d.ts.map +1 -1
  90. package/out/address/keys/point-lookup.js +2 -2
  91. package/out/address/keys/point-lookup.js.map +1 -1
  92. package/out/address/number-forms.d.ts +1 -1
  93. package/out/address/number-forms.d.ts.map +1 -1
  94. package/out/address/number-forms.js +4 -5
  95. package/out/address/number-forms.js.map +1 -1
  96. package/out/address/point/interpolation.d.ts +1 -1
  97. package/out/address/point/interpolation.d.ts.map +1 -1
  98. package/out/address/point/interpolation.js +9 -2
  99. package/out/address/point/interpolation.js.map +1 -1
  100. package/out/address/point/schema.d.ts +1 -1
  101. package/out/address/point/schema.d.ts.map +1 -1
  102. package/out/address/point.d.ts +4 -5
  103. package/out/address/point.d.ts.map +1 -1
  104. package/out/address/point.js +11 -11
  105. package/out/address/point.js.map +1 -1
  106. package/out/address/record.d.ts +1 -1
  107. package/out/address/record.d.ts.map +1 -1
  108. package/out/address/record.js +1 -1
  109. package/out/address/record.js.map +1 -1
  110. package/out/build/candidate.d.ts +26 -1
  111. package/out/build/candidate.d.ts.map +1 -1
  112. package/out/build/candidate.js +71 -32
  113. package/out/build/candidate.js.map +1 -1
  114. package/out/build/slim.d.ts.map +1 -1
  115. package/out/build/slim.js +4 -1
  116. package/out/build/slim.js.map +1 -1
  117. package/out/build/sources.d.ts +32 -0
  118. package/out/build/sources.d.ts.map +1 -0
  119. package/out/build/sources.js +35 -0
  120. package/out/build/sources.js.map +1 -0
  121. package/out/candidate/alias-bags.d.ts +0 -3
  122. package/out/candidate/alias-bags.d.ts.map +1 -1
  123. package/out/candidate/alias-bags.js +22 -7
  124. package/out/candidate/alias-bags.js.map +1 -1
  125. package/out/candidate/ancestors/schema.d.ts +1 -1
  126. package/out/candidate/ancestors/schema.d.ts.map +1 -1
  127. package/out/candidate/ancestors/sidecar.d.ts +0 -3
  128. package/out/candidate/ancestors/sidecar.d.ts.map +1 -1
  129. package/out/candidate/ancestors/sidecar.js +16 -2
  130. package/out/candidate/ancestors/sidecar.js.map +1 -1
  131. package/out/candidate/bare-admin-names.js +1 -1
  132. package/out/candidate/bare-admin-names.js.map +1 -1
  133. package/out/{capital-schema.d.ts → candidate/capital-schema.d.ts} +2 -2
  134. package/out/candidate/capital-schema.d.ts.map +1 -0
  135. package/out/{capital-schema.js → candidate/capital-schema.js} +2 -2
  136. package/out/candidate/capital-schema.js.map +1 -0
  137. package/out/candidate/capitals.d.ts.map +1 -0
  138. package/out/{capitals.js → candidate/capitals.js} +1 -1
  139. package/out/candidate/capitals.js.map +1 -0
  140. package/out/candidate/country-display-names.js +1 -1
  141. package/out/candidate/country-display-names.js.map +1 -1
  142. package/out/{coverage-manifest-schema.d.ts → candidate/coverage-manifest.d.ts} +1 -1
  143. package/out/candidate/coverage-manifest.d.ts.map +1 -0
  144. package/out/{coverage-manifest-schema.js → candidate/coverage-manifest.js} +1 -1
  145. package/out/candidate/coverage-manifest.js.map +1 -0
  146. package/out/candidate/{extract-fold.d.ts → extract-rows.d.ts} +2 -2
  147. package/out/candidate/extract-rows.d.ts.map +1 -0
  148. package/out/candidate/{extract-fold.js → extract-rows.js} +8 -5
  149. package/out/candidate/extract-rows.js.map +1 -0
  150. package/out/candidate/importance.d.ts +34 -3
  151. package/out/candidate/importance.d.ts.map +1 -1
  152. package/out/candidate/importance.js +53 -8
  153. package/out/candidate/importance.js.map +1 -1
  154. package/out/candidate/key-fold.d.ts +1 -1
  155. package/out/candidate/key-fold.d.ts.map +1 -1
  156. package/out/candidate/key-fold.js +1 -1
  157. package/out/candidate/key-fold.js.map +1 -1
  158. package/out/candidate/lookup.d.ts +5 -1
  159. package/out/candidate/lookup.d.ts.map +1 -1
  160. package/out/candidate/lookup.js +59 -43
  161. package/out/candidate/lookup.js.map +1 -1
  162. package/out/candidate/name-roles.d.ts.map +1 -1
  163. package/out/candidate/name-roles.js +1 -1
  164. package/out/candidate/name-roles.js.map +1 -1
  165. package/out/candidate/nickname-namesakes.d.ts +0 -4
  166. package/out/candidate/nickname-namesakes.d.ts.map +1 -1
  167. package/out/candidate/nickname-namesakes.js +12 -1
  168. package/out/candidate/nickname-namesakes.js.map +1 -1
  169. package/out/candidate/overture-twins.d.ts +30 -0
  170. package/out/candidate/overture-twins.d.ts.map +1 -0
  171. package/out/candidate/overture-twins.js +40 -0
  172. package/out/candidate/overture-twins.js.map +1 -0
  173. package/out/candidate/place-attrs.d.ts +2 -2
  174. package/out/candidate/postcode-browse.d.ts +36 -0
  175. package/out/candidate/postcode-browse.d.ts.map +1 -0
  176. package/out/candidate/postcode-browse.js +119 -0
  177. package/out/candidate/postcode-browse.js.map +1 -0
  178. package/out/candidate/schema.d.ts +30 -2
  179. package/out/candidate/schema.d.ts.map +1 -1
  180. package/out/candidate/schema.js +29 -0
  181. package/out/candidate/schema.js.map +1 -1
  182. package/out/candidate/scoring.d.ts +3 -3
  183. package/out/candidate/scoring.d.ts.map +1 -1
  184. package/out/candidate/scoring.js +2 -2
  185. package/out/candidate/scoring.js.map +1 -1
  186. package/out/convention.d.ts +1 -1
  187. package/out/convention.d.ts.map +1 -1
  188. package/out/env.d.ts +3 -0
  189. package/out/env.d.ts.map +1 -1
  190. package/out/env.js +14 -3
  191. package/out/env.js.map +1 -1
  192. package/out/fst/builder.d.ts.map +1 -1
  193. package/out/fst/builder.js +8 -6
  194. package/out/fst/builder.js.map +1 -1
  195. package/out/fst/deserialize-web.js +1 -1
  196. package/out/fst/deserialize-web.js.map +1 -1
  197. package/out/fst/freshness.js +2 -2
  198. package/out/fst/freshness.js.map +1 -1
  199. package/out/fst/serialize.js +1 -1
  200. package/out/fst/serialize.js.map +1 -1
  201. package/out/fts/query.d.ts +1 -1
  202. package/out/fts/query.d.ts.map +1 -1
  203. package/out/{search-fetch.d.ts → fts/search-fetch.d.ts} +2 -2
  204. package/out/fts/search-fetch.d.ts.map +1 -0
  205. package/out/fts/search-fetch.js.map +1 -0
  206. package/out/geonames/aliases.d.ts +18 -18
  207. package/out/geonames/aliases.d.ts.map +1 -1
  208. package/out/geonames/aliases.js +17 -17
  209. package/out/geonames/aliases.js.map +1 -1
  210. package/out/geonames/postal.d.ts +1 -1
  211. package/out/geonames/postal.js +3 -3
  212. package/out/index.d.ts +17 -17
  213. package/out/index.d.ts.map +1 -1
  214. package/out/index.js +12 -12
  215. package/out/index.js.map +1 -1
  216. package/out/{postal/city → labels/locality/postal-city}/alias/lookup.d.ts +1 -1
  217. package/out/labels/locality/postal-city/alias/lookup.d.ts.map +1 -0
  218. package/out/labels/locality/postal-city/alias/lookup.js.map +1 -0
  219. package/out/labels/locality/postal-city/alias/schema.d.ts.map +1 -0
  220. package/out/labels/locality/postal-city/alias/schema.js.map +1 -0
  221. package/out/{postal/city → labels/locality/postal-city}/candidate-schema.d.ts +1 -1
  222. package/out/labels/locality/postal-city/candidate-schema.d.ts.map +1 -0
  223. package/out/labels/locality/postal-city/candidate-schema.js.map +1 -0
  224. package/out/labels/locality.d.ts +4 -0
  225. package/out/labels/locality.d.ts.map +1 -0
  226. package/out/labels/locality.js +6 -0
  227. package/out/labels/locality.js.map +1 -0
  228. package/out/{region-keys.d.ts → labels/region.d.ts} +1 -1
  229. package/out/{region-keys.d.ts.map → labels/region.d.ts.map} +1 -1
  230. package/out/{region-keys.js → labels/region.js} +6 -3
  231. package/out/labels/region.js.map +1 -0
  232. package/out/{street → labels/street}/centroid/schema.d.ts +1 -1
  233. package/out/labels/street/centroid/schema.d.ts.map +1 -0
  234. package/out/labels/street/centroid/schema.js.map +1 -0
  235. package/out/{street → labels/street}/centroid.d.ts +5 -5
  236. package/out/labels/street/centroid.d.ts.map +1 -0
  237. package/out/{street → labels/street}/centroid.js +5 -5
  238. package/out/labels/street/centroid.js.map +1 -0
  239. package/out/{interpolation.d.ts → labels/street/interpolation.d.ts} +6 -1
  240. package/out/labels/street/interpolation.d.ts.map +1 -0
  241. package/out/{interpolation.js → labels/street/interpolation.js} +10 -8
  242. package/out/labels/street/interpolation.js.map +1 -0
  243. package/out/labels/street/locale.d.ts +26 -0
  244. package/out/labels/street/locale.d.ts.map +1 -0
  245. package/out/labels/street/locale.js +98 -0
  246. package/out/labels/street/locale.js.map +1 -0
  247. package/out/labels/street/morphology/fst/builder.d.ts.map +1 -0
  248. package/out/labels/street/morphology/fst/builder.js.map +1 -0
  249. package/out/labels/street/morphology/fst/loader.d.ts.map +1 -0
  250. package/out/{street → labels/street}/morphology/fst/loader.js +1 -1
  251. package/out/labels/street/morphology/fst/loader.js.map +1 -0
  252. package/out/labels/street/name-lookup.d.ts.map +1 -0
  253. package/out/{street → labels/street}/name-lookup.js +2 -0
  254. package/out/labels/street/name-lookup.js.map +1 -0
  255. package/out/{street → labels/street}/normalize.d.ts +85 -27
  256. package/out/labels/street/normalize.d.ts.map +1 -0
  257. package/out/{street → labels/street}/normalize.js +162 -119
  258. package/out/labels/street/normalize.js.map +1 -0
  259. package/out/{street → labels/street}/segment-schema.d.ts +1 -1
  260. package/out/labels/street/segment-schema.d.ts.map +1 -0
  261. package/out/labels/street/segment-schema.js.map +1 -0
  262. package/out/labels/street/table.d.ts.map +1 -0
  263. package/out/{street → labels/street}/table.js +1 -1
  264. package/out/labels/street/table.js.map +1 -0
  265. package/out/labels/street.d.ts +9 -0
  266. package/out/labels/street.d.ts.map +1 -0
  267. package/out/labels/street.js +11 -0
  268. package/out/labels/street.js.map +1 -0
  269. package/out/landmark/rows.js +1 -1
  270. package/out/landmark/rows.js.map +1 -1
  271. package/out/lookup/browse.d.ts +79 -0
  272. package/out/lookup/browse.d.ts.map +1 -0
  273. package/out/lookup/browse.js +194 -0
  274. package/out/lookup/browse.js.map +1 -0
  275. package/out/lookup/exact-match.d.ts.map +1 -0
  276. package/out/lookup/exact-match.js.map +1 -0
  277. package/out/lookup/extracts.d.ts.map +1 -0
  278. package/out/{extracts.js → lookup/extracts.js} +1 -1
  279. package/out/lookup/extracts.js.map +1 -0
  280. package/out/lookup/former-divisions.d.ts +99 -0
  281. package/out/lookup/former-divisions.d.ts.map +1 -0
  282. package/out/lookup/former-divisions.js +98 -0
  283. package/out/lookup/former-divisions.js.map +1 -0
  284. package/out/{postcode-point-lookup.d.ts → lookup/postcode-point.d.ts} +5 -1
  285. package/out/lookup/postcode-point.d.ts.map +1 -0
  286. package/out/{postcode-point-lookup.js → lookup/postcode-point.js} +1 -1
  287. package/out/lookup/postcode-point.js.map +1 -0
  288. package/out/{reverse.d.ts → lookup/reverse.d.ts} +1 -1
  289. package/out/lookup/reverse.d.ts.map +1 -0
  290. package/out/{reverse.js → lookup/reverse.js} +3 -3
  291. package/out/lookup/reverse.js.map +1 -0
  292. package/out/{types.d.ts → lookup/types.d.ts} +9 -0
  293. package/out/lookup/types.d.ts.map +1 -0
  294. package/out/lookup/types.js.map +1 -0
  295. package/out/lookup.d.ts +4 -4
  296. package/out/lookup.d.ts.map +1 -1
  297. package/out/lookup.js +14 -20
  298. package/out/lookup.js.map +1 -1
  299. package/out/poi/schema.d.ts +1 -1
  300. package/out/poi/schema.d.ts.map +1 -1
  301. package/out/ranking/name-score.d.ts.map +1 -0
  302. package/out/ranking/name-score.js.map +1 -0
  303. package/out/ranking/primary-preference.d.ts.map +1 -0
  304. package/out/{primary-preference.js → ranking/primary-preference.js} +4 -0
  305. package/out/ranking/primary-preference.js.map +1 -0
  306. package/out/ranking/proximity-rerank.d.ts.map +1 -0
  307. package/out/ranking/proximity-rerank.js.map +1 -0
  308. package/out/{ranking-weights.d.ts → ranking/weights.d.ts} +1 -1
  309. package/out/ranking/weights.d.ts.map +1 -0
  310. package/out/{ranking-weights.js → ranking/weights.js} +1 -1
  311. package/out/ranking/weights.js.map +1 -0
  312. package/out/schema/importance-source.d.ts.map +1 -0
  313. package/out/schema/importance-source.js.map +1 -0
  314. package/out/schema/overture-match.d.ts +53 -0
  315. package/out/schema/overture-match.d.ts.map +1 -0
  316. package/out/schema/overture-match.js +33 -0
  317. package/out/schema/overture-match.js.map +1 -0
  318. package/out/{place-importance-schema.d.ts → schema/place-importance.d.ts} +50 -1
  319. package/out/schema/place-importance.d.ts.map +1 -0
  320. package/out/{place-importance-schema.js → schema/place-importance.js} +34 -1
  321. package/out/schema/place-importance.js.map +1 -0
  322. package/out/{polygon-schema.d.ts → schema/polygon.d.ts} +1 -1
  323. package/out/schema/polygon.d.ts.map +1 -0
  324. package/out/{polygon-schema.js → schema/polygon.js} +1 -1
  325. package/out/schema/polygon.js.map +1 -0
  326. package/out/{unified-schema.d.ts → schema/unified.d.ts} +1 -1
  327. package/out/schema/unified.d.ts.map +1 -0
  328. package/out/{unified-schema.js → schema/unified.js} +1 -1
  329. package/out/schema/unified.js.map +1 -0
  330. package/out/schema.d.ts +3 -3
  331. package/out/sqlite/convention-source.js +1 -1
  332. package/out/sqlite/convention-source.js.map +1 -1
  333. package/out/uprn/existence.d.ts.map +1 -1
  334. package/out/uprn/existence.js +2 -0
  335. package/out/uprn/existence.js.map +1 -1
  336. package/out/{weights-overlay-linker.d.ts → weights/overlay-linker.d.ts} +43 -24
  337. package/out/weights/overlay-linker.d.ts.map +1 -0
  338. package/out/{weights-overlay-linker.js → weights/overlay-linker.js} +182 -66
  339. package/out/weights/overlay-linker.js.map +1 -0
  340. package/package.json +12 -32
  341. package/lib/postal.ts +0 -6
  342. package/lib/street/locale.ts +0 -64
  343. package/lib/street.ts +0 -11
  344. package/out/candidate/extract-fold.d.ts.map +0 -1
  345. package/out/candidate/extract-fold.js.map +0 -1
  346. package/out/capital-schema.d.ts.map +0 -1
  347. package/out/capital-schema.js.map +0 -1
  348. package/out/capitals.d.ts.map +0 -1
  349. package/out/capitals.js.map +0 -1
  350. package/out/coverage-manifest-schema.d.ts.map +0 -1
  351. package/out/coverage-manifest-schema.js.map +0 -1
  352. package/out/exact-match.d.ts.map +0 -1
  353. package/out/exact-match.js.map +0 -1
  354. package/out/extracts.d.ts.map +0 -1
  355. package/out/extracts.js.map +0 -1
  356. package/out/importance-source.d.ts.map +0 -1
  357. package/out/importance-source.js.map +0 -1
  358. package/out/interpolation.d.ts.map +0 -1
  359. package/out/interpolation.js.map +0 -1
  360. package/out/name-score.d.ts.map +0 -1
  361. package/out/name-score.js.map +0 -1
  362. package/out/place-importance-schema.d.ts.map +0 -1
  363. package/out/place-importance-schema.js.map +0 -1
  364. package/out/polygon-schema.d.ts.map +0 -1
  365. package/out/polygon-schema.js.map +0 -1
  366. package/out/postal/city/alias/lookup.d.ts.map +0 -1
  367. package/out/postal/city/alias/lookup.js.map +0 -1
  368. package/out/postal/city/alias/schema.d.ts.map +0 -1
  369. package/out/postal/city/alias/schema.js.map +0 -1
  370. package/out/postal/city/candidate-schema.d.ts.map +0 -1
  371. package/out/postal/city/candidate-schema.js.map +0 -1
  372. package/out/postal.d.ts +0 -4
  373. package/out/postal.d.ts.map +0 -1
  374. package/out/postal.js +0 -6
  375. package/out/postal.js.map +0 -1
  376. package/out/postcode-point-lookup.d.ts.map +0 -1
  377. package/out/postcode-point-lookup.js.map +0 -1
  378. package/out/primary-preference.d.ts.map +0 -1
  379. package/out/primary-preference.js.map +0 -1
  380. package/out/proximity-rerank.d.ts.map +0 -1
  381. package/out/proximity-rerank.js.map +0 -1
  382. package/out/ranking-weights.d.ts.map +0 -1
  383. package/out/ranking-weights.js.map +0 -1
  384. package/out/region-keys.js.map +0 -1
  385. package/out/reverse.d.ts.map +0 -1
  386. package/out/reverse.js.map +0 -1
  387. package/out/search-fetch.d.ts.map +0 -1
  388. package/out/search-fetch.js.map +0 -1
  389. package/out/street/centroid/schema.d.ts.map +0 -1
  390. package/out/street/centroid/schema.js.map +0 -1
  391. package/out/street/centroid.d.ts.map +0 -1
  392. package/out/street/centroid.js.map +0 -1
  393. package/out/street/locale.d.ts +0 -12
  394. package/out/street/locale.d.ts.map +0 -1
  395. package/out/street/locale.js +0 -54
  396. package/out/street/locale.js.map +0 -1
  397. package/out/street/morphology/fst/builder.d.ts.map +0 -1
  398. package/out/street/morphology/fst/builder.js.map +0 -1
  399. package/out/street/morphology/fst/loader.d.ts.map +0 -1
  400. package/out/street/morphology/fst/loader.js.map +0 -1
  401. package/out/street/name-lookup.d.ts.map +0 -1
  402. package/out/street/name-lookup.js.map +0 -1
  403. package/out/street/normalize.d.ts.map +0 -1
  404. package/out/street/normalize.js.map +0 -1
  405. package/out/street/segment-schema.d.ts.map +0 -1
  406. package/out/street/segment-schema.js.map +0 -1
  407. package/out/street/table.d.ts.map +0 -1
  408. package/out/street/table.js.map +0 -1
  409. package/out/street.d.ts +0 -9
  410. package/out/street.d.ts.map +0 -1
  411. package/out/street.js +0 -11
  412. package/out/street.js.map +0 -1
  413. package/out/types.d.ts.map +0 -1
  414. package/out/types.js.map +0 -1
  415. package/out/unified-schema.d.ts.map +0 -1
  416. package/out/unified-schema.js.map +0 -1
  417. package/out/weights-overlay-linker.d.ts.map +0 -1
  418. package/out/weights-overlay-linker.js.map +0 -1
  419. /package/lib/{coverage-manifest-schema.ts → candidate/coverage-manifest.ts} +0 -0
  420. /package/lib/{postal/city → labels/locality/postal-city}/alias/schema.ts +0 -0
  421. /package/lib/{street → labels/street}/morphology/fst/builder.ts +0 -0
  422. /package/lib/{exact-match.ts → lookup/exact-match.ts} +0 -0
  423. /package/lib/{name-score.ts → ranking/name-score.ts} +0 -0
  424. /package/lib/{proximity-rerank.ts → ranking/proximity-rerank.ts} +0 -0
  425. /package/lib/{ranking-weights.ts → ranking/weights.ts} +0 -0
  426. /package/lib/{importance-source.ts → schema/importance-source.ts} +0 -0
  427. /package/lib/{polygon-schema.ts → schema/polygon.ts} +0 -0
  428. /package/lib/{unified-schema.ts → schema/unified.ts} +0 -0
  429. /package/out/{capitals.d.ts → candidate/capitals.d.ts} +0 -0
  430. /package/out/{search-fetch.js → fts/search-fetch.js} +0 -0
  431. /package/out/{postal/city → labels/locality/postal-city}/alias/lookup.js +0 -0
  432. /package/out/{postal/city → labels/locality/postal-city}/alias/schema.d.ts +0 -0
  433. /package/out/{postal/city → labels/locality/postal-city}/alias/schema.js +0 -0
  434. /package/out/{postal/city → labels/locality/postal-city}/candidate-schema.js +0 -0
  435. /package/out/{street → labels/street}/centroid/schema.js +0 -0
  436. /package/out/{street → labels/street}/morphology/fst/builder.d.ts +0 -0
  437. /package/out/{street → labels/street}/morphology/fst/builder.js +0 -0
  438. /package/out/{street → labels/street}/morphology/fst/loader.d.ts +0 -0
  439. /package/out/{street → labels/street}/name-lookup.d.ts +0 -0
  440. /package/out/{street → labels/street}/segment-schema.js +0 -0
  441. /package/out/{street → labels/street}/table.d.ts +0 -0
  442. /package/out/{exact-match.d.ts → lookup/exact-match.d.ts} +0 -0
  443. /package/out/{exact-match.js → lookup/exact-match.js} +0 -0
  444. /package/out/{extracts.d.ts → lookup/extracts.d.ts} +0 -0
  445. /package/out/{types.js → lookup/types.js} +0 -0
  446. /package/out/{name-score.d.ts → ranking/name-score.d.ts} +0 -0
  447. /package/out/{name-score.js → ranking/name-score.js} +0 -0
  448. /package/out/{primary-preference.d.ts → ranking/primary-preference.d.ts} +0 -0
  449. /package/out/{proximity-rerank.d.ts → ranking/proximity-rerank.d.ts} +0 -0
  450. /package/out/{proximity-rerank.js → ranking/proximity-rerank.js} +0 -0
  451. /package/out/{importance-source.d.ts → schema/importance-source.d.ts} +0 -0
  452. /package/out/{importance-source.js → schema/importance-source.js} +0 -0
@@ -4,26 +4,30 @@
4
4
  import { isOfficialLanguage } from "@mailwoman/codex/country"
5
5
  import { readUnquotedTSV } from "@mailwoman/core/fs/delimited"
6
6
  import { pathExists } from "@mailwoman/core/fs/readers/stat"
7
- import { GEONAMES_ID_BASE, GEONAMES_POSTAL_ID_BASE, geonamesFoldID } from "@mailwoman/core/resolver/synthetic-id-ranges"
7
+ import {
8
+ GEONAMES_ID_BASE,
9
+ GEONAMES_POSTAL_ID_BASE,
10
+ geonamesPlaceID,
11
+ } from "@mailwoman/core/resolver/synthetic-id-ranges"
8
12
  import type { DatabaseClient, StatementSync } from "@mailwoman/sqlite/client"
9
13
  import { type PathBuilderLike, resolvePathBuilder } from "path-ts"
10
14
 
11
15
  import type { WOFDatabase } from "#schema"
12
16
 
13
- const FOLD_OWNED_TABLES = ["spr", "names", "place_population", "ancestors"] as const
17
+ const GEONAMES_OWNED_TABLES = ["spr", "names", "place_population", "ancestors"] as const
14
18
 
15
19
  /**
16
- * Deletes every row the GeoNames alias fold owns, with ids in
20
+ * Deletes every row the GeoNames alias step owns, with ids in
17
21
  * `[GEONAMES_ID_BASE, GEONAMES_POSTAL_ID_BASE)`, and returns the count removed per table.
18
22
  *
19
- * Fold ids are assigned sequentially, so a re-fold without this purge would attach
20
- * stale names, ancestors and populations to other places.
23
+ * Without this purge, a rerun would keep the previous run's rows, with their names,
24
+ * ancestors and populations, beside the rows it writes.
21
25
  * The upper bound leaves the postal and postcode id ranges above it untouched.
22
26
  */
23
27
  export function purgeGeonamesAliasRange<DB>(db: DatabaseClient<DB>): Record<string, number> {
24
28
  const removed: Record<string, number> = {}
25
29
 
26
- for (const table of FOLD_OWNED_TABLES) {
30
+ for (const table of GEONAMES_OWNED_TABLES) {
27
31
  const result = db
28
32
  .prepare(`DELETE FROM ${table} WHERE id >= ? AND id < ?`)
29
33
  .run(GEONAMES_ID_BASE, GEONAMES_POSTAL_ID_BASE)
@@ -58,19 +62,19 @@ export interface GeonamesIngestProgress {
58
62
  /**
59
63
  * The number of alternate names that the alias filter rejected.
60
64
  *
61
- * It distinguishes a sparse source from aliases that the fold discarded.
65
+ * It distinguishes a sparse source from aliases that the ingest discarded.
62
66
  */
63
67
  aliasesRefused: number | null
64
68
 
65
69
  /**
66
70
  * The number of populated places that matched an existing record and added their
67
- * names to it, or null when the fold had no matcher.
71
+ * names to it, or null when the ingest had no matcher.
68
72
  */
69
73
  matched?: number | null
70
74
  }
71
75
 
72
76
  /**
73
- * Formats a GeoNames fold progress event as one log line.
77
+ * Formats a GeoNames ingest progress event as one log line.
74
78
  */
75
79
  export function formatGeonamesIngestProgress(event: GeonamesIngestProgress, missingFile?: PathBuilderLike): string {
76
80
  if (event.skipped) {
@@ -145,9 +149,9 @@ async function parseAlternateNamesV2(
145
149
  }
146
150
 
147
151
  /**
148
- * A GeoNames place the fold is about to write.
152
+ * A GeoNames place the ingest is about to write.
149
153
  */
150
- export interface GeonamesFoldPlace {
154
+ export interface GeonamesPlace {
151
155
  geonamesID: number
152
156
  name: string
153
157
  placetype: "country" | "region" | "locality"
@@ -157,47 +161,47 @@ export interface GeonamesFoldPlace {
157
161
  }
158
162
 
159
163
  /**
160
- * The record a GeoNames place matched in the database being folded into.
164
+ * The record a GeoNames place matched in the database the places are added to.
161
165
  */
162
- export interface GeonamesFoldMatch {
166
+ export interface GeonamesPlaceMatch {
163
167
  id: number
164
168
  placetype: string
165
169
  }
166
170
 
167
171
  /**
168
- * Matches GeoNames places against the records already in the database being folded into.
172
+ * Matches GeoNames places against the records already in the database the places are added to.
169
173
  */
170
- export interface GeonamesFoldMatcher {
171
- match(place: GeonamesFoldPlace): GeonamesFoldMatch | null
174
+ export interface GeonamesPlaceMatcher {
175
+ match(place: GeonamesPlace): GeonamesPlaceMatch | null
172
176
  /**
173
177
  * Answers whether the matched record lacks a name, recording it so the name is written once.
174
178
  */
175
- claimName(match: GeonamesFoldMatch, country: string, name: string): boolean
176
- onGap(place: GeonamesFoldPlace & { id: number }): void
179
+ claimName(match: GeonamesPlaceMatch, country: string, name: string): boolean
180
+ onGap(place: GeonamesPlace & { id: number }): void
177
181
  }
178
182
 
179
183
  /**
180
- * Folds one country's GeoNames `A`-class rows, its country and its ADM1 regions,
181
- * and links each region the fold wrote to the country.
184
+ * Adds one country's GeoNames `A`-class rows, its country and its ADM1 regions,
185
+ * and links each region this step wrote to the country.
182
186
  *
183
187
  * A row that matches an existing record writes no row and adds its name to that record,
184
188
  * and its id is the existing record's.
185
- * Only regions the fold wrote are re-parented, so an existing region keeps its own parent.
189
+ * Only regions this step wrote are re-parented, so an existing region keeps its own parent.
186
190
  */
187
- function foldAdminRows(
191
+ function addAdminRows(
188
192
  statements: { db: DatabaseClient<WOFDatabase>; spr: StatementSync; names: StatementSync; ancestors: StatementSync },
189
193
  input: {
190
194
  rows: readonly string[][]
191
195
  country: string
192
196
  clean: (s: string) => string | null
193
- existing: GeonamesFoldMatcher | undefined
194
- claim: (match: GeonamesFoldMatch, name: string) => void
197
+ existing: GeonamesPlaceMatcher | undefined
198
+ claim: (match: GeonamesPlaceMatch, name: string) => void
195
199
  }
196
200
  ): { countryID: number; adminMap: Map<string, number> } {
197
201
  const { rows, country: cc, clean, existing, claim } = input
198
202
  let countryID = -1
199
203
  const adminMap = new Map<string, number>()
200
- // The regions this fold wrote, as opposed to existing records a region matched.
204
+ // The regions this step wrote, as opposed to existing records a region matched.
201
205
  const writtenRegions = new Set<number>()
202
206
 
203
207
  for (const f of rows) {
@@ -206,7 +210,7 @@ function foldAdminRows(
206
210
  if (!aname) continue
207
211
  const lat = Number(f[4]) || 0
208
212
  const lon = Number(f[5]) || 0
209
- const placetype: GeonamesFoldPlace["placetype"] = f[7]?.startsWith("PCL") ? "country" : "region"
213
+ const placetype: GeonamesPlace["placetype"] = f[7]?.startsWith("PCL") ? "country" : "region"
210
214
 
211
215
  if (placetype === "country" && countryID >= 0) continue
212
216
 
@@ -219,7 +223,7 @@ function foldAdminRows(
219
223
  claim(matched, aname)
220
224
  }
221
225
 
222
- const rid = matched?.id ?? geonamesFoldID(place.geonamesID)
226
+ const rid = matched?.id ?? geonamesPlaceID(place.geonamesID)
223
227
 
224
228
  if (!matched) {
225
229
  statements.spr.run(rid, -1, aname, placetype, cc, lat, lon, lat, lon, lat, lon, 1, 0, 0, 0, 0, 0)
@@ -250,8 +254,8 @@ function foldAdminRows(
250
254
  }
251
255
 
252
256
  /**
253
- * Purges the fold's id range, then adds GeoNames `P`-class places and their
254
- * alternate names for `countries` to `db`.
257
+ * Purges the GeoNames alias id range, then adds GeoNames `P`-class places
258
+ * and their alternate names for `countries` to `db`.
255
259
  * It returns the number of places ingested.
256
260
  *
257
261
  * The caller must then rebuild `place_search` with `buildPlaceSearchFTS(db, { drop: true })`
@@ -272,7 +276,7 @@ export async function ingestGeonamesAliases(
272
276
  * A GeoNames place that matches one adds its names to that record and writes no row.
273
277
  * A place that matches none is written and reported to `onGap`.
274
278
  */
275
- existing?: GeonamesFoldMatcher
279
+ existing?: GeonamesPlaceMatcher
276
280
  }
277
281
  ): Promise<number> {
278
282
  const LATIN_NAME = /^[\p{Script=Latin}\p{M}\s\-'.]{2,60}$/u
@@ -364,14 +368,14 @@ export async function ingestGeonamesAliases(
364
368
  /**
365
369
  * Writes a place's name onto the existing record it matched, once.
366
370
  */
367
- const claim = (match: GeonamesFoldMatch, name: string, language = "", privateuse = "", official = 0) => {
371
+ const claim = (match: GeonamesPlaceMatch, name: string, language = "", privateuse = "", official = 0) => {
368
372
  if (opts?.existing?.claimName(match, cc, name)) {
369
373
  namesInsert.run(match.id, name, match.placetype, cc, language, privateuse, official, 0)
370
374
  }
371
375
  }
372
376
 
373
377
  const { countryID, adminMap } = addAdmin
374
- ? foldAdminRows(
378
+ ? addAdminRows(
375
379
  { db, spr: sprInsert, names: namesInsert, ancestors: ancestorInsert },
376
380
  { rows: adminRows, country: cc, clean, existing: opts?.existing, claim }
377
381
  )
@@ -423,7 +427,7 @@ export async function ingestGeonamesAliases(
423
427
  continue
424
428
  }
425
429
 
426
- const nid = geonamesFoldID(place.geonamesID)
430
+ const nid = geonamesPlaceID(place.geonamesID)
427
431
 
428
432
  opts?.existing?.onGap({ ...place, id: nid })
429
433
 
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
3
 
4
4
  /**
5
- * Fold GeoNames postcode rows into a WOF or unified postcode extract as first-class
5
+ * Adds GeoNames postcode rows to a WOF or unified postcode extract as first-class
6
6
  * `postalcode` places for countries whose WOF postalcode repos do not exist.
7
7
  *
8
8
  * Two laws are enforced here in code rather than in a runbook.
@@ -18,7 +18,7 @@
18
18
  * Their average puts the code somewhere no address is.
19
19
  * The medoid is the member point nearest the group's mean.
20
20
  *
21
- * `build-unified-wof --geonames-postal-countries`, standalone folds and the `mailwoman
21
+ * `build-unified-wof --geonames-postal-countries`, standalone ingests and the `mailwoman
22
22
  * gazetteer` commands share one implementation. The GeoNames postal dump is
23
23
  * `download.geonames.org/export/zip/<CC>.zip` → `<CC>.txt`, a headerless TSV of country,
24
24
  * postcode, place, admin1, code1, admin2, code2, admin3, code3, lat, lon and accuracy.
@@ -209,7 +209,7 @@ export interface GeonamesPostalIngestResult {
209
209
  }
210
210
 
211
211
  /**
212
- * Fold GeoNames postcodes for `countries` into an open unified/postcode ingest DB: one `spr` row
212
+ * Add GeoNames postcodes for `countries` to an open unified/postcode ingest DB: one `spr` row
213
213
  * per distinct normalized postcode (placetype `postalcode`, medoid centroid, degenerate bbox),
214
214
  * the normalized form as `name`, and the display form as an extra `names` row when it differs.
215
215
  *
package/lib/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
2
  // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
3
 
4
- export type { FindPlaceQuery, PlaceCandidate, PlaceLookup, WOFPlacetype } from "#types"
4
+ export type { FindPlaceQuery, PlaceCandidate, PlaceLookup, WOFPlacetype } from "#lookup/types"
5
5
 
6
6
  export type {
7
7
  AncestorsTable,
@@ -16,7 +16,7 @@ export type {
16
16
  } from "#schema"
17
17
 
18
18
  export { WOFSQLitePlaceLookup, type WOFSQLitePlaceLookupOpts } from "#lookup"
19
- export { type RankingWeights } from "#ranking-weights"
19
+ export { type RankingWeights } from "#ranking/weights"
20
20
 
21
21
  export {
22
22
  CANDIDATE_ANCESTOR_COLUMNS,
@@ -53,10 +53,10 @@ export {
53
53
  createCountryCoverageTable,
54
54
  readGazetteerCoverageManifest,
55
55
  writeGazetteerCoverageManifest,
56
- } from "#coverage-manifest-schema"
56
+ } from "#candidate/coverage-manifest"
57
57
 
58
- export type { CountryBBoxTable, CountryCoverageTable, GazetteerCoverageDatabase } from "#coverage-manifest-schema"
59
- export { SQLiteStreetNameLookup, type SQLiteStreetNameLookupOpts } from "#street/name-lookup"
58
+ export type { CountryBBoxTable, CountryCoverageTable, GazetteerCoverageDatabase } from "#candidate/coverage-manifest"
59
+ export { SQLiteStreetNameLookup, type SQLiteStreetNameLookupOpts } from "#labels/street/name-lookup"
60
60
 
61
61
  export { type GeonamesIngestProgress, ingestGeonamesAliases, purgeGeonamesAliasRange } from "#geonames/aliases"
62
62
 
@@ -67,17 +67,20 @@ export {
67
67
  WOFPostalCityAliasLookup,
68
68
  type PostalCityAlias,
69
69
  type WOFPostalCityAliasLookupOpts,
70
- } from "#postal/city/alias/lookup"
70
+ } from "#labels/locality/postal-city/alias/lookup"
71
71
 
72
- export type { PostalCityAliasDatabase, PostalCityAliasTable } from "#postal/city/alias/schema"
72
+ export type { PostalCityAliasDatabase, PostalCityAliasTable } from "#labels/locality/postal-city/alias/schema"
73
73
 
74
74
  export {
75
75
  POSTAL_CITY_CANDIDATE_COLUMNS,
76
76
  POSTAL_CITY_CANDIDATE_TABLE,
77
77
  createPostalCityCandidateTable,
78
- } from "#postal/city/candidate-schema"
78
+ } from "#labels/locality/postal-city/candidate-schema"
79
79
 
80
- export type { PostalCityCandidateDatabase, PostalCityCandidateTable } from "#postal/city/candidate-schema"
80
+ export type {
81
+ PostalCityCandidateDatabase,
82
+ PostalCityCandidateTable,
83
+ } from "#labels/locality/postal-city/candidate-schema"
81
84
 
82
85
  export {
83
86
  ADDRESS_CONVENTION_TABLE,
@@ -95,7 +98,7 @@ export {
95
98
 
96
99
  export { SqliteConventionSource } from "#sqlite/convention-source"
97
100
 
98
- export { WOFPostcodeLookup } from "#postcode-point-lookup"
101
+ export { WOFPostcodeLookup } from "#lookup/postcode-point"
99
102
 
100
103
  export {
101
104
  PLACE_BBOX_TABLE,
@@ -115,28 +118,28 @@ export {
115
118
  type ReverseGeocodeOpts,
116
119
  type ReverseGeocodeResult,
117
120
  type WOFReverseGeocoderOpts,
118
- } from "#reverse"
121
+ } from "#lookup/reverse"
119
122
 
120
123
  export { AddressPointInterpolator } from "#address/point/interpolation"
121
124
  export { AddressPointSqliteLookup } from "#address/point"
122
125
  export { openAddressLayerLookup } from "#address/keys/open"
123
- export { readLatestAddressLayerManifest } from "#address/keys/layout"
126
+ export { readLatestAddressLayerManifest, readLatestAddressLayerManifests } from "#address/keys/layout"
124
127
 
125
128
  export {
126
129
  STREET_CENTROID_COLUMNS,
127
130
  createStreetCentroidIndexes,
128
131
  createStreetCentroidTable,
129
- } from "#street/centroid/schema"
132
+ } from "#labels/street/centroid/schema"
130
133
 
131
- export type { StreetCentroidDatabase, StreetCentroidTable } from "#street/centroid/schema"
132
- export { StreetCentroidSqliteLookup } from "#street/centroid"
134
+ export type { StreetCentroidDatabase, StreetCentroidTable } from "#labels/street/centroid/schema"
135
+ export { StreetCentroidSqliteLookup } from "#labels/street/centroid"
133
136
 
134
137
  export {
135
138
  StreetInterpolator,
136
139
  type InterpolatedHit,
137
140
  type InterpolationMethod,
138
141
  type InterpolationQuery,
139
- } from "#interpolation"
142
+ } from "#labels/street/interpolation"
140
143
 
141
144
  export {
142
145
  deriveSchemaName,
@@ -144,4 +147,4 @@ export {
144
147
  resolveExtracts,
145
148
  type ResolvedExtract,
146
149
  type ExtractConfig,
147
- } from "#extracts"
150
+ } from "#lookup/extracts"
@@ -19,7 +19,7 @@
19
19
 
20
20
  import { SQLiteLookup, type SQLiteLookupOptions } from "@mailwoman/sqlite/lookup"
21
21
 
22
- import type { PostalCityAliasDatabase } from "#postal/city/alias/schema"
22
+ import type { PostalCityAliasDatabase } from "#labels/locality/postal-city/alias/schema"
23
23
 
24
24
  /**
25
25
  * Where a {@link WOFPostalCityAliasLookup} reads from: a `postal-city-alias-<cc>.db` built by
@@ -22,7 +22,7 @@
22
22
 
23
23
  import { sql, type Kysely } from "kysely"
24
24
 
25
- import type { NameKey } from "#street/normalize"
25
+ import type { NameKey } from "#labels/street/normalize"
26
26
 
27
27
  /**
28
28
  * One postal-city → geo-locality edge, keyed exactly by `(name_key, postcode)`.
@@ -0,0 +1,6 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ export * from "#labels/locality/postal-city/alias/lookup"
5
+ export * from "#labels/locality/postal-city/alias/schema"
6
+ export * from "#labels/locality/postal-city/candidate-schema"
@@ -2,9 +2,12 @@
2
2
  // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
3
 
4
4
  /**
5
+ * The keys a parsed region qualifier is compared under: its own key,
6
+ * its subdivision's names and its county-prefix variants.
7
+ *
5
8
  * Both consumers use this expansion to compare parsed region qualifiers with stored keys.
6
9
  *
7
- * Admin-coherence verdicts (`mailwoman/admin-coherence.ts`) fold a qualifier
10
+ * Admin-coherence verdicts (`mailwoman/geocode/result/admin-coherence.ts`) fold a qualifier
8
11
  * and the winner's ancestry to decide `confirmed` or `contradicted`.
9
12
  * The candidate backend's admin-containment re-rank (`candidate-lookup.ts`)
10
13
  * uses the same fold to find region-class rows.
@@ -17,7 +20,7 @@
17
20
 
18
21
  import { matchSubdivision, matchSubdivisionIn } from "@mailwoman/codex/country"
19
22
 
20
- import { normalizeLocalityForKey } from "#street/normalize"
23
+ import { normalizeLocalityForKey } from "#labels/street/normalize"
21
24
 
22
25
  /**
23
26
  * The ancestry placetypes that answer for a parsed `region` qualifier,
@@ -8,7 +8,7 @@
8
8
 
9
9
  import type { Kysely } from "kysely"
10
10
 
11
- import type { NameKey, StreetKey } from "#street/normalize"
11
+ import type { NameKey, StreetKey } from "#labels/street/normalize"
12
12
 
13
13
  /**
14
14
  * One row per street, postcode and commune.
@@ -10,8 +10,7 @@ import { haversine } from "@mailwoman/spatial/geometries/point/distance"
10
10
  import { DatabaseClient } from "@mailwoman/sqlite/client"
11
11
  import type { PathBuilderLike } from "path-ts"
12
12
 
13
- import { hasTable, prepareGet, type PreparedGet } from "#sqlite-utils"
14
- import type { StreetCentroidDatabase } from "#street/centroid/schema"
13
+ import type { StreetCentroidDatabase } from "#labels/street/centroid/schema"
15
14
  import {
16
15
  normalizeLocalityForKey,
17
16
  normalizeStreetForKeyLocale,
@@ -20,7 +19,8 @@ import {
20
19
  streetLocaleForSurface,
21
20
  type StreetLocale,
22
21
  stripArrondissement,
23
- } from "#street/normalize"
22
+ } from "#labels/street/normalize"
23
+ import { hasTable, prepareGet, type PreparedGet } from "#sqlite-utils"
24
24
 
25
25
  /**
26
26
  * The weighted centroid, extent and provenance an aggregate probe returns;
@@ -65,12 +65,12 @@ export class StreetCentroidSqliteLookup implements StreetCentroidLookup {
65
65
  readonly #byLocality: PreparedGet<[locality: NameKey, street: StreetKey], AggRow> | undefined
66
66
 
67
67
  /**
68
- * The extract defaults to the `fr` street-normalization locale.
69
- * A mismatch with the extract's locale makes every key miss.
68
+ * @param opts.streetLocale The street locale the extract was built under.
69
+ * A mismatch makes every key miss.
70
70
  */
71
- constructor(dbPath: PathBuilderLike, opts: { streetLocale?: StreetLocale } = {}) {
71
+ constructor(dbPath: PathBuilderLike, opts: { streetLocale: StreetLocale }) {
72
72
  this.#db = new DatabaseClient<StreetCentroidDatabase>(dbPath, { readOnly: true })
73
- this.#locale = opts.streetLocale ?? "fr"
73
+ this.#locale = opts.streetLocale
74
74
 
75
75
  // An extract without a `street_centroid` table makes every lookup miss.
76
76
  if (hasTable(this.#db, "street_centroid")) {
@@ -7,15 +7,23 @@
7
7
  * and linear interpolation along the segment polyline.
8
8
  */
9
9
 
10
- import { parseJSONStrict } from "@mailwoman/core/json"
11
10
  import type { InterpolationLookup } from "@mailwoman/core/resolver"
11
+ import { parseJSONStrict } from "@mailwoman/core/values/json"
12
12
  import { haversine } from "@mailwoman/spatial/geometries/point/distance"
13
13
  import { clampFraction, pointAlong } from "@mailwoman/spatial/polyline"
14
14
  import { DatabaseClient } from "@mailwoman/sqlite/client"
15
15
 
16
+ import { streetLocaleForCountry } from "#labels/street/locale"
17
+ import { canonicalizeRouteKey, type RouteKey, streetKeyVariants } from "#labels/street/normalize"
18
+ import type { StreetSegmentDatabase } from "#labels/street/segment-schema"
16
19
  import { hasTable, prepareAll, type PreparedAll } from "#sqlite-utils"
17
- import { canonicalizeRouteKey, type RouteKey, streetKeyVariants } from "#street/normalize"
18
- import type { StreetSegmentDatabase } from "#street/segment-schema"
20
+
21
+ // country-branch: the segment databases are built from TIGER, the United States' street network.
22
+ // A street locale passed by the provider that opens a database would replace the constant.
23
+ /**
24
+ * The street locale the segment databases' keys are built under.
25
+ */
26
+ const SEGMENT_STREET_LOCALE = streetLocaleForCountry("US")
19
27
 
20
28
  /**
21
29
  * How an interpolated answer was computed, `address_point` for bracketed neighbor points
@@ -208,7 +216,7 @@ export class StreetInterpolator<
208
216
  const n = Number(numberRaw)
209
217
 
210
218
  // A variant advances the ladder when it produces no answer rather than merely no rows.
211
- for (const variant of streetKeyVariants(query.street)) {
219
+ for (const variant of streetKeyVariants(query.street, SEGMENT_STREET_LOCALE)) {
212
220
  const streetNorm = canonicalizeRouteKey(variant)
213
221
 
214
222
  // A ZIP that scopes to no candidate is a miss rather than a statewide guess.
@@ -0,0 +1,117 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * The street locale every country's address keys are folded under, for builders and readers alike.
6
+ */
7
+
8
+ import { OFFICIAL_LANGUAGES } from "@mailwoman/codex/country/official-languages"
9
+
10
+ import { parseStreetLocale, type StreetLocale } from "#labels/street/normalize"
11
+
12
+ /**
13
+ * A table from a language or country code to the street locale each row spells.
14
+ *
15
+ * A row that spells no street locale stops the module from loading.
16
+ */
17
+ function streetLocaleTable(
18
+ rows: ReadonlyArray<readonly [code: string, spelling: string]>
19
+ ): ReadonlyMap<string, StreetLocale> {
20
+ return new Map(rows.map(([code, spelling]) => [code, parseStreetLocale(spelling)]))
21
+ }
22
+
23
+ /**
24
+ * The locale whose rules fold streets written in each language, keyed by the two-letter
25
+ * ISO 639-1 code `OFFICIAL_LANGUAGES` lists first among a language's spellings.
26
+ */
27
+ const STREET_LOCALE_BY_LANGUAGE = streetLocaleTable([
28
+ ["en", "en"],
29
+ ["es", "es"],
30
+ ["fr", "fr"],
31
+ ["de", "de"],
32
+ ["it", "it"],
33
+ ["nl", "nl"],
34
+ ["pl", "pl"],
35
+ ["vi", "vn"],
36
+ ["id", "id"],
37
+ ["zh", "zh"],
38
+ ])
39
+
40
+ /**
41
+ * The locale of a country whose official languages select no one row of rules.
42
+ */
43
+ const UNDETERMINED_STREET_LOCALE = parseStreetLocale("und")
44
+
45
+ /**
46
+ * Countries whose built address databases fold under a locale their official languages don't select.
47
+ *
48
+ * Each row records how that country's databases were keyed, since a built database records no street locale.
49
+ *
50
+ * Canada's official languages span two locales.
51
+ * Its OSM extract folds under `en`, and `streetLocaleForSurface` routes a street
52
+ * that opens with a French type word to `fr`.
53
+ *
54
+ * The United States' state databases and address layer fold under `us`.
55
+ * Their builders key every street under the English fold, so the reader leaves a
56
+ * street such as `Promenade Blvd` to that fold too.
57
+ */
58
+ const STREET_LOCALE_EXCEPTIONS = streetLocaleTable([
59
+ ["CA", "en"],
60
+ ["US", "us"],
61
+ ])
62
+
63
+ /**
64
+ * The locale a country's streets fold under: its exception when it has one, else the one locale
65
+ * its official languages have rules in, else `und`, the shared fold with no language's abbreviations.
66
+ *
67
+ * The answer covers every ISO 3166-1 country, so a builder and a reader that
68
+ * both call this fold one street to one key.
69
+ * It is the one place a country is mapped to a street locale: every builder,
70
+ * reader and artifact manifest reads it.
71
+ *
72
+ * A country whose official languages span several locales folds under `und`
73
+ * until its built databases name one in {@link STREET_LOCALE_EXCEPTIONS}.
74
+ */
75
+ export function streetLocaleForCountry(countryCode: string): StreetLocale {
76
+ const country = countryCode.trim().toUpperCase()
77
+ const exception = STREET_LOCALE_EXCEPTIONS.get(country)
78
+
79
+ if (exception) return exception
80
+
81
+ const locales = new Set<StreetLocale>()
82
+
83
+ for (const language of OFFICIAL_LANGUAGES[country]?.official ?? []) {
84
+ const locale = STREET_LOCALE_BY_LANGUAGE.get(language)
85
+
86
+ if (locale) {
87
+ locales.add(locale)
88
+ }
89
+ }
90
+
91
+ return locales.size === 1 ? [...locales][0]! : UNDETERMINED_STREET_LOCALE
92
+ }
93
+
94
+ /**
95
+ * Creates the street-locale lookup for one source's built databases.
96
+ *
97
+ * `localeFor` answers {@link streetLocaleForCountry} for a country in `countries`
98
+ * and throws for any other, since that source has built no database there to key a query for.
99
+ * Every source therefore keys a country's streets under one locale.
100
+ */
101
+ export function createStreetLocaleRegistry(
102
+ countries: readonly string[],
103
+ label: string
104
+ ): { localeFor: (countryCode: string) => StreetLocale; supported: () => string[] } {
105
+ const built = new Set(countries.map((country) => country.toLowerCase()))
106
+
107
+ return {
108
+ localeFor: (countryCode) => {
109
+ if (!built.has(countryCode.toLowerCase())) {
110
+ throw new Error(`No database is registered for country "${countryCode}". ${label}`)
111
+ }
112
+
113
+ return streetLocaleForCountry(countryCode)
114
+ },
115
+ supported: () => [...built],
116
+ }
117
+ }
@@ -29,8 +29,8 @@ import type { PathBuilder, PathBuilderLike } from "path-ts"
29
29
  import type { FSTMatcher } from "#fst/matcher"
30
30
  import { deserializeFST, readFSTProvenance } from "#fst/serialize"
31
31
  import type { FSTProvenance } from "#fst/types"
32
+ import { buildStreetMorphologyFST } from "#labels/street/morphology/fst/builder"
32
33
  import { wofDatabasePath } from "#paths"
33
- import { buildStreetMorphologyFST } from "#street/morphology/fst/builder"
34
34
 
35
35
  /**
36
36
  * The sealed artifact's canonical filename, identical in the data-root staging dir
@@ -55,6 +55,8 @@ export class SQLiteStreetNameLookup extends SQLiteLookup<WOFDatabase> implements
55
55
 
56
56
  constructor(dbPath: PathBuilderLike, opts: SQLiteStreetNameLookupOpts = {}) {
57
57
  super({ databasePath: dbPath })
58
+ // country-branch: the default instance is the BAN street-centroid extract, a table of French streets.
59
+ // The countries recorded in the extract's manifest would replace the default.
58
60
  this.countries = new Set([...(opts.countries ?? ["FR"])].map((c) => c.toUpperCase()))
59
61
  const table = opts.table ?? "street_centroid"
60
62