@mailwoman/resolver-wof-sqlite 11.1.0 → 11.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (467) hide show
  1. package/README.md +5 -5
  2. package/lib/address/duplicate.ts +1 -1
  3. package/lib/address/keys/attribution.ts +6 -1
  4. package/lib/address/keys/build.ts +1 -1
  5. package/lib/address/keys/layout.ts +27 -1
  6. package/lib/address/keys/lookup.ts +2 -2
  7. package/lib/address/keys/point-lookup.ts +2 -2
  8. package/lib/address/number-forms.ts +4 -6
  9. package/lib/address/point/interpolation.ts +11 -3
  10. package/lib/address/point/schema.ts +1 -1
  11. package/lib/address/point.ts +15 -14
  12. package/lib/address/record.ts +1 -1
  13. package/lib/ancestry/backfill.ts +13 -43
  14. package/lib/build/candidate.ts +171 -35
  15. package/lib/build/slim.ts +4 -1
  16. package/lib/build/sources.ts +50 -0
  17. package/lib/candidate/alias-bags.ts +74 -20
  18. package/lib/candidate/ancestors/schema.ts +1 -1
  19. package/lib/candidate/ancestors/sidecar.ts +13 -2
  20. package/lib/candidate/bare-admin-names.ts +1 -1
  21. package/lib/{capital-schema.ts → candidate/capital-schema.ts} +3 -3
  22. package/lib/{capitals.ts → candidate/capitals.ts} +1 -1
  23. package/lib/candidate/country-display-names.ts +1 -1
  24. package/lib/candidate/{extract-fold.ts → extract-rows.ts} +7 -4
  25. package/lib/candidate/importance.ts +90 -11
  26. package/lib/candidate/key-fold.ts +132 -0
  27. package/lib/candidate/lookup.ts +101 -60
  28. package/lib/candidate/name-roles.ts +1 -1
  29. package/lib/candidate/nickname-namesakes.ts +147 -0
  30. package/lib/candidate/overture-twins.ts +83 -0
  31. package/lib/candidate/place-attrs.ts +2 -2
  32. package/lib/candidate/postcode-browse.ts +173 -0
  33. package/lib/candidate/schema.ts +43 -2
  34. package/lib/candidate/scoring.ts +4 -4
  35. package/lib/convention.ts +1 -1
  36. package/lib/env.ts +15 -3
  37. package/lib/fst/binary-matcher.ts +26 -41
  38. package/lib/fst/builder.ts +8 -6
  39. package/lib/fst/deserialize-web.ts +1 -1
  40. package/lib/fst/format.ts +144 -7
  41. package/lib/fst/freshness.ts +2 -2
  42. package/lib/fst/serialize.ts +93 -64
  43. package/lib/fts/query.ts +1 -1
  44. package/lib/{search-fetch.ts → fts/search-fetch.ts} +2 -2
  45. package/lib/geonames/aliases.ts +42 -45
  46. package/lib/geonames/postal.ts +3 -3
  47. package/lib/index.ts +20 -17
  48. package/lib/{postal/city → labels/locality/postal-city}/alias/lookup.ts +1 -1
  49. package/lib/{postal/city → labels/locality/postal-city}/candidate-schema.ts +1 -1
  50. package/lib/labels/locality.ts +6 -0
  51. package/lib/{region-keys.ts → labels/region.ts} +5 -2
  52. package/lib/{street → labels/street}/centroid/schema.ts +1 -1
  53. package/lib/{street → labels/street}/centroid.ts +7 -7
  54. package/lib/{interpolation.ts → labels/street/interpolation.ts} +12 -4
  55. package/lib/labels/street/locale.ts +117 -0
  56. package/lib/{street → labels/street}/morphology/fst/loader.ts +1 -1
  57. package/lib/{street → labels/street}/name-lookup.ts +2 -0
  58. package/lib/{street → labels/street}/normalize.ts +284 -133
  59. package/lib/{street → labels/street}/segment-schema.ts +1 -1
  60. package/lib/{street → labels/street}/table.ts +1 -1
  61. package/lib/labels/street.ts +11 -0
  62. package/lib/landmark/rows.ts +1 -1
  63. package/lib/lookup/browse.ts +304 -0
  64. package/lib/{extracts.ts → lookup/extracts.ts} +1 -1
  65. package/lib/lookup/former-divisions.ts +183 -0
  66. package/lib/{postcode-point-lookup.ts → lookup/postcode-point.ts} +5 -0
  67. package/lib/{reverse.ts → lookup/reverse.ts} +4 -4
  68. package/lib/{types.ts → lookup/types.ts} +10 -0
  69. package/lib/lookup.ts +21 -31
  70. package/lib/poi/schema.ts +1 -1
  71. package/lib/{primary-preference.ts → ranking/primary-preference.ts} +45 -2
  72. package/lib/schema/importance-source.ts +210 -0
  73. package/lib/schema/overture-match.ts +79 -0
  74. package/lib/{place-importance-schema.ts → schema/place-importance.ts} +86 -0
  75. package/lib/schema.ts +3 -3
  76. package/lib/sqlite/convention-source.ts +1 -1
  77. package/lib/uprn/existence.ts +2 -0
  78. package/lib/{weights-overlay-linker.ts → weights/overlay-linker.ts} +244 -103
  79. package/out/address/duplicate.js +1 -1
  80. package/out/address/duplicate.js.map +1 -1
  81. package/out/address/keys/attribution.d.ts +4 -0
  82. package/out/address/keys/attribution.d.ts.map +1 -1
  83. package/out/address/keys/attribution.js +5 -1
  84. package/out/address/keys/attribution.js.map +1 -1
  85. package/out/address/keys/build.d.ts.map +1 -1
  86. package/out/address/keys/build.js +1 -1
  87. package/out/address/keys/build.js.map +1 -1
  88. package/out/address/keys/layout.d.ts +18 -1
  89. package/out/address/keys/layout.d.ts.map +1 -1
  90. package/out/address/keys/layout.js +23 -1
  91. package/out/address/keys/layout.js.map +1 -1
  92. package/out/address/keys/lookup.js +2 -2
  93. package/out/address/keys/lookup.js.map +1 -1
  94. package/out/address/keys/point-lookup.d.ts.map +1 -1
  95. package/out/address/keys/point-lookup.js +2 -2
  96. package/out/address/keys/point-lookup.js.map +1 -1
  97. package/out/address/number-forms.d.ts +1 -1
  98. package/out/address/number-forms.d.ts.map +1 -1
  99. package/out/address/number-forms.js +4 -5
  100. package/out/address/number-forms.js.map +1 -1
  101. package/out/address/point/interpolation.d.ts +1 -1
  102. package/out/address/point/interpolation.d.ts.map +1 -1
  103. package/out/address/point/interpolation.js +9 -2
  104. package/out/address/point/interpolation.js.map +1 -1
  105. package/out/address/point/schema.d.ts +1 -1
  106. package/out/address/point/schema.d.ts.map +1 -1
  107. package/out/address/point.d.ts +4 -5
  108. package/out/address/point.d.ts.map +1 -1
  109. package/out/address/point.js +11 -11
  110. package/out/address/point.js.map +1 -1
  111. package/out/address/record.d.ts +1 -1
  112. package/out/address/record.d.ts.map +1 -1
  113. package/out/address/record.js +1 -1
  114. package/out/address/record.js.map +1 -1
  115. package/out/ancestry/backfill.d.ts +14 -9
  116. package/out/ancestry/backfill.d.ts.map +1 -1
  117. package/out/ancestry/backfill.js +4 -42
  118. package/out/ancestry/backfill.js.map +1 -1
  119. package/out/build/candidate.d.ts +46 -1
  120. package/out/build/candidate.d.ts.map +1 -1
  121. package/out/build/candidate.js +82 -31
  122. package/out/build/candidate.js.map +1 -1
  123. package/out/build/slim.d.ts.map +1 -1
  124. package/out/build/slim.js +4 -1
  125. package/out/build/slim.js.map +1 -1
  126. package/out/build/sources.d.ts +32 -0
  127. package/out/build/sources.d.ts.map +1 -0
  128. package/out/build/sources.js +35 -0
  129. package/out/build/sources.js.map +1 -0
  130. package/out/candidate/alias-bags.d.ts +8 -3
  131. package/out/candidate/alias-bags.d.ts.map +1 -1
  132. package/out/candidate/alias-bags.js +63 -17
  133. package/out/candidate/alias-bags.js.map +1 -1
  134. package/out/candidate/ancestors/schema.d.ts +1 -1
  135. package/out/candidate/ancestors/schema.d.ts.map +1 -1
  136. package/out/candidate/ancestors/sidecar.d.ts +0 -3
  137. package/out/candidate/ancestors/sidecar.d.ts.map +1 -1
  138. package/out/candidate/ancestors/sidecar.js +16 -2
  139. package/out/candidate/ancestors/sidecar.js.map +1 -1
  140. package/out/candidate/bare-admin-names.js +1 -1
  141. package/out/candidate/bare-admin-names.js.map +1 -1
  142. package/out/{capital-schema.d.ts → candidate/capital-schema.d.ts} +2 -2
  143. package/out/candidate/capital-schema.d.ts.map +1 -0
  144. package/out/{capital-schema.js → candidate/capital-schema.js} +2 -2
  145. package/out/candidate/capital-schema.js.map +1 -0
  146. package/out/candidate/capitals.d.ts.map +1 -0
  147. package/out/{capitals.js → candidate/capitals.js} +1 -1
  148. package/out/candidate/capitals.js.map +1 -0
  149. package/out/candidate/country-display-names.js +1 -1
  150. package/out/candidate/country-display-names.js.map +1 -1
  151. package/out/{coverage-manifest-schema.d.ts → candidate/coverage-manifest.d.ts} +1 -1
  152. package/out/candidate/coverage-manifest.d.ts.map +1 -0
  153. package/out/{coverage-manifest-schema.js → candidate/coverage-manifest.js} +1 -1
  154. package/out/candidate/coverage-manifest.js.map +1 -0
  155. package/out/candidate/{extract-fold.d.ts → extract-rows.d.ts} +2 -2
  156. package/out/candidate/extract-rows.d.ts.map +1 -0
  157. package/out/candidate/{extract-fold.js → extract-rows.js} +8 -5
  158. package/out/candidate/extract-rows.js.map +1 -0
  159. package/out/candidate/importance.d.ts +34 -3
  160. package/out/candidate/importance.d.ts.map +1 -1
  161. package/out/candidate/importance.js +57 -11
  162. package/out/candidate/importance.js.map +1 -1
  163. package/out/candidate/key-fold.d.ts +55 -0
  164. package/out/candidate/key-fold.d.ts.map +1 -0
  165. package/out/candidate/key-fold.js +80 -0
  166. package/out/candidate/key-fold.js.map +1 -0
  167. package/out/candidate/lookup.d.ts +5 -1
  168. package/out/candidate/lookup.d.ts.map +1 -1
  169. package/out/candidate/lookup.js +80 -54
  170. package/out/candidate/lookup.js.map +1 -1
  171. package/out/candidate/name-roles.d.ts.map +1 -1
  172. package/out/candidate/name-roles.js +1 -1
  173. package/out/candidate/name-roles.js.map +1 -1
  174. package/out/candidate/nickname-namesakes.d.ts +28 -0
  175. package/out/candidate/nickname-namesakes.d.ts.map +1 -0
  176. package/out/candidate/nickname-namesakes.js +109 -0
  177. package/out/candidate/nickname-namesakes.js.map +1 -0
  178. package/out/candidate/overture-twins.d.ts +30 -0
  179. package/out/candidate/overture-twins.d.ts.map +1 -0
  180. package/out/candidate/overture-twins.js +40 -0
  181. package/out/candidate/overture-twins.js.map +1 -0
  182. package/out/candidate/place-attrs.d.ts +2 -2
  183. package/out/candidate/postcode-browse.d.ts +36 -0
  184. package/out/candidate/postcode-browse.d.ts.map +1 -0
  185. package/out/candidate/postcode-browse.js +119 -0
  186. package/out/candidate/postcode-browse.js.map +1 -0
  187. package/out/candidate/schema.d.ts +30 -2
  188. package/out/candidate/schema.d.ts.map +1 -1
  189. package/out/candidate/schema.js +29 -0
  190. package/out/candidate/schema.js.map +1 -1
  191. package/out/candidate/scoring.d.ts +3 -3
  192. package/out/candidate/scoring.d.ts.map +1 -1
  193. package/out/candidate/scoring.js +2 -2
  194. package/out/candidate/scoring.js.map +1 -1
  195. package/out/convention.d.ts +1 -1
  196. package/out/convention.d.ts.map +1 -1
  197. package/out/env.d.ts +3 -0
  198. package/out/env.d.ts.map +1 -1
  199. package/out/env.js +14 -3
  200. package/out/env.js.map +1 -1
  201. package/out/fst/binary-matcher.d.ts.map +1 -1
  202. package/out/fst/binary-matcher.js +9 -30
  203. package/out/fst/binary-matcher.js.map +1 -1
  204. package/out/fst/builder.d.ts.map +1 -1
  205. package/out/fst/builder.js +8 -6
  206. package/out/fst/builder.js.map +1 -1
  207. package/out/fst/deserialize-web.js +1 -1
  208. package/out/fst/deserialize-web.js.map +1 -1
  209. package/out/fst/format.d.ts +60 -9
  210. package/out/fst/format.d.ts.map +1 -1
  211. package/out/fst/format.js +97 -6
  212. package/out/fst/format.js.map +1 -1
  213. package/out/fst/freshness.js +2 -2
  214. package/out/fst/freshness.js.map +1 -1
  215. package/out/fst/serialize.d.ts.map +1 -1
  216. package/out/fst/serialize.js +67 -55
  217. package/out/fst/serialize.js.map +1 -1
  218. package/out/fts/query.d.ts +1 -1
  219. package/out/fts/query.d.ts.map +1 -1
  220. package/out/{search-fetch.d.ts → fts/search-fetch.d.ts} +2 -2
  221. package/out/fts/search-fetch.d.ts.map +1 -0
  222. package/out/fts/search-fetch.js.map +1 -0
  223. package/out/geonames/aliases.d.ts +18 -18
  224. package/out/geonames/aliases.d.ts.map +1 -1
  225. package/out/geonames/aliases.js +20 -24
  226. package/out/geonames/aliases.js.map +1 -1
  227. package/out/geonames/postal.d.ts +1 -1
  228. package/out/geonames/postal.js +3 -3
  229. package/out/index.d.ts +17 -17
  230. package/out/index.d.ts.map +1 -1
  231. package/out/index.js +12 -12
  232. package/out/index.js.map +1 -1
  233. package/out/{postal/city → labels/locality/postal-city}/alias/lookup.d.ts +1 -1
  234. package/out/labels/locality/postal-city/alias/lookup.d.ts.map +1 -0
  235. package/out/labels/locality/postal-city/alias/lookup.js.map +1 -0
  236. package/out/labels/locality/postal-city/alias/schema.d.ts.map +1 -0
  237. package/out/labels/locality/postal-city/alias/schema.js.map +1 -0
  238. package/out/{postal/city → labels/locality/postal-city}/candidate-schema.d.ts +1 -1
  239. package/out/labels/locality/postal-city/candidate-schema.d.ts.map +1 -0
  240. package/out/labels/locality/postal-city/candidate-schema.js.map +1 -0
  241. package/out/labels/locality.d.ts +4 -0
  242. package/out/labels/locality.d.ts.map +1 -0
  243. package/out/labels/locality.js +6 -0
  244. package/out/labels/locality.js.map +1 -0
  245. package/out/{region-keys.d.ts → labels/region.d.ts} +1 -1
  246. package/out/{region-keys.d.ts.map → labels/region.d.ts.map} +1 -1
  247. package/out/{region-keys.js → labels/region.js} +6 -3
  248. package/out/labels/region.js.map +1 -0
  249. package/out/{street → labels/street}/centroid/schema.d.ts +1 -1
  250. package/out/labels/street/centroid/schema.d.ts.map +1 -0
  251. package/out/labels/street/centroid/schema.js.map +1 -0
  252. package/out/{street → labels/street}/centroid.d.ts +5 -5
  253. package/out/labels/street/centroid.d.ts.map +1 -0
  254. package/out/{street → labels/street}/centroid.js +5 -5
  255. package/out/labels/street/centroid.js.map +1 -0
  256. package/out/{interpolation.d.ts → labels/street/interpolation.d.ts} +6 -1
  257. package/out/labels/street/interpolation.d.ts.map +1 -0
  258. package/out/{interpolation.js → labels/street/interpolation.js} +10 -8
  259. package/out/labels/street/interpolation.js.map +1 -0
  260. package/out/labels/street/locale.d.ts +26 -0
  261. package/out/labels/street/locale.d.ts.map +1 -0
  262. package/out/labels/street/locale.js +98 -0
  263. package/out/labels/street/locale.js.map +1 -0
  264. package/out/labels/street/morphology/fst/builder.d.ts.map +1 -0
  265. package/out/labels/street/morphology/fst/builder.js.map +1 -0
  266. package/out/labels/street/morphology/fst/loader.d.ts.map +1 -0
  267. package/out/{street → labels/street}/morphology/fst/loader.js +1 -1
  268. package/out/labels/street/morphology/fst/loader.js.map +1 -0
  269. package/out/labels/street/name-lookup.d.ts.map +1 -0
  270. package/out/{street → labels/street}/name-lookup.js +2 -0
  271. package/out/labels/street/name-lookup.js.map +1 -0
  272. package/out/labels/street/normalize.d.ts +188 -0
  273. package/out/labels/street/normalize.d.ts.map +1 -0
  274. package/out/{street → labels/street}/normalize.js +200 -119
  275. package/out/labels/street/normalize.js.map +1 -0
  276. package/out/{street → labels/street}/segment-schema.d.ts +1 -1
  277. package/out/labels/street/segment-schema.d.ts.map +1 -0
  278. package/out/labels/street/segment-schema.js.map +1 -0
  279. package/out/labels/street/table.d.ts.map +1 -0
  280. package/out/{street → labels/street}/table.js +1 -1
  281. package/out/labels/street/table.js.map +1 -0
  282. package/out/labels/street.d.ts +9 -0
  283. package/out/labels/street.d.ts.map +1 -0
  284. package/out/labels/street.js +11 -0
  285. package/out/labels/street.js.map +1 -0
  286. package/out/landmark/rows.js +1 -1
  287. package/out/landmark/rows.js.map +1 -1
  288. package/out/lookup/browse.d.ts +79 -0
  289. package/out/lookup/browse.d.ts.map +1 -0
  290. package/out/lookup/browse.js +194 -0
  291. package/out/lookup/browse.js.map +1 -0
  292. package/out/lookup/exact-match.d.ts.map +1 -0
  293. package/out/lookup/exact-match.js.map +1 -0
  294. package/out/lookup/extracts.d.ts.map +1 -0
  295. package/out/{extracts.js → lookup/extracts.js} +1 -1
  296. package/out/lookup/extracts.js.map +1 -0
  297. package/out/lookup/former-divisions.d.ts +99 -0
  298. package/out/lookup/former-divisions.d.ts.map +1 -0
  299. package/out/lookup/former-divisions.js +98 -0
  300. package/out/lookup/former-divisions.js.map +1 -0
  301. package/out/{postcode-point-lookup.d.ts → lookup/postcode-point.d.ts} +5 -1
  302. package/out/lookup/postcode-point.d.ts.map +1 -0
  303. package/out/{postcode-point-lookup.js → lookup/postcode-point.js} +1 -1
  304. package/out/lookup/postcode-point.js.map +1 -0
  305. package/out/{reverse.d.ts → lookup/reverse.d.ts} +1 -1
  306. package/out/lookup/reverse.d.ts.map +1 -0
  307. package/out/{reverse.js → lookup/reverse.js} +3 -3
  308. package/out/lookup/reverse.js.map +1 -0
  309. package/out/{types.d.ts → lookup/types.d.ts} +9 -0
  310. package/out/lookup/types.d.ts.map +1 -0
  311. package/out/lookup/types.js.map +1 -0
  312. package/out/lookup.d.ts +4 -4
  313. package/out/lookup.d.ts.map +1 -1
  314. package/out/lookup.js +14 -20
  315. package/out/lookup.js.map +1 -1
  316. package/out/poi/schema.d.ts +1 -1
  317. package/out/poi/schema.d.ts.map +1 -1
  318. package/out/ranking/name-score.d.ts.map +1 -0
  319. package/out/ranking/name-score.js.map +1 -0
  320. package/out/{primary-preference.d.ts → ranking/primary-preference.d.ts} +20 -1
  321. package/out/ranking/primary-preference.d.ts.map +1 -0
  322. package/out/{primary-preference.js → ranking/primary-preference.js} +35 -1
  323. package/out/ranking/primary-preference.js.map +1 -0
  324. package/out/ranking/proximity-rerank.d.ts.map +1 -0
  325. package/out/ranking/proximity-rerank.js.map +1 -0
  326. package/out/{ranking-weights.d.ts → ranking/weights.d.ts} +1 -1
  327. package/out/ranking/weights.d.ts.map +1 -0
  328. package/out/{ranking-weights.js → ranking/weights.js} +1 -1
  329. package/out/ranking/weights.js.map +1 -0
  330. package/out/schema/importance-source.d.ts +90 -0
  331. package/out/schema/importance-source.d.ts.map +1 -0
  332. package/out/schema/importance-source.js +133 -0
  333. package/out/schema/importance-source.js.map +1 -0
  334. package/out/schema/overture-match.d.ts +53 -0
  335. package/out/schema/overture-match.d.ts.map +1 -0
  336. package/out/schema/overture-match.js +33 -0
  337. package/out/schema/overture-match.js.map +1 -0
  338. package/out/{place-importance-schema.d.ts → schema/place-importance.d.ts} +50 -1
  339. package/out/schema/place-importance.d.ts.map +1 -0
  340. package/out/{place-importance-schema.js → schema/place-importance.js} +34 -1
  341. package/out/schema/place-importance.js.map +1 -0
  342. package/out/{polygon-schema.d.ts → schema/polygon.d.ts} +1 -1
  343. package/out/schema/polygon.d.ts.map +1 -0
  344. package/out/{polygon-schema.js → schema/polygon.js} +1 -1
  345. package/out/schema/polygon.js.map +1 -0
  346. package/out/{unified-schema.d.ts → schema/unified.d.ts} +1 -1
  347. package/out/schema/unified.d.ts.map +1 -0
  348. package/out/{unified-schema.js → schema/unified.js} +1 -1
  349. package/out/schema/unified.js.map +1 -0
  350. package/out/schema.d.ts +3 -3
  351. package/out/sqlite/convention-source.js +1 -1
  352. package/out/sqlite/convention-source.js.map +1 -1
  353. package/out/uprn/existence.d.ts.map +1 -1
  354. package/out/uprn/existence.js +2 -0
  355. package/out/uprn/existence.js.map +1 -1
  356. package/out/{weights-overlay-linker.d.ts → weights/overlay-linker.d.ts} +43 -24
  357. package/out/weights/overlay-linker.d.ts.map +1 -0
  358. package/out/{weights-overlay-linker.js → weights/overlay-linker.js} +182 -66
  359. package/out/weights/overlay-linker.js.map +1 -0
  360. package/package.json +12 -32
  361. package/lib/postal.ts +0 -6
  362. package/lib/street/locale.ts +0 -64
  363. package/lib/street.ts +0 -11
  364. package/out/candidate/extract-fold.d.ts.map +0 -1
  365. package/out/candidate/extract-fold.js.map +0 -1
  366. package/out/capital-schema.d.ts.map +0 -1
  367. package/out/capital-schema.js.map +0 -1
  368. package/out/capitals.d.ts.map +0 -1
  369. package/out/capitals.js.map +0 -1
  370. package/out/coverage-manifest-schema.d.ts.map +0 -1
  371. package/out/coverage-manifest-schema.js.map +0 -1
  372. package/out/exact-match.d.ts.map +0 -1
  373. package/out/exact-match.js.map +0 -1
  374. package/out/extracts.d.ts.map +0 -1
  375. package/out/extracts.js.map +0 -1
  376. package/out/interpolation.d.ts.map +0 -1
  377. package/out/interpolation.js.map +0 -1
  378. package/out/name-score.d.ts.map +0 -1
  379. package/out/name-score.js.map +0 -1
  380. package/out/place-importance-schema.d.ts.map +0 -1
  381. package/out/place-importance-schema.js.map +0 -1
  382. package/out/polygon-schema.d.ts.map +0 -1
  383. package/out/polygon-schema.js.map +0 -1
  384. package/out/postal/city/alias/lookup.d.ts.map +0 -1
  385. package/out/postal/city/alias/lookup.js.map +0 -1
  386. package/out/postal/city/alias/schema.d.ts.map +0 -1
  387. package/out/postal/city/alias/schema.js.map +0 -1
  388. package/out/postal/city/candidate-schema.d.ts.map +0 -1
  389. package/out/postal/city/candidate-schema.js.map +0 -1
  390. package/out/postal.d.ts +0 -4
  391. package/out/postal.d.ts.map +0 -1
  392. package/out/postal.js +0 -6
  393. package/out/postal.js.map +0 -1
  394. package/out/postcode-point-lookup.d.ts.map +0 -1
  395. package/out/postcode-point-lookup.js.map +0 -1
  396. package/out/primary-preference.d.ts.map +0 -1
  397. package/out/primary-preference.js.map +0 -1
  398. package/out/proximity-rerank.d.ts.map +0 -1
  399. package/out/proximity-rerank.js.map +0 -1
  400. package/out/ranking-weights.d.ts.map +0 -1
  401. package/out/ranking-weights.js.map +0 -1
  402. package/out/region-keys.js.map +0 -1
  403. package/out/reverse.d.ts.map +0 -1
  404. package/out/reverse.js.map +0 -1
  405. package/out/search-fetch.d.ts.map +0 -1
  406. package/out/search-fetch.js.map +0 -1
  407. package/out/street/centroid/schema.d.ts.map +0 -1
  408. package/out/street/centroid/schema.js.map +0 -1
  409. package/out/street/centroid.d.ts.map +0 -1
  410. package/out/street/centroid.js.map +0 -1
  411. package/out/street/locale.d.ts +0 -12
  412. package/out/street/locale.d.ts.map +0 -1
  413. package/out/street/locale.js +0 -54
  414. package/out/street/locale.js.map +0 -1
  415. package/out/street/morphology/fst/builder.d.ts.map +0 -1
  416. package/out/street/morphology/fst/builder.js.map +0 -1
  417. package/out/street/morphology/fst/loader.d.ts.map +0 -1
  418. package/out/street/morphology/fst/loader.js.map +0 -1
  419. package/out/street/name-lookup.d.ts.map +0 -1
  420. package/out/street/name-lookup.js.map +0 -1
  421. package/out/street/normalize.d.ts +0 -111
  422. package/out/street/normalize.d.ts.map +0 -1
  423. package/out/street/normalize.js.map +0 -1
  424. package/out/street/segment-schema.d.ts.map +0 -1
  425. package/out/street/segment-schema.js.map +0 -1
  426. package/out/street/table.d.ts.map +0 -1
  427. package/out/street/table.js.map +0 -1
  428. package/out/street.d.ts +0 -9
  429. package/out/street.d.ts.map +0 -1
  430. package/out/street.js +0 -11
  431. package/out/street.js.map +0 -1
  432. package/out/types.d.ts.map +0 -1
  433. package/out/types.js.map +0 -1
  434. package/out/unified-schema.d.ts.map +0 -1
  435. package/out/unified-schema.js.map +0 -1
  436. package/out/weights-overlay-linker.d.ts.map +0 -1
  437. package/out/weights-overlay-linker.js.map +0 -1
  438. /package/lib/{coverage-manifest-schema.ts → candidate/coverage-manifest.ts} +0 -0
  439. /package/lib/{postal/city → labels/locality/postal-city}/alias/schema.ts +0 -0
  440. /package/lib/{street → labels/street}/morphology/fst/builder.ts +0 -0
  441. /package/lib/{exact-match.ts → lookup/exact-match.ts} +0 -0
  442. /package/lib/{name-score.ts → ranking/name-score.ts} +0 -0
  443. /package/lib/{proximity-rerank.ts → ranking/proximity-rerank.ts} +0 -0
  444. /package/lib/{ranking-weights.ts → ranking/weights.ts} +0 -0
  445. /package/lib/{polygon-schema.ts → schema/polygon.ts} +0 -0
  446. /package/lib/{unified-schema.ts → schema/unified.ts} +0 -0
  447. /package/out/{capitals.d.ts → candidate/capitals.d.ts} +0 -0
  448. /package/out/{search-fetch.js → fts/search-fetch.js} +0 -0
  449. /package/out/{postal/city → labels/locality/postal-city}/alias/lookup.js +0 -0
  450. /package/out/{postal/city → labels/locality/postal-city}/alias/schema.d.ts +0 -0
  451. /package/out/{postal/city → labels/locality/postal-city}/alias/schema.js +0 -0
  452. /package/out/{postal/city → labels/locality/postal-city}/candidate-schema.js +0 -0
  453. /package/out/{street → labels/street}/centroid/schema.js +0 -0
  454. /package/out/{street → labels/street}/morphology/fst/builder.d.ts +0 -0
  455. /package/out/{street → labels/street}/morphology/fst/builder.js +0 -0
  456. /package/out/{street → labels/street}/morphology/fst/loader.d.ts +0 -0
  457. /package/out/{street → labels/street}/name-lookup.d.ts +0 -0
  458. /package/out/{street → labels/street}/segment-schema.js +0 -0
  459. /package/out/{street → labels/street}/table.d.ts +0 -0
  460. /package/out/{exact-match.d.ts → lookup/exact-match.d.ts} +0 -0
  461. /package/out/{exact-match.js → lookup/exact-match.js} +0 -0
  462. /package/out/{extracts.d.ts → lookup/extracts.d.ts} +0 -0
  463. /package/out/{types.js → lookup/types.js} +0 -0
  464. /package/out/{name-score.d.ts → ranking/name-score.d.ts} +0 -0
  465. /package/out/{name-score.js → ranking/name-score.js} +0 -0
  466. /package/out/{proximity-rerank.d.ts → ranking/proximity-rerank.d.ts} +0 -0
  467. /package/out/{proximity-rerank.js → ranking/proximity-rerank.js} +0 -0
@@ -20,8 +20,8 @@ import { readWOFSourceIdentity } from "#fst/freshness"
20
20
  import type { FSTNode } from "#fst/matcher"
21
21
  import { FSTMatcher, normalizeTokens } from "#fst/matcher"
22
22
  import type { BuildFSTOpts, BuildFSTResult, FSTProvenance, PlaceEntry, PlacetypeID } from "#fst/types"
23
- import { loadImportanceSplit } from "#place-importance-schema"
24
23
  import type { WOFDatabase } from "#schema"
24
+ import { loadImportanceSplit } from "#schema/place-importance"
25
25
 
26
26
  const DEFAULT_PLACETYPES: PlacetypeID[] = [
27
27
  "country",
@@ -33,6 +33,8 @@ const DEFAULT_PLACETYPES: PlacetypeID[] = [
33
33
  "neighbourhood",
34
34
  ]
35
35
 
36
+ // country-branch: an FST built with no country list holds the places of one country, the US.
37
+ // The commit that added the default recorded no reason, and a required `countries` option would replace it.
36
38
  const DEFAULT_COUNTRIES = ["US"]
37
39
  const DEFAULT_LANGUAGES = ["eng", ""]
38
40
  /**
@@ -88,13 +90,13 @@ export async function buildFSTFromWOF(opts: BuildFSTOpts): Promise<{
88
90
  progress("spr", `Loaded ${sprRows.length} places`)
89
91
 
90
92
  // 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.
93
+ // so no place the admin build added from Overture Divisions may reach one.
92
94
  const overturePlaces = sprRows.filter((row) => row.id >= OVERTURE_ID_BASE && row.id < GEONAMES_ID_BASE).length
93
95
 
94
96
  if (overturePlaces) {
95
97
  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
+ `buildFSTFromWOF: ${overturePlaces} of ${sprRows.length} places for [${countries}] come from Overture ` +
99
+ "Divisions, which is ODbL; build the FST from countries the admin build adds no Overture places for"
98
100
  )
99
101
  }
100
102
 
@@ -204,9 +206,9 @@ export async function buildFSTFromWOF(opts: BuildFSTOpts): Promise<{
204
206
 
205
207
  const allLanguages = languages.includes("*")
206
208
 
207
- // A WOF record can hold an alias the Overture fold added to it.
209
+ // A WOF record can hold an alias the Overture step added to it.
208
210
  // A database built before `names.source` existed holds no such alias,
209
- // because the fold then wrote only its own places.
211
+ // because the Overture step then wrote only its own places.
210
212
  const hasSource = allRows<{ name: string }>(db.prepare("SELECT name FROM pragma_table_info('names')")).some(
211
213
  (column) => column.name === "source"
212
214
  )
@@ -11,7 +11,7 @@
11
11
  * Serialization stays Node-only because it is a build-time operation.
12
12
  */
13
13
 
14
- import { tryParsingJSON } from "@mailwoman/core/json"
14
+ import { tryParsingJSON } from "@mailwoman/core/values/json"
15
15
 
16
16
  import { BinaryFSTMatcher } from "#fst/binary-matcher"
17
17
  import { HEADER_SIZE, VERSION_WITH_METADATA } from "#fst/format"
package/lib/fst/format.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * Both runtimes convert {@link FST_MAGIC_BYTES} themselves.
11
11
  */
12
12
 
13
- import type { PlacetypeID } from "#fst/types"
13
+ import type { PlaceEntry, PlacetypeID } from "#fst/types"
14
14
 
15
15
  /**
16
16
  * Format version this tree writes and the maximum either deserializer accepts, published
@@ -27,7 +27,7 @@ import type { PlacetypeID } from "#fst/types"
27
27
  *
28
28
  * A check that's the writer's version cannot drift from it.
29
29
  */
30
- export const FST_FORMAT_VERSION = 5
30
+ export const FST_FORMAT_VERSION = 6
31
31
 
32
32
  /**
33
33
  * Fixed header size in bytes.
@@ -75,18 +75,155 @@ export const VERSION_TWO_SCORE_SPLIT = 5
75
75
  /**
76
76
  * Place-entry size in bytes at or above {@link VERSION_TWO_SCORE_SPLIT}.
77
77
  */
78
- export const SPLIT_PLACE_ENTRY_SIZE = 60
78
+ const SPLIT_PLACE_ENTRY_SIZE = 60
79
79
 
80
80
  /**
81
81
  * Place-entry size in bytes below {@link VERSION_TWO_SCORE_SPLIT}.
82
82
  */
83
- export const LEGACY_PLACE_ENTRY_SIZE = 56
83
+ const LEGACY_PLACE_ENTRY_SIZE = 56
84
84
 
85
85
  /**
86
- * Byte offset of the encyclopedic float inside a v5 place entry — immediately
87
- * after the 8-slot parent chain.
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`.
88
130
  */
89
- export const ENCYCLOPEDIC_OFFSET = 56
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
+ }
147
+
148
+ /**
149
+ * The byte offset of the id table.
150
+ * The table starts where the place table ends.
151
+ */
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
+ }
90
227
 
91
228
  /**
92
229
  * `placeFlags` bit 0 (byte `pp+7`, v5+): this place has an encyclopedic score.
@@ -5,11 +5,11 @@
5
5
  * Does an `fst-*.bin` still match the gazetteer it was built from?
6
6
  */
7
7
 
8
+ import { md5File } from "@mailwoman/core/crypto/hash"
8
9
  import { readFileRange, readLocalTextFile } from "@mailwoman/core/fs/readers"
9
10
  import { pathExists, statPath } from "@mailwoman/core/fs/readers/stat"
10
11
  import { writeLocalTextFile } from "@mailwoman/core/fs/writers"
11
- import { md5File } from "@mailwoman/core/hash"
12
- import { tryParsingJSON } from "@mailwoman/core/json"
12
+ import { tryParsingJSON } from "@mailwoman/core/values/json"
13
13
  import { basename, resolvePath, type PathBuilderLike } from "path-ts"
14
14
 
15
15
  import { FST_FORMAT_VERSION } from "#fst/format"
@@ -14,28 +14,30 @@
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.
23
24
  */
24
25
 
25
- import { tryParsingJSON, stringifyJSON } from "@mailwoman/core/json"
26
+ import { tryParsingJSON, stringifyJSON } from "@mailwoman/core/values/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,11 +49,46 @@ 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
+ }
81
+
82
+ return { ids, indexOf: new Map(ids.map((id, index) => [id, index])) }
83
+ }
84
+
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)
91
+ }
55
92
 
56
93
  const placetypeToIdx = new Map<string, number>(PLACETYPE_ORDER.map((placetype, index) => [placetype, index]))
57
94
 
@@ -100,10 +137,12 @@ export function serializeFST(matcher: FSTMatcher, provenance?: FSTProvenance): B
100
137
  const stringTableSize = (strings.length + 1) * 4 + stringBytes
101
138
  const stateTableSize = nodes.length * WIDE_STATE_ENTRY_SIZE
102
139
  const edgeTableSize = totalEdges * EDGE_ENTRY_SIZE
103
- 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
104
143
  const provenanceJson = provenance ? Buffer.from(stringifyJSON(provenance), "utf8") : null
105
144
  const provenanceSize = provenanceJson ? 4 + provenanceJson.length : 0
106
- const binarySize = HEADER_SIZE + stringTableSize + stateTableSize + edgeTableSize + placeTableSize
145
+ const binarySize = HEADER_SIZE + stringTableSize + stateTableSize + edgeTableSize + placeTableSize + idTableSize
107
146
  const totalSize = binarySize + provenanceSize
108
147
  const buf = Buffer.alloc(totalSize)
109
148
  let pos = 0
@@ -172,33 +211,44 @@ export function serializeFST(matcher: FSTMatcher, provenance?: FSTProvenance): B
172
211
  }
173
212
 
174
213
  for (const place of node.places) {
175
- const pp = placeTableStart + placeIdx * SPLIT_PLACE_ENTRY_SIZE
176
- // WOF uses negative parent ids such as -1 as sentinels.
177
- const validChain = place.parentChain.filter((id) => id > 0)
178
- const chainLen = Math.min(validChain.length, MAX_CHAIN_LEN)
179
- buf.writeUInt32LE(place.wofID, pp)
180
- buf.writeUInt8(placetypeToIdx.get(place.placetype) ?? 0, pp + 4)
181
- buf.writeUInt8(chainLen, pp + 5)
182
- 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
+
183
226
  // An absent encyclopedic score writes flag 0 and a 0.0 float.
184
227
  // Readers skip the float when the flag is 0.
185
228
  const hasEncyclopedic = place.encyclopedic != null
186
- buf.writeUInt8(hasEncyclopedic ? PLACE_FLAG_HAS_ENCYCLOPEDIC : 0, pp + 7)
187
- buf.writeUInt32LE(intern(place.name), pp + 8)
188
- buf.writeFloatLE(place.referential, pp + 12)
189
- buf.writeFloatLE(place.lat, pp + 16)
190
- buf.writeFloatLE(place.lon, pp + 20)
191
-
192
- for (let ci = 0; ci < MAX_CHAIN_LEN; ci++) {
193
- 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)
194
237
  }
195
238
 
196
- buf.writeFloatLE(place.encyclopedic ?? 0, pp + ENCYCLOPEDIC_OFFSET)
239
+ buf.writeFloatLE(place.encyclopedic ?? 0, pp + PLACE_LAYOUT.encyclopedic!)
197
240
 
198
241
  placeIdx++
199
242
  }
200
243
  }
201
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
+
202
252
  if (provenanceJson) {
203
253
  const trailerStart = binarySize
204
254
  buf.writeUInt32LE(provenanceJson.length, trailerStart)
@@ -223,13 +273,13 @@ export function deserializeFST(buf: Buffer): FSTMatcher {
223
273
  throw new Error(`FST version ${version} unsupported (expected 1..${FST_FORMAT_VERSION})`)
224
274
  }
225
275
 
226
- const isV2 = version >= 2
227
- const isSplit = version >= VERSION_TWO_SCORE_SPLIT
228
276
  const hasAmbiguity = (buf.readUInt16LE(6) & 1) === 1
277
+ const placeLayout = placeEntryLayout(version)
278
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)
229
279
 
230
280
  const stateCount = buf.readUInt32LE(8)
231
281
  const edgeCount = buf.readUInt32LE(12)
232
- const _placeCount = buf.readUInt32LE(16)
282
+ const placeCount = buf.readUInt32LE(16)
233
283
  const stringCount = buf.readUInt32LE(20)
234
284
  const stringBytes = buf.readUInt32LE(24)
235
285
 
@@ -254,10 +304,10 @@ export function deserializeFST(buf: Buffer): FSTMatcher {
254
304
  pos += stringBytes
255
305
 
256
306
  const stateEntrySize = version >= VERSION_WIDE_STATE_COUNTERS ? WIDE_STATE_ENTRY_SIZE : NARROW_STATE_ENTRY_SIZE
257
- const placeEntrySize = version >= VERSION_TWO_SCORE_SPLIT ? SPLIT_PLACE_ENTRY_SIZE : LEGACY_PLACE_ENTRY_SIZE
258
307
  const stateTableStart = pos
259
308
  const edgeTableStart = stateTableStart + stateCount * stateEntrySize
260
309
  const placeTableStart = edgeTableStart + edgeCount * EDGE_ENTRY_SIZE
310
+ const ids = loadIDTable(view, idTableOffset(placeTableStart, placeCount, placeLayout), placeLayout)
261
311
 
262
312
  const nodes: FSTNode[] = new Array(stateCount)
263
313
 
@@ -284,36 +334,15 @@ export function deserializeFST(buf: Buffer): FSTMatcher {
284
334
  const places: PlaceEntry[] = new Array(placeCountForState)
285
335
 
286
336
  for (let pi = 0; pi < placeCountForState; pi++) {
287
- const pp = placeTableStart + (placeStart + pi) * placeEntrySize
288
- const chainLen = buf.readUInt8(pp + 5)
289
- const parentChain: number[] = []
290
-
291
- for (let ci = 0; ci < chainLen; ci++) {
292
- parentChain.push(buf.readUInt32LE(pp + 24 + ci * 4))
293
- }
294
-
295
- // Version 1 stored a raw population u32 here.
296
- // This version maps it through the `referentialFromPopulation` curve.
297
- // Later versions store an f32 score.
298
- const referential = isV2
299
- ? buf.readFloatLE(pp + 12)
300
- : Math.min(1, Math.log2(1 + buf.readUInt32LE(pp + 12) / 1000) / 14)
301
-
302
- // Files before version 5 have no encyclopedic score, so their reserved byte isn't read as a flag.
303
- const hasEncyclopedic =
304
- isSplit && (buf.readUInt8(pp + 7) & PLACE_FLAG_HAS_ENCYCLOPEDIC) === PLACE_FLAG_HAS_ENCYCLOPEDIC
305
-
306
- places[pi] = {
307
- wofID: buf.readUInt32LE(pp),
308
- placetype: PLACETYPE_ORDER[buf.readUInt8(pp + 4)] ?? "locality",
309
- name: strings[buf.readUInt32LE(pp + 8)]!,
310
- referential,
311
- lat: buf.readFloatLE(pp + 16),
312
- lon: buf.readFloatLE(pp + 20),
313
- parentChain,
314
- crossCountryBranches: hasAmbiguity ? buf.readUInt8(pp + 6) : null,
315
- encyclopedic: hasEncyclopedic ? buf.readFloatLE(pp + ENCYCLOPEDIC_OFFSET) : null,
316
- }
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
+ )
317
346
  }
318
347
 
319
348
  nodes[si] = { edges, places }
package/lib/fts/query.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * Query shaping for the FTS5 lookup: placetype normalization and the match-expression sanitizer.
6
6
  */
7
7
 
8
- import type { FindPlaceQuery, WOFPlacetype } from "#types"
8
+ import type { FindPlaceQuery, WOFPlacetype } from "#lookup/types"
9
9
 
10
10
  export function normalizePlacetypes(p: FindPlaceQuery["placetype"]): WOFPlacetype[] | null {
11
11
  if (!p) return null
@@ -21,8 +21,8 @@ import { bboxAround } from "@mailwoman/spatial/bbox"
21
21
  import type { DatabaseClient, SQLInputValue } from "@mailwoman/sqlite/client"
22
22
 
23
23
  import { PLACE_BBOX_TABLE, PLACE_POPULATION_TABLE } from "#fts"
24
- import type { RankingWeights } from "#ranking-weights"
25
- import type { FindPlaceQuery, WOFPlacetype } from "#types"
24
+ import type { FindPlaceQuery, WOFPlacetype } from "#lookup/types"
25
+ import type { RankingWeights } from "#ranking/weights"
26
26
  /**
27
27
  * Query length at or below which the FTS window is widened.
28
28
  *