@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.
- package/README.md +5 -5
- package/lib/address/duplicate.ts +1 -1
- package/lib/address/keys/attribution.ts +6 -1
- package/lib/address/keys/build.ts +1 -1
- package/lib/address/keys/layout.ts +27 -1
- package/lib/address/keys/lookup.ts +2 -2
- package/lib/address/keys/point-lookup.ts +2 -2
- package/lib/address/number-forms.ts +4 -6
- package/lib/address/point/interpolation.ts +11 -3
- package/lib/address/point/schema.ts +1 -1
- package/lib/address/point.ts +15 -14
- package/lib/address/record.ts +1 -1
- package/lib/ancestry/backfill.ts +13 -43
- package/lib/build/candidate.ts +171 -35
- package/lib/build/slim.ts +4 -1
- package/lib/build/sources.ts +50 -0
- package/lib/candidate/alias-bags.ts +74 -20
- package/lib/candidate/ancestors/schema.ts +1 -1
- package/lib/candidate/ancestors/sidecar.ts +13 -2
- package/lib/candidate/bare-admin-names.ts +1 -1
- package/lib/{capital-schema.ts → candidate/capital-schema.ts} +3 -3
- package/lib/{capitals.ts → candidate/capitals.ts} +1 -1
- package/lib/candidate/country-display-names.ts +1 -1
- package/lib/candidate/{extract-fold.ts → extract-rows.ts} +7 -4
- package/lib/candidate/importance.ts +90 -11
- package/lib/candidate/key-fold.ts +132 -0
- package/lib/candidate/lookup.ts +101 -60
- package/lib/candidate/name-roles.ts +1 -1
- package/lib/candidate/nickname-namesakes.ts +147 -0
- package/lib/candidate/overture-twins.ts +83 -0
- package/lib/candidate/place-attrs.ts +2 -2
- package/lib/candidate/postcode-browse.ts +173 -0
- package/lib/candidate/schema.ts +43 -2
- package/lib/candidate/scoring.ts +4 -4
- package/lib/convention.ts +1 -1
- package/lib/env.ts +15 -3
- package/lib/fst/binary-matcher.ts +26 -41
- package/lib/fst/builder.ts +8 -6
- package/lib/fst/deserialize-web.ts +1 -1
- package/lib/fst/format.ts +144 -7
- package/lib/fst/freshness.ts +2 -2
- package/lib/fst/serialize.ts +93 -64
- package/lib/fts/query.ts +1 -1
- package/lib/{search-fetch.ts → fts/search-fetch.ts} +2 -2
- package/lib/geonames/aliases.ts +42 -45
- package/lib/geonames/postal.ts +3 -3
- package/lib/index.ts +20 -17
- package/lib/{postal/city → labels/locality/postal-city}/alias/lookup.ts +1 -1
- package/lib/{postal/city → labels/locality/postal-city}/candidate-schema.ts +1 -1
- package/lib/labels/locality.ts +6 -0
- package/lib/{region-keys.ts → labels/region.ts} +5 -2
- package/lib/{street → labels/street}/centroid/schema.ts +1 -1
- package/lib/{street → labels/street}/centroid.ts +7 -7
- package/lib/{interpolation.ts → labels/street/interpolation.ts} +12 -4
- package/lib/labels/street/locale.ts +117 -0
- package/lib/{street → labels/street}/morphology/fst/loader.ts +1 -1
- package/lib/{street → labels/street}/name-lookup.ts +2 -0
- package/lib/{street → labels/street}/normalize.ts +284 -133
- package/lib/{street → labels/street}/segment-schema.ts +1 -1
- package/lib/{street → labels/street}/table.ts +1 -1
- package/lib/labels/street.ts +11 -0
- package/lib/landmark/rows.ts +1 -1
- package/lib/lookup/browse.ts +304 -0
- package/lib/{extracts.ts → lookup/extracts.ts} +1 -1
- package/lib/lookup/former-divisions.ts +183 -0
- package/lib/{postcode-point-lookup.ts → lookup/postcode-point.ts} +5 -0
- package/lib/{reverse.ts → lookup/reverse.ts} +4 -4
- package/lib/{types.ts → lookup/types.ts} +10 -0
- package/lib/lookup.ts +21 -31
- package/lib/poi/schema.ts +1 -1
- package/lib/{primary-preference.ts → ranking/primary-preference.ts} +45 -2
- package/lib/schema/importance-source.ts +210 -0
- package/lib/schema/overture-match.ts +79 -0
- package/lib/{place-importance-schema.ts → schema/place-importance.ts} +86 -0
- package/lib/schema.ts +3 -3
- package/lib/sqlite/convention-source.ts +1 -1
- package/lib/uprn/existence.ts +2 -0
- package/lib/{weights-overlay-linker.ts → weights/overlay-linker.ts} +244 -103
- package/out/address/duplicate.js +1 -1
- package/out/address/duplicate.js.map +1 -1
- package/out/address/keys/attribution.d.ts +4 -0
- package/out/address/keys/attribution.d.ts.map +1 -1
- package/out/address/keys/attribution.js +5 -1
- package/out/address/keys/attribution.js.map +1 -1
- package/out/address/keys/build.d.ts.map +1 -1
- package/out/address/keys/build.js +1 -1
- package/out/address/keys/build.js.map +1 -1
- package/out/address/keys/layout.d.ts +18 -1
- package/out/address/keys/layout.d.ts.map +1 -1
- package/out/address/keys/layout.js +23 -1
- package/out/address/keys/layout.js.map +1 -1
- package/out/address/keys/lookup.js +2 -2
- package/out/address/keys/lookup.js.map +1 -1
- package/out/address/keys/point-lookup.d.ts.map +1 -1
- package/out/address/keys/point-lookup.js +2 -2
- package/out/address/keys/point-lookup.js.map +1 -1
- package/out/address/number-forms.d.ts +1 -1
- package/out/address/number-forms.d.ts.map +1 -1
- package/out/address/number-forms.js +4 -5
- package/out/address/number-forms.js.map +1 -1
- package/out/address/point/interpolation.d.ts +1 -1
- package/out/address/point/interpolation.d.ts.map +1 -1
- package/out/address/point/interpolation.js +9 -2
- package/out/address/point/interpolation.js.map +1 -1
- package/out/address/point/schema.d.ts +1 -1
- package/out/address/point/schema.d.ts.map +1 -1
- package/out/address/point.d.ts +4 -5
- package/out/address/point.d.ts.map +1 -1
- package/out/address/point.js +11 -11
- package/out/address/point.js.map +1 -1
- package/out/address/record.d.ts +1 -1
- package/out/address/record.d.ts.map +1 -1
- package/out/address/record.js +1 -1
- package/out/address/record.js.map +1 -1
- package/out/ancestry/backfill.d.ts +14 -9
- package/out/ancestry/backfill.d.ts.map +1 -1
- package/out/ancestry/backfill.js +4 -42
- package/out/ancestry/backfill.js.map +1 -1
- package/out/build/candidate.d.ts +46 -1
- package/out/build/candidate.d.ts.map +1 -1
- package/out/build/candidate.js +82 -31
- package/out/build/candidate.js.map +1 -1
- package/out/build/slim.d.ts.map +1 -1
- package/out/build/slim.js +4 -1
- package/out/build/slim.js.map +1 -1
- package/out/build/sources.d.ts +32 -0
- package/out/build/sources.d.ts.map +1 -0
- package/out/build/sources.js +35 -0
- package/out/build/sources.js.map +1 -0
- package/out/candidate/alias-bags.d.ts +8 -3
- package/out/candidate/alias-bags.d.ts.map +1 -1
- package/out/candidate/alias-bags.js +63 -17
- package/out/candidate/alias-bags.js.map +1 -1
- package/out/candidate/ancestors/schema.d.ts +1 -1
- package/out/candidate/ancestors/schema.d.ts.map +1 -1
- package/out/candidate/ancestors/sidecar.d.ts +0 -3
- package/out/candidate/ancestors/sidecar.d.ts.map +1 -1
- package/out/candidate/ancestors/sidecar.js +16 -2
- package/out/candidate/ancestors/sidecar.js.map +1 -1
- package/out/candidate/bare-admin-names.js +1 -1
- package/out/candidate/bare-admin-names.js.map +1 -1
- package/out/{capital-schema.d.ts → candidate/capital-schema.d.ts} +2 -2
- package/out/candidate/capital-schema.d.ts.map +1 -0
- package/out/{capital-schema.js → candidate/capital-schema.js} +2 -2
- package/out/candidate/capital-schema.js.map +1 -0
- package/out/candidate/capitals.d.ts.map +1 -0
- package/out/{capitals.js → candidate/capitals.js} +1 -1
- package/out/candidate/capitals.js.map +1 -0
- package/out/candidate/country-display-names.js +1 -1
- package/out/candidate/country-display-names.js.map +1 -1
- package/out/{coverage-manifest-schema.d.ts → candidate/coverage-manifest.d.ts} +1 -1
- package/out/candidate/coverage-manifest.d.ts.map +1 -0
- package/out/{coverage-manifest-schema.js → candidate/coverage-manifest.js} +1 -1
- package/out/candidate/coverage-manifest.js.map +1 -0
- package/out/candidate/{extract-fold.d.ts → extract-rows.d.ts} +2 -2
- package/out/candidate/extract-rows.d.ts.map +1 -0
- package/out/candidate/{extract-fold.js → extract-rows.js} +8 -5
- package/out/candidate/extract-rows.js.map +1 -0
- package/out/candidate/importance.d.ts +34 -3
- package/out/candidate/importance.d.ts.map +1 -1
- package/out/candidate/importance.js +57 -11
- package/out/candidate/importance.js.map +1 -1
- package/out/candidate/key-fold.d.ts +55 -0
- package/out/candidate/key-fold.d.ts.map +1 -0
- package/out/candidate/key-fold.js +80 -0
- package/out/candidate/key-fold.js.map +1 -0
- package/out/candidate/lookup.d.ts +5 -1
- package/out/candidate/lookup.d.ts.map +1 -1
- package/out/candidate/lookup.js +80 -54
- package/out/candidate/lookup.js.map +1 -1
- package/out/candidate/name-roles.d.ts.map +1 -1
- package/out/candidate/name-roles.js +1 -1
- package/out/candidate/name-roles.js.map +1 -1
- package/out/candidate/nickname-namesakes.d.ts +28 -0
- package/out/candidate/nickname-namesakes.d.ts.map +1 -0
- package/out/candidate/nickname-namesakes.js +109 -0
- package/out/candidate/nickname-namesakes.js.map +1 -0
- package/out/candidate/overture-twins.d.ts +30 -0
- package/out/candidate/overture-twins.d.ts.map +1 -0
- package/out/candidate/overture-twins.js +40 -0
- package/out/candidate/overture-twins.js.map +1 -0
- package/out/candidate/place-attrs.d.ts +2 -2
- package/out/candidate/postcode-browse.d.ts +36 -0
- package/out/candidate/postcode-browse.d.ts.map +1 -0
- package/out/candidate/postcode-browse.js +119 -0
- package/out/candidate/postcode-browse.js.map +1 -0
- package/out/candidate/schema.d.ts +30 -2
- package/out/candidate/schema.d.ts.map +1 -1
- package/out/candidate/schema.js +29 -0
- package/out/candidate/schema.js.map +1 -1
- package/out/candidate/scoring.d.ts +3 -3
- package/out/candidate/scoring.d.ts.map +1 -1
- package/out/candidate/scoring.js +2 -2
- package/out/candidate/scoring.js.map +1 -1
- package/out/convention.d.ts +1 -1
- package/out/convention.d.ts.map +1 -1
- package/out/env.d.ts +3 -0
- package/out/env.d.ts.map +1 -1
- package/out/env.js +14 -3
- package/out/env.js.map +1 -1
- package/out/fst/binary-matcher.d.ts.map +1 -1
- package/out/fst/binary-matcher.js +9 -30
- package/out/fst/binary-matcher.js.map +1 -1
- package/out/fst/builder.d.ts.map +1 -1
- package/out/fst/builder.js +8 -6
- package/out/fst/builder.js.map +1 -1
- package/out/fst/deserialize-web.js +1 -1
- package/out/fst/deserialize-web.js.map +1 -1
- package/out/fst/format.d.ts +60 -9
- package/out/fst/format.d.ts.map +1 -1
- package/out/fst/format.js +97 -6
- package/out/fst/format.js.map +1 -1
- package/out/fst/freshness.js +2 -2
- package/out/fst/freshness.js.map +1 -1
- package/out/fst/serialize.d.ts.map +1 -1
- package/out/fst/serialize.js +67 -55
- package/out/fst/serialize.js.map +1 -1
- package/out/fts/query.d.ts +1 -1
- package/out/fts/query.d.ts.map +1 -1
- package/out/{search-fetch.d.ts → fts/search-fetch.d.ts} +2 -2
- package/out/fts/search-fetch.d.ts.map +1 -0
- package/out/fts/search-fetch.js.map +1 -0
- package/out/geonames/aliases.d.ts +18 -18
- package/out/geonames/aliases.d.ts.map +1 -1
- package/out/geonames/aliases.js +20 -24
- package/out/geonames/aliases.js.map +1 -1
- package/out/geonames/postal.d.ts +1 -1
- package/out/geonames/postal.js +3 -3
- package/out/index.d.ts +17 -17
- package/out/index.d.ts.map +1 -1
- package/out/index.js +12 -12
- package/out/index.js.map +1 -1
- package/out/{postal/city → labels/locality/postal-city}/alias/lookup.d.ts +1 -1
- package/out/labels/locality/postal-city/alias/lookup.d.ts.map +1 -0
- package/out/labels/locality/postal-city/alias/lookup.js.map +1 -0
- package/out/labels/locality/postal-city/alias/schema.d.ts.map +1 -0
- package/out/labels/locality/postal-city/alias/schema.js.map +1 -0
- package/out/{postal/city → labels/locality/postal-city}/candidate-schema.d.ts +1 -1
- package/out/labels/locality/postal-city/candidate-schema.d.ts.map +1 -0
- package/out/labels/locality/postal-city/candidate-schema.js.map +1 -0
- package/out/labels/locality.d.ts +4 -0
- package/out/labels/locality.d.ts.map +1 -0
- package/out/labels/locality.js +6 -0
- package/out/labels/locality.js.map +1 -0
- package/out/{region-keys.d.ts → labels/region.d.ts} +1 -1
- package/out/{region-keys.d.ts.map → labels/region.d.ts.map} +1 -1
- package/out/{region-keys.js → labels/region.js} +6 -3
- package/out/labels/region.js.map +1 -0
- package/out/{street → labels/street}/centroid/schema.d.ts +1 -1
- package/out/labels/street/centroid/schema.d.ts.map +1 -0
- package/out/labels/street/centroid/schema.js.map +1 -0
- package/out/{street → labels/street}/centroid.d.ts +5 -5
- package/out/labels/street/centroid.d.ts.map +1 -0
- package/out/{street → labels/street}/centroid.js +5 -5
- package/out/labels/street/centroid.js.map +1 -0
- package/out/{interpolation.d.ts → labels/street/interpolation.d.ts} +6 -1
- package/out/labels/street/interpolation.d.ts.map +1 -0
- package/out/{interpolation.js → labels/street/interpolation.js} +10 -8
- package/out/labels/street/interpolation.js.map +1 -0
- package/out/labels/street/locale.d.ts +26 -0
- package/out/labels/street/locale.d.ts.map +1 -0
- package/out/labels/street/locale.js +98 -0
- package/out/labels/street/locale.js.map +1 -0
- package/out/labels/street/morphology/fst/builder.d.ts.map +1 -0
- package/out/labels/street/morphology/fst/builder.js.map +1 -0
- package/out/labels/street/morphology/fst/loader.d.ts.map +1 -0
- package/out/{street → labels/street}/morphology/fst/loader.js +1 -1
- package/out/labels/street/morphology/fst/loader.js.map +1 -0
- package/out/labels/street/name-lookup.d.ts.map +1 -0
- package/out/{street → labels/street}/name-lookup.js +2 -0
- package/out/labels/street/name-lookup.js.map +1 -0
- package/out/labels/street/normalize.d.ts +188 -0
- package/out/labels/street/normalize.d.ts.map +1 -0
- package/out/{street → labels/street}/normalize.js +200 -119
- package/out/labels/street/normalize.js.map +1 -0
- package/out/{street → labels/street}/segment-schema.d.ts +1 -1
- package/out/labels/street/segment-schema.d.ts.map +1 -0
- package/out/labels/street/segment-schema.js.map +1 -0
- package/out/labels/street/table.d.ts.map +1 -0
- package/out/{street → labels/street}/table.js +1 -1
- package/out/labels/street/table.js.map +1 -0
- package/out/labels/street.d.ts +9 -0
- package/out/labels/street.d.ts.map +1 -0
- package/out/labels/street.js +11 -0
- package/out/labels/street.js.map +1 -0
- package/out/landmark/rows.js +1 -1
- package/out/landmark/rows.js.map +1 -1
- package/out/lookup/browse.d.ts +79 -0
- package/out/lookup/browse.d.ts.map +1 -0
- package/out/lookup/browse.js +194 -0
- package/out/lookup/browse.js.map +1 -0
- package/out/lookup/exact-match.d.ts.map +1 -0
- package/out/lookup/exact-match.js.map +1 -0
- package/out/lookup/extracts.d.ts.map +1 -0
- package/out/{extracts.js → lookup/extracts.js} +1 -1
- package/out/lookup/extracts.js.map +1 -0
- package/out/lookup/former-divisions.d.ts +99 -0
- package/out/lookup/former-divisions.d.ts.map +1 -0
- package/out/lookup/former-divisions.js +98 -0
- package/out/lookup/former-divisions.js.map +1 -0
- package/out/{postcode-point-lookup.d.ts → lookup/postcode-point.d.ts} +5 -1
- package/out/lookup/postcode-point.d.ts.map +1 -0
- package/out/{postcode-point-lookup.js → lookup/postcode-point.js} +1 -1
- package/out/lookup/postcode-point.js.map +1 -0
- package/out/{reverse.d.ts → lookup/reverse.d.ts} +1 -1
- package/out/lookup/reverse.d.ts.map +1 -0
- package/out/{reverse.js → lookup/reverse.js} +3 -3
- package/out/lookup/reverse.js.map +1 -0
- package/out/{types.d.ts → lookup/types.d.ts} +9 -0
- package/out/lookup/types.d.ts.map +1 -0
- package/out/lookup/types.js.map +1 -0
- package/out/lookup.d.ts +4 -4
- package/out/lookup.d.ts.map +1 -1
- package/out/lookup.js +14 -20
- package/out/lookup.js.map +1 -1
- package/out/poi/schema.d.ts +1 -1
- package/out/poi/schema.d.ts.map +1 -1
- package/out/ranking/name-score.d.ts.map +1 -0
- package/out/ranking/name-score.js.map +1 -0
- package/out/{primary-preference.d.ts → ranking/primary-preference.d.ts} +20 -1
- package/out/ranking/primary-preference.d.ts.map +1 -0
- package/out/{primary-preference.js → ranking/primary-preference.js} +35 -1
- package/out/ranking/primary-preference.js.map +1 -0
- package/out/ranking/proximity-rerank.d.ts.map +1 -0
- package/out/ranking/proximity-rerank.js.map +1 -0
- package/out/{ranking-weights.d.ts → ranking/weights.d.ts} +1 -1
- package/out/ranking/weights.d.ts.map +1 -0
- package/out/{ranking-weights.js → ranking/weights.js} +1 -1
- package/out/ranking/weights.js.map +1 -0
- package/out/schema/importance-source.d.ts +90 -0
- package/out/schema/importance-source.d.ts.map +1 -0
- package/out/schema/importance-source.js +133 -0
- package/out/schema/importance-source.js.map +1 -0
- package/out/schema/overture-match.d.ts +53 -0
- package/out/schema/overture-match.d.ts.map +1 -0
- package/out/schema/overture-match.js +33 -0
- package/out/schema/overture-match.js.map +1 -0
- package/out/{place-importance-schema.d.ts → schema/place-importance.d.ts} +50 -1
- package/out/schema/place-importance.d.ts.map +1 -0
- package/out/{place-importance-schema.js → schema/place-importance.js} +34 -1
- package/out/schema/place-importance.js.map +1 -0
- package/out/{polygon-schema.d.ts → schema/polygon.d.ts} +1 -1
- package/out/schema/polygon.d.ts.map +1 -0
- package/out/{polygon-schema.js → schema/polygon.js} +1 -1
- package/out/schema/polygon.js.map +1 -0
- package/out/{unified-schema.d.ts → schema/unified.d.ts} +1 -1
- package/out/schema/unified.d.ts.map +1 -0
- package/out/{unified-schema.js → schema/unified.js} +1 -1
- package/out/schema/unified.js.map +1 -0
- package/out/schema.d.ts +3 -3
- package/out/sqlite/convention-source.js +1 -1
- package/out/sqlite/convention-source.js.map +1 -1
- package/out/uprn/existence.d.ts.map +1 -1
- package/out/uprn/existence.js +2 -0
- package/out/uprn/existence.js.map +1 -1
- package/out/{weights-overlay-linker.d.ts → weights/overlay-linker.d.ts} +43 -24
- package/out/weights/overlay-linker.d.ts.map +1 -0
- package/out/{weights-overlay-linker.js → weights/overlay-linker.js} +182 -66
- package/out/weights/overlay-linker.js.map +1 -0
- package/package.json +12 -32
- package/lib/postal.ts +0 -6
- package/lib/street/locale.ts +0 -64
- package/lib/street.ts +0 -11
- package/out/candidate/extract-fold.d.ts.map +0 -1
- package/out/candidate/extract-fold.js.map +0 -1
- package/out/capital-schema.d.ts.map +0 -1
- package/out/capital-schema.js.map +0 -1
- package/out/capitals.d.ts.map +0 -1
- package/out/capitals.js.map +0 -1
- package/out/coverage-manifest-schema.d.ts.map +0 -1
- package/out/coverage-manifest-schema.js.map +0 -1
- package/out/exact-match.d.ts.map +0 -1
- package/out/exact-match.js.map +0 -1
- package/out/extracts.d.ts.map +0 -1
- package/out/extracts.js.map +0 -1
- package/out/interpolation.d.ts.map +0 -1
- package/out/interpolation.js.map +0 -1
- package/out/name-score.d.ts.map +0 -1
- package/out/name-score.js.map +0 -1
- package/out/place-importance-schema.d.ts.map +0 -1
- package/out/place-importance-schema.js.map +0 -1
- package/out/polygon-schema.d.ts.map +0 -1
- package/out/polygon-schema.js.map +0 -1
- package/out/postal/city/alias/lookup.d.ts.map +0 -1
- package/out/postal/city/alias/lookup.js.map +0 -1
- package/out/postal/city/alias/schema.d.ts.map +0 -1
- package/out/postal/city/alias/schema.js.map +0 -1
- package/out/postal/city/candidate-schema.d.ts.map +0 -1
- package/out/postal/city/candidate-schema.js.map +0 -1
- package/out/postal.d.ts +0 -4
- package/out/postal.d.ts.map +0 -1
- package/out/postal.js +0 -6
- package/out/postal.js.map +0 -1
- package/out/postcode-point-lookup.d.ts.map +0 -1
- package/out/postcode-point-lookup.js.map +0 -1
- package/out/primary-preference.d.ts.map +0 -1
- package/out/primary-preference.js.map +0 -1
- package/out/proximity-rerank.d.ts.map +0 -1
- package/out/proximity-rerank.js.map +0 -1
- package/out/ranking-weights.d.ts.map +0 -1
- package/out/ranking-weights.js.map +0 -1
- package/out/region-keys.js.map +0 -1
- package/out/reverse.d.ts.map +0 -1
- package/out/reverse.js.map +0 -1
- package/out/search-fetch.d.ts.map +0 -1
- package/out/search-fetch.js.map +0 -1
- package/out/street/centroid/schema.d.ts.map +0 -1
- package/out/street/centroid/schema.js.map +0 -1
- package/out/street/centroid.d.ts.map +0 -1
- package/out/street/centroid.js.map +0 -1
- package/out/street/locale.d.ts +0 -12
- package/out/street/locale.d.ts.map +0 -1
- package/out/street/locale.js +0 -54
- package/out/street/locale.js.map +0 -1
- package/out/street/morphology/fst/builder.d.ts.map +0 -1
- package/out/street/morphology/fst/builder.js.map +0 -1
- package/out/street/morphology/fst/loader.d.ts.map +0 -1
- package/out/street/morphology/fst/loader.js.map +0 -1
- package/out/street/name-lookup.d.ts.map +0 -1
- package/out/street/name-lookup.js.map +0 -1
- package/out/street/normalize.d.ts +0 -111
- package/out/street/normalize.d.ts.map +0 -1
- package/out/street/normalize.js.map +0 -1
- package/out/street/segment-schema.d.ts.map +0 -1
- package/out/street/segment-schema.js.map +0 -1
- package/out/street/table.d.ts.map +0 -1
- package/out/street/table.js.map +0 -1
- package/out/street.d.ts +0 -9
- package/out/street.d.ts.map +0 -1
- package/out/street.js +0 -11
- package/out/street.js.map +0 -1
- package/out/types.d.ts.map +0 -1
- package/out/types.js.map +0 -1
- package/out/unified-schema.d.ts.map +0 -1
- package/out/unified-schema.js.map +0 -1
- package/out/weights-overlay-linker.d.ts.map +0 -1
- package/out/weights-overlay-linker.js.map +0 -1
- /package/lib/{coverage-manifest-schema.ts → candidate/coverage-manifest.ts} +0 -0
- /package/lib/{postal/city → labels/locality/postal-city}/alias/schema.ts +0 -0
- /package/lib/{street → labels/street}/morphology/fst/builder.ts +0 -0
- /package/lib/{exact-match.ts → lookup/exact-match.ts} +0 -0
- /package/lib/{name-score.ts → ranking/name-score.ts} +0 -0
- /package/lib/{proximity-rerank.ts → ranking/proximity-rerank.ts} +0 -0
- /package/lib/{ranking-weights.ts → ranking/weights.ts} +0 -0
- /package/lib/{polygon-schema.ts → schema/polygon.ts} +0 -0
- /package/lib/{unified-schema.ts → schema/unified.ts} +0 -0
- /package/out/{capitals.d.ts → candidate/capitals.d.ts} +0 -0
- /package/out/{search-fetch.js → fts/search-fetch.js} +0 -0
- /package/out/{postal/city → labels/locality/postal-city}/alias/lookup.js +0 -0
- /package/out/{postal/city → labels/locality/postal-city}/alias/schema.d.ts +0 -0
- /package/out/{postal/city → labels/locality/postal-city}/alias/schema.js +0 -0
- /package/out/{postal/city → labels/locality/postal-city}/candidate-schema.js +0 -0
- /package/out/{street → labels/street}/centroid/schema.js +0 -0
- /package/out/{street → labels/street}/morphology/fst/builder.d.ts +0 -0
- /package/out/{street → labels/street}/morphology/fst/builder.js +0 -0
- /package/out/{street → labels/street}/morphology/fst/loader.d.ts +0 -0
- /package/out/{street → labels/street}/name-lookup.d.ts +0 -0
- /package/out/{street → labels/street}/segment-schema.js +0 -0
- /package/out/{street → labels/street}/table.d.ts +0 -0
- /package/out/{exact-match.d.ts → lookup/exact-match.d.ts} +0 -0
- /package/out/{exact-match.js → lookup/exact-match.js} +0 -0
- /package/out/{extracts.d.ts → lookup/extracts.d.ts} +0 -0
- /package/out/{types.js → lookup/types.js} +0 -0
- /package/out/{name-score.d.ts → ranking/name-score.d.ts} +0 -0
- /package/out/{name-score.js → ranking/name-score.js} +0 -0
- /package/out/{proximity-rerank.d.ts → ranking/proximity-rerank.d.ts} +0 -0
- /package/out/{proximity-rerank.js → ranking/proximity-rerank.js} +0 -0
package/lib/fst/builder.ts
CHANGED
|
@@ -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
|
|
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
|
|
97
|
-
"Divisions
|
|
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
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
83
|
+
const LEGACY_PLACE_ENTRY_SIZE = 56
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
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
|
|
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.
|
package/lib/fst/freshness.ts
CHANGED
|
@@ -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 {
|
|
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"
|
package/lib/fst/serialize.ts
CHANGED
|
@@ -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
|
-
*
|
|
19
|
-
*
|
|
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
|
-
|
|
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
|
|
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
|
-
*
|
|
60
|
+
* @throws When an id isn't a safe integer.
|
|
61
|
+
* An f64 holds only safe integers exactly.
|
|
53
62
|
*/
|
|
54
|
-
|
|
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 *
|
|
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 *
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
buf.
|
|
180
|
-
buf.writeUInt8(
|
|
181
|
-
|
|
182
|
-
buf.writeUInt8(
|
|
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 +
|
|
187
|
-
buf.writeUInt32LE(intern(place.name), pp +
|
|
188
|
-
buf.writeFloatLE(place.referential, pp +
|
|
189
|
-
buf.writeFloatLE(place.lat, pp +
|
|
190
|
-
buf.writeFloatLE(place.lon, pp +
|
|
191
|
-
|
|
192
|
-
for (let ci = 0; ci <
|
|
193
|
-
buf.writeUInt32LE(ci < chainLen ? validChain[ci]! : 0, pp +
|
|
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 +
|
|
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
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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 {
|
|
25
|
-
import type {
|
|
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
|
*
|