@mailwoman/resolver-wof-sqlite 11.0.0 → 11.2.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 (557) hide show
  1. package/README.md +6 -6
  2. package/lib/address/duplicate.ts +133 -0
  3. package/lib/address/keys/attribution.ts +119 -0
  4. package/lib/address/keys/build.ts +768 -0
  5. package/lib/address/keys/layout.ts +166 -0
  6. package/lib/address/keys/local-runner.ts +18 -0
  7. package/lib/address/keys/lookup.ts +205 -0
  8. package/lib/address/keys/open.ts +33 -0
  9. package/lib/address/keys/point-lookup.ts +130 -0
  10. package/lib/address/keys/postcode.ts +27 -0
  11. package/lib/address/keys/schema.ts +264 -0
  12. package/lib/address/number-forms.ts +61 -0
  13. package/lib/address/point/interpolation.ts +28 -23
  14. package/lib/address/point/schema.ts +2 -5
  15. package/lib/address/point/spine-schema.ts +4 -4
  16. package/lib/address/point.ts +12 -79
  17. package/lib/address/record.ts +155 -0
  18. package/lib/address/stack.ts +20 -0
  19. package/lib/address/subdivision-bounds.ts +81 -0
  20. package/lib/address.ts +2 -5
  21. package/lib/ancestry/backfill.ts +18 -47
  22. package/lib/ancestry.ts +10 -10
  23. package/lib/build/candidate.ts +44 -48
  24. package/lib/build/population-corrections.ts +4 -4
  25. package/lib/build/slim.ts +3 -6
  26. package/lib/candidate/alias-bags.ts +58 -18
  27. package/lib/candidate/ancestors/schema.ts +63 -43
  28. package/lib/candidate/ancestors/sidecar.ts +3 -3
  29. package/lib/candidate/bare-admin-names.ts +3 -3
  30. package/lib/candidate/country-display-names.ts +2 -5
  31. package/lib/candidate/extract-fold.ts +2 -5
  32. package/lib/candidate/fts.ts +5 -5
  33. package/lib/candidate/importance.ts +30 -24
  34. package/lib/candidate/key-fold.ts +132 -0
  35. package/lib/candidate/lookup.ts +25 -18
  36. package/lib/candidate/name-roles.ts +4 -4
  37. package/lib/candidate/nickname-namesakes.ts +140 -0
  38. package/lib/candidate/own-name.ts +12 -10
  39. package/lib/candidate/place-attrs.ts +4 -4
  40. package/lib/candidate/schema.ts +2 -5
  41. package/lib/candidate/scoring.ts +3 -6
  42. package/lib/capital-schema.ts +11 -10
  43. package/lib/capitals.ts +15 -12
  44. package/lib/convention/schema.ts +7 -7
  45. package/lib/convention.ts +3 -3
  46. package/lib/coverage-manifest-schema.ts +4 -4
  47. package/lib/env.ts +7 -6
  48. package/lib/exact-match.ts +6 -7
  49. package/lib/extracts.ts +11 -9
  50. package/lib/fst/autocomplete.ts +19 -15
  51. package/lib/fst/binary-matcher.ts +36 -50
  52. package/lib/fst/builder.ts +32 -11
  53. package/lib/fst/deserialize-web.ts +9 -8
  54. package/lib/fst/format.ts +153 -14
  55. package/lib/fst/freshness.ts +3 -4
  56. package/lib/fst/matcher.ts +6 -6
  57. package/lib/fst/serialize.ts +94 -69
  58. package/lib/fst/types.ts +4 -4
  59. package/lib/fst.ts +2 -5
  60. package/lib/fts/query.ts +3 -4
  61. package/lib/fts.ts +2 -5
  62. package/lib/geonames/aliases.ts +189 -46
  63. package/lib/geonames/postal.ts +17 -15
  64. package/lib/geonames.ts +2 -5
  65. package/lib/importance-source.ts +210 -0
  66. package/lib/index.ts +4 -5
  67. package/lib/interpolation.ts +7 -6
  68. package/lib/landmark/rows.ts +5 -5
  69. package/lib/landmark.ts +6 -6
  70. package/lib/lookup.ts +8 -8
  71. package/lib/name-score.ts +7 -6
  72. package/lib/nsul/lookup.ts +19 -15
  73. package/lib/nsul/schema.ts +4 -5
  74. package/lib/nsul.ts +2 -5
  75. package/lib/paths.ts +7 -7
  76. package/lib/place-importance-schema.ts +5 -8
  77. package/lib/poi/lookup.ts +11 -10
  78. package/lib/poi/schema.ts +16 -10
  79. package/lib/poi.ts +2 -5
  80. package/lib/polygon-schema.ts +10 -9
  81. package/lib/postal/city/alias/lookup.ts +14 -13
  82. package/lib/postal/city/alias/schema.ts +12 -12
  83. package/lib/postal/city/candidate-schema.ts +15 -12
  84. package/lib/postal.ts +2 -5
  85. package/lib/postcode-point-lookup.ts +2 -5
  86. package/lib/primary-preference.ts +42 -7
  87. package/lib/proximity-rerank.ts +23 -19
  88. package/lib/ranking-weights.ts +8 -7
  89. package/lib/region-keys.ts +15 -14
  90. package/lib/reverse.ts +16 -17
  91. package/lib/schema.ts +20 -6
  92. package/lib/search-fetch.ts +15 -11
  93. package/lib/sqlite/convention-source.ts +2 -5
  94. package/lib/sqlite/utils.ts +4 -4
  95. package/lib/street/centroid/schema.ts +6 -6
  96. package/lib/street/centroid.ts +3 -3
  97. package/lib/street/locale.ts +64 -0
  98. package/lib/street/morphology/fst/builder.ts +21 -19
  99. package/lib/street/morphology/fst/loader.ts +15 -13
  100. package/lib/street/name-lookup.ts +15 -14
  101. package/lib/street/normalize.ts +62 -17
  102. package/lib/street/segment-schema.ts +16 -14
  103. package/lib/street/table.ts +276 -0
  104. package/lib/street.ts +3 -5
  105. package/lib/types.ts +3 -6
  106. package/lib/unified-schema.ts +31 -9
  107. package/lib/uprn/existence.ts +10 -10
  108. package/lib/uprn/lookup.ts +7 -8
  109. package/lib/uprn/schema.ts +5 -5
  110. package/lib/uprn.ts +2 -5
  111. package/lib/weights-overlay-linker.ts +5 -8
  112. package/out/address/duplicate.d.ts +74 -0
  113. package/out/address/duplicate.d.ts.map +1 -0
  114. package/out/address/duplicate.js +79 -0
  115. package/out/address/duplicate.js.map +1 -0
  116. package/out/address/keys/attribution.d.ts +56 -0
  117. package/out/address/keys/attribution.d.ts.map +1 -0
  118. package/out/address/keys/attribution.js +64 -0
  119. package/out/address/keys/attribution.js.map +1 -0
  120. package/out/address/keys/build.d.ts +154 -0
  121. package/out/address/keys/build.d.ts.map +1 -0
  122. package/out/address/keys/build.js +423 -0
  123. package/out/address/keys/build.js.map +1 -0
  124. package/out/address/keys/layout.d.ts +92 -0
  125. package/out/address/keys/layout.d.ts.map +1 -0
  126. package/out/address/keys/layout.js +87 -0
  127. package/out/address/keys/layout.js.map +1 -0
  128. package/out/address/keys/local-runner.d.ts +9 -0
  129. package/out/address/keys/local-runner.d.ts.map +1 -0
  130. package/out/address/keys/local-runner.js +13 -0
  131. package/out/address/keys/local-runner.js.map +1 -0
  132. package/out/address/keys/lookup.d.ts +80 -0
  133. package/out/address/keys/lookup.d.ts.map +1 -0
  134. package/out/address/keys/lookup.js +104 -0
  135. package/out/address/keys/lookup.js.map +1 -0
  136. package/out/address/keys/open.d.ts +10 -0
  137. package/out/address/keys/open.d.ts.map +1 -0
  138. package/out/address/keys/open.js +28 -0
  139. package/out/address/keys/open.js.map +1 -0
  140. package/out/address/keys/point-lookup.d.ts +25 -0
  141. package/out/address/keys/point-lookup.d.ts.map +1 -0
  142. package/out/address/keys/point-lookup.js +100 -0
  143. package/out/address/keys/point-lookup.js.map +1 -0
  144. package/out/address/keys/postcode.d.ts +9 -0
  145. package/out/address/keys/postcode.d.ts.map +1 -0
  146. package/out/address/keys/postcode.js +25 -0
  147. package/out/address/keys/postcode.js.map +1 -0
  148. package/out/address/keys/schema.d.ts +156 -0
  149. package/out/address/keys/schema.d.ts.map +1 -0
  150. package/out/address/keys/schema.js +119 -0
  151. package/out/address/keys/schema.js.map +1 -0
  152. package/out/address/number-forms.d.ts +19 -0
  153. package/out/address/number-forms.d.ts.map +1 -0
  154. package/out/address/number-forms.js +50 -0
  155. package/out/address/number-forms.js.map +1 -0
  156. package/out/address/point/interpolation.d.ts +24 -22
  157. package/out/address/point/interpolation.d.ts.map +1 -1
  158. package/out/address/point/interpolation.js +3 -31
  159. package/out/address/point/interpolation.js.map +1 -1
  160. package/out/address/point/schema.d.ts +0 -5
  161. package/out/address/point/schema.d.ts.map +1 -1
  162. package/out/address/point/schema.js +2 -5
  163. package/out/address/point/schema.js.map +1 -1
  164. package/out/address/point/spine-schema.d.ts +1 -4
  165. package/out/address/point/spine-schema.d.ts.map +1 -1
  166. package/out/address/point/spine-schema.js +3 -4
  167. package/out/address/point/spine-schema.js.map +1 -1
  168. package/out/address/point.d.ts +0 -3
  169. package/out/address/point.d.ts.map +1 -1
  170. package/out/address/point.js +12 -71
  171. package/out/address/point.js.map +1 -1
  172. package/out/address/record.d.ts +125 -0
  173. package/out/address/record.d.ts.map +1 -0
  174. package/out/address/record.js +49 -0
  175. package/out/address/record.js.map +1 -0
  176. package/out/address/stack.d.ts +14 -0
  177. package/out/address/stack.d.ts.map +1 -0
  178. package/out/address/stack.js +19 -0
  179. package/out/address/stack.js.map +1 -0
  180. package/out/address/subdivision-bounds.d.ts +32 -0
  181. package/out/address/subdivision-bounds.d.ts.map +1 -0
  182. package/out/address/subdivision-bounds.js +48 -0
  183. package/out/address/subdivision-bounds.js.map +1 -0
  184. package/out/address.d.ts +0 -5
  185. package/out/address.d.ts.map +1 -1
  186. package/out/address.js +2 -5
  187. package/out/address.js.map +1 -1
  188. package/out/ancestry/backfill.d.ts +11 -13
  189. package/out/ancestry/backfill.d.ts.map +1 -1
  190. package/out/ancestry/backfill.js +6 -44
  191. package/out/ancestry/backfill.js.map +1 -1
  192. package/out/ancestry.d.ts +0 -14
  193. package/out/ancestry.d.ts.map +1 -1
  194. package/out/ancestry.js +9 -10
  195. package/out/ancestry.js.map +1 -1
  196. package/out/build/candidate.d.ts +20 -22
  197. package/out/build/candidate.d.ts.map +1 -1
  198. package/out/build/candidate.js +16 -28
  199. package/out/build/candidate.js.map +1 -1
  200. package/out/build/population-corrections.d.ts +1 -4
  201. package/out/build/population-corrections.d.ts.map +1 -1
  202. package/out/build/population-corrections.js +2 -19
  203. package/out/build/population-corrections.js.map +1 -1
  204. package/out/build/slim.d.ts +0 -5
  205. package/out/build/slim.d.ts.map +1 -1
  206. package/out/build/slim.js +3 -6
  207. package/out/build/slim.js.map +1 -1
  208. package/out/candidate/alias-bags.d.ts +9 -4
  209. package/out/candidate/alias-bags.d.ts.map +1 -1
  210. package/out/candidate/alias-bags.js +46 -19
  211. package/out/candidate/alias-bags.js.map +1 -1
  212. package/out/candidate/ancestors/schema.d.ts +60 -43
  213. package/out/candidate/ancestors/schema.d.ts.map +1 -1
  214. package/out/candidate/ancestors/schema.js +62 -43
  215. package/out/candidate/ancestors/schema.js.map +1 -1
  216. package/out/candidate/ancestors/sidecar.d.ts +0 -3
  217. package/out/candidate/ancestors/sidecar.d.ts.map +1 -1
  218. package/out/candidate/ancestors/sidecar.js +2 -6
  219. package/out/candidate/ancestors/sidecar.js.map +1 -1
  220. package/out/candidate/bare-admin-names.d.ts +0 -6
  221. package/out/candidate/bare-admin-names.d.ts.map +1 -1
  222. package/out/candidate/bare-admin-names.js +2 -3
  223. package/out/candidate/bare-admin-names.js.map +1 -1
  224. package/out/candidate/country-display-names.d.ts +0 -5
  225. package/out/candidate/country-display-names.d.ts.map +1 -1
  226. package/out/candidate/country-display-names.js +2 -5
  227. package/out/candidate/country-display-names.js.map +1 -1
  228. package/out/candidate/extract-fold.d.ts +0 -5
  229. package/out/candidate/extract-fold.d.ts.map +1 -1
  230. package/out/candidate/extract-fold.js +2 -5
  231. package/out/candidate/extract-fold.js.map +1 -1
  232. package/out/candidate/fts.d.ts +2 -5
  233. package/out/candidate/fts.d.ts.map +1 -1
  234. package/out/candidate/fts.js +2 -7
  235. package/out/candidate/fts.js.map +1 -1
  236. package/out/candidate/importance.d.ts +3 -33
  237. package/out/candidate/importance.d.ts.map +1 -1
  238. package/out/candidate/importance.js +29 -24
  239. package/out/candidate/importance.js.map +1 -1
  240. package/out/candidate/key-fold.d.ts +55 -0
  241. package/out/candidate/key-fold.d.ts.map +1 -0
  242. package/out/candidate/key-fold.js +80 -0
  243. package/out/candidate/key-fold.js.map +1 -0
  244. package/out/candidate/lookup.d.ts +0 -5
  245. package/out/candidate/lookup.d.ts.map +1 -1
  246. package/out/candidate/lookup.js +24 -17
  247. package/out/candidate/lookup.js.map +1 -1
  248. package/out/candidate/name-roles.d.ts +0 -6
  249. package/out/candidate/name-roles.d.ts.map +1 -1
  250. package/out/candidate/name-roles.js +3 -4
  251. package/out/candidate/name-roles.js.map +1 -1
  252. package/out/candidate/nickname-namesakes.d.ts +32 -0
  253. package/out/candidate/nickname-namesakes.d.ts.map +1 -0
  254. package/out/candidate/nickname-namesakes.js +98 -0
  255. package/out/candidate/nickname-namesakes.js.map +1 -0
  256. package/out/candidate/own-name.d.ts +0 -18
  257. package/out/candidate/own-name.d.ts.map +1 -1
  258. package/out/candidate/own-name.js +11 -10
  259. package/out/candidate/own-name.js.map +1 -1
  260. package/out/candidate/place-attrs.d.ts +1 -4
  261. package/out/candidate/place-attrs.d.ts.map +1 -1
  262. package/out/candidate/place-attrs.js +2 -12
  263. package/out/candidate/place-attrs.js.map +1 -1
  264. package/out/candidate/schema.d.ts +0 -5
  265. package/out/candidate/schema.d.ts.map +1 -1
  266. package/out/candidate/schema.js +2 -5
  267. package/out/candidate/schema.js.map +1 -1
  268. package/out/candidate/scoring.d.ts +0 -5
  269. package/out/candidate/scoring.d.ts.map +1 -1
  270. package/out/candidate/scoring.js +3 -6
  271. package/out/candidate/scoring.js.map +1 -1
  272. package/out/capital-schema.d.ts +0 -14
  273. package/out/capital-schema.d.ts.map +1 -1
  274. package/out/capital-schema.js +10 -10
  275. package/out/capital-schema.js.map +1 -1
  276. package/out/capitals.d.ts +0 -16
  277. package/out/capitals.d.ts.map +1 -1
  278. package/out/capitals.js +14 -12
  279. package/out/capitals.js.map +1 -1
  280. package/out/convention/schema.d.ts +4 -7
  281. package/out/convention/schema.d.ts.map +1 -1
  282. package/out/convention/schema.js +2 -10
  283. package/out/convention/schema.js.map +1 -1
  284. package/out/convention.d.ts +0 -3
  285. package/out/convention.d.ts.map +1 -1
  286. package/out/convention.js +2 -8
  287. package/out/convention.js.map +1 -1
  288. package/out/coverage-manifest-schema.d.ts +1 -4
  289. package/out/coverage-manifest-schema.d.ts.map +1 -1
  290. package/out/coverage-manifest-schema.js +2 -3
  291. package/out/coverage-manifest-schema.js.map +1 -1
  292. package/out/env.d.ts +0 -8
  293. package/out/env.d.ts.map +1 -1
  294. package/out/env.js +6 -6
  295. package/out/env.js.map +1 -1
  296. package/out/exact-match.d.ts +2 -6
  297. package/out/exact-match.d.ts.map +1 -1
  298. package/out/exact-match.js +3 -9
  299. package/out/exact-match.js.map +1 -1
  300. package/out/extracts.d.ts +8 -9
  301. package/out/extracts.d.ts.map +1 -1
  302. package/out/extracts.js +9 -8
  303. package/out/extracts.js.map +1 -1
  304. package/out/fst/autocomplete.d.ts +1 -19
  305. package/out/fst/autocomplete.d.ts.map +1 -1
  306. package/out/fst/autocomplete.js +2 -18
  307. package/out/fst/autocomplete.js.map +1 -1
  308. package/out/fst/binary-matcher.d.ts +6 -8
  309. package/out/fst/binary-matcher.d.ts.map +1 -1
  310. package/out/fst/binary-matcher.js +12 -43
  311. package/out/fst/binary-matcher.js.map +1 -1
  312. package/out/fst/builder.d.ts +0 -12
  313. package/out/fst/builder.d.ts.map +1 -1
  314. package/out/fst/builder.js +23 -11
  315. package/out/fst/builder.js.map +1 -1
  316. package/out/fst/deserialize-web.d.ts +1 -12
  317. package/out/fst/deserialize-web.d.ts.map +1 -1
  318. package/out/fst/deserialize-web.js +8 -8
  319. package/out/fst/deserialize-web.js.map +1 -1
  320. package/out/fst/format.d.ts +66 -16
  321. package/out/fst/format.d.ts.map +1 -1
  322. package/out/fst/format.js +100 -16
  323. package/out/fst/format.js.map +1 -1
  324. package/out/fst/freshness.d.ts +0 -7
  325. package/out/fst/freshness.d.ts.map +1 -1
  326. package/out/fst/freshness.js +2 -4
  327. package/out/fst/freshness.js.map +1 -1
  328. package/out/fst/matcher.d.ts +3 -6
  329. package/out/fst/matcher.d.ts.map +1 -1
  330. package/out/fst/matcher.js +2 -9
  331. package/out/fst/matcher.js.map +1 -1
  332. package/out/fst/serialize.d.ts +0 -23
  333. package/out/fst/serialize.d.ts.map +1 -1
  334. package/out/fst/serialize.js +68 -60
  335. package/out/fst/serialize.js.map +1 -1
  336. package/out/fst/types.d.ts +1 -4
  337. package/out/fst/types.d.ts.map +1 -1
  338. package/out/fst/types.js +2 -6
  339. package/out/fst/types.js.map +1 -1
  340. package/out/fst.d.ts +0 -5
  341. package/out/fst.d.ts.map +1 -1
  342. package/out/fst.js +2 -5
  343. package/out/fst.js.map +1 -1
  344. package/out/fts/query.d.ts +0 -4
  345. package/out/fts/query.d.ts.map +1 -1
  346. package/out/fts/query.js +2 -7
  347. package/out/fts/query.js.map +1 -1
  348. package/out/fts.d.ts +0 -5
  349. package/out/fts.d.ts.map +1 -1
  350. package/out/fts.js +2 -5
  351. package/out/fts.js.map +1 -1
  352. package/out/geonames/aliases.d.ts +43 -5
  353. package/out/geonames/aliases.d.ts.map +1 -1
  354. package/out/geonames/aliases.js +108 -44
  355. package/out/geonames/aliases.js.map +1 -1
  356. package/out/geonames/postal.d.ts +1 -25
  357. package/out/geonames/postal.d.ts.map +1 -1
  358. package/out/geonames/postal.js +15 -14
  359. package/out/geonames/postal.js.map +1 -1
  360. package/out/geonames.d.ts +0 -5
  361. package/out/geonames.d.ts.map +1 -1
  362. package/out/geonames.js +2 -5
  363. package/out/geonames.js.map +1 -1
  364. package/out/importance-source.d.ts +90 -0
  365. package/out/importance-source.d.ts.map +1 -0
  366. package/out/importance-source.js +133 -0
  367. package/out/importance-source.js.map +1 -0
  368. package/out/index.d.ts +2 -5
  369. package/out/index.d.ts.map +1 -1
  370. package/out/index.js +4 -5
  371. package/out/index.js.map +1 -1
  372. package/out/interpolation.d.ts +0 -7
  373. package/out/interpolation.d.ts.map +1 -1
  374. package/out/interpolation.js +6 -6
  375. package/out/interpolation.js.map +1 -1
  376. package/out/landmark/rows.d.ts +2 -5
  377. package/out/landmark/rows.d.ts.map +1 -1
  378. package/out/landmark/rows.js +2 -8
  379. package/out/landmark/rows.js.map +1 -1
  380. package/out/landmark.d.ts +3 -6
  381. package/out/landmark.d.ts.map +1 -1
  382. package/out/landmark.js +2 -8
  383. package/out/landmark.js.map +1 -1
  384. package/out/lookup.d.ts +0 -7
  385. package/out/lookup.d.ts.map +1 -1
  386. package/out/lookup.js +7 -8
  387. package/out/lookup.js.map +1 -1
  388. package/out/name-score.d.ts +4 -6
  389. package/out/name-score.d.ts.map +1 -1
  390. package/out/name-score.js +6 -6
  391. package/out/name-score.js.map +1 -1
  392. package/out/nsul/lookup.d.ts +16 -15
  393. package/out/nsul/lookup.d.ts.map +1 -1
  394. package/out/nsul/lookup.js +2 -25
  395. package/out/nsul/lookup.js.map +1 -1
  396. package/out/nsul/schema.d.ts +1 -5
  397. package/out/nsul/schema.d.ts.map +1 -1
  398. package/out/nsul/schema.js +3 -8
  399. package/out/nsul/schema.js.map +1 -1
  400. package/out/nsul.d.ts +0 -5
  401. package/out/nsul.d.ts.map +1 -1
  402. package/out/nsul.js +2 -5
  403. package/out/nsul.js.map +1 -1
  404. package/out/paths.d.ts +1 -13
  405. package/out/paths.d.ts.map +1 -1
  406. package/out/paths.js +6 -7
  407. package/out/paths.js.map +1 -1
  408. package/out/place-importance-schema.d.ts +3 -8
  409. package/out/place-importance-schema.d.ts.map +1 -1
  410. package/out/place-importance-schema.js +3 -6
  411. package/out/place-importance-schema.js.map +1 -1
  412. package/out/poi/lookup.d.ts +0 -13
  413. package/out/poi/lookup.d.ts.map +1 -1
  414. package/out/poi/lookup.js +10 -10
  415. package/out/poi/lookup.js.map +1 -1
  416. package/out/poi/schema.d.ts +13 -10
  417. package/out/poi/schema.d.ts.map +1 -1
  418. package/out/poi/schema.js +2 -13
  419. package/out/poi/schema.js.map +1 -1
  420. package/out/poi.d.ts +0 -5
  421. package/out/poi.d.ts.map +1 -1
  422. package/out/poi.js +2 -5
  423. package/out/poi.js.map +1 -1
  424. package/out/polygon-schema.d.ts +7 -9
  425. package/out/polygon-schema.d.ts.map +1 -1
  426. package/out/polygon-schema.js +2 -12
  427. package/out/polygon-schema.js.map +1 -1
  428. package/out/postal/city/alias/lookup.d.ts +11 -13
  429. package/out/postal/city/alias/lookup.d.ts.map +1 -1
  430. package/out/postal/city/alias/lookup.js +13 -13
  431. package/out/postal/city/alias/lookup.js.map +1 -1
  432. package/out/postal/city/alias/schema.d.ts +9 -12
  433. package/out/postal/city/alias/schema.d.ts.map +1 -1
  434. package/out/postal/city/alias/schema.js +2 -17
  435. package/out/postal/city/alias/schema.js.map +1 -1
  436. package/out/postal/city/candidate-schema.d.ts +12 -12
  437. package/out/postal/city/candidate-schema.d.ts.map +1 -1
  438. package/out/postal/city/candidate-schema.js +14 -12
  439. package/out/postal/city/candidate-schema.js.map +1 -1
  440. package/out/postal.d.ts +0 -5
  441. package/out/postal.d.ts.map +1 -1
  442. package/out/postal.js +2 -5
  443. package/out/postal.js.map +1 -1
  444. package/out/postcode-point-lookup.d.ts +0 -5
  445. package/out/postcode-point-lookup.d.ts.map +1 -1
  446. package/out/postcode-point-lookup.js +2 -5
  447. package/out/postcode-point-lookup.js.map +1 -1
  448. package/out/primary-preference.d.ts +20 -6
  449. package/out/primary-preference.d.ts.map +1 -1
  450. package/out/primary-preference.js +33 -6
  451. package/out/primary-preference.js.map +1 -1
  452. package/out/proximity-rerank.d.ts +2 -26
  453. package/out/proximity-rerank.d.ts.map +1 -1
  454. package/out/proximity-rerank.js +22 -19
  455. package/out/proximity-rerank.js.map +1 -1
  456. package/out/ranking-weights.d.ts +5 -7
  457. package/out/ranking-weights.d.ts.map +1 -1
  458. package/out/ranking-weights.js +2 -9
  459. package/out/ranking-weights.js.map +1 -1
  460. package/out/region-keys.d.ts +0 -15
  461. package/out/region-keys.d.ts.map +1 -1
  462. package/out/region-keys.js +14 -14
  463. package/out/region-keys.js.map +1 -1
  464. package/out/reverse.d.ts +1 -24
  465. package/out/reverse.d.ts.map +1 -1
  466. package/out/reverse.js +14 -16
  467. package/out/reverse.js.map +1 -1
  468. package/out/schema.d.ts +17 -6
  469. package/out/schema.d.ts.map +1 -1
  470. package/out/schema.js +2 -15
  471. package/out/schema.js.map +1 -1
  472. package/out/search-fetch.d.ts +0 -13
  473. package/out/search-fetch.d.ts.map +1 -1
  474. package/out/search-fetch.js +14 -11
  475. package/out/search-fetch.js.map +1 -1
  476. package/out/sqlite/convention-source.d.ts +0 -5
  477. package/out/sqlite/convention-source.d.ts.map +1 -1
  478. package/out/sqlite/convention-source.js +2 -5
  479. package/out/sqlite/convention-source.js.map +1 -1
  480. package/out/sqlite/utils.d.ts +1 -7
  481. package/out/sqlite/utils.d.ts.map +1 -1
  482. package/out/sqlite/utils.js +3 -4
  483. package/out/sqlite/utils.js.map +1 -1
  484. package/out/street/centroid/schema.d.ts +3 -6
  485. package/out/street/centroid/schema.d.ts.map +1 -1
  486. package/out/street/centroid/schema.js +2 -7
  487. package/out/street/centroid/schema.js.map +1 -1
  488. package/out/street/centroid.d.ts +0 -3
  489. package/out/street/centroid.d.ts.map +1 -1
  490. package/out/street/centroid.js +2 -6
  491. package/out/street/centroid.js.map +1 -1
  492. package/out/street/locale.d.ts +12 -0
  493. package/out/street/locale.d.ts.map +1 -0
  494. package/out/street/locale.js +54 -0
  495. package/out/street/locale.js.map +1 -0
  496. package/out/street/morphology/fst/builder.d.ts +1 -26
  497. package/out/street/morphology/fst/builder.d.ts.map +1 -1
  498. package/out/street/morphology/fst/builder.js +19 -18
  499. package/out/street/morphology/fst/builder.js.map +1 -1
  500. package/out/street/morphology/fst/loader.d.ts +0 -20
  501. package/out/street/morphology/fst/loader.d.ts.map +1 -1
  502. package/out/street/morphology/fst/loader.js +14 -13
  503. package/out/street/morphology/fst/loader.js.map +1 -1
  504. package/out/street/name-lookup.d.ts +11 -13
  505. package/out/street/name-lookup.d.ts.map +1 -1
  506. package/out/street/name-lookup.js +14 -14
  507. package/out/street/name-lookup.js.map +1 -1
  508. package/out/street/normalize.d.ts +29 -12
  509. package/out/street/normalize.d.ts.map +1 -1
  510. package/out/street/normalize.js +53 -13
  511. package/out/street/normalize.js.map +1 -1
  512. package/out/street/segment-schema.d.ts +11 -12
  513. package/out/street/segment-schema.d.ts.map +1 -1
  514. package/out/street/segment-schema.js +13 -12
  515. package/out/street/segment-schema.js.map +1 -1
  516. package/out/street/table.d.ts +154 -0
  517. package/out/street/table.d.ts.map +1 -0
  518. package/out/street/table.js +122 -0
  519. package/out/street/table.js.map +1 -0
  520. package/out/street.d.ts +1 -5
  521. package/out/street.d.ts.map +1 -1
  522. package/out/street.js +3 -5
  523. package/out/street.js.map +1 -1
  524. package/out/types.d.ts +1 -6
  525. package/out/types.d.ts.map +1 -1
  526. package/out/types.js +2 -5
  527. package/out/types.js.map +1 -1
  528. package/out/unified-schema.d.ts +18 -7
  529. package/out/unified-schema.d.ts.map +1 -1
  530. package/out/unified-schema.js +14 -10
  531. package/out/unified-schema.js.map +1 -1
  532. package/out/uprn/existence.d.ts +7 -10
  533. package/out/uprn/existence.d.ts.map +1 -1
  534. package/out/uprn/existence.js +9 -10
  535. package/out/uprn/existence.js.map +1 -1
  536. package/out/uprn/lookup.d.ts +1 -8
  537. package/out/uprn/lookup.d.ts.map +1 -1
  538. package/out/uprn/lookup.js +6 -8
  539. package/out/uprn/lookup.js.map +1 -1
  540. package/out/uprn/schema.d.ts +2 -5
  541. package/out/uprn/schema.d.ts.map +1 -1
  542. package/out/uprn/schema.js +2 -7
  543. package/out/uprn/schema.js.map +1 -1
  544. package/out/uprn.d.ts +0 -5
  545. package/out/uprn.d.ts.map +1 -1
  546. package/out/uprn.js +2 -5
  547. package/out/uprn.js.map +1 -1
  548. package/out/weights-overlay-linker.d.ts +3 -8
  549. package/out/weights-overlay-linker.d.ts.map +1 -1
  550. package/out/weights-overlay-linker.js +5 -8
  551. package/out/weights-overlay-linker.js.map +1 -1
  552. package/package.json +12 -12
  553. package/lib/currency-backfill.ts +0 -289
  554. package/out/currency-backfill.d.ts +0 -68
  555. package/out/currency-backfill.d.ts.map +0 -1
  556. package/out/currency-backfill.js +0 -169
  557. package/out/currency-backfill.js.map +0 -1
@@ -1,7 +1,7 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
5
  * @file Pass 2 of the candidate build: explode `place_search.alt_names` into distinct alias rows.
6
6
  */
7
7
 
@@ -12,7 +12,7 @@ import type { PlaceAttrs, StageRow } from "#candidate/place-attrs"
12
12
  import type { CandidateDatabase } from "#candidate/schema"
13
13
  import { ALIAS_SEPARATOR } from "#fts"
14
14
  import type { WOFDatabase } from "#schema"
15
- import { normalizeLocalityForKey } from "#street/normalize"
15
+ import { type NameKey, normalizeLocalityForKey, withoutApostropheLikeMarks } from "#street/normalize"
16
16
 
17
17
  /**
18
18
  * The official name of every current region, keyed `${country id}\0${name key}` →
@@ -52,9 +52,16 @@ function officialNameHoldersByRegion(
52
52
  * Pass 2: explode each place's `place_search.alt_names` bag into distinct-key alias rows
53
53
  * (`is_primary = 0`), and count each place's distinct staged keys with the primary included.
54
54
  *
55
- * With `regionPlacetypeID` and `ccID` given, a region's alias that is another same-country region's
55
+ * With `regionPlacetypeID` and `ccID` given, a region's alias that's another same-country region's
56
56
  * official name is refused and counted rather than staged (see {@link officialNameHoldersByRegion}).
57
57
  * Without them the pass stages every alias.
58
+ *
59
+ * Each key holding an apostrophe-like mark, the primary's included, also stages
60
+ * its mark-free form ({@link withoutApostropheLikeMarks}).
61
+ * The count excludes those forms.
62
+ *
63
+ * The gloss detector compares the count with its threshold, and a mark-free form
64
+ * spells a name the count already includes.
58
65
  */
59
66
  export function explodeAliasBags(
60
67
  src: DatabaseClient<WOFDatabase>,
@@ -72,9 +79,16 @@ export function explodeAliasBags(
72
79
  */
73
80
  bareName?: (countryID: number, alias: string) => string | null
74
81
  } = {}
75
- ): { nAlias: number; nBare: number; keyCounts: Map<number, number>; regionOfficialRefused: number } {
82
+ ): {
83
+ nAlias: number
84
+ nBare: number
85
+ nMarkFree: number
86
+ keyCounts: Map<number, number>
87
+ regionOfficialRefused: number
88
+ } {
76
89
  let nAlias = 0
77
90
  let nBare = 0
91
+ let nMarkFree = 0
78
92
  let regionOfficialRefused = 0
79
93
  const keyCounts = new Map<number, number>()
80
94
 
@@ -90,14 +104,35 @@ export function explodeAliasBags(
90
104
  const a = attrs.get(id)
91
105
  const alt = r.alt_names as string | null
92
106
 
93
- if (!a || !alt) continue
107
+ if (!a) continue
94
108
  const seen = new Set<string>([a.pkey])
109
+ const markFree = new Set<string>()
95
110
  const isRegion = a.ptid === opts.regionPlacetypeID
96
111
 
112
+ const refused = (k: string): boolean => {
113
+ if (!isRegion) return false
114
+ const holder = official.get(`${a.cid}\0${k}`)
115
+
116
+ return typeof holder === "number" && holder !== id
117
+ }
118
+
119
+ // Returns 1 when it staged a row, so the caller adds the result to the count.
120
+ const stageMarkFree = (k: NameKey): number => {
121
+ const free = withoutApostropheLikeMarks(k)
122
+
123
+ if (!free || free === k || seen.has(free) || markFree.has(free) || refused(free)) return 0
124
+ markFree.add(free)
125
+ stageRow(free, a, id, 0)
126
+
127
+ return 1
128
+ }
129
+
130
+ nMarkFree += stageMarkFree(a.pkey as NameKey)
131
+
97
132
  // The writer space-pads each separator and appends a trailing one, so every piece
98
133
  // includes surrounding whitespace and the last one is empty.
99
134
  // `normalizeLocalityForKey` folds both away.
100
- for (const piece of alt.split(ALIAS_SEPARATOR)) {
135
+ for (const piece of alt?.split(ALIAS_SEPARATOR) ?? []) {
101
136
  const bare = opts.bareName?.(a.cid, piece.trim())
102
137
  const keys = [normalizeLocalityForKey(piece), bare ? normalizeLocalityForKey(bare) : ""]
103
138
 
@@ -105,30 +140,35 @@ export function explodeAliasBags(
105
140
  if (!k || seen.has(k)) continue
106
141
  seen.add(k)
107
142
 
108
- if (isRegion) {
109
- const holder = official.get(`${a.cid}\0${k}`)
110
-
111
- if (typeof holder === "number" && holder !== id) {
112
- regionOfficialRefused++
143
+ if (refused(k)) {
144
+ regionOfficialRefused++
113
145
 
114
- continue
115
- }
146
+ continue
116
147
  }
117
148
 
118
- stageRow(k, a, id, 0)
149
+ // A mark-free form staged earlier now arrives as a name of its own, so it counts as one.
150
+ if (markFree.delete(k)) {
151
+ nMarkFree--
152
+ } else {
153
+ stageRow(k, a, id, 0)
154
+ }
119
155
 
120
156
  if (position) {
121
157
  nBare++
122
158
  } else {
123
159
  nAlias++
124
160
  }
161
+
162
+ nMarkFree += stageMarkFree(k as NameKey)
125
163
  }
126
164
  }
127
165
 
128
- keyCounts.set(id, seen.size)
166
+ if (alt) {
167
+ keyCounts.set(id, seen.size)
168
+ }
129
169
  }
130
170
 
131
171
  out.exec("COMMIT")
132
172
 
133
- return { nAlias, nBare, keyCounts, regionOfficialRefused }
173
+ return { nAlias, nBare, nMarkFree, keyCounts, regionOfficialRefused }
134
174
  }
@@ -1,53 +1,73 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
+ * Typed schema for the candidate gazetteer's ancestors sidecar
6
+ * (`candidate_ancestor` + `candidate_interval`) — the containment lineage the candidate
7
+ * table itself cannot answer, built into the same `candidate.db` by `build-candidate.ts`
8
+ * and read by {@link WOFCandidateTableLookup.ancestors}.
5
9
  *
6
- * Typed schema for the candidate gazetteer's ancestors sidecar (`candidate_ancestor` +
7
- * `candidate_interval`) — the containment lineage the candidate table itself cannot answer, built
8
- * into the same `candidate.db` by `build-candidate.ts` and read by
9
- * {@link WOFCandidateTableLookup.ancestors}.
10
+ * The sidecar stores denormalized closure rows.
11
+ * Each row represents one (place, ancestor) edge.
10
12
  *
11
- * The sidecar stores denormalized closure rows. Each row represents one (place, ancestor) edge. The row includes the
12
- * parent's placetype, display name and folded key. The two consumers determine this layout:
13
+ * The row includes the parent's placetype, display name and folded key.
14
+ * The two consumers determine this layout:
13
15
  *
14
16
  * 1. The admin-coherence check needs the winner's chain as (placetype, name) pairs in one probe.
15
- * A fixed-slot `[id.8]` chain returns ids. Each id would then need a name lookup, but the artifact has no
16
- * per-id table. That design requires up to 8 indirections. The closure row requires none.
17
- * 2. The account layer needs every candidate under a `name_key` enumerable with its chain from
18
- * one artifact probe ("present-but-outranked, discriminated by containment"). That is the
19
- * candidate probe (contiguous) followed by one `spr_id`-clustered closure probe per candidate
20
- * — each a handful of adjacent pages.
21
- *
22
- * The artifact is read over HTTP byte ranges. A join to a dimension table scatters page fetches. A `without rowid`
23
- * B-tree clustered on `(spr_id, depth)` keeps a whole chain in 1–2 pages. The builder repeats parent strings to
24
- * avoid joins during reads.
25
- *
26
- * `depth` is 1 for the nearest ancestor (deepest containment tier) and increases outward to the
27
- * country. This matches the nearest-first order that `ancestry.ts` serves for the FTS backend. Both backends'
28
- * `ancestors()` results therefore use the same order. The order within a place is deterministic:
29
- * containment depth descending (`placetypeDepth`), then ancestor id ascending, capped at
30
- * {@link MAX_ANCESTOR_DEPTH}. `parent_name_key` is the shared {@link normalizeLocalityForKey}
31
- * fold — the same fold `candidate.name_key` is built with, so a chain entry and a candidate key
32
- * compare under one normalizer.
33
- *
34
- * `candidate_interval` stores pre/post-order labels over the canonical-parent forest. The builder assigns them
35
- * during construction. The predicate `a.pre <= d.pre and d.post <= a.post` tests whether `a` contains `d` in O(1)
36
- * time. It needs no chain scan or tier information. Descendants of `a` occupy the contiguous range
37
- * `pre between a.pre and a.post`. Interval labels add relabeling work to updates. This database is sealed and
38
- * read-only, so the builder can regenerate all labels together.
39
- *
40
- * WOF places can have multiple parents because boundaries can be ambiguous or participate in multiple
41
- * hierarchies. `candidate_ancestor` stores every parent. Its closure rows hold the complete containment record.
42
- * One interval pair encodes only a tree. The interval forest therefore links each place to one canonical parent:
43
- * the depth-1 edge with the finest containment tier and lowest ancestor id. This follows the same MIN-based
44
- * stability convention as the candidate table's `region_id` stamp. A containment query about another hierarchy
45
- * must consult the closure rows. The interval result answers only whether a place is contained along the canonical
46
- * hierarchy.
17
+ * A fixed-slot `[id.8]` chain returns ids.
18
+ * Each id would then need a name lookup, but the artifact has no per-id table.
19
+ * That design requires up to 8 indirections.
20
+ * The closure row requires none.
21
+ * 2. The account layer needs every candidate under a `name_key` enumerable with its chain
22
+ * from one artifact probe ("present-but-outranked, discriminated by containment").
23
+ * That's the candidate probe (contiguous) followed by one `spr_id`-clustered
24
+ * closure probe per candidate — each a handful of adjacent pages.
25
+ *
26
+ * The artifact is read over HTTP byte ranges.
27
+ * A join to a dimension table scatters page fetches.
28
+ *
29
+ * A `without rowid` B-tree clustered on `(spr_id, depth)` keeps a whole chain in 1–2 pages.
30
+ * The builder repeats parent strings to avoid joins during reads.
31
+ *
32
+ * `depth` is 1 for the nearest ancestor (deepest containment tier) and increases outward to the country.
33
+ * This matches the nearest-first order that `ancestry.ts` serves for the FTS backend.
34
+ *
35
+ * Both backends' `ancestors()` results therefore use the same order.
36
+ * The order within a place is deterministic: containment depth descending (`placetypeDepth`),
37
+ * then ancestor id ascending, capped at {@link MAX_ANCESTOR_DEPTH}.
38
+ *
39
+ * `parent_name_key` is the shared {@link normalizeLocalityForKey} fold.
40
+ * It's the same fold `candidate.name_key` is built with, so a chain entry
41
+ * and a candidate key compare under one normalizer.
42
+ *
43
+ * `candidate_interval` stores pre/post-order labels over the canonical-parent forest.
44
+ * The builder assigns them during construction.
45
+ *
46
+ * The predicate `a.pre <= d.pre and d.post <= a.post` tests whether `a` contains `d` in O(1) time.
47
+ * It needs no chain scan or tier information.
48
+ *
49
+ * Descendants of `a` occupy the contiguous range `pre between a.pre and a.post`.
50
+ * Interval labels add relabeling work to updates.
51
+ *
52
+ * This database is sealed and read-only, so the builder can regenerate all labels together.
53
+ *
54
+ * WOF places can have multiple parents because boundaries can be ambiguous
55
+ * or participate in multiple hierarchies.
56
+ * `candidate_ancestor` stores every parent.
57
+ *
58
+ * Its closure rows hold the complete containment record.
59
+ * One interval pair encodes only a tree.
60
+ *
61
+ * The interval forest therefore links each place to one canonical parent:
62
+ * the depth-1 edge with the finest containment tier and lowest ancestor id.
63
+ * This follows the same MIN-based stability convention as the candidate table's `region_id` stamp.
64
+ *
65
+ * A containment query about another hierarchy must consult the closure rows.
66
+ * The interval result answers only whether a place is contained along the canonical hierarchy.
47
67
  *
48
68
  * absence semantics (meaning-of-zero): a place with no `candidate_interval` row has no recorded
49
- * ancestry in the source (extract-fed postcodes and localities, isolated places, cycle-skipped
50
- * rows). Absence is unverifiable, never a containment verdict.
69
+ * ancestry in the source (extract-fed postcodes and localities, isolated places, cycle-skipped rows).
70
+ * Absence is unverifiable, never a containment verdict.
51
71
  */
52
72
 
53
73
  import { sql, type Kysely } from "kysely"
@@ -1,7 +1,7 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
5
  * @file Pass 3b of the candidate build — the containment sidecar (closure rows + interval labels).
6
6
  */
7
7
 
@@ -1,7 +1,7 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
5
  * @file A candidate build pass that keys each admin place under its bare name as well as its full one.
6
6
  */
7
7
 
@@ -1,8 +1,5 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  import { enumerateCountryDisplayNames } from "@mailwoman/codex/country"
8
5
 
@@ -1,8 +1,5 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  import { DatabaseClient } from "@mailwoman/sqlite/client"
8
5
  import { tableExists } from "@mailwoman/sqlite/introspection"
@@ -1,9 +1,9 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * FTS5-trigram fuzzy index over the candidate gazetteer's normalized `name_key`; raw SQL on purpose, since Kysely cannot express `create virtual table … using fts5`.
5
+ * FTS5-trigram fuzzy index over the candidate gazetteer's normalized `name_key`;
6
+ * raw SQL on purpose, since Kysely cannot express `create virtual table … using fts5`.
7
7
  */
8
8
 
9
9
  import type { DatabaseClient } from "@mailwoman/sqlite/client"
@@ -1,32 +1,38 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
+ * The score side of the candidate build: load a WOF admin database's `place_importance`
6
+ * into a lookup the candidate builder probes per place, so every candidate row can
7
+ * include the toponym-fame prior a bare city name is decided on.
8
+ *
9
+ * The join key is `(name_key, country, placetype)`, the same {@link normalizeLocalityForKey}
10
+ * the candidate build uses for its probe key, so the two sides fold identically.
11
+ * The score source is the importance build the candidate build matched to its
12
+ * admin database by md5 (`importance-source.ts`).
5
13
  *
6
- * The score side of the candidate build: load a WOF admin database's `place_importance` into a
7
- * lookup the candidate builder probes per place, so every candidate row can include the
8
- * toponym-fame prior a bare city name is decided on.
14
+ * The join stays on the name key rather than the id, the join every candidate build has used,
15
+ * so matching the two files changes which scores are read and leaves the join unchanged.
9
16
  *
10
- * The join key is `(name_key, country, placetype)`, the same {@link normalizeLocalityForKey} the
11
- * candidate build uses for its probe key, so the two sides fold identically. An id join is wrong
12
- * here, because the score source (`admin-global-priority-importance.db`) and the candidate build's
13
- * admin source are different snapshots whose ids disagree. An id join silently drops rows and
14
- * leaves the ranking inert on the queries the prior exists for.
17
+ * The key by itself isn't enough.
18
+ * `(warwick, US, locality)` covers eleven different places.
15
19
  *
16
- * The key by itself is not enough. `(warwick, US, locality)` covers eleven different places.
17
20
  * The group's maximum would give every Warwick in America the fame of Warwick, Rhode Island.
18
21
  * The join picks the nearest centroid when it falls within {@link IMPORTANCE_JOIN_RADIUS_KM}.
19
- * Two artifacts describing the same settlement put its centroid
20
- * in almost the same place. Two towns with the same name in one country do not.
21
22
  *
22
- * `place_importance.importance` lands in the column verbatim, the pre-split conflation that is
23
- * encyclopedia-derived where the concordance matched and a population-derived proxy everywhere
24
- * else. See {@link CandidateTable.importance} for why the split `encyclopedic` channel is not what
25
- * is written here.
23
+ * Two artifacts describing the same settlement put its centroid in almost the same place.
24
+ * Two towns with the same name in one country do not.
25
+ *
26
+ * `place_importance.importance` lands in the column verbatim, the pre-split conflation that's
27
+ * encyclopedia-derived where the concordance matched and a population-derived proxy everywhere else.
28
+ * See {@link CandidateTable.importance} for why the split `encyclopedic`
29
+ * channel isn't what's written here.
30
+ *
31
+ * A place with no match gets NULL.
32
+ * NULL means the place's fame is unmeasured.
26
33
  *
27
- * A place with no match gets NULL. NULL means the place's fame is unmeasured.
28
- * The consumer (`resolver/toponym-prior.ts`) leaves an unmeasured candidate at the position
29
- * population assigned it.
34
+ * The consumer (`resolver/toponym-prior.ts`) leaves an unmeasured candidate
35
+ * at the position population assigned it.
30
36
  */
31
37
 
32
38
  import { haversine } from "@mailwoman/spatial/geometries/point/distance"
@@ -43,7 +49,7 @@ import { normalizeLocalityForKey } from "#street/normalize"
43
49
  * The nearest-centroid distances separate into a mode where the two snapshots agree
44
50
  * and a background rate of two different towns wearing one name in one country.
45
51
  *
46
- * The background rate does not decay with distance.
52
+ * The background rate doesn't decay with distance.
47
53
  * Ten kilometers separates the two populations.
48
54
  *
49
55
  * That distance matches the join's purpose.
@@ -111,7 +117,7 @@ export class ImportanceIndex {
111
117
  * Compare this number across rebuilds.
112
118
  * A jump means the score source and the admin source have drifted apart
113
119
  * and the join is being asked to guess.
114
- * It does not mean the radius is too tight.
120
+ * It doesn't mean the radius is too tight.
115
121
  */
116
122
  refused = 0
117
123
 
@@ -122,7 +128,7 @@ export class ImportanceIndex {
122
128
 
123
129
  /**
124
130
  * The importance of the scored place nearest `(lat, lon)` sharing `name`'s folded key, `country`
125
- * and `placetype`, or null when there is no such place within {@link IMPORTANCE_JOIN_RADIUS_KM}.
131
+ * and `placetype`, or null when there's no such place within {@link IMPORTANCE_JOIN_RADIUS_KM}.
126
132
  *
127
133
  * Null is unmeasured.
128
134
  * Keep the value null.
@@ -0,0 +1,132 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * @file Extra folds a `candidate.db` applies to every `name_key`, recorded in the artifact so its reader
6
+ * folds each query key the same way.
7
+ *
8
+ * A fold changes which keys exist, so the build and the reader must agree on it. The build applies it
9
+ * as a post-pass over the materialized `candidate` table, and the reader reads the recorded folds once.
10
+ */
11
+
12
+ import type { DatabaseClient } from "@mailwoman/sqlite/client"
13
+
14
+ import type { CandidateDatabase } from "#candidate/schema"
15
+ import { hasTable } from "#sqlite-utils"
16
+ import { type NameKey, withArabicLetterVariantsFolded } from "#street/normalize"
17
+
18
+ /**
19
+ * The table that lists the folds applied to the artifact's `name_key` column, one row per fold.
20
+ * An artifact without it applies none.
21
+ */
22
+ export const CANDIDATE_KEY_FOLD_TABLE = "candidate_key_fold"
23
+
24
+ /**
25
+ * The folds a candidate build can apply on top of `normalizeLocalityForKey`.
26
+ */
27
+ export const CandidateKeyFold = {
28
+ /**
29
+ * {@link withArabicLetterVariantsFolded}: hamza, madda and vowel marks dropped,
30
+ * `ى` written `ي`, `ة` written `ه`.
31
+ */
32
+ ArabicLetterVariants: "arabic-letter-variants",
33
+ } as const
34
+
35
+ export type CandidateKeyFold = (typeof CandidateKeyFold)[keyof typeof CandidateKeyFold]
36
+
37
+ /**
38
+ * The key function of each fold, and the GLOB that selects the keys it can change.
39
+ */
40
+ const FOLDS: Readonly<Record<CandidateKeyFold, { fold: (key: NameKey) => NameKey; glob: string }>> = {
41
+ [CandidateKeyFold.ArabicLetterVariants]: { fold: withArabicLetterVariantsFolded, glob: "*[؀-ۿ]*" },
42
+ }
43
+
44
+ /**
45
+ * The counts {@link applyCandidateKeyFold} reports.
46
+ */
47
+ export interface CandidateKeyFoldResult {
48
+ /**
49
+ * Rows whose key the fold changed.
50
+ */
51
+ rekeyed: number
52
+ /**
53
+ * Rekeyed rows dropped because the folded key already held the same place under the same scope.
54
+ */
55
+ merged: number
56
+ }
57
+
58
+ /**
59
+ * Rewrites every `candidate.name_key` the fold changes and records the fold
60
+ * in {@link CANDIDATE_KEY_FOLD_TABLE}.
61
+ *
62
+ * A row whose folded key already exists for the same place, scope, placetype and rank is merged into it.
63
+ * It runs on a writable copy or inside a build, never on a published artifact.
64
+ */
65
+ export async function applyCandidateKeyFold(
66
+ db: DatabaseClient<CandidateDatabase>,
67
+ foldName: CandidateKeyFold
68
+ ): Promise<CandidateKeyFoldResult> {
69
+ const { fold, glob } = FOLDS[foldName]
70
+ const sqlName = `mw_key_fold_${foldName.replaceAll("-", "_")}`
71
+
72
+ db.function(sqlName, { deterministic: true }, (key) => fold(String(key) as NameKey))
73
+
74
+ const changed = `name_key GLOB '${glob}' AND ${sqlName}(name_key) <> name_key`
75
+ const { n: rekeyed } = db.prepare(`SELECT count(*) AS n FROM candidate WHERE ${changed}`).get() as { n: number }
76
+
77
+ db.exec("BEGIN")
78
+
79
+ const inserted = db
80
+ .prepare(
81
+ "INSERT OR IGNORE INTO candidate SELECT " +
82
+ `${sqlName}(name_key), country_id, region_id, placetype_id, neg_rank, spr_id, name, latitude, longitude, ` +
83
+ "min_lat, min_lon, max_lat, max_lon, population, is_primary, importance, name_role " +
84
+ `FROM candidate WHERE ${changed}`
85
+ )
86
+ .run()
87
+
88
+ db.prepare(`DELETE FROM candidate WHERE ${changed}`).run()
89
+
90
+ await db.schema
91
+ .createTable(CANDIDATE_KEY_FOLD_TABLE)
92
+ .ifNotExists()
93
+ .addColumn("fold", "text", (c) => c.primaryKey())
94
+ .execute()
95
+
96
+ db.prepare(`INSERT OR IGNORE INTO ${CANDIDATE_KEY_FOLD_TABLE} (fold) VALUES (?)`).run(foldName)
97
+ db.exec("COMMIT")
98
+
99
+ return { rekeyed, merged: rekeyed - Number(inserted.changes) }
100
+ }
101
+
102
+ /**
103
+ * The query-key function an artifact's recorded folds call for: identity when it records none.
104
+ *
105
+ * A fold name the reader doesn't know raises, because a key that misses that
106
+ * fold would miss every row the fold rewrote.
107
+ */
108
+ export function candidateQueryKeyFold(db: DatabaseClient<CandidateDatabase>): (key: NameKey) => NameKey {
109
+ if (!hasTable(db, CANDIDATE_KEY_FOLD_TABLE)) return (key) => key
110
+
111
+ const names = (
112
+ db.prepare(`SELECT fold FROM ${CANDIDATE_KEY_FOLD_TABLE} ORDER BY fold`).all() as { fold: string }[]
113
+ ).map((row) => row.fold)
114
+
115
+ const folds = names.map((name) => {
116
+ const known = FOLDS[name as CandidateKeyFold]
117
+
118
+ if (!known) throw new Error(`candidate.db records the key fold ${name}, which this reader doesn't implement`)
119
+
120
+ return known.fold
121
+ })
122
+
123
+ return (key) => {
124
+ let folded = key
125
+
126
+ for (const fold of folds) {
127
+ folded = fold(folded)
128
+ }
129
+
130
+ return folded
131
+ }
132
+ }
@@ -1,8 +1,5 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  import { expandPlacetypeFilter } from "@mailwoman/codex/placetype-map"
8
5
  import type { VariantAliasExemption } from "@mailwoman/core/geocode"
@@ -22,10 +19,11 @@ import {
22
19
  type IntervalLabel,
23
20
  } from "#candidate/ancestors/schema"
24
21
  import { CANDIDATE_FTS_TABLE } from "#candidate/fts"
22
+ import { candidateQueryKeyFold } from "#candidate/key-fold"
25
23
  import type { CandidateDatabase, CandidateTable, CountryCodeTable, PlacetypeCodeTable } from "#candidate/schema"
26
24
  import { readGazetteerCoverageManifest } from "#coverage-manifest-schema"
27
25
  import { POSTAL_CITY_CANDIDATE_TABLE, type PostalCityCandidateTable } from "#postal/city/candidate-schema"
28
- import { rankByPrimaryPreference, type RankedRow, RERANK_FETCH } from "#primary-preference"
26
+ import { rankByPrimaryPreference, type RankedRow, regionAliasMargin, RERANK_FETCH } from "#primary-preference"
29
27
  import { applyProximityRerank } from "#proximity-rerank"
30
28
  import { REGION_CLASS_PLACETYPES, regionQualifierProbeKeys } from "#region-keys"
31
29
  import { hasColumn, hasTable } from "#sqlite-utils"
@@ -136,6 +134,10 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
136
134
  readonly #intervalCache = new Map<number, IntervalLabel | null>()
137
135
 
138
136
  readonly #qualifierProbe: ReturnType<DatabaseClient["prepare"]> | undefined
137
+ /**
138
+ * The folds the artifact recorded for its `name_key` column, applied to every query key.
139
+ */
140
+ readonly #queryKeyFold: (key: NameKey) => NameKey
139
141
  /**
140
142
  * Ancestor lineage accessor, nearest-first, present only when the artifact supports it.
141
143
  */
@@ -144,6 +146,8 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
144
146
  constructor(opts: WOFCandidateTableLookupOpts) {
145
147
  super(opts)
146
148
 
149
+ this.#queryKeyFold = candidateQueryKeyFold(this.database)
150
+
147
151
  for (const r of allRows<CountryCodeTable>(this.database.prepare("SELECT id, code FROM country_codes"))) {
148
152
  const code = String(r.code).toUpperCase()
149
153
  this.#countryToID.set(code, Number(r.id))
@@ -249,7 +253,7 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
249
253
  for (const key of regionQualifierProbeKeys(qualifier, country)) {
250
254
  if (!key) continue
251
255
 
252
- for (const row of allRows<{ spr_id: number }>(this.#qualifierProbe, key)) {
256
+ for (const row of allRows<{ spr_id: number }>(this.#qualifierProbe, this.#queryKeyFold(key as NameKey))) {
253
257
  ids.add(Number(row.spr_id))
254
258
  }
255
259
  }
@@ -428,7 +432,8 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
428
432
  text = text.replaceAll(/\s+/g, "")
429
433
  }
430
434
 
431
- const nameKey = normalizeLocalityForKey(text)
435
+ const nameKey = this.#queryKeyFold(normalizeLocalityForKey(text))
436
+ const strippedNameKey = this.#queryKeyFold(normalizeLocalityForKey(stripLocalityQualifier(text)))
432
437
 
433
438
  if (!nameKey) return []
434
439
 
@@ -538,19 +543,19 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
538
543
 
539
544
  const fetched = allRows<CandidateRow>(this.database.prepare(sql), ...params, Math.max(limit, RERANK_FETCH))
540
545
 
541
- return rankByPrimaryPreference(fetched, limit, undefined, this.#idToPlacetype, this.#variantAliasExemption)
546
+ // Inside a stated region, an alias yields to a different place whose primary name equals
547
+ // the query, including an own-name variant the exemption spares from the worldwide penalty.
548
+ return regionID === null
549
+ ? rankByPrimaryPreference(fetched, limit, undefined, this.#idToPlacetype, this.#variantAliasExemption)
550
+ : rankByPrimaryPreference(fetched, limit, regionAliasMargin, this.#idToPlacetype)
542
551
  }
543
552
 
544
553
  const cascade = (regionID: number | null): Array<RankedRow<CandidateRow>> => {
545
554
  let rows = probe(nameKey, regionID)
546
555
 
547
- if (!rows.length) {
548
- const strippedKey = normalizeLocalityForKey(stripLocalityQualifier(text))
549
-
550
- if (strippedKey && strippedKey !== nameKey) {
551
- // Stripped probes only accept primary rows to avoid alias-scrape matches.
552
- rows = probe(strippedKey, regionID).filter((r) => r.is_primary === 1)
553
- }
556
+ // Stripped probes only accept primary rows to avoid alias-scrape matches.
557
+ if (!rows.length && strippedNameKey && strippedNameKey !== nameKey) {
558
+ rows = probe(strippedNameKey, regionID).filter((r) => r.is_primary === 1)
554
559
  }
555
560
 
556
561
  // Typo-tolerant fallback for true name misses only, skipping postcodes.
@@ -576,7 +581,9 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
576
581
  const hits = allRows<{ name_key: string }>(this.#ftsProbe, match, FUZZY_FETCH)
577
582
 
578
583
  const ranked = hits
579
- .map((h) => ({ nk: String(h.name_key), s: wordFuzzySimilarity(nameKey, String(h.name_key)) }))
584
+ // An index built before the artifact's key folds holds unfolded keys, so each hit is folded too.
585
+ .map((h) => this.#queryKeyFold(String(h.name_key) as NameKey))
586
+ .map((nk) => ({ nk, s: wordFuzzySimilarity(nameKey, nk) }))
580
587
  .filter((h) => h.s >= WORD_FUZZY_MIN && (hasCountryEvidence || h.nk[0] === nameKey[0]))
581
588
  // oxlint-disable-next-line unicorn/no-array-sort -- sorts a freshly-built array. toSorted would double-allocate on a hot path
582
589
  .sort((a, b) => b.s - a.s)
@@ -641,7 +648,7 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
641
648
  // Admin-containment re-rank runs last.
642
649
  const containmentOptions: ContainmentOptions = {
643
650
  nameKey,
644
- strippedKey: normalizeLocalityForKey(stripLocalityQualifier(text)),
651
+ strippedKey: strippedNameKey,
645
652
  shapeFilters,
646
653
  shapeParams,
647
654
  limit,