@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
@@ -0,0 +1,155 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * The one record every address-source adapter emits, and the key-table builder reads.
6
+ */
7
+
8
+ import type { ADMIN_HIERARCHY_TAGS } from "@mailwoman/codex/component"
9
+
10
+ import { type NameKey, normalizeLocalityForKey, type RouteKey, type StreetKey } from "#street/normalize"
11
+
12
+ /**
13
+ * The hierarchy level a place name on an address record states, as the encoder model tags it.
14
+ *
15
+ * A record stores its postcode in {@link AddressRecord.postcode}, so `postcode` is never a name's level.
16
+ */
17
+ export type AddressNameLevel = Exclude<(typeof ADMIN_HIERARCHY_TAGS)[number], "postcode">
18
+
19
+ /**
20
+ * How an adapter arrived at a place name.
21
+ */
22
+ export const AddressNameForm = {
23
+ /**
24
+ * The publisher's own value, such as NAD's `Inc_Muni` `Town of Madison`.
25
+ */
26
+ Written: "written",
27
+ /**
28
+ * The written municipality without its legal-form words, such as `Madison` from `Town of Madison`,
29
+ * or the city an arrondissement belongs to, such as `Paris` from `Paris 3e Arrondissement`.
30
+ *
31
+ * The per-source table of those words is data, never a branch in the adapter.
32
+ */
33
+ Bare: "bare",
34
+ /**
35
+ * The postal city the publisher states, such as NAD's `Post_City`, or the postcode
36
+ * gazetteer's city for the record's postcode.
37
+ */
38
+ Postal: "postal",
39
+ } as const
40
+
41
+ export type AddressNameForm = (typeof AddressNameForm)[keyof typeof AddressNameForm]
42
+
43
+ /**
44
+ * One place name on an address record.
45
+ */
46
+ export interface AddressName {
47
+ level: AddressNameLevel
48
+ form: AddressNameForm
49
+ /**
50
+ * The name as the record states it, kept for display.
51
+ */
52
+ value: string
53
+ /**
54
+ * Shared `normalizeLocalityForKey` of `value`, the form a key table stores and a lookup probes.
55
+ */
56
+ key: NameKey
57
+ }
58
+
59
+ /**
60
+ * Collects a record's names in the order an adapter states them.
61
+ *
62
+ * Each value is trimmed and keyed with `normalizeLocalityForKey`.
63
+ * A value whose key is empty, or whose level and key an earlier name already holds, is skipped.
64
+ */
65
+ export function collectAddressNames(): {
66
+ names: AddressName[]
67
+ add(level: AddressNameLevel, form: AddressNameForm, value: string | null | undefined): void
68
+ } {
69
+ const names: AddressName[] = []
70
+ const seen = new Set<string>()
71
+
72
+ return {
73
+ names,
74
+ add(level, form, value) {
75
+ const trimmed = value?.trim()
76
+
77
+ if (!trimmed) return
78
+
79
+ const key = normalizeLocalityForKey(trimmed)
80
+ const identity = `${level}|${key}`
81
+
82
+ if (!key || seen.has(identity)) return
83
+
84
+ seen.add(identity)
85
+ names.push({ level, form, value: trimmed, key })
86
+ },
87
+ }
88
+ }
89
+
90
+ /**
91
+ * One address point from one source, with every name tagged by its hierarchy level.
92
+ *
93
+ * Two sources' records for one address stay two records.
94
+ * The reader returns both with their sources.
95
+ */
96
+ export interface AddressRecord {
97
+ /**
98
+ * The wire source id the register maps, such as `usgov-nad` or `openaddresses:us/wi/statewide`.
99
+ */
100
+ source: string
101
+ /**
102
+ * The publisher's own id for the point, such as NAD's normalized `UUID`.
103
+ *
104
+ * An adapter whose publisher states none writes a digest of the rendered address.
105
+ */
106
+ sourceRecordID: string
107
+ /**
108
+ * The ISO 3166-1 alpha-2 code of the country the point lies in.
109
+ */
110
+ country: string
111
+ /**
112
+ * The ISO 3166-2 code of the first-level subdivision the point lies in, such as `US-WI`
113
+ * or `FR-IDF`, or `null` when the source states none.
114
+ *
115
+ * A country large enough to be split is written one file per subdivision.
116
+ */
117
+ subdivision: string | null
118
+ /**
119
+ * The house number lower-cased and kept as text, since `123-A` and `12 1/2` are numbers.
120
+ */
121
+ number: string
122
+ unit: string | null
123
+ /**
124
+ * The street as the publisher writes it, kept for display.
125
+ */
126
+ streetRaw: string
127
+ streetKey: StreetKey
128
+ routeKey: RouteKey
129
+ postcode: string | null
130
+ /**
131
+ * Every place name the record states or an adapter derived, at every level, in no fixed order.
132
+ *
133
+ * A level may hold several names, such as a municipality's written and bare forms.
134
+ */
135
+ names: readonly AddressName[]
136
+ /**
137
+ * The publisher's own code for the municipality, such as BAN's `code_insee` (`75103`),
138
+ * or `null` when the publisher states none.
139
+ *
140
+ * The key-table build joins it to the Who's On First place that holds the same code.
141
+ */
142
+ adminCode: string | null
143
+ lat: number
144
+ lon: number
145
+ /**
146
+ * How the publisher placed the point, such as NAD's `Placement` (`Structure - Rooftop`),
147
+ * or `null` when unstated.
148
+ */
149
+ placement: string | null
150
+ /**
151
+ * The authority that assigned the address, such as NAD's `AddAuth` (`co.adams.wi.us`),
152
+ * or `null` when unstated.
153
+ */
154
+ authority: string | null
155
+ }
@@ -0,0 +1,20 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * Counts the distinct addresses one source places at one point.
6
+ */
7
+
8
+ /**
9
+ * The SQL that lists every stacked point of an `address` table: each source and point,
10
+ * rounded to 1e-5 degrees, with `n`, the distinct street-and-number pairs the source
11
+ * places there, for points where `n` exceeds `minimum`.
12
+ *
13
+ * It selects `source_id`, `la`, `lo` and `n`.
14
+ * The layer build, its duplicate rule and the pair sampler all read stacks through it,
15
+ * so each counts a stack the same way.
16
+ */
17
+ export function addressPointStacksSQL(minimum: number): string {
18
+ return `SELECT source_id, round(lat, 5) AS la, round(lon, 5) AS lo, count(DISTINCT street_raw || '|' || number) AS n
19
+ FROM address GROUP BY 1, 2, 3 HAVING n > ${Math.trunc(minimum)}`
20
+ }
@@ -0,0 +1,81 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * Refuses an address record whose point lies outside the bounding box of the subdivision it states.
6
+ */
7
+
8
+ import { type LatLonBounds, latLonBoundsContain } from "@mailwoman/spatial/bbox"
9
+ import { DatabaseClient } from "@mailwoman/sqlite/client"
10
+ import type { PathBuilderLike } from "path-ts"
11
+
12
+ import type { AddressRecord } from "#address/record"
13
+
14
+ /**
15
+ * The reason a record outside its subdivision's box is refused under.
16
+ */
17
+ export const OUTSIDE_SUBDIVISION = "outside-subdivision"
18
+
19
+ /**
20
+ * A record check over one Who's On First admin database, closed on dispose.
21
+ */
22
+ export interface SubdivisionBoundsCheck extends Disposable {
23
+ /**
24
+ * Returns {@linkcode OUTSIDE_SUBDIVISION} for a record whose point lies outside
25
+ * the bounding box of its stated subdivision, or `null`.
26
+ *
27
+ * A record that states no subdivision, or whose subdivision the database
28
+ * holds no current region for, is kept.
29
+ */
30
+ refuse(record: AddressRecord): string | null
31
+ /**
32
+ * The subdivisions the database held no current region for, so their records went unchecked.
33
+ */
34
+ readonly unchecked: ReadonlySet<string>
35
+ }
36
+
37
+ /**
38
+ * Opens a check that reads each subdivision's box from a Who's On First admin database.
39
+ *
40
+ * The region is found by its `iso:code` concordance (`US-WI`), so the check reads
41
+ * every country's subdivisions the same way.
42
+ * Each box is read once and kept.
43
+ */
44
+ export function openSubdivisionBoundsCheck(adminDatabasePath: PathBuilderLike): SubdivisionBoundsCheck {
45
+ const db = new DatabaseClient<unknown>(adminDatabasePath, { readOnly: true })
46
+
47
+ const read = db.prepare(
48
+ `SELECT s.min_latitude AS minLat, s.max_latitude AS maxLat, s.min_longitude AS minLon, s.max_longitude AS maxLon
49
+ FROM concordances c JOIN spr s ON s.id = c.id
50
+ WHERE c.other_source = 'iso:code' AND c.other_id = ? AND s.placetype = 'region' AND s.is_current = 1
51
+ ORDER BY s.max_latitude - s.min_latitude DESC LIMIT 1`
52
+ )
53
+
54
+ const boxes = new Map<string, LatLonBounds | null>()
55
+ const unchecked = new Set<string>()
56
+
57
+ return {
58
+ unchecked,
59
+ refuse(record) {
60
+ const subdivision = record.subdivision
61
+
62
+ if (!subdivision) return null
63
+
64
+ let box = boxes.get(subdivision)
65
+
66
+ if (box === undefined) {
67
+ box = (read.get(subdivision) as LatLonBounds | undefined) ?? null
68
+ boxes.set(subdivision, box)
69
+
70
+ if (!box) {
71
+ unchecked.add(subdivision)
72
+ }
73
+ }
74
+
75
+ if (!box) return null
76
+
77
+ return latLonBoundsContain(box, record.lat, record.lon) ? null : OUTSIDE_SUBDIVISION
78
+ },
79
+ [Symbol.dispose]: () => db[Symbol.dispose](),
80
+ }
81
+ }
package/lib/address.ts CHANGED
@@ -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
  export * from "#address/point"
8
5
  export * from "#address/point/interpolation"
@@ -1,76 +1,47 @@
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
+ * Repair the truncated ancestry left by the `parent_id` closure.
5
6
  *
6
- * Repair the truncated ancestry left by the `parent_id` closure. Must run after `populateAncestors` and before the build freezes.
7
+ * Must run after `populateAncestors` and before the build freezes.
7
8
  */
8
9
 
9
- import { readWOFFeature } from "@mailwoman/gazetteer/whosonfirst"
10
+ import type { WOFFeature } from "@mailwoman/gazetteer/whosonfirst"
10
11
  import { hierarchyAncestorsInAnyBranch } from "@mailwoman/gazetteer/whosonfirst/hierarchy"
11
12
  import type { DatabaseClient } from "@mailwoman/sqlite/client"
12
- import { PathBuilder, type PathBuilderLike } from "path-ts"
13
- import { Globerator } from "spliterator/node/fs"
14
13
 
15
14
  import type { WOFDatabase } from "#schema"
16
15
 
16
+ /**
17
+ * Reads the WOF record with an id, such as a primary-key read of the WOF record store, or returns `null`.
18
+ */
19
+ export type WOFFeatureReader = (
20
+ id: number
21
+ ) => Pick<WOFFeature, "properties"> | null | Promise<Pick<WOFFeature, "properties"> | null>
22
+
17
23
  const TOP_PLACETYPES = new Set(["country", "continent", "empire", "ocean", "marinearea", "planet"])
18
24
 
19
25
  export interface AncestryBackfillResult {
20
26
  placesFixed: number
21
27
  rowsAdded: number
22
28
  /**
23
- * Candidates whose source geojson was not found (non-WOF backfilled places or absent repos),
29
+ * Candidates the reader returned no record for (non-WOF backfilled places or absent repos),
24
30
  * skipped rather than treated as an error.
25
31
  */
26
32
  noGeojson: number
27
33
  }
28
34
 
29
- /**
30
- * Discover the `data` directories under a WOF repos root that hold attached geojson,
31
- * accepting both the nested lab layout and a flat layout at most two directory levels deep.
32
- */
33
- export async function discoverAdminDataRoots(reposRoot: PathBuilderLike): Promise<PathBuilder[]> {
34
- const roots: PathBuilder[] = []
35
-
36
- const visit = async (dir: PathBuilder, depth: number): Promise<void> => {
37
- if (depth > 2) return
38
-
39
- let names: string[]
40
-
41
- try {
42
- names = (await Globerator.from("*", { cwd: dir, withFileTypes: true, onlyFiles: false }).toArray())
43
- .filter((entry) => entry.isDirectory())
44
- .map((entry) => entry.name)
45
- } catch {
46
- return
47
- }
48
-
49
- for (const name of names) {
50
- const child = dir(name)
51
-
52
- if (name === "data") {
53
- roots.push(child)
54
- } else if (name.startsWith("whosonfirst-data")) {
55
- await visit(child, depth + 1)
56
- }
57
- }
58
- }
59
-
60
- await visit(PathBuilder.from(reposRoot), 0)
61
-
62
- return roots
63
- }
64
-
65
35
  /**
66
36
  * Insert missing ancestor rows for places whose ancestry chain ended before reaching a country.
67
37
  *
68
- * The function reads `wof:hierarchy` and runs in one transaction under the caller's connection.
38
+ * The function reads each candidate's `wof:hierarchy` through `readFeature`
39
+ * and runs in one transaction under the caller's connection.
69
40
  * `opts.maxID` bounds the scan to avoid probing synthetic-id Overture and GeoNames rows.
70
41
  */
71
42
  export async function backfillAncestorsFromHierarchy(
72
43
  db: DatabaseClient<WOFDatabase>,
73
- geojsonRoots: readonly PathBuilderLike[],
44
+ readFeature: WOFFeatureReader,
74
45
  opts: { maxID?: number } = {}
75
46
  ): Promise<AncestryBackfillResult> {
76
47
  const maxID = opts.maxID ?? Number.MAX_SAFE_INTEGER
@@ -123,7 +94,7 @@ export async function backfillAncestorsFromHierarchy(
123
94
 
124
95
  for (const { id, placetype } of candidates) {
125
96
  if (placetype && TOP_PLACETYPES.has(placetype)) continue
126
- const gj = await readWOFFeature(id, geojsonRoots)
97
+ const gj = await readFeature(id)
127
98
  const hierarchy = gj?.properties?.["wof:hierarchy"]
128
99
 
129
100
  if (!hierarchy || !hierarchy.length) {
package/lib/ancestry.ts CHANGED
@@ -1,16 +1,16 @@
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 shared ancestor-lineage walk over the WOF `ancestors` table: one place's
6
+ * containment chain joined with `spr` for canonical names and centroids,
7
+ * ordered nearest-first with the deepest placetype first and the country last.
5
8
  *
6
- * The shared ancestor-lineage walk over the WOF `ancestors` table: one place's containment chain
7
- * joined with `spr` for canonical names and centroids, ordered nearest-first with the deepest
8
- * placetype first and the country last.
9
+ * The reverse geocoder and `WOFSQLitePlaceLookup.ancestors()` share this walk.
10
+ * Placetype specificity lives here in `PLACETYPE_DEPTH`, a single TypeScript map that extends
11
+ * below `localadmin` so locality, borough, neighborhood and microhood rank correctly.
9
12
  *
10
- * The reverse geocoder and `WOFSQLitePlaceLookup.ancestors()` share this walk. Placetype
11
- * specificity lives here in `PLACETYPE_DEPTH`, a single TypeScript map that extends below
12
- * `localadmin` so locality, borough, neighborhood and microhood rank correctly. Forward
13
- * resolution rarely sees those as ancestor placetypes, while reverse geocoding always does.
13
+ * Forward resolution rarely sees those as ancestor placetypes, while reverse geocoding always does.
14
14
  */
15
15
 
16
16
  import { allRows } from "@mailwoman/core/utils"
@@ -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 { COUNTRY_POPULATION } from "@mailwoman/codex/country"
8
5
  import { bareAdminName } from "@mailwoman/codex/country/bare-admin-names"
@@ -20,7 +17,9 @@ import { stageCountryDisplayNames } from "#candidate/country-display-names"
20
17
  import { foldExtract } from "#candidate/extract-fold"
21
18
  import { createCandidateFTS } from "#candidate/fts"
22
19
  import { IMPORTANCE_JOIN_RADIUS_KM, loadImportanceIndex } from "#candidate/importance"
20
+ import { applyCandidateKeyFold, type CandidateKeyFold } from "#candidate/key-fold"
23
21
  import { GLOSS_KEY_THRESHOLD, stampNameRoles } from "#candidate/name-roles"
22
+ import { refuseNicknamesOfNamesakes } from "#candidate/nickname-namesakes"
24
23
  import type { PlaceAttrs } from "#candidate/place-attrs"
25
24
  import {
26
25
  CANDIDATE_COLUMNS,
@@ -30,7 +29,6 @@ import {
30
29
  } from "#candidate/schema"
31
30
  import { createCapitalTable } from "#capital-schema"
32
31
  import type { CapitalPoint } from "#capitals"
33
- import { resurrectCurrencyHoles } from "#currency-backfill"
34
32
  import type { WOFDatabase } from "#schema"
35
33
  import { normalizeLocalityForKey } from "#street/normalize"
36
34
 
@@ -87,25 +85,6 @@ export interface BuildCandidateOptions {
87
85
  */
88
86
  importance?: PathBuilderLike
89
87
 
90
- /**
91
- * Settings for restoring deprecated WOF places that have no successor and have a GeoNames attestation.
92
- *
93
- * A deprecated place is restored only when no live row of the same name lies within 10 km and
94
- * a GeoNames populated place with the same folded name and at least 1,000 people lies within 10 km.
95
- * Countries without `<cc>.txt` under `geonamesDir` are skipped and reported.
96
- */
97
- currencyBackfill?: {
98
- geonamesDir: PathBuilderLike
99
- countries: readonly string[]
100
-
101
- /**
102
- * The deprecated placetypes eligible for restoration.
103
- *
104
- * @defaultValue `locality`
105
- */
106
- deadPlacetypes?: readonly string[]
107
- }
108
-
109
88
  /**
110
89
  * Receives a phase name and a message as each build step runs.
111
90
  */
@@ -119,6 +98,14 @@ export interface BuildCandidateOptions {
119
98
  * @defaultValue {@linkcode GLOSS_KEY_THRESHOLD}
120
99
  */
121
100
  glossKeyThreshold?: number
101
+
102
+ /**
103
+ * Folds applied to every `name_key` after `normalizeLocalityForKey`, recorded in
104
+ * the artifact so its reader folds query keys the same way.
105
+ *
106
+ * @defaultValue none
107
+ */
108
+ keyFolds?: readonly CandidateKeyFold[]
122
109
  }
123
110
 
124
111
  /**
@@ -129,6 +116,11 @@ export interface BuildCandidateResult {
129
116
  places: number
130
117
  primaries: number
131
118
  aliases: number
119
+ /**
120
+ * The count of alias rows staged as a name's key with its apostrophe-like marks
121
+ * removed (`hawaii` for `Hawaiʻi`), which `aliases` excludes.
122
+ */
123
+ markFreeAliases: number
132
124
 
133
125
  /**
134
126
  * The count of region aliases dropped because another region in the same
@@ -137,6 +129,14 @@ export interface BuildCandidateResult {
137
129
  * The count is always zero for a source without a `names` table.
138
130
  */
139
131
  regionOfficialRefused: number
132
+
133
+ /**
134
+ * The count of alias rows from a colloquial or unclassified name dropped
135
+ * because a populated place holds the same key by a real name.
136
+ *
137
+ * The count is always zero for a source without a `names` table.
138
+ */
139
+ nicknameRefused: number
140
140
  abbrevs: number
141
141
  postcodes: number
142
142
 
@@ -420,32 +420,11 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
420
420
  }).toLocaleString()} bare admin names`
421
421
  )
422
422
 
423
- if (opts.currencyBackfill) {
424
- const nBackfill = await resurrectCurrencyHoles({
425
- src,
426
- tx: kdb,
427
- geonamesDir: opts.currencyBackfill.geonamesDir,
428
- countries: opts.currencyBackfill.countries,
429
- ...(opts.currencyBackfill.deadPlacetypes ? { deadPlacetypes: opts.currencyBackfill.deadPlacetypes } : {}),
430
- attrs,
431
- ccID,
432
- ptID,
433
- regionOf,
434
- importance,
435
- stageRow,
436
- progress,
437
- })
438
-
439
- progress("currency-backfill", `${nBackfill.toLocaleString()} resurrections staged`)
440
- } else {
441
- progress("currency-backfill", "not configured — deprecated-no-successor holes stay dead (#1737)")
442
- }
443
-
444
423
  progress("aliases", "exploding alias bags")
445
424
 
446
425
  const iso2ByCountryID = new Map([...ccodes].map(([code, id]) => [id, code]))
447
426
 
448
- const { nAlias, nBare, keyCounts, regionOfficialRefused } = explodeAliasBags(src, kdb, attrs, stageRow, {
427
+ const { nAlias, nBare, nMarkFree, keyCounts, regionOfficialRefused } = explodeAliasBags(src, kdb, attrs, stageRow, {
449
428
  regionPlacetypeID: ptID("region"),
450
429
  ccID,
451
430
  bareName: (countryID, alias) => bareAdminName(iso2ByCountryID.get(countryID) ?? "", alias),
@@ -453,7 +432,8 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
453
432
 
454
433
  progress(
455
434
  "aliases",
456
- `${nAlias.toLocaleString()} aliases; ${nBare.toLocaleString()} bare admin aliases` +
435
+ `${nAlias.toLocaleString()} aliases; ${nBare.toLocaleString()} bare admin aliases; ` +
436
+ `${nMarkFree.toLocaleString()} mark-free aliases` +
457
437
  (regionOfficialRefused
458
438
  ? `; ${regionOfficialRefused.toLocaleString()} region aliases refused as another region's official name`
459
439
  : "")
@@ -477,6 +457,14 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
477
457
  kdb.exec("COMMIT")
478
458
  progress("abbrevs", `${nAbbr.toLocaleString()} abbrevs`)
479
459
 
460
+ const nicknames = refuseNicknamesOfNamesakes(src, kdb, attrs)
461
+
462
+ progress(
463
+ "nicknames",
464
+ `${nicknames.rows.toLocaleString()} colloquial or unclassified alias rows refused on ` +
465
+ `${nicknames.keys.toLocaleString()} keys a populated place holds by a real name`
466
+ )
467
+
480
468
  const roles = stampNameRoles({
481
469
  src,
482
470
  out: kdb,
@@ -585,6 +573,12 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
585
573
  kdb.exec(`INSERT OR IGNORE INTO candidate (${cols}) SELECT ${cols} FROM cand_stage ORDER BY ${keyOrder};`)
586
574
  await kdb.schema.dropTable("cand_stage").execute()
587
575
 
576
+ for (const fold of opts.keyFolds ?? []) {
577
+ const { rekeyed, merged } = await applyCandidateKeyFold(kdb, fold)
578
+
579
+ progress("key-fold", `${fold}: ${rekeyed.toLocaleString()} rows rekeyed, ${merged.toLocaleString()} merged`)
580
+ }
581
+
588
582
  progress("fts", "building FTS5-trigram fuzzy index")
589
583
  createCandidateFTS(kdb)
590
584
 
@@ -601,7 +595,9 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
601
595
  places: attrs.size,
602
596
  primaries: nPrim,
603
597
  aliases: nAlias,
598
+ markFreeAliases: nMarkFree,
604
599
  regionOfficialRefused,
600
+ nicknameRefused: nicknames.rows,
605
601
  abbrevs: nAbbr,
606
602
  postcodes: nPostcode,
607
603
  postcodeAliases: nPostcodeAlias,
@@ -1,10 +1,10 @@
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 Populations the gazetteer records at a fraction of their size, corrected against the record's own concordance.
6
6
  *
7
- * This file records corrections for review. The build must not rewrite populations from a
7
+ * This file records corrections for review. The build mustn't rewrite populations from a
8
8
  * same-name-parent ratio. The detector cannot distinguish a district's mis-recorded namesake
9
9
  * city from a small village with the district name. Both places are real.
10
10
  *
package/lib/build/slim.ts CHANGED
@@ -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 { statPath, pathExists } from "@mailwoman/core/fs/readers/stat"
8
5
  import { temporaryDirectory } from "@mailwoman/core/fs/temporary"
@@ -161,7 +158,7 @@ export async function buildSlimWOFDatabase(opts: BuildSlimOptions): Promise<Buil
161
158
  }
162
159
 
163
160
  // `place_search` and `place_bbox` derive purely from `spr` + `names`, and the
164
- // population aux table is not rebuilt because it was copied verbatim.
161
+ // population aux table isn't rebuilt because it was copied verbatim.
165
162
  progress("fts", "building place_search / place_bbox on slim DB")
166
163
 
167
164
  buildPlaceSearchFTS(out, {