@mailwoman/resolver-wof-sqlite 9.1.0 → 9.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 +36 -20
- package/lib/address/index.ts +9 -0
- package/{address-point-interpolation.ts → lib/address/point-interpolation.ts} +40 -28
- package/{address-point-schema.ts → lib/address/point-schema.ts} +34 -8
- package/lib/address/point.ts +280 -0
- package/{ancestry-backfill.ts → lib/ancestry/backfill.ts} +14 -19
- package/{ancestry.ts → lib/ancestry/index.ts} +13 -8
- package/{build-candidate.ts → lib/build-candidate.ts} +243 -199
- package/{build-slim.ts → lib/build-slim.ts} +153 -168
- package/lib/candidate/alias-bags.ts +56 -0
- package/lib/candidate/ancestors-sidecar.ts +204 -0
- package/lib/candidate/country-display-names.ts +79 -0
- package/lib/candidate/extract-fold.ts +138 -0
- package/lib/candidate/name-roles.ts +238 -0
- package/lib/candidate/own-name.ts +146 -0
- package/lib/candidate/place-attrs.ts +44 -0
- package/lib/candidate-ancestors-schema.ts +195 -0
- package/{candidate-fts.ts → lib/candidate-fts.ts} +7 -5
- package/{candidate-importance.ts → lib/candidate-importance.ts} +54 -57
- package/lib/candidate-lookup.ts +976 -0
- package/{candidate-schema.ts → lib/candidate-schema.ts} +34 -6
- package/lib/candidate-scoring.ts +261 -0
- package/lib/capital-schema.ts +89 -0
- package/lib/capitals.ts +148 -0
- package/{coincident-roles.ts → lib/coincident-roles.ts} +75 -19
- package/{convention.ts → lib/convention/index.ts} +5 -5
- package/lib/convention/schema.ts +72 -0
- package/{coverage-manifest-schema.ts → lib/coverage-manifest-schema.ts} +15 -16
- package/lib/currency-backfill.ts +334 -0
- package/lib/env.ts +50 -0
- package/lib/exact-match.ts +113 -0
- package/{sharding.ts → lib/extracts.ts} +63 -60
- package/lib/fst/autocomplete.ts +176 -0
- package/{fst-builder.ts → lib/fst/builder.ts} +30 -27
- package/{fst-deserialize-web.ts → lib/fst/deserialize-web.ts} +27 -87
- package/lib/fst/format.ts +106 -0
- package/{fst-freshness.ts → lib/fst/freshness.ts} +42 -75
- package/lib/fst/index.ts +14 -0
- package/{fst-matcher.ts → lib/fst/matcher.ts} +1 -1
- package/{fst-serialize.ts → lib/fst/serialize.ts} +37 -115
- package/{fst-types.ts → lib/fst/types.ts} +4 -2
- package/{fts.ts → lib/fts/index.ts} +28 -23
- package/{fts-query.ts → lib/fts/query.ts} +2 -2
- package/{geonames-aliases.ts → lib/geonames/aliases.ts} +13 -13
- package/lib/geonames/index.ts +8 -0
- package/{geonames-postal.ts → lib/geonames/postal.ts} +16 -15
- package/{index.ts → lib/index.ts} +52 -48
- package/{interpolation.ts → lib/interpolation.ts} +137 -41
- package/lib/lookup.ts +861 -0
- package/{name-score.ts → lib/name-score.ts} +6 -4
- package/lib/nsul/index.ts +8 -0
- package/lib/nsul/lookup.ts +144 -0
- package/lib/nsul/schema.ts +130 -0
- package/{place-importance-schema.ts → lib/place-importance-schema.ts} +70 -22
- package/lib/poi/index.ts +8 -0
- package/{poi-lookup.ts → lib/poi/lookup.ts} +32 -39
- package/{poi-schema.ts → lib/poi/schema.ts} +10 -6
- package/lib/polygon-schema.ts +47 -0
- package/{postal-city-alias-lookup.ts → lib/postal/city-alias-lookup.ts} +15 -21
- package/{postal-city-candidate-schema.ts → lib/postal/city-candidate-schema.ts} +4 -2
- package/lib/postal/index.ts +9 -0
- package/{postcode-point-lookup.ts → lib/postcode-point-lookup.ts} +17 -15
- package/lib/primary-preference.ts +226 -0
- package/lib/proximity-rerank.ts +120 -0
- package/{ranking-weights.ts → lib/ranking-weights.ts} +30 -4
- package/lib/region-keys.ts +144 -0
- package/{reverse.ts → lib/reverse.ts} +45 -56
- package/{schema.ts → lib/schema.ts} +11 -1
- package/lib/search-fetch.ts +257 -0
- package/{sqlite-convention-source.ts → lib/sqlite-convention-source.ts} +9 -10
- package/lib/sqlite-utils.ts +83 -0
- package/{street-centroid-schema.ts → lib/street/centroid-schema.ts} +12 -6
- package/{street-centroid.ts → lib/street/centroid.ts} +26 -28
- package/lib/street/index.ts +13 -0
- package/{street-morphology-fst-builder.ts → lib/street/morphology-fst-builder.ts} +24 -14
- package/{street-morphology-fst-loader.ts → lib/street/morphology-fst-loader.ts} +14 -12
- package/{street-name-lookup.ts → lib/street/name-lookup.ts} +14 -30
- package/lib/street/normalize.ts +572 -0
- package/{street-segment-schema.ts → lib/street/segment-schema.ts} +13 -8
- package/{types.ts → lib/types.ts} +49 -9
- package/{unified-schema.ts → lib/unified-schema.ts} +21 -25
- package/lib/uprn/existence.ts +84 -0
- package/lib/uprn/index.ts +9 -0
- package/lib/uprn/lookup.ts +206 -0
- package/lib/uprn/schema.ts +124 -0
- package/lib/weights-overlay-linker.ts +878 -0
- package/out/address/index.d.ts +9 -0
- package/out/address/index.d.ts.map +1 -0
- package/out/address/index.js +9 -0
- package/out/address/index.js.map +1 -0
- package/out/{address-point-interpolation.d.ts → address/point-interpolation.d.ts} +11 -10
- package/out/address/point-interpolation.d.ts.map +1 -0
- package/out/{address-point-interpolation.js → address/point-interpolation.js} +29 -23
- package/out/address/point-interpolation.js.map +1 -0
- package/out/{address-point-schema.d.ts → address/point-schema.d.ts} +30 -10
- package/out/address/point-schema.d.ts.map +1 -0
- package/out/{address-point-schema.js → address/point-schema.js} +7 -3
- package/out/address/point-schema.js.map +1 -0
- package/out/{address-point.d.ts → address/point.d.ts} +16 -8
- package/out/address/point.d.ts.map +1 -0
- package/out/address/point.js +191 -0
- package/out/address/point.js.map +1 -0
- package/out/{ancestry-backfill.d.ts → ancestry/backfill.d.ts} +7 -5
- package/out/ancestry/backfill.d.ts.map +1 -0
- package/out/{ancestry-backfill.js → ancestry/backfill.js} +12 -16
- package/out/ancestry/backfill.js.map +1 -0
- package/out/{ancestry.d.ts → ancestry/index.d.ts} +6 -5
- package/out/ancestry/index.d.ts.map +1 -0
- package/out/{ancestry.js → ancestry/index.js} +7 -7
- package/out/ancestry/index.js.map +1 -0
- package/out/build-candidate.d.ts +88 -7
- package/out/build-candidate.d.ts.map +1 -1
- package/out/build-candidate.js +145 -149
- package/out/build-candidate.js.map +1 -1
- package/out/build-slim.d.ts +5 -5
- package/out/build-slim.d.ts.map +1 -1
- package/out/build-slim.js +127 -142
- package/out/build-slim.js.map +1 -1
- package/out/candidate/alias-bags.d.ts +19 -0
- package/out/candidate/alias-bags.d.ts.map +1 -0
- package/out/candidate/alias-bags.js +39 -0
- package/out/candidate/alias-bags.js.map +1 -0
- package/out/candidate/ancestors-sidecar.d.ts +32 -0
- package/out/candidate/ancestors-sidecar.d.ts.map +1 -0
- package/out/candidate/ancestors-sidecar.js +140 -0
- package/out/candidate/ancestors-sidecar.js.map +1 -0
- package/out/candidate/country-display-names.d.ts +35 -0
- package/out/candidate/country-display-names.d.ts.map +1 -0
- package/out/candidate/country-display-names.js +59 -0
- package/out/candidate/country-display-names.js.map +1 -0
- package/out/candidate/extract-fold.d.ts +32 -0
- package/out/candidate/extract-fold.d.ts.map +1 -0
- package/out/candidate/extract-fold.js +104 -0
- package/out/candidate/extract-fold.js.map +1 -0
- package/out/candidate/name-roles.d.ts +57 -0
- package/out/candidate/name-roles.d.ts.map +1 -0
- package/out/candidate/name-roles.js +166 -0
- package/out/candidate/name-roles.js.map +1 -0
- package/out/candidate/own-name.d.ts +50 -0
- package/out/candidate/own-name.d.ts.map +1 -0
- package/out/candidate/own-name.js +132 -0
- package/out/candidate/own-name.js.map +1 -0
- package/out/candidate/place-attrs.d.ts +43 -0
- package/out/candidate/place-attrs.d.ts.map +1 -0
- package/out/candidate/place-attrs.js +15 -0
- package/out/candidate/place-attrs.js.map +1 -0
- package/out/candidate-ancestors-schema.d.ts +150 -0
- package/out/candidate-ancestors-schema.d.ts.map +1 -0
- package/out/candidate-ancestors-schema.js +123 -0
- package/out/candidate-ancestors-schema.js.map +1 -0
- package/out/candidate-fts.d.ts +7 -5
- package/out/candidate-fts.d.ts.map +1 -1
- package/out/candidate-fts.js +5 -3
- package/out/candidate-fts.js.map +1 -1
- package/out/candidate-importance.d.ts +16 -16
- package/out/candidate-importance.d.ts.map +1 -1
- package/out/candidate-importance.js +47 -52
- package/out/candidate-importance.js.map +1 -1
- package/out/candidate-lookup.d.ts +31 -52
- package/out/candidate-lookup.d.ts.map +1 -1
- package/out/candidate-lookup.js +380 -172
- package/out/candidate-lookup.js.map +1 -1
- package/out/candidate-schema.d.ts +31 -7
- package/out/candidate-schema.d.ts.map +1 -1
- package/out/candidate-schema.js +3 -0
- package/out/candidate-schema.js.map +1 -1
- package/out/candidate-scoring.d.ts +34 -0
- package/out/candidate-scoring.d.ts.map +1 -0
- package/out/candidate-scoring.js +196 -0
- package/out/candidate-scoring.js.map +1 -0
- package/out/capital-schema.d.ts +51 -0
- package/out/capital-schema.d.ts.map +1 -0
- package/out/capital-schema.js +63 -0
- package/out/capital-schema.js.map +1 -0
- package/out/capitals.d.ts +69 -0
- package/out/capitals.d.ts.map +1 -0
- package/out/capitals.js +98 -0
- package/out/capitals.js.map +1 -0
- package/out/coincident-roles.d.ts +12 -4
- package/out/coincident-roles.d.ts.map +1 -1
- package/out/coincident-roles.js +43 -11
- package/out/coincident-roles.js.map +1 -1
- package/out/{convention.d.ts → convention/index.d.ts} +5 -5
- package/out/convention/index.d.ts.map +1 -0
- package/out/{convention.js → convention/index.js} +4 -4
- package/out/convention/index.js.map +1 -0
- package/out/convention/schema.d.ts +51 -0
- package/out/convention/schema.d.ts.map +1 -0
- package/out/convention/schema.js +34 -0
- package/out/convention/schema.js.map +1 -0
- package/out/coverage-manifest-schema.d.ts +8 -8
- package/out/coverage-manifest-schema.d.ts.map +1 -1
- package/out/coverage-manifest-schema.js +6 -10
- package/out/coverage-manifest-schema.js.map +1 -1
- package/out/currency-backfill.d.ts +90 -0
- package/out/currency-backfill.d.ts.map +1 -0
- package/out/currency-backfill.js +196 -0
- package/out/currency-backfill.js.map +1 -0
- package/out/env.d.ts +43 -0
- package/out/env.d.ts.map +1 -0
- package/out/env.js +48 -0
- package/out/env.js.map +1 -0
- package/out/exact-match.d.ts +25 -0
- package/out/exact-match.d.ts.map +1 -0
- package/out/exact-match.js +88 -0
- package/out/exact-match.js.map +1 -0
- package/out/extracts.d.ts +114 -0
- package/out/extracts.d.ts.map +1 -0
- package/out/{sharding.js → extracts.js} +38 -38
- package/out/extracts.js.map +1 -0
- package/out/{fst-autocomplete.d.ts → fst/autocomplete.d.ts} +13 -13
- package/out/fst/autocomplete.d.ts.map +1 -0
- package/out/fst/autocomplete.js +113 -0
- package/out/fst/autocomplete.js.map +1 -0
- package/out/{fst-builder.d.ts → fst/builder.d.ts} +5 -5
- package/out/fst/builder.d.ts.map +1 -0
- package/out/{fst-builder.js → fst/builder.js} +24 -24
- package/out/fst/builder.js.map +1 -0
- package/out/{fst-deserialize-web.d.ts → fst/deserialize-web.d.ts} +3 -3
- package/out/fst/deserialize-web.d.ts.map +1 -0
- package/out/{fst-deserialize-web.js → fst/deserialize-web.js} +10 -74
- package/out/fst/deserialize-web.js.map +1 -0
- package/out/fst/format.d.ts +80 -0
- package/out/fst/format.d.ts.map +1 -0
- package/out/fst/format.js +91 -0
- package/out/fst/format.js.map +1 -0
- package/out/{fst-freshness.d.ts → fst/freshness.d.ts} +11 -14
- package/out/fst/freshness.d.ts.map +1 -0
- package/out/{fst-freshness.js → fst/freshness.js} +42 -74
- package/out/fst/freshness.js.map +1 -0
- package/out/fst/index.d.ts +14 -0
- package/out/fst/index.d.ts.map +1 -0
- package/out/fst/index.js +14 -0
- package/out/fst/index.js.map +1 -0
- package/out/{fst-matcher.d.ts → fst/matcher.d.ts} +2 -2
- package/out/fst/matcher.d.ts.map +1 -0
- package/out/{fst-matcher.js → fst/matcher.js} +1 -1
- package/out/fst/matcher.js.map +1 -0
- package/out/{fst-serialize.d.ts → fst/serialize.d.ts} +5 -10
- package/out/fst/serialize.d.ts.map +1 -0
- package/out/{fst-serialize.js → fst/serialize.js} +18 -98
- package/out/fst/serialize.js.map +1 -0
- package/out/{fst-types.d.ts → fst/types.d.ts} +4 -3
- package/out/fst/types.d.ts.map +1 -0
- package/out/{fst-types.js → fst/types.js} +1 -1
- package/out/fst/types.js.map +1 -0
- package/out/{fts.d.ts → fts/index.d.ts} +20 -13
- package/out/fts/index.d.ts.map +1 -0
- package/out/{fts.js → fts/index.js} +20 -15
- package/out/fts/index.js.map +1 -0
- package/out/{fts-query.d.ts → fts/query.d.ts} +2 -2
- package/out/fts/query.d.ts.map +1 -0
- package/out/{fts-query.js → fts/query.js} +2 -2
- package/out/fts/query.js.map +1 -0
- package/out/{geonames-aliases.d.ts → geonames/aliases.d.ts} +8 -6
- package/out/geonames/aliases.d.ts.map +1 -0
- package/out/{geonames-aliases.js → geonames/aliases.js} +7 -7
- package/out/geonames/aliases.js.map +1 -0
- package/out/geonames/index.d.ts +8 -0
- package/out/geonames/index.d.ts.map +1 -0
- package/out/geonames/index.js +8 -0
- package/out/geonames/index.js.map +1 -0
- package/out/{geonames-postal.d.ts → geonames/postal.d.ts} +12 -10
- package/out/geonames/postal.d.ts.map +1 -0
- package/out/{geonames-postal.js → geonames/postal.js} +11 -11
- package/out/geonames/postal.js.map +1 -0
- package/out/index.d.ts +32 -31
- package/out/index.d.ts.map +1 -1
- package/out/index.js +24 -24
- package/out/index.js.map +1 -1
- package/out/interpolation.d.ts +18 -9
- package/out/interpolation.d.ts.map +1 -1
- package/out/interpolation.js +108 -36
- package/out/interpolation.js.map +1 -1
- package/out/lookup.d.ts +25 -25
- package/out/lookup.d.ts.map +1 -1
- package/out/lookup.js +174 -558
- package/out/lookup.js.map +1 -1
- package/out/name-score.d.ts +0 -10
- package/out/name-score.d.ts.map +1 -1
- package/out/name-score.js +6 -4
- package/out/name-score.js.map +1 -1
- package/out/nsul/index.d.ts +8 -0
- package/out/nsul/index.d.ts.map +1 -0
- package/out/nsul/index.js +8 -0
- package/out/nsul/index.js.map +1 -0
- package/out/nsul/lookup.d.ts +83 -0
- package/out/nsul/lookup.d.ts.map +1 -0
- package/out/nsul/lookup.js +80 -0
- package/out/nsul/lookup.js.map +1 -0
- package/out/nsul/schema.d.ts +100 -0
- package/out/nsul/schema.d.ts.map +1 -0
- package/out/nsul/schema.js +78 -0
- package/out/nsul/schema.js.map +1 -0
- package/out/place-importance-schema.d.ts +47 -10
- package/out/place-importance-schema.d.ts.map +1 -1
- package/out/place-importance-schema.js +56 -10
- package/out/place-importance-schema.js.map +1 -1
- package/out/poi/index.d.ts +8 -0
- package/out/poi/index.d.ts.map +1 -0
- package/out/poi/index.js +8 -0
- package/out/poi/index.js.map +1 -0
- package/out/{poi-lookup.d.ts → poi/lookup.d.ts} +8 -10
- package/out/poi/lookup.d.ts.map +1 -0
- package/out/{poi-lookup.js → poi/lookup.js} +24 -29
- package/out/poi/lookup.js.map +1 -0
- package/out/{poi-schema.d.ts → poi/schema.d.ts} +10 -6
- package/out/poi/schema.d.ts.map +1 -0
- package/out/{poi-schema.js → poi/schema.js} +1 -1
- package/out/poi/schema.js.map +1 -0
- package/out/polygon-schema.d.ts +37 -0
- package/out/polygon-schema.d.ts.map +1 -0
- package/out/polygon-schema.js +23 -0
- package/out/polygon-schema.js.map +1 -0
- package/out/{postal-city-alias-lookup.d.ts → postal/city-alias-lookup.d.ts} +7 -6
- package/out/postal/city-alias-lookup.d.ts.map +1 -0
- package/out/{postal-city-alias-lookup.js → postal/city-alias-lookup.js} +12 -16
- package/out/postal/city-alias-lookup.js.map +1 -0
- package/out/{postal-city-alias-schema.d.ts → postal/city-alias-schema.d.ts} +1 -1
- package/out/{postal-city-alias-schema.d.ts.map → postal/city-alias-schema.d.ts.map} +1 -1
- package/out/{postal-city-alias-schema.js → postal/city-alias-schema.js} +1 -1
- package/out/{postal-city-alias-schema.js.map → postal/city-alias-schema.js.map} +1 -1
- package/out/{postal-city-candidate-schema.d.ts → postal/city-candidate-schema.d.ts} +4 -3
- package/out/postal/city-candidate-schema.d.ts.map +1 -0
- package/out/{postal-city-candidate-schema.js → postal/city-candidate-schema.js} +2 -2
- package/out/{postal-city-candidate-schema.js.map → postal/city-candidate-schema.js.map} +1 -1
- package/out/postal/index.d.ts +9 -0
- package/out/postal/index.d.ts.map +1 -0
- package/out/postal/index.js +9 -0
- package/out/postal/index.js.map +1 -0
- package/out/postcode-point-lookup.d.ts +10 -10
- package/out/postcode-point-lookup.d.ts.map +1 -1
- package/out/postcode-point-lookup.js +13 -13
- package/out/postcode-point-lookup.js.map +1 -1
- package/out/primary-preference.d.ts +133 -0
- package/out/primary-preference.d.ts.map +1 -0
- package/out/primary-preference.js +146 -0
- package/out/primary-preference.js.map +1 -0
- package/out/proximity-rerank.d.ts +77 -0
- package/out/proximity-rerank.d.ts.map +1 -0
- package/out/proximity-rerank.js +86 -0
- package/out/proximity-rerank.js.map +1 -0
- package/out/ranking-weights.d.ts +15 -3
- package/out/ranking-weights.d.ts.map +1 -1
- package/out/ranking-weights.js +21 -3
- package/out/ranking-weights.js.map +1 -1
- package/out/region-keys.d.ts +47 -0
- package/out/region-keys.d.ts.map +1 -0
- package/out/region-keys.js +121 -0
- package/out/region-keys.js.map +1 -0
- package/out/reverse.d.ts +6 -6
- package/out/reverse.d.ts.map +1 -1
- package/out/reverse.js +23 -35
- package/out/reverse.js.map +1 -1
- package/out/schema.d.ts +10 -1
- package/out/schema.d.ts.map +1 -1
- package/out/schema.js.map +1 -1
- package/out/search-fetch.d.ts +59 -0
- package/out/search-fetch.d.ts.map +1 -0
- package/out/search-fetch.js +184 -0
- package/out/search-fetch.js.map +1 -0
- package/out/sqlite-convention-source.d.ts +7 -7
- package/out/sqlite-convention-source.d.ts.map +1 -1
- package/out/sqlite-convention-source.js +5 -5
- package/out/sqlite-convention-source.js.map +1 -1
- package/out/sqlite-utils.d.ts +24 -6
- package/out/sqlite-utils.d.ts.map +1 -1
- package/out/sqlite-utils.js +24 -7
- package/out/sqlite-utils.js.map +1 -1
- package/out/{street-centroid-schema.d.ts → street/centroid-schema.d.ts} +12 -7
- package/out/street/centroid-schema.d.ts.map +1 -0
- package/out/{street-centroid-schema.js → street/centroid-schema.js} +5 -5
- package/out/{street-centroid-schema.js.map → street/centroid-schema.js.map} +1 -1
- package/out/{street-centroid.d.ts → street/centroid.d.ts} +6 -6
- package/out/street/centroid.d.ts.map +1 -0
- package/out/{street-centroid.js → street/centroid.js} +18 -24
- package/out/street/centroid.js.map +1 -0
- package/out/street/index.d.ts +13 -0
- package/out/street/index.d.ts.map +1 -0
- package/out/street/index.js +13 -0
- package/out/street/index.js.map +1 -0
- package/out/{street-morphology-fst-builder.d.ts → street/morphology-fst-builder.d.ts} +4 -4
- package/out/street/morphology-fst-builder.d.ts.map +1 -0
- package/out/{street-morphology-fst-builder.js → street/morphology-fst-builder.js} +18 -13
- package/out/street/morphology-fst-builder.js.map +1 -0
- package/out/{street-morphology-fst-loader.d.ts → street/morphology-fst-loader.d.ts} +5 -5
- package/out/street/morphology-fst-loader.d.ts.map +1 -0
- package/out/{street-morphology-fst-loader.js → street/morphology-fst-loader.js} +11 -10
- package/out/street/morphology-fst-loader.js.map +1 -0
- package/out/{street-name-lookup.d.ts → street/name-lookup.d.ts} +4 -7
- package/out/street/name-lookup.d.ts.map +1 -0
- package/out/{street-name-lookup.js → street/name-lookup.js} +9 -23
- package/out/street/name-lookup.js.map +1 -0
- package/out/street/normalize.d.ts +179 -0
- package/out/street/normalize.d.ts.map +1 -0
- package/out/street/normalize.js +457 -0
- package/out/street/normalize.js.map +1 -0
- package/out/{street-segment-schema.d.ts → street/segment-schema.d.ts} +13 -9
- package/out/street/segment-schema.d.ts.map +1 -0
- package/out/{street-segment-schema.js → street/segment-schema.js} +4 -4
- package/out/{street-segment-schema.js.map → street/segment-schema.js.map} +1 -1
- package/out/types.d.ts +49 -9
- package/out/types.d.ts.map +1 -1
- package/out/types.js.map +1 -1
- package/out/unified-schema.d.ts +6 -5
- package/out/unified-schema.d.ts.map +1 -1
- package/out/unified-schema.js +16 -19
- package/out/unified-schema.js.map +1 -1
- package/out/uprn/existence.d.ts +53 -0
- package/out/uprn/existence.d.ts.map +1 -0
- package/out/uprn/existence.js +61 -0
- package/out/uprn/existence.js.map +1 -0
- package/out/uprn/index.d.ts +9 -0
- package/out/uprn/index.d.ts.map +1 -0
- package/out/uprn/index.js +9 -0
- package/out/uprn/index.js.map +1 -0
- package/out/uprn/lookup.d.ts +85 -0
- package/out/uprn/lookup.d.ts.map +1 -0
- package/out/uprn/lookup.js +149 -0
- package/out/uprn/lookup.js.map +1 -0
- package/out/uprn/schema.d.ts +93 -0
- package/out/uprn/schema.d.ts.map +1 -0
- package/out/uprn/schema.js +78 -0
- package/out/uprn/schema.js.map +1 -0
- package/out/weights-overlay-linker.d.ts +299 -0
- package/out/weights-overlay-linker.d.ts.map +1 -0
- package/out/weights-overlay-linker.js +511 -0
- package/out/weights-overlay-linker.js.map +1 -0
- package/package.json +622 -154
- package/address-point.ts +0 -125
- package/candidate-lookup.ts +0 -720
- package/fst-autocomplete.ts +0 -204
- package/geo.ts +0 -121
- package/lookup.ts +0 -1354
- package/out/address-point-interpolation.d.ts.map +0 -1
- package/out/address-point-interpolation.js.map +0 -1
- package/out/address-point-schema.d.ts.map +0 -1
- package/out/address-point-schema.js.map +0 -1
- package/out/address-point.d.ts.map +0 -1
- package/out/address-point.js +0 -84
- package/out/address-point.js.map +0 -1
- package/out/ancestry-backfill.d.ts.map +0 -1
- package/out/ancestry-backfill.js.map +0 -1
- package/out/ancestry.d.ts.map +0 -1
- package/out/ancestry.js.map +0 -1
- package/out/convention.d.ts.map +0 -1
- package/out/convention.js.map +0 -1
- package/out/fst-autocomplete.d.ts.map +0 -1
- package/out/fst-autocomplete.js +0 -130
- package/out/fst-autocomplete.js.map +0 -1
- package/out/fst-builder.d.ts.map +0 -1
- package/out/fst-builder.js.map +0 -1
- package/out/fst-deserialize-web.d.ts.map +0 -1
- package/out/fst-deserialize-web.js.map +0 -1
- package/out/fst-freshness.d.ts.map +0 -1
- package/out/fst-freshness.js.map +0 -1
- package/out/fst-matcher.d.ts.map +0 -1
- package/out/fst-matcher.js.map +0 -1
- package/out/fst-serialize.d.ts.map +0 -1
- package/out/fst-serialize.js.map +0 -1
- package/out/fst-types.d.ts.map +0 -1
- package/out/fst-types.js.map +0 -1
- package/out/fts-query.d.ts.map +0 -1
- package/out/fts-query.js.map +0 -1
- package/out/fts.d.ts.map +0 -1
- package/out/fts.js.map +0 -1
- package/out/geo.d.ts +0 -74
- package/out/geo.d.ts.map +0 -1
- package/out/geo.js +0 -71
- package/out/geo.js.map +0 -1
- package/out/geonames-aliases.d.ts.map +0 -1
- package/out/geonames-aliases.js.map +0 -1
- package/out/geonames-postal.d.ts.map +0 -1
- package/out/geonames-postal.js.map +0 -1
- package/out/poi-lookup.d.ts.map +0 -1
- package/out/poi-lookup.js.map +0 -1
- package/out/poi-schema.d.ts.map +0 -1
- package/out/poi-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-candidate-schema.d.ts.map +0 -1
- package/out/sharding.d.ts +0 -114
- package/out/sharding.d.ts.map +0 -1
- package/out/sharding.js.map +0 -1
- package/out/street-centroid-schema.d.ts.map +0 -1
- package/out/street-centroid.d.ts.map +0 -1
- package/out/street-centroid.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 -95
- package/out/street-normalize.d.ts.map +0 -1
- package/out/street-normalize.js +0 -272
- package/out/street-normalize.js.map +0 -1
- package/out/street-segment-schema.d.ts.map +0 -1
- package/sqlite-utils.ts +0 -46
- package/street-normalize.ts +0 -318
- /package/{postal-city-alias-schema.ts → lib/postal/city-alias-schema.ts} +0 -0
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
* manifest (tier `shipped`, spine `h3` res 9) and per-res-6-cell coverage.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import type { DatabaseSync } from "node:sqlite"
|
|
16
|
-
|
|
17
15
|
import type { LayerContractDatabase } from "@mailwoman/core/layers"
|
|
16
|
+
import type { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
18
17
|
import { sql, type Kysely } from "kysely"
|
|
19
18
|
|
|
19
|
+
import type { NameKey } from "#street/normalize"
|
|
20
|
+
|
|
20
21
|
/**
|
|
21
22
|
* One POI row. Clustered PK: h3_cell → category_id → neg_rank → rowid_key.
|
|
22
23
|
*/
|
|
@@ -39,9 +40,12 @@ export interface POITable {
|
|
|
39
40
|
rowid_key: number
|
|
40
41
|
name: string | null
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
+
* Probe key for exact name lookups, minted by {@link normalizeLocalityForKey} at build AND at query.
|
|
44
|
+
*
|
|
45
|
+
* Branded because a `toLowerCase()` approximation of the fold is still a `string`: it binds to the parameter, returns
|
|
46
|
+
* fewer rows, and the shortfall reads as a coverage gap in the data rather than a defect in the probe.
|
|
43
47
|
*/
|
|
44
|
-
name_key:
|
|
48
|
+
name_key: NameKey | null
|
|
45
49
|
brand_wikidata: string | null
|
|
46
50
|
latitude: number
|
|
47
51
|
longitude: number
|
|
@@ -69,7 +73,7 @@ export interface POIStageTable {
|
|
|
69
73
|
neg_rank: number | null
|
|
70
74
|
rowid_key: number | null
|
|
71
75
|
name: string | null
|
|
72
|
-
name_key:
|
|
76
|
+
name_key: NameKey | null
|
|
73
77
|
brand_wikidata: string | null
|
|
74
78
|
latitude: number
|
|
75
79
|
longitude: number
|
|
@@ -187,7 +191,7 @@ export const POI_FTS_TABLE = "poi_search"
|
|
|
187
191
|
/**
|
|
188
192
|
* FTS5 stays raw SQL by project rule (Kysely can't express virtual tables). Content-keyed by name_key.
|
|
189
193
|
*/
|
|
190
|
-
export function createPOISearchFTS(db:
|
|
194
|
+
export function createPOISearchFTS<DB>(db: DatabaseClient<DB>): void {
|
|
191
195
|
db.exec(
|
|
192
196
|
`CREATE VIRTUAL TABLE ${POI_FTS_TABLE} USING fts5(name, name_key UNINDEXED, h3_cell UNINDEXED, tokenize = 'unicode61')`
|
|
193
197
|
)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Typed schema for the polygon sidecar (`wof-polygons.db`) — the one table `WOFReverseGeocoder` probes for a
|
|
7
|
+
* place's geometry. The interface is the read/write contract and {@link createPolygonsTable} creates the table, so a
|
|
8
|
+
* column added to one is a compile error against the other.
|
|
9
|
+
*
|
|
10
|
+
* The sidecar is OPTIONAL to the reverse geocoder: without it every result falls back to a centroid, so the reader
|
|
11
|
+
* checks for the table's presence rather than assuming it.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { Kysely } from "kysely"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* One admin polygon, keyed by WOF id.
|
|
18
|
+
*/
|
|
19
|
+
export interface PolygonsTable {
|
|
20
|
+
id: number
|
|
21
|
+
/**
|
|
22
|
+
* The GeoJSON geometry, JSON-encoded. A row that fails to parse reads as no-polygon, never as an error — a malformed
|
|
23
|
+
* geometry must not fail the whole reverse query.
|
|
24
|
+
*/
|
|
25
|
+
geom: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface PolygonDatabase {
|
|
29
|
+
polygons: PolygonsTable
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The slice of a Kysely handle the polygon DDL touches. Kysely is invariant in its schema parameter, so naming only
|
|
34
|
+
* `schema` lets a builder holding a wider handle pass it without a cast.
|
|
35
|
+
*/
|
|
36
|
+
export type PolygonSchemaHandle = Pick<Kysely<PolygonDatabase>, "schema">
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create the `polygons` table — called before the streaming bulk load.
|
|
40
|
+
*/
|
|
41
|
+
export async function createPolygonsTable(db: PolygonSchemaHandle): Promise<void> {
|
|
42
|
+
await db.schema
|
|
43
|
+
.createTable("polygons")
|
|
44
|
+
.addColumn("id", "integer", (column) => column.primaryKey())
|
|
45
|
+
.addColumn("geom", "text", (column) => column.notNull())
|
|
46
|
+
.execute()
|
|
47
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Node reader over the POSTAL-CITY ALIAS table (`postal-city-alias-<cc>.db`) — the observed
|
|
7
7
|
* `postal_city → geo_locality` aliases per postcode (`build-postal-city-alias.ts`). Consumed by
|
|
8
|
-
* {@link
|
|
8
|
+
* {@link WOFSQLitePlaceLookup}'s coordinate-first locality scorer: a user-typed postal city
|
|
9
9
|
* ("Antioch", postcode 37013) becomes a name-match alias for the geographic locality the postcode
|
|
10
10
|
* actually sits in ("Nashville"), so the right place tiers to the top instead of a same-named
|
|
11
11
|
* town in another state. Opt-in — the lookup is only constructed when a path is supplied, and
|
|
@@ -16,11 +16,9 @@
|
|
|
16
16
|
* uses), keeping one normalizer in one place.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
20
20
|
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
import type { PostalCityAliasDatabase } from "./postal-city-alias-schema.ts"
|
|
21
|
+
import type { PostalCityAliasDatabase } from "#postal/city-alias-schema"
|
|
24
22
|
|
|
25
23
|
export interface WOFPostalCityAliasLookupOpts {
|
|
26
24
|
/**
|
|
@@ -30,7 +28,7 @@ export interface WOFPostalCityAliasLookupOpts {
|
|
|
30
28
|
/**
|
|
31
29
|
* Pre-opened handle (tests / shared connections). Mutually exclusive with `databasePath`.
|
|
32
30
|
*/
|
|
33
|
-
database?:
|
|
31
|
+
database?: DatabaseClient<PostalCityAliasDatabase>
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
/**
|
|
@@ -56,24 +54,22 @@ export interface PostalCityAlias {
|
|
|
56
54
|
* differs from the geographic name — the rows that carry alias signal), issued via the typed Kysely query builder
|
|
57
55
|
* against {@link PostalCityAliasDatabase}.
|
|
58
56
|
*/
|
|
59
|
-
export class WOFPostalCityAliasLookup {
|
|
60
|
-
#db:
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
export class WOFPostalCityAliasLookup implements Disposable {
|
|
58
|
+
#db: DatabaseClient<PostalCityAliasDatabase>
|
|
59
|
+
/**
|
|
60
|
+
* Resources this instance opened. A connection handed in by a caller is NOT in here, so disposal cannot reach it —
|
|
61
|
+
* ownership is membership rather than a flag a later branch has to check.
|
|
62
|
+
*/
|
|
63
|
+
readonly #resources = new DisposableStack()
|
|
63
64
|
|
|
64
65
|
constructor(opts: WOFPostalCityAliasLookupOpts) {
|
|
65
66
|
if (opts.database) {
|
|
66
67
|
this.#db = opts.database
|
|
67
|
-
this.#ownsDB = false
|
|
68
68
|
} else if (opts.databasePath) {
|
|
69
|
-
this.#db = new
|
|
70
|
-
this.#ownsDB = true
|
|
69
|
+
this.#db = this.#resources.use(new DatabaseClient<PostalCityAliasDatabase>(opts.databasePath, { readOnly: true }))
|
|
71
70
|
} else {
|
|
72
71
|
throw new Error("WOFPostalCityAliasLookup needs `databasePath` or `database`")
|
|
73
72
|
}
|
|
74
|
-
|
|
75
|
-
// `#kdb` wraps `#db` for the typed query; close() owns the raw handle directly (sync).
|
|
76
|
-
this.#kdb = new DatabaseClient<PostalCityAliasDatabase>({ database: this.#db })
|
|
77
73
|
}
|
|
78
74
|
|
|
79
75
|
/**
|
|
@@ -85,7 +81,7 @@ export class WOFPostalCityAliasLookup {
|
|
|
85
81
|
|
|
86
82
|
if (!pc) return []
|
|
87
83
|
|
|
88
|
-
const rows = await this.#
|
|
84
|
+
const rows = await this.#db
|
|
89
85
|
.selectFrom("postal_city_alias")
|
|
90
86
|
.select(["postal_city", "geo_locality", "n"])
|
|
91
87
|
.where("postcode", "=", pc)
|
|
@@ -95,9 +91,7 @@ export class WOFPostalCityAliasLookup {
|
|
|
95
91
|
return rows.map((r) => ({ postalCity: String(r.postal_city), geoLocality: String(r.geo_locality), n: Number(r.n) }))
|
|
96
92
|
}
|
|
97
93
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.#db.close()
|
|
101
|
-
}
|
|
94
|
+
[Symbol.dispose](): void {
|
|
95
|
+
this.#resources[Symbol.dispose]()
|
|
102
96
|
}
|
|
103
97
|
}
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
|
|
21
21
|
import { sql, type Kysely } from "kysely"
|
|
22
22
|
|
|
23
|
+
import type { NameKey } from "#street/normalize"
|
|
24
|
+
|
|
23
25
|
/**
|
|
24
26
|
* One postal-city → geo-locality edge, keyed exactly by `(name_key, postcode)`. The probe returns the geographic
|
|
25
27
|
* locality directly; the denormalized name/coord avoid a join back to `candidate`.
|
|
@@ -28,7 +30,7 @@ export interface PostalCityCandidateTable {
|
|
|
28
30
|
/**
|
|
29
31
|
* {@link normalizeLocalityForKey} of the postal-city name — the build/query-consistent probe key.
|
|
30
32
|
*/
|
|
31
|
-
name_key:
|
|
33
|
+
name_key: NameKey
|
|
32
34
|
/**
|
|
33
35
|
* The postcode the alias is scoped to (the second half of the exact key).
|
|
34
36
|
*/
|
|
@@ -53,7 +55,7 @@ export interface PostalCityCandidateDatabase {
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
/**
|
|
56
|
-
* The table name the lookup probes (existence-
|
|
58
|
+
* The table name the lookup probes (existence-restricted, so an old candidate.db without it is byte-stable).
|
|
57
59
|
*/
|
|
58
60
|
export const POSTAL_CITY_CANDIDATE_TABLE = "postal_city_candidate"
|
|
59
61
|
|
|
@@ -4,22 +4,24 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
6
|
* SQLite-backed postcode lookup for the postcode anchor (#240). A thin exact-match resolver over
|
|
7
|
-
* one or more `postalcode-*.db`
|
|
7
|
+
* one or more `postalcode-*.db` extracts (the `spr` schema built by `build-unified-wof --placetypes
|
|
8
8
|
* postalcode`, then centroid-backfilled by `scripts/backfill-postcode-centroids.ts`).
|
|
9
9
|
*
|
|
10
10
|
* This is the production implementation of the `PostcodeResolver` interface consumed by
|
|
11
11
|
* `@mailwoman/neural`'s `extractPostcodeAnchors`. It is deliberately dumb: an indexed exact-match
|
|
12
|
-
* on the postcode string across every
|
|
12
|
+
* on the postcode string across every extract, unioned. No FTS, no ranking, no proximity — the
|
|
13
13
|
* anchor only needs "does this string exist as a postcode, in which countries, near where". A
|
|
14
|
-
* future WASM build swaps this for an FST-backed resolver behind the same `lookup()`
|
|
14
|
+
* future WASM build swaps this for an FST-backed resolver behind the same `lookup()` interface.
|
|
15
15
|
*
|
|
16
|
-
* Why multiple
|
|
17
|
-
* query to ONE
|
|
18
|
-
* single query could only ever hit one country's
|
|
19
|
-
* countries to build its country posterior, so it queries each
|
|
16
|
+
* Why multiple extracts instead of the multi-extract `WOFSQLitePlaceLookup`: that resolver routes a
|
|
17
|
+
* query to ONE extract by placetype, but every postcode extract shares `placetype='postalcode'`, so a
|
|
18
|
+
* single query could only ever hit one country's extract. The anchor needs the union across
|
|
19
|
+
* countries to build its country posterior, so it queries each extract directly.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import {
|
|
22
|
+
import { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
23
|
+
|
|
24
|
+
import type { WOFDatabase } from "#schema"
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* A gazetteer hit. `lat`/`lon` of 0 means the postcode is known but has no centroid (no admin parent).
|
|
@@ -34,19 +36,19 @@ const LOOKUP_SQL =
|
|
|
34
36
|
"SELECT country, latitude AS lat, longitude AS lon FROM spr WHERE name = ? AND placetype = 'postalcode' AND is_current != 0"
|
|
35
37
|
|
|
36
38
|
export class WOFPostcodeLookup {
|
|
37
|
-
readonly #dbs:
|
|
38
|
-
readonly #stmts: ReturnType<
|
|
39
|
+
readonly #dbs: DatabaseClient<WOFDatabase>[]
|
|
40
|
+
readonly #stmts: ReturnType<DatabaseClient["prepare"]>[]
|
|
39
41
|
|
|
40
42
|
/**
|
|
41
|
-
* Open each
|
|
43
|
+
* Open each extract read-only and prepare its exact-match statement.
|
|
42
44
|
*/
|
|
43
45
|
constructor(dbPaths: readonly string[]) {
|
|
44
|
-
this.#dbs = dbPaths.map((p) => new
|
|
46
|
+
this.#dbs = dbPaths.map((p) => new DatabaseClient<WOFDatabase>(p, { readOnly: true }))
|
|
45
47
|
this.#stmts = this.#dbs.map((db) => db.prepare(LOOKUP_SQL))
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
|
-
* Exact-match the postcode across every
|
|
51
|
+
* Exact-match the postcode across every extract and union the rows.
|
|
50
52
|
*/
|
|
51
53
|
lookup(postcode: string): PostcodePlace[] {
|
|
52
54
|
const out: PostcodePlace[] = []
|
|
@@ -60,9 +62,9 @@ export class WOFPostcodeLookup {
|
|
|
60
62
|
return out
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
|
|
65
|
+
[Symbol.dispose](): void {
|
|
64
66
|
for (const db of this.#dbs) {
|
|
65
|
-
db.
|
|
67
|
+
db.destroy()
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Bounded cross-country PRIMARY-NAME preference over a population-ordered candidate row set — the
|
|
7
|
+
* `is_primary` ranking signal, PURE and platform-free so the Node candidate lookup
|
|
8
|
+
* (`candidate-lookup.ts`) and the browser twin (`docs/src/shared/httpvfs-resolver.ts`) rank with the
|
|
9
|
+
* SAME function rather than two copies that drift (the #861 server↔demo parity contract).
|
|
10
|
+
*
|
|
11
|
+
* Only type imports and arithmetic live here: anything with a `node:` import stays out.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { CandidateTable } from "#candidate-schema"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The row shape the re-rank needs. `is_primary` is optional: a reader over an artifact vintage that predates the column
|
|
18
|
+
* omits it from the SELECT, no row reads as primary, and the re-rank no-ops by construction — the exact degradation the
|
|
19
|
+
* browser reader's vintage guard relies on.
|
|
20
|
+
*/
|
|
21
|
+
export type PrimaryPreferenceRow = Pick<CandidateTable, "neg_rank" | "country_id"> &
|
|
22
|
+
Partial<Pick<CandidateTable, "is_primary" | "placetype_id" | "population" | "name_role">>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Bounded PRIMARY-NAME preference across a CROSS-COUNTRY name collision (the `is_primary` ranking signal).
|
|
26
|
+
*
|
|
27
|
+
* The raw candidate order is population-first (`neg_rank ASC`) and treats an ALIAS row (a place's alt-name / exonym,
|
|
28
|
+
* `is_primary=0`) and a PRIMARY-name row (`is_primary=1`) on equal footing. So a foreign place whose transliterated
|
|
29
|
+
* exonym coincidentally normalizes to a query — Changchun CN stores the Turkish exonym "Çançun" (`name_key="cancun"`),
|
|
30
|
+
* 4.19 M pop — outranks the PRIMARY-name place the query actually means (Cancún MX, 0.89 M pop). This penalty makes a
|
|
31
|
+
* same-key alias have to clear a population MARGIN over a foreign primary before it wins.
|
|
32
|
+
*
|
|
33
|
+
* It is deliberately NOT a dominant sort key (no `ORDER BY is_primary DESC`, which would make every primary outrank
|
|
34
|
+
* every alias and break the alt-names users depend on — "NYC"→New York, "LA"→Los Angeles, "Frisco"→San Francisco). Two
|
|
35
|
+
* bounds keep it a soft prior:
|
|
36
|
+
*
|
|
37
|
+
* 1. **Cross-country only.** The penalty applies to an alias ONLY when the top-population primary sharing the key is in a
|
|
38
|
+
* DIFFERENT country. A SAME-country nickname contest (San Francisco's alias "Frisco" vs the primary Frisco, TX —
|
|
39
|
+
* both US) is left on pure population, so the legitimate alias still wins.
|
|
40
|
+
* 2. **Population-bounded.** The penalty is {@link PRIMARY_PREFERENCE_LOG10} in log10-population units — an alias must be
|
|
41
|
+
* at least 10x more populous than the foreign primary to still win. So a genuinely dominant alias keeps winning
|
|
42
|
+
* ("Los Angeles" over La, Ghana — gap 1.6; "Las Vegas" over Vegas, Cuba — gap 2.4) while a near-tie coincidental
|
|
43
|
+
* collision defers to the primary (Cancún over Changchun — gap 0.7).
|
|
44
|
+
*/
|
|
45
|
+
export const PRIMARY_PREFERENCE_LOG10 = 1
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The placetype the seat preference promotes: the populated-place tier a district duplicate shares its name and its
|
|
49
|
+
* population with. Named rather than inlined because narrowing the term to this ONE tier is what keeps it off the
|
|
50
|
+
* region/county and locality/neighbourhood contests — see `rankByPrimaryPreference` for the measurement.
|
|
51
|
+
*/
|
|
52
|
+
const SEAT_PLACETYPE = "locality"
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Over-fetch cap for {@link rankByPrimaryPreference}: the candidate rows for one `name_key` (all same-name places
|
|
56
|
+
* worldwide) are re-ranked in-process, so the probe fetches this many (population-ordered) before the re-rank rather
|
|
57
|
+
* than the caller's small `limit`, ensuring the intended primary isn't pushed below the fold by a cluster of
|
|
58
|
+
* more-populous foreign aliases. Bounded and small — a single contiguous B-tree scan.
|
|
59
|
+
*/
|
|
60
|
+
export const RERANK_FETCH = 64
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A candidate row annotated with the {@link rankByPrimaryPreference} effective rank + the exact-tier demotion flag.
|
|
64
|
+
*/
|
|
65
|
+
export type RankedRow<R> = R & {
|
|
66
|
+
/**
|
|
67
|
+
* `neg_rank` plus the bounded cross-country alias penalty — the value the row is ORDERED by, and the base the emitted
|
|
68
|
+
* `prominence` is derived from (so the resolver walk's `prominence ?? score` sort, `resolve.ts`, agrees with this
|
|
69
|
+
* order; the raw `score`/`neg_rank` is left intact for the walk's `minWinningScore` floor).
|
|
70
|
+
*/
|
|
71
|
+
effectiveNegRank: number
|
|
72
|
+
/**
|
|
73
|
+
* True when this row is a cross-country alias that LOST the bounded population contest to the same-key primary — a
|
|
74
|
+
* coincidental foreign exonym (Changchun's "Çançun" for "Cancun"). Such a row is dropped out of the exact-match tier
|
|
75
|
+
* (`exactMatch=false`) so the resolver walk's country pin — the model's `anchorPosterior`, which "never crosses the
|
|
76
|
+
* exact/partial boundary" (`resolve.ts`) — can't ride a spurious posterior (CN 0.86 for "Cancun") back over the
|
|
77
|
+
* primary. Only the LOSING foreign alias is demoted; a dominant alias (Los Angeles over La, Ghana) keeps its exact
|
|
78
|
+
* tier, and a same-country nickname (San Francisco's "Frisco") is never touched.
|
|
79
|
+
*/
|
|
80
|
+
demoted: boolean
|
|
81
|
+
/**
|
|
82
|
+
* True when this row came from the TYPO-CORRECTOR tier — the FTS5-trigram fallback that fires only after the exact
|
|
83
|
+
* and qualifier-strip probes both missed. Such a row answers a query the gazetteer does not contain, so it is a fuzzy
|
|
84
|
+
* match by construction and must not claim `exactMatch` (#17). Recall is unaffected: the row is still returned, still
|
|
85
|
+
* ranked, still resolvable — it just stops asserting a match quality it does not have, which is what the FTS backend
|
|
86
|
+
* has always done and what every `exactMatch`-filtering consumer assumed.
|
|
87
|
+
*/
|
|
88
|
+
fuzzy?: boolean
|
|
89
|
+
/**
|
|
90
|
+
* The admin-containment verdict (#1717 stage 2), stamped by `candidate-lookup.ts` when the query carried a
|
|
91
|
+
* `regionQualifier` and the artifact carries the ancestors sidecar — the `fuzzy` precedent: a lookup-tier annotation
|
|
92
|
+
* declared on the shared row shape. Tri-state like `ResolvedPlace.containedByQualifier`: absent means the question
|
|
93
|
+
* was never asked, never "not contained".
|
|
94
|
+
*/
|
|
95
|
+
containedByQualifier?: boolean
|
|
96
|
+
/**
|
|
97
|
+
* The #1882 exemption's firing mark (#1893): this row would have taken the cross-country alias penalty and
|
|
98
|
+
* `exemptVariantAliases` prevented it. PRESENT only when the exemption changed this row's treatment; absent on every
|
|
99
|
+
* row it merely inspected — an in-country variant, a primary, a set with no foreign top primary. The winner-level
|
|
100
|
+
* receipt downstream (`mechanism_fired_on.variant_alias_exemption`) counts this mark only when it survives onto the
|
|
101
|
+
* selected candidate.
|
|
102
|
+
*/
|
|
103
|
+
variantExempted?: true
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Bounded cross-country primary-name preference (see {@link PRIMARY_PREFERENCE_LOG10}). Pure + total-ordered so
|
|
108
|
+
* `candidate-lookup.test.ts` can exercise it on synthetic rows. `rows` arrive population-ordered (`neg_rank ASC`); an
|
|
109
|
+
* alias (`is_primary=0`) is pushed back by `delta` in log10-population units ONLY when the top-population primary
|
|
110
|
+
* sharing the key is in a different country, and is `demoted` out of the exact tier when that penalty leaves it BEHIND
|
|
111
|
+
* the primary. Returns the top `limit` after the re-rank, each annotated.
|
|
112
|
+
*
|
|
113
|
+
* `placetypes` (the artifact's own `placetype_codes` map) enables the LAST tiebreak, the SEAT preference: when
|
|
114
|
+
* `effectiveNegRank` and raw `neg_rank` both tie — two same-key rows population cannot separate at all — a
|
|
115
|
+
* {@link SEAT_PLACETYPE} row carrying a real population outranks every other placetype. Omit the map and every row
|
|
116
|
+
* scores 0, the term cancels, and the order is exactly the population-then-scan-order it was before.
|
|
117
|
+
*
|
|
118
|
+
* The tie it exists for is a DUPLICATE, not a contest. A district and its identically-named seat town are stored as two
|
|
119
|
+
* rows carrying the SAME population, so `neg_rank` is equal to the bit and `referential` follows it
|
|
120
|
+
* (`referentialFromPopulation` is a pure function of population). Turkey's `Of` is the measured case — locality
|
|
121
|
+
* 8114738869649 and its parent county 8837168432019 both hold population 44212 — and 358 locality/parent-county pairs
|
|
122
|
+
* across 15 countries share the shape in `admin-global-priority.db` (TR 162, CA 77, US 47, HR 24, DO 14). Without the
|
|
123
|
+
* term their order is whatever the scan hands the sorter.
|
|
124
|
+
*
|
|
125
|
+
* WHERE THE TERM DECIDES, AND WHERE IT CANNOT (#1729). It binds inside `findPlace`, so it orders every row set that
|
|
126
|
+
* actually CONTAINS the tie — but the resolver walk's probes all carry a placetype filter, and
|
|
127
|
+
* `PLACETYPE_FILTER_GROUPS` (core/resolver) never mixes `locality` with `county`: the `Of`-shape locality/county pair
|
|
128
|
+
* is PARTITIONED before this ranker runs, the locality probe fetches one row, and the walk's own `locality` request
|
|
129
|
+
* selects the seat by construction — the same winner, decided upstream. The tie that reaches an end-to-end answer
|
|
130
|
+
* through this term is the IN-GROUP residue: a locality/localadmin (or borough) duplicate whose `importance` values
|
|
131
|
+
* also tie. Downstream the resolver re-sorts by importance (`resolver/toponym-prior.ts`) but is stable on equal keys,
|
|
132
|
+
* so the order stamped here is the order that answers — inverting this term moves bare `Pu-cheng-hsien` 1,100 km
|
|
133
|
+
* (locality Pucheng over the 浦城县 localadmin, identical population and importance). Where importance separates the pair,
|
|
134
|
+
* the fame prior overrides by design; a probe with NO placetype filter (the browser cascade's last resort, the dev
|
|
135
|
+
* lookup tools) presents the full tie and this term is all that breaks it.
|
|
136
|
+
*
|
|
137
|
+
* BOTH CONDITIONS ARE required, and a plain "finer placetype wins" measured wrong before this shape was settled: it
|
|
138
|
+
* moved the top slot on 11,377 keys in `candidate.db`, of which only 722 were the seat/district duplicate. The rest
|
|
139
|
+
* were contests between genuinely distinct places that merely tie — 2,885 `locality → neighbourhood` (a bare city name
|
|
140
|
+
* losing to a same-named hood), 2,973 `region → county`, 2,662 `postalcode → locality` — and 7,179 of the 11,377 sat at
|
|
141
|
+
* population 0, where a tie means NO EVIDENCE rather than equal evidence. Requiring a real population keeps the term
|
|
142
|
+
* off every no-evidence tie; promoting the populated-place tier specifically, rather than whatever is finer, keeps it
|
|
143
|
+
* off the admin-tier and hood contests. It can never reach a pair population separates: it does not override a
|
|
144
|
+
* population gap, it replaces an undetermined order with a stated one.
|
|
145
|
+
*/
|
|
146
|
+
export function rankByPrimaryPreference<R extends PrimaryPreferenceRow>(
|
|
147
|
+
rows: readonly R[],
|
|
148
|
+
limit: number,
|
|
149
|
+
delta = PRIMARY_PREFERENCE_LOG10,
|
|
150
|
+
placetypes?: ReadonlyMap<number, string>,
|
|
151
|
+
exemptVariantAliases = false
|
|
152
|
+
): Array<RankedRow<R>> {
|
|
153
|
+
// The primary the alias actually competes with for the top slot: highest population (min neg_rank). Undefined
|
|
154
|
+
// when the set has no primary → nothing to prefer, penalty is 0, order stays population-first (today's behavior).
|
|
155
|
+
let topPrimary: R | undefined
|
|
156
|
+
|
|
157
|
+
for (const r of rows) {
|
|
158
|
+
if (r.is_primary === 1 && (topPrimary == null || r.neg_rank < topPrimary.neg_rank)) {
|
|
159
|
+
topPrimary = r
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const topCountry = topPrimary?.country_id
|
|
164
|
+
|
|
165
|
+
// A cross-country alias (different country than the top primary) is penalized; it is DEMOTED when even after — i.e.
|
|
166
|
+
// the penalty leaves its effective rank behind the primary's raw rank (it lost the bounded population contest).
|
|
167
|
+
//
|
|
168
|
+
// #1882 exemption (opt-in): a `name_role = 'variant'` alias is the holder's OWN primary name in another
|
|
169
|
+
// orthography (`Брэст` → `brest`, `George Town` → `georgetown` — the build's own-name detector), so the
|
|
170
|
+
// query is naming THAT place, not colliding with it; the penalty exists for the coincidental-collision
|
|
171
|
+
// class ("Çançun"/`cancun`), which the detector's measured threshold keeps un-stamped. An artifact
|
|
172
|
+
// predating the role column carries no 'variant' rows, so the flag no-ops there by construction.
|
|
173
|
+
const wouldPenalize = (r: R): boolean =>
|
|
174
|
+
typeof topCountry === "number" && r.is_primary !== 1 && r.country_id !== topCountry
|
|
175
|
+
|
|
176
|
+
const isCrossCountryAlias = (r: R): boolean =>
|
|
177
|
+
wouldPenalize(r) && !(exemptVariantAliases && r.name_role === "variant")
|
|
178
|
+
|
|
179
|
+
const annotate = (r: R): RankedRow<R> => {
|
|
180
|
+
const penalized = isCrossCountryAlias(r)
|
|
181
|
+
const effectiveNegRank = r.neg_rank + (penalized ? delta : 0)
|
|
182
|
+
|
|
183
|
+
// The firing mark (#1893): this row WOULD have taken the cross-country penalty and the exemption
|
|
184
|
+
// prevented it — conditions the winner-level receipt needs, computed where the decision is made. A
|
|
185
|
+
// variant row that was in-country, primary, or keyed under a set with no foreign primary never
|
|
186
|
+
// fired, and stays unmarked.
|
|
187
|
+
const exempted = !penalized && exemptVariantAliases && r.name_role === "variant" && wouldPenalize(r)
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
...r,
|
|
191
|
+
effectiveNegRank,
|
|
192
|
+
demoted: penalized && effectiveNegRank > topPrimary!.neg_rank,
|
|
193
|
+
...(exempted ? { variantExempted: true as const } : {}),
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// 1 for a populated-place row that can BE a district's seat, 0 for everything else — no code map, no
|
|
198
|
+
// placetype on the row, an id the map does not carry, a placetype that is not the seat tier, or no
|
|
199
|
+
// recorded population. Every row scoring 0 cancels the term, leaving exactly the
|
|
200
|
+
// population-then-scan-order the sort had before it existed.
|
|
201
|
+
const seatPreference = (r: R): number =>
|
|
202
|
+
placetypes != null &&
|
|
203
|
+
typeof r.placetype_id === "number" &&
|
|
204
|
+
typeof r.population === "number" &&
|
|
205
|
+
r.population > 0 &&
|
|
206
|
+
placetypes.get(r.placetype_id) === SEAT_PLACETYPE
|
|
207
|
+
? 1
|
|
208
|
+
: 0
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
rows
|
|
212
|
+
.map((r, i) => ({ row: annotate(r), i }))
|
|
213
|
+
// Effective rank ASC; ties keep population order, then the seat preference DESC, then original
|
|
214
|
+
// index (stable).
|
|
215
|
+
// oxlint-disable-next-line unicorn/no-array-sort -- sorts a freshly-built array; toSorted would double-allocate on a hot path
|
|
216
|
+
.sort(
|
|
217
|
+
(a, b) =>
|
|
218
|
+
a.row.effectiveNegRank - b.row.effectiveNegRank ||
|
|
219
|
+
a.row.neg_rank - b.row.neg_rank ||
|
|
220
|
+
seatPreference(b.row) - seatPreference(a.row) ||
|
|
221
|
+
a.i - b.i
|
|
222
|
+
)
|
|
223
|
+
.slice(0, limit)
|
|
224
|
+
.map((x) => x.row)
|
|
225
|
+
)
|
|
226
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The proximity re-rank (#938): with bias hints — the demo's map viewport, a user location — re-order exact-match
|
|
7
|
+
* candidates by population and nearness on one additive scale, so an in-view namesake wins a tie without a hard
|
|
8
|
+
* filter. Byte-identical to plain population order when no bias is passed.
|
|
9
|
+
*
|
|
10
|
+
* This lives in its own platform-free module because it has to run identically in two places: the Node candidate
|
|
11
|
+
* reader and the browser byte-range twin. That is the #861 server↔demo parity contract and the second thing
|
|
12
|
+
* here held by construction rather than by comment (`primary-preference.ts` was the first). Constants alone were not
|
|
13
|
+
* enough — the two copies agreed on every literal and still diverged on which field the population term reads and on
|
|
14
|
+
* whether the combined value is written back, which is the half that actually decides the answer.
|
|
15
|
+
*
|
|
16
|
+
* Two properties are required and easy to lose when transcribing:
|
|
17
|
+
*
|
|
18
|
+
* 1. The population base is `prominence ?? score`, NOT `score`. `prominence` carries the bounded cross-country
|
|
19
|
+
* primary preference, so reading raw score lets a coincidental foreign alias ride population back over a primary
|
|
20
|
+
* whenever a viewport hint happens to be present.
|
|
21
|
+
* 2. The combined value is PERSISTED into `prominence`. The resolver walk re-sorts by `prominence ?? score`, so a
|
|
22
|
+
* caller that only returns the array in bias order has its ordering silently discarded downstream.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { haversineKm } from "@mailwoman/spatial"
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Full magnitude of the nearness term at distance 0, before decay.
|
|
29
|
+
*/
|
|
30
|
+
export const BIAS_BOOST = 4
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Full magnitude of the population term, reached at {@link POP_SCALE_LOG10} and capped there.
|
|
34
|
+
*/
|
|
35
|
+
export const POP_BOOST = 4
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* `log10(population + 1)` at which the population term saturates — 6 means a population of one million earns the whole
|
|
39
|
+
* {@link POP_BOOST}, and larger populations earn no more.
|
|
40
|
+
*/
|
|
41
|
+
export const POP_SCALE_LOG10 = 6
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Distance at which the nearness term halves.
|
|
45
|
+
*
|
|
46
|
+
* SHARPER than the FTS reader's 100 km on purpose: the candidate backend's score is log-population ALONE, with no bm25
|
|
47
|
+
* document term, so the population signal is weaker relative to the bias and a gentle 100 km decay let a 230 km-distant
|
|
48
|
+
* alias-exact township ("Paris Township", OH) edge out a global city ("Paris", FR) from a nearby view. At ~30 km the
|
|
49
|
+
* boost reaches only candidates the user is actually looking at: an in-view namesake still wins (Dublin, OH from an
|
|
50
|
+
* Ohio view), a distant one no longer does (Paris stays FR from a Michigan view).
|
|
51
|
+
*/
|
|
52
|
+
export const PROX_SCALE_KM = 30
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* One bias hint — a coordinate the user is looking at or standing on, optionally weighted.
|
|
56
|
+
*/
|
|
57
|
+
export interface ProximityBias {
|
|
58
|
+
lat: number
|
|
59
|
+
lon: number
|
|
60
|
+
weight?: number
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The candidate fields the re-rank reads and writes. Structural rather than a concrete candidate type, so the Node
|
|
65
|
+
* reader's `PlaceCandidate` and the browser twin's row shape both satisfy it without an adapter.
|
|
66
|
+
*/
|
|
67
|
+
export interface ProximityRerankable {
|
|
68
|
+
lat: number
|
|
69
|
+
lon: number
|
|
70
|
+
score: number
|
|
71
|
+
prominence?: number
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Population plus nearness on one additive scale. Exported for tests and for a caller that wants the value without the
|
|
76
|
+
* sort; ordinary callers want {@link applyProximityRerank}.
|
|
77
|
+
*/
|
|
78
|
+
export function combinedProminence(candidate: ProximityRerankable, bias: readonly ProximityBias[]): number {
|
|
79
|
+
const popBase = candidate.prominence ?? candidate.score
|
|
80
|
+
const popTerm = POP_BOOST * Math.min(1, Math.max(0, popBase) / POP_SCALE_LOG10)
|
|
81
|
+
let proxTerm = 0
|
|
82
|
+
|
|
83
|
+
// A candidate at the null island has no coordinate, not a coordinate at 0,0 — it earns no nearness term rather
|
|
84
|
+
// than an enormous one.
|
|
85
|
+
if (!(candidate.lat === 0 && candidate.lon === 0)) {
|
|
86
|
+
for (const b of bias) {
|
|
87
|
+
const d = haversineKm(b.lat, b.lon, candidate.lat, candidate.lon)
|
|
88
|
+
const term = (BIAS_BOOST * (b.weight ?? 1)) / (1 + d / PROX_SCALE_KM)
|
|
89
|
+
|
|
90
|
+
if (term > proxTerm) {
|
|
91
|
+
proxTerm = term
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return popTerm + proxTerm
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Re-order `candidates` in place by {@link combinedProminence}, persisting each combined value into `prominence` so the
|
|
101
|
+
* resolver walk's own `prominence ?? score` sort carries the bias order rather than undoing it. Stable within equal
|
|
102
|
+
* prominence, preserving the population order the index already gave. A caller with no bias hints must not call this —
|
|
103
|
+
* the no-bias path is plain population order by construction.
|
|
104
|
+
*/
|
|
105
|
+
export function applyProximityRerank<T extends ProximityRerankable>(
|
|
106
|
+
candidates: T[],
|
|
107
|
+
bias: readonly ProximityBias[]
|
|
108
|
+
): T[] {
|
|
109
|
+
candidates
|
|
110
|
+
.map((c, i) => {
|
|
111
|
+
c.prominence = combinedProminence(c, bias)
|
|
112
|
+
|
|
113
|
+
return { c, i, p: c.prominence }
|
|
114
|
+
})
|
|
115
|
+
// oxlint-disable-next-line unicorn/no-array-sort -- sorts a freshly-built array; toSorted would double-allocate on a hot path
|
|
116
|
+
.sort((a, b) => b.p - a.p || a.i - b.i)
|
|
117
|
+
.forEach((x, j) => (candidates[j] = x.c))
|
|
118
|
+
|
|
119
|
+
return candidates
|
|
120
|
+
}
|