@mailwoman/resolver-wof-sqlite 11.2.0 → 11.4.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/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 +42 -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/build/candidate.ts +136 -40
- package/lib/build/slim.ts +4 -1
- package/lib/build/sources.ts +50 -0
- package/lib/candidate/alias-bags.ts +22 -8
- 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 +86 -8
- package/lib/candidate/key-fold.ts +1 -1
- package/lib/candidate/lookup.ts +79 -48
- package/lib/candidate/name-roles.ts +1 -1
- package/lib/candidate/nickname-namesakes.ts +8 -1
- 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/builder.ts +8 -6
- package/lib/fst/deserialize-web.ts +1 -1
- package/lib/fst/freshness.ts +2 -2
- package/lib/fst/serialize.ts +1 -1
- package/lib/fts/query.ts +1 -1
- package/lib/{search-fetch.ts → fts/search-fetch.ts} +2 -2
- package/lib/geonames/aliases.ts +37 -33
- 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} +56 -5
- 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 +293 -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} +5 -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 +6 -1
- package/out/address/number-forms.d.ts.map +1 -1
- package/out/address/number-forms.js +36 -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/build/candidate.d.ts +26 -1
- package/out/build/candidate.d.ts.map +1 -1
- package/out/build/candidate.js +71 -32
- 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 +0 -3
- package/out/candidate/alias-bags.d.ts.map +1 -1
- package/out/candidate/alias-bags.js +22 -7
- 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 +53 -8
- package/out/candidate/importance.js.map +1 -1
- package/out/candidate/key-fold.d.ts +1 -1
- package/out/candidate/key-fold.d.ts.map +1 -1
- package/out/candidate/key-fold.js +1 -1
- package/out/candidate/key-fold.js.map +1 -1
- package/out/candidate/lookup.d.ts +5 -1
- package/out/candidate/lookup.d.ts.map +1 -1
- package/out/candidate/lookup.js +59 -43
- 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 +0 -4
- package/out/candidate/nickname-namesakes.d.ts.map +1 -1
- package/out/candidate/nickname-namesakes.js +12 -1
- package/out/candidate/nickname-namesakes.js.map +1 -1
- 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/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/freshness.js +2 -2
- package/out/fst/freshness.js.map +1 -1
- package/out/fst/serialize.js +1 -1
- 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 +17 -17
- 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} +40 -9
- 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 +207 -0
- package/out/labels/street/normalize.d.ts.map +1 -0
- package/out/{street → labels/street}/normalize.js +198 -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/ranking/primary-preference.d.ts.map +1 -0
- package/out/{primary-preference.js → ranking/primary-preference.js} +4 -0
- 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.map +1 -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/importance-source.d.ts.map +0 -1
- package/out/importance-source.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 -130
- 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/{importance-source.ts → schema/importance-source.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/{primary-preference.d.ts → ranking/primary-preference.d.ts} +0 -0
- /package/out/{proximity-rerank.d.ts → ranking/proximity-rerank.d.ts} +0 -0
- /package/out/{proximity-rerank.js → ranking/proximity-rerank.js} +0 -0
- /package/out/{importance-source.d.ts → schema/importance-source.d.ts} +0 -0
- /package/out/{importance-source.js → schema/importance-source.js} +0 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Pages through an admin gazetteer's current places in ascending id order, inside a bounding box.
|
|
6
|
+
*
|
|
7
|
+
* A page continues after the last id the previous page returned, so the database seeks
|
|
8
|
+
* to it through the primary key and a deep page costs what the first page costs.
|
|
9
|
+
* The box selects a place by its point (`spr.latitude`, `spr.longitude`).
|
|
10
|
+
*
|
|
11
|
+
* Two plans read a page, and the box decides between them.
|
|
12
|
+
*
|
|
13
|
+
* - A box whose extent count in the `place_bbox` R*Tree is at most
|
|
14
|
+
* {@link EXTENT_PROBE_LIMIT} reads those places through the R*Tree, keeps the
|
|
15
|
+
* ones whose point lies inside the box, and sorts them by id.
|
|
16
|
+
* The cost is the box's extent count and doesn't depend on the page's position.
|
|
17
|
+
* - A larger box walks `spr` in primary-key order from the cursor and stops at the page's last row.
|
|
18
|
+
* Such a box holds enough places that the walk ends early, and it never reads more than the table once.
|
|
19
|
+
*
|
|
20
|
+
* The R*Tree indexes each place's extent rather than its point.
|
|
21
|
+
* The admin build widens every located place's extent to hold its point,
|
|
22
|
+
* and `gazetteer verify`'s `point-in-extent` check holds the database to that.
|
|
23
|
+
*
|
|
24
|
+
* An extent that meets no part of the box therefore holds no point inside it.
|
|
25
|
+
*
|
|
26
|
+
* A place without a recorded extent has no R*Tree row.
|
|
27
|
+
* The R*Tree plan would miss it, so the browser reads those places once,
|
|
28
|
+
* on first use, and adds the ones inside the box.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { stringifyJSON } from "@mailwoman/core/values/json"
|
|
32
|
+
import { type LatLonBounds, latLonBoundsContain } from "@mailwoman/spatial/bbox"
|
|
33
|
+
import { SQLiteLookup, type SQLiteLookupOptions } from "@mailwoman/sqlite/lookup"
|
|
34
|
+
import { sql } from "kysely"
|
|
35
|
+
|
|
36
|
+
import { PLACE_BBOX_TABLE } from "#fts"
|
|
37
|
+
import type { SprTable, WOFDatabase } from "#schema"
|
|
38
|
+
import { hasTable } from "#sqlite-utils"
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The `place_bbox` R*Tree `fts.ts` builds: one row per current place with a recorded extent.
|
|
42
|
+
*/
|
|
43
|
+
export interface PlaceBBoxTable {
|
|
44
|
+
id: number
|
|
45
|
+
min_lat: number
|
|
46
|
+
max_lat: number
|
|
47
|
+
min_lon: number
|
|
48
|
+
max_lon: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The tables the browser reads.
|
|
53
|
+
*/
|
|
54
|
+
export interface PlaceBrowseDatabase {
|
|
55
|
+
spr: WOFDatabase["spr"]
|
|
56
|
+
[PLACE_BBOX_TABLE]: PlaceBBoxTable
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* One current place, as a page returns it.
|
|
61
|
+
*/
|
|
62
|
+
export type BrowsedPlace = Pick<SprTable, "id" | "name" | "placetype" | "country" | "latitude" | "longitude">
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A box in WGS 84 degrees.
|
|
66
|
+
*
|
|
67
|
+
* A minimum longitude above the maximum crosses the antimeridian.
|
|
68
|
+
*/
|
|
69
|
+
export type BrowseBox = LatLonBounds
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* One page request.
|
|
73
|
+
*/
|
|
74
|
+
export interface BrowsePageRequest {
|
|
75
|
+
/**
|
|
76
|
+
* The box a place's point must lie in, or null for every place.
|
|
77
|
+
*/
|
|
78
|
+
box: BrowseBox | null
|
|
79
|
+
/**
|
|
80
|
+
* Return only places whose id exceeds this one, or null to start at the first place.
|
|
81
|
+
*/
|
|
82
|
+
after: number | null
|
|
83
|
+
limit: number
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The most R*Tree extents a box may intersect for its page to be read through the R*Tree,
|
|
88
|
+
* unless {@link WOFPlaceBrowserOptions.extentProbeLimit} sets another.
|
|
89
|
+
*
|
|
90
|
+
* It chooses a plan and decides no result.
|
|
91
|
+
* Both plans return the same rows, because each selects a place by its point.
|
|
92
|
+
*/
|
|
93
|
+
const EXTENT_PROBE_LIMIT = 50_000
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Where a {@link WOFPlaceBrowser} reads from, and when it reads a page through the R*Tree.
|
|
97
|
+
*/
|
|
98
|
+
export interface WOFPlaceBrowserOptions extends SQLiteLookupOptions<PlaceBrowseDatabase> {
|
|
99
|
+
/**
|
|
100
|
+
* The most R*Tree extents a box may intersect for its page to be read through the R*Tree.
|
|
101
|
+
*
|
|
102
|
+
* @defaultValue 50,000. On `admin-global-priority.db`, a page of up to 1001 places took at most 40 ms
|
|
103
|
+
* through either plan with this limit, the probe included (measured on #3142).
|
|
104
|
+
*/
|
|
105
|
+
extentProbeLimit?: number
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The candidates read past a page's limit in one query of the R*Tree plan,
|
|
110
|
+
* for the few whose extent meets the box while their point lies outside it.
|
|
111
|
+
*/
|
|
112
|
+
const PAGE_CHUNK_MARGIN = 64
|
|
113
|
+
|
|
114
|
+
const COLUMNS = ["id", "name", "placetype", "country", "latitude", "longitude"] as const
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* A place the R*Tree plan can't find through the R*Tree.
|
|
118
|
+
*/
|
|
119
|
+
interface IrregularPlace {
|
|
120
|
+
id: number
|
|
121
|
+
latitude: number
|
|
122
|
+
longitude: number
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The box split at the antimeridian into boxes whose minimum longitude doesn't exceed the maximum.
|
|
127
|
+
*/
|
|
128
|
+
function unwrappedBoxes(box: BrowseBox): BrowseBox[] {
|
|
129
|
+
if (box.minLon <= box.maxLon) return [box]
|
|
130
|
+
|
|
131
|
+
return [
|
|
132
|
+
{ ...box, maxLon: 180 },
|
|
133
|
+
{ ...box, minLon: -180 },
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Whether a point lies inside the box, edges included, across the antimeridian too.
|
|
139
|
+
*/
|
|
140
|
+
function boxContains(box: BrowseBox, latitude: number, longitude: number): boolean {
|
|
141
|
+
return unwrappedBoxes(box).some((part) => latLonBoundsContain(part, latitude, longitude))
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Pages through the current places of an admin gazetteer such as `admin-global-priority.db`.
|
|
146
|
+
*
|
|
147
|
+
* A place is current when `is_current != 0` and `is_deprecated = 0`,
|
|
148
|
+
* the filter the resolver and the R*Tree build apply.
|
|
149
|
+
*/
|
|
150
|
+
export class WOFPlaceBrowser extends SQLiteLookup<PlaceBrowseDatabase> {
|
|
151
|
+
#irregular: Promise<IrregularPlace[]> | undefined
|
|
152
|
+
readonly #extentProbeLimit: number
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @throws When the database lacks `spr` or the `place_bbox` R*Tree, because it can't answer a box page.
|
|
156
|
+
*/
|
|
157
|
+
constructor({ extentProbeLimit = EXTENT_PROBE_LIMIT, ...options }: WOFPlaceBrowserOptions) {
|
|
158
|
+
super(options)
|
|
159
|
+
|
|
160
|
+
this.#extentProbeLimit = extentProbeLimit
|
|
161
|
+
|
|
162
|
+
for (const table of ["spr", PLACE_BBOX_TABLE]) {
|
|
163
|
+
if (!hasTable(this.database, table)) {
|
|
164
|
+
this[Symbol.dispose]()
|
|
165
|
+
|
|
166
|
+
throw new Error(`the database has no ${table} table`)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
#current() {
|
|
172
|
+
return this.database
|
|
173
|
+
.selectFrom("spr")
|
|
174
|
+
.select(COLUMNS)
|
|
175
|
+
.where("spr.is_current", "!=", 0)
|
|
176
|
+
.where("spr.is_deprecated", "=", 0)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The current place with this id, or null when the gazetteer holds no current place with it.
|
|
181
|
+
*/
|
|
182
|
+
async place(id: number): Promise<BrowsedPlace | null> {
|
|
183
|
+
return (await this.#current().where("spr.id", "=", id).executeTakeFirst()) ?? null
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The current places the request selects, in ascending id order, at most `limit` of them.
|
|
188
|
+
*/
|
|
189
|
+
async page({ box, after, limit }: BrowsePageRequest): Promise<BrowsedPlace[]> {
|
|
190
|
+
if (box) {
|
|
191
|
+
const extentIDs = await this.#extentsIntersecting(box)
|
|
192
|
+
|
|
193
|
+
if (extentIDs) return this.#pageThroughExtents(box, extentIDs, after, limit)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let query = this.#current()
|
|
197
|
+
.where("spr.id", ">", after ?? Number.MIN_SAFE_INTEGER)
|
|
198
|
+
.orderBy("spr.id")
|
|
199
|
+
.limit(limit)
|
|
200
|
+
|
|
201
|
+
if (box) {
|
|
202
|
+
query = query
|
|
203
|
+
.where("spr.latitude", ">=", box.minLat)
|
|
204
|
+
.where("spr.latitude", "<=", box.maxLat)
|
|
205
|
+
.where((eb) =>
|
|
206
|
+
box.minLon <= box.maxLon
|
|
207
|
+
? eb.and([eb("spr.longitude", ">=", box.minLon), eb("spr.longitude", "<=", box.maxLon)])
|
|
208
|
+
: eb.or([eb("spr.longitude", ">=", box.minLon), eb("spr.longitude", "<=", box.maxLon)])
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return query.execute()
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The ids of the R*Tree extents the box intersects, or null when they exceed the probe limit.
|
|
217
|
+
*/
|
|
218
|
+
async #extentsIntersecting(box: BrowseBox): Promise<Set<number> | null> {
|
|
219
|
+
const ids = new Set<number>()
|
|
220
|
+
|
|
221
|
+
for (const part of unwrappedBoxes(box)) {
|
|
222
|
+
const rows = await this.database
|
|
223
|
+
.selectFrom(PLACE_BBOX_TABLE)
|
|
224
|
+
.select("id")
|
|
225
|
+
.where("min_lon", "<=", part.maxLon)
|
|
226
|
+
.where("max_lon", ">=", part.minLon)
|
|
227
|
+
.where("min_lat", "<=", part.maxLat)
|
|
228
|
+
.where("max_lat", ">=", part.minLat)
|
|
229
|
+
.limit(this.#extentProbeLimit + 1 - ids.size)
|
|
230
|
+
.execute()
|
|
231
|
+
|
|
232
|
+
for (const { id } of rows) {
|
|
233
|
+
ids.add(id)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (ids.size > this.#extentProbeLimit) return null
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return ids
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async #pageThroughExtents(
|
|
243
|
+
box: BrowseBox,
|
|
244
|
+
extentIDs: Set<number>,
|
|
245
|
+
after: number | null,
|
|
246
|
+
limit: number
|
|
247
|
+
): Promise<BrowsedPlace[]> {
|
|
248
|
+
const candidates = new Set<number>()
|
|
249
|
+
|
|
250
|
+
for (const id of extentIDs) {
|
|
251
|
+
if (after == null || id > after) {
|
|
252
|
+
candidates.add(id)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
for (const place of await this.#irregularPlaces()) {
|
|
257
|
+
if ((after == null || place.id > after) && boxContains(box, place.latitude, place.longitude)) {
|
|
258
|
+
candidates.add(place.id)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// A candidate's extent meets the box, and its point lies inside unless the extent crosses an edge.
|
|
263
|
+
// A chunk past the limit therefore holds the page in the common case.
|
|
264
|
+
const ordered = [...candidates].toSorted((a, b) => a - b)
|
|
265
|
+
const page: BrowsedPlace[] = []
|
|
266
|
+
const chunk = limit + PAGE_CHUNK_MARGIN
|
|
267
|
+
|
|
268
|
+
for (let start = 0; start < ordered.length && page.length < limit; start += chunk) {
|
|
269
|
+
const ids = ordered.slice(start, start + chunk)
|
|
270
|
+
|
|
271
|
+
const rows = await this.#current()
|
|
272
|
+
.where("spr.id", "in", sql<number>`(SELECT value FROM json_each(${stringifyJSON(ids)}))`)
|
|
273
|
+
.orderBy("spr.id")
|
|
274
|
+
.execute()
|
|
275
|
+
|
|
276
|
+
for (const row of rows) {
|
|
277
|
+
if (page.length < limit && boxContains(box, row.latitude, row.longitude)) {
|
|
278
|
+
page.push(row)
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return page
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* The current places the R*Tree build skipped, read once: a null extent,
|
|
288
|
+
* or the all-zero extent it treats as none.
|
|
289
|
+
*/
|
|
290
|
+
#irregularPlaces(): Promise<IrregularPlace[]> {
|
|
291
|
+
this.#irregular ??= this.database
|
|
292
|
+
.selectFrom("spr")
|
|
293
|
+
.select(["id", "latitude", "longitude"])
|
|
294
|
+
.where("spr.is_current", "!=", 0)
|
|
295
|
+
.where("spr.is_deprecated", "=", 0)
|
|
296
|
+
.where(
|
|
297
|
+
sql<boolean>`(spr.min_latitude IS NULL OR spr.max_latitude IS NULL OR spr.min_longitude IS NULL OR spr.max_longitude IS NULL
|
|
298
|
+
OR (spr.min_latitude = 0 AND spr.max_latitude = 0 AND spr.min_longitude = 0 AND spr.max_longitude = 0))`
|
|
299
|
+
)
|
|
300
|
+
.execute()
|
|
301
|
+
|
|
302
|
+
return this.#irregular
|
|
303
|
+
}
|
|
304
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
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 { stringifyJSON } from "@mailwoman/core/json"
|
|
4
|
+
import { stringifyJSON } from "@mailwoman/core/values/json"
|
|
5
5
|
import { basename, PathBuilder, type PathBuilderLike } from "path-ts"
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @file The former administrative divisions table: each division that no longer exists, with
|
|
6
|
+
* the current places its containment evidence ties it to.
|
|
7
|
+
*
|
|
8
|
+
* `mailwoman gazetteer` tooling builds the table from GeoNames' historical divisions
|
|
9
|
+
* (feature codes `ADM1H` through `ADM5H` and `PCLH`) and from Who's On First's ceased admin records,
|
|
10
|
+
* for every country. The resolver reads it behind the `formerDivisions` switch, and the
|
|
11
|
+
* `former-divisions` corpus recipe reads it to place a former division in rendered addresses.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { dataRootPath } from "@mailwoman/core/data-root"
|
|
15
|
+
import { readLocalJSONFile } from "@mailwoman/core/fs/readers"
|
|
16
|
+
import { pathExists } from "@mailwoman/core/fs/readers/stat"
|
|
17
|
+
import type { FormerDivisionLookup, FormerDivisionMatch } from "@mailwoman/core/resolver"
|
|
18
|
+
import type { PathBuilder, PathBuilderLike } from "path-ts"
|
|
19
|
+
|
|
20
|
+
import { normalizeLocalityForKey } from "#labels/street/normalize"
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The table's default location, `$MAILWOMAN_DATA_ROOT/gazetteer/former-divisions-v1.json`.
|
|
24
|
+
*/
|
|
25
|
+
export function formerDivisionsTablePath(): PathBuilder {
|
|
26
|
+
return dataRootPath("gazetteer", "former-divisions-v1.json")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Reads the table at `path`.
|
|
31
|
+
*
|
|
32
|
+
* @throws When the file is absent or isn't format 1, with the path in the message,
|
|
33
|
+
* because a caller that asked for former divisions mustn't run as though none existed.
|
|
34
|
+
*/
|
|
35
|
+
export async function readFormerDivisionsTable(
|
|
36
|
+
path: PathBuilderLike = formerDivisionsTablePath()
|
|
37
|
+
): Promise<FormerDivisionsTable> {
|
|
38
|
+
if (!(await pathExists(path))) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`former divisions table not found at ${path}; build it with \`node packages/gazetteer/tools/former-divisions.run.ts\``
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const table = await readLocalJSONFile<FormerDivisionsTable>(path)
|
|
45
|
+
|
|
46
|
+
if (table.format !== 1 || !Array.isArray(table.divisions)) {
|
|
47
|
+
throw new Error(`${path} is not a format-1 former divisions table`)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return table
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The containment evidence a link rests on.
|
|
55
|
+
*/
|
|
56
|
+
export const FormerDivisionEvidence = {
|
|
57
|
+
/**
|
|
58
|
+
* A GeoNames `hierarchy.txt` row whose parent is the historical division.
|
|
59
|
+
*/
|
|
60
|
+
GeonamesHierarchy: "geonames_hierarchy",
|
|
61
|
+
/**
|
|
62
|
+
* Current GeoNames rows that still hold the historical division's retired admin code.
|
|
63
|
+
*/
|
|
64
|
+
GeonamesAdminCodes: "geonames_admin_codes",
|
|
65
|
+
/**
|
|
66
|
+
* A ceased WOF record's `wof:superseded_by`.
|
|
67
|
+
*/
|
|
68
|
+
WOFSupersession: "wof_supersession",
|
|
69
|
+
} as const
|
|
70
|
+
|
|
71
|
+
export type FormerDivisionEvidence = (typeof FormerDivisionEvidence)[keyof typeof FormerDivisionEvidence]
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The current places one kind of evidence ties a former division to.
|
|
75
|
+
*/
|
|
76
|
+
export interface FormerDivisionLink {
|
|
77
|
+
evidence: FormerDivisionEvidence
|
|
78
|
+
/**
|
|
79
|
+
* WOF ids of the current places, sorted.
|
|
80
|
+
*/
|
|
81
|
+
wofIDs: number[]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* One former division.
|
|
86
|
+
*/
|
|
87
|
+
export interface FormerDivisionRecord {
|
|
88
|
+
/**
|
|
89
|
+
* Upper-case ISO 3166-1 alpha-2 code.
|
|
90
|
+
*/
|
|
91
|
+
country: string
|
|
92
|
+
name: string
|
|
93
|
+
/**
|
|
94
|
+
* Every surface name the division is matched by, `name` first.
|
|
95
|
+
*/
|
|
96
|
+
names: string[]
|
|
97
|
+
/**
|
|
98
|
+
* The GeoNames feature code (`ADM2H`) or, for a division only WOF records, its placetype (`county`).
|
|
99
|
+
*/
|
|
100
|
+
kind: string
|
|
101
|
+
/**
|
|
102
|
+
* The `ComponentTag` the division takes in an address: `subregion` at county level,
|
|
103
|
+
* else the matching level.
|
|
104
|
+
*/
|
|
105
|
+
tag: "country" | "region" | "subregion" | "locality"
|
|
106
|
+
geonamesID: number | null
|
|
107
|
+
wofID: number | null
|
|
108
|
+
latitude: number | null
|
|
109
|
+
longitude: number | null
|
|
110
|
+
/**
|
|
111
|
+
* At least one link.
|
|
112
|
+
*
|
|
113
|
+
* The builder leaves a division without a link out of the table.
|
|
114
|
+
*/
|
|
115
|
+
links: FormerDivisionLink[]
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The table's file.
|
|
120
|
+
*/
|
|
121
|
+
export interface FormerDivisionsTable {
|
|
122
|
+
format: 1
|
|
123
|
+
builtAt: string
|
|
124
|
+
/**
|
|
125
|
+
* Each input's path and digest, so a reader can tell which inputs built the table.
|
|
126
|
+
*/
|
|
127
|
+
inputs: Record<string, string>
|
|
128
|
+
divisions: FormerDivisionRecord[]
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The key a former division's name is matched under, the candidate table's locality fold.
|
|
133
|
+
*/
|
|
134
|
+
export function formerDivisionNameKey(name: string): string {
|
|
135
|
+
return normalizeLocalityForKey(name)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Reads the table at `path` and indexes it, throwing as {@link readFormerDivisionsTable} does.
|
|
140
|
+
*/
|
|
141
|
+
export async function readFormerDivisionLookup(
|
|
142
|
+
path: PathBuilderLike = formerDivisionsTablePath()
|
|
143
|
+
): Promise<FormerDivisionLookup> {
|
|
144
|
+
return createFormerDivisionLookup(await readFormerDivisionsTable(path))
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Indexes a table's divisions by name key for {@link FormerDivisionLookup.divisionsNamed}.
|
|
149
|
+
*/
|
|
150
|
+
export function createFormerDivisionLookup(table: Pick<FormerDivisionsTable, "divisions">): FormerDivisionLookup {
|
|
151
|
+
const byKey = new Map<string, FormerDivisionMatch[]>()
|
|
152
|
+
|
|
153
|
+
for (const division of table.divisions) {
|
|
154
|
+
const match: FormerDivisionMatch = {
|
|
155
|
+
name: division.name,
|
|
156
|
+
country: division.country,
|
|
157
|
+
kind: division.kind,
|
|
158
|
+
tag: division.tag,
|
|
159
|
+
geonamesID: division.geonamesID,
|
|
160
|
+
wofID: division.wofID,
|
|
161
|
+
linkedIDs: new Set(division.links.flatMap((link) => link.wofIDs)),
|
|
162
|
+
evidence: division.links.map((link) => link.evidence),
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
for (const key of new Set(division.names.map(formerDivisionNameKey).filter((folded) => folded.length > 0))) {
|
|
166
|
+
let matches = byKey.get(key)
|
|
167
|
+
|
|
168
|
+
if (!matches) {
|
|
169
|
+
byKey.set(key, (matches = []))
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
matches.push(match)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
divisionsNamed(value, country) {
|
|
178
|
+
const matches = byKey.get(formerDivisionNameKey(value)) ?? []
|
|
179
|
+
|
|
180
|
+
return country ? matches.filter((match) => match.country === country) : matches
|
|
181
|
+
},
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The postcode lookup over gazetteer databases: the country and point of each
|
|
6
|
+
* `postalcode` place a postcode spells.
|
|
7
|
+
*/
|
|
8
|
+
|
|
4
9
|
import type { PostcodePlace } from "@mailwoman/core/resolver"
|
|
5
10
|
import { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
6
11
|
import type { PathBuilderLike } from "path-ts"
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
* 4. Assemble the deepest place's ancestor chain through the same walk forward
|
|
18
18
|
* resolution uses, so consumers get a symmetric tree.
|
|
19
19
|
*
|
|
20
|
-
* Reverse quality
|
|
21
|
-
* `containment` records
|
|
20
|
+
* Reverse quality depends on each country's polygon coverage.
|
|
21
|
+
* The `containment` field records whether each result used a polygon or an approximate centroid fallback.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import { tryParsingJSON } from "@mailwoman/core/json"
|
|
25
24
|
import { allRows } from "@mailwoman/core/utils"
|
|
25
|
+
import { tryParsingJSON } from "@mailwoman/core/values/json"
|
|
26
26
|
import type { ParsedGeometry } from "@mailwoman/spatial"
|
|
27
27
|
import { bboxAround } from "@mailwoman/spatial/bbox"
|
|
28
28
|
import { haversine } from "@mailwoman/spatial/geometries/point/distance"
|
|
@@ -33,8 +33,8 @@ import type { PathBuilderLike } from "path-ts"
|
|
|
33
33
|
|
|
34
34
|
import { ancestorLineage, placetypeDepth } from "#ancestry"
|
|
35
35
|
import { PLACE_BBOX_TABLE } from "#fts"
|
|
36
|
+
import type { PlaceCandidate, WOFPlacetype } from "#lookup/types"
|
|
36
37
|
import type { WOFDatabase } from "#schema"
|
|
37
|
-
import type { PlaceCandidate, WOFPlacetype } from "#types"
|
|
38
38
|
/**
|
|
39
39
|
* Largest absolute latitude in WGS-84 degrees.
|
|
40
40
|
*/
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The place-lookup interface: the query a caller sends, the candidate a backend
|
|
6
|
+
* returns, and the placetypes both speak in.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { ScoreUnmeasuredReason } from "@mailwoman/core/resolver"
|
|
4
10
|
import type { LatLon, LatLonBounds } from "@mailwoman/spatial"
|
|
5
11
|
|
|
6
12
|
/**
|
|
@@ -44,6 +50,10 @@ export interface PlaceCandidate {
|
|
|
44
50
|
*/
|
|
45
51
|
parent_id: number | null
|
|
46
52
|
score: number
|
|
53
|
+
/**
|
|
54
|
+
* Why `score` is unmeasured: the candidate table ranks by a population the place doesn't record.
|
|
55
|
+
*/
|
|
56
|
+
scoreUnmeasured?: ScoreUnmeasuredReason | null
|
|
47
57
|
distanceKm: number | null
|
|
48
58
|
|
|
49
59
|
/**
|
package/lib/lookup.ts
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* Kysely-typed query layer where the queries are non-trivial and raw SQL where they're not.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { expandPlacetypeFilter } from "@mailwoman/codex/placetype-map"
|
|
9
|
+
import { expandPlacetypeFilter } from "@mailwoman/codex/labels/placetype-map"
|
|
10
|
+
import { postcodeRetryForms } from "@mailwoman/codex/labels/postcode/retry-forms"
|
|
10
11
|
import type { Ancestor } from "@mailwoman/core/resolver"
|
|
11
12
|
import { allRows } from "@mailwoman/core/utils"
|
|
12
13
|
import { haversine } from "@mailwoman/spatial/geometries/point/distance"
|
|
@@ -25,13 +26,6 @@ import {
|
|
|
25
26
|
type ResolvedConvention,
|
|
26
27
|
type Strategy,
|
|
27
28
|
} from "#convention"
|
|
28
|
-
import {
|
|
29
|
-
pickExtractForPlacetype,
|
|
30
|
-
pickExtractsForPlacetype,
|
|
31
|
-
resolveExtracts,
|
|
32
|
-
type ResolvedExtract,
|
|
33
|
-
type ExtractConfig,
|
|
34
|
-
} from "#extracts"
|
|
35
29
|
import {
|
|
36
30
|
buildPlaceSearchFTS,
|
|
37
31
|
PLACE_BBOX_TABLE,
|
|
@@ -42,14 +36,21 @@ import {
|
|
|
42
36
|
placeSearchFTSExists,
|
|
43
37
|
} from "#fts"
|
|
44
38
|
import { normalizePlacetypes, sanitizeFTSQuery } from "#fts/query"
|
|
45
|
-
import {
|
|
46
|
-
import {
|
|
47
|
-
import
|
|
48
|
-
|
|
39
|
+
import { fetchSearchRows, type RawSearchRow } from "#fts/search-fetch"
|
|
40
|
+
import type { WOFPostalCityAliasLookup } from "#labels/locality/postal-city/alias/lookup"
|
|
41
|
+
import {
|
|
42
|
+
pickExtractForPlacetype,
|
|
43
|
+
pickExtractsForPlacetype,
|
|
44
|
+
resolveExtracts,
|
|
45
|
+
type ResolvedExtract,
|
|
46
|
+
type ExtractConfig,
|
|
47
|
+
} from "#lookup/extracts"
|
|
48
|
+
import type { FindPlaceQuery, PlaceCandidate, PlaceLookup, WOFPlacetype } from "#lookup/types"
|
|
49
|
+
import { cfNormalize, softNameScore } from "#ranking/name-score"
|
|
50
|
+
import { DEFAULT_WEIGHTS, populationScaleTerm, type RankingWeights } from "#ranking/weights"
|
|
49
51
|
import type { WOFDatabase } from "#schema"
|
|
50
|
-
import {
|
|
52
|
+
import { encyclopedicClauses } from "#schema/place-importance"
|
|
51
53
|
import { SqliteConventionSource } from "#sqlite/convention-source"
|
|
52
|
-
import type { FindPlaceQuery, PlaceCandidate, PlaceLookup, WOFPlacetype } from "#types"
|
|
53
54
|
|
|
54
55
|
export interface WOFSQLitePlaceLookupOpts {
|
|
55
56
|
/**
|
|
@@ -326,25 +327,14 @@ export class WOFSQLitePlaceLookup extends SQLiteLookup<WOFDatabase> implements P
|
|
|
326
327
|
|
|
327
328
|
if (found.length) return found
|
|
328
329
|
|
|
329
|
-
// On a postcode-typed
|
|
330
|
-
//
|
|
331
|
-
if (
|
|
332
|
-
query.country
|
|
333
|
-
|
|
334
|
-
/^\d{4}\s?[A-Za-z]{2}$/.test(query.text.trim())
|
|
335
|
-
) {
|
|
336
|
-
const trimmed = query.text.trim()
|
|
337
|
-
const joined = trimmed.replaceAll(/\s+/g, "")
|
|
330
|
+
// On a postcode-typed miss, retry with the forms the codex states for the query's country.
|
|
331
|
+
// The rule is keyed by country so the same shape elsewhere cannot coarsen to another system's code.
|
|
332
|
+
if (normalizePlacetypes(query.placetype)?.includes("postalcode") ?? false) {
|
|
333
|
+
for (const text of postcodeRetryForms(query.text, query.country)) {
|
|
334
|
+
const retried = await this.findPlace({ ...query, text })
|
|
338
335
|
|
|
339
|
-
|
|
340
|
-
const full = await this.findPlace({ ...query, text: joined })
|
|
341
|
-
|
|
342
|
-
if (full.length) return full
|
|
336
|
+
if (retried.length) return retried
|
|
343
337
|
}
|
|
344
|
-
|
|
345
|
-
const stem = trimmed.slice(0, 4)
|
|
346
|
-
|
|
347
|
-
if (stem !== trimmed) return this.findPlace({ ...query, text: stem })
|
|
348
338
|
}
|
|
349
339
|
|
|
350
340
|
return found
|
package/lib/poi/schema.ts
CHANGED
|
@@ -22,7 +22,7 @@ import type { layerschemadatabase } from "@mailwoman/core/layers"
|
|
|
22
22
|
import type { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
23
23
|
import { sql, type Kysely } from "kysely"
|
|
24
24
|
|
|
25
|
-
import type { NameKey } from "#street/normalize"
|
|
25
|
+
import type { NameKey } from "#labels/street/normalize"
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* One POI row.
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The primary-name preference re-rank: a place whose primary name is the query outranks a place
|
|
6
|
+
* that lists it as an alias, unless the alias row's population exceeds it by a stated log10 margin.
|
|
7
|
+
*/
|
|
8
|
+
|
|
4
9
|
import { latLonBoundsContain } from "@mailwoman/spatial/bbox"
|
|
5
10
|
|
|
6
11
|
import type { CandidateTable } from "#candidate/schema"
|