@mailwoman/resolver-wof-sqlite 11.1.0 → 11.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/lib/address/duplicate.ts +1 -1
- package/lib/address/keys/attribution.ts +6 -1
- package/lib/address/keys/build.ts +1 -1
- package/lib/address/keys/layout.ts +27 -1
- package/lib/address/keys/lookup.ts +2 -2
- package/lib/address/keys/point-lookup.ts +2 -2
- package/lib/address/number-forms.ts +4 -6
- package/lib/address/point/interpolation.ts +11 -3
- package/lib/address/point/schema.ts +1 -1
- package/lib/address/point.ts +15 -14
- package/lib/address/record.ts +1 -1
- package/lib/ancestry/backfill.ts +13 -43
- package/lib/build/candidate.ts +171 -35
- package/lib/build/slim.ts +4 -1
- package/lib/build/sources.ts +50 -0
- package/lib/candidate/alias-bags.ts +74 -20
- package/lib/candidate/ancestors/schema.ts +1 -1
- package/lib/candidate/ancestors/sidecar.ts +13 -2
- package/lib/candidate/bare-admin-names.ts +1 -1
- package/lib/{capital-schema.ts → candidate/capital-schema.ts} +3 -3
- package/lib/{capitals.ts → candidate/capitals.ts} +1 -1
- package/lib/candidate/country-display-names.ts +1 -1
- package/lib/candidate/{extract-fold.ts → extract-rows.ts} +7 -4
- package/lib/candidate/importance.ts +90 -11
- package/lib/candidate/key-fold.ts +132 -0
- package/lib/candidate/lookup.ts +101 -60
- package/lib/candidate/name-roles.ts +1 -1
- package/lib/candidate/nickname-namesakes.ts +147 -0
- package/lib/candidate/overture-twins.ts +83 -0
- package/lib/candidate/place-attrs.ts +2 -2
- package/lib/candidate/postcode-browse.ts +173 -0
- package/lib/candidate/schema.ts +43 -2
- package/lib/candidate/scoring.ts +4 -4
- package/lib/convention.ts +1 -1
- package/lib/env.ts +15 -3
- package/lib/fst/binary-matcher.ts +26 -41
- package/lib/fst/builder.ts +8 -6
- package/lib/fst/deserialize-web.ts +1 -1
- package/lib/fst/format.ts +144 -7
- package/lib/fst/freshness.ts +2 -2
- package/lib/fst/serialize.ts +93 -64
- package/lib/fts/query.ts +1 -1
- package/lib/{search-fetch.ts → fts/search-fetch.ts} +2 -2
- package/lib/geonames/aliases.ts +42 -45
- package/lib/geonames/postal.ts +3 -3
- package/lib/index.ts +20 -17
- package/lib/{postal/city → labels/locality/postal-city}/alias/lookup.ts +1 -1
- package/lib/{postal/city → labels/locality/postal-city}/candidate-schema.ts +1 -1
- package/lib/labels/locality.ts +6 -0
- package/lib/{region-keys.ts → labels/region.ts} +5 -2
- package/lib/{street → labels/street}/centroid/schema.ts +1 -1
- package/lib/{street → labels/street}/centroid.ts +7 -7
- package/lib/{interpolation.ts → labels/street/interpolation.ts} +12 -4
- package/lib/labels/street/locale.ts +117 -0
- package/lib/{street → labels/street}/morphology/fst/loader.ts +1 -1
- package/lib/{street → labels/street}/name-lookup.ts +2 -0
- package/lib/{street → labels/street}/normalize.ts +284 -133
- package/lib/{street → labels/street}/segment-schema.ts +1 -1
- package/lib/{street → labels/street}/table.ts +1 -1
- package/lib/labels/street.ts +11 -0
- package/lib/landmark/rows.ts +1 -1
- package/lib/lookup/browse.ts +304 -0
- package/lib/{extracts.ts → lookup/extracts.ts} +1 -1
- package/lib/lookup/former-divisions.ts +183 -0
- package/lib/{postcode-point-lookup.ts → lookup/postcode-point.ts} +5 -0
- package/lib/{reverse.ts → lookup/reverse.ts} +4 -4
- package/lib/{types.ts → lookup/types.ts} +10 -0
- package/lib/lookup.ts +21 -31
- package/lib/poi/schema.ts +1 -1
- package/lib/{primary-preference.ts → ranking/primary-preference.ts} +45 -2
- package/lib/schema/importance-source.ts +210 -0
- package/lib/schema/overture-match.ts +79 -0
- package/lib/{place-importance-schema.ts → schema/place-importance.ts} +86 -0
- package/lib/schema.ts +3 -3
- package/lib/sqlite/convention-source.ts +1 -1
- package/lib/uprn/existence.ts +2 -0
- package/lib/{weights-overlay-linker.ts → weights/overlay-linker.ts} +244 -103
- package/out/address/duplicate.js +1 -1
- package/out/address/duplicate.js.map +1 -1
- package/out/address/keys/attribution.d.ts +4 -0
- package/out/address/keys/attribution.d.ts.map +1 -1
- package/out/address/keys/attribution.js +5 -1
- package/out/address/keys/attribution.js.map +1 -1
- package/out/address/keys/build.d.ts.map +1 -1
- package/out/address/keys/build.js +1 -1
- package/out/address/keys/build.js.map +1 -1
- package/out/address/keys/layout.d.ts +18 -1
- package/out/address/keys/layout.d.ts.map +1 -1
- package/out/address/keys/layout.js +23 -1
- package/out/address/keys/layout.js.map +1 -1
- package/out/address/keys/lookup.js +2 -2
- package/out/address/keys/lookup.js.map +1 -1
- package/out/address/keys/point-lookup.d.ts.map +1 -1
- package/out/address/keys/point-lookup.js +2 -2
- package/out/address/keys/point-lookup.js.map +1 -1
- package/out/address/number-forms.d.ts +1 -1
- package/out/address/number-forms.d.ts.map +1 -1
- package/out/address/number-forms.js +4 -5
- package/out/address/number-forms.js.map +1 -1
- package/out/address/point/interpolation.d.ts +1 -1
- package/out/address/point/interpolation.d.ts.map +1 -1
- package/out/address/point/interpolation.js +9 -2
- package/out/address/point/interpolation.js.map +1 -1
- package/out/address/point/schema.d.ts +1 -1
- package/out/address/point/schema.d.ts.map +1 -1
- package/out/address/point.d.ts +4 -5
- package/out/address/point.d.ts.map +1 -1
- package/out/address/point.js +11 -11
- package/out/address/point.js.map +1 -1
- package/out/address/record.d.ts +1 -1
- package/out/address/record.d.ts.map +1 -1
- package/out/address/record.js +1 -1
- package/out/address/record.js.map +1 -1
- package/out/ancestry/backfill.d.ts +14 -9
- package/out/ancestry/backfill.d.ts.map +1 -1
- package/out/ancestry/backfill.js +4 -42
- package/out/ancestry/backfill.js.map +1 -1
- package/out/build/candidate.d.ts +46 -1
- package/out/build/candidate.d.ts.map +1 -1
- package/out/build/candidate.js +82 -31
- package/out/build/candidate.js.map +1 -1
- package/out/build/slim.d.ts.map +1 -1
- package/out/build/slim.js +4 -1
- package/out/build/slim.js.map +1 -1
- package/out/build/sources.d.ts +32 -0
- package/out/build/sources.d.ts.map +1 -0
- package/out/build/sources.js +35 -0
- package/out/build/sources.js.map +1 -0
- package/out/candidate/alias-bags.d.ts +8 -3
- package/out/candidate/alias-bags.d.ts.map +1 -1
- package/out/candidate/alias-bags.js +63 -17
- package/out/candidate/alias-bags.js.map +1 -1
- package/out/candidate/ancestors/schema.d.ts +1 -1
- package/out/candidate/ancestors/schema.d.ts.map +1 -1
- package/out/candidate/ancestors/sidecar.d.ts +0 -3
- package/out/candidate/ancestors/sidecar.d.ts.map +1 -1
- package/out/candidate/ancestors/sidecar.js +16 -2
- package/out/candidate/ancestors/sidecar.js.map +1 -1
- package/out/candidate/bare-admin-names.js +1 -1
- package/out/candidate/bare-admin-names.js.map +1 -1
- package/out/{capital-schema.d.ts → candidate/capital-schema.d.ts} +2 -2
- package/out/candidate/capital-schema.d.ts.map +1 -0
- package/out/{capital-schema.js → candidate/capital-schema.js} +2 -2
- package/out/candidate/capital-schema.js.map +1 -0
- package/out/candidate/capitals.d.ts.map +1 -0
- package/out/{capitals.js → candidate/capitals.js} +1 -1
- package/out/candidate/capitals.js.map +1 -0
- package/out/candidate/country-display-names.js +1 -1
- package/out/candidate/country-display-names.js.map +1 -1
- package/out/{coverage-manifest-schema.d.ts → candidate/coverage-manifest.d.ts} +1 -1
- package/out/candidate/coverage-manifest.d.ts.map +1 -0
- package/out/{coverage-manifest-schema.js → candidate/coverage-manifest.js} +1 -1
- package/out/candidate/coverage-manifest.js.map +1 -0
- package/out/candidate/{extract-fold.d.ts → extract-rows.d.ts} +2 -2
- package/out/candidate/extract-rows.d.ts.map +1 -0
- package/out/candidate/{extract-fold.js → extract-rows.js} +8 -5
- package/out/candidate/extract-rows.js.map +1 -0
- package/out/candidate/importance.d.ts +34 -3
- package/out/candidate/importance.d.ts.map +1 -1
- package/out/candidate/importance.js +57 -11
- package/out/candidate/importance.js.map +1 -1
- package/out/candidate/key-fold.d.ts +55 -0
- package/out/candidate/key-fold.d.ts.map +1 -0
- package/out/candidate/key-fold.js +80 -0
- package/out/candidate/key-fold.js.map +1 -0
- package/out/candidate/lookup.d.ts +5 -1
- package/out/candidate/lookup.d.ts.map +1 -1
- package/out/candidate/lookup.js +80 -54
- package/out/candidate/lookup.js.map +1 -1
- package/out/candidate/name-roles.d.ts.map +1 -1
- package/out/candidate/name-roles.js +1 -1
- package/out/candidate/name-roles.js.map +1 -1
- package/out/candidate/nickname-namesakes.d.ts +28 -0
- package/out/candidate/nickname-namesakes.d.ts.map +1 -0
- package/out/candidate/nickname-namesakes.js +109 -0
- package/out/candidate/nickname-namesakes.js.map +1 -0
- package/out/candidate/overture-twins.d.ts +30 -0
- package/out/candidate/overture-twins.d.ts.map +1 -0
- package/out/candidate/overture-twins.js +40 -0
- package/out/candidate/overture-twins.js.map +1 -0
- package/out/candidate/place-attrs.d.ts +2 -2
- package/out/candidate/postcode-browse.d.ts +36 -0
- package/out/candidate/postcode-browse.d.ts.map +1 -0
- package/out/candidate/postcode-browse.js +119 -0
- package/out/candidate/postcode-browse.js.map +1 -0
- package/out/candidate/schema.d.ts +30 -2
- package/out/candidate/schema.d.ts.map +1 -1
- package/out/candidate/schema.js +29 -0
- package/out/candidate/schema.js.map +1 -1
- package/out/candidate/scoring.d.ts +3 -3
- package/out/candidate/scoring.d.ts.map +1 -1
- package/out/candidate/scoring.js +2 -2
- package/out/candidate/scoring.js.map +1 -1
- package/out/convention.d.ts +1 -1
- package/out/convention.d.ts.map +1 -1
- package/out/env.d.ts +3 -0
- package/out/env.d.ts.map +1 -1
- package/out/env.js +14 -3
- package/out/env.js.map +1 -1
- package/out/fst/binary-matcher.d.ts.map +1 -1
- package/out/fst/binary-matcher.js +9 -30
- package/out/fst/binary-matcher.js.map +1 -1
- package/out/fst/builder.d.ts.map +1 -1
- package/out/fst/builder.js +8 -6
- package/out/fst/builder.js.map +1 -1
- package/out/fst/deserialize-web.js +1 -1
- package/out/fst/deserialize-web.js.map +1 -1
- package/out/fst/format.d.ts +60 -9
- package/out/fst/format.d.ts.map +1 -1
- package/out/fst/format.js +97 -6
- package/out/fst/format.js.map +1 -1
- package/out/fst/freshness.js +2 -2
- package/out/fst/freshness.js.map +1 -1
- package/out/fst/serialize.d.ts.map +1 -1
- package/out/fst/serialize.js +67 -55
- package/out/fst/serialize.js.map +1 -1
- package/out/fts/query.d.ts +1 -1
- package/out/fts/query.d.ts.map +1 -1
- package/out/{search-fetch.d.ts → fts/search-fetch.d.ts} +2 -2
- package/out/fts/search-fetch.d.ts.map +1 -0
- package/out/fts/search-fetch.js.map +1 -0
- package/out/geonames/aliases.d.ts +18 -18
- package/out/geonames/aliases.d.ts.map +1 -1
- package/out/geonames/aliases.js +20 -24
- package/out/geonames/aliases.js.map +1 -1
- package/out/geonames/postal.d.ts +1 -1
- package/out/geonames/postal.js +3 -3
- package/out/index.d.ts +17 -17
- package/out/index.d.ts.map +1 -1
- package/out/index.js +12 -12
- package/out/index.js.map +1 -1
- package/out/{postal/city → labels/locality/postal-city}/alias/lookup.d.ts +1 -1
- package/out/labels/locality/postal-city/alias/lookup.d.ts.map +1 -0
- package/out/labels/locality/postal-city/alias/lookup.js.map +1 -0
- package/out/labels/locality/postal-city/alias/schema.d.ts.map +1 -0
- package/out/labels/locality/postal-city/alias/schema.js.map +1 -0
- package/out/{postal/city → labels/locality/postal-city}/candidate-schema.d.ts +1 -1
- package/out/labels/locality/postal-city/candidate-schema.d.ts.map +1 -0
- package/out/labels/locality/postal-city/candidate-schema.js.map +1 -0
- package/out/labels/locality.d.ts +4 -0
- package/out/labels/locality.d.ts.map +1 -0
- package/out/labels/locality.js +6 -0
- package/out/labels/locality.js.map +1 -0
- package/out/{region-keys.d.ts → labels/region.d.ts} +1 -1
- package/out/{region-keys.d.ts.map → labels/region.d.ts.map} +1 -1
- package/out/{region-keys.js → labels/region.js} +6 -3
- package/out/labels/region.js.map +1 -0
- package/out/{street → labels/street}/centroid/schema.d.ts +1 -1
- package/out/labels/street/centroid/schema.d.ts.map +1 -0
- package/out/labels/street/centroid/schema.js.map +1 -0
- package/out/{street → labels/street}/centroid.d.ts +5 -5
- package/out/labels/street/centroid.d.ts.map +1 -0
- package/out/{street → labels/street}/centroid.js +5 -5
- package/out/labels/street/centroid.js.map +1 -0
- package/out/{interpolation.d.ts → labels/street/interpolation.d.ts} +6 -1
- package/out/labels/street/interpolation.d.ts.map +1 -0
- package/out/{interpolation.js → labels/street/interpolation.js} +10 -8
- package/out/labels/street/interpolation.js.map +1 -0
- package/out/labels/street/locale.d.ts +26 -0
- package/out/labels/street/locale.d.ts.map +1 -0
- package/out/labels/street/locale.js +98 -0
- package/out/labels/street/locale.js.map +1 -0
- package/out/labels/street/morphology/fst/builder.d.ts.map +1 -0
- package/out/labels/street/morphology/fst/builder.js.map +1 -0
- package/out/labels/street/morphology/fst/loader.d.ts.map +1 -0
- package/out/{street → labels/street}/morphology/fst/loader.js +1 -1
- package/out/labels/street/morphology/fst/loader.js.map +1 -0
- package/out/labels/street/name-lookup.d.ts.map +1 -0
- package/out/{street → labels/street}/name-lookup.js +2 -0
- package/out/labels/street/name-lookup.js.map +1 -0
- package/out/labels/street/normalize.d.ts +188 -0
- package/out/labels/street/normalize.d.ts.map +1 -0
- package/out/{street → labels/street}/normalize.js +200 -119
- package/out/labels/street/normalize.js.map +1 -0
- package/out/{street → labels/street}/segment-schema.d.ts +1 -1
- package/out/labels/street/segment-schema.d.ts.map +1 -0
- package/out/labels/street/segment-schema.js.map +1 -0
- package/out/labels/street/table.d.ts.map +1 -0
- package/out/{street → labels/street}/table.js +1 -1
- package/out/labels/street/table.js.map +1 -0
- package/out/labels/street.d.ts +9 -0
- package/out/labels/street.d.ts.map +1 -0
- package/out/labels/street.js +11 -0
- package/out/labels/street.js.map +1 -0
- package/out/landmark/rows.js +1 -1
- package/out/landmark/rows.js.map +1 -1
- package/out/lookup/browse.d.ts +79 -0
- package/out/lookup/browse.d.ts.map +1 -0
- package/out/lookup/browse.js +194 -0
- package/out/lookup/browse.js.map +1 -0
- package/out/lookup/exact-match.d.ts.map +1 -0
- package/out/lookup/exact-match.js.map +1 -0
- package/out/lookup/extracts.d.ts.map +1 -0
- package/out/{extracts.js → lookup/extracts.js} +1 -1
- package/out/lookup/extracts.js.map +1 -0
- package/out/lookup/former-divisions.d.ts +99 -0
- package/out/lookup/former-divisions.d.ts.map +1 -0
- package/out/lookup/former-divisions.js +98 -0
- package/out/lookup/former-divisions.js.map +1 -0
- package/out/{postcode-point-lookup.d.ts → lookup/postcode-point.d.ts} +5 -1
- package/out/lookup/postcode-point.d.ts.map +1 -0
- package/out/{postcode-point-lookup.js → lookup/postcode-point.js} +1 -1
- package/out/lookup/postcode-point.js.map +1 -0
- package/out/{reverse.d.ts → lookup/reverse.d.ts} +1 -1
- package/out/lookup/reverse.d.ts.map +1 -0
- package/out/{reverse.js → lookup/reverse.js} +3 -3
- package/out/lookup/reverse.js.map +1 -0
- package/out/{types.d.ts → lookup/types.d.ts} +9 -0
- package/out/lookup/types.d.ts.map +1 -0
- package/out/lookup/types.js.map +1 -0
- package/out/lookup.d.ts +4 -4
- package/out/lookup.d.ts.map +1 -1
- package/out/lookup.js +14 -20
- package/out/lookup.js.map +1 -1
- package/out/poi/schema.d.ts +1 -1
- package/out/poi/schema.d.ts.map +1 -1
- package/out/ranking/name-score.d.ts.map +1 -0
- package/out/ranking/name-score.js.map +1 -0
- package/out/{primary-preference.d.ts → ranking/primary-preference.d.ts} +20 -1
- package/out/ranking/primary-preference.d.ts.map +1 -0
- package/out/{primary-preference.js → ranking/primary-preference.js} +35 -1
- package/out/ranking/primary-preference.js.map +1 -0
- package/out/ranking/proximity-rerank.d.ts.map +1 -0
- package/out/ranking/proximity-rerank.js.map +1 -0
- package/out/{ranking-weights.d.ts → ranking/weights.d.ts} +1 -1
- package/out/ranking/weights.d.ts.map +1 -0
- package/out/{ranking-weights.js → ranking/weights.js} +1 -1
- package/out/ranking/weights.js.map +1 -0
- package/out/schema/importance-source.d.ts +90 -0
- package/out/schema/importance-source.d.ts.map +1 -0
- package/out/schema/importance-source.js +133 -0
- package/out/schema/importance-source.js.map +1 -0
- package/out/schema/overture-match.d.ts +53 -0
- package/out/schema/overture-match.d.ts.map +1 -0
- package/out/schema/overture-match.js +33 -0
- package/out/schema/overture-match.js.map +1 -0
- package/out/{place-importance-schema.d.ts → schema/place-importance.d.ts} +50 -1
- package/out/schema/place-importance.d.ts.map +1 -0
- package/out/{place-importance-schema.js → schema/place-importance.js} +34 -1
- package/out/schema/place-importance.js.map +1 -0
- package/out/{polygon-schema.d.ts → schema/polygon.d.ts} +1 -1
- package/out/schema/polygon.d.ts.map +1 -0
- package/out/{polygon-schema.js → schema/polygon.js} +1 -1
- package/out/schema/polygon.js.map +1 -0
- package/out/{unified-schema.d.ts → schema/unified.d.ts} +1 -1
- package/out/schema/unified.d.ts.map +1 -0
- package/out/{unified-schema.js → schema/unified.js} +1 -1
- package/out/schema/unified.js.map +1 -0
- package/out/schema.d.ts +3 -3
- package/out/sqlite/convention-source.js +1 -1
- package/out/sqlite/convention-source.js.map +1 -1
- package/out/uprn/existence.d.ts.map +1 -1
- package/out/uprn/existence.js +2 -0
- package/out/uprn/existence.js.map +1 -1
- package/out/{weights-overlay-linker.d.ts → weights/overlay-linker.d.ts} +43 -24
- package/out/weights/overlay-linker.d.ts.map +1 -0
- package/out/{weights-overlay-linker.js → weights/overlay-linker.js} +182 -66
- package/out/weights/overlay-linker.js.map +1 -0
- package/package.json +12 -32
- package/lib/postal.ts +0 -6
- package/lib/street/locale.ts +0 -64
- package/lib/street.ts +0 -11
- package/out/candidate/extract-fold.d.ts.map +0 -1
- package/out/candidate/extract-fold.js.map +0 -1
- package/out/capital-schema.d.ts.map +0 -1
- package/out/capital-schema.js.map +0 -1
- package/out/capitals.d.ts.map +0 -1
- package/out/capitals.js.map +0 -1
- package/out/coverage-manifest-schema.d.ts.map +0 -1
- package/out/coverage-manifest-schema.js.map +0 -1
- package/out/exact-match.d.ts.map +0 -1
- package/out/exact-match.js.map +0 -1
- package/out/extracts.d.ts.map +0 -1
- package/out/extracts.js.map +0 -1
- package/out/interpolation.d.ts.map +0 -1
- package/out/interpolation.js.map +0 -1
- package/out/name-score.d.ts.map +0 -1
- package/out/name-score.js.map +0 -1
- package/out/place-importance-schema.d.ts.map +0 -1
- package/out/place-importance-schema.js.map +0 -1
- package/out/polygon-schema.d.ts.map +0 -1
- package/out/polygon-schema.js.map +0 -1
- package/out/postal/city/alias/lookup.d.ts.map +0 -1
- package/out/postal/city/alias/lookup.js.map +0 -1
- package/out/postal/city/alias/schema.d.ts.map +0 -1
- package/out/postal/city/alias/schema.js.map +0 -1
- package/out/postal/city/candidate-schema.d.ts.map +0 -1
- package/out/postal/city/candidate-schema.js.map +0 -1
- package/out/postal.d.ts +0 -4
- package/out/postal.d.ts.map +0 -1
- package/out/postal.js +0 -6
- package/out/postal.js.map +0 -1
- package/out/postcode-point-lookup.d.ts.map +0 -1
- package/out/postcode-point-lookup.js.map +0 -1
- package/out/primary-preference.d.ts.map +0 -1
- package/out/primary-preference.js.map +0 -1
- package/out/proximity-rerank.d.ts.map +0 -1
- package/out/proximity-rerank.js.map +0 -1
- package/out/ranking-weights.d.ts.map +0 -1
- package/out/ranking-weights.js.map +0 -1
- package/out/region-keys.js.map +0 -1
- package/out/reverse.d.ts.map +0 -1
- package/out/reverse.js.map +0 -1
- package/out/search-fetch.d.ts.map +0 -1
- package/out/search-fetch.js.map +0 -1
- package/out/street/centroid/schema.d.ts.map +0 -1
- package/out/street/centroid/schema.js.map +0 -1
- package/out/street/centroid.d.ts.map +0 -1
- package/out/street/centroid.js.map +0 -1
- package/out/street/locale.d.ts +0 -12
- package/out/street/locale.d.ts.map +0 -1
- package/out/street/locale.js +0 -54
- package/out/street/locale.js.map +0 -1
- package/out/street/morphology/fst/builder.d.ts.map +0 -1
- package/out/street/morphology/fst/builder.js.map +0 -1
- package/out/street/morphology/fst/loader.d.ts.map +0 -1
- package/out/street/morphology/fst/loader.js.map +0 -1
- package/out/street/name-lookup.d.ts.map +0 -1
- package/out/street/name-lookup.js.map +0 -1
- package/out/street/normalize.d.ts +0 -111
- package/out/street/normalize.d.ts.map +0 -1
- package/out/street/normalize.js.map +0 -1
- package/out/street/segment-schema.d.ts.map +0 -1
- package/out/street/segment-schema.js.map +0 -1
- package/out/street/table.d.ts.map +0 -1
- package/out/street/table.js.map +0 -1
- package/out/street.d.ts +0 -9
- package/out/street.d.ts.map +0 -1
- package/out/street.js +0 -11
- package/out/street.js.map +0 -1
- package/out/types.d.ts.map +0 -1
- package/out/types.js.map +0 -1
- package/out/unified-schema.d.ts.map +0 -1
- package/out/unified-schema.js.map +0 -1
- package/out/weights-overlay-linker.d.ts.map +0 -1
- package/out/weights-overlay-linker.js.map +0 -1
- /package/lib/{coverage-manifest-schema.ts → candidate/coverage-manifest.ts} +0 -0
- /package/lib/{postal/city → labels/locality/postal-city}/alias/schema.ts +0 -0
- /package/lib/{street → labels/street}/morphology/fst/builder.ts +0 -0
- /package/lib/{exact-match.ts → lookup/exact-match.ts} +0 -0
- /package/lib/{name-score.ts → ranking/name-score.ts} +0 -0
- /package/lib/{proximity-rerank.ts → ranking/proximity-rerank.ts} +0 -0
- /package/lib/{ranking-weights.ts → ranking/weights.ts} +0 -0
- /package/lib/{polygon-schema.ts → schema/polygon.ts} +0 -0
- /package/lib/{unified-schema.ts → schema/unified.ts} +0 -0
- /package/out/{capitals.d.ts → candidate/capitals.d.ts} +0 -0
- /package/out/{search-fetch.js → fts/search-fetch.js} +0 -0
- /package/out/{postal/city → labels/locality/postal-city}/alias/lookup.js +0 -0
- /package/out/{postal/city → labels/locality/postal-city}/alias/schema.d.ts +0 -0
- /package/out/{postal/city → labels/locality/postal-city}/alias/schema.js +0 -0
- /package/out/{postal/city → labels/locality/postal-city}/candidate-schema.js +0 -0
- /package/out/{street → labels/street}/centroid/schema.js +0 -0
- /package/out/{street → labels/street}/morphology/fst/builder.d.ts +0 -0
- /package/out/{street → labels/street}/morphology/fst/builder.js +0 -0
- /package/out/{street → labels/street}/morphology/fst/loader.d.ts +0 -0
- /package/out/{street → labels/street}/name-lookup.d.ts +0 -0
- /package/out/{street → labels/street}/segment-schema.js +0 -0
- /package/out/{street → labels/street}/table.d.ts +0 -0
- /package/out/{exact-match.d.ts → lookup/exact-match.d.ts} +0 -0
- /package/out/{exact-match.js → lookup/exact-match.js} +0 -0
- /package/out/{extracts.d.ts → lookup/extracts.d.ts} +0 -0
- /package/out/{types.js → lookup/types.js} +0 -0
- /package/out/{name-score.d.ts → ranking/name-score.d.ts} +0 -0
- /package/out/{name-score.js → ranking/name-score.js} +0 -0
- /package/out/{proximity-rerank.d.ts → ranking/proximity-rerank.d.ts} +0 -0
- /package/out/{proximity-rerank.js → ranking/proximity-rerank.js} +0 -0
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Phase 4.2 of the mailwoman neural-resolver plan — see [`docs/plan/phases/PHASE
|
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
|
-
```
|
|
9
|
+
```sh npm2yarn
|
|
10
10
|
npm install @mailwoman/resolver-wof-sqlite
|
|
11
11
|
```
|
|
12
12
|
|
|
@@ -90,7 +90,7 @@ The Geocode Earth team mirrors WOF SQLite distributions at <https://data.geocode
|
|
|
90
90
|
| `whosonfirst-data-admin-us-latest.db.bz2` | ~845 MB | US administrative places (country / region / locality / borough). |
|
|
91
91
|
| `whosonfirst-data-postalcode-us-latest.db.bz2` | ~320 MB | US postcodes. |
|
|
92
92
|
|
|
93
|
-
```
|
|
93
|
+
```sh
|
|
94
94
|
curl -L -o whosonfirst-data-admin-us-latest.db.bz2 \
|
|
95
95
|
https://data.geocode.earth/wof/dist/sqlite/whosonfirst-data-admin-us-latest.db.bz2
|
|
96
96
|
bunzip2 whosonfirst-data-admin-us-latest.db.bz2
|
|
@@ -107,7 +107,7 @@ Upstream WOF SQLite distributions ship a `places` table but **not** an FTS5 inde
|
|
|
107
107
|
|
|
108
108
|
A one-shot operator script ships with this package as a `bin`:
|
|
109
109
|
|
|
110
|
-
```
|
|
110
|
+
```sh
|
|
111
111
|
mailwoman gazetteer build fts /path/to/whosonfirst-data-admin-us-latest.db
|
|
112
112
|
```
|
|
113
113
|
|
|
@@ -122,7 +122,7 @@ The CLI:
|
|
|
122
122
|
`populating-bbox` and `done`.
|
|
123
123
|
- Exits 0 with a no-op message if both indexes already exist.
|
|
124
124
|
|
|
125
|
-
```
|
|
125
|
+
```sh
|
|
126
126
|
# Refresh after pulling a newer WOF dump
|
|
127
127
|
mailwoman gazetteer build fts /path/to/wof.db --drop
|
|
128
128
|
```
|
|
@@ -133,7 +133,7 @@ mailwoman gazetteer build fts /path/to/wof.db --drop
|
|
|
133
133
|
|
|
134
134
|
Builds a trimmed WOF SQLite distribution sized for browser-side deployments (Path B of the demo plan). The full admin-US distribution is ~4 GB. A slim US bundle with the top-1k localities by population plus all postcodes lands at **~35 MB**, small enough to ship as a static asset.
|
|
135
135
|
|
|
136
|
-
```
|
|
136
|
+
```sh
|
|
137
137
|
# Defaults: --top 1000 localities, --countries US, drops geojson after building aux tables
|
|
138
138
|
# The slim wof-hot.db distribution is RETIRED (2026-06-20): the demo byte-range-resolves
|
|
139
139
|
# against the global candidate table. `buildSlimWOFDatabase` remains importable from
|
package/lib/address/duplicate.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { haversine } from "@mailwoman/spatial/geometries/point/distance"
|
|
10
10
|
|
|
11
|
-
import { normalizeLocalityForKey } from "#street/normalize"
|
|
11
|
+
import { normalizeLocalityForKey } from "#labels/street/normalize"
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* The farthest apart two records' points may lie, in kilometers, while their localities disagree.
|
|
@@ -13,6 +13,11 @@ import { dirname, resolvePathBuilder, type PathBuilder, type PathBuilderLike } f
|
|
|
13
13
|
import { addressLayerFiles } from "#address/keys/layout"
|
|
14
14
|
import type { AddressDetailDatabase, AddressLookupDatabase } from "#address/keys/schema"
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* The name of the ledger file beside each region's `lookup.db`.
|
|
18
|
+
*/
|
|
19
|
+
export const ADDRESS_LAYER_ATTRIBUTION_FILE = "ATTRIBUTION.json"
|
|
20
|
+
|
|
16
21
|
/**
|
|
17
22
|
* One source and authority of a region's rows, with the terms the source records.
|
|
18
23
|
*/
|
|
@@ -111,7 +116,7 @@ export async function writeAddressLayerAttribution(
|
|
|
111
116
|
})
|
|
112
117
|
.toSorted((left, right) => right.records - left.records)
|
|
113
118
|
|
|
114
|
-
const path = resolvePathBuilder(dirname(files.lookup),
|
|
119
|
+
const path = resolvePathBuilder(dirname(files.lookup), ADDRESS_LAYER_ATTRIBUTION_FILE)
|
|
115
120
|
|
|
116
121
|
await writeLocalJSONFile(entries, path)
|
|
117
122
|
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
import { ByteFormatter } from "@mailwoman/core/fs/formatters"
|
|
13
13
|
import { readFilesystemSpace, statPath } from "@mailwoman/core/fs/readers/stat"
|
|
14
14
|
import { makeDirectories, removePathIfPresent } from "@mailwoman/core/fs/writers"
|
|
15
|
-
import { parseJSONStrict, stringifyJSON } from "@mailwoman/core/json"
|
|
16
15
|
import { sourcePresentCoverageCells } from "@mailwoman/core/layers"
|
|
17
16
|
import { type LayerManifest, writeLayerCoverage, writeLayerManifest } from "@mailwoman/core/layers/manifest"
|
|
18
17
|
import { createLayerCoverageTable, createLayerManifestTable } from "@mailwoman/core/layers/schema"
|
|
18
|
+
import { parseJSONStrict, stringifyJSON } from "@mailwoman/core/values/json"
|
|
19
19
|
import { shortCellToInt } from "@mailwoman/spatial"
|
|
20
20
|
import { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
21
21
|
import { buildSealedArtifact } from "@mailwoman/sqlite/sealed/build"
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
* so code holds no list of countries or subdivisions.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import { type RecordedFile, sha256File } from "@mailwoman/core/crypto/hash"
|
|
13
14
|
import { readLocalJSONFile, sortedGlob } from "@mailwoman/core/fs/readers"
|
|
14
15
|
import { pathExists, statPath } from "@mailwoman/core/fs/readers/stat"
|
|
15
16
|
import { writeLocalJSONFile } from "@mailwoman/core/fs/writers"
|
|
16
|
-
import { type RecordedFile, sha256File } from "@mailwoman/core/hash"
|
|
17
17
|
import { relative, resolvePathBuilder, type PathBuilder, type PathBuilderLike } from "path-ts"
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -151,6 +151,32 @@ export async function readLatestAddressLayerManifest(
|
|
|
151
151
|
return newest ? readLocalJSONFile<AddressLayerCountryManifest>(newest) : null
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
/**
|
|
155
|
+
* The newest manifest of every country that has an address layer under `root`, ordered by country.
|
|
156
|
+
*
|
|
157
|
+
* A root with no `addresses` directory, or with zero manifests in it, answers an empty list.
|
|
158
|
+
* A reader therefore learns which countries have a layer by reading the root, and holds no list of them.
|
|
159
|
+
*
|
|
160
|
+
* @throws When a manifest exists and can't be read.
|
|
161
|
+
*/
|
|
162
|
+
export async function readLatestAddressLayerManifests(root: PathBuilderLike): Promise<AddressLayerCountryManifest[]> {
|
|
163
|
+
const layerDir = resolvePathBuilder(root, "addresses")
|
|
164
|
+
|
|
165
|
+
if (!(await pathExists(layerDir))) return []
|
|
166
|
+
|
|
167
|
+
// A manifest sits at `<country>/<version>/manifest.json`.
|
|
168
|
+
// Versions are ISO dates, so within one country's directory the last path is the newest.
|
|
169
|
+
const paths = await sortedGlob(layerDir, "*/*/manifest.json")
|
|
170
|
+
const manifests = await Promise.all(paths.map((path) => readLocalJSONFile<AddressLayerCountryManifest>(path)))
|
|
171
|
+
const newest = new Map<string, AddressLayerCountryManifest>()
|
|
172
|
+
|
|
173
|
+
for (const manifest of manifests) {
|
|
174
|
+
newest.set(manifest.country.toUpperCase(), manifest)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return [...newest.values()].toSorted((left, right) => left.country.localeCompare(right.country))
|
|
178
|
+
}
|
|
179
|
+
|
|
154
180
|
/**
|
|
155
181
|
* Writes a country's manifest beside its files, after every region it lists is built.
|
|
156
182
|
*/
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
|
|
13
13
|
import { addressPostcodeKey } from "#address/keys/postcode"
|
|
14
14
|
import { houseNumberForms } from "#address/number-forms"
|
|
15
|
-
import { streetLocaleForCountry } from "#street/locale"
|
|
15
|
+
import { streetLocaleForCountry } from "#labels/street/locale"
|
|
16
16
|
import {
|
|
17
17
|
normalizeHouseNumberForKey,
|
|
18
18
|
normalizeLocalityForKey,
|
|
19
19
|
type StreetLocale,
|
|
20
20
|
streetKeyVariants,
|
|
21
21
|
streetLocaleForSurface,
|
|
22
|
-
} from "#street/normalize"
|
|
22
|
+
} from "#labels/street/normalize"
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* The one capability the reader needs from a database: run a parameterized `SELECT` and return its rows.
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* `lookup.db` through `AddressKeyLookup`.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import { memoizeResettable } from "@mailwoman/core/memoize"
|
|
9
|
+
import { memoizeResettable } from "@mailwoman/core/async/memoize"
|
|
11
10
|
import type { AddressPointHit, AddressPointLookup } from "@mailwoman/core/resolver"
|
|
11
|
+
import { parseJSONStrict } from "@mailwoman/core/values/json"
|
|
12
12
|
import { type LatLonBounds, latLonBoundsContain } from "@mailwoman/spatial/bbox"
|
|
13
13
|
|
|
14
14
|
import {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { isJoinedHouseNumber } from "@mailwoman/match/address-point"
|
|
5
5
|
|
|
6
|
-
import type
|
|
6
|
+
import { streetKeyRulesOf, type StreetLocale } from "#labels/street/normalize"
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The forms a normalized house number is probed under, the written form first,
|
|
@@ -51,11 +51,9 @@ export function* houseNumberForms(number: string, locale: StreetLocale): Generat
|
|
|
51
51
|
yield spaced[1]!
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
const base = /^(\d+)(?:[之附]\d+)+$/u.exec(number)?.[1]
|
|
54
|
+
const base = streetKeyRulesOf(locale).houseNumberBase?.exec(number)?.[1]
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
56
|
+
if (base) {
|
|
57
|
+
yield base
|
|
60
58
|
}
|
|
61
59
|
}
|
|
@@ -39,9 +39,17 @@ import { haversine } from "@mailwoman/spatial/geometries/point/distance"
|
|
|
39
39
|
import { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
40
40
|
|
|
41
41
|
import type { AddressPointDatabase } from "#address/point/schema"
|
|
42
|
-
import type { InterpolatedHit, InterpolationQuery, StreetInterpolator } from "#interpolation"
|
|
42
|
+
import type { InterpolatedHit, InterpolationQuery, StreetInterpolator } from "#labels/street/interpolation"
|
|
43
|
+
import { streetLocaleForCountry } from "#labels/street/locale"
|
|
44
|
+
import { canonicalizeRouteKey, type RouteKey, streetKeyVariants } from "#labels/street/normalize"
|
|
43
45
|
import { hasTable, prepareAll, type PreparedAll } from "#sqlite-utils"
|
|
44
|
-
|
|
46
|
+
|
|
47
|
+
// country-branch: this reader is opened over the United States' state extracts only.
|
|
48
|
+
// A street locale passed by the provider that opens an extract would replace the constant.
|
|
49
|
+
/**
|
|
50
|
+
* The street locale the extracts this reader interpolates over are keyed under.
|
|
51
|
+
*/
|
|
52
|
+
const EXTRACT_STREET_LOCALE = streetLocaleForCountry("US")
|
|
45
53
|
/**
|
|
46
54
|
* Extrapolation cap for a single-sided bracket: at most one pair-span beyond
|
|
47
55
|
* the nearest known point (`t = 2`).
|
|
@@ -125,7 +133,7 @@ export class AddressPointInterpolator<
|
|
|
125
133
|
// Key-variant ladder (see `streetKeyVariants`), the same probe order as the exact-point reader.
|
|
126
134
|
let rows: PointRow[] = []
|
|
127
135
|
|
|
128
|
-
for (const variant of streetKeyVariants(query.street)) {
|
|
136
|
+
for (const variant of streetKeyVariants(query.street, EXTRACT_STREET_LOCALE)) {
|
|
129
137
|
const streetKey = canonicalizeRouteKey(variant)
|
|
130
138
|
|
|
131
139
|
rows = this.#byPostcode(query.postcode.trim(), streetKey, n)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { Kysely } from "kysely"
|
|
5
5
|
|
|
6
|
-
import type { NameKey, RouteKey, StreetKey } from "#street/normalize"
|
|
6
|
+
import type { NameKey, RouteKey, StreetKey } from "#labels/street/normalize"
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* One rooftop address point; `(street_norm, number)` within a `postcode`
|
package/lib/address/point.ts
CHANGED
|
@@ -13,18 +13,18 @@ import type { PathBuilderLike } from "path-ts"
|
|
|
13
13
|
|
|
14
14
|
import { houseNumberForms } from "#address/number-forms"
|
|
15
15
|
import type { AddressPointDatabase, AddressPointTable } from "#address/point/schema"
|
|
16
|
-
import { hasTable, prepareGet, type PreparedGet } from "#sqlite-utils"
|
|
17
16
|
import {
|
|
18
17
|
normalizeHouseNumberForKey,
|
|
19
|
-
normalizeLocalityForKey,
|
|
20
|
-
normalizeLocalityForKeyLocale,
|
|
21
18
|
type NameKey,
|
|
22
19
|
type StreetKey,
|
|
20
|
+
type StreetKeyRules,
|
|
21
|
+
streetKeyRulesOf,
|
|
23
22
|
streetKeyVariants,
|
|
24
23
|
streetLocaleForSurface,
|
|
25
24
|
stripArrondissement,
|
|
26
25
|
type StreetLocale,
|
|
27
|
-
} from "#street/normalize"
|
|
26
|
+
} from "#labels/street/normalize"
|
|
27
|
+
import { hasTable, prepareGet, type PreparedGet } from "#sqlite-utils"
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* The columns this lookup reads, typed from the shared {@link AddressPointTable}
|
|
@@ -54,6 +54,7 @@ export class AddressPointSqliteLookup<DB extends AddressPointDatabase = AddressP
|
|
|
54
54
|
{
|
|
55
55
|
readonly #db: DatabaseClient<DB>
|
|
56
56
|
readonly #locale: StreetLocale
|
|
57
|
+
readonly #rules: StreetKeyRules
|
|
57
58
|
readonly #localityKeys: "full" | "abbreviated"
|
|
58
59
|
readonly #localityLevel: "place" | "finest"
|
|
59
60
|
readonly #byPostcode: PreparedGet<[postcode: string, street: StreetKey, number: string], AddressPointRow> | undefined
|
|
@@ -101,21 +102,21 @@ export class AddressPointSqliteLookup<DB extends AddressPointDatabase = AddressP
|
|
|
101
102
|
* The OSM builder stores `addr:suburb` before `addr:city`, so
|
|
102
103
|
* `Teschener Weg 5, 14163 Berlin` is stored under `zehlendorf`.
|
|
103
104
|
*
|
|
104
|
-
* @defaultValue `
|
|
105
|
-
* @defaultValue `"abbreviated"` for `"us"` and `"full"` for every other locale.
|
|
105
|
+
* @defaultValue The locale's own `localityKeys` rule.
|
|
106
106
|
* @defaultValue `"place"`
|
|
107
107
|
*/
|
|
108
108
|
constructor(
|
|
109
109
|
dbPath: PathBuilderLike,
|
|
110
110
|
opts: {
|
|
111
|
-
streetLocale
|
|
111
|
+
streetLocale: StreetLocale
|
|
112
112
|
localityKeys?: "full" | "abbreviated"
|
|
113
113
|
localityLevel?: "place" | "finest"
|
|
114
|
-
}
|
|
114
|
+
}
|
|
115
115
|
) {
|
|
116
116
|
this.#db = new DatabaseClient<DB>(dbPath, { readOnly: true })
|
|
117
|
-
this.#locale = opts.streetLocale
|
|
118
|
-
this.#
|
|
117
|
+
this.#locale = opts.streetLocale
|
|
118
|
+
this.#rules = streetKeyRulesOf(opts.streetLocale)
|
|
119
|
+
this.#localityKeys = opts.localityKeys ?? this.#rules.localityKeys
|
|
119
120
|
this.#localityLevel = opts.localityLevel ?? "place"
|
|
120
121
|
|
|
121
122
|
// An extract without an `address_point` table, such as an interrupted build, makes every lookup miss.
|
|
@@ -179,10 +180,10 @@ export class AddressPointSqliteLookup<DB extends AddressPointDatabase = AddressP
|
|
|
179
180
|
// The Taiwanese register has no postcode, so this pair becomes the locality key.
|
|
180
181
|
// A query with only the 鄉鎮市區 matches the stored key by its suffix.
|
|
181
182
|
const scoped =
|
|
182
|
-
this.#
|
|
183
|
+
this.#rules.localityFromRegionAndSubregion && !query.locality && query.subregion
|
|
183
184
|
? query.region
|
|
184
185
|
? { ...query, locality: `${query.region}${query.subregion}` }
|
|
185
|
-
: { ...query, localityTail:
|
|
186
|
+
: { ...query, localityTail: this.#rules.localityKey(query.subregion) }
|
|
186
187
|
: query
|
|
187
188
|
|
|
188
189
|
// `streetKeyVariants` yields the literal key first.
|
|
@@ -301,9 +302,9 @@ export class AddressPointSqliteLookup<DB extends AddressPointDatabase = AddressP
|
|
|
301
302
|
* and "Paris" produce the same key.
|
|
302
303
|
*/
|
|
303
304
|
#localityKey(locality: string): NameKey {
|
|
304
|
-
|
|
305
|
+
const key = this.#rules.localityKey(locality)
|
|
305
306
|
|
|
306
|
-
return
|
|
307
|
+
return this.#rules.arrondissementAtBaseCity ? stripArrondissement(key) : key
|
|
307
308
|
}
|
|
308
309
|
|
|
309
310
|
/**
|
package/lib/address/record.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import type { ADMIN_HIERARCHY_TAGS } from "@mailwoman/codex/component"
|
|
9
9
|
|
|
10
|
-
import { type NameKey, normalizeLocalityForKey, type RouteKey, type StreetKey } from "#street/normalize"
|
|
10
|
+
import { type NameKey, normalizeLocalityForKey, type RouteKey, type StreetKey } from "#labels/street/normalize"
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* The hierarchy level a place name on an address record states, as the encoder model tags it.
|
package/lib/ancestry/backfill.ts
CHANGED
|
@@ -7,71 +7,41 @@
|
|
|
7
7
|
* Must run after `populateAncestors` and before the build freezes.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import type { WOFFeature } from "@mailwoman/gazetteer/whosonfirst"
|
|
11
11
|
import { hierarchyAncestorsInAnyBranch } from "@mailwoman/gazetteer/whosonfirst/hierarchy"
|
|
12
12
|
import type { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
13
|
-
import { PathBuilder, type PathBuilderLike } from "path-ts"
|
|
14
|
-
import { Globerator } from "spliterator/node/fs"
|
|
15
13
|
|
|
16
14
|
import type { WOFDatabase } from "#schema"
|
|
17
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Reads the WOF record with an id, such as a primary-key read of the WOF record store, or returns `null`.
|
|
18
|
+
*/
|
|
19
|
+
export type WOFFeatureReader = (
|
|
20
|
+
id: number
|
|
21
|
+
) => Pick<WOFFeature, "properties"> | null | Promise<Pick<WOFFeature, "properties"> | null>
|
|
22
|
+
|
|
18
23
|
const TOP_PLACETYPES = new Set(["country", "continent", "empire", "ocean", "marinearea", "planet"])
|
|
19
24
|
|
|
20
25
|
export interface AncestryBackfillResult {
|
|
21
26
|
placesFixed: number
|
|
22
27
|
rowsAdded: number
|
|
23
28
|
/**
|
|
24
|
-
* Candidates
|
|
29
|
+
* Candidates the reader returned no record for (non-WOF backfilled places or absent repos),
|
|
25
30
|
* skipped rather than treated as an error.
|
|
26
31
|
*/
|
|
27
32
|
noGeojson: number
|
|
28
33
|
}
|
|
29
34
|
|
|
30
|
-
/**
|
|
31
|
-
* Discover the `data` directories under a WOF repos root that hold attached geojson,
|
|
32
|
-
* accepting both the nested lab layout and a flat layout at most two directory levels deep.
|
|
33
|
-
*/
|
|
34
|
-
export async function discoverAdminDataRoots(reposRoot: PathBuilderLike): Promise<PathBuilder[]> {
|
|
35
|
-
const roots: PathBuilder[] = []
|
|
36
|
-
|
|
37
|
-
const visit = async (dir: PathBuilder, depth: number): Promise<void> => {
|
|
38
|
-
if (depth > 2) return
|
|
39
|
-
|
|
40
|
-
let names: string[]
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
names = (await Globerator.from("*", { cwd: dir, withFileTypes: true, onlyFiles: false }).toArray())
|
|
44
|
-
.filter((entry) => entry.isDirectory())
|
|
45
|
-
.map((entry) => entry.name)
|
|
46
|
-
} catch {
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
for (const name of names) {
|
|
51
|
-
const child = dir(name)
|
|
52
|
-
|
|
53
|
-
if (name === "data") {
|
|
54
|
-
roots.push(child)
|
|
55
|
-
} else if (name.startsWith("whosonfirst-data")) {
|
|
56
|
-
await visit(child, depth + 1)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
await visit(PathBuilder.from(reposRoot), 0)
|
|
62
|
-
|
|
63
|
-
return roots
|
|
64
|
-
}
|
|
65
|
-
|
|
66
35
|
/**
|
|
67
36
|
* Insert missing ancestor rows for places whose ancestry chain ended before reaching a country.
|
|
68
37
|
*
|
|
69
|
-
* The function reads `wof:hierarchy`
|
|
38
|
+
* The function reads each candidate's `wof:hierarchy` through `readFeature`
|
|
39
|
+
* and runs in one transaction under the caller's connection.
|
|
70
40
|
* `opts.maxID` bounds the scan to avoid probing synthetic-id Overture and GeoNames rows.
|
|
71
41
|
*/
|
|
72
42
|
export async function backfillAncestorsFromHierarchy(
|
|
73
43
|
db: DatabaseClient<WOFDatabase>,
|
|
74
|
-
|
|
44
|
+
readFeature: WOFFeatureReader,
|
|
75
45
|
opts: { maxID?: number } = {}
|
|
76
46
|
): Promise<AncestryBackfillResult> {
|
|
77
47
|
const maxID = opts.maxID ?? Number.MAX_SAFE_INTEGER
|
|
@@ -124,7 +94,7 @@ export async function backfillAncestorsFromHierarchy(
|
|
|
124
94
|
|
|
125
95
|
for (const { id, placetype } of candidates) {
|
|
126
96
|
if (placetype && TOP_PLACETYPES.has(placetype)) continue
|
|
127
|
-
const gj = await
|
|
97
|
+
const gj = await readFeature(id)
|
|
128
98
|
const hierarchy = gj?.properties?.["wof:hierarchy"]
|
|
129
99
|
|
|
130
100
|
if (!hierarchy || !hierarchy.length) {
|