@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,16 +1,17 @@
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
+ * Build an FST (finite-state transducer) from a WOF SQLite database.
5
6
  *
6
- * Build an FST (finite-state transducer) from a WOF SQLite database. The FST maps normalized token
7
- * sequences to PlaceEntry arrays, pre-computing the valid interpretations for every prefix of
8
- * every place name in the gazetteer.
7
+ * The FST maps normalized token sequences to PlaceEntry arrays, pre-computing the valid
8
+ * interpretations for every prefix of every place name in the gazetteer.
9
9
  *
10
- * Build pipeline: open WOF DB → query spr + names → normalize names → insert into trie → attach
11
- * PlaceEntry at terminals → return FSTMatcher.
10
+ * Build pipeline: open WOF DB → query spr + names → normalize names → insert into
11
+ * trie → attach PlaceEntry at terminals → return FSTMatcher.
12
12
  */
13
13
 
14
+ import { GEONAMES_ID_BASE, OVERTURE_ID_BASE } from "@mailwoman/core/resolver/synthetic-id-ranges"
14
15
  import { allRows, getRow } from "@mailwoman/core/utils"
15
16
  import { DatabaseClient } from "@mailwoman/sqlite/client"
16
17
  import { resolvePath } from "path-ts"
@@ -86,6 +87,17 @@ export async function buildFSTFromWOF(opts: BuildFSTOpts): Promise<{
86
87
  const sprRows = allRows<SprRow>(sprStmt, ...countries, ...placetypes)
87
88
  progress("spr", `Loaded ${sprRows.length} places`)
88
89
 
90
+ // An FST ships in npm packages whose license cannot include the Open Database License,
91
+ // so no place from the Overture Divisions fold may reach one.
92
+ const overturePlaces = sprRows.filter((row) => row.id >= OVERTURE_ID_BASE && row.id < GEONAMES_ID_BASE).length
93
+
94
+ if (overturePlaces) {
95
+ throw new Error(
96
+ `buildFSTFromWOF: ${overturePlaces} of ${sprRows.length} places for [${countries}] come from the Overture ` +
97
+ "Divisions fold, which is ODbL; build the FST from countries the fold does not cover"
98
+ )
99
+ }
100
+
89
101
  const sprByID = new Map<number, SprRow>()
90
102
 
91
103
  for (const row of sprRows) {
@@ -192,14 +204,23 @@ export async function buildFSTFromWOF(opts: BuildFSTOpts): Promise<{
192
204
 
193
205
  const allLanguages = languages.includes("*")
194
206
 
207
+ // A WOF record can hold an alias the Overture fold added to it.
208
+ // A database built before `names.source` existed holds no such alias,
209
+ // because the fold then wrote only its own places.
210
+ const hasSource = allRows<{ name: string }>(db.prepare("SELECT name FROM pragma_table_info('names')")).some(
211
+ (column) => column.name === "source"
212
+ )
213
+
214
+ const sourceFilter = hasSource ? " AND source != 'overture'" : ""
215
+
195
216
  for (let i = 0; i < placeIDs.length; i += 500) {
196
217
  const chunk = placeIDs.slice(i, i + 500)
197
218
  const idPlaceholders = chunk.map(() => "?").join(",")
198
219
 
199
220
  const nameStmt = allLanguages
200
- ? db.prepare(`SELECT id, name, language, privateuse FROM names WHERE id IN (${idPlaceholders})`)
221
+ ? db.prepare(`SELECT id, name, language, privateuse FROM names WHERE id IN (${idPlaceholders})${sourceFilter}`)
201
222
  : db.prepare(
202
- `SELECT id, name, language, privateuse FROM names WHERE id IN (${idPlaceholders}) AND language IN (${languages.map(() => "?").join(",")})`
223
+ `SELECT id, name, language, privateuse FROM names WHERE id IN (${idPlaceholders}) AND language IN (${languages.map(() => "?").join(",")})${sourceFilter}`
203
224
  )
204
225
 
205
226
  const nameRows = allLanguages
@@ -336,7 +357,7 @@ export async function buildFSTFromWOF(opts: BuildFSTOpts): Promise<{
336
357
  // at that path, because the admin database is sealed and replaced by a rebuild
337
358
  // so the path is constant across every generation.
338
359
  // `sourceIdentity` lets a caller that already knows the digest, or is building
339
- // from something that is not a file at all, supply it instead.
360
+ // from something that's not a file at all, supply it instead.
340
361
  progress("stamp", `Reading source identity for ${dbPath}`)
341
362
  const source = opts.sourceIdentity ?? (await readWOFSourceIdentity(dbPath))
342
363
 
@@ -1,13 +1,14 @@
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
+ * Browser-compatible FST reader.
5
6
  *
6
- * Browser-compatible FST reader. Uses DataView + TextDecoder instead of Node's Buffer so the same binary format
7
- * loads in the browser and in a Cloudflare Worker through fetch(url).then(r => r.arrayBuffer()).
7
+ * Uses DataView + TextDecoder instead of Node's Buffer so the same binary format loads in
8
+ * the browser and in a Cloudflare Worker through fetch(url).then(r => r.arrayBuffer()).
8
9
  *
9
- * This is a read-only counterpart to serialize.ts. Serialization stays Node-only because it is a build-time
10
- * operation.
10
+ * This is a read-only counterpart to serialize.ts.
11
+ * Serialization stays Node-only because it is a build-time operation.
11
12
  */
12
13
 
13
14
  import { tryParsingJSON } from "@mailwoman/core/json"
@@ -19,7 +20,7 @@ import type { FSTProvenance } from "#fst/types"
19
20
  /**
20
21
  * Opens an FST binary for matching, answering queries from the bytes in place.
21
22
  *
22
- * The matcher keeps a reference to `input`, so the caller must not modify it afterward.
23
+ * The matcher keeps a reference to `input`, so the caller mustn't modify it afterward.
23
24
  */
24
25
  export function deserializeFSTWeb(input: ArrayBuffer | Uint8Array): BinaryFSTMatcher {
25
26
  return new BinaryFSTMatcher(input)
package/lib/fst/format.ts CHANGED
@@ -1,14 +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 FST binary-format constants, shared by the Node serializer/deserializer
6
+ * (`fst-serialize.ts`) and the browser deserializer (`fst-deserialize-web.ts`).
5
7
  *
6
- * The FST binary-format constants, shared by the Node serializer/deserializer (`fst-serialize.ts`)
7
- * and the browser deserializer (`fst-deserialize-web.ts`). This module stays platform-free.
8
- * It uses no Buffer at module scope. Both runtimes convert {@link FST_MAGIC_BYTES} themselves.
8
+ * This module stays platform-free.
9
+ * It uses no Buffer at module scope.
10
+ * Both runtimes convert {@link FST_MAGIC_BYTES} themselves.
9
11
  */
10
12
 
11
- import type { PlacetypeID } from "#fst/types"
13
+ import type { PlaceEntry, PlacetypeID } from "#fst/types"
12
14
 
13
15
  /**
14
16
  * Format version this tree writes and the maximum either deserializer accepts, published
@@ -23,9 +25,9 @@ import type { PlacetypeID } from "#fst/types"
23
25
  *
24
26
  * It later stayed at 4 through the v5 two-score split until someone updated it by hand.
25
27
  *
26
- * A check that is the writer's version cannot drift from it.
28
+ * A check that's the writer's version cannot drift from it.
27
29
  */
28
- export const FST_FORMAT_VERSION = 5
30
+ export const FST_FORMAT_VERSION = 6
29
31
 
30
32
  /**
31
33
  * Fixed header size in bytes.
@@ -73,18 +75,155 @@ export const VERSION_TWO_SCORE_SPLIT = 5
73
75
  /**
74
76
  * Place-entry size in bytes at or above {@link VERSION_TWO_SCORE_SPLIT}.
75
77
  */
76
- export const SPLIT_PLACE_ENTRY_SIZE = 60
78
+ const SPLIT_PLACE_ENTRY_SIZE = 60
77
79
 
78
80
  /**
79
81
  * Place-entry size in bytes below {@link VERSION_TWO_SCORE_SPLIT}.
80
82
  */
81
- export const LEGACY_PLACE_ENTRY_SIZE = 56
83
+ const LEGACY_PLACE_ENTRY_SIZE = 56
84
+
85
+ /**
86
+ * Format version that moved WOF ids into an id table.
87
+ *
88
+ * A place entry's id and its parent ids are u32 indices into the table.
89
+ * The table follows the place table as a u32 count and one f64 per distinct id in ascending order.
90
+ *
91
+ * The `mailwoman` fork's WOF records take ids from 9,895,000,000, above the u32 maximum of 4,294,967,295.
92
+ *
93
+ * An f64 holds every integer up to 2^53 exactly.
94
+ * Each distinct id is stored once, so a file grows by 8 bytes per distinct id
95
+ * rather than by 36 bytes per place entry.
96
+ */
97
+ export const VERSION_ID_TABLE = 6
98
+
99
+ /**
100
+ * The number of parent-id slots in every place entry.
101
+ */
102
+ export const PARENT_CHAIN_SLOTS = 8
103
+
104
+ /**
105
+ * Where each field of a place entry sits, in bytes from the entry's start, for one format version.
106
+ */
107
+ export interface PlaceEntryLayout {
108
+ size: number
109
+ /**
110
+ * Whether the id fields hold indices into the id table ({@link VERSION_ID_TABLE}) rather than WOF ids.
111
+ */
112
+ idTable: boolean
113
+ placetype: number
114
+ chainLength: number
115
+ crossCountryBranches: number
116
+ flags: number
117
+ name: number
118
+ referential: number
119
+ latitude: number
120
+ longitude: number
121
+ chain: number
122
+ /**
123
+ * `null` before {@link VERSION_TWO_SCORE_SPLIT}, which had no encyclopedic score.
124
+ */
125
+ encyclopedic: number | null
126
+ }
127
+
128
+ /**
129
+ * The place-entry layout of format `version`.
130
+ */
131
+ export function placeEntryLayout(version: number): PlaceEntryLayout {
132
+ return {
133
+ size: version >= VERSION_TWO_SCORE_SPLIT ? SPLIT_PLACE_ENTRY_SIZE : LEGACY_PLACE_ENTRY_SIZE,
134
+ idTable: version >= VERSION_ID_TABLE,
135
+ placetype: 4,
136
+ chainLength: 5,
137
+ crossCountryBranches: 6,
138
+ flags: 7,
139
+ name: 8,
140
+ referential: 12,
141
+ latitude: 16,
142
+ longitude: 20,
143
+ chain: 24,
144
+ encyclopedic: version >= VERSION_TWO_SCORE_SPLIT ? 24 + PARENT_CHAIN_SLOTS * 4 : null,
145
+ }
146
+ }
82
147
 
83
148
  /**
84
- * Byte offset of the encyclopedic float inside a v5 place entry — immediately
85
- * after the 8-slot parent chain.
149
+ * The byte offset of the id table.
150
+ * The table starts where the place table ends.
86
151
  */
87
- export const ENCYCLOPEDIC_OFFSET = 56
152
+ export function idTableOffset(placeTableStart: number, placeCount: number, layout: PlaceEntryLayout): number {
153
+ return placeTableStart + placeCount * layout.size
154
+ }
155
+
156
+ /**
157
+ * The WOF ids an id-table file stores, in table order, or `null` for a file
158
+ * before {@link VERSION_ID_TABLE}.
159
+ */
160
+ export function loadIDTable(view: DataView, offset: number, layout: PlaceEntryLayout): Float64Array | null {
161
+ if (!layout.idTable) return null
162
+ const count = view.getUint32(offset, true)
163
+ const ids = new Float64Array(count)
164
+
165
+ for (let index = 0; index < count; index++) {
166
+ ids[index] = view.getFloat64(offset + 4 + index * 8, true)
167
+ }
168
+
169
+ return ids
170
+ }
171
+
172
+ /**
173
+ * Decodes the place entry at byte `entry` of a format-`version` file.
174
+ *
175
+ * Both deserializers call this, so a layout change reaches the Node and the browser readers together.
176
+ * `string` resolves a string-table index.
177
+ *
178
+ * `ids` is the file's id table, `null` before {@link VERSION_ID_TABLE}.
179
+ * `hasAmbiguity` is the header's flag bit 0.
180
+ */
181
+ export function decodePlaceEntry(
182
+ view: DataView,
183
+ entry: number,
184
+ version: number,
185
+ layout: PlaceEntryLayout,
186
+ hasAmbiguity: boolean,
187
+ string: (index: number) => string,
188
+ ids: Float64Array | null
189
+ ): PlaceEntry {
190
+ const readID = (offset: number) => {
191
+ const value = view.getUint32(entry + offset, true)
192
+
193
+ return ids ? ids[value]! : value
194
+ }
195
+
196
+ const chainLength = view.getUint8(entry + layout.chainLength)
197
+ const parentChain: number[] = new Array(chainLength)
198
+
199
+ for (let index = 0; index < chainLength; index++) {
200
+ parentChain[index] = readID(layout.chain + index * 4)
201
+ }
202
+
203
+ // Version 1 stored a raw population u32 where later versions store the referential score.
204
+ // It maps through the `referentialFromPopulation` curve.
205
+ const referential =
206
+ version >= 2
207
+ ? view.getFloat32(entry + layout.referential, true)
208
+ : Math.min(1, Math.log2(1 + view.getUint32(entry + layout.referential, true) / 1000) / 14)
209
+
210
+ // Files before version 5 have no encyclopedic score, so their reserved flag byte isn't read.
211
+ const hasEncyclopedic =
212
+ layout.encyclopedic !== null &&
213
+ (view.getUint8(entry + layout.flags) & PLACE_FLAG_HAS_ENCYCLOPEDIC) === PLACE_FLAG_HAS_ENCYCLOPEDIC
214
+
215
+ return {
216
+ wofID: readID(0),
217
+ placetype: PLACETYPE_ORDER[view.getUint8(entry + layout.placetype)] ?? "locality",
218
+ name: string(view.getUint32(entry + layout.name, true)),
219
+ referential,
220
+ lat: view.getFloat32(entry + layout.latitude, true),
221
+ lon: view.getFloat32(entry + layout.longitude, true),
222
+ parentChain,
223
+ crossCountryBranches: hasAmbiguity ? view.getUint8(entry + layout.crossCountryBranches) : null,
224
+ encyclopedic: hasEncyclopedic ? view.getFloat32(entry + layout.encyclopedic!, true) : null,
225
+ }
226
+ }
88
227
 
89
228
  /**
90
229
  * `placeFlags` bit 0 (byte `pp+7`, v5+): this place has an encyclopedic score.
@@ -1,8 +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
- *
6
5
  * Does an `fst-*.bin` still match the gazetteer it was built from?
7
6
  */
8
7
 
@@ -1,11 +1,11 @@
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
+ * In-memory FST matcher.
5
6
  *
6
- * In-memory FST matcher. Built by `fst-builder.ts`, queried at runtime for emission priors and CLI
7
- * introspection. The structure is a deterministic trie over normalized tokens with PlaceEntry
8
- * arrays at accepting states.
7
+ * Built by `fst-builder.ts`, queried at runtime for emission priors and CLI introspection.
8
+ * The structure is a deterministic trie over normalized tokens with PlaceEntry arrays at accepting states.
9
9
  */
10
10
 
11
11
  import type { AncestrieMatch } from "@mailwoman/ancestrie"
@@ -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 Binary serialization for the FST gazetteer.
6
6
  *
7
7
  * All integers are little-endian. The writer emits the current version. The reader accepts every earlier version.
@@ -14,9 +14,10 @@
14
14
  * 4 the entry is 12 bytes with u16 counts.
15
15
  * - Edge table, 8 bytes per edge: stringIdx u32, targetState u32.
16
16
  * - Place table, 60 bytes per place: wofID u32, placetypeIdx u8, chainLen u8, crossCountryBranches u8,
17
- * placeFlags u8 (bit 0 means `encyclopedic` is present), nameIdx u32, referential f32, lat f32, lon f32.
18
- * Each entry then stores eight u32 parent ids. Version 5 added encyclopedic f32. Earlier entries contain 56 bytes.
19
- * Those entries have no encyclopedic score.
17
+ * placeFlags u8 (bit 0 means `encyclopedic` is present), nameIdx u32, referential f32, lat f32, lon f32,
18
+ * eight u32 parent ids, encyclopedic f32. From version 6 the wofID and parent-id fields are indices into
19
+ * the id table. Before version 5 the entry is 56 bytes with no encyclopedic score.
20
+ * - Id table, from version 6: a u32 count, then one f64 WOF id per distinct id, ascending.
20
21
  * - Provenance trailer: a u32 length followed by JSON.
21
22
  *
22
23
  * Presence bits keep a missing value distinct from a stored zero.
@@ -25,17 +26,18 @@
25
26
  import { tryParsingJSON, stringifyJSON } from "@mailwoman/core/json"
26
27
 
27
28
  import {
29
+ decodePlaceEntry,
30
+ idTableOffset,
31
+ loadIDTable,
28
32
  EDGE_ENTRY_SIZE,
29
- ENCYCLOPEDIC_OFFSET,
30
33
  FST_FORMAT_VERSION,
31
34
  FST_MAGIC_BYTES,
32
35
  HEADER_SIZE,
33
- LEGACY_PLACE_ENTRY_SIZE,
34
36
  NARROW_STATE_ENTRY_SIZE,
37
+ PARENT_CHAIN_SLOTS,
35
38
  PLACE_FLAG_HAS_ENCYCLOPEDIC,
36
39
  PLACETYPE_ORDER,
37
- SPLIT_PLACE_ENTRY_SIZE,
38
- VERSION_TWO_SCORE_SPLIT,
40
+ placeEntryLayout,
39
41
  VERSION_WIDE_STATE_COUNTERS,
40
42
  VERSION_WITH_METADATA,
41
43
  WIDE_STATE_ENTRY_SIZE,
@@ -47,18 +49,49 @@ import type { FSTProvenance, PlaceEntry } from "#fst/types"
47
49
  const MAGIC = Buffer.from(FST_MAGIC_BYTES)
48
50
 
49
51
  /**
50
- * The longest parent chain stored per place.
52
+ * The place-entry layout this writer emits.
53
+ */
54
+ const PLACE_LAYOUT = placeEntryLayout(FST_FORMAT_VERSION)
55
+
56
+ /**
57
+ * The id table for `nodes`: every place's id and its first {@link PARENT_CHAIN_SLOTS}
58
+ * valid parent ids, distinct and ascending, with each id's index.
51
59
  *
52
- * The writer keeps the first eight valid parent ids and drops the rest.
60
+ * @throws When an id isn't a safe integer.
61
+ * An f64 holds only safe integers exactly.
53
62
  */
54
- const MAX_CHAIN_LEN = 8
63
+ function buildIDTable(nodes: readonly FSTNode[]): { ids: number[]; indexOf: Map<number, number> } {
64
+ const distinct = new Set<number>()
65
+
66
+ for (const node of nodes) {
67
+ for (const place of node.places) {
68
+ distinct.add(place.wofID)
69
+
70
+ for (const id of validParentChain(place.parentChain)) {
71
+ distinct.add(id)
72
+ }
73
+ }
74
+ }
75
+
76
+ const ids = [...distinct].toSorted((a, b) => a - b)
77
+
78
+ for (const id of ids) {
79
+ if (!Number.isSafeInteger(id)) throw new RangeError(`serializeFST: WOF id ${id} is not a safe integer`)
80
+ }
55
81
 
56
- const placetypeToIdx = new Map<string, number>()
82
+ return { ids, indexOf: new Map(ids.map((id, index) => [id, index])) }
83
+ }
57
84
 
58
- for (let i = 0; i < PLACETYPE_ORDER.length; i++) {
59
- placetypeToIdx.set(PLACETYPE_ORDER[i]!, i)
85
+ /**
86
+ * The parent ids a place entry stores: the first eight positive ids,
87
+ * since WOF uses negative ids such as -1 as sentinels.
88
+ */
89
+ function validParentChain(chain: readonly number[]): number[] {
90
+ return chain.filter((id) => id > 0).slice(0, PARENT_CHAIN_SLOTS)
60
91
  }
61
92
 
93
+ const placetypeToIdx = new Map<string, number>(PLACETYPE_ORDER.map((placetype, index) => [placetype, index]))
94
+
62
95
  /**
63
96
  * Serializes a matcher, with optional provenance, into the current FST binary format.
64
97
  */
@@ -104,10 +137,12 @@ export function serializeFST(matcher: FSTMatcher, provenance?: FSTProvenance): B
104
137
  const stringTableSize = (strings.length + 1) * 4 + stringBytes
105
138
  const stateTableSize = nodes.length * WIDE_STATE_ENTRY_SIZE
106
139
  const edgeTableSize = totalEdges * EDGE_ENTRY_SIZE
107
- const placeTableSize = totalPlaces * SPLIT_PLACE_ENTRY_SIZE
140
+ const placeTableSize = totalPlaces * PLACE_LAYOUT.size
141
+ const idTable = buildIDTable(nodes)
142
+ const idTableSize = 4 + idTable.ids.length * 8
108
143
  const provenanceJson = provenance ? Buffer.from(stringifyJSON(provenance), "utf8") : null
109
144
  const provenanceSize = provenanceJson ? 4 + provenanceJson.length : 0
110
- const binarySize = HEADER_SIZE + stringTableSize + stateTableSize + edgeTableSize + placeTableSize
145
+ const binarySize = HEADER_SIZE + stringTableSize + stateTableSize + edgeTableSize + placeTableSize + idTableSize
111
146
  const totalSize = binarySize + provenanceSize
112
147
  const buf = Buffer.alloc(totalSize)
113
148
  let pos = 0
@@ -176,33 +211,44 @@ export function serializeFST(matcher: FSTMatcher, provenance?: FSTProvenance): B
176
211
  }
177
212
 
178
213
  for (const place of node.places) {
179
- const pp = placeTableStart + placeIdx * SPLIT_PLACE_ENTRY_SIZE
180
- // WOF uses negative parent ids such as -1 as sentinels.
181
- const validChain = place.parentChain.filter((id) => id > 0)
182
- const chainLen = Math.min(validChain.length, MAX_CHAIN_LEN)
183
- buf.writeUInt32LE(place.wofID, pp)
184
- buf.writeUInt8(placetypeToIdx.get(place.placetype) ?? 0, pp + 4)
185
- buf.writeUInt8(chainLen, pp + 5)
186
- buf.writeUInt8(hasAmbiguity ? Math.min(place.crossCountryBranches ?? 0, 255) : 0, pp + 6)
214
+ const pp = placeTableStart + placeIdx * PLACE_LAYOUT.size
215
+ const validChain = validParentChain(place.parentChain)
216
+ const chainLen = validChain.length
217
+ buf.writeUInt32LE(idTable.indexOf.get(place.wofID)!, pp)
218
+ buf.writeUInt8(placetypeToIdx.get(place.placetype) ?? 0, pp + PLACE_LAYOUT.placetype)
219
+ buf.writeUInt8(chainLen, pp + PLACE_LAYOUT.chainLength)
220
+
221
+ buf.writeUInt8(
222
+ hasAmbiguity ? Math.min(place.crossCountryBranches ?? 0, 255) : 0,
223
+ pp + PLACE_LAYOUT.crossCountryBranches
224
+ )
225
+
187
226
  // An absent encyclopedic score writes flag 0 and a 0.0 float.
188
227
  // Readers skip the float when the flag is 0.
189
228
  const hasEncyclopedic = place.encyclopedic != null
190
- buf.writeUInt8(hasEncyclopedic ? PLACE_FLAG_HAS_ENCYCLOPEDIC : 0, pp + 7)
191
- buf.writeUInt32LE(intern(place.name), pp + 8)
192
- buf.writeFloatLE(place.referential, pp + 12)
193
- buf.writeFloatLE(place.lat, pp + 16)
194
- buf.writeFloatLE(place.lon, pp + 20)
195
-
196
- for (let ci = 0; ci < MAX_CHAIN_LEN; ci++) {
197
- buf.writeUInt32LE(ci < chainLen ? validChain[ci]! : 0, pp + 24 + ci * 4)
229
+ buf.writeUInt8(hasEncyclopedic ? PLACE_FLAG_HAS_ENCYCLOPEDIC : 0, pp + PLACE_LAYOUT.flags)
230
+ buf.writeUInt32LE(intern(place.name), pp + PLACE_LAYOUT.name)
231
+ buf.writeFloatLE(place.referential, pp + PLACE_LAYOUT.referential)
232
+ buf.writeFloatLE(place.lat, pp + PLACE_LAYOUT.latitude)
233
+ buf.writeFloatLE(place.lon, pp + PLACE_LAYOUT.longitude)
234
+
235
+ for (let ci = 0; ci < PARENT_CHAIN_SLOTS; ci++) {
236
+ buf.writeUInt32LE(ci < chainLen ? idTable.indexOf.get(validChain[ci]!)! : 0, pp + PLACE_LAYOUT.chain + ci * 4)
198
237
  }
199
238
 
200
- buf.writeFloatLE(place.encyclopedic ?? 0, pp + ENCYCLOPEDIC_OFFSET)
239
+ buf.writeFloatLE(place.encyclopedic ?? 0, pp + PLACE_LAYOUT.encyclopedic!)
201
240
 
202
241
  placeIdx++
203
242
  }
204
243
  }
205
244
 
245
+ const idTableStart = idTableOffset(placeTableStart, totalPlaces, PLACE_LAYOUT)
246
+ buf.writeUInt32LE(idTable.ids.length, idTableStart)
247
+
248
+ for (const [index, id] of idTable.ids.entries()) {
249
+ buf.writeDoubleLE(id, idTableStart + 4 + index * 8)
250
+ }
251
+
206
252
  if (provenanceJson) {
207
253
  const trailerStart = binarySize
208
254
  buf.writeUInt32LE(provenanceJson.length, trailerStart)
@@ -227,13 +273,13 @@ export function deserializeFST(buf: Buffer): FSTMatcher {
227
273
  throw new Error(`FST version ${version} unsupported (expected 1..${FST_FORMAT_VERSION})`)
228
274
  }
229
275
 
230
- const isV2 = version >= 2
231
- const isSplit = version >= VERSION_TWO_SCORE_SPLIT
232
276
  const hasAmbiguity = (buf.readUInt16LE(6) & 1) === 1
277
+ const placeLayout = placeEntryLayout(version)
278
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)
233
279
 
234
280
  const stateCount = buf.readUInt32LE(8)
235
281
  const edgeCount = buf.readUInt32LE(12)
236
- const _placeCount = buf.readUInt32LE(16)
282
+ const placeCount = buf.readUInt32LE(16)
237
283
  const stringCount = buf.readUInt32LE(20)
238
284
  const stringBytes = buf.readUInt32LE(24)
239
285
 
@@ -258,10 +304,10 @@ export function deserializeFST(buf: Buffer): FSTMatcher {
258
304
  pos += stringBytes
259
305
 
260
306
  const stateEntrySize = version >= VERSION_WIDE_STATE_COUNTERS ? WIDE_STATE_ENTRY_SIZE : NARROW_STATE_ENTRY_SIZE
261
- const placeEntrySize = version >= VERSION_TWO_SCORE_SPLIT ? SPLIT_PLACE_ENTRY_SIZE : LEGACY_PLACE_ENTRY_SIZE
262
307
  const stateTableStart = pos
263
308
  const edgeTableStart = stateTableStart + stateCount * stateEntrySize
264
309
  const placeTableStart = edgeTableStart + edgeCount * EDGE_ENTRY_SIZE
310
+ const ids = loadIDTable(view, idTableOffset(placeTableStart, placeCount, placeLayout), placeLayout)
265
311
 
266
312
  const nodes: FSTNode[] = new Array(stateCount)
267
313
 
@@ -288,36 +334,15 @@ export function deserializeFST(buf: Buffer): FSTMatcher {
288
334
  const places: PlaceEntry[] = new Array(placeCountForState)
289
335
 
290
336
  for (let pi = 0; pi < placeCountForState; pi++) {
291
- const pp = placeTableStart + (placeStart + pi) * placeEntrySize
292
- const chainLen = buf.readUInt8(pp + 5)
293
- const parentChain: number[] = []
294
-
295
- for (let ci = 0; ci < chainLen; ci++) {
296
- parentChain.push(buf.readUInt32LE(pp + 24 + ci * 4))
297
- }
298
-
299
- // Version 1 stored a raw population u32 here.
300
- // This version maps it through the `referentialFromPopulation` curve.
301
- // Later versions store an f32 score.
302
- const referential = isV2
303
- ? buf.readFloatLE(pp + 12)
304
- : Math.min(1, Math.log2(1 + buf.readUInt32LE(pp + 12) / 1000) / 14)
305
-
306
- // Files before version 5 have no encyclopedic score, so their reserved byte is not read as a flag.
307
- const hasEncyclopedic =
308
- isSplit && (buf.readUInt8(pp + 7) & PLACE_FLAG_HAS_ENCYCLOPEDIC) === PLACE_FLAG_HAS_ENCYCLOPEDIC
309
-
310
- places[pi] = {
311
- wofID: buf.readUInt32LE(pp),
312
- placetype: PLACETYPE_ORDER[buf.readUInt8(pp + 4)] ?? "locality",
313
- name: strings[buf.readUInt32LE(pp + 8)]!,
314
- referential,
315
- lat: buf.readFloatLE(pp + 16),
316
- lon: buf.readFloatLE(pp + 20),
317
- parentChain,
318
- crossCountryBranches: hasAmbiguity ? buf.readUInt8(pp + 6) : null,
319
- encyclopedic: hasEncyclopedic ? buf.readFloatLE(pp + ENCYCLOPEDIC_OFFSET) : null,
320
- }
337
+ places[pi] = decodePlaceEntry(
338
+ view,
339
+ placeTableStart + (placeStart + pi) * placeLayout.size,
340
+ version,
341
+ placeLayout,
342
+ hasAmbiguity,
343
+ (index) => strings[index]!,
344
+ ids
345
+ )
321
346
  }
322
347
 
323
348
  nodes[si] = { edges, places }
package/lib/fst/types.ts CHANGED
@@ -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 Types for the FST gazetteer. These types map place-name token sequences to place entries.
6
6
  */
7
7
 
@@ -150,7 +150,7 @@ export interface BuildFSTOpts {
150
150
  */
151
151
  excludeSurfaces?: ReadonlySet<string>
152
152
  /**
153
- * Tokens that a name must not consist of entirely, such as "de la".
153
+ * Tokens that a name mustn't consist of entirely, such as "de la".
154
154
  *
155
155
  * Build this set from stopwords only.
156
156
  * A street-type word can be part of a real name, as in "Avenue Road".
package/lib/fst.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 "#fst/autocomplete"
8
5
  export * from "#fst/binary-matcher"
package/lib/fts/query.ts CHANGED
@@ -1,8 +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
- *
6
5
  * Query shaping for the FTS5 lookup: placetype normalization and the match-expression sanitizer.
7
6
  */
8
7
 
package/lib/fts.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 type { DatabaseClient } from "@mailwoman/sqlite/client"
8
5
  import { tableExists } from "@mailwoman/sqlite/introspection"