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