@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
@@ -8,7 +8,7 @@
8
8
 
9
9
  import { haversine } from "@mailwoman/spatial/geometries/point/distance"
10
10
 
11
- import { normalizeLocalityForKey } from "#street/normalize"
11
+ import { normalizeLocalityForKey } from "#labels/street/normalize"
12
12
 
13
13
  /**
14
14
  * The farthest apart two records' points may lie, in kilometers, while their localities disagree.
@@ -13,6 +13,11 @@ import { dirname, resolvePathBuilder, type PathBuilder, type PathBuilderLike } f
13
13
  import { addressLayerFiles } from "#address/keys/layout"
14
14
  import type { AddressDetailDatabase, AddressLookupDatabase } from "#address/keys/schema"
15
15
 
16
+ /**
17
+ * The name of the ledger file beside each region's `lookup.db`.
18
+ */
19
+ export const ADDRESS_LAYER_ATTRIBUTION_FILE = "ATTRIBUTION.json"
20
+
16
21
  /**
17
22
  * One source and authority of a region's rows, with the terms the source records.
18
23
  */
@@ -111,7 +116,7 @@ export async function writeAddressLayerAttribution(
111
116
  })
112
117
  .toSorted((left, right) => right.records - left.records)
113
118
 
114
- const path = resolvePathBuilder(dirname(files.lookup), "ATTRIBUTION.json")
119
+ const path = resolvePathBuilder(dirname(files.lookup), ADDRESS_LAYER_ATTRIBUTION_FILE)
115
120
 
116
121
  await writeLocalJSONFile(entries, path)
117
122
 
@@ -12,10 +12,10 @@
12
12
  import { ByteFormatter } from "@mailwoman/core/fs/formatters"
13
13
  import { readFilesystemSpace, statPath } from "@mailwoman/core/fs/readers/stat"
14
14
  import { makeDirectories, removePathIfPresent } from "@mailwoman/core/fs/writers"
15
- import { parseJSONStrict, stringifyJSON } from "@mailwoman/core/json"
16
15
  import { sourcePresentCoverageCells } from "@mailwoman/core/layers"
17
16
  import { type LayerManifest, writeLayerCoverage, writeLayerManifest } from "@mailwoman/core/layers/manifest"
18
17
  import { createLayerCoverageTable, createLayerManifestTable } from "@mailwoman/core/layers/schema"
18
+ import { parseJSONStrict, stringifyJSON } from "@mailwoman/core/values/json"
19
19
  import { shortCellToInt } from "@mailwoman/spatial"
20
20
  import { DatabaseClient } from "@mailwoman/sqlite/client"
21
21
  import { buildSealedArtifact } from "@mailwoman/sqlite/sealed/build"
@@ -10,10 +10,10 @@
10
10
  * so code holds no list of countries or subdivisions.
11
11
  */
12
12
 
13
+ import { type RecordedFile, sha256File } from "@mailwoman/core/crypto/hash"
13
14
  import { readLocalJSONFile, sortedGlob } from "@mailwoman/core/fs/readers"
14
15
  import { pathExists, statPath } from "@mailwoman/core/fs/readers/stat"
15
16
  import { writeLocalJSONFile } from "@mailwoman/core/fs/writers"
16
- import { type RecordedFile, sha256File } from "@mailwoman/core/hash"
17
17
  import { relative, resolvePathBuilder, type PathBuilder, type PathBuilderLike } from "path-ts"
18
18
 
19
19
  /**
@@ -151,6 +151,32 @@ export async function readLatestAddressLayerManifest(
151
151
  return newest ? readLocalJSONFile<AddressLayerCountryManifest>(newest) : null
152
152
  }
153
153
 
154
+ /**
155
+ * The newest manifest of every country that has an address layer under `root`, ordered by country.
156
+ *
157
+ * A root with no `addresses` directory, or with zero manifests in it, answers an empty list.
158
+ * A reader therefore learns which countries have a layer by reading the root, and holds no list of them.
159
+ *
160
+ * @throws When a manifest exists and can't be read.
161
+ */
162
+ export async function readLatestAddressLayerManifests(root: PathBuilderLike): Promise<AddressLayerCountryManifest[]> {
163
+ const layerDir = resolvePathBuilder(root, "addresses")
164
+
165
+ if (!(await pathExists(layerDir))) return []
166
+
167
+ // A manifest sits at `<country>/<version>/manifest.json`.
168
+ // Versions are ISO dates, so within one country's directory the last path is the newest.
169
+ const paths = await sortedGlob(layerDir, "*/*/manifest.json")
170
+ const manifests = await Promise.all(paths.map((path) => readLocalJSONFile<AddressLayerCountryManifest>(path)))
171
+ const newest = new Map<string, AddressLayerCountryManifest>()
172
+
173
+ for (const manifest of manifests) {
174
+ newest.set(manifest.country.toUpperCase(), manifest)
175
+ }
176
+
177
+ return [...newest.values()].toSorted((left, right) => left.country.localeCompare(right.country))
178
+ }
179
+
154
180
  /**
155
181
  * Writes a country's manifest beside its files, after every region it lists is built.
156
182
  */
@@ -12,14 +12,14 @@
12
12
 
13
13
  import { addressPostcodeKey } from "#address/keys/postcode"
14
14
  import { houseNumberForms } from "#address/number-forms"
15
- import { streetLocaleForCountry } from "#street/locale"
15
+ import { streetLocaleForCountry } from "#labels/street/locale"
16
16
  import {
17
17
  normalizeHouseNumberForKey,
18
18
  normalizeLocalityForKey,
19
19
  type StreetLocale,
20
20
  streetKeyVariants,
21
21
  streetLocaleForSurface,
22
- } from "#street/normalize"
22
+ } from "#labels/street/normalize"
23
23
 
24
24
  /**
25
25
  * The one capability the reader needs from a database: run a parameterized `SELECT` and return its rows.
@@ -6,9 +6,9 @@
6
6
  * `lookup.db` through `AddressKeyLookup`.
7
7
  */
8
8
 
9
- import { parseJSONStrict } from "@mailwoman/core/json"
10
- import { memoizeResettable } from "@mailwoman/core/memoize"
9
+ import { memoizeResettable } from "@mailwoman/core/async/memoize"
11
10
  import type { AddressPointHit, AddressPointLookup } from "@mailwoman/core/resolver"
11
+ import { parseJSONStrict } from "@mailwoman/core/values/json"
12
12
  import { type LatLonBounds, latLonBoundsContain } from "@mailwoman/spatial/bbox"
13
13
 
14
14
  import {
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { isJoinedHouseNumber } from "@mailwoman/match/address-point"
5
5
 
6
- import type { StreetLocale } from "#street/normalize"
6
+ import { streetKeyRulesOf, type StreetLocale } from "#labels/street/normalize"
7
7
 
8
8
  /**
9
9
  * The forms a normalized house number is probed under, the written form first,
@@ -51,11 +51,9 @@ export function* houseNumberForms(number: string, locale: StreetLocale): Generat
51
51
  yield spaced[1]!
52
52
  }
53
53
 
54
- if (locale === "zh") {
55
- const base = /^(\d+)(?:[之附]\d+)+$/u.exec(number)?.[1]
54
+ const base = streetKeyRulesOf(locale).houseNumberBase?.exec(number)?.[1]
56
55
 
57
- if (base) {
58
- yield base
59
- }
56
+ if (base) {
57
+ yield base
60
58
  }
61
59
  }
@@ -39,9 +39,17 @@ import { haversine } from "@mailwoman/spatial/geometries/point/distance"
39
39
  import { DatabaseClient } from "@mailwoman/sqlite/client"
40
40
 
41
41
  import type { AddressPointDatabase } from "#address/point/schema"
42
- import type { InterpolatedHit, InterpolationQuery, StreetInterpolator } from "#interpolation"
42
+ import type { InterpolatedHit, InterpolationQuery, StreetInterpolator } from "#labels/street/interpolation"
43
+ import { streetLocaleForCountry } from "#labels/street/locale"
44
+ import { canonicalizeRouteKey, type RouteKey, streetKeyVariants } from "#labels/street/normalize"
43
45
  import { hasTable, prepareAll, type PreparedAll } from "#sqlite-utils"
44
- import { canonicalizeRouteKey, type RouteKey, streetKeyVariants } from "#street/normalize"
46
+
47
+ // country-branch: this reader is opened over the United States' state extracts only.
48
+ // A street locale passed by the provider that opens an extract would replace the constant.
49
+ /**
50
+ * The street locale the extracts this reader interpolates over are keyed under.
51
+ */
52
+ const EXTRACT_STREET_LOCALE = streetLocaleForCountry("US")
45
53
  /**
46
54
  * Extrapolation cap for a single-sided bracket: at most one pair-span beyond
47
55
  * the nearest known point (`t = 2`).
@@ -125,7 +133,7 @@ export class AddressPointInterpolator<
125
133
  // Key-variant ladder (see `streetKeyVariants`), the same probe order as the exact-point reader.
126
134
  let rows: PointRow[] = []
127
135
 
128
- for (const variant of streetKeyVariants(query.street)) {
136
+ for (const variant of streetKeyVariants(query.street, EXTRACT_STREET_LOCALE)) {
129
137
  const streetKey = canonicalizeRouteKey(variant)
130
138
 
131
139
  rows = this.#byPostcode(query.postcode.trim(), streetKey, n)
@@ -3,7 +3,7 @@
3
3
 
4
4
  import type { Kysely } from "kysely"
5
5
 
6
- import type { NameKey, RouteKey, StreetKey } from "#street/normalize"
6
+ import type { NameKey, RouteKey, StreetKey } from "#labels/street/normalize"
7
7
 
8
8
  /**
9
9
  * One rooftop address point; `(street_norm, number)` within a `postcode`
@@ -13,18 +13,18 @@ import type { PathBuilderLike } from "path-ts"
13
13
 
14
14
  import { houseNumberForms } from "#address/number-forms"
15
15
  import type { AddressPointDatabase, AddressPointTable } from "#address/point/schema"
16
- import { hasTable, prepareGet, type PreparedGet } from "#sqlite-utils"
17
16
  import {
18
17
  normalizeHouseNumberForKey,
19
- normalizeLocalityForKey,
20
- normalizeLocalityForKeyLocale,
21
18
  type NameKey,
22
19
  type StreetKey,
20
+ type StreetKeyRules,
21
+ streetKeyRulesOf,
23
22
  streetKeyVariants,
24
23
  streetLocaleForSurface,
25
24
  stripArrondissement,
26
25
  type StreetLocale,
27
- } from "#street/normalize"
26
+ } from "#labels/street/normalize"
27
+ import { hasTable, prepareGet, type PreparedGet } from "#sqlite-utils"
28
28
 
29
29
  /**
30
30
  * The columns this lookup reads, typed from the shared {@link AddressPointTable}
@@ -54,6 +54,7 @@ export class AddressPointSqliteLookup<DB extends AddressPointDatabase = AddressP
54
54
  {
55
55
  readonly #db: DatabaseClient<DB>
56
56
  readonly #locale: StreetLocale
57
+ readonly #rules: StreetKeyRules
57
58
  readonly #localityKeys: "full" | "abbreviated"
58
59
  readonly #localityLevel: "place" | "finest"
59
60
  readonly #byPostcode: PreparedGet<[postcode: string, street: StreetKey, number: string], AddressPointRow> | undefined
@@ -101,21 +102,21 @@ export class AddressPointSqliteLookup<DB extends AddressPointDatabase = AddressP
101
102
  * The OSM builder stores `addr:suburb` before `addr:city`, so
102
103
  * `Teschener Weg 5, 14163 Berlin` is stored under `zehlendorf`.
103
104
  *
104
- * @defaultValue `"us"`
105
- * @defaultValue `"abbreviated"` for `"us"` and `"full"` for every other locale.
105
+ * @defaultValue The locale's own `localityKeys` rule.
106
106
  * @defaultValue `"place"`
107
107
  */
108
108
  constructor(
109
109
  dbPath: PathBuilderLike,
110
110
  opts: {
111
- streetLocale?: StreetLocale
111
+ streetLocale: StreetLocale
112
112
  localityKeys?: "full" | "abbreviated"
113
113
  localityLevel?: "place" | "finest"
114
- } = {}
114
+ }
115
115
  ) {
116
116
  this.#db = new DatabaseClient<DB>(dbPath, { readOnly: true })
117
- this.#locale = opts.streetLocale ?? "us"
118
- this.#localityKeys = opts.localityKeys ?? (this.#locale === "us" ? "abbreviated" : "full")
117
+ this.#locale = opts.streetLocale
118
+ this.#rules = streetKeyRulesOf(opts.streetLocale)
119
+ this.#localityKeys = opts.localityKeys ?? this.#rules.localityKeys
119
120
  this.#localityLevel = opts.localityLevel ?? "place"
120
121
 
121
122
  // An extract without an `address_point` table, such as an interrupted build, makes every lookup miss.
@@ -179,10 +180,10 @@ export class AddressPointSqliteLookup<DB extends AddressPointDatabase = AddressP
179
180
  // The Taiwanese register has no postcode, so this pair becomes the locality key.
180
181
  // A query with only the 鄉鎮市區 matches the stored key by its suffix.
181
182
  const scoped =
182
- this.#locale === "zh" && !query.locality && query.subregion
183
+ this.#rules.localityFromRegionAndSubregion && !query.locality && query.subregion
183
184
  ? query.region
184
185
  ? { ...query, locality: `${query.region}${query.subregion}` }
185
- : { ...query, localityTail: normalizeLocalityForKeyLocale(query.subregion, "zh") }
186
+ : { ...query, localityTail: this.#rules.localityKey(query.subregion) }
186
187
  : query
187
188
 
188
189
  // `streetKeyVariants` yields the literal key first.
@@ -301,9 +302,9 @@ export class AddressPointSqliteLookup<DB extends AddressPointDatabase = AddressP
301
302
  * and "Paris" produce the same key.
302
303
  */
303
304
  #localityKey(locality: string): NameKey {
304
- if (this.#locale === "fr") return stripArrondissement(normalizeLocalityForKey(locality))
305
+ const key = this.#rules.localityKey(locality)
305
306
 
306
- return normalizeLocalityForKeyLocale(locality, this.#locale)
307
+ return this.#rules.arrondissementAtBaseCity ? stripArrondissement(key) : key
307
308
  }
308
309
 
309
310
  /**
@@ -7,7 +7,7 @@
7
7
 
8
8
  import type { ADMIN_HIERARCHY_TAGS } from "@mailwoman/codex/component"
9
9
 
10
- import { type NameKey, normalizeLocalityForKey, type RouteKey, type StreetKey } from "#street/normalize"
10
+ import { type NameKey, normalizeLocalityForKey, type RouteKey, type StreetKey } from "#labels/street/normalize"
11
11
 
12
12
  /**
13
13
  * The hierarchy level a place name on an address record states, as the encoder model tags it.
@@ -5,7 +5,8 @@ import { COUNTRY_POPULATION } from "@mailwoman/codex/country"
5
5
  import { bareAdminName } from "@mailwoman/codex/country/bare-admin-names"
6
6
  import { pathExists } from "@mailwoman/core/fs/readers/stat"
7
7
  import { removePath } from "@mailwoman/core/fs/writers"
8
- import { stringifyJSON } from "@mailwoman/core/json"
8
+ import { isOverturePartID } from "@mailwoman/core/resolver/synthetic-id-ranges"
9
+ import { stringifyJSON } from "@mailwoman/core/values/json"
9
10
  import { DatabaseClient } from "@mailwoman/sqlite/client"
10
11
  import type { PathBuilderLike } from "path-ts"
11
12
 
@@ -13,24 +14,27 @@ import { POPULATION_CORRECTIONS } from "#build/population-corrections"
13
14
  import { explodeAliasBags } from "#candidate/alias-bags"
14
15
  import { buildAncestorsSidecar } from "#candidate/ancestors/sidecar"
15
16
  import { stageBareAdminNames } from "#candidate/bare-admin-names"
17
+ import { createCapitalTable } from "#candidate/capital-schema"
18
+ import type { CapitalPoint } from "#candidate/capitals"
16
19
  import { stageCountryDisplayNames } from "#candidate/country-display-names"
17
- import { foldExtract } from "#candidate/extract-fold"
20
+ import { stageExtractRows } from "#candidate/extract-rows"
18
21
  import { createCandidateFTS } from "#candidate/fts"
19
22
  import { IMPORTANCE_JOIN_RADIUS_KM, loadImportanceIndex } from "#candidate/importance"
20
23
  import { applyCandidateKeyFold, type CandidateKeyFold } from "#candidate/key-fold"
21
24
  import { GLOSS_KEY_THRESHOLD, stampNameRoles } from "#candidate/name-roles"
22
25
  import { refuseNicknamesOfNamesakes } from "#candidate/nickname-namesakes"
26
+ import { stageOvertureTwins } from "#candidate/overture-twins"
23
27
  import type { PlaceAttrs } from "#candidate/place-attrs"
24
28
  import {
25
29
  CANDIDATE_COLUMNS,
30
+ createCandidatePostcodePlaceIndex,
26
31
  createCandidateStagingTables,
27
32
  createCandidateTable,
28
33
  type CandidateDatabase,
34
+ POSTCODE_PLACETYPE,
29
35
  } from "#candidate/schema"
30
- import { createCapitalTable } from "#capital-schema"
31
- import type { CapitalPoint } from "#capitals"
36
+ import { normalizeLocalityForKey } from "#labels/street/normalize"
32
37
  import type { WOFDatabase } from "#schema"
33
- import { normalizeLocalityForKey } from "#street/normalize"
34
38
 
35
39
  /**
36
40
  * Options for {@link buildCandidateTable}.
@@ -85,6 +89,18 @@ export interface BuildCandidateOptions {
85
89
  */
86
90
  importance?: PathBuilderLike
87
91
 
92
+ /**
93
+ * Rank each place with no population by the importance database's
94
+ * `place_population_estimate`, when it has an estimate there.
95
+ *
96
+ * The estimate sets `neg_rank` only; `population` stays NULL, because no source measured it.
97
+ *
98
+ * Requires {@link BuildCandidateOptions.importance}, built with sub-locality estimates.
99
+ *
100
+ * @defaultValue false
101
+ */
102
+ populationEstimates?: boolean
103
+
88
104
  /**
89
105
  * Receives a phase name and a message as each build step runs.
90
106
  */
@@ -181,6 +197,11 @@ export interface BuildCandidateResult {
181
197
  */
182
198
  importanceFiltered: number | null
183
199
 
200
+ /**
201
+ * The count of places ranked by a population estimate, or `null` when estimates weren't asked for.
202
+ */
203
+ populationEstimated: number | null
204
+
184
205
  /**
185
206
  * The count of alias rows the gloss anomaly detector stamped `name_role = 'gloss'`.
186
207
  */
@@ -201,6 +222,78 @@ export interface BuildCandidateResult {
201
222
  * The count of places in `keyTailPlaces` with at least one stamped role row.
202
223
  */
203
224
  keyTailWithRole: number
225
+
226
+ /**
227
+ * The Overture divisions the admin database matched to a WOF record, copied into
228
+ * `overture_wof_match`, or null when the admin database predates that table.
229
+ */
230
+ overtureMatches: number | null
231
+
232
+ /**
233
+ * The matched divisions' staged rows dropped on keys their WOF record holds,
234
+ * or null with `overtureMatches`.
235
+ */
236
+ overtureTwinRowsDropped: number | null
237
+ }
238
+
239
+ /**
240
+ * Each place's region from the admin database's `ancestors`, the lowest id
241
+ * when it has more than one, with the count of places that have more than one.
242
+ */
243
+ function loadRegionAncestry(src: DatabaseClient<WOFDatabase>): { regionOf: Map<number, number>; multiRegion: number } {
244
+ const regionOf = new Map<number, number>()
245
+ let multiRegion = 0
246
+
247
+ for (const r of src
248
+ .prepare(
249
+ "SELECT id, MIN(ancestor_id) AS ancestor_id, COUNT(DISTINCT ancestor_id) AS n" +
250
+ " FROM ancestors WHERE ancestor_placetype='region' GROUP BY id"
251
+ )
252
+ .iterate()) {
253
+ regionOf.set(Number(r.id), Number(r.ancestor_id))
254
+
255
+ if (Number(r.n) > 1) {
256
+ multiRegion++
257
+ }
258
+ }
259
+
260
+ return { regionOf, multiRegion }
261
+ }
262
+
263
+ /**
264
+ * The two staging passes that delete rows by another place's rows, in order:
265
+ * the nickname refusal, then the Overture twins.
266
+ *
267
+ * The twins pass compares with the WOF rows the refusal keeps.
268
+ */
269
+ async function refuseNicknamesAndTwins(
270
+ src: DatabaseClient<WOFDatabase>,
271
+ kdb: DatabaseClient<CandidateDatabase>,
272
+ attrs: Map<number, PlaceAttrs>,
273
+ progress: (phase: string, message: string) => void
274
+ ): Promise<{
275
+ nicknames: ReturnType<typeof refuseNicknamesOfNamesakes>
276
+ twins: Awaited<ReturnType<typeof stageOvertureTwins>>
277
+ }> {
278
+ const nicknames = refuseNicknamesOfNamesakes(src, kdb, attrs)
279
+
280
+ progress(
281
+ "nicknames",
282
+ `${nicknames.rows.toLocaleString()} colloquial or unclassified alias rows refused on ` +
283
+ `${nicknames.keys.toLocaleString()} keys a populated place holds by a real name`
284
+ )
285
+
286
+ const twins = await stageOvertureTwins(src, kdb)
287
+
288
+ if (twins) {
289
+ progress(
290
+ "overture-twins",
291
+ `${twins.matches.toLocaleString()} Overture divisions matched to a WOF record. ` +
292
+ `${twins.rowsDropped.toLocaleString()} of their rows dropped on keys the WOF record holds`
293
+ )
294
+ }
295
+
296
+ return { nicknames, twins }
204
297
  }
205
298
 
206
299
  /**
@@ -254,33 +347,24 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
254
347
 
255
348
  if (opts.importance) {
256
349
  progress("importance", `loading place_importance from ${opts.importance}`)
257
- importance = loadImportanceIndex(opts.importance)
350
+ importance = loadImportanceIndex(opts.importance, { populationEstimates: opts.populationEstimates === true })
258
351
 
259
352
  progress(
260
353
  "importance",
261
354
  `${importance.stats.places.toLocaleString()} scored places in ${importance.stats.keys.toLocaleString()} (name, country, placetype) groups` +
262
- (importance.stats.unkeyable ? `; ${importance.stats.unkeyable.toLocaleString()} unkeyable names skipped` : "")
355
+ (importance.stats.unkeyable ? `; ${importance.stats.unkeyable.toLocaleString()} unkeyable names skipped` : "") +
356
+ (typeof importance.stats.estimates === "number"
357
+ ? `; ${importance.stats.estimates.toLocaleString()} population estimates to rank unmeasured places by`
358
+ : "")
263
359
  )
360
+ } else if (opts.populationEstimates) {
361
+ throw new Error("buildCandidateTable: populationEstimates reads the importance database; pass importance too")
264
362
  } else {
265
363
  progress("importance", "no score source given — `importance` will be NULL on every row")
266
364
  }
267
365
 
268
366
  progress("region", "loading region ancestry")
269
- const regionOf = new Map<number, number>()
270
- let multiRegion = 0
271
-
272
- for (const r of src
273
- .prepare(
274
- "SELECT id, MIN(ancestor_id) AS ancestor_id, COUNT(DISTINCT ancestor_id) AS n" +
275
- " FROM ancestors WHERE ancestor_placetype='region' GROUP BY id"
276
- )
277
- .iterate()) {
278
- regionOf.set(Number(r.id), Number(r.ancestor_id))
279
-
280
- if (Number(r.n) > 1) {
281
- multiRegion++
282
- }
283
- }
367
+ const { regionOf, multiRegion } = loadRegionAncestry(src)
284
368
 
285
369
  progress(
286
370
  "region",
@@ -316,7 +400,7 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
316
400
  POPULATION_CORRECTIONS[sid]?.population ??
317
401
  (wofPop === null && r.placetype === "country" ? (COUNTRY_POPULATION[String(r.country ?? "")] ?? null) : wofPop)
318
402
 
319
- const neg = -Math.log10((pop ?? 0) + 1)
403
+ const neg = -Math.log10((pop ?? importance?.estimatedPopulation(sid) ?? 0) + 1)
320
404
  const name = String(r.name ?? "")
321
405
  const pkey = normalizeLocalityForKey(name)
322
406
  const lat = r.lat as number
@@ -336,7 +420,15 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
336
420
  pop,
337
421
  neg,
338
422
  pkey,
339
- imp: importance?.find(name, r.country as string | null, r.placetype as string | null, lat, lon) ?? null,
423
+ imp:
424
+ importance?.find(
425
+ name,
426
+ r.country as string | null,
427
+ r.placetype as string | null,
428
+ lat,
429
+ lon,
430
+ isOverturePartID(sid)
431
+ ) ?? null,
340
432
  }
341
433
 
342
434
  attrs.set(sid, a)
@@ -457,13 +549,7 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
457
549
  kdb.exec("COMMIT")
458
550
  progress("abbrevs", `${nAbbr.toLocaleString()} abbrevs`)
459
551
 
460
- const nicknames = refuseNicknamesOfNamesakes(src, kdb, attrs)
461
-
462
- progress(
463
- "nicknames",
464
- `${nicknames.rows.toLocaleString()} colloquial or unclassified alias rows refused on ` +
465
- `${nicknames.keys.toLocaleString()} keys a populated place holds by a real name`
466
- )
552
+ const { nicknames, twins } = await refuseNicknamesAndTwins(src, kdb, attrs, progress)
467
553
 
468
554
  const roles = stampNameRoles({
469
555
  src,
@@ -482,18 +568,18 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
482
568
  let nPostcodeAlias = 0
483
569
 
484
570
  for (const pcDB of opts.postcodes ?? []) {
485
- const folded = foldExtract({
571
+ const staged = stageExtractRows({
486
572
  out: kdb,
487
573
  extractPath: pcDB,
488
- extractPlacetype: "postalcode",
574
+ extractPlacetype: POSTCODE_PLACETYPE,
489
575
  ccID,
490
576
  ptID,
491
577
  stageRow,
492
578
  progress,
493
579
  })
494
580
 
495
- nPostcode += folded.primaries
496
- nPostcodeAlias += folded.aliases
581
+ nPostcode += staged.primaries
582
+ nPostcodeAlias += staged.aliases
497
583
  }
498
584
 
499
585
  if (nPostcode > 0) {
@@ -505,7 +591,7 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
505
591
  let nLocalityAncestor = 0
506
592
 
507
593
  for (const locDB of opts.localities ?? []) {
508
- const folded = foldExtract({
594
+ const staged = stageExtractRows({
509
595
  out: kdb,
510
596
  extractPath: locDB,
511
597
  extractPlacetype: "locality",
@@ -516,15 +602,15 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
516
602
  progress,
517
603
  })
518
604
 
519
- nLocality += folded.primaries
520
- nLocalityScoped += folded.scoped
521
- nLocalityAncestor += folded.ancestorRows
605
+ nLocality += staged.primaries
606
+ nLocalityScoped += staged.scoped
607
+ nLocalityAncestor += staged.ancestorRows
522
608
  }
523
609
 
524
610
  if (nLocality > 0) {
525
611
  progress(
526
612
  "localities",
527
- `${nLocality.toLocaleString()} extract localities folded` +
613
+ `${nLocality.toLocaleString()} extract localities added` +
528
614
  (nLocalityScoped
529
615
  ? `; ${nLocalityScoped.toLocaleString()} carry a region scope (${nLocalityAncestor.toLocaleString()} closure rows)`
530
616
  : "")
@@ -582,6 +668,13 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
582
668
  progress("fts", "building FTS5-trigram fuzzy index")
583
669
  createCandidateFTS(kdb)
584
670
 
671
+ const postcodePlacetypeID = ptcodes.get(POSTCODE_PLACETYPE)
672
+
673
+ if (postcodePlacetypeID != null) {
674
+ progress("postcode-index", `indexing postcode places by spr_id (placetype id ${postcodePlacetypeID})`)
675
+ await createCandidatePostcodePlaceIndex(kdb, postcodePlacetypeID)
676
+ }
677
+
585
678
  kdb.exec("PRAGMA page_size=8192")
586
679
  kdb.exec("VACUUM")
587
680
 
@@ -607,5 +700,8 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
607
700
  ...roles,
608
701
  importanceScored: importance ? importance.matched : null,
609
702
  importanceFiltered: importance ? importance.refused : null,
703
+ populationEstimated: typeof importance?.stats.estimates === "number" ? importance.estimated : null,
704
+ overtureMatches: twins ? twins.matches : null,
705
+ overtureTwinRowsDropped: twins ? twins.rowsDropped : null,
610
706
  }
611
707
  }
package/lib/build/slim.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  import { statPath, pathExists } from "@mailwoman/core/fs/readers/stat"
5
5
  import { temporaryDirectory } from "@mailwoman/core/fs/temporary"
6
6
  import { copyFileTo, removePath } from "@mailwoman/core/fs/writers"
7
- import { stringifyJSON } from "@mailwoman/core/json"
7
+ import { stringifyJSON } from "@mailwoman/core/values/json"
8
8
  import { countRows } from "@mailwoman/sqlite"
9
9
  import { DatabaseClient } from "@mailwoman/sqlite/client"
10
10
  import { sealDatabase } from "@mailwoman/sqlite/sealed/db"
@@ -103,6 +103,9 @@ interface BuildSchema {
103
103
  }
104
104
 
105
105
  export async function buildSlimWOFDatabase(opts: BuildSlimOptions): Promise<BuildSlimResult> {
106
+ // country-branch: a slim build that states no countries keeps the places of one country, the US.
107
+ // The commit that added the default recorded no reason, and a required
108
+ // `countries` option would replace it.
106
109
  const countries = (opts.countries ?? ["US"]).map((c) => c.toUpperCase())
107
110
  const topLocalities = opts.topLocalitiesPerCountry ?? 1000
108
111
  const progress = opts.onProgress ?? (() => {})
@@ -0,0 +1,50 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * The sources a gazetteer build records in its `layer_manifest.source`, and
6
+ * where a user obtains each one.
7
+ *
8
+ * The admin build writes these names, joined with `+`, and a server reads them
9
+ * back to link each collection to the data behind it.
10
+ * One table serves both, so a name the build writes always has its location here.
11
+ */
12
+
13
+ import type { SourceLocation } from "@mailwoman/core/resolver"
14
+
15
+ /**
16
+ * The name each gazetteer source goes by in a manifest's `source`.
17
+ */
18
+ export const GazetteerSourceName = {
19
+ WhosOnFirst: "whosonfirst",
20
+ OvertureDivisions: "overture-divisions",
21
+ GeoNames: "geonames",
22
+ } as const
23
+
24
+ export type GazetteerSourceName = (typeof GazetteerSourceName)[keyof typeof GazetteerSourceName]
25
+
26
+ /**
27
+ * The location of each gazetteer source.
28
+ *
29
+ * Who's On First points to the `mailwoman` organization.
30
+ * It holds the forks of the `whosonfirst-data-admin-<cc>` repositories the admin build clones.
31
+ *
32
+ * Each fork's upstream is the repository of the same name under `whosonfirst-data`.
33
+ */
34
+ export const GAZETTEER_SOURCE_LOCATIONS: Readonly<Record<GazetteerSourceName, SourceLocation>> = {
35
+ [GazetteerSourceName.WhosOnFirst]: { title: "Who's On First", url: "https://github.com/mailwoman" },
36
+ [GazetteerSourceName.OvertureDivisions]: {
37
+ title: "Overture Maps divisions theme",
38
+ url: "https://docs.overturemaps.org/guides/divisions/",
39
+ },
40
+ [GazetteerSourceName.GeoNames]: { title: "GeoNames", url: "https://download.geonames.org/export/dump/" },
41
+ }
42
+
43
+ /**
44
+ * The location of a source a manifest records, or null when the name has none here.
45
+ */
46
+ export function gazetteerSourceLocation(name: string): SourceLocation | null {
47
+ return Object.hasOwn(GAZETTEER_SOURCE_LOCATIONS, name)
48
+ ? GAZETTEER_SOURCE_LOCATIONS[name as GazetteerSourceName]
49
+ : null
50
+ }