@mailwoman/resolver-wof-sqlite 11.2.0 → 11.4.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 (453) 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 +42 -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} +56 -5
  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 +293 -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 +6 -1
  93. package/out/address/number-forms.d.ts.map +1 -1
  94. package/out/address/number-forms.js +36 -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} +40 -9
  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/labels/street/normalize.d.ts +207 -0
  256. package/out/labels/street/normalize.d.ts.map +1 -0
  257. package/out/{street → labels/street}/normalize.js +198 -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 +0 -130
  404. package/out/street/normalize.d.ts.map +0 -1
  405. package/out/street/normalize.js.map +0 -1
  406. package/out/street/segment-schema.d.ts.map +0 -1
  407. package/out/street/segment-schema.js.map +0 -1
  408. package/out/street/table.d.ts.map +0 -1
  409. package/out/street/table.js.map +0 -1
  410. package/out/street.d.ts +0 -9
  411. package/out/street.d.ts.map +0 -1
  412. package/out/street.js +0 -11
  413. package/out/street.js.map +0 -1
  414. package/out/types.d.ts.map +0 -1
  415. package/out/types.js.map +0 -1
  416. package/out/unified-schema.d.ts.map +0 -1
  417. package/out/unified-schema.js.map +0 -1
  418. package/out/weights-overlay-linker.d.ts.map +0 -1
  419. package/out/weights-overlay-linker.js.map +0 -1
  420. /package/lib/{coverage-manifest-schema.ts → candidate/coverage-manifest.ts} +0 -0
  421. /package/lib/{postal/city → labels/locality/postal-city}/alias/schema.ts +0 -0
  422. /package/lib/{street → labels/street}/morphology/fst/builder.ts +0 -0
  423. /package/lib/{exact-match.ts → lookup/exact-match.ts} +0 -0
  424. /package/lib/{name-score.ts → ranking/name-score.ts} +0 -0
  425. /package/lib/{proximity-rerank.ts → ranking/proximity-rerank.ts} +0 -0
  426. /package/lib/{ranking-weights.ts → ranking/weights.ts} +0 -0
  427. /package/lib/{importance-source.ts → schema/importance-source.ts} +0 -0
  428. /package/lib/{polygon-schema.ts → schema/polygon.ts} +0 -0
  429. /package/lib/{unified-schema.ts → schema/unified.ts} +0 -0
  430. /package/out/{capitals.d.ts → candidate/capitals.d.ts} +0 -0
  431. /package/out/{search-fetch.js → fts/search-fetch.js} +0 -0
  432. /package/out/{postal/city → labels/locality/postal-city}/alias/lookup.js +0 -0
  433. /package/out/{postal/city → labels/locality/postal-city}/alias/schema.d.ts +0 -0
  434. /package/out/{postal/city → labels/locality/postal-city}/alias/schema.js +0 -0
  435. /package/out/{postal/city → labels/locality/postal-city}/candidate-schema.js +0 -0
  436. /package/out/{street → labels/street}/centroid/schema.js +0 -0
  437. /package/out/{street → labels/street}/morphology/fst/builder.d.ts +0 -0
  438. /package/out/{street → labels/street}/morphology/fst/builder.js +0 -0
  439. /package/out/{street → labels/street}/morphology/fst/loader.d.ts +0 -0
  440. /package/out/{street → labels/street}/name-lookup.d.ts +0 -0
  441. /package/out/{street → labels/street}/segment-schema.js +0 -0
  442. /package/out/{street → labels/street}/table.d.ts +0 -0
  443. /package/out/{exact-match.d.ts → lookup/exact-match.d.ts} +0 -0
  444. /package/out/{exact-match.js → lookup/exact-match.js} +0 -0
  445. /package/out/{extracts.d.ts → lookup/extracts.d.ts} +0 -0
  446. /package/out/{types.js → lookup/types.js} +0 -0
  447. /package/out/{name-score.d.ts → ranking/name-score.d.ts} +0 -0
  448. /package/out/{name-score.js → ranking/name-score.js} +0 -0
  449. /package/out/{primary-preference.d.ts → ranking/primary-preference.d.ts} +0 -0
  450. /package/out/{proximity-rerank.d.ts → ranking/proximity-rerank.d.ts} +0 -0
  451. /package/out/{proximity-rerank.js → ranking/proximity-rerank.js} +0 -0
  452. /package/out/{importance-source.d.ts → schema/importance-source.d.ts} +0 -0
  453. /package/out/{importance-source.js → schema/importance-source.js} +0 -0
@@ -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
+ }
@@ -5,14 +5,15 @@
5
5
  * @file Pass 2 of the candidate build: explode `place_search.alt_names` into distinct alias rows.
6
6
  */
7
7
 
8
+ import { isOverturePartID } from "@mailwoman/core/resolver/synthetic-id-ranges"
8
9
  import type { DatabaseClient } from "@mailwoman/sqlite/client"
9
10
  import { tableExists } from "@mailwoman/sqlite/introspection"
10
11
 
11
12
  import type { PlaceAttrs, StageRow } from "#candidate/place-attrs"
12
13
  import type { CandidateDatabase } from "#candidate/schema"
13
14
  import { ALIAS_SEPARATOR } from "#fts"
15
+ import { type NameKey, normalizeLocalityForKey, withoutApostropheLikeMarks } from "#labels/street/normalize"
14
16
  import type { WOFDatabase } from "#schema"
15
- import { type NameKey, normalizeLocalityForKey, withoutApostropheLikeMarks } from "#street/normalize"
16
17
 
17
18
  /**
18
19
  * The official name of every current region, keyed `${country id}\0${name key}` →
@@ -22,14 +23,19 @@ import { type NameKey, normalizeLocalityForKey, withoutApostropheLikeMarks } fro
22
23
  *
23
24
  * The positive evidence behind the alias refusal below: a name is refused from a region's
24
25
  * bag only when another region of the same country holds it as its official name.
26
+ *
27
+ * `rest` leaves out the regions of the Overture Divisions part and `all` holds every region.
28
+ * The gazetteer is a Collective Database whose Overture part is ODbL, so a region outside that part
29
+ * reads `rest`, and an Overture division's official name never refuses a WOF or GeoNames region's alias.
25
30
  */
26
31
  function officialNameHoldersByRegion(
27
32
  src: DatabaseClient<WOFDatabase>,
28
33
  ccID: (code: string | null) => number
29
- ): Map<string, number> {
30
- const keys = new Map<string, number>()
34
+ ): { rest: Map<string, number>; all: Map<string, number> } {
35
+ const rest = new Map<string, number>()
36
+ const all = new Map<string, number>()
31
37
 
32
- if (!tableExists(src, "names")) return keys
38
+ if (!tableExists(src, "names")) return { rest, all }
33
39
 
34
40
  for (const r of src
35
41
  .prepare(
@@ -41,11 +47,18 @@ function officialNameHoldersByRegion(
41
47
  const k = normalizeLocalityForKey(String(r.name ?? ""))
42
48
 
43
49
  if (k) {
44
- keys.set(`${ccID(r.country as string | null)}\0${k}`, Number(r.id))
50
+ const key = `${ccID(r.country as string | null)}\0${k}`
51
+ const id = Number(r.id)
52
+
53
+ all.set(key, id)
54
+
55
+ if (!isOverturePartID(id)) {
56
+ rest.set(key, id)
57
+ }
45
58
  }
46
59
  }
47
60
 
48
- return keys
61
+ return { rest, all }
49
62
  }
50
63
 
51
64
  /**
@@ -95,7 +108,7 @@ export function explodeAliasBags(
95
108
  const official =
96
109
  typeof opts.regionPlacetypeID === "number" && opts.ccID
97
110
  ? officialNameHoldersByRegion(src, opts.ccID)
98
- : new Map<string, number>()
111
+ : { rest: new Map<string, number>(), all: new Map<string, number>() }
99
112
 
100
113
  out.exec("BEGIN")
101
114
 
@@ -108,10 +121,11 @@ export function explodeAliasBags(
108
121
  const seen = new Set<string>([a.pkey])
109
122
  const markFree = new Set<string>()
110
123
  const isRegion = a.ptid === opts.regionPlacetypeID
124
+ const holders = isOverturePartID(id) ? official.all : official.rest
111
125
 
112
126
  const refused = (k: string): boolean => {
113
127
  if (!isRegion) return false
114
- const holder = official.get(`${a.cid}\0${k}`)
128
+ const holder = holders.get(`${a.cid}\0${k}`)
115
129
 
116
130
  return typeof holder === "number" && holder !== id
117
131
  }
@@ -76,7 +76,7 @@ import { sql, type Kysely } from "kysely"
76
76
  // parameter is invariant, so the DDL functions must take the full database type their caller holds.
77
77
  // Erased at runtime.
78
78
  import type { CandidateDatabase } from "#candidate/schema"
79
- import type { NameKey } from "#street/normalize"
79
+ import type { NameKey } from "#labels/street/normalize"
80
80
 
81
81
  /**
82
82
  * The deepest chain the sidecar stores per place.
@@ -5,6 +5,7 @@
5
5
  * @file Pass 3b of the candidate build — the containment sidecar (closure rows + interval labels).
6
6
  */
7
7
 
8
+ import { isOverturePartID } from "@mailwoman/core/resolver/synthetic-id-ranges"
8
9
  import type { DatabaseClient } from "@mailwoman/sqlite/client"
9
10
 
10
11
  import { placetypeDepth } from "#ancestry"
@@ -77,7 +78,15 @@ export async function buildAncestorsSidecar(ctx: {
77
78
  ancestorRows++
78
79
  }
79
80
 
80
- const canonical = edges[0]!.aid
81
+ // The gazetteer is a Collective Database whose Overture Divisions part is ODbL.
82
+ // The interval tree links a place only to a parent of its own part, so an Overture division
83
+ // under a WOF record leaves that record's labels as they are without the Overture divisions.
84
+ // The closure rows above keep every edge, and containment across the parts
85
+ // reads them instead of the labels.
86
+ const childOverture = isOverturePartID(childID)
87
+ const canonical = edges.find((edge) => isOverturePartID(edge.aid) === childOverture)?.aid
88
+
89
+ if (typeof canonical !== "number") return
81
90
 
82
91
  canonicalParentOf.set(childID, canonical)
83
92
 
@@ -138,8 +147,10 @@ export async function buildAncestorsSidecar(ctx: {
138
147
 
139
148
  const roots = [...forest].filter((id) => !canonicalParentOf.has(id))
140
149
 
150
+ // The Overture part's trees are numbered after every other tree, so the other parts' labels
151
+ // are the labels a build without the Overture divisions gives them.
141
152
  // oxlint-disable-next-line unicorn/no-array-sort -- sorts an array this pass built
142
- roots.sort((a, b) => a - b)
153
+ roots.sort((a, b) => Number(isOverturePartID(a)) - Number(isOverturePartID(b)) || a - b)
143
154
 
144
155
  let counter = 0
145
156
 
@@ -8,7 +8,7 @@
8
8
  import { bareAdminName } from "@mailwoman/codex/country/bare-admin-names"
9
9
 
10
10
  import type { PlaceAttrs, StageRow } from "#candidate/place-attrs"
11
- import { normalizeLocalityForKey } from "#street/normalize"
11
+ import { normalizeLocalityForKey } from "#labels/street/normalize"
12
12
 
13
13
  /**
14
14
  * Stages an alias row under the bare form of every place name a country writes with an admin-unit suffix.
@@ -14,11 +14,11 @@
14
14
  * keeps the coordinate radius from promoting a capital's same-name neighbors (`capitals.ts`).
15
15
  */
16
16
 
17
- import { tryParsingJSON } from "@mailwoman/core/json"
17
+ import { tryParsingJSON } from "@mailwoman/core/values/json"
18
18
  import type { DatabaseClient } from "@mailwoman/sqlite/client"
19
19
  import type { Kysely } from "kysely"
20
20
 
21
- import type { CapitalPoint } from "#capitals"
21
+ import type { CapitalPoint } from "#candidate/capitals"
22
22
  import { hasTable } from "#sqlite-utils"
23
23
 
24
24
  /**
@@ -47,7 +47,7 @@ export interface CapitalTable {
47
47
  /**
48
48
  * Create the table on a build in progress.
49
49
  *
50
- * Async because Kysely's schema-builder is.
50
+ * The function is async because Kysely's schema builder is asynchronous.
51
51
  * Called from the candidate build's DDL phase alongside the other typed builders.
52
52
  */
53
53
  export async function createCapitalTable<DB extends { capital: CapitalTable }>(db: Kysely<DB>): Promise<void> {
@@ -20,7 +20,7 @@
20
20
 
21
21
  import { haversine } from "@mailwoman/spatial/geometries/point/distance"
22
22
 
23
- import { normalizeLocalityForKey } from "#street/normalize"
23
+ import { normalizeLocalityForKey } from "#labels/street/normalize"
24
24
 
25
25
  /**
26
26
  * Capital status of one candidate: national capital, admin-1 seat, or neither.
@@ -4,7 +4,7 @@
4
4
  import { enumerateCountryDisplayNames } from "@mailwoman/codex/country"
5
5
 
6
6
  import type { PlaceAttrs, StageRow } from "#candidate/place-attrs"
7
- import { normalizeLocalityForKey } from "#street/normalize"
7
+ import { normalizeLocalityForKey } from "#labels/street/normalize"
8
8
 
9
9
  /**
10
10
  * Stages each country name that `Intl.DisplayNames` renders in the codex display-name
@@ -8,8 +8,8 @@ import type { PathBuilderLike } from "path-ts"
8
8
  import { CANDIDATE_ANCESTOR_COLUMNS, CANDIDATE_ANCESTOR_TABLE } from "#candidate/ancestors/schema"
9
9
  import type { PlaceAttrs, StageRow } from "#candidate/place-attrs"
10
10
  import type { CandidateDatabase } from "#candidate/schema"
11
+ import { normalizeLocalityForKey } from "#labels/street/normalize"
11
12
  import type { WOFDatabase } from "#schema"
12
- import { normalizeLocalityForKey } from "#street/normalize"
13
13
 
14
14
  function extractRegionAncestry(pc: DatabaseClient<WOFDatabase>, attrs: Map<number, PlaceAttrs>): Map<number, number> {
15
15
  const regionOf = new Map<number, number>()
@@ -41,7 +41,7 @@ function extractRegionAncestry(pc: DatabaseClient<WOFDatabase>, attrs: Map<numbe
41
41
  * the row also gets that region's scope and the region's ancestor chain.
42
42
  * The stored ancestors then agree with the row's scope.
43
43
  */
44
- export function foldExtract(ctx: {
44
+ export function stageExtractRows(ctx: {
45
45
  out: DatabaseClient<CandidateDatabase>
46
46
  extractPath: PathBuilderLike
47
47
  extractPlacetype: "postalcode" | "locality"
@@ -77,11 +77,14 @@ export function foldExtract(ctx: {
77
77
 
78
78
  out.exec("BEGIN")
79
79
 
80
+ // A deprecated record is one its source withdrew as wrong, and it stays out whatever point it holds.
81
+ // A record that only ceased (`is_current = 0`) stays in: a terminated postcode still
82
+ // appears in written addresses, and the extract keeps its last point.
80
83
  for (const r of pc
81
84
  .prepare(
82
85
  `SELECT id, name, country, latitude, longitude,
83
86
  min_latitude AS mnlat, min_longitude AS mnlon, max_latitude AS mxlat, max_longitude AS mxlon
84
- FROM spr WHERE placetype = ? AND latitude != 0 AND longitude != 0`
87
+ FROM spr WHERE placetype = ? AND latitude != 0 AND longitude != 0 AND is_deprecated = 0`
85
88
  )
86
89
  .iterate(extractPlacetype)) {
87
90
  const name = String(r.name ?? "")
@@ -164,7 +167,7 @@ export function foldExtract(ctx: {
164
167
 
165
168
  out.exec("COMMIT")
166
169
  } else {
167
- progress("postcode-aliases", `${extractPath} has no \`names\` table — no delivery-city aliases to fold`)
170
+ progress("postcode-aliases", `${extractPath} has no \`names\` table — no delivery-city aliases to add`)
168
171
  }
169
172
 
170
173
  return { primaries, aliases, scoped, ancestorRows }
@@ -35,12 +35,14 @@
35
35
  * at the position population assigned it.
36
36
  */
37
37
 
38
+ import { isOverturePartID } from "@mailwoman/core/resolver/synthetic-id-ranges"
38
39
  import { haversine } from "@mailwoman/spatial/geometries/point/distance"
39
40
  import { DatabaseClient } from "@mailwoman/sqlite/client"
40
41
  import type { PathBuilderLike } from "path-ts"
41
42
 
42
43
  import type { CandidateDatabase } from "#candidate/schema"
43
- import { normalizeLocalityForKey } from "#street/normalize"
44
+ import { normalizeLocalityForKey } from "#labels/street/normalize"
45
+ import { loadPopulationEstimates, type PlacePopulationEstimateDatabase } from "#schema/place-importance"
44
46
 
45
47
  /**
46
48
  * How far apart two artifacts may put the same place's centroid and still be read as the same place.
@@ -64,6 +66,10 @@ interface ScoredPlace {
64
66
  lat: number
65
67
  lon: number
66
68
  importance: number
69
+ /**
70
+ * Whether the scored place is a row of the Overture Divisions part.
71
+ */
72
+ overture: boolean
67
73
  }
68
74
 
69
75
  /**
@@ -86,6 +92,11 @@ export interface ImportanceIndexStats {
86
92
  * (non-Latin punctuation-only names, blanks).
87
93
  */
88
94
  unkeyable: number
95
+ /**
96
+ * Population estimates read from `place_population_estimate`, or null
97
+ * when the loader wasn't asked for them.
98
+ */
99
+ estimates: number | null
89
100
  }
90
101
 
91
102
  /**
@@ -120,10 +131,36 @@ export class ImportanceIndex {
120
131
  * It doesn't mean the radius is too tight.
121
132
  */
122
133
  refused = 0
134
+ /**
135
+ * Places {@link estimatedPopulation} returned an estimate for.
136
+ */
137
+ estimated = 0
123
138
 
124
- constructor(groups: Map<string, ScoredPlace[]>, stats: ImportanceIndexStats) {
139
+ readonly #estimates: ReadonlyMap<number, number>
140
+
141
+ constructor(
142
+ groups: Map<string, ScoredPlace[]>,
143
+ stats: ImportanceIndexStats,
144
+ estimates: ReadonlyMap<number, number> = new Map()
145
+ ) {
125
146
  this.#groups = groups
126
147
  this.stats = stats
148
+ this.#estimates = estimates
149
+ }
150
+
151
+ /**
152
+ * The ranking population the importance build estimated for the place with WOF
153
+ * id `id`, or undefined when it holds none.
154
+ * Ask only for a place without a measured population.
155
+ */
156
+ estimatedPopulation(id: number): number | undefined {
157
+ const estimate = this.#estimates.get(id)
158
+
159
+ if (typeof estimate === "number") {
160
+ this.estimated++
161
+ }
162
+
163
+ return estimate
127
164
  }
128
165
 
129
166
  /**
@@ -136,8 +173,20 @@ export class ImportanceIndex {
136
173
  *
137
174
  * The source column already contains a population-derived fallback where one exists.
138
175
  * A second fallback would make an absence indistinguishable from a measurement.
176
+ *
177
+ * The gazetteer is a Collective Database whose Overture Divisions part is ODbL.
178
+ * A row outside that part (`overtureRow` false) reads only scores of places outside it,
179
+ * so an Overture division's Wikidata-joined score never reaches a WOF or GeoNames row.
180
+ * An Overture row may read any score.
139
181
  */
140
- find(name: string, country: string | null, placetype: string | null, lat: number, lon: number): number | null {
182
+ find(
183
+ name: string,
184
+ country: string | null,
185
+ placetype: string | null,
186
+ lat: number,
187
+ lon: number,
188
+ overtureRow = false
189
+ ): number | null {
141
190
  const nameKey = normalizeLocalityForKey(name)
142
191
 
143
192
  if (!nameKey) return null
@@ -148,8 +197,13 @@ export class ImportanceIndex {
148
197
 
149
198
  let best: ScoredPlace | null = null
150
199
  let bestKm = Infinity
200
+ let eligible = false
151
201
 
152
202
  for (const place of group) {
203
+ if (place.overture && !overtureRow) continue
204
+
205
+ eligible = true
206
+
153
207
  const km = haversine(lat, lon, place.lat, place.lon)
154
208
 
155
209
  if (km < bestKm) {
@@ -158,6 +212,9 @@ export class ImportanceIndex {
158
212
  }
159
213
  }
160
214
 
215
+ // A row outside the Overture part reads a group of only Overture scores as an absent group.
216
+ if (!eligible) return null
217
+
161
218
  if (!best || bestKm > IMPORTANCE_JOIN_RADIUS_KM) {
162
219
  this.refused++
163
220
 
@@ -183,9 +240,19 @@ export class ImportanceIndex {
183
240
  *
184
241
  * The whole table is held in memory on purpose, because the build probes it once for every place
185
242
  * and the alternative is a prepared statement per place against a multi-gigabyte database.
243
+ *
244
+ * With `populationEstimates`, it also reads `place_population_estimate`, keyed by WOF id
245
+ * because the importance database is a copy of the admin database the candidate build reads.
246
+ *
247
+ * @throws With `populationEstimates`, when the database holds no estimates table.
186
248
  */
187
- export function loadImportanceIndex(databasePath: PathBuilderLike): ImportanceIndex {
188
- using db = new DatabaseClient<CandidateDatabase>(databasePath, { readOnly: true })
249
+ export function loadImportanceIndex(
250
+ databasePath: PathBuilderLike,
251
+ options: { populationEstimates?: boolean } = {}
252
+ ): ImportanceIndex {
253
+ using db = new DatabaseClient<CandidateDatabase & PlacePopulationEstimateDatabase>(databasePath, {
254
+ readOnly: true,
255
+ })
189
256
 
190
257
  const groups = new Map<string, ScoredPlace[]>()
191
258
  let places = 0
@@ -193,7 +260,7 @@ export function loadImportanceIndex(databasePath: PathBuilderLike): ImportanceIn
193
260
 
194
261
  for (const row of db
195
262
  .prepare(
196
- `SELECT s.name AS name, s.country AS country, s.placetype AS placetype,
263
+ `SELECT s.id AS id, s.name AS name, s.country AS country, s.placetype AS placetype,
197
264
  s.latitude AS latitude, s.longitude AS longitude, i.importance AS importance
198
265
  FROM place_importance i JOIN spr s ON s.id = i.id
199
266
  WHERE s.is_current != 0 AND s.is_deprecated = 0`
@@ -218,10 +285,21 @@ export function loadImportanceIndex(databasePath: PathBuilderLike): ImportanceIn
218
285
  groups.set(key, group)
219
286
  }
220
287
 
221
- group.push({ lat: Number(row.latitude), lon: Number(row.longitude), importance })
288
+ group.push({
289
+ lat: Number(row.latitude),
290
+ lon: Number(row.longitude),
291
+ importance,
292
+ overture: isOverturePartID(Number(row.id)),
293
+ })
222
294
 
223
295
  places++
224
296
  }
225
297
 
226
- return new ImportanceIndex(groups, { places, keys: groups.size, unkeyable })
298
+ const estimates = options.populationEstimates ? loadPopulationEstimates(db) : null
299
+
300
+ return new ImportanceIndex(
301
+ groups,
302
+ { places, keys: groups.size, unkeyable, estimates: estimates ? estimates.size : null },
303
+ estimates ?? undefined
304
+ )
227
305
  }
@@ -12,8 +12,8 @@
12
12
  import type { DatabaseClient } from "@mailwoman/sqlite/client"
13
13
 
14
14
  import type { CandidateDatabase } from "#candidate/schema"
15
+ import { type NameKey, withArabicLetterVariantsFolded } from "#labels/street/normalize"
15
16
  import { hasTable } from "#sqlite-utils"
16
- import { type NameKey, withArabicLetterVariantsFolded } from "#street/normalize"
17
17
 
18
18
  /**
19
19
  * The table that lists the folds applied to the artifact's `name_key` column, one row per fold.
@@ -1,9 +1,14 @@
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 { expandPlacetypeFilter } from "@mailwoman/codex/placetype-map"
4
+ import { expandPlacetypeFilter } from "@mailwoman/codex/labels/placetype-map"
5
5
  import type { VariantAliasExemption } from "@mailwoman/core/geocode"
6
- import { type Ancestor, type GazetteerArtifactCoverage, referentialFromPopulation } from "@mailwoman/core/resolver"
6
+ import {
7
+ type Ancestor,
8
+ type GazetteerArtifactCoverage,
9
+ populationScoreUnmeasured,
10
+ referentialFromPopulation,
11
+ } from "@mailwoman/core/resolver"
7
12
  import { allRows } from "@mailwoman/core/utils"
8
13
  import { jaroWinkler, levenshteinSimilarity } from "@mailwoman/match/comparators"
9
14
  import { partitionByContainment } from "@mailwoman/resolver"
@@ -18,17 +23,20 @@ import {
18
23
  type CandidateAncestorTable,
19
24
  type IntervalLabel,
20
25
  } from "#candidate/ancestors/schema"
26
+ import { readGazetteerCoverageManifest } from "#candidate/coverage-manifest"
21
27
  import { CANDIDATE_FTS_TABLE } from "#candidate/fts"
22
28
  import { candidateQueryKeyFold } from "#candidate/key-fold"
23
29
  import type { CandidateDatabase, CandidateTable, CountryCodeTable, PlacetypeCodeTable } from "#candidate/schema"
24
- import { readGazetteerCoverageManifest } from "#coverage-manifest-schema"
25
- import { POSTAL_CITY_CANDIDATE_TABLE, type PostalCityCandidateTable } from "#postal/city/candidate-schema"
26
- import { rankByPrimaryPreference, type RankedRow, regionAliasMargin, RERANK_FETCH } from "#primary-preference"
27
- import { applyProximityRerank } from "#proximity-rerank"
28
- import { REGION_CLASS_PLACETYPES, regionQualifierProbeKeys } from "#region-keys"
30
+ import {
31
+ POSTAL_CITY_CANDIDATE_TABLE,
32
+ type PostalCityCandidateTable,
33
+ } from "#labels/locality/postal-city/candidate-schema"
34
+ import { REGION_CLASS_PLACETYPES, regionQualifierProbeKeys } from "#labels/region"
35
+ import { type NameKey, normalizeLocalityForKey, stripLocalityQualifier } from "#labels/street/normalize"
36
+ import type { FindPlaceQuery, PlaceCandidate, PlaceLookup, WOFPlacetype } from "#lookup/types"
37
+ import { rankByPrimaryPreference, type RankedRow, regionAliasMargin, RERANK_FETCH } from "#ranking/primary-preference"
38
+ import { applyProximityRerank } from "#ranking/proximity-rerank"
29
39
  import { hasColumn, hasTable } from "#sqlite-utils"
30
- import { type NameKey, normalizeLocalityForKey, stripLocalityQualifier } from "#street/normalize"
31
- import type { FindPlaceQuery, PlaceCandidate, PlaceLookup, WOFPlacetype } from "#types"
32
40
 
33
41
  /**
34
42
  * Where a {@link WOFCandidateTableLookup} reads from
@@ -134,6 +142,8 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
134
142
  readonly #intervalCache = new Map<number, IntervalLabel | null>()
135
143
 
136
144
  readonly #qualifierProbe: ReturnType<DatabaseClient["prepare"]> | undefined
145
+
146
+ #placeProbe: ReturnType<DatabaseClient["prepare"]> | undefined
137
147
  /**
138
148
  * The folds the artifact recorded for its `name_key` column, applied to every query key.
139
149
  */
@@ -665,58 +675,79 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
665
675
  rows = this.#applyContainment(rows, new Set([query.parentQualifierID]), containmentOptions)
666
676
  }
667
677
 
668
- const candidates = rows.map((row): PlaceCandidate => {
669
- const hasBbox = row.min_lat != null && row.max_lat != null && row.min_lon != null && row.max_lon != null
670
- const parent = this.#ancestorLineage(Number(row.spr_id))[0]
671
- const hasPopulation = row.population !== null && row.population > 0
678
+ const candidates = rows.map((row) => this.#toCandidate(row, regionScopeMiss))
672
679
 
673
- return {
674
- id: Number(row.spr_id),
675
- name: String(row.name ?? ""),
676
- placetype: (this.#idToPlacetype.get(Number(row.placetype_id)) ?? "") as WOFPlacetype,
680
+ if (query.bias && query.bias.length) {
681
+ applyProximityRerank(candidates, query.bias)
682
+ }
677
683
 
678
- country: this.#idToCountry.get(Number(row.country_id)) ?? "",
679
- lat: Number(row.latitude),
680
- lon: Number(row.longitude),
684
+ return candidates
685
+ }
681
686
 
682
- parent_id: parent ? Number(parent.id) : null,
687
+ /**
688
+ * One place by its `spr_id`, read from its primary-name row, or null when the table holds no row for it.
689
+ */
690
+ place(id: number): PlaceCandidate | null {
691
+ if (!Number.isInteger(id)) return null
683
692
 
684
- score: -Number(row.neg_rank),
685
- distanceKm: null,
693
+ this.#placeProbe ??= this.database.prepare(
694
+ "SELECT spr_id, name, country_id, placetype_id, latitude, longitude, min_lat, min_lon, max_lat, max_lon, neg_rank, is_primary, population" +
695
+ `${this.#importanceSelect} FROM candidate WHERE spr_id = ? ORDER BY is_primary DESC LIMIT 1`
696
+ )
686
697
 
687
- prominence: -Number(row.effectiveNegRank),
698
+ const row = this.#placeProbe.get(id) as CandidateRow | undefined
688
699
 
689
- exactMatch: !row.demoted && !row.fuzzy,
700
+ return row ? this.#toCandidate({ ...row, effectiveNegRank: row.neg_rank, demoted: false }, false) : null
701
+ }
690
702
 
691
- regionScopeMiss: regionScopeMiss ? true : null,
703
+ #toCandidate(row: RankedRow<CandidateRow>, regionScopeMiss: boolean): PlaceCandidate {
704
+ const hasBbox = row.min_lat != null && row.max_lat != null && row.min_lon != null && row.max_lon != null
705
+ const parent = this.#ancestorLineage(Number(row.spr_id))[0]
706
+ const hasPopulation = row.population !== null && row.population > 0
692
707
 
693
- containedByQualifier: row.containedByQualifier ?? null,
708
+ return {
709
+ id: Number(row.spr_id),
710
+ name: String(row.name ?? ""),
711
+ placetype: (this.#idToPlacetype.get(Number(row.placetype_id)) ?? "") as WOFPlacetype,
694
712
 
695
- variantAliasExempted: row.variantExempted ? true : null,
713
+ country: this.#idToCountry.get(Number(row.country_id)) ?? "",
714
+ lat: Number(row.latitude),
715
+ lon: Number(row.longitude),
696
716
 
697
- matchedAlias: row.is_primary === 0 ? true : null,
717
+ parent_id: parent ? Number(parent.id) : null,
698
718
 
699
- population: hasPopulation ? row.population : null,
700
- referential: hasPopulation ? referentialFromPopulation(row.population) : null,
701
- encyclopedic: null,
719
+ score: -Number(row.neg_rank),
720
+ // `neg_rank` is -log10(population + 1), so a place without a population ranks at
721
+ // 0 unmeasured, unless the build ranked it by a population estimate.
722
+ scoreUnmeasured: populationScoreUnmeasured(row.population, Number(row.neg_rank)),
723
+ distanceKm: null,
702
724
 
703
- importance: typeof row.importance === "number" && Number.isFinite(row.importance) ? row.importance : null,
704
- bbox: hasBbox
705
- ? {
706
- minLat: Number(row.min_lat),
707
- maxLat: Number(row.max_lat),
708
- minLon: Number(row.min_lon),
709
- maxLon: Number(row.max_lon),
710
- }
711
- : null,
712
- mismatch: null,
713
- }
714
- })
725
+ prominence: -Number(row.effectiveNegRank),
715
726
 
716
- if (query.bias && query.bias.length) {
717
- applyProximityRerank(candidates, query.bias)
718
- }
727
+ exactMatch: !row.demoted && !row.fuzzy,
719
728
 
720
- return candidates
729
+ regionScopeMiss: regionScopeMiss ? true : null,
730
+
731
+ containedByQualifier: row.containedByQualifier ?? null,
732
+
733
+ variantAliasExempted: row.variantExempted ? true : null,
734
+
735
+ matchedAlias: row.is_primary === 0 ? true : null,
736
+
737
+ population: hasPopulation ? row.population : null,
738
+ referential: hasPopulation ? referentialFromPopulation(row.population) : null,
739
+ encyclopedic: null,
740
+
741
+ importance: typeof row.importance === "number" && Number.isFinite(row.importance) ? row.importance : null,
742
+ bbox: hasBbox
743
+ ? {
744
+ minLat: Number(row.min_lat),
745
+ maxLat: Number(row.max_lat),
746
+ minLon: Number(row.min_lon),
747
+ maxLon: Number(row.max_lon),
748
+ }
749
+ : null,
750
+ mismatch: null,
751
+ }
721
752
  }
722
753
  }
@@ -12,8 +12,8 @@ import { tableExists } from "@mailwoman/sqlite/introspection"
12
12
  import { isOwnNameVariant } from "#candidate/own-name"
13
13
  import type { PlaceAttrs } from "#candidate/place-attrs"
14
14
  import type { CandidateDatabase } from "#candidate/schema"
15
+ import { normalizeLocalityForKey } from "#labels/street/normalize"
15
16
  import type { WOFDatabase } from "#schema"
16
- import { normalizeLocalityForKey } from "#street/normalize"
17
17
 
18
18
  /**
19
19
  * Key-count threshold for the gloss anomaly detector.