@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
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file Pass 3b of the candidate build — the containment sidecar (closure rows + interval labels).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
9
|
+
|
|
10
|
+
import { placetypeDepth } from "#ancestry/index"
|
|
11
|
+
import {
|
|
12
|
+
CANDIDATE_ANCESTOR_COLUMNS,
|
|
13
|
+
CANDIDATE_ANCESTOR_TABLE,
|
|
14
|
+
CANDIDATE_INTERVAL_TABLE,
|
|
15
|
+
createCandidateAncestorTable,
|
|
16
|
+
createCandidateIntervalTable,
|
|
17
|
+
MAX_ANCESTOR_DEPTH,
|
|
18
|
+
} from "#candidate-ancestors-schema"
|
|
19
|
+
import type { CandidateDatabase } from "#candidate-schema"
|
|
20
|
+
import type { PlaceAttrs } from "#candidate/place-attrs"
|
|
21
|
+
import type { WOFDatabase } from "#schema"
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Pass 3b — the ancestors sidecar: closure rows + interval labels (candidate-ancestors-schema.ts owns the encoding
|
|
25
|
+
* decision and the DAG/absence semantics). Reads the same source `ancestors` table the region stamp reads,
|
|
26
|
+
* denormalizing each edge with the parent's name/key from `attrs`, streamed `ORDER BY id` so the clustered `(spr_id,
|
|
27
|
+
* depth)` insert is sorted — the contiguous-leaves discipline of the candidate table itself.
|
|
28
|
+
*
|
|
29
|
+
* Excluded by policy: self rows, and placetypes outside the containment ladder (continent, empire, …: `placetypeDepth` 0)
|
|
30
|
+
* — they discriminate nothing a consumer of this sidecar checks. An edge to a parent with no current `spr` row has no
|
|
31
|
+
* name to denormalize; it is dropped and counted rather than stored blind.
|
|
32
|
+
*/
|
|
33
|
+
export async function buildAncestorsSidecar(ctx: {
|
|
34
|
+
src: DatabaseClient<WOFDatabase>
|
|
35
|
+
out: DatabaseClient<CandidateDatabase>
|
|
36
|
+
attrs: Map<number, PlaceAttrs>
|
|
37
|
+
ptID: (pt: string | null) => number
|
|
38
|
+
progress: (phase: string, message: string) => void
|
|
39
|
+
}): Promise<{ ancestorRows: number; ancestorPlaces: number; intervalPlaces: number }> {
|
|
40
|
+
const { src, out, attrs, ptID, progress } = ctx
|
|
41
|
+
|
|
42
|
+
progress("ancestors", "building containment sidecar (closure rows + interval labels)")
|
|
43
|
+
await createCandidateAncestorTable(ctx.out)
|
|
44
|
+
await createCandidateIntervalTable(ctx.out)
|
|
45
|
+
|
|
46
|
+
const insAncestor = out.prepare(
|
|
47
|
+
`INSERT INTO ${CANDIDATE_ANCESTOR_TABLE} VALUES (${CANDIDATE_ANCESTOR_COLUMNS.map(() => "?").join(", ")})`
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
// The canonical-parent forest the interval labels are computed over. One parent per place — the
|
|
51
|
+
// depth-1 edge (finest containment tier, lowest ancestor id; the `regionOf` MIN-stability
|
|
52
|
+
// convention). ALL parents stay in the closure rows; only the interval tree canonicalizes.
|
|
53
|
+
const canonicalParentOf = new Map<number, number>()
|
|
54
|
+
const childrenOf = new Map<number, number[]>()
|
|
55
|
+
const forest = new Set<number>()
|
|
56
|
+
|
|
57
|
+
let ancestorRows = 0
|
|
58
|
+
let ancestorPlaces = 0
|
|
59
|
+
let droppedParents = 0
|
|
60
|
+
|
|
61
|
+
// Per-child edge buffer; the stream below is grouped by child id, so each flush owns one place.
|
|
62
|
+
let childID = -1
|
|
63
|
+
let edges: Array<{ aid: number; apt: string }> = []
|
|
64
|
+
|
|
65
|
+
const flush = (): void => {
|
|
66
|
+
if (childID < 0 || !edges.length) return
|
|
67
|
+
|
|
68
|
+
// Deterministic nearest-first: containment depth descending, then ancestor id ascending —
|
|
69
|
+
// the FTS backend's `ancestorLineage` ordering, made stable across rebuilds.
|
|
70
|
+
edges.sort((a, b) => placetypeDepth(b.apt) - placetypeDepth(a.apt) || a.aid - b.aid)
|
|
71
|
+
|
|
72
|
+
if (edges.length > MAX_ANCESTOR_DEPTH) {
|
|
73
|
+
edges = edges.slice(0, MAX_ANCESTOR_DEPTH)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
ancestorPlaces++
|
|
77
|
+
|
|
78
|
+
for (const [i, edge] of edges.entries()) {
|
|
79
|
+
const parent = attrs.get(edge.aid)!
|
|
80
|
+
|
|
81
|
+
insAncestor.run(childID, i + 1, edge.aid, ptID(edge.apt), parent.name, parent.pkey)
|
|
82
|
+
|
|
83
|
+
ancestorRows++
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const canonical = edges[0]!.aid
|
|
87
|
+
|
|
88
|
+
canonicalParentOf.set(childID, canonical)
|
|
89
|
+
|
|
90
|
+
const siblings = childrenOf.get(canonical)
|
|
91
|
+
|
|
92
|
+
if (siblings) {
|
|
93
|
+
siblings.push(childID)
|
|
94
|
+
} else {
|
|
95
|
+
childrenOf.set(canonical, [childID])
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
forest.add(childID)
|
|
99
|
+
forest.add(canonical)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
out.exec("BEGIN")
|
|
103
|
+
|
|
104
|
+
for (const r of src
|
|
105
|
+
.prepare("SELECT id, ancestor_id, ancestor_placetype FROM ancestors WHERE ancestor_id != id ORDER BY id")
|
|
106
|
+
.iterate()) {
|
|
107
|
+
const id = Number(r.id)
|
|
108
|
+
|
|
109
|
+
if (id !== childID) {
|
|
110
|
+
flush()
|
|
111
|
+
childID = id
|
|
112
|
+
edges = []
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (!attrs.has(id)) continue
|
|
116
|
+
|
|
117
|
+
const apt = String(r.ancestor_placetype ?? "")
|
|
118
|
+
|
|
119
|
+
if (placetypeDepth(apt) === 0) continue
|
|
120
|
+
|
|
121
|
+
const aid = Number(r.ancestor_id)
|
|
122
|
+
|
|
123
|
+
if (!attrs.has(aid)) {
|
|
124
|
+
droppedParents++
|
|
125
|
+
|
|
126
|
+
continue
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
edges.push({ aid, apt })
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
flush()
|
|
133
|
+
out.exec("COMMIT")
|
|
134
|
+
|
|
135
|
+
// Interval labels: pre/post-order DFS over the canonical-parent forest. Root order and child
|
|
136
|
+
// order are id-ascending so the labels are stable across rebuilds of the same source.
|
|
137
|
+
const preOf = new Map<number, number>()
|
|
138
|
+
const postOf = new Map<number, number>()
|
|
139
|
+
|
|
140
|
+
for (const kids of childrenOf.values()) {
|
|
141
|
+
// oxlint-disable-next-line unicorn/no-array-sort -- sorts an array this pass just built
|
|
142
|
+
kids.sort((a, b) => a - b)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const roots = [...forest].filter((id) => !canonicalParentOf.has(id))
|
|
146
|
+
|
|
147
|
+
// oxlint-disable-next-line unicorn/no-array-sort -- sorts an array this pass just built
|
|
148
|
+
roots.sort((a, b) => a - b)
|
|
149
|
+
|
|
150
|
+
let counter = 0
|
|
151
|
+
|
|
152
|
+
for (const root of roots) {
|
|
153
|
+
preOf.set(root, counter++)
|
|
154
|
+
const stack: Array<{ id: number; next: number }> = [{ id: root, next: 0 }]
|
|
155
|
+
|
|
156
|
+
while (stack.length) {
|
|
157
|
+
const top = stack.at(-1)!
|
|
158
|
+
const kids = childrenOf.get(top.id)
|
|
159
|
+
|
|
160
|
+
if (kids && top.next < kids.length) {
|
|
161
|
+
const kid = kids[top.next++]!
|
|
162
|
+
|
|
163
|
+
// Each child holds exactly one canonical parent, so a labeled node here means the
|
|
164
|
+
// grouping upstream broke — skip rather than corrupt the numbering.
|
|
165
|
+
if (preOf.has(kid)) continue
|
|
166
|
+
|
|
167
|
+
preOf.set(kid, counter++)
|
|
168
|
+
stack.push({ id: kid, next: 0 })
|
|
169
|
+
} else {
|
|
170
|
+
postOf.set(top.id, counter++)
|
|
171
|
+
stack.pop()
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// A canonical-parent CYCLE (corrupt source ancestry) leaves its members unreachable from any
|
|
177
|
+
// root: they simply receive no label, and containment against them reads unverifiable — the
|
|
178
|
+
// absence semantics the schema module states. Counted so a jump is visible across rebuilds.
|
|
179
|
+
const cycleSkipped = forest.size - preOf.size
|
|
180
|
+
|
|
181
|
+
const insInterval = out.prepare(`INSERT INTO ${CANDIDATE_INTERVAL_TABLE} VALUES (?, ?, ?)`)
|
|
182
|
+
const labeled = [...preOf.keys()]
|
|
183
|
+
|
|
184
|
+
// oxlint-disable-next-line unicorn/no-array-sort -- sorts an array this pass just built
|
|
185
|
+
labeled.sort((a, b) => a - b)
|
|
186
|
+
|
|
187
|
+
out.exec("BEGIN")
|
|
188
|
+
|
|
189
|
+
for (const id of labeled) {
|
|
190
|
+
insInterval.run(id, preOf.get(id)!, postOf.get(id)!)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
out.exec("COMMIT")
|
|
194
|
+
|
|
195
|
+
progress(
|
|
196
|
+
"ancestors",
|
|
197
|
+
`${ancestorRows.toLocaleString()} closure rows across ${ancestorPlaces.toLocaleString()} places; ` +
|
|
198
|
+
`${preOf.size.toLocaleString()} interval labels` +
|
|
199
|
+
(droppedParents ? `; ${droppedParents.toLocaleString()} edges dropped (parent has no current spr row)` : "") +
|
|
200
|
+
(cycleSkipped ? `; ${cycleSkipped.toLocaleString()} places skipped (canonical-parent cycle)` : "")
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
return { ancestorRows, ancestorPlaces, intervalPlaces: preOf.size }
|
|
204
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file Pass 1b of the candidate build — fold ICU's country display names onto the country rows.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { enumerateCountryDisplayNames } from "@mailwoman/codex/country"
|
|
9
|
+
|
|
10
|
+
import type { PlaceAttrs, StageRow } from "#candidate/place-attrs"
|
|
11
|
+
import { normalizeLocalityForKey } from "#street/normalize"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Fold every country surface ICU knows onto that country's candidate row (#1678 thread 1).
|
|
15
|
+
*
|
|
16
|
+
* A bare `格鲁吉亚` (Georgia the country) resolved to NOTHING while `佐治亚州` (Georgia the US state) resolved correctly, and
|
|
17
|
+
* the model gave both the same wrong `locality` tag — so the tag was never the variable. Measured 2026-08-15: 140 of
|
|
18
|
+
* 237 country rows are synthetic and carry a canonical English name and nothing else; WOF holds no Chinese country
|
|
19
|
+
* names at all; and the GeoNames alias fold filters through a Latin-script regex, so neither existing source could ever
|
|
20
|
+
* supply them.
|
|
21
|
+
*
|
|
22
|
+
* `Intl.DisplayNames` already knows every one — ~280 regions, ~5,244 surfaces, from the same ICU the runtime uses for
|
|
23
|
+
* every other locale-sensitive operation. No download, no vendored corpus, no snapshot to drift.
|
|
24
|
+
*
|
|
25
|
+
* `is_primary = 0`: these are NAMES THE WORLD USES, not the country's canonical name. The display `name` stays whatever
|
|
26
|
+
* the gazetteer already had, so resolving `格鲁吉亚` answers with the Georgia country row rather than renaming it.
|
|
27
|
+
*
|
|
28
|
+
* Returns the row count so the caller can report it — a zero means ICU supplied nothing, which is a different fact from
|
|
29
|
+
* the pass not having run.
|
|
30
|
+
*/
|
|
31
|
+
export function stageCountryDisplayNames(ctx: {
|
|
32
|
+
attrs: Map<number, PlaceAttrs>
|
|
33
|
+
iso2ByID: Map<number, string>
|
|
34
|
+
countryPtID: number
|
|
35
|
+
stageRow: StageRow
|
|
36
|
+
tx: { exec(sql: string): void }
|
|
37
|
+
}): number {
|
|
38
|
+
// One country row per ISO2. Where a code has several (historic rows surviving the is_current filter), the most
|
|
39
|
+
// populous wins — the same tiebreak the ranking uses everywhere else.
|
|
40
|
+
const countryByISO2 = new Map<string, { sid: number; a: PlaceAttrs }>()
|
|
41
|
+
|
|
42
|
+
for (const [sid, a] of ctx.attrs) {
|
|
43
|
+
if (a.ptid !== ctx.countryPtID) continue
|
|
44
|
+
|
|
45
|
+
const iso2 = ctx.iso2ByID.get(a.cid)
|
|
46
|
+
|
|
47
|
+
if (!iso2 || iso2 === "??") continue
|
|
48
|
+
|
|
49
|
+
const held = countryByISO2.get(iso2)
|
|
50
|
+
|
|
51
|
+
if (!held || a.pop > held.a.pop) {
|
|
52
|
+
countryByISO2.set(iso2, { sid, a })
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let staged = 0
|
|
57
|
+
|
|
58
|
+
ctx.tx.exec("BEGIN")
|
|
59
|
+
|
|
60
|
+
for (const { iso2, name } of enumerateCountryDisplayNames()) {
|
|
61
|
+
const target = countryByISO2.get(iso2)
|
|
62
|
+
|
|
63
|
+
if (!target) continue
|
|
64
|
+
|
|
65
|
+
const k = normalizeLocalityForKey(name)
|
|
66
|
+
|
|
67
|
+
// The country's own key is already staged as its primary; INSERT OR IGNORE at materialization dedupes the
|
|
68
|
+
// rest, so this only skips the obvious self-alias.
|
|
69
|
+
if (!k || k === target.a.pkey) continue
|
|
70
|
+
|
|
71
|
+
ctx.stageRow(k, target.a, target.sid, 0)
|
|
72
|
+
|
|
73
|
+
staged++
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
ctx.tx.exec("COMMIT")
|
|
77
|
+
|
|
78
|
+
return staged
|
|
79
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file Pass 4 of the candidate build — fold a postcode or locality extract into the staging table.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
9
|
+
import { tableExists } from "@mailwoman/sqlite/introspection"
|
|
10
|
+
|
|
11
|
+
import type { CandidateDatabase } from "#candidate-schema"
|
|
12
|
+
import type { PlaceAttrs, StageRow } from "#candidate/place-attrs"
|
|
13
|
+
import type { WOFDatabase } from "#schema"
|
|
14
|
+
import { normalizeLocalityForKey } from "#street/normalize"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Fold ONE extract (`spr` rows at `extractPlacetype` carrying real coordinates) in, then pass 4b: the alias names
|
|
18
|
+
* hanging off that same extract's `names` table.
|
|
19
|
+
*
|
|
20
|
+
* Self-contained by construction — it shares only the staging statement and the code dictionaries with the admin passes
|
|
21
|
+
* above it, and nothing downstream reads anything it produces except the two counters it returns.
|
|
22
|
+
*/
|
|
23
|
+
export function foldExtract(ctx: {
|
|
24
|
+
/**
|
|
25
|
+
* The staging connection. The extract itself is opened read-only here and closed before returning.
|
|
26
|
+
*/
|
|
27
|
+
out: DatabaseClient<CandidateDatabase>
|
|
28
|
+
extractPath: string
|
|
29
|
+
extractPlacetype: "postalcode" | "locality"
|
|
30
|
+
ccID: (code: string | null) => number
|
|
31
|
+
ptID: (pt: string | null) => number
|
|
32
|
+
stageRow: StageRow
|
|
33
|
+
progress: (phase: string, message: string) => void
|
|
34
|
+
}): { primaries: number; aliases: number } {
|
|
35
|
+
const { out, extractPath, extractPlacetype, ccID, ptID, stageRow, progress } = ctx
|
|
36
|
+
|
|
37
|
+
progress(extractPlacetype === "postalcode" ? "postcodes" : "localities", `reading ${extractPath}`)
|
|
38
|
+
|
|
39
|
+
using pc = new DatabaseClient<WOFDatabase>(extractPath, { readOnly: true })
|
|
40
|
+
const pcPtid = ptID(extractPlacetype)
|
|
41
|
+
// Per-extract, not the admin `attrs` map: pass 1 only ever sees the admin DB, so the alias pass
|
|
42
|
+
// below has nothing to join against unless this primary loop records what it staged.
|
|
43
|
+
const pcAttrs = new Map<number, PlaceAttrs>()
|
|
44
|
+
let primaries = 0
|
|
45
|
+
let aliases = 0
|
|
46
|
+
|
|
47
|
+
out.exec("BEGIN")
|
|
48
|
+
|
|
49
|
+
for (const r of pc
|
|
50
|
+
.prepare(
|
|
51
|
+
`SELECT id, name, country, latitude, longitude,
|
|
52
|
+
min_latitude AS mnlat, min_longitude AS mnlon, max_latitude AS mxlat, max_longitude AS mxlon
|
|
53
|
+
FROM spr WHERE placetype = ? AND latitude != 0 AND longitude != 0`
|
|
54
|
+
)
|
|
55
|
+
.iterate(extractPlacetype)) {
|
|
56
|
+
const name = String(r.name ?? "")
|
|
57
|
+
const key = normalizeLocalityForKey(name)
|
|
58
|
+
|
|
59
|
+
if (!key) continue
|
|
60
|
+
|
|
61
|
+
const lat = r.latitude as number
|
|
62
|
+
const lon = r.longitude as number
|
|
63
|
+
|
|
64
|
+
// region_id 0 (a postcode is unique by name+country — no same-name disambiguation); neg_rank 0
|
|
65
|
+
// (no population). bbox = the postcode's own min/max (falls back to the centroid point).
|
|
66
|
+
const a: PlaceAttrs = {
|
|
67
|
+
cid: ccID(r.country as string | null),
|
|
68
|
+
rid: 0,
|
|
69
|
+
ptid: pcPtid,
|
|
70
|
+
name,
|
|
71
|
+
lat,
|
|
72
|
+
lon,
|
|
73
|
+
mnLat: (r.mnlat as number) || lat,
|
|
74
|
+
mnLon: (r.mnlon as number) || lon,
|
|
75
|
+
mxLat: (r.mxlat as number) || lat,
|
|
76
|
+
mxLon: (r.mxlon as number) || lon,
|
|
77
|
+
pop: 0,
|
|
78
|
+
neg: 0,
|
|
79
|
+
pkey: key,
|
|
80
|
+
// A postcode has no toponym fame — nobody writes an encyclopedia article about SW1A 2AA — and
|
|
81
|
+
// the score source carries no `postalcode` rows to join against anyway. NULL is the truthful
|
|
82
|
+
// value: unmeasured, so the ranking key leaves postcode rows exactly where they were.
|
|
83
|
+
imp: null,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
pcAttrs.set(Number(r.id), a)
|
|
87
|
+
stageRow(key, a, Number(r.id), 1)
|
|
88
|
+
|
|
89
|
+
primaries++
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
out.exec("COMMIT")
|
|
93
|
+
|
|
94
|
+
// --- pass 4b: postcode ALIAS names (#1495) ---
|
|
95
|
+
//
|
|
96
|
+
// The delivery-city names GeoNames supplies for a ZIP ("Brooklyn" for 11201) are written into
|
|
97
|
+
// the extract's `names` table by `postcode/centroid-fills.ts`'s `geonamesNameFill`. Everything
|
|
98
|
+
// downstream of `names` picked them up EXCEPT this build: `fts.ts` unions `spr.name` with every
|
|
99
|
+
// `names` row into `place_search.alt_names`, so the FTS backend resolved "Brooklyn" → 11201
|
|
100
|
+
// while the candidate backend — whose every row IS an exact-tier row — had no key for it at
|
|
101
|
+
// all. Pass 2 does the equivalent fold for admin places, but reads the ADMIN `place_search`,
|
|
102
|
+
// and `attrs` holds admin ids only, so a postcode extract could never reach it.
|
|
103
|
+
//
|
|
104
|
+
// Same discipline as pass 2: `is_primary = 0` (so `rankByPrimaryPreference` treats it as an
|
|
105
|
+
// alias, not a canonical postcode name), the row stays denormalized onto the POSTCODE's own
|
|
106
|
+
// spr_id/coords/bbox, and the display `name` stays the postcode — resolving "brooklyn" answers
|
|
107
|
+
// with place 11201, it does not rename the place to its delivery city.
|
|
108
|
+
const hasNames = tableExists(pc, "names")
|
|
109
|
+
|
|
110
|
+
if (hasNames) {
|
|
111
|
+
out.exec("BEGIN")
|
|
112
|
+
|
|
113
|
+
for (const r of pc.prepare("SELECT id, name FROM names").iterate()) {
|
|
114
|
+
const a = pcAttrs.get(Number(r.id))
|
|
115
|
+
|
|
116
|
+
if (!a) continue
|
|
117
|
+
|
|
118
|
+
const k = normalizeLocalityForKey(String(r.name ?? ""))
|
|
119
|
+
|
|
120
|
+
// The postcode's own key is already staged as the primary; `INSERT OR IGNORE` at
|
|
121
|
+
// materialization dedupes repeats, so this only skips the obvious self-alias.
|
|
122
|
+
if (!k || k === a.pkey) continue
|
|
123
|
+
|
|
124
|
+
stageRow(k, a, Number(r.id), 0)
|
|
125
|
+
|
|
126
|
+
aliases++
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
out.exec("COMMIT")
|
|
130
|
+
} else {
|
|
131
|
+
// Never a silent zero: real extracts come from `createUnifiedSchema`, which always creates
|
|
132
|
+
// `names`. A extract without it has no alias surface to lose, but say so rather than reporting
|
|
133
|
+
// "0 aliases" from a table that was never read.
|
|
134
|
+
progress("postcode-aliases", `${extractPath} has no \`names\` table — no delivery-city aliases to fold`)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return { primaries, aliases }
|
|
138
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file Pass 3c of the candidate build — the `name_role` detectors and the thresholds they are judged by.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { isOfficialLanguage } from "@mailwoman/codex/country"
|
|
9
|
+
import type { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
10
|
+
import { tableExists } from "@mailwoman/sqlite/introspection"
|
|
11
|
+
|
|
12
|
+
import type { CandidateDatabase } from "#candidate-schema"
|
|
13
|
+
import { isOwnNameVariant } from "#candidate/own-name"
|
|
14
|
+
import type { PlaceAttrs } from "#candidate/place-attrs"
|
|
15
|
+
import type { WOFDatabase } from "#schema"
|
|
16
|
+
import { normalizeLocalityForKey } from "#street/normalize"
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Key-count threshold for the gloss anomaly detector (#1730) — the sweep's own boundary: 4,000 places carried >= 50
|
|
20
|
+
* keys, and a legitimate famous place at that count (New York, 176 keys) is separated by the PROMINENCE check, never by
|
|
21
|
+
* this number alone.
|
|
22
|
+
*/
|
|
23
|
+
export const GLOSS_KEY_THRESHOLD = 50
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Placetypes the gloss detector never flags. A country or region legitimately carries a name in every language — that
|
|
27
|
+
* is what an exonym set IS — so key volume discriminates nothing there. The detector's population is the non-admin
|
|
28
|
+
* tail, where a place named by a common noun ("Poisson", "Sunday") accumulating 200+ translations is a
|
|
29
|
+
* machine-translated gloss set, not fame.
|
|
30
|
+
*/
|
|
31
|
+
export const GLOSS_EXCLUDED_PLACETYPES: ReadonlySet<string> = new Set([
|
|
32
|
+
"country",
|
|
33
|
+
"dependency",
|
|
34
|
+
"disputed",
|
|
35
|
+
"empire",
|
|
36
|
+
"macroregion",
|
|
37
|
+
"region",
|
|
38
|
+
"macrocounty",
|
|
39
|
+
"county",
|
|
40
|
+
])
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Pass 3c — the #1730 name-role prototype: two independent detectors over the staged rows, WRITE-ONLY in this
|
|
44
|
+
* generation (no ranking consumer; the rank penalty is its own D-rule-conditional step with the `gloss_key` board as
|
|
45
|
+
* regression check). Both stamp `is_primary = 0` rows only — a place's canonical name and the `place_abbr` region
|
|
46
|
+
* abbreviations are never a gloss or a variant.
|
|
47
|
+
*
|
|
48
|
+
* - `gloss` is ANOMALY-based, and stamps only the certain core: key volume at/over the threshold + a non-admin placetype
|
|
49
|
+
*
|
|
50
|
+
* - NO measured prominence (population absent AND importance unmeasured). Provenance cannot separate a gloss from an
|
|
51
|
+
* exonym — WOF imported both as `x_preferred` — and prominence is what rescues New York/Paris.
|
|
52
|
+
* - `abbr` is PROVENANCE-based — the #936 signal: a WOF `variant` name in one of the country's official languages (or
|
|
53
|
+
* English), measured there at a 13× key-collision rate. A source without a `names` table (fixture-scale admin DBs)
|
|
54
|
+
* skips this detector loudly.
|
|
55
|
+
*
|
|
56
|
+
* Returns the stamp counts plus the census the prototype exists to report: how much of the ≥-threshold key tail carries
|
|
57
|
+
* any role.
|
|
58
|
+
*/
|
|
59
|
+
export function stampNameRoles(ctx: {
|
|
60
|
+
src: DatabaseClient<WOFDatabase>
|
|
61
|
+
out: DatabaseClient<CandidateDatabase>
|
|
62
|
+
attrs: Map<number, PlaceAttrs>
|
|
63
|
+
keyCounts: Map<number, number>
|
|
64
|
+
glossThreshold: number
|
|
65
|
+
ptcodes: Map<string, number>
|
|
66
|
+
ccodes: Map<string, number>
|
|
67
|
+
progress: (phase: string, message: string) => void
|
|
68
|
+
}): { roleGloss: number; roleAbbr: number; roleVariant: number; keyTailPlaces: number; keyTailWithRole: number } {
|
|
69
|
+
const { src, out, attrs, keyCounts, glossThreshold, progress } = ctx
|
|
70
|
+
progress("roles", "stamping name roles (gloss anomaly + abbr provenance)")
|
|
71
|
+
|
|
72
|
+
const ptNameByID = new Map([...ctx.ptcodes].map(([placetype, id]) => [id, placetype]))
|
|
73
|
+
const iso2ByCID = new Map([...ctx.ccodes].map(([code, id]) => [id, code]))
|
|
74
|
+
|
|
75
|
+
let keyTailPlaces = 0
|
|
76
|
+
const glossSids: number[] = []
|
|
77
|
+
|
|
78
|
+
for (const [sid, count] of keyCounts) {
|
|
79
|
+
if (count < glossThreshold) continue
|
|
80
|
+
|
|
81
|
+
keyTailPlaces++
|
|
82
|
+
const a = attrs.get(sid)
|
|
83
|
+
|
|
84
|
+
if (!a) continue
|
|
85
|
+
|
|
86
|
+
if (GLOSS_EXCLUDED_PLACETYPES.has(ptNameByID.get(a.ptid) ?? "")) continue
|
|
87
|
+
|
|
88
|
+
if (a.pop > 0 || a.imp != null) continue
|
|
89
|
+
glossSids.push(sid)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
out.exec(
|
|
93
|
+
"CREATE TEMP TABLE role_key (spr_id INTEGER NOT NULL, name_key TEXT NOT NULL, PRIMARY KEY (spr_id, name_key)) WITHOUT ROWID"
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
const insRoleKey = out.prepare("INSERT OR IGNORE INTO role_key VALUES (?, ?)")
|
|
97
|
+
|
|
98
|
+
// Zero abbr stamps from a skipped detector is a different fact from zero variants found.
|
|
99
|
+
const hasSourceNames = tableExists(src, "names")
|
|
100
|
+
|
|
101
|
+
if (hasSourceNames) {
|
|
102
|
+
out.exec("BEGIN")
|
|
103
|
+
|
|
104
|
+
// Two provenance routes into the same stamp: WOF's abbreviation/short name KINDS arrive in the
|
|
105
|
+
// LANGUAGE column ('abbr'/'short' — 280 rows, measured 2026-08-18, Toledo's 'TO' among them) and
|
|
106
|
+
// qualify by kind alone; everything else qualifies as a variant in an official language.
|
|
107
|
+
for (const r of src
|
|
108
|
+
.prepare("SELECT id, name, language FROM names WHERE privateuse = 'variant' OR language IN ('abbr', 'short')")
|
|
109
|
+
.iterate()) {
|
|
110
|
+
const a = attrs.get(Number(r.id))
|
|
111
|
+
|
|
112
|
+
if (!a) continue
|
|
113
|
+
const language = String(r.language ?? "")
|
|
114
|
+
|
|
115
|
+
if (language !== "abbr" && language !== "short") {
|
|
116
|
+
const iso2 = iso2ByCID.get(a.cid) ?? "??"
|
|
117
|
+
|
|
118
|
+
if (language !== "eng" && !isOfficialLanguage(iso2, language)) continue
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const k = normalizeLocalityForKey(String(r.name ?? ""))
|
|
122
|
+
|
|
123
|
+
if (!k || k === a.pkey) continue
|
|
124
|
+
insRoleKey.run(Number(r.id), k)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
out.exec("COMMIT")
|
|
128
|
+
} else {
|
|
129
|
+
progress("roles", "source carries no `names` table — abbr detector skipped (gloss still runs)")
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Stamp order is precedence: the provenance-based abbr first, then the own-name variant verdict,
|
|
133
|
+
// then gloss fills what neither claimed.
|
|
134
|
+
const roleAbbr = Number(
|
|
135
|
+
out
|
|
136
|
+
.prepare(
|
|
137
|
+
`UPDATE cand_stage SET name_role = 'abbr'
|
|
138
|
+
WHERE is_primary = 0 AND EXISTS (
|
|
139
|
+
SELECT 1 FROM role_key rk WHERE rk.spr_id = cand_stage.spr_id AND rk.name_key = cand_stage.name_key)`
|
|
140
|
+
)
|
|
141
|
+
.run().changes
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
// --- variant detector (#1882): the alias surface is the holder's OWN primary name in another
|
|
145
|
+
// orthography — romanization, spacing/diacritic variant, or abbreviation expansion. The verdict
|
|
146
|
+
// is per (alias key, primary key) pair, so it runs in JS over the still-unstamped alias rows;
|
|
147
|
+
// an uncovered script answers no-verdict and stamps nothing (own-name.ts owns the predicate and
|
|
148
|
+
// its measured threshold). Runs BEFORE gloss on purpose: a surface that IS the place's own name
|
|
149
|
+
// is not a translation, whatever the key volume says.
|
|
150
|
+
out.exec(
|
|
151
|
+
"CREATE TEMP TABLE variant_key (spr_id INTEGER NOT NULL, name_key TEXT NOT NULL, PRIMARY KEY (spr_id, name_key)) WITHOUT ROWID"
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
const insVariantKey = out.prepare("INSERT OR IGNORE INTO variant_key VALUES (?, ?)")
|
|
155
|
+
let variantScanned = 0
|
|
156
|
+
|
|
157
|
+
out.exec("BEGIN")
|
|
158
|
+
|
|
159
|
+
for (const r of out
|
|
160
|
+
.prepare("SELECT DISTINCT spr_id, name_key FROM cand_stage WHERE is_primary = 0 AND name_role IS NULL")
|
|
161
|
+
.iterate()) {
|
|
162
|
+
variantScanned++
|
|
163
|
+
const a = attrs.get(Number(r.spr_id))
|
|
164
|
+
|
|
165
|
+
if (!a?.pkey) continue
|
|
166
|
+
|
|
167
|
+
if (isOwnNameVariant(String(a.pkey), String(r.name_key))) {
|
|
168
|
+
insVariantKey.run(Number(r.spr_id), String(r.name_key))
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
out.exec("COMMIT")
|
|
173
|
+
|
|
174
|
+
const roleVariant = Number(
|
|
175
|
+
out
|
|
176
|
+
.prepare(
|
|
177
|
+
`UPDATE cand_stage SET name_role = 'variant'
|
|
178
|
+
WHERE is_primary = 0 AND name_role IS NULL AND EXISTS (
|
|
179
|
+
SELECT 1 FROM variant_key vk WHERE vk.spr_id = cand_stage.spr_id AND vk.name_key = cand_stage.name_key)`
|
|
180
|
+
)
|
|
181
|
+
.run().changes
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
out.exec("DROP TABLE variant_key")
|
|
185
|
+
|
|
186
|
+
progress(
|
|
187
|
+
"roles",
|
|
188
|
+
`variant: ${roleVariant.toLocaleString()} of ${variantScanned.toLocaleString()} unstamped alias keys are own-name variants`
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
out.exec("CREATE TEMP TABLE role_place (spr_id INTEGER PRIMARY KEY) WITHOUT ROWID")
|
|
192
|
+
out.exec("CREATE TEMP TABLE key_tail (spr_id INTEGER PRIMARY KEY) WITHOUT ROWID")
|
|
193
|
+
const insRolePlace = out.prepare("INSERT OR IGNORE INTO role_place VALUES (?)")
|
|
194
|
+
const insKeyTail = out.prepare("INSERT OR IGNORE INTO key_tail VALUES (?)")
|
|
195
|
+
out.exec("BEGIN")
|
|
196
|
+
|
|
197
|
+
for (const sid of glossSids) {
|
|
198
|
+
insRolePlace.run(sid)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
for (const [sid, count] of keyCounts) {
|
|
202
|
+
if (count >= glossThreshold) {
|
|
203
|
+
insKeyTail.run(sid)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
out.exec("COMMIT")
|
|
208
|
+
|
|
209
|
+
const roleGloss = Number(
|
|
210
|
+
out
|
|
211
|
+
.prepare(
|
|
212
|
+
`UPDATE cand_stage SET name_role = 'gloss'
|
|
213
|
+
WHERE is_primary = 0 AND name_role IS NULL AND spr_id IN (SELECT spr_id FROM role_place)`
|
|
214
|
+
)
|
|
215
|
+
.run().changes
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
const keyTailWithRole = Number(
|
|
219
|
+
out
|
|
220
|
+
.prepare(
|
|
221
|
+
`SELECT count(DISTINCT spr_id) AS n FROM cand_stage
|
|
222
|
+
WHERE name_role IS NOT NULL AND spr_id IN (SELECT spr_id FROM key_tail)`
|
|
223
|
+
)
|
|
224
|
+
.get()!["n"]
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
out.exec("DROP TABLE role_key")
|
|
228
|
+
out.exec("DROP TABLE role_place")
|
|
229
|
+
out.exec("DROP TABLE key_tail")
|
|
230
|
+
|
|
231
|
+
progress(
|
|
232
|
+
"roles",
|
|
233
|
+
`${roleAbbr.toLocaleString()} abbr + ${roleGloss.toLocaleString()} gloss rows stamped; ` +
|
|
234
|
+
`key tail (>= ${glossThreshold} keys): ${keyTailWithRole.toLocaleString()} of ${keyTailPlaces.toLocaleString()} places carry a role`
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
return { roleGloss, roleAbbr, roleVariant, keyTailPlaces, keyTailWithRole }
|
|
238
|
+
}
|