@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
@@ -0,0 +1,147 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * @file The candidate build's nickname refusal: a colloquial or unclassified name doesn't become an
6
+ * alias row when a populated place holds the same key by a real name.
7
+ */
8
+
9
+ import { GEONAMES_ID_BASE, OVERTURE_ID_BASE } from "@mailwoman/core/resolver/synthetic-id-ranges"
10
+ import type { DatabaseClient } from "@mailwoman/sqlite/client"
11
+ import { tableExists } from "@mailwoman/sqlite/introspection"
12
+
13
+ import type { PlaceAttrs } from "#candidate/place-attrs"
14
+ import type { CandidateDatabase } from "#candidate/schema"
15
+ import { normalizeLocalityForKey, withoutApostropheLikeMarks } from "#labels/street/normalize"
16
+ import type { WOFDatabase } from "#schema"
17
+
18
+ /**
19
+ * The WOF name kinds that name a place without being its name: a colloquial name
20
+ * (`Motor City`, `T.O.`) and an unclassified one.
21
+ * An unclassified name is mostly a code (`DE`, `AP`, `GTA`).
22
+ */
23
+ const NICKNAME_KINDS: readonly string[] = ["colloquial", "unknown"]
24
+
25
+ /**
26
+ * The keys a name stages as alias rows: its key, and its mark-free form when that differs.
27
+ */
28
+ function stagedKeys(name: string): string[] {
29
+ const k = normalizeLocalityForKey(name)
30
+
31
+ if (!k) return []
32
+ const free = withoutApostropheLikeMarks(k)
33
+
34
+ return free && free !== k ? [k, free] : [k]
35
+ }
36
+
37
+ /**
38
+ * Deletes the alias rows a place holds only through a colloquial or unclassified name,
39
+ * when another place with a population holds the same key by any other name.
40
+ *
41
+ * The candidate ranks a key's rows by population, so a nickname of a large place outranks
42
+ * every smaller place whose own name the nickname spells: `T.O.` and `To.`
43
+ * (Toronto) over Tó, `Garden City` (Victoria) over each Garden City, `DE` (Germany) over Delaware's `DE`.
44
+ *
45
+ * A namesake without a population ranks last under any populated holder, so a nickname whose
46
+ * only namesakes are unpopulated stays: `Motor City` keeps Detroit over Motor City, California.
47
+ * A nickname that several places share also stays when no other place holds its key
48
+ * by a real name (`The Windy City` for Chicago and Wellington).
49
+ *
50
+ * Runs on `cand_stage` after the primaries, aliases and abbreviations are staged,
51
+ * and before the postcode extracts.
52
+ * A postcode row stores no population.
53
+ *
54
+ * @returns The count of alias rows deleted, and of distinct keys they held.
55
+ */
56
+ export function refuseNicknamesOfNamesakes(
57
+ src: DatabaseClient<WOFDatabase>,
58
+ out: DatabaseClient<CandidateDatabase>,
59
+ attrs: Map<number, PlaceAttrs>
60
+ ): { rows: number; keys: number } {
61
+ if (!tableExists(src, "names")) return { rows: 0, keys: 0 }
62
+
63
+ const kinds = NICKNAME_KINDS.map(() => "?").join(", ")
64
+ const nicknameKeys = new Map<number, Set<string>>()
65
+
66
+ for (const r of src.prepare(`SELECT id, name FROM names WHERE privateuse IN (${kinds})`).iterate(...NICKNAME_KINDS)) {
67
+ const id = Number(r.id)
68
+
69
+ if (!attrs.has(id)) continue
70
+ let keys = nicknameKeys.get(id)
71
+
72
+ if (!keys) {
73
+ keys = new Set()
74
+ nicknameKeys.set(id, keys)
75
+ }
76
+
77
+ for (const k of stagedKeys(String(r.name ?? ""))) {
78
+ keys.add(k)
79
+ }
80
+ }
81
+
82
+ if (!nicknameKeys.size) return { rows: 0, keys: 0 }
83
+
84
+ // A key the place also holds by a real name belongs to that name's row and is never refused.
85
+ const realNames = src.prepare(`SELECT name FROM names WHERE id = ? AND privateuse NOT IN (${kinds})`)
86
+ const abbrs = tableExists(src, "place_abbr") ? src.prepare("SELECT abbr FROM place_abbr WHERE id = ?") : null
87
+
88
+ const ownKeys = (id: number): string[] => [
89
+ ...stagedKeys(attrs.get(id)?.name ?? ""),
90
+ ...realNames.all(id, ...NICKNAME_KINDS).flatMap((r) => stagedKeys(String(r.name ?? ""))),
91
+ ...(abbrs?.all(id).flatMap((r) => stagedKeys(String(r.abbr ?? ""))) ?? []),
92
+ ]
93
+
94
+ out.exec(
95
+ "CREATE TEMP TABLE nickname_key (spr_id INTEGER NOT NULL, name_key TEXT NOT NULL, PRIMARY KEY (spr_id, name_key)) WITHOUT ROWID"
96
+ )
97
+
98
+ const insNickname = out.prepare("INSERT OR IGNORE INTO nickname_key VALUES (?, ?)")
99
+ out.exec("BEGIN")
100
+
101
+ for (const [id, keys] of nicknameKeys) {
102
+ for (const k of ownKeys(id)) {
103
+ keys.delete(k)
104
+ }
105
+
106
+ for (const k of keys) {
107
+ insNickname.run(id, k)
108
+ }
109
+ }
110
+
111
+ out.exec("COMMIT")
112
+
113
+ out.exec("CREATE INDEX temp.nickname_key_by_key ON nickname_key (name_key)")
114
+ out.exec("CREATE TEMP TABLE namesake_key (name_key TEXT PRIMARY KEY) WITHOUT ROWID")
115
+
116
+ // An Overture division is never a namesake.
117
+ // The gazetteer is a Collective Database whose Overture Divisions part is ODbL, and a WOF
118
+ // or GeoNames alias refused because of a division's row would be that part altering the rest.
119
+ // The Overture step writes no nickname kind on a division, so no Overture
120
+ // row holds a nickname to refuse either.
121
+ out.exec(
122
+ `INSERT OR IGNORE INTO namesake_key
123
+ SELECT cs.name_key FROM cand_stage cs
124
+ WHERE cs.population > 0
125
+ AND NOT (cs.spr_id >= ${OVERTURE_ID_BASE} AND cs.spr_id < ${GEONAMES_ID_BASE})
126
+ AND cs.name_key IN (SELECT name_key FROM nickname_key)
127
+ AND NOT EXISTS (SELECT 1 FROM nickname_key nk WHERE nk.spr_id = cs.spr_id AND nk.name_key = cs.name_key)`
128
+ )
129
+
130
+ const keys = Number(out.prepare("SELECT count(*) AS n FROM namesake_key").get()!["n"])
131
+
132
+ const rows = Number(
133
+ out
134
+ .prepare(
135
+ `DELETE FROM cand_stage
136
+ WHERE is_primary = 0
137
+ AND name_key IN (SELECT name_key FROM namesake_key)
138
+ AND EXISTS (SELECT 1 FROM nickname_key nk WHERE nk.spr_id = cand_stage.spr_id AND nk.name_key = cand_stage.name_key)`
139
+ )
140
+ .run().changes
141
+ )
142
+
143
+ out.exec("DROP TABLE namesake_key")
144
+ out.exec("DROP TABLE nickname_key")
145
+
146
+ return { rows, keys }
147
+ }
@@ -0,0 +1,83 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * @file The candidate build's Overture twins: a matched division answers only on the keys its WOF record lacks.
6
+ *
7
+ * The admin gazetteer writes every Overture division as its own row, including a division that matched a
8
+ * WOF record, and records the pair in `overture_wof_match`. Both rows staged in full would return one place
9
+ * twice for every name the two share. The pass deletes each matched division's staged rows on the keys its
10
+ * WOF record also holds, so the division answers only on the names WOF lacks.
11
+ *
12
+ * It changes only the Overture part's rows. The WOF rows it reads are left as they are, so the gazetteer
13
+ * stays a Collective Database whose Overture Divisions part is ODbL. The match table is copied into the
14
+ * artifact as a table of that part.
15
+ */
16
+
17
+ import type { DatabaseClient } from "@mailwoman/sqlite/client"
18
+
19
+ import type { CandidateDatabase } from "#candidate/schema"
20
+ import type { WOFDatabase } from "#schema"
21
+ import { createOvertureWOFMatchTable, OVERTURE_WOF_MATCH_TABLE, readOvertureWOFMatches } from "#schema/overture-match"
22
+
23
+ /**
24
+ * Copies the admin database's `overture_wof_match` into the candidate and drops each
25
+ * matched division's staged rows on keys its WOF record holds.
26
+ *
27
+ * Runs on `cand_stage` after the nickname refusal, so the comparison is with the WOF rows that stay.
28
+ *
29
+ * @returns The matches copied and the staged rows dropped, or `null`
30
+ * when the admin database predates the table.
31
+ * Such a database's matched divisions wrote no rows of their own.
32
+ */
33
+ export async function stageOvertureTwins(
34
+ src: DatabaseClient<WOFDatabase>,
35
+ out: DatabaseClient<CandidateDatabase>
36
+ ): Promise<{ matches: number; rowsDropped: number } | null> {
37
+ const matches = readOvertureWOFMatches(src)
38
+
39
+ if (!matches) return null
40
+
41
+ await createOvertureWOFMatchTable(out)
42
+
43
+ const insert = out.prepare(`INSERT INTO ${OVERTURE_WOF_MATCH_TABLE} (overture_id, wof_id, match_by) VALUES (?, ?, ?)`)
44
+
45
+ out.exec("BEGIN")
46
+
47
+ for (const match of matches) {
48
+ insert.run(match.overture_id, match.wof_id, match.match_by)
49
+ }
50
+
51
+ out.exec("COMMIT")
52
+
53
+ // `cand_stage` has no index while it stages, so each side is one scan: the WOF records' keys
54
+ // are collected under their divisions' ids, then every division row is checked against that table.
55
+ out.exec(
56
+ "CREATE TEMP TABLE twin_wof (wof_id INTEGER NOT NULL, overture_id INTEGER NOT NULL, PRIMARY KEY (wof_id, overture_id)) WITHOUT ROWID"
57
+ )
58
+
59
+ out.exec(`INSERT OR IGNORE INTO twin_wof SELECT wof_id, overture_id FROM ${OVERTURE_WOF_MATCH_TABLE}`)
60
+
61
+ out.exec(
62
+ "CREATE TEMP TABLE twin_key (overture_id INTEGER NOT NULL, name_key TEXT NOT NULL, PRIMARY KEY (overture_id, name_key)) WITHOUT ROWID"
63
+ )
64
+
65
+ out.exec(
66
+ `INSERT OR IGNORE INTO twin_key
67
+ SELECT t.overture_id, w.name_key FROM cand_stage w JOIN twin_wof t ON t.wof_id = w.spr_id`
68
+ )
69
+
70
+ const rowsDropped = Number(
71
+ out
72
+ .prepare(
73
+ `DELETE FROM cand_stage
74
+ WHERE EXISTS (SELECT 1 FROM twin_key t WHERE t.overture_id = cand_stage.spr_id AND t.name_key = cand_stage.name_key)`
75
+ )
76
+ .run().changes
77
+ )
78
+
79
+ out.exec("DROP TABLE twin_key")
80
+ out.exec("DROP TABLE twin_wof")
81
+
82
+ return { matches: matches.length, rowsDropped }
83
+ }
@@ -5,7 +5,7 @@
5
5
  * @file The per-place record every candidate-staging pass writes its rows from.
6
6
  *
7
7
  * Pass 1 reduces each current `spr` row to one {@link PlaceAttrs}. Every later pass (alias bags,
8
- * region abbreviations, country display names, the currency backfill, the extract folds) discovers
8
+ * region abbreviations, country display names, the currency backfill, the extract rows) discovers
9
9
  * additional name keys for a place already in that map and stages a row against the same record.
10
10
  * That keeps each candidate row denormalized without re-reading the source. A pass therefore needs
11
11
  * exactly four values: the key, place, row ID, plus a flag for the place's canonical name.
@@ -45,7 +45,7 @@ export interface PlaceAttrs {
45
45
  * Stages one candidate row with a normalized name key, place, source ID,
46
46
  * plus a canonical-name flag (`is_primary`).
47
47
  *
48
- * `sid` is passed separately rather than read off the place because an extract fold
48
+ * `sid` is passed separately rather than read off the place because the extract-rows pass
49
49
  * and the alias pass stage rows for ids the admin `attrs` map never held.
50
50
  */
51
51
  export type StageRow = (k: string, a: PlaceAttrs, sid: number, isPrimary: number) => void
@@ -0,0 +1,173 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * Pages through a candidate gazetteer's postcode places in ascending `spr_id`
6
+ * order, inside a bounding box.
7
+ *
8
+ * A page reads only {@link CANDIDATE_POSTCODE_PLACE_INDEX}: the index holds each
9
+ * postcode place's primary rows in `spr_id` order with their point and name.
10
+ * Each entry also stores the clustered key, and its `country_id` identifies the country.
11
+ *
12
+ * A page continues after the last id the previous page returned, so the database
13
+ * seeks to it and a deep page costs what the first page costs.
14
+ *
15
+ * A box filters the walk by point, so a box holding few postcode places reads more
16
+ * of the index before its page fills, and never more than the index once.
17
+ *
18
+ * The statements stay raw because a partial index is used only by a query that
19
+ * states its literal, and `INDEXED BY` has no query-builder form.
20
+ * `INDEXED BY` makes a statement fail to prepare rather than scan the table when the index is missing.
21
+ */
22
+
23
+ import { DatabaseClient, type StatementSync } from "@mailwoman/sqlite/client"
24
+ import { indexExists, tableExists } from "@mailwoman/sqlite/introspection"
25
+ import { SQLiteLookup, type SQLiteLookupOptions } from "@mailwoman/sqlite/lookup"
26
+ import type { PathBuilderLike } from "path-ts"
27
+
28
+ import { CANDIDATE_POSTCODE_PLACE_INDEX, type CandidateDatabase, POSTCODE_PLACETYPE } from "#candidate/schema"
29
+ import type { BrowsedPlace, BrowsePageRequest } from "#lookup/browse"
30
+ import type { WOFDatabase } from "#schema"
31
+
32
+ /**
33
+ * Whether a WOF database such as `postalcode-us.db` holds at least one current postcode place in `spr`.
34
+ *
35
+ * A database without `spr` holds none.
36
+ */
37
+ export function wofDatabaseHoldsPostcodes(databasePath: PathBuilderLike): boolean {
38
+ using db = new DatabaseClient<WOFDatabase>(databasePath, { readOnly: true })
39
+
40
+ if (!tableExists(db, "spr")) return false
41
+
42
+ return Boolean(
43
+ db.prepare("SELECT 1 FROM spr WHERE placetype = ? AND is_current != 0 LIMIT 1").get(POSTCODE_PLACETYPE)
44
+ )
45
+ }
46
+
47
+ interface PostcodeRow {
48
+ spr_id: number
49
+ country_id: number
50
+ latitude: number | null
51
+ longitude: number | null
52
+ name: string | null
53
+ }
54
+
55
+ /**
56
+ * The statements of a gazetteer that records the postcode placetype.
57
+ */
58
+ interface PostcodeStatements {
59
+ any: StatementSync
60
+ place: StatementSync
61
+ page: StatementSync
62
+ pageInBox: StatementSync
63
+ pageAcrossAntimeridian: StatementSync
64
+ }
65
+
66
+ /**
67
+ * Pages through the postcode places of a candidate gazetteer such as `candidate.db`.
68
+ *
69
+ * A postcode place appears once, read from the primary row with the least name.
70
+ */
71
+ export class PostcodePlaceBrowser extends SQLiteLookup<CandidateDatabase> {
72
+ /**
73
+ * Null when the gazetteer records no postcode placetype.
74
+ */
75
+ readonly #statements: PostcodeStatements | null
76
+ readonly #countryCodes: Map<number, string>
77
+
78
+ /**
79
+ * @throws When the gazetteer records the postcode placetype but lacks
80
+ * {@link CANDIDATE_POSTCODE_PLACE_INDEX}, because a page would then scan the whole candidate table.
81
+ */
82
+ constructor(options: SQLiteLookupOptions<CandidateDatabase>) {
83
+ super(options)
84
+
85
+ const placetype = this.database
86
+ .prepare("SELECT id FROM placetype_codes WHERE placetype = ?")
87
+ .get(POSTCODE_PLACETYPE) as { id: number } | undefined
88
+
89
+ if (placetype && !indexExists(this.database, CANDIDATE_POSTCODE_PLACE_INDEX)) {
90
+ this[Symbol.dispose]()
91
+
92
+ throw new Error(`the candidate gazetteer has no ${CANDIDATE_POSTCODE_PLACE_INDEX} index`)
93
+ }
94
+
95
+ this.#statements = placetype ? this.#prepare(placetype.id) : null
96
+
97
+ const countries = this.database.prepare("SELECT id, code FROM country_codes").all() as Array<{
98
+ id: number
99
+ code: string
100
+ }>
101
+
102
+ this.#countryCodes = new Map(countries.map(({ id, code }) => [id, code]))
103
+ }
104
+
105
+ #prepare(placetypeID: number): PostcodeStatements {
106
+ const from =
107
+ `FROM candidate INDEXED BY ${CANDIDATE_POSTCODE_PLACE_INDEX} ` +
108
+ `WHERE placetype_id = ${Math.trunc(placetypeID)} AND is_primary = 1`
109
+
110
+ const select = `SELECT spr_id, country_id, latitude, longitude, MIN(name) AS name ${from}`
111
+
112
+ const page = (box: string) =>
113
+ this.database.prepare(`${select} AND spr_id > ? ${box} GROUP BY spr_id ORDER BY spr_id LIMIT ?`)
114
+
115
+ return {
116
+ any: this.database.prepare(`SELECT 1 ${from} LIMIT 1`),
117
+ place: this.database.prepare(`${select} AND spr_id = ? GROUP BY spr_id`),
118
+ page: page(""),
119
+ pageInBox: page("AND latitude BETWEEN ? AND ? AND longitude BETWEEN ? AND ?"),
120
+ pageAcrossAntimeridian: page("AND latitude BETWEEN ? AND ? AND (longitude >= ? OR longitude <= ?)"),
121
+ }
122
+ }
123
+
124
+ #toPlace(row: PostcodeRow): BrowsedPlace {
125
+ return {
126
+ id: row.spr_id,
127
+ name: row.name ?? "",
128
+ placetype: POSTCODE_PLACETYPE,
129
+ country: this.#countryCodes.get(row.country_id) ?? "",
130
+ latitude: row.latitude ?? 0,
131
+ longitude: row.longitude ?? 0,
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Whether the gazetteer holds at least one postcode place.
137
+ */
138
+ holdsPostcodes(): boolean {
139
+ return Boolean(this.#statements?.any.get())
140
+ }
141
+
142
+ /**
143
+ * The postcode place with this id, or null when the gazetteer holds no postcode place with it.
144
+ */
145
+ async place(id: number): Promise<BrowsedPlace | null> {
146
+ const row = this.#statements?.place.get(id) as PostcodeRow | undefined
147
+
148
+ return row ? this.#toPlace(row) : null
149
+ }
150
+
151
+ /**
152
+ * The postcode places the request selects, in ascending id order, at most `limit` of them.
153
+ */
154
+ async page({ box, after, limit }: BrowsePageRequest): Promise<BrowsedPlace[]> {
155
+ const statements = this.#statements
156
+
157
+ if (!statements) return []
158
+
159
+ const cursor = after ?? Number.MIN_SAFE_INTEGER
160
+
161
+ let rows: unknown[]
162
+
163
+ if (!box) {
164
+ rows = statements.page.all(cursor, limit)
165
+ } else {
166
+ const statement = box.minLon <= box.maxLon ? statements.pageInBox : statements.pageAcrossAntimeridian
167
+
168
+ rows = statement.all(cursor, box.minLat, box.maxLat, box.minLon, box.maxLon, limit)
169
+ }
170
+
171
+ return (rows as PostcodeRow[]).map((row) => this.#toPlace(row))
172
+ }
173
+ }
@@ -4,8 +4,9 @@
4
4
  import { sql, type Kysely } from "kysely"
5
5
 
6
6
  import type { CandidateAncestorsDatabase } from "#candidate/ancestors/schema"
7
- import type { CapitalTable } from "#capital-schema"
8
- import type { NameKey } from "#street/normalize"
7
+ import type { CapitalTable } from "#candidate/capital-schema"
8
+ import type { NameKey } from "#labels/street/normalize"
9
+ import type { OvertureWOFMatchTable } from "#schema/overture-match"
9
10
 
10
11
  /**
11
12
  * One candidate row.
@@ -102,6 +103,11 @@ export interface CandidateDatabase extends CandidateAncestorsDatabase {
102
103
  * See capital-schema.ts.
103
104
  */
104
105
  capital: CapitalTable
106
+ /**
107
+ * Which WOF record each matched Overture division is, a table of the Overture Divisions part.
108
+ * See overture-match-schema.ts.
109
+ */
110
+ overture_wof_match: OvertureWOFMatchTable
105
111
  }
106
112
 
107
113
  /**
@@ -206,3 +212,38 @@ export async function createCandidateTable(db: Kysely<CandidateDatabase>): Promi
206
212
  .modifyEnd(sql`without rowid`)
207
213
  .execute()
208
214
  }
215
+
216
+ /**
217
+ * The partial index over the primary rows of postcode places, in `spr_id` order.
218
+ *
219
+ * It holds `spr_id`, the point and the name.
220
+ * Each entry also stores the clustered key.
221
+ *
222
+ * A page of postcode places in id order, with or without a box, therefore reads only the index.
223
+ */
224
+ export const CANDIDATE_POSTCODE_PLACE_INDEX = "candidate_postcode_place"
225
+
226
+ /**
227
+ * The placetype of postcode places in `placetype_codes`.
228
+ */
229
+ export const POSTCODE_PLACETYPE = "postalcode"
230
+
231
+ /**
232
+ * Create {@link CANDIDATE_POSTCODE_PLACE_INDEX} on the built `candidate` table.
233
+ *
234
+ * A partial index selects its rows with a literal, so the placetype's dictionary id is
235
+ * written into the index and a reader states the same literal to use it.
236
+ *
237
+ * @param placetypeID The id `placetype_codes` gives {@link POSTCODE_PLACETYPE}.
238
+ */
239
+ export async function createCandidatePostcodePlaceIndex(
240
+ db: Kysely<CandidateDatabase>,
241
+ placetypeID: number
242
+ ): Promise<void> {
243
+ await db.schema
244
+ .createIndex(CANDIDATE_POSTCODE_PLACE_INDEX)
245
+ .on("candidate")
246
+ .columns(["spr_id", "latitude", "longitude", "name"])
247
+ .where(sql<boolean>`placetype_id = ${sql.lit(placetypeID)} AND is_primary = 1`)
248
+ .execute()
249
+ }
@@ -5,11 +5,11 @@ import { compareReferential, referentialFromPopulation } from "@mailwoman/core/r
5
5
  import { haversine } from "@mailwoman/spatial/geometries/point/distance"
6
6
  import type { DatabaseClient } from "@mailwoman/sqlite/client"
7
7
 
8
- import { exactMatchIDs, officialNameIDs } from "#exact-match"
9
8
  import { foldQueryText } from "#fts"
10
- import { populationBoostTerm, type RankingWeights } from "#ranking-weights"
11
- import type { RawSearchRow } from "#search-fetch"
12
- import type { FindPlaceQuery, PlaceCandidate, WOFPlacetype } from "#types"
9
+ import type { RawSearchRow } from "#fts/search-fetch"
10
+ import { exactMatchIDs, officialNameIDs } from "#lookup/exact-match"
11
+ import type { FindPlaceQuery, PlaceCandidate, WOFPlacetype } from "#lookup/types"
12
+ import { populationBoostTerm, type RankingWeights } from "#ranking/weights"
13
13
 
14
14
  /**
15
15
  * Score one raw FTS row into a `PlaceCandidate`: the weighted sum over the negated
package/lib/convention.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * The strategy implementations live in `lookup.ts` and are registered by name.
8
8
  */
9
9
 
10
- import type { FindPlaceQuery, PlaceCandidate } from "#types"
10
+ import type { FindPlaceQuery, PlaceCandidate } from "#lookup/types"
11
11
 
12
12
  /**
13
13
  * Soft-scoring weights for the `postcode_area_resolution` strategy: `pc·S_pc + name·S_name + pop·S_pop`.
package/lib/env.ts CHANGED
@@ -3,9 +3,9 @@
3
3
 
4
4
  /**
5
5
  * Environment variables name the WOF SQLite artifacts this resolver opens
6
- * and the development weights the overlay
7
- * linker materializes.
8
- * CLI flags (`--resolve-db`, …) override these at the call site.
6
+ * and the development weights overlay that the linker materializes.
7
+ *
8
+ * CLI flags (`--resolve-db`, …) override these values at the call site.
9
9
  */
10
10
 
11
11
  import { $public as corePublic, liveEnv } from "@mailwoman/core/env"
@@ -43,6 +43,18 @@ export const PublicWOFSQLiteEnvSchema = z.object({
43
43
  title: "Development tokenizer",
44
44
  description: "Path to the tokenizer artifact linked for local neural-weights development.",
45
45
  }),
46
+ /**
47
+ * Set by GitHub Actions itself.
48
+ *
49
+ * The dev weights linker refuses to write the shared overlay under it.
50
+ * Release-kit's view extends this one and uses it as the predicate for npm `--provenance`,
51
+ * because npm can only mint an attestation from a CI provider it supports.
52
+ */
53
+ GITHUB_ACTIONS: z.coerce.boolean().default(false).meta({
54
+ title: "GitHub Actions",
55
+ description:
56
+ "Whether the process is running under GitHub Actions. The dev weights linker then requires `MAILWOMAN_WEIGHTS_OVERLAY_ROOT`, and release publication enables npm provenance.",
57
+ }),
46
58
  })
47
59
 
48
60
  /**
@@ -16,17 +16,16 @@ import type { AncestrieMatch } from "@mailwoman/ancestrie"
16
16
  import { hashFNV1a } from "@mailwoman/core/coarse-placer/fnv-hash"
17
17
 
18
18
  import {
19
+ decodePlaceEntry,
20
+ idTableOffset,
21
+ loadIDTable,
19
22
  EDGE_ENTRY_SIZE,
20
- ENCYCLOPEDIC_OFFSET,
21
23
  FST_FORMAT_VERSION,
22
24
  FST_MAGIC_BYTES,
23
25
  HEADER_SIZE,
24
- LEGACY_PLACE_ENTRY_SIZE,
25
26
  NARROW_STATE_ENTRY_SIZE,
26
- PLACE_FLAG_HAS_ENCYCLOPEDIC,
27
- PLACETYPE_ORDER,
28
- SPLIT_PLACE_ENTRY_SIZE,
29
- VERSION_TWO_SCORE_SPLIT,
27
+ placeEntryLayout,
28
+ type PlaceEntryLayout,
30
29
  VERSION_WIDE_STATE_COUNTERS,
31
30
  WIDE_STATE_ENTRY_SIZE,
32
31
  } from "#fst/format"
@@ -71,10 +70,13 @@ export class BinaryFSTMatcher {
71
70
  readonly #decoder = new TextDecoder("utf-8")
72
71
  readonly #version: number
73
72
  readonly #isWide: boolean
74
- readonly #isSplit: boolean
75
73
  readonly #hasAmbiguity: boolean
76
74
  readonly #stateEntrySize: number
77
- readonly #placeEntrySize: number
75
+ readonly #placeLayout: PlaceEntryLayout
76
+ /**
77
+ * The file's id table, or `null` for a file that stores WOF ids in its place entries.
78
+ */
79
+ readonly #ids: Float64Array | null
78
80
  readonly #stringDataStart: number
79
81
  readonly #stateTableStart: number
80
82
  readonly #edgeTableStart: number
@@ -106,12 +108,10 @@ export class BinaryFSTMatcher {
106
108
  this.#view = view
107
109
  this.#version = version
108
110
  this.#isWide = version >= VERSION_WIDE_STATE_COUNTERS
109
- this.#isSplit = version >= VERSION_TWO_SCORE_SPLIT
110
111
  // Flags bit 0, as `serializeFST` writes it: place rows include surface-ambiguity data.
111
112
  this.#hasAmbiguity = (view.getUint16(6, true) & 1) === 1
112
113
  this.#stateEntrySize = this.#isWide ? WIDE_STATE_ENTRY_SIZE : NARROW_STATE_ENTRY_SIZE
113
- // Version 5 grew the place entry by the encyclopedic float.
114
- this.#placeEntrySize = this.#isSplit ? SPLIT_PLACE_ENTRY_SIZE : LEGACY_PLACE_ENTRY_SIZE
114
+ this.#placeLayout = placeEntryLayout(version)
115
115
 
116
116
  const stateCount = view.getUint32(8, true)
117
117
  const edgeCount = view.getUint32(12, true)
@@ -130,6 +130,12 @@ export class BinaryFSTMatcher {
130
130
  this.#edgeTableStart = this.#stateTableStart + stateCount * this.#stateEntrySize
131
131
  this.#placeTableStart = this.#edgeTableStart + edgeCount * EDGE_ENTRY_SIZE
132
132
 
133
+ this.#ids = loadIDTable(
134
+ view,
135
+ idTableOffset(this.#placeTableStart, view.getUint32(16, true), this.#placeLayout),
136
+ this.#placeLayout
137
+ )
138
+
133
139
  this.#tokenSlots = new Int32Array(tableCapacity(stringCount)).fill(EMPTY_SLOT)
134
140
 
135
141
  const edgeCapacity = tableCapacity(edgeCount)
@@ -346,35 +352,14 @@ export class BinaryFSTMatcher {
346
352
  }
347
353
 
348
354
  #placeAt(placeIndex: number): PlaceEntry {
349
- const view = this.#view
350
- const entry = this.#placeTableStart + placeIndex * this.#placeEntrySize
351
- const chainLength = view.getUint8(entry + 5)
352
- const parentChain: number[] = new Array(chainLength)
353
-
354
- for (let index = 0; index < chainLength; index++) {
355
- parentChain[index] = view.getUint32(entry + 24 + index * 4, true)
356
- }
357
-
358
- // Version 1 stored a raw population u32 here, and later versions store the referential score.
359
- // `deserializeFST` explains why a version 1 value converts to the referential score this way.
360
- const referential =
361
- this.#version >= 2
362
- ? view.getFloat32(entry + 12, true)
363
- : Math.min(1, Math.log2(1 + view.getUint32(entry + 12, true) / 1000) / 14)
364
-
365
- const hasEncyclopedic =
366
- this.#isSplit && (view.getUint8(entry + 7) & PLACE_FLAG_HAS_ENCYCLOPEDIC) === PLACE_FLAG_HAS_ENCYCLOPEDIC
367
-
368
- return {
369
- wofID: view.getUint32(entry, true),
370
- placetype: PLACETYPE_ORDER[view.getUint8(entry + 4)] ?? "locality",
371
- name: this.#string(view.getUint32(entry + 8, true)),
372
- referential,
373
- lat: view.getFloat32(entry + 16, true),
374
- lon: view.getFloat32(entry + 20, true),
375
- parentChain,
376
- crossCountryBranches: this.#hasAmbiguity ? view.getUint8(entry + 6) : null,
377
- encyclopedic: hasEncyclopedic ? view.getFloat32(entry + ENCYCLOPEDIC_OFFSET, true) : null,
378
- }
355
+ return decodePlaceEntry(
356
+ this.#view,
357
+ this.#placeTableStart + placeIndex * this.#placeLayout.size,
358
+ this.#version,
359
+ this.#placeLayout,
360
+ this.#hasAmbiguity,
361
+ (index) => this.#string(index),
362
+ this.#ids
363
+ )
379
364
  }
380
365
  }