@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
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
* keeps the coordinate radius from promoting a capital's same-name neighbors (`capitals.ts`).
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { tryParsingJSON } from "@mailwoman/core/json"
|
|
17
|
+
import { tryParsingJSON } from "@mailwoman/core/values/json"
|
|
18
18
|
import type { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
19
19
|
import type { Kysely } from "kysely"
|
|
20
20
|
|
|
21
|
-
import type { CapitalPoint } from "#capitals"
|
|
21
|
+
import type { CapitalPoint } from "#candidate/capitals"
|
|
22
22
|
import { hasTable } from "#sqlite-utils"
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -47,7 +47,7 @@ export interface CapitalTable {
|
|
|
47
47
|
/**
|
|
48
48
|
* Create the table on a build in progress.
|
|
49
49
|
*
|
|
50
|
-
*
|
|
50
|
+
* The function is async because Kysely's schema builder is asynchronous.
|
|
51
51
|
* Called from the candidate build's DDL phase alongside the other typed builders.
|
|
52
52
|
*/
|
|
53
53
|
export async function createCapitalTable<DB extends { capital: CapitalTable }>(db: Kysely<DB>): Promise<void> {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
import { haversine } from "@mailwoman/spatial/geometries/point/distance"
|
|
22
22
|
|
|
23
|
-
import { normalizeLocalityForKey } from "#street/normalize"
|
|
23
|
+
import { normalizeLocalityForKey } from "#labels/street/normalize"
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Capital status of one candidate: national capital, admin-1 seat, or neither.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { enumerateCountryDisplayNames } from "@mailwoman/codex/country"
|
|
5
5
|
|
|
6
6
|
import type { PlaceAttrs, StageRow } from "#candidate/place-attrs"
|
|
7
|
-
import { normalizeLocalityForKey } from "#street/normalize"
|
|
7
|
+
import { normalizeLocalityForKey } from "#labels/street/normalize"
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Stages each country name that `Intl.DisplayNames` renders in the codex display-name
|
|
@@ -8,8 +8,8 @@ import type { PathBuilderLike } from "path-ts"
|
|
|
8
8
|
import { CANDIDATE_ANCESTOR_COLUMNS, CANDIDATE_ANCESTOR_TABLE } from "#candidate/ancestors/schema"
|
|
9
9
|
import type { PlaceAttrs, StageRow } from "#candidate/place-attrs"
|
|
10
10
|
import type { CandidateDatabase } from "#candidate/schema"
|
|
11
|
+
import { normalizeLocalityForKey } from "#labels/street/normalize"
|
|
11
12
|
import type { WOFDatabase } from "#schema"
|
|
12
|
-
import { normalizeLocalityForKey } from "#street/normalize"
|
|
13
13
|
|
|
14
14
|
function extractRegionAncestry(pc: DatabaseClient<WOFDatabase>, attrs: Map<number, PlaceAttrs>): Map<number, number> {
|
|
15
15
|
const regionOf = new Map<number, number>()
|
|
@@ -41,7 +41,7 @@ function extractRegionAncestry(pc: DatabaseClient<WOFDatabase>, attrs: Map<numbe
|
|
|
41
41
|
* the row also gets that region's scope and the region's ancestor chain.
|
|
42
42
|
* The stored ancestors then agree with the row's scope.
|
|
43
43
|
*/
|
|
44
|
-
export function
|
|
44
|
+
export function stageExtractRows(ctx: {
|
|
45
45
|
out: DatabaseClient<CandidateDatabase>
|
|
46
46
|
extractPath: PathBuilderLike
|
|
47
47
|
extractPlacetype: "postalcode" | "locality"
|
|
@@ -77,11 +77,14 @@ export function foldExtract(ctx: {
|
|
|
77
77
|
|
|
78
78
|
out.exec("BEGIN")
|
|
79
79
|
|
|
80
|
+
// A deprecated record is one its source withdrew as wrong, and it stays out whatever point it holds.
|
|
81
|
+
// A record that only ceased (`is_current = 0`) stays in: a terminated postcode still
|
|
82
|
+
// appears in written addresses, and the extract keeps its last point.
|
|
80
83
|
for (const r of pc
|
|
81
84
|
.prepare(
|
|
82
85
|
`SELECT id, name, country, latitude, longitude,
|
|
83
86
|
min_latitude AS mnlat, min_longitude AS mnlon, max_latitude AS mxlat, max_longitude AS mxlon
|
|
84
|
-
FROM spr WHERE placetype = ? AND latitude != 0 AND longitude != 0`
|
|
87
|
+
FROM spr WHERE placetype = ? AND latitude != 0 AND longitude != 0 AND is_deprecated = 0`
|
|
85
88
|
)
|
|
86
89
|
.iterate(extractPlacetype)) {
|
|
87
90
|
const name = String(r.name ?? "")
|
|
@@ -164,7 +167,7 @@ export function foldExtract(ctx: {
|
|
|
164
167
|
|
|
165
168
|
out.exec("COMMIT")
|
|
166
169
|
} else {
|
|
167
|
-
progress("postcode-aliases", `${extractPath} has no \`names\` table — no delivery-city aliases to
|
|
170
|
+
progress("postcode-aliases", `${extractPath} has no \`names\` table — no delivery-city aliases to add`)
|
|
168
171
|
}
|
|
169
172
|
|
|
170
173
|
return { primaries, aliases, scoped, ancestorRows }
|
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
*
|
|
9
9
|
* The join key is `(name_key, country, placetype)`, the same {@link normalizeLocalityForKey}
|
|
10
10
|
* the candidate build uses for its probe key, so the two sides fold identically.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* The score source is the importance build the candidate build matched to its
|
|
12
|
+
* admin database by md5 (`importance-source.ts`).
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* The join stays on the name key rather than the id, the join every candidate build has used,
|
|
15
|
+
* so matching the two files changes which scores are read and leaves the join unchanged.
|
|
15
16
|
*
|
|
16
17
|
* The key by itself isn't enough.
|
|
17
18
|
* `(warwick, US, locality)` covers eleven different places.
|
|
@@ -34,12 +35,14 @@
|
|
|
34
35
|
* at the position population assigned it.
|
|
35
36
|
*/
|
|
36
37
|
|
|
38
|
+
import { isOverturePartID } from "@mailwoman/core/resolver/synthetic-id-ranges"
|
|
37
39
|
import { haversine } from "@mailwoman/spatial/geometries/point/distance"
|
|
38
40
|
import { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
39
41
|
import type { PathBuilderLike } from "path-ts"
|
|
40
42
|
|
|
41
43
|
import type { CandidateDatabase } from "#candidate/schema"
|
|
42
|
-
import { normalizeLocalityForKey } from "#street/normalize"
|
|
44
|
+
import { normalizeLocalityForKey } from "#labels/street/normalize"
|
|
45
|
+
import { loadPopulationEstimates, type PlacePopulationEstimateDatabase } from "#schema/place-importance"
|
|
43
46
|
|
|
44
47
|
/**
|
|
45
48
|
* How far apart two artifacts may put the same place's centroid and still be read as the same place.
|
|
@@ -63,6 +66,10 @@ interface ScoredPlace {
|
|
|
63
66
|
lat: number
|
|
64
67
|
lon: number
|
|
65
68
|
importance: number
|
|
69
|
+
/**
|
|
70
|
+
* Whether the scored place is a row of the Overture Divisions part.
|
|
71
|
+
*/
|
|
72
|
+
overture: boolean
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
/**
|
|
@@ -85,6 +92,11 @@ export interface ImportanceIndexStats {
|
|
|
85
92
|
* (non-Latin punctuation-only names, blanks).
|
|
86
93
|
*/
|
|
87
94
|
unkeyable: number
|
|
95
|
+
/**
|
|
96
|
+
* Population estimates read from `place_population_estimate`, or null
|
|
97
|
+
* when the loader wasn't asked for them.
|
|
98
|
+
*/
|
|
99
|
+
estimates: number | null
|
|
88
100
|
}
|
|
89
101
|
|
|
90
102
|
/**
|
|
@@ -119,10 +131,36 @@ export class ImportanceIndex {
|
|
|
119
131
|
* It doesn't mean the radius is too tight.
|
|
120
132
|
*/
|
|
121
133
|
refused = 0
|
|
134
|
+
/**
|
|
135
|
+
* Places {@link estimatedPopulation} returned an estimate for.
|
|
136
|
+
*/
|
|
137
|
+
estimated = 0
|
|
122
138
|
|
|
123
|
-
|
|
139
|
+
readonly #estimates: ReadonlyMap<number, number>
|
|
140
|
+
|
|
141
|
+
constructor(
|
|
142
|
+
groups: Map<string, ScoredPlace[]>,
|
|
143
|
+
stats: ImportanceIndexStats,
|
|
144
|
+
estimates: ReadonlyMap<number, number> = new Map()
|
|
145
|
+
) {
|
|
124
146
|
this.#groups = groups
|
|
125
147
|
this.stats = stats
|
|
148
|
+
this.#estimates = estimates
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The ranking population the importance build estimated for the place with WOF
|
|
153
|
+
* id `id`, or undefined when it holds none.
|
|
154
|
+
* Ask only for a place without a measured population.
|
|
155
|
+
*/
|
|
156
|
+
estimatedPopulation(id: number): number | undefined {
|
|
157
|
+
const estimate = this.#estimates.get(id)
|
|
158
|
+
|
|
159
|
+
if (typeof estimate === "number") {
|
|
160
|
+
this.estimated++
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return estimate
|
|
126
164
|
}
|
|
127
165
|
|
|
128
166
|
/**
|
|
@@ -135,8 +173,20 @@ export class ImportanceIndex {
|
|
|
135
173
|
*
|
|
136
174
|
* The source column already contains a population-derived fallback where one exists.
|
|
137
175
|
* A second fallback would make an absence indistinguishable from a measurement.
|
|
176
|
+
*
|
|
177
|
+
* The gazetteer is a Collective Database whose Overture Divisions part is ODbL.
|
|
178
|
+
* A row outside that part (`overtureRow` false) reads only scores of places outside it,
|
|
179
|
+
* so an Overture division's Wikidata-joined score never reaches a WOF or GeoNames row.
|
|
180
|
+
* An Overture row may read any score.
|
|
138
181
|
*/
|
|
139
|
-
find(
|
|
182
|
+
find(
|
|
183
|
+
name: string,
|
|
184
|
+
country: string | null,
|
|
185
|
+
placetype: string | null,
|
|
186
|
+
lat: number,
|
|
187
|
+
lon: number,
|
|
188
|
+
overtureRow = false
|
|
189
|
+
): number | null {
|
|
140
190
|
const nameKey = normalizeLocalityForKey(name)
|
|
141
191
|
|
|
142
192
|
if (!nameKey) return null
|
|
@@ -147,8 +197,13 @@ export class ImportanceIndex {
|
|
|
147
197
|
|
|
148
198
|
let best: ScoredPlace | null = null
|
|
149
199
|
let bestKm = Infinity
|
|
200
|
+
let eligible = false
|
|
150
201
|
|
|
151
202
|
for (const place of group) {
|
|
203
|
+
if (place.overture && !overtureRow) continue
|
|
204
|
+
|
|
205
|
+
eligible = true
|
|
206
|
+
|
|
152
207
|
const km = haversine(lat, lon, place.lat, place.lon)
|
|
153
208
|
|
|
154
209
|
if (km < bestKm) {
|
|
@@ -157,6 +212,9 @@ export class ImportanceIndex {
|
|
|
157
212
|
}
|
|
158
213
|
}
|
|
159
214
|
|
|
215
|
+
// A row outside the Overture part reads a group of only Overture scores as an absent group.
|
|
216
|
+
if (!eligible) return null
|
|
217
|
+
|
|
160
218
|
if (!best || bestKm > IMPORTANCE_JOIN_RADIUS_KM) {
|
|
161
219
|
this.refused++
|
|
162
220
|
|
|
@@ -182,9 +240,19 @@ export class ImportanceIndex {
|
|
|
182
240
|
*
|
|
183
241
|
* The whole table is held in memory on purpose, because the build probes it once for every place
|
|
184
242
|
* and the alternative is a prepared statement per place against a multi-gigabyte database.
|
|
243
|
+
*
|
|
244
|
+
* With `populationEstimates`, it also reads `place_population_estimate`, keyed by WOF id
|
|
245
|
+
* because the importance database is a copy of the admin database the candidate build reads.
|
|
246
|
+
*
|
|
247
|
+
* @throws With `populationEstimates`, when the database holds no estimates table.
|
|
185
248
|
*/
|
|
186
|
-
export function loadImportanceIndex(
|
|
187
|
-
|
|
249
|
+
export function loadImportanceIndex(
|
|
250
|
+
databasePath: PathBuilderLike,
|
|
251
|
+
options: { populationEstimates?: boolean } = {}
|
|
252
|
+
): ImportanceIndex {
|
|
253
|
+
using db = new DatabaseClient<CandidateDatabase & PlacePopulationEstimateDatabase>(databasePath, {
|
|
254
|
+
readOnly: true,
|
|
255
|
+
})
|
|
188
256
|
|
|
189
257
|
const groups = new Map<string, ScoredPlace[]>()
|
|
190
258
|
let places = 0
|
|
@@ -192,7 +260,7 @@ export function loadImportanceIndex(databasePath: PathBuilderLike): ImportanceIn
|
|
|
192
260
|
|
|
193
261
|
for (const row of db
|
|
194
262
|
.prepare(
|
|
195
|
-
`SELECT s.name AS name, s.country AS country, s.placetype AS placetype,
|
|
263
|
+
`SELECT s.id AS id, s.name AS name, s.country AS country, s.placetype AS placetype,
|
|
196
264
|
s.latitude AS latitude, s.longitude AS longitude, i.importance AS importance
|
|
197
265
|
FROM place_importance i JOIN spr s ON s.id = i.id
|
|
198
266
|
WHERE s.is_current != 0 AND s.is_deprecated = 0`
|
|
@@ -217,10 +285,21 @@ export function loadImportanceIndex(databasePath: PathBuilderLike): ImportanceIn
|
|
|
217
285
|
groups.set(key, group)
|
|
218
286
|
}
|
|
219
287
|
|
|
220
|
-
group.push({
|
|
288
|
+
group.push({
|
|
289
|
+
lat: Number(row.latitude),
|
|
290
|
+
lon: Number(row.longitude),
|
|
291
|
+
importance,
|
|
292
|
+
overture: isOverturePartID(Number(row.id)),
|
|
293
|
+
})
|
|
221
294
|
|
|
222
295
|
places++
|
|
223
296
|
}
|
|
224
297
|
|
|
225
|
-
|
|
298
|
+
const estimates = options.populationEstimates ? loadPopulationEstimates(db) : null
|
|
299
|
+
|
|
300
|
+
return new ImportanceIndex(
|
|
301
|
+
groups,
|
|
302
|
+
{ places, keys: groups.size, unkeyable, estimates: estimates ? estimates.size : null },
|
|
303
|
+
estimates ?? undefined
|
|
304
|
+
)
|
|
226
305
|
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @file Extra folds a `candidate.db` applies to every `name_key`, recorded in the artifact so its reader
|
|
6
|
+
* folds each query key the same way.
|
|
7
|
+
*
|
|
8
|
+
* A fold changes which keys exist, so the build and the reader must agree on it. The build applies it
|
|
9
|
+
* as a post-pass over the materialized `candidate` table, and the reader reads the recorded folds once.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
13
|
+
|
|
14
|
+
import type { CandidateDatabase } from "#candidate/schema"
|
|
15
|
+
import { type NameKey, withArabicLetterVariantsFolded } from "#labels/street/normalize"
|
|
16
|
+
import { hasTable } from "#sqlite-utils"
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The table that lists the folds applied to the artifact's `name_key` column, one row per fold.
|
|
20
|
+
* An artifact without it applies none.
|
|
21
|
+
*/
|
|
22
|
+
export const CANDIDATE_KEY_FOLD_TABLE = "candidate_key_fold"
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The folds a candidate build can apply on top of `normalizeLocalityForKey`.
|
|
26
|
+
*/
|
|
27
|
+
export const CandidateKeyFold = {
|
|
28
|
+
/**
|
|
29
|
+
* {@link withArabicLetterVariantsFolded}: hamza, madda and vowel marks dropped,
|
|
30
|
+
* `ى` written `ي`, `ة` written `ه`.
|
|
31
|
+
*/
|
|
32
|
+
ArabicLetterVariants: "arabic-letter-variants",
|
|
33
|
+
} as const
|
|
34
|
+
|
|
35
|
+
export type CandidateKeyFold = (typeof CandidateKeyFold)[keyof typeof CandidateKeyFold]
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The key function of each fold, and the GLOB that selects the keys it can change.
|
|
39
|
+
*/
|
|
40
|
+
const FOLDS: Readonly<Record<CandidateKeyFold, { fold: (key: NameKey) => NameKey; glob: string }>> = {
|
|
41
|
+
[CandidateKeyFold.ArabicLetterVariants]: { fold: withArabicLetterVariantsFolded, glob: "*[-ۿ]*" },
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The counts {@link applyCandidateKeyFold} reports.
|
|
46
|
+
*/
|
|
47
|
+
export interface CandidateKeyFoldResult {
|
|
48
|
+
/**
|
|
49
|
+
* Rows whose key the fold changed.
|
|
50
|
+
*/
|
|
51
|
+
rekeyed: number
|
|
52
|
+
/**
|
|
53
|
+
* Rekeyed rows dropped because the folded key already held the same place under the same scope.
|
|
54
|
+
*/
|
|
55
|
+
merged: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Rewrites every `candidate.name_key` the fold changes and records the fold
|
|
60
|
+
* in {@link CANDIDATE_KEY_FOLD_TABLE}.
|
|
61
|
+
*
|
|
62
|
+
* A row whose folded key already exists for the same place, scope, placetype and rank is merged into it.
|
|
63
|
+
* It runs on a writable copy or inside a build, never on a published artifact.
|
|
64
|
+
*/
|
|
65
|
+
export async function applyCandidateKeyFold(
|
|
66
|
+
db: DatabaseClient<CandidateDatabase>,
|
|
67
|
+
foldName: CandidateKeyFold
|
|
68
|
+
): Promise<CandidateKeyFoldResult> {
|
|
69
|
+
const { fold, glob } = FOLDS[foldName]
|
|
70
|
+
const sqlName = `mw_key_fold_${foldName.replaceAll("-", "_")}`
|
|
71
|
+
|
|
72
|
+
db.function(sqlName, { deterministic: true }, (key) => fold(String(key) as NameKey))
|
|
73
|
+
|
|
74
|
+
const changed = `name_key GLOB '${glob}' AND ${sqlName}(name_key) <> name_key`
|
|
75
|
+
const { n: rekeyed } = db.prepare(`SELECT count(*) AS n FROM candidate WHERE ${changed}`).get() as { n: number }
|
|
76
|
+
|
|
77
|
+
db.exec("BEGIN")
|
|
78
|
+
|
|
79
|
+
const inserted = db
|
|
80
|
+
.prepare(
|
|
81
|
+
"INSERT OR IGNORE INTO candidate SELECT " +
|
|
82
|
+
`${sqlName}(name_key), country_id, region_id, placetype_id, neg_rank, spr_id, name, latitude, longitude, ` +
|
|
83
|
+
"min_lat, min_lon, max_lat, max_lon, population, is_primary, importance, name_role " +
|
|
84
|
+
`FROM candidate WHERE ${changed}`
|
|
85
|
+
)
|
|
86
|
+
.run()
|
|
87
|
+
|
|
88
|
+
db.prepare(`DELETE FROM candidate WHERE ${changed}`).run()
|
|
89
|
+
|
|
90
|
+
await db.schema
|
|
91
|
+
.createTable(CANDIDATE_KEY_FOLD_TABLE)
|
|
92
|
+
.ifNotExists()
|
|
93
|
+
.addColumn("fold", "text", (c) => c.primaryKey())
|
|
94
|
+
.execute()
|
|
95
|
+
|
|
96
|
+
db.prepare(`INSERT OR IGNORE INTO ${CANDIDATE_KEY_FOLD_TABLE} (fold) VALUES (?)`).run(foldName)
|
|
97
|
+
db.exec("COMMIT")
|
|
98
|
+
|
|
99
|
+
return { rekeyed, merged: rekeyed - Number(inserted.changes) }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The query-key function an artifact's recorded folds call for: identity when it records none.
|
|
104
|
+
*
|
|
105
|
+
* A fold name the reader doesn't know raises, because a key that misses that
|
|
106
|
+
* fold would miss every row the fold rewrote.
|
|
107
|
+
*/
|
|
108
|
+
export function candidateQueryKeyFold(db: DatabaseClient<CandidateDatabase>): (key: NameKey) => NameKey {
|
|
109
|
+
if (!hasTable(db, CANDIDATE_KEY_FOLD_TABLE)) return (key) => key
|
|
110
|
+
|
|
111
|
+
const names = (
|
|
112
|
+
db.prepare(`SELECT fold FROM ${CANDIDATE_KEY_FOLD_TABLE} ORDER BY fold`).all() as { fold: string }[]
|
|
113
|
+
).map((row) => row.fold)
|
|
114
|
+
|
|
115
|
+
const folds = names.map((name) => {
|
|
116
|
+
const known = FOLDS[name as CandidateKeyFold]
|
|
117
|
+
|
|
118
|
+
if (!known) throw new Error(`candidate.db records the key fold ${name}, which this reader doesn't implement`)
|
|
119
|
+
|
|
120
|
+
return known.fold
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
return (key) => {
|
|
124
|
+
let folded = key
|
|
125
|
+
|
|
126
|
+
for (const fold of folds) {
|
|
127
|
+
folded = fold(folded)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return folded
|
|
131
|
+
}
|
|
132
|
+
}
|
package/lib/candidate/lookup.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
3
|
|
|
4
|
-
import { expandPlacetypeFilter } from "@mailwoman/codex/placetype-map"
|
|
4
|
+
import { expandPlacetypeFilter } from "@mailwoman/codex/labels/placetype-map"
|
|
5
5
|
import type { VariantAliasExemption } from "@mailwoman/core/geocode"
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
type Ancestor,
|
|
8
|
+
type GazetteerArtifactCoverage,
|
|
9
|
+
populationScoreUnmeasured,
|
|
10
|
+
referentialFromPopulation,
|
|
11
|
+
} from "@mailwoman/core/resolver"
|
|
7
12
|
import { allRows } from "@mailwoman/core/utils"
|
|
8
13
|
import { jaroWinkler, levenshteinSimilarity } from "@mailwoman/match/comparators"
|
|
9
14
|
import { partitionByContainment } from "@mailwoman/resolver"
|
|
@@ -18,16 +23,20 @@ import {
|
|
|
18
23
|
type CandidateAncestorTable,
|
|
19
24
|
type IntervalLabel,
|
|
20
25
|
} from "#candidate/ancestors/schema"
|
|
26
|
+
import { readGazetteerCoverageManifest } from "#candidate/coverage-manifest"
|
|
21
27
|
import { CANDIDATE_FTS_TABLE } from "#candidate/fts"
|
|
28
|
+
import { candidateQueryKeyFold } from "#candidate/key-fold"
|
|
22
29
|
import type { CandidateDatabase, CandidateTable, CountryCodeTable, PlacetypeCodeTable } from "#candidate/schema"
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
import { REGION_CLASS_PLACETYPES, regionQualifierProbeKeys } from "#region
|
|
30
|
+
import {
|
|
31
|
+
POSTAL_CITY_CANDIDATE_TABLE,
|
|
32
|
+
type PostalCityCandidateTable,
|
|
33
|
+
} from "#labels/locality/postal-city/candidate-schema"
|
|
34
|
+
import { REGION_CLASS_PLACETYPES, regionQualifierProbeKeys } from "#labels/region"
|
|
35
|
+
import { type NameKey, normalizeLocalityForKey, stripLocalityQualifier } from "#labels/street/normalize"
|
|
36
|
+
import type { FindPlaceQuery, PlaceCandidate, PlaceLookup, WOFPlacetype } from "#lookup/types"
|
|
37
|
+
import { rankByPrimaryPreference, type RankedRow, regionAliasMargin, RERANK_FETCH } from "#ranking/primary-preference"
|
|
38
|
+
import { applyProximityRerank } from "#ranking/proximity-rerank"
|
|
28
39
|
import { hasColumn, hasTable } from "#sqlite-utils"
|
|
29
|
-
import { type NameKey, normalizeLocalityForKey, stripLocalityQualifier } from "#street/normalize"
|
|
30
|
-
import type { FindPlaceQuery, PlaceCandidate, PlaceLookup, WOFPlacetype } from "#types"
|
|
31
40
|
|
|
32
41
|
/**
|
|
33
42
|
* Where a {@link WOFCandidateTableLookup} reads from
|
|
@@ -133,6 +142,12 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
|
|
|
133
142
|
readonly #intervalCache = new Map<number, IntervalLabel | null>()
|
|
134
143
|
|
|
135
144
|
readonly #qualifierProbe: ReturnType<DatabaseClient["prepare"]> | undefined
|
|
145
|
+
|
|
146
|
+
#placeProbe: ReturnType<DatabaseClient["prepare"]> | undefined
|
|
147
|
+
/**
|
|
148
|
+
* The folds the artifact recorded for its `name_key` column, applied to every query key.
|
|
149
|
+
*/
|
|
150
|
+
readonly #queryKeyFold: (key: NameKey) => NameKey
|
|
136
151
|
/**
|
|
137
152
|
* Ancestor lineage accessor, nearest-first, present only when the artifact supports it.
|
|
138
153
|
*/
|
|
@@ -141,6 +156,8 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
|
|
|
141
156
|
constructor(opts: WOFCandidateTableLookupOpts) {
|
|
142
157
|
super(opts)
|
|
143
158
|
|
|
159
|
+
this.#queryKeyFold = candidateQueryKeyFold(this.database)
|
|
160
|
+
|
|
144
161
|
for (const r of allRows<CountryCodeTable>(this.database.prepare("SELECT id, code FROM country_codes"))) {
|
|
145
162
|
const code = String(r.code).toUpperCase()
|
|
146
163
|
this.#countryToID.set(code, Number(r.id))
|
|
@@ -246,7 +263,7 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
|
|
|
246
263
|
for (const key of regionQualifierProbeKeys(qualifier, country)) {
|
|
247
264
|
if (!key) continue
|
|
248
265
|
|
|
249
|
-
for (const row of allRows<{ spr_id: number }>(this.#qualifierProbe, key)) {
|
|
266
|
+
for (const row of allRows<{ spr_id: number }>(this.#qualifierProbe, this.#queryKeyFold(key as NameKey))) {
|
|
250
267
|
ids.add(Number(row.spr_id))
|
|
251
268
|
}
|
|
252
269
|
}
|
|
@@ -425,7 +442,8 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
|
|
|
425
442
|
text = text.replaceAll(/\s+/g, "")
|
|
426
443
|
}
|
|
427
444
|
|
|
428
|
-
const nameKey = normalizeLocalityForKey(text)
|
|
445
|
+
const nameKey = this.#queryKeyFold(normalizeLocalityForKey(text))
|
|
446
|
+
const strippedNameKey = this.#queryKeyFold(normalizeLocalityForKey(stripLocalityQualifier(text)))
|
|
429
447
|
|
|
430
448
|
if (!nameKey) return []
|
|
431
449
|
|
|
@@ -535,19 +553,19 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
|
|
|
535
553
|
|
|
536
554
|
const fetched = allRows<CandidateRow>(this.database.prepare(sql), ...params, Math.max(limit, RERANK_FETCH))
|
|
537
555
|
|
|
538
|
-
|
|
556
|
+
// Inside a stated region, an alias yields to a different place whose primary name equals
|
|
557
|
+
// the query, including an own-name variant the exemption spares from the worldwide penalty.
|
|
558
|
+
return regionID === null
|
|
559
|
+
? rankByPrimaryPreference(fetched, limit, undefined, this.#idToPlacetype, this.#variantAliasExemption)
|
|
560
|
+
: rankByPrimaryPreference(fetched, limit, regionAliasMargin, this.#idToPlacetype)
|
|
539
561
|
}
|
|
540
562
|
|
|
541
563
|
const cascade = (regionID: number | null): Array<RankedRow<CandidateRow>> => {
|
|
542
564
|
let rows = probe(nameKey, regionID)
|
|
543
565
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
if (strippedKey && strippedKey !== nameKey) {
|
|
548
|
-
// Stripped probes only accept primary rows to avoid alias-scrape matches.
|
|
549
|
-
rows = probe(strippedKey, regionID).filter((r) => r.is_primary === 1)
|
|
550
|
-
}
|
|
566
|
+
// Stripped probes only accept primary rows to avoid alias-scrape matches.
|
|
567
|
+
if (!rows.length && strippedNameKey && strippedNameKey !== nameKey) {
|
|
568
|
+
rows = probe(strippedNameKey, regionID).filter((r) => r.is_primary === 1)
|
|
551
569
|
}
|
|
552
570
|
|
|
553
571
|
// Typo-tolerant fallback for true name misses only, skipping postcodes.
|
|
@@ -573,7 +591,9 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
|
|
|
573
591
|
const hits = allRows<{ name_key: string }>(this.#ftsProbe, match, FUZZY_FETCH)
|
|
574
592
|
|
|
575
593
|
const ranked = hits
|
|
576
|
-
|
|
594
|
+
// An index built before the artifact's key folds holds unfolded keys, so each hit is folded too.
|
|
595
|
+
.map((h) => this.#queryKeyFold(String(h.name_key) as NameKey))
|
|
596
|
+
.map((nk) => ({ nk, s: wordFuzzySimilarity(nameKey, nk) }))
|
|
577
597
|
.filter((h) => h.s >= WORD_FUZZY_MIN && (hasCountryEvidence || h.nk[0] === nameKey[0]))
|
|
578
598
|
// oxlint-disable-next-line unicorn/no-array-sort -- sorts a freshly-built array. toSorted would double-allocate on a hot path
|
|
579
599
|
.sort((a, b) => b.s - a.s)
|
|
@@ -638,7 +658,7 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
|
|
|
638
658
|
// Admin-containment re-rank runs last.
|
|
639
659
|
const containmentOptions: ContainmentOptions = {
|
|
640
660
|
nameKey,
|
|
641
|
-
strippedKey:
|
|
661
|
+
strippedKey: strippedNameKey,
|
|
642
662
|
shapeFilters,
|
|
643
663
|
shapeParams,
|
|
644
664
|
limit,
|
|
@@ -655,58 +675,79 @@ export class WOFCandidateTableLookup extends SQLiteLookup<CandidateDatabase> imp
|
|
|
655
675
|
rows = this.#applyContainment(rows, new Set([query.parentQualifierID]), containmentOptions)
|
|
656
676
|
}
|
|
657
677
|
|
|
658
|
-
const candidates = rows.map((row)
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
678
|
+
const candidates = rows.map((row) => this.#toCandidate(row, regionScopeMiss))
|
|
679
|
+
|
|
680
|
+
if (query.bias && query.bias.length) {
|
|
681
|
+
applyProximityRerank(candidates, query.bias)
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
return candidates
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* One place by its `spr_id`, read from its primary-name row, or null when the table holds no row for it.
|
|
689
|
+
*/
|
|
690
|
+
place(id: number): PlaceCandidate | null {
|
|
691
|
+
if (!Number.isInteger(id)) return null
|
|
662
692
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
693
|
+
this.#placeProbe ??= this.database.prepare(
|
|
694
|
+
"SELECT spr_id, name, country_id, placetype_id, latitude, longitude, min_lat, min_lon, max_lat, max_lon, neg_rank, is_primary, population" +
|
|
695
|
+
`${this.#importanceSelect} FROM candidate WHERE spr_id = ? ORDER BY is_primary DESC LIMIT 1`
|
|
696
|
+
)
|
|
667
697
|
|
|
668
|
-
|
|
669
|
-
lat: Number(row.latitude),
|
|
670
|
-
lon: Number(row.longitude),
|
|
698
|
+
const row = this.#placeProbe.get(id) as CandidateRow | undefined
|
|
671
699
|
|
|
672
|
-
|
|
700
|
+
return row ? this.#toCandidate({ ...row, effectiveNegRank: row.neg_rank, demoted: false }, false) : null
|
|
701
|
+
}
|
|
673
702
|
|
|
674
|
-
|
|
675
|
-
|
|
703
|
+
#toCandidate(row: RankedRow<CandidateRow>, regionScopeMiss: boolean): PlaceCandidate {
|
|
704
|
+
const hasBbox = row.min_lat != null && row.max_lat != null && row.min_lon != null && row.max_lon != null
|
|
705
|
+
const parent = this.#ancestorLineage(Number(row.spr_id))[0]
|
|
706
|
+
const hasPopulation = row.population !== null && row.population > 0
|
|
676
707
|
|
|
677
|
-
|
|
708
|
+
return {
|
|
709
|
+
id: Number(row.spr_id),
|
|
710
|
+
name: String(row.name ?? ""),
|
|
711
|
+
placetype: (this.#idToPlacetype.get(Number(row.placetype_id)) ?? "") as WOFPlacetype,
|
|
678
712
|
|
|
679
|
-
|
|
713
|
+
country: this.#idToCountry.get(Number(row.country_id)) ?? "",
|
|
714
|
+
lat: Number(row.latitude),
|
|
715
|
+
lon: Number(row.longitude),
|
|
680
716
|
|
|
681
|
-
|
|
717
|
+
parent_id: parent ? Number(parent.id) : null,
|
|
682
718
|
|
|
683
|
-
|
|
719
|
+
score: -Number(row.neg_rank),
|
|
720
|
+
// `neg_rank` is -log10(population + 1), so a place without a population ranks at
|
|
721
|
+
// 0 unmeasured, unless the build ranked it by a population estimate.
|
|
722
|
+
scoreUnmeasured: populationScoreUnmeasured(row.population, Number(row.neg_rank)),
|
|
723
|
+
distanceKm: null,
|
|
684
724
|
|
|
685
|
-
|
|
725
|
+
prominence: -Number(row.effectiveNegRank),
|
|
686
726
|
|
|
687
|
-
|
|
727
|
+
exactMatch: !row.demoted && !row.fuzzy,
|
|
688
728
|
|
|
689
|
-
|
|
690
|
-
referential: hasPopulation ? referentialFromPopulation(row.population) : null,
|
|
691
|
-
encyclopedic: null,
|
|
729
|
+
regionScopeMiss: regionScopeMiss ? true : null,
|
|
692
730
|
|
|
693
|
-
|
|
694
|
-
bbox: hasBbox
|
|
695
|
-
? {
|
|
696
|
-
minLat: Number(row.min_lat),
|
|
697
|
-
maxLat: Number(row.max_lat),
|
|
698
|
-
minLon: Number(row.min_lon),
|
|
699
|
-
maxLon: Number(row.max_lon),
|
|
700
|
-
}
|
|
701
|
-
: null,
|
|
702
|
-
mismatch: null,
|
|
703
|
-
}
|
|
704
|
-
})
|
|
731
|
+
containedByQualifier: row.containedByQualifier ?? null,
|
|
705
732
|
|
|
706
|
-
|
|
707
|
-
applyProximityRerank(candidates, query.bias)
|
|
708
|
-
}
|
|
733
|
+
variantAliasExempted: row.variantExempted ? true : null,
|
|
709
734
|
|
|
710
|
-
|
|
735
|
+
matchedAlias: row.is_primary === 0 ? true : null,
|
|
736
|
+
|
|
737
|
+
population: hasPopulation ? row.population : null,
|
|
738
|
+
referential: hasPopulation ? referentialFromPopulation(row.population) : null,
|
|
739
|
+
encyclopedic: null,
|
|
740
|
+
|
|
741
|
+
importance: typeof row.importance === "number" && Number.isFinite(row.importance) ? row.importance : null,
|
|
742
|
+
bbox: hasBbox
|
|
743
|
+
? {
|
|
744
|
+
minLat: Number(row.min_lat),
|
|
745
|
+
maxLat: Number(row.max_lat),
|
|
746
|
+
minLon: Number(row.min_lon),
|
|
747
|
+
maxLon: Number(row.max_lon),
|
|
748
|
+
}
|
|
749
|
+
: null,
|
|
750
|
+
mismatch: null,
|
|
751
|
+
}
|
|
711
752
|
}
|
|
712
753
|
}
|
|
@@ -12,8 +12,8 @@ import { tableExists } from "@mailwoman/sqlite/introspection"
|
|
|
12
12
|
import { isOwnNameVariant } from "#candidate/own-name"
|
|
13
13
|
import type { PlaceAttrs } from "#candidate/place-attrs"
|
|
14
14
|
import type { CandidateDatabase } from "#candidate/schema"
|
|
15
|
+
import { normalizeLocalityForKey } from "#labels/street/normalize"
|
|
15
16
|
import type { WOFDatabase } from "#schema"
|
|
16
|
-
import { normalizeLocalityForKey } from "#street/normalize"
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Key-count threshold for the gloss anomaly detector.
|