@mailwoman/resolver-wof-sqlite 11.1.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 (467) hide show
  1. package/README.md +5 -5
  2. package/lib/address/duplicate.ts +1 -1
  3. package/lib/address/keys/attribution.ts +6 -1
  4. package/lib/address/keys/build.ts +1 -1
  5. package/lib/address/keys/layout.ts +27 -1
  6. package/lib/address/keys/lookup.ts +2 -2
  7. package/lib/address/keys/point-lookup.ts +2 -2
  8. package/lib/address/number-forms.ts +4 -6
  9. package/lib/address/point/interpolation.ts +11 -3
  10. package/lib/address/point/schema.ts +1 -1
  11. package/lib/address/point.ts +15 -14
  12. package/lib/address/record.ts +1 -1
  13. package/lib/ancestry/backfill.ts +13 -43
  14. package/lib/build/candidate.ts +171 -35
  15. package/lib/build/slim.ts +4 -1
  16. package/lib/build/sources.ts +50 -0
  17. package/lib/candidate/alias-bags.ts +74 -20
  18. package/lib/candidate/ancestors/schema.ts +1 -1
  19. package/lib/candidate/ancestors/sidecar.ts +13 -2
  20. package/lib/candidate/bare-admin-names.ts +1 -1
  21. package/lib/{capital-schema.ts → candidate/capital-schema.ts} +3 -3
  22. package/lib/{capitals.ts → candidate/capitals.ts} +1 -1
  23. package/lib/candidate/country-display-names.ts +1 -1
  24. package/lib/candidate/{extract-fold.ts → extract-rows.ts} +7 -4
  25. package/lib/candidate/importance.ts +90 -11
  26. package/lib/candidate/key-fold.ts +132 -0
  27. package/lib/candidate/lookup.ts +101 -60
  28. package/lib/candidate/name-roles.ts +1 -1
  29. package/lib/candidate/nickname-namesakes.ts +147 -0
  30. package/lib/candidate/overture-twins.ts +83 -0
  31. package/lib/candidate/place-attrs.ts +2 -2
  32. package/lib/candidate/postcode-browse.ts +173 -0
  33. package/lib/candidate/schema.ts +43 -2
  34. package/lib/candidate/scoring.ts +4 -4
  35. package/lib/convention.ts +1 -1
  36. package/lib/env.ts +15 -3
  37. package/lib/fst/binary-matcher.ts +26 -41
  38. package/lib/fst/builder.ts +8 -6
  39. package/lib/fst/deserialize-web.ts +1 -1
  40. package/lib/fst/format.ts +144 -7
  41. package/lib/fst/freshness.ts +2 -2
  42. package/lib/fst/serialize.ts +93 -64
  43. package/lib/fts/query.ts +1 -1
  44. package/lib/{search-fetch.ts → fts/search-fetch.ts} +2 -2
  45. package/lib/geonames/aliases.ts +42 -45
  46. package/lib/geonames/postal.ts +3 -3
  47. package/lib/index.ts +20 -17
  48. package/lib/{postal/city → labels/locality/postal-city}/alias/lookup.ts +1 -1
  49. package/lib/{postal/city → labels/locality/postal-city}/candidate-schema.ts +1 -1
  50. package/lib/labels/locality.ts +6 -0
  51. package/lib/{region-keys.ts → labels/region.ts} +5 -2
  52. package/lib/{street → labels/street}/centroid/schema.ts +1 -1
  53. package/lib/{street → labels/street}/centroid.ts +7 -7
  54. package/lib/{interpolation.ts → labels/street/interpolation.ts} +12 -4
  55. package/lib/labels/street/locale.ts +117 -0
  56. package/lib/{street → labels/street}/morphology/fst/loader.ts +1 -1
  57. package/lib/{street → labels/street}/name-lookup.ts +2 -0
  58. package/lib/{street → labels/street}/normalize.ts +284 -133
  59. package/lib/{street → labels/street}/segment-schema.ts +1 -1
  60. package/lib/{street → labels/street}/table.ts +1 -1
  61. package/lib/labels/street.ts +11 -0
  62. package/lib/landmark/rows.ts +1 -1
  63. package/lib/lookup/browse.ts +304 -0
  64. package/lib/{extracts.ts → lookup/extracts.ts} +1 -1
  65. package/lib/lookup/former-divisions.ts +183 -0
  66. package/lib/{postcode-point-lookup.ts → lookup/postcode-point.ts} +5 -0
  67. package/lib/{reverse.ts → lookup/reverse.ts} +4 -4
  68. package/lib/{types.ts → lookup/types.ts} +10 -0
  69. package/lib/lookup.ts +21 -31
  70. package/lib/poi/schema.ts +1 -1
  71. package/lib/{primary-preference.ts → ranking/primary-preference.ts} +45 -2
  72. package/lib/schema/importance-source.ts +210 -0
  73. package/lib/schema/overture-match.ts +79 -0
  74. package/lib/{place-importance-schema.ts → schema/place-importance.ts} +86 -0
  75. package/lib/schema.ts +3 -3
  76. package/lib/sqlite/convention-source.ts +1 -1
  77. package/lib/uprn/existence.ts +2 -0
  78. package/lib/{weights-overlay-linker.ts → weights/overlay-linker.ts} +244 -103
  79. package/out/address/duplicate.js +1 -1
  80. package/out/address/duplicate.js.map +1 -1
  81. package/out/address/keys/attribution.d.ts +4 -0
  82. package/out/address/keys/attribution.d.ts.map +1 -1
  83. package/out/address/keys/attribution.js +5 -1
  84. package/out/address/keys/attribution.js.map +1 -1
  85. package/out/address/keys/build.d.ts.map +1 -1
  86. package/out/address/keys/build.js +1 -1
  87. package/out/address/keys/build.js.map +1 -1
  88. package/out/address/keys/layout.d.ts +18 -1
  89. package/out/address/keys/layout.d.ts.map +1 -1
  90. package/out/address/keys/layout.js +23 -1
  91. package/out/address/keys/layout.js.map +1 -1
  92. package/out/address/keys/lookup.js +2 -2
  93. package/out/address/keys/lookup.js.map +1 -1
  94. package/out/address/keys/point-lookup.d.ts.map +1 -1
  95. package/out/address/keys/point-lookup.js +2 -2
  96. package/out/address/keys/point-lookup.js.map +1 -1
  97. package/out/address/number-forms.d.ts +1 -1
  98. package/out/address/number-forms.d.ts.map +1 -1
  99. package/out/address/number-forms.js +4 -5
  100. package/out/address/number-forms.js.map +1 -1
  101. package/out/address/point/interpolation.d.ts +1 -1
  102. package/out/address/point/interpolation.d.ts.map +1 -1
  103. package/out/address/point/interpolation.js +9 -2
  104. package/out/address/point/interpolation.js.map +1 -1
  105. package/out/address/point/schema.d.ts +1 -1
  106. package/out/address/point/schema.d.ts.map +1 -1
  107. package/out/address/point.d.ts +4 -5
  108. package/out/address/point.d.ts.map +1 -1
  109. package/out/address/point.js +11 -11
  110. package/out/address/point.js.map +1 -1
  111. package/out/address/record.d.ts +1 -1
  112. package/out/address/record.d.ts.map +1 -1
  113. package/out/address/record.js +1 -1
  114. package/out/address/record.js.map +1 -1
  115. package/out/ancestry/backfill.d.ts +14 -9
  116. package/out/ancestry/backfill.d.ts.map +1 -1
  117. package/out/ancestry/backfill.js +4 -42
  118. package/out/ancestry/backfill.js.map +1 -1
  119. package/out/build/candidate.d.ts +46 -1
  120. package/out/build/candidate.d.ts.map +1 -1
  121. package/out/build/candidate.js +82 -31
  122. package/out/build/candidate.js.map +1 -1
  123. package/out/build/slim.d.ts.map +1 -1
  124. package/out/build/slim.js +4 -1
  125. package/out/build/slim.js.map +1 -1
  126. package/out/build/sources.d.ts +32 -0
  127. package/out/build/sources.d.ts.map +1 -0
  128. package/out/build/sources.js +35 -0
  129. package/out/build/sources.js.map +1 -0
  130. package/out/candidate/alias-bags.d.ts +8 -3
  131. package/out/candidate/alias-bags.d.ts.map +1 -1
  132. package/out/candidate/alias-bags.js +63 -17
  133. package/out/candidate/alias-bags.js.map +1 -1
  134. package/out/candidate/ancestors/schema.d.ts +1 -1
  135. package/out/candidate/ancestors/schema.d.ts.map +1 -1
  136. package/out/candidate/ancestors/sidecar.d.ts +0 -3
  137. package/out/candidate/ancestors/sidecar.d.ts.map +1 -1
  138. package/out/candidate/ancestors/sidecar.js +16 -2
  139. package/out/candidate/ancestors/sidecar.js.map +1 -1
  140. package/out/candidate/bare-admin-names.js +1 -1
  141. package/out/candidate/bare-admin-names.js.map +1 -1
  142. package/out/{capital-schema.d.ts → candidate/capital-schema.d.ts} +2 -2
  143. package/out/candidate/capital-schema.d.ts.map +1 -0
  144. package/out/{capital-schema.js → candidate/capital-schema.js} +2 -2
  145. package/out/candidate/capital-schema.js.map +1 -0
  146. package/out/candidate/capitals.d.ts.map +1 -0
  147. package/out/{capitals.js → candidate/capitals.js} +1 -1
  148. package/out/candidate/capitals.js.map +1 -0
  149. package/out/candidate/country-display-names.js +1 -1
  150. package/out/candidate/country-display-names.js.map +1 -1
  151. package/out/{coverage-manifest-schema.d.ts → candidate/coverage-manifest.d.ts} +1 -1
  152. package/out/candidate/coverage-manifest.d.ts.map +1 -0
  153. package/out/{coverage-manifest-schema.js → candidate/coverage-manifest.js} +1 -1
  154. package/out/candidate/coverage-manifest.js.map +1 -0
  155. package/out/candidate/{extract-fold.d.ts → extract-rows.d.ts} +2 -2
  156. package/out/candidate/extract-rows.d.ts.map +1 -0
  157. package/out/candidate/{extract-fold.js → extract-rows.js} +8 -5
  158. package/out/candidate/extract-rows.js.map +1 -0
  159. package/out/candidate/importance.d.ts +34 -3
  160. package/out/candidate/importance.d.ts.map +1 -1
  161. package/out/candidate/importance.js +57 -11
  162. package/out/candidate/importance.js.map +1 -1
  163. package/out/candidate/key-fold.d.ts +55 -0
  164. package/out/candidate/key-fold.d.ts.map +1 -0
  165. package/out/candidate/key-fold.js +80 -0
  166. package/out/candidate/key-fold.js.map +1 -0
  167. package/out/candidate/lookup.d.ts +5 -1
  168. package/out/candidate/lookup.d.ts.map +1 -1
  169. package/out/candidate/lookup.js +80 -54
  170. package/out/candidate/lookup.js.map +1 -1
  171. package/out/candidate/name-roles.d.ts.map +1 -1
  172. package/out/candidate/name-roles.js +1 -1
  173. package/out/candidate/name-roles.js.map +1 -1
  174. package/out/candidate/nickname-namesakes.d.ts +28 -0
  175. package/out/candidate/nickname-namesakes.d.ts.map +1 -0
  176. package/out/candidate/nickname-namesakes.js +109 -0
  177. package/out/candidate/nickname-namesakes.js.map +1 -0
  178. package/out/candidate/overture-twins.d.ts +30 -0
  179. package/out/candidate/overture-twins.d.ts.map +1 -0
  180. package/out/candidate/overture-twins.js +40 -0
  181. package/out/candidate/overture-twins.js.map +1 -0
  182. package/out/candidate/place-attrs.d.ts +2 -2
  183. package/out/candidate/postcode-browse.d.ts +36 -0
  184. package/out/candidate/postcode-browse.d.ts.map +1 -0
  185. package/out/candidate/postcode-browse.js +119 -0
  186. package/out/candidate/postcode-browse.js.map +1 -0
  187. package/out/candidate/schema.d.ts +30 -2
  188. package/out/candidate/schema.d.ts.map +1 -1
  189. package/out/candidate/schema.js +29 -0
  190. package/out/candidate/schema.js.map +1 -1
  191. package/out/candidate/scoring.d.ts +3 -3
  192. package/out/candidate/scoring.d.ts.map +1 -1
  193. package/out/candidate/scoring.js +2 -2
  194. package/out/candidate/scoring.js.map +1 -1
  195. package/out/convention.d.ts +1 -1
  196. package/out/convention.d.ts.map +1 -1
  197. package/out/env.d.ts +3 -0
  198. package/out/env.d.ts.map +1 -1
  199. package/out/env.js +14 -3
  200. package/out/env.js.map +1 -1
  201. package/out/fst/binary-matcher.d.ts.map +1 -1
  202. package/out/fst/binary-matcher.js +9 -30
  203. package/out/fst/binary-matcher.js.map +1 -1
  204. package/out/fst/builder.d.ts.map +1 -1
  205. package/out/fst/builder.js +8 -6
  206. package/out/fst/builder.js.map +1 -1
  207. package/out/fst/deserialize-web.js +1 -1
  208. package/out/fst/deserialize-web.js.map +1 -1
  209. package/out/fst/format.d.ts +60 -9
  210. package/out/fst/format.d.ts.map +1 -1
  211. package/out/fst/format.js +97 -6
  212. package/out/fst/format.js.map +1 -1
  213. package/out/fst/freshness.js +2 -2
  214. package/out/fst/freshness.js.map +1 -1
  215. package/out/fst/serialize.d.ts.map +1 -1
  216. package/out/fst/serialize.js +67 -55
  217. package/out/fst/serialize.js.map +1 -1
  218. package/out/fts/query.d.ts +1 -1
  219. package/out/fts/query.d.ts.map +1 -1
  220. package/out/{search-fetch.d.ts → fts/search-fetch.d.ts} +2 -2
  221. package/out/fts/search-fetch.d.ts.map +1 -0
  222. package/out/fts/search-fetch.js.map +1 -0
  223. package/out/geonames/aliases.d.ts +18 -18
  224. package/out/geonames/aliases.d.ts.map +1 -1
  225. package/out/geonames/aliases.js +20 -24
  226. package/out/geonames/aliases.js.map +1 -1
  227. package/out/geonames/postal.d.ts +1 -1
  228. package/out/geonames/postal.js +3 -3
  229. package/out/index.d.ts +17 -17
  230. package/out/index.d.ts.map +1 -1
  231. package/out/index.js +12 -12
  232. package/out/index.js.map +1 -1
  233. package/out/{postal/city → labels/locality/postal-city}/alias/lookup.d.ts +1 -1
  234. package/out/labels/locality/postal-city/alias/lookup.d.ts.map +1 -0
  235. package/out/labels/locality/postal-city/alias/lookup.js.map +1 -0
  236. package/out/labels/locality/postal-city/alias/schema.d.ts.map +1 -0
  237. package/out/labels/locality/postal-city/alias/schema.js.map +1 -0
  238. package/out/{postal/city → labels/locality/postal-city}/candidate-schema.d.ts +1 -1
  239. package/out/labels/locality/postal-city/candidate-schema.d.ts.map +1 -0
  240. package/out/labels/locality/postal-city/candidate-schema.js.map +1 -0
  241. package/out/labels/locality.d.ts +4 -0
  242. package/out/labels/locality.d.ts.map +1 -0
  243. package/out/labels/locality.js +6 -0
  244. package/out/labels/locality.js.map +1 -0
  245. package/out/{region-keys.d.ts → labels/region.d.ts} +1 -1
  246. package/out/{region-keys.d.ts.map → labels/region.d.ts.map} +1 -1
  247. package/out/{region-keys.js → labels/region.js} +6 -3
  248. package/out/labels/region.js.map +1 -0
  249. package/out/{street → labels/street}/centroid/schema.d.ts +1 -1
  250. package/out/labels/street/centroid/schema.d.ts.map +1 -0
  251. package/out/labels/street/centroid/schema.js.map +1 -0
  252. package/out/{street → labels/street}/centroid.d.ts +5 -5
  253. package/out/labels/street/centroid.d.ts.map +1 -0
  254. package/out/{street → labels/street}/centroid.js +5 -5
  255. package/out/labels/street/centroid.js.map +1 -0
  256. package/out/{interpolation.d.ts → labels/street/interpolation.d.ts} +6 -1
  257. package/out/labels/street/interpolation.d.ts.map +1 -0
  258. package/out/{interpolation.js → labels/street/interpolation.js} +10 -8
  259. package/out/labels/street/interpolation.js.map +1 -0
  260. package/out/labels/street/locale.d.ts +26 -0
  261. package/out/labels/street/locale.d.ts.map +1 -0
  262. package/out/labels/street/locale.js +98 -0
  263. package/out/labels/street/locale.js.map +1 -0
  264. package/out/labels/street/morphology/fst/builder.d.ts.map +1 -0
  265. package/out/labels/street/morphology/fst/builder.js.map +1 -0
  266. package/out/labels/street/morphology/fst/loader.d.ts.map +1 -0
  267. package/out/{street → labels/street}/morphology/fst/loader.js +1 -1
  268. package/out/labels/street/morphology/fst/loader.js.map +1 -0
  269. package/out/labels/street/name-lookup.d.ts.map +1 -0
  270. package/out/{street → labels/street}/name-lookup.js +2 -0
  271. package/out/labels/street/name-lookup.js.map +1 -0
  272. package/out/labels/street/normalize.d.ts +188 -0
  273. package/out/labels/street/normalize.d.ts.map +1 -0
  274. package/out/{street → labels/street}/normalize.js +200 -119
  275. package/out/labels/street/normalize.js.map +1 -0
  276. package/out/{street → labels/street}/segment-schema.d.ts +1 -1
  277. package/out/labels/street/segment-schema.d.ts.map +1 -0
  278. package/out/labels/street/segment-schema.js.map +1 -0
  279. package/out/labels/street/table.d.ts.map +1 -0
  280. package/out/{street → labels/street}/table.js +1 -1
  281. package/out/labels/street/table.js.map +1 -0
  282. package/out/labels/street.d.ts +9 -0
  283. package/out/labels/street.d.ts.map +1 -0
  284. package/out/labels/street.js +11 -0
  285. package/out/labels/street.js.map +1 -0
  286. package/out/landmark/rows.js +1 -1
  287. package/out/landmark/rows.js.map +1 -1
  288. package/out/lookup/browse.d.ts +79 -0
  289. package/out/lookup/browse.d.ts.map +1 -0
  290. package/out/lookup/browse.js +194 -0
  291. package/out/lookup/browse.js.map +1 -0
  292. package/out/lookup/exact-match.d.ts.map +1 -0
  293. package/out/lookup/exact-match.js.map +1 -0
  294. package/out/lookup/extracts.d.ts.map +1 -0
  295. package/out/{extracts.js → lookup/extracts.js} +1 -1
  296. package/out/lookup/extracts.js.map +1 -0
  297. package/out/lookup/former-divisions.d.ts +99 -0
  298. package/out/lookup/former-divisions.d.ts.map +1 -0
  299. package/out/lookup/former-divisions.js +98 -0
  300. package/out/lookup/former-divisions.js.map +1 -0
  301. package/out/{postcode-point-lookup.d.ts → lookup/postcode-point.d.ts} +5 -1
  302. package/out/lookup/postcode-point.d.ts.map +1 -0
  303. package/out/{postcode-point-lookup.js → lookup/postcode-point.js} +1 -1
  304. package/out/lookup/postcode-point.js.map +1 -0
  305. package/out/{reverse.d.ts → lookup/reverse.d.ts} +1 -1
  306. package/out/lookup/reverse.d.ts.map +1 -0
  307. package/out/{reverse.js → lookup/reverse.js} +3 -3
  308. package/out/lookup/reverse.js.map +1 -0
  309. package/out/{types.d.ts → lookup/types.d.ts} +9 -0
  310. package/out/lookup/types.d.ts.map +1 -0
  311. package/out/lookup/types.js.map +1 -0
  312. package/out/lookup.d.ts +4 -4
  313. package/out/lookup.d.ts.map +1 -1
  314. package/out/lookup.js +14 -20
  315. package/out/lookup.js.map +1 -1
  316. package/out/poi/schema.d.ts +1 -1
  317. package/out/poi/schema.d.ts.map +1 -1
  318. package/out/ranking/name-score.d.ts.map +1 -0
  319. package/out/ranking/name-score.js.map +1 -0
  320. package/out/{primary-preference.d.ts → ranking/primary-preference.d.ts} +20 -1
  321. package/out/ranking/primary-preference.d.ts.map +1 -0
  322. package/out/{primary-preference.js → ranking/primary-preference.js} +35 -1
  323. package/out/ranking/primary-preference.js.map +1 -0
  324. package/out/ranking/proximity-rerank.d.ts.map +1 -0
  325. package/out/ranking/proximity-rerank.js.map +1 -0
  326. package/out/{ranking-weights.d.ts → ranking/weights.d.ts} +1 -1
  327. package/out/ranking/weights.d.ts.map +1 -0
  328. package/out/{ranking-weights.js → ranking/weights.js} +1 -1
  329. package/out/ranking/weights.js.map +1 -0
  330. package/out/schema/importance-source.d.ts +90 -0
  331. package/out/schema/importance-source.d.ts.map +1 -0
  332. package/out/schema/importance-source.js +133 -0
  333. package/out/schema/importance-source.js.map +1 -0
  334. package/out/schema/overture-match.d.ts +53 -0
  335. package/out/schema/overture-match.d.ts.map +1 -0
  336. package/out/schema/overture-match.js +33 -0
  337. package/out/schema/overture-match.js.map +1 -0
  338. package/out/{place-importance-schema.d.ts → schema/place-importance.d.ts} +50 -1
  339. package/out/schema/place-importance.d.ts.map +1 -0
  340. package/out/{place-importance-schema.js → schema/place-importance.js} +34 -1
  341. package/out/schema/place-importance.js.map +1 -0
  342. package/out/{polygon-schema.d.ts → schema/polygon.d.ts} +1 -1
  343. package/out/schema/polygon.d.ts.map +1 -0
  344. package/out/{polygon-schema.js → schema/polygon.js} +1 -1
  345. package/out/schema/polygon.js.map +1 -0
  346. package/out/{unified-schema.d.ts → schema/unified.d.ts} +1 -1
  347. package/out/schema/unified.d.ts.map +1 -0
  348. package/out/{unified-schema.js → schema/unified.js} +1 -1
  349. package/out/schema/unified.js.map +1 -0
  350. package/out/schema.d.ts +3 -3
  351. package/out/sqlite/convention-source.js +1 -1
  352. package/out/sqlite/convention-source.js.map +1 -1
  353. package/out/uprn/existence.d.ts.map +1 -1
  354. package/out/uprn/existence.js +2 -0
  355. package/out/uprn/existence.js.map +1 -1
  356. package/out/{weights-overlay-linker.d.ts → weights/overlay-linker.d.ts} +43 -24
  357. package/out/weights/overlay-linker.d.ts.map +1 -0
  358. package/out/{weights-overlay-linker.js → weights/overlay-linker.js} +182 -66
  359. package/out/weights/overlay-linker.js.map +1 -0
  360. package/package.json +12 -32
  361. package/lib/postal.ts +0 -6
  362. package/lib/street/locale.ts +0 -64
  363. package/lib/street.ts +0 -11
  364. package/out/candidate/extract-fold.d.ts.map +0 -1
  365. package/out/candidate/extract-fold.js.map +0 -1
  366. package/out/capital-schema.d.ts.map +0 -1
  367. package/out/capital-schema.js.map +0 -1
  368. package/out/capitals.d.ts.map +0 -1
  369. package/out/capitals.js.map +0 -1
  370. package/out/coverage-manifest-schema.d.ts.map +0 -1
  371. package/out/coverage-manifest-schema.js.map +0 -1
  372. package/out/exact-match.d.ts.map +0 -1
  373. package/out/exact-match.js.map +0 -1
  374. package/out/extracts.d.ts.map +0 -1
  375. package/out/extracts.js.map +0 -1
  376. package/out/interpolation.d.ts.map +0 -1
  377. package/out/interpolation.js.map +0 -1
  378. package/out/name-score.d.ts.map +0 -1
  379. package/out/name-score.js.map +0 -1
  380. package/out/place-importance-schema.d.ts.map +0 -1
  381. package/out/place-importance-schema.js.map +0 -1
  382. package/out/polygon-schema.d.ts.map +0 -1
  383. package/out/polygon-schema.js.map +0 -1
  384. package/out/postal/city/alias/lookup.d.ts.map +0 -1
  385. package/out/postal/city/alias/lookup.js.map +0 -1
  386. package/out/postal/city/alias/schema.d.ts.map +0 -1
  387. package/out/postal/city/alias/schema.js.map +0 -1
  388. package/out/postal/city/candidate-schema.d.ts.map +0 -1
  389. package/out/postal/city/candidate-schema.js.map +0 -1
  390. package/out/postal.d.ts +0 -4
  391. package/out/postal.d.ts.map +0 -1
  392. package/out/postal.js +0 -6
  393. package/out/postal.js.map +0 -1
  394. package/out/postcode-point-lookup.d.ts.map +0 -1
  395. package/out/postcode-point-lookup.js.map +0 -1
  396. package/out/primary-preference.d.ts.map +0 -1
  397. package/out/primary-preference.js.map +0 -1
  398. package/out/proximity-rerank.d.ts.map +0 -1
  399. package/out/proximity-rerank.js.map +0 -1
  400. package/out/ranking-weights.d.ts.map +0 -1
  401. package/out/ranking-weights.js.map +0 -1
  402. package/out/region-keys.js.map +0 -1
  403. package/out/reverse.d.ts.map +0 -1
  404. package/out/reverse.js.map +0 -1
  405. package/out/search-fetch.d.ts.map +0 -1
  406. package/out/search-fetch.js.map +0 -1
  407. package/out/street/centroid/schema.d.ts.map +0 -1
  408. package/out/street/centroid/schema.js.map +0 -1
  409. package/out/street/centroid.d.ts.map +0 -1
  410. package/out/street/centroid.js.map +0 -1
  411. package/out/street/locale.d.ts +0 -12
  412. package/out/street/locale.d.ts.map +0 -1
  413. package/out/street/locale.js +0 -54
  414. package/out/street/locale.js.map +0 -1
  415. package/out/street/morphology/fst/builder.d.ts.map +0 -1
  416. package/out/street/morphology/fst/builder.js.map +0 -1
  417. package/out/street/morphology/fst/loader.d.ts.map +0 -1
  418. package/out/street/morphology/fst/loader.js.map +0 -1
  419. package/out/street/name-lookup.d.ts.map +0 -1
  420. package/out/street/name-lookup.js.map +0 -1
  421. package/out/street/normalize.d.ts +0 -111
  422. package/out/street/normalize.d.ts.map +0 -1
  423. package/out/street/normalize.js.map +0 -1
  424. package/out/street/segment-schema.d.ts.map +0 -1
  425. package/out/street/segment-schema.js.map +0 -1
  426. package/out/street/table.d.ts.map +0 -1
  427. package/out/street/table.js.map +0 -1
  428. package/out/street.d.ts +0 -9
  429. package/out/street.d.ts.map +0 -1
  430. package/out/street.js +0 -11
  431. package/out/street.js.map +0 -1
  432. package/out/types.d.ts.map +0 -1
  433. package/out/types.js.map +0 -1
  434. package/out/unified-schema.d.ts.map +0 -1
  435. package/out/unified-schema.js.map +0 -1
  436. package/out/weights-overlay-linker.d.ts.map +0 -1
  437. package/out/weights-overlay-linker.js.map +0 -1
  438. /package/lib/{coverage-manifest-schema.ts → candidate/coverage-manifest.ts} +0 -0
  439. /package/lib/{postal/city → labels/locality/postal-city}/alias/schema.ts +0 -0
  440. /package/lib/{street → labels/street}/morphology/fst/builder.ts +0 -0
  441. /package/lib/{exact-match.ts → lookup/exact-match.ts} +0 -0
  442. /package/lib/{name-score.ts → ranking/name-score.ts} +0 -0
  443. /package/lib/{proximity-rerank.ts → ranking/proximity-rerank.ts} +0 -0
  444. /package/lib/{ranking-weights.ts → ranking/weights.ts} +0 -0
  445. /package/lib/{polygon-schema.ts → schema/polygon.ts} +0 -0
  446. /package/lib/{unified-schema.ts → schema/unified.ts} +0 -0
  447. /package/out/{capitals.d.ts → candidate/capitals.d.ts} +0 -0
  448. /package/out/{search-fetch.js → fts/search-fetch.js} +0 -0
  449. /package/out/{postal/city → labels/locality/postal-city}/alias/lookup.js +0 -0
  450. /package/out/{postal/city → labels/locality/postal-city}/alias/schema.d.ts +0 -0
  451. /package/out/{postal/city → labels/locality/postal-city}/alias/schema.js +0 -0
  452. /package/out/{postal/city → labels/locality/postal-city}/candidate-schema.js +0 -0
  453. /package/out/{street → labels/street}/centroid/schema.js +0 -0
  454. /package/out/{street → labels/street}/morphology/fst/builder.d.ts +0 -0
  455. /package/out/{street → labels/street}/morphology/fst/builder.js +0 -0
  456. /package/out/{street → labels/street}/morphology/fst/loader.d.ts +0 -0
  457. /package/out/{street → labels/street}/name-lookup.d.ts +0 -0
  458. /package/out/{street → labels/street}/segment-schema.js +0 -0
  459. /package/out/{street → labels/street}/table.d.ts +0 -0
  460. /package/out/{exact-match.d.ts → lookup/exact-match.d.ts} +0 -0
  461. /package/out/{exact-match.js → lookup/exact-match.js} +0 -0
  462. /package/out/{extracts.d.ts → lookup/extracts.d.ts} +0 -0
  463. /package/out/{types.js → lookup/types.js} +0 -0
  464. /package/out/{name-score.d.ts → ranking/name-score.d.ts} +0 -0
  465. /package/out/{name-score.js → ranking/name-score.js} +0 -0
  466. /package/out/{proximity-rerank.d.ts → ranking/proximity-rerank.d.ts} +0 -0
  467. /package/out/{proximity-rerank.js → ranking/proximity-rerank.js} +0 -0
@@ -1,6 +1,13 @@
1
1
  // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
2
  // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
3
 
4
+ /**
5
+ * The primary-name preference re-rank: a place whose primary name is the query outranks a place
6
+ * that lists it as an alias, unless the alias row's population exceeds it by a stated log10 margin.
7
+ */
8
+
9
+ import { latLonBoundsContain } from "@mailwoman/spatial/bbox"
10
+
4
11
  import type { CandidateTable } from "#candidate/schema"
5
12
 
6
13
  /**
@@ -20,6 +27,40 @@ export type PrimaryPreferenceRow = Pick<CandidateTable, "neg_rank"> &
20
27
  */
21
28
  export const PRIMARY_PREFERENCE_LOG10 = 1
22
29
 
30
+ /**
31
+ * The alias penalty inside a stated region, larger than any log10 population gap.
32
+ *
33
+ * A query that states the region (`Junction, IL`) has already chosen among the world's namesakes,
34
+ * so a place whose primary name equals the query outranks a different place that lists it as an alias.
35
+ * WOF `und` variant names include former names of absorbed communities, such as `Junction` on West
36
+ * Chicago, and a population gap between the two places is no evidence of which one the query means.
37
+ */
38
+ export const REGION_PRIMARY_PREFERENCE_LOG10 = 100
39
+
40
+ /**
41
+ * The alias penalty inside a stated region for one alias row against the top primary row.
42
+ *
43
+ * A primary row inside the alias row's extent records the same place twice,
44
+ * as the Setauket hamlet inside the Setauket-East Setauket census place,
45
+ * so the worldwide margin applies and population decides.
46
+ * A primary row outside it is a different place, and the region margin applies.
47
+ */
48
+ export function regionAliasMargin(
49
+ alias: Partial<Pick<CandidateTable, "min_lat" | "min_lon" | "max_lat" | "max_lon">>,
50
+ primary: Partial<Pick<CandidateTable, "latitude" | "longitude">>
51
+ ): number {
52
+ const { min_lat: minLat, min_lon: minLon, max_lat: maxLat, max_lon: maxLon } = alias
53
+ const { latitude, longitude } = primary
54
+
55
+ if (minLat == null || minLon == null || maxLat == null || maxLon == null || latitude == null || longitude == null) {
56
+ return REGION_PRIMARY_PREFERENCE_LOG10
57
+ }
58
+
59
+ return latLonBoundsContain({ minLat, minLon, maxLat, maxLon }, latitude, longitude)
60
+ ? PRIMARY_PREFERENCE_LOG10
61
+ : REGION_PRIMARY_PREFERENCE_LOG10
62
+ }
63
+
23
64
  const SEAT_PLACETYPE = "locality"
24
65
 
25
66
  /**
@@ -80,6 +121,7 @@ export type RankedRow<R> = R & {
80
121
  * Re-ranks population-ordered candidate rows.
81
122
  *
82
123
  * An alias must beat the top primary by `delta` in log10 population, in any country.
124
+ * A `delta` function returns the margin for one alias row against the top primary row.
83
125
  * The function returns the top `limit` rows.
84
126
  *
85
127
  * When `placetypes` is given, an exact tie prefers a populated `locality`.
@@ -88,7 +130,7 @@ export type RankedRow<R> = R & {
88
130
  export function rankByPrimaryPreference<R extends PrimaryPreferenceRow>(
89
131
  rows: readonly R[],
90
132
  limit: number,
91
- delta = PRIMARY_PREFERENCE_LOG10,
133
+ delta: number | ((alias: R, primary: R) => number) = PRIMARY_PREFERENCE_LOG10,
92
134
  placetypes?: ReadonlyMap<number, string>,
93
135
  exemptVariantAliases = false
94
136
  ): Array<RankedRow<R>> {
@@ -105,7 +147,8 @@ export function rankByPrimaryPreference<R extends PrimaryPreferenceRow>(
105
147
  const annotate = (r: R): RankedRow<R> => {
106
148
  const exempted = exemptVariantAliases && r.name_role === "variant" && isAliasOfPrimary(r)
107
149
  const penalized = isAliasOfPrimary(r) && !exempted
108
- const effectiveNegRank = r.neg_rank + (penalized ? delta : 0)
150
+ const margin = penalized ? (typeof delta === "number" ? delta : delta(r, topPrimary!)) : 0
151
+ const effectiveNegRank = r.neg_rank + margin
109
152
 
110
153
  return {
111
154
  ...r,
@@ -0,0 +1,210 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * Which admin database an importance build was made from.
6
+ *
7
+ * `mailwoman gazetteer importance` copies an admin database and adds `place_importance` to the copy.
8
+ * It stamps the admin file's md5 and size into the copy's `importance_source` table, the same
9
+ * identity an FST stamps as `sourceDBMD5` and `sourceDBBytes` ({@linkcode readWOFSourceIdentity}).
10
+ *
11
+ * The copy is written beside the admin database at {@linkcode importanceDatabasePath},
12
+ * a name derived from the admin md5, so the candidate build finds the importance build for
13
+ * its admin database by hashing that database, and checks the stamp before reading a score.
14
+ */
15
+
16
+ import { pathExists } from "@mailwoman/core/fs/readers/stat"
17
+ import { DatabaseClient } from "@mailwoman/sqlite/client"
18
+ import { tableExists } from "@mailwoman/sqlite/introspection"
19
+ import type { Kysely } from "kysely"
20
+ import { basename, dirname, resolvePathBuilder, type PathBuilderLike } from "path-ts"
21
+
22
+ import { type FSTSourceIdentity, readWOFSourceIdentity } from "#fst/freshness"
23
+
24
+ /**
25
+ * The one row of `importance_source`: the admin database the importance build copied.
26
+ */
27
+ export interface ImportanceSourceTable {
28
+ /**
29
+ * The admin path as the importance build was given it.
30
+ */
31
+ admin_path: string
32
+ /**
33
+ * The admin file's md5 as lowercase hex.
34
+ */
35
+ admin_md5: string
36
+ /**
37
+ * The admin file's size in bytes.
38
+ */
39
+ admin_bytes: number
40
+ }
41
+
42
+ export interface ImportanceSourceDatabase {
43
+ importance_source: ImportanceSourceTable
44
+ }
45
+
46
+ /**
47
+ * The admin database an importance build records, read back from its stamp.
48
+ */
49
+ export interface ImportanceAdminSource extends FSTSourceIdentity {
50
+ path: string
51
+ }
52
+
53
+ /**
54
+ * The count of md5 hex characters in the importance file name.
55
+ * The stamp inside the file holds the whole digest.
56
+ */
57
+ const NAME_DIGEST_LENGTH = 12
58
+
59
+ /**
60
+ * Where the importance build for an admin database lives: beside it,
61
+ * under a name built from the admin's md5.
62
+ *
63
+ * `admin-global-priority.db` with md5 `6a0c2736…` gives `admin-global-priority-importance-6a0c2736xxxx.db`.
64
+ */
65
+ export function importanceDatabasePath(adminDB: PathBuilderLike, adminMD5: string): string {
66
+ const name = basename(adminDB.toString(), ".db")
67
+
68
+ return resolvePathBuilder(dirname(adminDB.toString()))(
69
+ `${name}-importance-${adminMD5.slice(0, NAME_DIGEST_LENGTH)}.db`
70
+ ).toString()
71
+ }
72
+
73
+ /**
74
+ * Create `importance_source` and write the admin identity into it, replacing any earlier row.
75
+ */
76
+ export async function writeImportanceSource(
77
+ db: Kysely<ImportanceSourceDatabase>,
78
+ source: ImportanceAdminSource
79
+ ): Promise<void> {
80
+ await db.schema.dropTable("importance_source").ifExists().execute()
81
+
82
+ await db.schema
83
+ .createTable("importance_source")
84
+ .addColumn("admin_path", "text", (c) => c.notNull())
85
+ .addColumn("admin_md5", "text", (c) => c.notNull())
86
+ .addColumn("admin_bytes", "integer", (c) => c.notNull())
87
+ .execute()
88
+
89
+ await db
90
+ .insertInto("importance_source")
91
+ .values({ admin_path: source.path, admin_md5: source.md5, admin_bytes: source.bytes })
92
+ .execute()
93
+ }
94
+
95
+ /**
96
+ * Read the admin identity an importance build stamped.
97
+ *
98
+ * Returns `null` only when the file has no `importance_source` table.
99
+ * Such a file is an importance build that predates the stamp.
100
+ *
101
+ * @throws When the file is missing, or when the table holds other than one row.
102
+ */
103
+ export async function readImportanceSource(importanceDB: PathBuilderLike): Promise<ImportanceAdminSource | null> {
104
+ if (!(await pathExists(importanceDB))) {
105
+ throw new Error(`importance source: ${importanceDB} not found`)
106
+ }
107
+
108
+ using db = new DatabaseClient<ImportanceSourceDatabase>(importanceDB, { readOnly: true })
109
+
110
+ if (!tableExists(db, "importance_source")) return null
111
+
112
+ const rows = await db.selectFrom("importance_source").selectAll().execute()
113
+
114
+ if (rows.length !== 1) {
115
+ throw new Error(`importance source: ${importanceDB} holds ${rows.length} importance_source rows, expected 1`)
116
+ }
117
+
118
+ const [row] = rows
119
+
120
+ return { path: row!.admin_path, md5: row!.admin_md5, bytes: Number(row!.admin_bytes) }
121
+ }
122
+
123
+ /**
124
+ * The importance build a reader uses, with its own md5 for a manifest or a report.
125
+ */
126
+ export interface ResolvedImportance {
127
+ path: string
128
+ md5: string
129
+ }
130
+
131
+ /**
132
+ * A refusal from {@linkcode resolveImportanceForAdmin}.
133
+ * Its message gives the admin path and the importance path.
134
+ */
135
+ export class ImportanceSourceError extends Error {
136
+ constructor(message: string) {
137
+ super(message)
138
+
139
+ this.name = "ImportanceSourceError"
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Find the importance build that belongs with `adminDB` and check its stamp.
145
+ *
146
+ * Every reader of importance scores finds its file here, from the admin database it reads.
147
+ * Without `importanceDB` the file is the one {@linkcode importanceDatabasePath} gives for the admin md5.
148
+ * A given `importanceDB` is checked the same way.
149
+ *
150
+ * @throws {ImportanceSourceError} When no importance build exists for the admin database,
151
+ * when the file has no `importance_source` stamp, or when its stamp records another admin database.
152
+ */
153
+ export async function resolveImportanceForAdmin(
154
+ adminDB: PathBuilderLike,
155
+ importanceDB?: PathBuilderLike
156
+ ): Promise<ResolvedImportance> {
157
+ if (!(await pathExists(adminDB))) {
158
+ throw new ImportanceSourceError(`admin ${adminDB} does not exist, so no importance build can be matched to it.`)
159
+ }
160
+
161
+ const admin = await readWOFSourceIdentity(adminDB)
162
+ const path = (importanceDB ?? importanceDatabasePath(adminDB, admin.md5)).toString()
163
+ const rebuild = `mailwoman gazetteer importance --admin ${adminDB}`
164
+
165
+ if (!(await pathExists(path))) {
166
+ throw new ImportanceSourceError(
167
+ `no importance build for admin ${adminDB} (md5 ${admin.md5}): ${path} does not exist. ` +
168
+ `Build it with \`${rebuild}\`.`
169
+ )
170
+ }
171
+
172
+ const stamped = await readImportanceSource(path)
173
+
174
+ if (!stamped) {
175
+ throw new ImportanceSourceError(
176
+ `importance ${path} records no admin database (no importance_source table), so it cannot be ` +
177
+ `matched to admin ${adminDB} (md5 ${admin.md5}). Rebuild it with \`${rebuild}\`.`
178
+ )
179
+ }
180
+
181
+ if (stamped.md5 !== admin.md5 || stamped.bytes !== admin.bytes) {
182
+ throw new ImportanceSourceError(
183
+ `importance ${path} was built from admin ${stamped.path} (md5 ${stamped.md5}, ` +
184
+ `${stamped.bytes} bytes), not admin ${adminDB} (md5 ${admin.md5}, ${admin.bytes} bytes). ` +
185
+ `Rebuild it with \`${rebuild}\`.`
186
+ )
187
+ }
188
+
189
+ return { path, md5: (await readWOFSourceIdentity(path)).md5 }
190
+ }
191
+
192
+ /**
193
+ * {@linkcode resolveImportanceForAdmin} for a report that goes on without scores.
194
+ *
195
+ * A refusal comes back as its message, and the message gives both paths.
196
+ * The report states that message as the reason it read no scores.
197
+ *
198
+ * @throws Any error other than an {@linkcode ImportanceSourceError}.
199
+ */
200
+ export async function resolveImportanceOrRefusal(
201
+ adminDB: PathBuilderLike
202
+ ): Promise<(ResolvedImportance & { refusal: null }) | { path: null; md5: null; refusal: string }> {
203
+ try {
204
+ return { ...(await resolveImportanceForAdmin(adminDB)), refusal: null }
205
+ } catch (error) {
206
+ if (error instanceof ImportanceSourceError) return { path: null, md5: null, refusal: error.message }
207
+
208
+ throw error
209
+ }
210
+ }
@@ -0,0 +1,79 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * The `overture_wof_match` table: which Who's On First record each matched Overture division is.
6
+ *
7
+ * The admin gazetteer is a Collective Database.
8
+ * Its Overture Divisions part is ODbL-1.0, and the Overture step writes every division as its
9
+ * own row in the Overture id range rather than adding its names or Wikidata id to a WOF record.
10
+ *
11
+ * A lookup that returns each place once reads the match from this table
12
+ * instead of from an altered WOF row.
13
+ * The table is derived from Overture data, so it belongs to the Overture part
14
+ * and travels with that part's ODbL offer.
15
+ *
16
+ * The admin build writes it, the candidate build copies it into `candidate.db`,
17
+ * and the Overture part's offer file includes it.
18
+ */
19
+
20
+ import type { DatabaseClient } from "@mailwoman/sqlite/client"
21
+ import type { Kysely } from "kysely"
22
+
23
+ import { hasTable } from "#sqlite-utils"
24
+
25
+ /**
26
+ * The table name every writer and reader uses.
27
+ */
28
+ export const OVERTURE_WOF_MATCH_TABLE = "overture_wof_match"
29
+
30
+ /**
31
+ * One matched division: its Overture-part row and the WOF record it names.
32
+ */
33
+ export interface OvertureWOFMatchTable {
34
+ /**
35
+ * The division's row id, inside the Overture id range.
36
+ */
37
+ overture_id: number
38
+ /**
39
+ * The WOF record the division matched.
40
+ */
41
+ wof_id: number
42
+ /**
43
+ * The evidence that matched them: `country`, `wikidata`, `geonames` or `name`.
44
+ */
45
+ match_by: string
46
+ }
47
+
48
+ export interface OvertureWOFMatchDatabase {
49
+ overture_wof_match: OvertureWOFMatchTable
50
+ }
51
+
52
+ /**
53
+ * Create the table, keyed by the Overture row so each division records at most one match.
54
+ */
55
+ export async function createOvertureWOFMatchTable<DB extends OvertureWOFMatchDatabase>(db: Kysely<DB>): Promise<void> {
56
+ await db.schema
57
+ .createTable(OVERTURE_WOF_MATCH_TABLE)
58
+ .ifNotExists()
59
+ .addColumn("overture_id", "integer", (c) => c.primaryKey())
60
+ .addColumn("wof_id", "integer", (c) => c.notNull())
61
+ .addColumn("match_by", "text", (c) => c.notNull())
62
+ .execute()
63
+ }
64
+
65
+ /**
66
+ * Every recorded match, or `null` when the database predates the table.
67
+ *
68
+ * A database without the table was built before the Overture rows became an independent part,
69
+ * when a matched division wrote no row of its own, so its matches are unrecorded rather than zero.
70
+ */
71
+ export function readOvertureWOFMatches<DB>(db: DatabaseClient<DB>): OvertureWOFMatchTable[] | null {
72
+ if (!hasTable(db, OVERTURE_WOF_MATCH_TABLE)) return null
73
+
74
+ return (
75
+ db
76
+ .prepare(`SELECT overture_id, wof_id, match_by FROM ${OVERTURE_WOF_MATCH_TABLE} ORDER BY overture_id`)
77
+ .all() as Array<{ overture_id: number; wof_id: number; match_by: string }>
78
+ ).map((row) => ({ overture_id: Number(row.overture_id), wof_id: Number(row.wof_id), match_by: String(row.match_by) }))
79
+ }
@@ -1,6 +1,11 @@
1
1
  // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
2
  // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
3
 
4
+ /**
5
+ * The `place_importance` table of an admin gazetteer: its columns, its DDL, the referential
6
+ * score derived from population, and the blend of that score with the encyclopedic one.
7
+ */
8
+
4
9
  import { referentialFromPopulation } from "@mailwoman/core/resolver"
5
10
  import { allRows } from "@mailwoman/core/utils"
6
11
  import type { DatabaseClient } from "@mailwoman/sqlite/client"
@@ -72,6 +77,87 @@ export async function createPlaceImportanceTable(db: Kysely<PlaceImportanceDatab
72
77
  .execute()
73
78
  }
74
79
 
80
+ /**
81
+ * Describes one row of the `place_population_estimate` table: a sub-locality's population estimated
82
+ * from the settlement that contains it, for a place the admin database records no population for.
83
+ *
84
+ * The estimate is the containing settlement's population divided by one more than the
85
+ * number of places of the same placetype that settlement contains.
86
+ * The `+ 1` keeps a share for the part of the settlement no recorded child covers,
87
+ * so an estimate is always smaller than its parent's population.
88
+ */
89
+ export interface PlacePopulationEstimateTable {
90
+ id: number
91
+
92
+ /**
93
+ * The point estimate.
94
+ */
95
+ population: number
96
+
97
+ /**
98
+ * The value the candidate table ranks the place by: the point estimate scaled by the lower decile
99
+ * of measured / estimated population over every sub-locality that has a measured population.
100
+ *
101
+ * A ranked estimate outranks a measured place only where nine in ten measured sub-localities would.
102
+ */
103
+ rank_population: number
104
+
105
+ /**
106
+ * The settlement whose population the estimate divides: the place's `parent_id`.
107
+ */
108
+ parent_id: number
109
+
110
+ /**
111
+ * The parent's current children with this place's placetype, the place included.
112
+ */
113
+ siblings: number
114
+ }
115
+
116
+ /**
117
+ * Types the `place_population_estimate` table of an importance database.
118
+ */
119
+ export interface PlacePopulationEstimateDatabase {
120
+ place_population_estimate: PlacePopulationEstimateTable
121
+ }
122
+
123
+ /**
124
+ * Drops and recreates the `place_population_estimate` table.
125
+ */
126
+ export async function createPlacePopulationEstimateTable(db: Kysely<PlacePopulationEstimateDatabase>): Promise<void> {
127
+ await db.schema.dropTable("place_population_estimate").ifExists().execute()
128
+
129
+ await db.schema
130
+ .createTable("place_population_estimate")
131
+ .addColumn("id", "integer", (c) => c.primaryKey())
132
+ .addColumn("population", "real", (c) => c.notNull())
133
+ .addColumn("rank_population", "real", (c) => c.notNull())
134
+ .addColumn("parent_id", "integer", (c) => c.notNull())
135
+ .addColumn("siblings", "integer", (c) => c.notNull())
136
+ .execute()
137
+ }
138
+
139
+ /**
140
+ * Reads every estimate's ranking population (`rank_population`) from an
141
+ * importance database, keyed by WOF id.
142
+ *
143
+ * @throws When the database has no `place_population_estimate` table, because the
144
+ * importance build that wrote it ran without sub-locality estimates.
145
+ */
146
+ export function loadPopulationEstimates<DB>(db: DatabaseClient<DB>): Map<number, number> {
147
+ if (!tableColumns(db, "place_population_estimate").has("rank_population")) {
148
+ throw new Error(
149
+ "place_population_estimate: the importance database has no estimates table. " +
150
+ "Rebuild it with `mailwoman gazetteer importance --sub-locality-estimates`."
151
+ )
152
+ }
153
+
154
+ const rows = allRows<{ id: number; rank_population: number }>(
155
+ db.prepare("SELECT id, rank_population FROM place_population_estimate")
156
+ )
157
+
158
+ return new Map(rows.map((row) => [Number(row.id), Number(row.rank_population)]))
159
+ }
160
+
75
161
  /**
76
162
  * Caps how far the encyclopedic score may raise a place's blended importance above its referential score.
77
163
  *
package/lib/schema.ts CHANGED
@@ -85,7 +85,7 @@ export interface SprTable {
85
85
  *
86
86
  * Real WOF dumps omit it.
87
87
  * These are the aliases eligible to join the name-exact tier.
88
- * See `unified-schema.ts` for the full interface.
88
+ * See `schema/unified.ts` for the full interface.
89
89
  */
90
90
  export interface NamesTable {
91
91
  id: number
@@ -102,7 +102,7 @@ export interface NamesTable {
102
102
  name: string
103
103
  lastmodified: number
104
104
  /**
105
- * The dataset the row came from, one of `ROW_SOURCES` in `unified-schema.ts`.
105
+ * The dataset the row came from, one of `ROW_SOURCES` in `schema/unified.ts`.
106
106
  *
107
107
  * Databases built before the column existed have no such column.
108
108
  */
@@ -177,7 +177,7 @@ export interface ConcordancesTable {
177
177
  other_source: string
178
178
  lastmodified: number
179
179
  /**
180
- * The dataset the row came from, one of `ROW_SOURCES` in `unified-schema.ts`.
180
+ * The dataset the row came from, one of `ROW_SOURCES` in `schema/unified.ts`.
181
181
  *
182
182
  * Databases built before the column existed have no such column.
183
183
  */
@@ -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
- import { tryParsingJSON } from "@mailwoman/core/json"
4
+ import { tryParsingJSON } from "@mailwoman/core/values/json"
5
5
  import type { DatabaseClient } from "@mailwoman/sqlite/client"
6
6
 
7
7
  import { ADDRESS_CONVENTION_TABLE, type Convention, type ConventionSource } from "#convention"
@@ -28,6 +28,8 @@ import { UPRN_COVERAGE_H3_RESOLUTION, UPRN_H3_RESOLUTION, uprnH3Cell } from "#up
28
28
  */
29
29
  export const UPRN_EXISTENCE_FOLD = foldIdentity((s) => s)
30
30
 
31
+ // country-branch: OS Open UPRN is Ordnance Survey's product, and its coverage is Great Britain.
32
+ // The countries recorded in the layer's manifest would replace the list.
31
33
  /**
32
34
  * The countries OS Open uprn covers.
33
35
  *