@mailwoman/core 9.1.0 → 9.2.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 +1 -1
- package/api/responses.ts +12 -0
- package/coarse-placer/featurize.ts +0 -2
- package/coarse-placer/tools/build-dataset.ts +1 -1
- package/coarse-placer/tools/build-outlier-exposure.ts +1 -1
- package/coarse-placer/tools/build-outlier-latin.ts +13 -7
- package/coarse-placer/tools/build-outlier-oa.ts +11 -5
- package/coarse-placer/tools/eval-latin-offmap.ts +3 -2
- package/coarse-placer/tools/eval-openset.ts +3 -2
- package/coarse-placer/tools/eval-quant-compare.ts +3 -2
- package/coarse-placer/tools/eval.ts +3 -2
- package/coarse-placer/tools/fnv-hash.ts +1 -6
- package/coarse-placer/tools/index.ts +1 -1
- package/coarse-placer/tools/probe-frontier.ts +3 -2
- package/coarse-placer/tools/quantize.ts +2 -2
- package/coarse-placer/tools/train.ts +2 -1
- package/crypto/node.ts +3 -1
- package/data/internal/dictionaries/languages.csv +184 -184
- package/data/libpostal/README.md +8 -2
- package/db/schema.ts +12 -3
- package/decoder/containment.ts +5 -1
- package/decoder/index.ts +1 -0
- package/decoder/parse-diff.ts +347 -0
- package/decoder/proposals-to-tree.ts +1 -1
- package/decoder/serialize-json.ts +51 -7
- package/decoder/serialize-tuples.ts +7 -1
- package/decoder/serialize-xml.ts +1 -1
- package/decoder/tree-shape.ts +144 -0
- package/decoder/types.ts +8 -0
- package/decoder/validate-tree.ts +15 -3
- package/env/index.ts +3 -1
- package/env/paths.ts +21 -33
- package/env/schema.ts +26 -3
- package/fs/utils/formatters.ts +107 -0
- package/fs/utils/index.ts +7 -0
- package/fs/zip.ts +1 -1
- package/layers/manifest.ts +56 -15
- package/layers/schema.ts +54 -2
- package/locale/locale.ts +1 -1
- package/locale/registry.ts +1 -1
- package/objects.ts +20 -8
- package/out/api/responses.d.ts +9 -0
- package/out/api/responses.d.ts.map +1 -1
- package/out/api/responses.js +11 -0
- package/out/api/responses.js.map +1 -1
- package/out/coarse-placer/featurize.d.ts +0 -1
- package/out/coarse-placer/featurize.d.ts.map +1 -1
- package/out/coarse-placer/featurize.js.map +1 -1
- package/out/coarse-placer/tools/build-dataset.js +1 -1
- package/out/coarse-placer/tools/build-dataset.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-exposure.js +1 -1
- package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-latin.js +12 -7
- package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-oa.js +10 -5
- package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
- package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-latin-offmap.js +2 -2
- package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
- package/out/coarse-placer/tools/eval-openset.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-openset.js +2 -2
- package/out/coarse-placer/tools/eval-openset.js.map +1 -1
- package/out/coarse-placer/tools/eval-quant-compare.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-quant-compare.js +2 -2
- package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
- package/out/coarse-placer/tools/eval.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval.js +2 -2
- package/out/coarse-placer/tools/eval.js.map +1 -1
- package/out/coarse-placer/tools/fnv-hash.d.ts +1 -6
- package/out/coarse-placer/tools/fnv-hash.d.ts.map +1 -1
- package/out/coarse-placer/tools/fnv-hash.js +1 -6
- package/out/coarse-placer/tools/fnv-hash.js.map +1 -1
- package/out/coarse-placer/tools/index.d.ts +1 -1
- package/out/coarse-placer/tools/index.js +1 -1
- package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
- package/out/coarse-placer/tools/probe-frontier.js +2 -2
- package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
- package/out/coarse-placer/tools/quantize.js +2 -2
- package/out/coarse-placer/tools/quantize.js.map +1 -1
- package/out/coarse-placer/tools/train.d.ts.map +1 -1
- package/out/coarse-placer/tools/train.js +1 -1
- package/out/coarse-placer/tools/train.js.map +1 -1
- package/out/crypto/node.d.ts.map +1 -1
- package/out/crypto/node.js +2 -1
- package/out/crypto/node.js.map +1 -1
- package/out/db/schema.d.ts +12 -3
- package/out/db/schema.d.ts.map +1 -1
- package/out/db/schema.js +6 -0
- package/out/db/schema.js.map +1 -1
- package/out/decoder/containment.d.ts.map +1 -1
- package/out/decoder/containment.js +5 -1
- package/out/decoder/containment.js.map +1 -1
- package/out/decoder/index.d.ts +1 -0
- package/out/decoder/index.d.ts.map +1 -1
- package/out/decoder/index.js +1 -0
- package/out/decoder/index.js.map +1 -1
- package/out/decoder/parse-diff.d.ts +125 -0
- package/out/decoder/parse-diff.d.ts.map +1 -0
- package/out/decoder/parse-diff.js +219 -0
- package/out/decoder/parse-diff.js.map +1 -0
- package/out/decoder/proposals-to-tree.js.map +1 -1
- package/out/decoder/serialize-json.d.ts +29 -0
- package/out/decoder/serialize-json.d.ts.map +1 -1
- package/out/decoder/serialize-json.js +20 -4
- package/out/decoder/serialize-json.js.map +1 -1
- package/out/decoder/serialize-tuples.d.ts +8 -1
- package/out/decoder/serialize-tuples.d.ts.map +1 -1
- package/out/decoder/serialize-tuples.js +7 -1
- package/out/decoder/serialize-tuples.js.map +1 -1
- package/out/decoder/serialize-xml.js +1 -1
- package/out/decoder/serialize-xml.js.map +1 -1
- package/out/decoder/tree-shape.d.ts +84 -0
- package/out/decoder/tree-shape.d.ts.map +1 -0
- package/out/decoder/tree-shape.js +98 -0
- package/out/decoder/tree-shape.js.map +1 -0
- package/out/decoder/types.d.ts +11 -0
- package/out/decoder/types.d.ts.map +1 -1
- package/out/decoder/validate-tree.d.ts +8 -0
- package/out/decoder/validate-tree.d.ts.map +1 -1
- package/out/decoder/validate-tree.js +4 -3
- package/out/decoder/validate-tree.js.map +1 -1
- package/out/env/index.d.ts +10 -1
- package/out/env/index.d.ts.map +1 -1
- package/out/env/index.js +2 -1
- package/out/env/index.js.map +1 -1
- package/out/env/paths.d.ts +15 -8
- package/out/env/paths.d.ts.map +1 -1
- package/out/env/paths.js +19 -29
- package/out/env/paths.js.map +1 -1
- package/out/env/schema.d.ts +9 -1
- package/out/env/schema.d.ts.map +1 -1
- package/out/env/schema.js +25 -3
- package/out/env/schema.js.map +1 -1
- package/out/fs/utils/formatters.d.ts +57 -0
- package/out/fs/utils/formatters.d.ts.map +1 -0
- package/out/fs/utils/formatters.js +79 -0
- package/out/fs/utils/formatters.js.map +1 -0
- package/out/fs/utils/index.d.ts +7 -0
- package/out/fs/utils/index.d.ts.map +1 -0
- package/out/fs/utils/index.js +7 -0
- package/out/fs/utils/index.js.map +1 -0
- package/out/fs/zip.js +1 -1
- package/out/fs/zip.js.map +1 -1
- package/out/layers/manifest.d.ts +32 -7
- package/out/layers/manifest.d.ts.map +1 -1
- package/out/layers/manifest.js +31 -6
- package/out/layers/manifest.js.map +1 -1
- package/out/layers/schema.d.ts +48 -2
- package/out/layers/schema.d.ts.map +1 -1
- package/out/layers/schema.js +32 -0
- package/out/layers/schema.js.map +1 -1
- package/out/locale/locale.d.ts +1 -1
- package/out/locale/locale.d.ts.map +1 -1
- package/out/locale/registry.js +1 -1
- package/out/locale/registry.js.map +1 -1
- package/out/objects.d.ts +12 -6
- package/out/objects.d.ts.map +1 -1
- package/out/objects.js +4 -1
- package/out/objects.js.map +1 -1
- package/out/pipeline/index.d.ts +2 -6
- package/out/pipeline/index.d.ts.map +1 -1
- package/out/pipeline/index.js +1 -3
- package/out/pipeline/index.js.map +1 -1
- package/out/pipeline/runtime-pipeline.d.ts +51 -9
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.js +29 -132
- package/out/pipeline/runtime-pipeline.js.map +1 -1
- package/out/pipeline/span-proposer.js +1 -1
- package/out/pipeline/span-proposer.js.map +1 -1
- package/out/pipeline/types.d.ts +22 -14
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js.map +1 -1
- package/out/policy/defaults.d.ts +1 -1
- package/out/policy/defaults.d.ts.map +1 -1
- package/out/policy/defaults.js +1 -1
- package/out/policy/defaults.js.map +1 -1
- package/out/policy/policy.d.ts +1 -1
- package/out/policy/policy.d.ts.map +1 -1
- package/out/policy/registry.d.ts +1 -1
- package/out/policy/registry.d.ts.map +1 -1
- package/out/resolver/coverage-facts.d.ts +89 -0
- package/out/resolver/coverage-facts.d.ts.map +1 -0
- package/out/resolver/coverage-facts.js +22 -0
- package/out/resolver/coverage-facts.js.map +1 -0
- package/out/resolver/index.d.ts +2 -1
- package/out/resolver/index.d.ts.map +1 -1
- package/out/resolver/index.js +1 -0
- package/out/resolver/index.js.map +1 -1
- package/out/resolver/lookup-types.d.ts +178 -0
- package/out/resolver/lookup-types.d.ts.map +1 -0
- package/out/resolver/lookup-types.js +11 -0
- package/out/resolver/lookup-types.js.map +1 -0
- package/out/resolver/placetype-map.d.ts +71 -0
- package/out/resolver/placetype-map.d.ts.map +1 -0
- package/out/resolver/placetype-map.js +98 -0
- package/out/resolver/placetype-map.js.map +1 -0
- package/out/resolver/postcode-format.d.ts +38 -0
- package/out/resolver/postcode-format.d.ts.map +1 -0
- package/out/resolver/postcode-format.js +83 -0
- package/out/resolver/postcode-format.js.map +1 -0
- package/out/resolver/types.d.ts +271 -297
- package/out/resolver/types.d.ts.map +1 -1
- package/out/resolver/types.js +4 -97
- package/out/resolver/types.js.map +1 -1
- package/out/resources/git.d.ts +8 -1
- package/out/resources/git.d.ts.map +1 -1
- package/out/resources/git.js +4 -3
- package/out/resources/git.js.map +1 -1
- package/out/resources/languages/types.gen.d.ts +1 -1
- package/out/resources/languages/types.gen.d.ts.map +1 -1
- package/out/resources/languages/types.gen.js +40 -0
- package/out/resources/languages/types.gen.js.map +1 -1
- package/out/resources/libpostal.d.ts +2 -2
- package/out/resources/libpostal.d.ts.map +1 -1
- package/out/resources/libpostal.js +2 -2
- package/out/resources/libpostal.js.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +2 -2
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.js +28 -3
- package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
- package/out/resources/whosonfirst/loader.d.ts +2 -2
- package/out/resources/whosonfirst/loader.d.ts.map +1 -1
- package/out/resources/whosonfirst/loader.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.js +2 -2
- package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.d.ts +9 -1
- package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.js +1 -1
- package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/definition.js +1 -1
- package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/index.d.ts +1 -0
- package/out/resources/whosonfirst/placetypes/index.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/index.js +1 -0
- package/out/resources/whosonfirst/placetypes/index.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/specificity.d.ts +65 -0
- package/out/resources/whosonfirst/placetypes/specificity.d.ts.map +1 -0
- package/out/resources/whosonfirst/placetypes/specificity.js +101 -0
- package/out/resources/whosonfirst/placetypes/specificity.js.map +1 -0
- package/out/resources/whosonfirst/sharded-repo.d.ts +28 -0
- package/out/resources/whosonfirst/sharded-repo.d.ts.map +1 -1
- package/out/resources/whosonfirst/sharded-repo.js +46 -2
- package/out/resources/whosonfirst/sharded-repo.js.map +1 -1
- package/out/scripting/arguments.d.ts +27 -0
- package/out/scripting/arguments.d.ts.map +1 -0
- package/out/scripting/arguments.js +32 -0
- package/out/scripting/arguments.js.map +1 -0
- package/out/scripting/command.d.ts +28 -0
- package/out/scripting/command.d.ts.map +1 -0
- package/out/scripting/command.js +47 -0
- package/out/scripting/command.js.map +1 -0
- package/out/scripting/index.js +3 -3
- package/out/scripting/index.js.map +1 -1
- package/out/scripting/utils/index.d.ts +1 -12
- package/out/scripting/utils/index.d.ts.map +1 -1
- package/out/scripting/utils/index.js +4 -21
- package/out/scripting/utils/index.js.map +1 -1
- package/out/tools/download-libpostal-resources.d.ts.map +1 -1
- package/out/tools/download-libpostal-resources.js +4 -7
- package/out/tools/download-libpostal-resources.js.map +1 -1
- package/out/tools/download-ssl-address.d.ts +3 -3
- package/out/tools/download-ssl-address.d.ts.map +1 -1
- package/out/tools/download-ssl-address.js +26 -13
- package/out/tools/download-ssl-address.js.map +1 -1
- package/out/tools/generate-language-types.d.ts +16 -1
- package/out/tools/generate-language-types.d.ts.map +1 -1
- package/out/tools/generate-language-types.js +38 -5
- package/out/tools/generate-language-types.js.map +1 -1
- package/out/tools/index.d.ts +1 -2
- package/out/tools/index.d.ts.map +1 -1
- package/out/tools/index.js +1 -2
- package/out/tools/index.js.map +1 -1
- package/out/utils/data-root.d.ts +27 -7
- package/out/utils/data-root.d.ts.map +1 -1
- package/out/utils/data-root.js +36 -13
- package/out/utils/data-root.js.map +1 -1
- package/out/utils/hash.d.ts +2 -3
- package/out/utils/hash.d.ts.map +1 -1
- package/out/utils/hash.js +3 -3
- package/out/utils/hash.js.map +1 -1
- package/out/utils/index.d.ts +1 -0
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +1 -0
- package/out/utils/index.js.map +1 -1
- package/out/utils/jsonl.js +1 -1
- package/out/utils/jsonl.js.map +1 -1
- package/out/utils/repo.d.ts +8 -0
- package/out/utils/repo.d.ts.map +1 -1
- package/out/utils/repo.js +10 -1
- package/out/utils/repo.js.map +1 -1
- package/out/utils/sealed-db.d.ts +11 -0
- package/out/utils/sealed-db.d.ts.map +1 -1
- package/out/utils/sealed-db.js +28 -1
- package/out/utils/sealed-db.js.map +1 -1
- package/out/utils/sqlite-rows.d.ts +34 -0
- package/out/utils/sqlite-rows.d.ts.map +1 -0
- package/out/utils/sqlite-rows.js +37 -0
- package/out/utils/sqlite-rows.js.map +1 -0
- package/out/utils/stats.d.ts +1 -6
- package/out/utils/stats.d.ts.map +1 -1
- package/out/utils/stats.js +1 -6
- package/out/utils/stats.js.map +1 -1
- package/package.json +476 -7
- package/pipeline/index.ts +12 -14
- package/pipeline/runtime-pipeline.ts +29 -183
- package/pipeline/span-proposer.ts +1 -1
- package/pipeline/types.ts +26 -15
- package/policy/defaults.ts +1 -1
- package/policy/policy.ts +1 -1
- package/policy/registry.ts +1 -1
- package/resolver/coverage-facts.ts +102 -0
- package/resolver/index.ts +5 -0
- package/resolver/lookup-types.ts +174 -0
- package/resolver/placetype-map.ts +122 -0
- package/resolver/postcode-format.ts +89 -0
- package/resolver/types.ts +293 -351
- package/resources/git.ts +18 -4
- package/resources/languages/types.gen.ts +60 -0
- package/resources/libpostal.ts +4 -3
- package/resources/whosonfirst/DataSourceCache.ts +2 -1
- package/resources/whosonfirst/PlacetypeDataSource.ts +36 -11
- package/resources/whosonfirst/loader.ts +3 -2
- package/resources/whosonfirst/placetypes/Placetype.ts +3 -2
- package/resources/whosonfirst/placetypes/admin.ts +11 -2
- package/resources/whosonfirst/placetypes/definition.ts +4 -3
- package/resources/whosonfirst/placetypes/index.ts +1 -0
- package/resources/whosonfirst/placetypes/specificity.ts +114 -0
- package/resources/whosonfirst/sharded-repo.ts +55 -2
- package/scripting/arguments.ts +38 -0
- package/scripting/command.ts +55 -0
- package/scripting/index.ts +3 -3
- package/scripting/utils/index.ts +6 -23
- package/tools/download-libpostal-resources.ts +4 -7
- package/tools/download-ssl-address.ts +28 -12
- package/tools/generate-language-types.ts +39 -5
- package/tools/index.ts +1 -2
- package/utils/data-root.ts +40 -14
- package/utils/hash.ts +5 -4
- package/utils/index.ts +1 -0
- package/utils/jsonl.ts +1 -1
- package/utils/repo.ts +12 -1
- package/utils/sealed-db.ts +30 -1
- package/utils/sqlite-rows.ts +40 -0
- package/utils/stats.ts +1 -6
- package/data/libpostal/dictionaries/all/chains.txt +0 -504
- package/kysley/adapter.ts +0 -29
- package/out/kysley/adapter.d.ts +0 -13
- package/out/kysley/adapter.d.ts.map +0 -1
- package/out/kysley/adapter.js +0 -25
- package/out/kysley/adapter.js.map +0 -1
- package/out/pipeline/reconcile-lookups.d.ts +0 -39
- package/out/pipeline/reconcile-lookups.d.ts.map +0 -1
- package/out/pipeline/reconcile-lookups.js +0 -88
- package/out/pipeline/reconcile-lookups.js.map +0 -1
- package/out/pipeline/reconcile.d.ts +0 -153
- package/out/pipeline/reconcile.d.ts.map +0 -1
- package/out/pipeline/reconcile.js +0 -388
- package/out/pipeline/reconcile.js.map +0 -1
- package/out/pipeline/span-logit-aggregation.d.ts +0 -58
- package/out/pipeline/span-logit-aggregation.d.ts.map +0 -1
- package/out/pipeline/span-logit-aggregation.js +0 -117
- package/out/pipeline/span-logit-aggregation.js.map +0 -1
- package/pipeline/reconcile-lookups.ts +0 -111
- package/pipeline/reconcile.ts +0 -583
- package/pipeline/span-logit-aggregation.ts +0 -156
package/resources/git.ts
CHANGED
|
@@ -8,9 +8,10 @@ import { execFile } from "node:child_process"
|
|
|
8
8
|
import * as fs from "node:fs/promises"
|
|
9
9
|
import { promisify } from "node:util"
|
|
10
10
|
|
|
11
|
-
import { tryStat } from "@mailwoman/core/fs"
|
|
12
11
|
import { PathBuilder, type PathBuilderLike } from "path-ts"
|
|
13
12
|
|
|
13
|
+
import { tryStat } from "#fs"
|
|
14
|
+
|
|
14
15
|
const execFileAsync = promisify(execFile)
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -36,19 +37,32 @@ export async function prepareRepositoryDirectories(
|
|
|
36
37
|
return { ownerDirectory, repoDirectory, exists }
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
/**
|
|
41
|
+
* What a synchronization did, so a caller can report it.
|
|
42
|
+
*
|
|
43
|
+
* A clone and a pull differ by orders of magnitude in both time and bytes — reporting them as one "synchronized" makes
|
|
44
|
+
* a first-time clone indistinguishable from a no-op refresh while it holds the progress display still.
|
|
45
|
+
*/
|
|
46
|
+
export type SynchronizeAction = "cloned" | "pulled" | "skipped"
|
|
47
|
+
|
|
39
48
|
/**
|
|
40
49
|
* Synchronize a repository source, i.e. clone or pull the repository.
|
|
41
50
|
*/
|
|
42
|
-
export async function synchronizeRepo(
|
|
43
|
-
|
|
51
|
+
export async function synchronizeRepo(
|
|
52
|
+
source: RepositorySource,
|
|
53
|
+
localRepoDirectory: PathBuilderLike
|
|
54
|
+
): Promise<SynchronizeAction> {
|
|
55
|
+
if (source.name.includes("deprecated")) return "skipped"
|
|
44
56
|
|
|
45
57
|
const { ownerDirectory, repoDirectory, exists } = await prepareRepositoryDirectories(source, localRepoDirectory)
|
|
46
58
|
|
|
47
59
|
if (exists) {
|
|
48
60
|
await execFileAsync("git", ["pull"], { cwd: repoDirectory.toString() })
|
|
49
61
|
|
|
50
|
-
return
|
|
62
|
+
return "pulled"
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
await execFileAsync("git", ["clone", "--depth=1", source.url], { cwd: ownerDirectory.toString() })
|
|
66
|
+
|
|
67
|
+
return "cloned"
|
|
54
68
|
}
|
|
@@ -427,10 +427,12 @@ export type Alpha3bLanguageCode =
|
|
|
427
427
|
| "afr"
|
|
428
428
|
| "aka"
|
|
429
429
|
| "alb"
|
|
430
|
+
| "sqi"
|
|
430
431
|
| "amh"
|
|
431
432
|
| "ara"
|
|
432
433
|
| "arg"
|
|
433
434
|
| "arm"
|
|
435
|
+
| "hye"
|
|
434
436
|
| "asm"
|
|
435
437
|
| "ava"
|
|
436
438
|
| "ave"
|
|
@@ -439,6 +441,7 @@ export type Alpha3bLanguageCode =
|
|
|
439
441
|
| "bak"
|
|
440
442
|
| "bam"
|
|
441
443
|
| "baq"
|
|
444
|
+
| "eus"
|
|
442
445
|
| "bel"
|
|
443
446
|
| "ben"
|
|
444
447
|
| "bis"
|
|
@@ -446,19 +449,23 @@ export type Alpha3bLanguageCode =
|
|
|
446
449
|
| "bre"
|
|
447
450
|
| "bul"
|
|
448
451
|
| "bur"
|
|
452
|
+
| "mya"
|
|
449
453
|
| "cat"
|
|
450
454
|
| "cha"
|
|
451
455
|
| "che"
|
|
452
456
|
| "chi"
|
|
457
|
+
| "zho"
|
|
453
458
|
| "chu"
|
|
454
459
|
| "chv"
|
|
455
460
|
| "cor"
|
|
456
461
|
| "cos"
|
|
457
462
|
| "cre"
|
|
458
463
|
| "cze"
|
|
464
|
+
| "ces"
|
|
459
465
|
| "dan"
|
|
460
466
|
| "div"
|
|
461
467
|
| "dut"
|
|
468
|
+
| "nld"
|
|
462
469
|
| "dzo"
|
|
463
470
|
| "eng"
|
|
464
471
|
| "epo"
|
|
@@ -468,15 +475,19 @@ export type Alpha3bLanguageCode =
|
|
|
468
475
|
| "fij"
|
|
469
476
|
| "fin"
|
|
470
477
|
| "fre"
|
|
478
|
+
| "fra"
|
|
471
479
|
| "fry"
|
|
472
480
|
| "ful"
|
|
473
481
|
| "geo"
|
|
482
|
+
| "kat"
|
|
474
483
|
| "ger"
|
|
484
|
+
| "deu"
|
|
475
485
|
| "gla"
|
|
476
486
|
| "gle"
|
|
477
487
|
| "glg"
|
|
478
488
|
| "glv"
|
|
479
489
|
| "gre"
|
|
490
|
+
| "ell"
|
|
480
491
|
| "grn"
|
|
481
492
|
| "guj"
|
|
482
493
|
| "hat"
|
|
@@ -489,6 +500,7 @@ export type Alpha3bLanguageCode =
|
|
|
489
500
|
| "hun"
|
|
490
501
|
| "ibo"
|
|
491
502
|
| "ice"
|
|
503
|
+
| "isl"
|
|
492
504
|
| "ido"
|
|
493
505
|
| "iii"
|
|
494
506
|
| "iku"
|
|
@@ -523,11 +535,14 @@ export type Alpha3bLanguageCode =
|
|
|
523
535
|
| "lub"
|
|
524
536
|
| "lug"
|
|
525
537
|
| "mac"
|
|
538
|
+
| "mkd"
|
|
526
539
|
| "mah"
|
|
527
540
|
| "mal"
|
|
528
541
|
| "mao"
|
|
542
|
+
| "mri"
|
|
529
543
|
| "mar"
|
|
530
544
|
| "may"
|
|
545
|
+
| "msa"
|
|
531
546
|
| "mlg"
|
|
532
547
|
| "mlt"
|
|
533
548
|
| "mon"
|
|
@@ -548,6 +563,7 @@ export type Alpha3bLanguageCode =
|
|
|
548
563
|
| "oss"
|
|
549
564
|
| "pan"
|
|
550
565
|
| "per"
|
|
566
|
+
| "fas"
|
|
551
567
|
| "pli"
|
|
552
568
|
| "pol"
|
|
553
569
|
| "por"
|
|
@@ -555,12 +571,14 @@ export type Alpha3bLanguageCode =
|
|
|
555
571
|
| "que"
|
|
556
572
|
| "roh"
|
|
557
573
|
| "rum"
|
|
574
|
+
| "ron"
|
|
558
575
|
| "run"
|
|
559
576
|
| "rus"
|
|
560
577
|
| "sag"
|
|
561
578
|
| "san"
|
|
562
579
|
| "sin"
|
|
563
580
|
| "slo"
|
|
581
|
+
| "slk"
|
|
564
582
|
| "slv"
|
|
565
583
|
| "sme"
|
|
566
584
|
| "smo"
|
|
@@ -583,6 +601,7 @@ export type Alpha3bLanguageCode =
|
|
|
583
601
|
| "tgl"
|
|
584
602
|
| "tha"
|
|
585
603
|
| "tib"
|
|
604
|
+
| "bod"
|
|
586
605
|
| "tir"
|
|
587
606
|
| "ton"
|
|
588
607
|
| "tsn"
|
|
@@ -598,6 +617,7 @@ export type Alpha3bLanguageCode =
|
|
|
598
617
|
| "vie"
|
|
599
618
|
| "vol"
|
|
600
619
|
| "wel"
|
|
620
|
+
| "cym"
|
|
601
621
|
| "wln"
|
|
602
622
|
| "wol"
|
|
603
623
|
| "xho"
|
|
@@ -809,10 +829,12 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
|
|
|
809
829
|
["afr", ["Afrikaans"]],
|
|
810
830
|
["aka", ["Akan"]],
|
|
811
831
|
["alb", ["Albanian"]],
|
|
832
|
+
["sqi", ["Albanian"]],
|
|
812
833
|
["amh", ["Amharic"]],
|
|
813
834
|
["ara", ["Arabic"]],
|
|
814
835
|
["arg", ["Aragonese"]],
|
|
815
836
|
["arm", ["Armenian"]],
|
|
837
|
+
["hye", ["Armenian"]],
|
|
816
838
|
["asm", ["Assamese"]],
|
|
817
839
|
["ava", ["Avaric"]],
|
|
818
840
|
["ave", ["Avestan"]],
|
|
@@ -821,6 +843,7 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
|
|
|
821
843
|
["bak", ["Bashkir"]],
|
|
822
844
|
["bam", ["Bambara"]],
|
|
823
845
|
["baq", ["Basque"]],
|
|
846
|
+
["eus", ["Basque"]],
|
|
824
847
|
["bel", ["Belarusian"]],
|
|
825
848
|
["ben", ["Bengali"]],
|
|
826
849
|
["bis", ["Bislama"]],
|
|
@@ -828,19 +851,23 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
|
|
|
828
851
|
["bre", ["Breton"]],
|
|
829
852
|
["bul", ["Bulgarian"]],
|
|
830
853
|
["bur", ["Burmese"]],
|
|
854
|
+
["mya", ["Burmese"]],
|
|
831
855
|
["cat", ["Catalan", "Valencian"]],
|
|
832
856
|
["cha", ["Chamorro"]],
|
|
833
857
|
["che", ["Chechen"]],
|
|
834
858
|
["chi", ["Chinese"]],
|
|
859
|
+
["zho", ["Chinese"]],
|
|
835
860
|
["chu", ["Church Slavic", "Old Slavonic", "Church Slavonic", "Old Bulgarian", "Old Church Slavonic"]],
|
|
836
861
|
["chv", ["Chuvash"]],
|
|
837
862
|
["cor", ["Cornish"]],
|
|
838
863
|
["cos", ["Corsican"]],
|
|
839
864
|
["cre", ["Cree"]],
|
|
840
865
|
["cze", ["Czech"]],
|
|
866
|
+
["ces", ["Czech"]],
|
|
841
867
|
["dan", ["Danish"]],
|
|
842
868
|
["div", ["Divehi", "Dhivehi", "Maldivian"]],
|
|
843
869
|
["dut", ["Dutch", "Flemish"]],
|
|
870
|
+
["nld", ["Dutch", "Flemish"]],
|
|
844
871
|
["dzo", ["Dzongkha"]],
|
|
845
872
|
["eng", ["English"]],
|
|
846
873
|
["epo", ["Esperanto"]],
|
|
@@ -850,15 +877,19 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
|
|
|
850
877
|
["fij", ["Fijian"]],
|
|
851
878
|
["fin", ["Finnish"]],
|
|
852
879
|
["fre", ["French"]],
|
|
880
|
+
["fra", ["French"]],
|
|
853
881
|
["fry", ["Western Frisian"]],
|
|
854
882
|
["ful", ["Fulah"]],
|
|
855
883
|
["geo", ["Georgian"]],
|
|
884
|
+
["kat", ["Georgian"]],
|
|
856
885
|
["ger", ["German"]],
|
|
886
|
+
["deu", ["German"]],
|
|
857
887
|
["gla", ["Gaelic", "Scottish Gaelic"]],
|
|
858
888
|
["gle", ["Irish"]],
|
|
859
889
|
["glg", ["Galician"]],
|
|
860
890
|
["glv", ["Manx"]],
|
|
861
891
|
["gre", ["Greek, Modern (1453-)"]],
|
|
892
|
+
["ell", ["Greek, Modern (1453-)"]],
|
|
862
893
|
["grn", ["Guarani"]],
|
|
863
894
|
["guj", ["Gujarati"]],
|
|
864
895
|
["hat", ["Haitian", "Haitian Creole"]],
|
|
@@ -871,6 +902,7 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
|
|
|
871
902
|
["hun", ["Hungarian"]],
|
|
872
903
|
["ibo", ["Igbo"]],
|
|
873
904
|
["ice", ["Icelandic"]],
|
|
905
|
+
["isl", ["Icelandic"]],
|
|
874
906
|
["ido", ["Ido"]],
|
|
875
907
|
["iii", ["Sichuan Yi", "Nuosu"]],
|
|
876
908
|
["iku", ["Inuktitut"]],
|
|
@@ -905,11 +937,14 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
|
|
|
905
937
|
["lub", ["Luba-Katanga"]],
|
|
906
938
|
["lug", ["Ganda"]],
|
|
907
939
|
["mac", ["Macedonian"]],
|
|
940
|
+
["mkd", ["Macedonian"]],
|
|
908
941
|
["mah", ["Marshallese"]],
|
|
909
942
|
["mal", ["Malayalam"]],
|
|
910
943
|
["mao", ["Maori"]],
|
|
944
|
+
["mri", ["Maori"]],
|
|
911
945
|
["mar", ["Marathi"]],
|
|
912
946
|
["may", ["Malay"]],
|
|
947
|
+
["msa", ["Malay"]],
|
|
913
948
|
["mlg", ["Malagasy"]],
|
|
914
949
|
["mlt", ["Maltese"]],
|
|
915
950
|
["mon", ["Mongolian"]],
|
|
@@ -930,6 +965,7 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
|
|
|
930
965
|
["oss", ["Ossetian", "Ossetic"]],
|
|
931
966
|
["pan", ["Panjabi", "Punjabi"]],
|
|
932
967
|
["per", ["Persian"]],
|
|
968
|
+
["fas", ["Persian"]],
|
|
933
969
|
["pli", ["Pali"]],
|
|
934
970
|
["pol", ["Polish"]],
|
|
935
971
|
["por", ["Portuguese"]],
|
|
@@ -937,12 +973,14 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
|
|
|
937
973
|
["que", ["Quechua"]],
|
|
938
974
|
["roh", ["Romansh"]],
|
|
939
975
|
["rum", ["Romanian", "Moldavian", "Moldovan"]],
|
|
976
|
+
["ron", ["Romanian", "Moldavian", "Moldovan"]],
|
|
940
977
|
["run", ["Rundi"]],
|
|
941
978
|
["rus", ["Russian"]],
|
|
942
979
|
["sag", ["Sango"]],
|
|
943
980
|
["san", ["Sanskrit"]],
|
|
944
981
|
["sin", ["Sinhala", "Sinhalese"]],
|
|
945
982
|
["slo", ["Slovak"]],
|
|
983
|
+
["slk", ["Slovak"]],
|
|
946
984
|
["slv", ["Slovenian"]],
|
|
947
985
|
["sme", ["Northern Sami"]],
|
|
948
986
|
["smo", ["Samoan"]],
|
|
@@ -965,6 +1003,7 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
|
|
|
965
1003
|
["tgl", ["Tagalog"]],
|
|
966
1004
|
["tha", ["Thai"]],
|
|
967
1005
|
["tib", ["Tibetan"]],
|
|
1006
|
+
["bod", ["Tibetan"]],
|
|
968
1007
|
["tir", ["Tigrinya"]],
|
|
969
1008
|
["ton", ["Tonga (Tonga Islands)"]],
|
|
970
1009
|
["tsn", ["Tswana"]],
|
|
@@ -980,6 +1019,7 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
|
|
|
980
1019
|
["vie", ["Vietnamese"]],
|
|
981
1020
|
["vol", ["Volapük"]],
|
|
982
1021
|
["wel", ["Welsh"]],
|
|
1022
|
+
["cym", ["Welsh"]],
|
|
983
1023
|
["wln", ["Walloon"]],
|
|
984
1024
|
["wol", ["Wolof"]],
|
|
985
1025
|
["xho", ["Xhosa"]],
|
|
@@ -1365,4 +1405,24 @@ export const Alpha3bToAlpha2: ReadonlyMap<Alpha3bLanguageCode, Alpha2LanguageCod
|
|
|
1365
1405
|
["yor", "yo"],
|
|
1366
1406
|
["zha", "za"],
|
|
1367
1407
|
["zul", "zu"],
|
|
1408
|
+
["sqi", "sq"],
|
|
1409
|
+
["hye", "hy"],
|
|
1410
|
+
["eus", "eu"],
|
|
1411
|
+
["mya", "my"],
|
|
1412
|
+
["zho", "zh"],
|
|
1413
|
+
["ces", "cs"],
|
|
1414
|
+
["nld", "nl"],
|
|
1415
|
+
["fra", "fr"],
|
|
1416
|
+
["kat", "ka"],
|
|
1417
|
+
["deu", "de"],
|
|
1418
|
+
["ell", "el"],
|
|
1419
|
+
["isl", "is"],
|
|
1420
|
+
["mkd", "mk"],
|
|
1421
|
+
["mri", "mi"],
|
|
1422
|
+
["msa", "ms"],
|
|
1423
|
+
["fas", "fa"],
|
|
1424
|
+
["ron", "ro"],
|
|
1425
|
+
["slk", "sk"],
|
|
1426
|
+
["bod", "bo"],
|
|
1427
|
+
["cym", "cy"],
|
|
1368
1428
|
])
|
package/resources/libpostal.ts
CHANGED
|
@@ -7,13 +7,14 @@
|
|
|
7
7
|
import { readdir } from "node:fs/promises"
|
|
8
8
|
import { availableParallelism } from "node:os"
|
|
9
9
|
|
|
10
|
-
import { tryStat } from "@mailwoman/core/fs"
|
|
11
|
-
import type { Alpha2LanguageCode } from "@mailwoman/core/resources/languages"
|
|
12
|
-
import { TextNormalizer, type TextNormalizerInit } from "@mailwoman/core/tokenization"
|
|
13
10
|
import type { PathBuilder } from "path-ts"
|
|
14
11
|
import pluralize from "pluralize"
|
|
15
12
|
import { AsyncSequence, TextSpliterator } from "spliterator"
|
|
16
13
|
|
|
14
|
+
import { tryStat } from "#fs"
|
|
15
|
+
import type { Alpha2LanguageCode } from "#resources/languages"
|
|
16
|
+
import { TextNormalizer, type TextNormalizerInit } from "#tokenization"
|
|
17
|
+
|
|
17
18
|
import { resourceDictionaryPathBuilder } from "../utils/repo.ts"
|
|
18
19
|
import { LocaleIndex } from "./LocaleIndex.ts"
|
|
19
20
|
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
import { mkdirSync } from "node:fs"
|
|
8
8
|
|
|
9
|
-
import type { Alpha3bLanguageCode } from "@mailwoman/core/resources/languages"
|
|
10
9
|
import { dirname } from "path-ts"
|
|
11
10
|
|
|
11
|
+
import type { Alpha3bLanguageCode } from "#resources/languages"
|
|
12
|
+
|
|
12
13
|
import { PlacetypeDataSource, type PlacetypeDataSourceOptions } from "./PlacetypeDataSource.ts"
|
|
13
14
|
import type { WhosOnFirstPlacetype } from "./placetypes/definition.ts"
|
|
14
15
|
|
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
|
|
7
7
|
import { DatabaseSync, type DatabaseSyncOptions, type SQLInputValue } from "node:sqlite"
|
|
8
8
|
|
|
9
|
+
import { PathBuilder, type PathBuilderLike } from "path-ts"
|
|
10
|
+
|
|
9
11
|
import {
|
|
10
12
|
type Alpha2LanguageCode,
|
|
11
13
|
type Alpha3bLanguageCode,
|
|
12
14
|
Alpha3bToAlpha2,
|
|
13
15
|
isAlpha3bLanguageCode,
|
|
14
|
-
} from "
|
|
15
|
-
import { PathBuilder, type PathBuilderLike } from "path-ts"
|
|
16
|
+
} from "#resources/languages"
|
|
16
17
|
|
|
17
18
|
import { tryWithBackoff } from "./backoff.ts"
|
|
18
19
|
import type { WhosOnFirstPlacetype } from "./placetypes/definition.ts"
|
|
@@ -65,6 +66,36 @@ export interface PlacetypeRecord {
|
|
|
65
66
|
short: string | null
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
function sqlParameters(input: Partial<PlacetypeRecord>): Record<string, SQLInputValue> {
|
|
70
|
+
const parameters: Record<string, SQLInputValue> = {}
|
|
71
|
+
|
|
72
|
+
for (const [key, value] of Object.entries(input)) {
|
|
73
|
+
if (value !== undefined) {
|
|
74
|
+
parameters[key] = value
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return parameters
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function nullableString(value: unknown): string | null {
|
|
82
|
+
return value == null ? null : String(value)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function placetypeRecordFromRow(row: Record<string, SQLInputValue>): PlacetypeRecord {
|
|
86
|
+
return {
|
|
87
|
+
id: Number(row["id"]),
|
|
88
|
+
src: String(row["src"]),
|
|
89
|
+
parent_id: Number(row["parent_id"]),
|
|
90
|
+
name: String(row["name"]),
|
|
91
|
+
preferred: nullableString(row["preferred"]),
|
|
92
|
+
variant: nullableString(row["variant"]),
|
|
93
|
+
colloquial: nullableString(row["colloquial"]),
|
|
94
|
+
abbr: nullableString(row["abbr"]),
|
|
95
|
+
short: nullableString(row["short"]),
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
68
99
|
/**
|
|
69
100
|
* A data source for WhosOnFirst placetype records.
|
|
70
101
|
*/
|
|
@@ -80,11 +111,7 @@ export class PlacetypeDataSource implements Disposable {
|
|
|
80
111
|
? Alpha3bToAlpha2.get(languageCode)
|
|
81
112
|
: languageCode
|
|
82
113
|
|
|
83
|
-
return PathBuilder.from(
|
|
84
|
-
dataDirectory,
|
|
85
|
-
placetype,
|
|
86
|
-
`${normalizedLanguageCode}.db`
|
|
87
|
-
) as unknown as PathBuilder<`/${P}/${L}.db`>
|
|
114
|
+
return PathBuilder.from(dataDirectory, placetype, `${normalizedLanguageCode}.db`)
|
|
88
115
|
}
|
|
89
116
|
|
|
90
117
|
public prepareTables(): void {
|
|
@@ -155,9 +182,7 @@ export class PlacetypeDataSource implements Disposable {
|
|
|
155
182
|
|
|
156
183
|
// node:sqlite's StatementSync.iterate() accepts named params via an object whose keys match
|
|
157
184
|
// the `@name` / `:name` / `$name` placeholders in the SQL.
|
|
158
|
-
return Iterator.from(
|
|
159
|
-
statement.iterate(criteria as unknown as Record<string, SQLInputValue>)
|
|
160
|
-
) as unknown as IteratorObject<PlacetypeRecord>
|
|
185
|
+
return Iterator.from(statement.iterate(sqlParameters(criteria))).map(placetypeRecordFromRow)
|
|
161
186
|
}
|
|
162
187
|
|
|
163
188
|
/**
|
|
@@ -191,7 +216,7 @@ export class PlacetypeDataSource implements Disposable {
|
|
|
191
216
|
parent_id = excluded.parent_id
|
|
192
217
|
`)
|
|
193
218
|
|
|
194
|
-
statement.run(record
|
|
219
|
+
statement.run(sqlParameters(record))
|
|
195
220
|
}
|
|
196
221
|
|
|
197
222
|
await tryWithBackoff(5, perform)
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { Alpha3bLanguageCode } from "@mailwoman/core/resources/languages"
|
|
8
|
-
import type { TextNormalizer } from "@mailwoman/core/tokenization"
|
|
9
7
|
import FastGlob, { type Entry } from "fast-glob"
|
|
10
8
|
import { PathBuilder, type PathBuilderLike } from "path-ts"
|
|
11
9
|
import { TextSpliterator } from "spliterator"
|
|
12
10
|
|
|
11
|
+
import type { Alpha3bLanguageCode } from "#resources/languages"
|
|
12
|
+
import type { TextNormalizer } from "#tokenization"
|
|
13
|
+
|
|
13
14
|
import type { Displayable } from "../debugging.ts"
|
|
14
15
|
import { ResourceMapCache } from "../ResourceMapCache.ts"
|
|
15
16
|
import { DisposableSet } from "../set.ts"
|
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
import * as fs from "node:fs/promises"
|
|
8
8
|
|
|
9
|
-
import { parseJSONStrict } from "@mailwoman/core/objects"
|
|
10
|
-
import { prepareRepositoryDirectories, type RepositorySource } from "@mailwoman/core/resources"
|
|
11
9
|
import FastGlob from "fast-glob"
|
|
12
10
|
import type { PathBuilder } from "path-ts"
|
|
13
11
|
import { parallelMap } from "spliterator"
|
|
14
12
|
|
|
13
|
+
import { parseJSONStrict } from "#objects"
|
|
14
|
+
|
|
15
|
+
import { prepareRepositoryDirectories, type RepositorySource } from "../../git.ts"
|
|
15
16
|
import {
|
|
16
17
|
normalizePlacetypeDefinition,
|
|
17
18
|
type PlacetypeDefinition,
|
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import type { GeoFeature, GeometryLiteral } from "@mailwoman/spatial"
|
|
8
|
+
|
|
7
9
|
import {
|
|
8
10
|
type Alpha2LanguageCode,
|
|
9
11
|
type Alpha3bLanguageCode,
|
|
10
12
|
Alpha3bToAlpha2,
|
|
11
13
|
isAlpha2LanguageCode,
|
|
12
14
|
isAlpha3bLanguageCode,
|
|
13
|
-
} from "
|
|
14
|
-
import type { GeoFeature, GeometryLiteral } from "@mailwoman/spatial"
|
|
15
|
+
} from "#resources/languages"
|
|
15
16
|
|
|
16
17
|
import type { WhosOnFirstPlacetype } from "./definition.ts"
|
|
17
18
|
|
|
@@ -36,6 +37,14 @@ export interface WOFBaseProperties {
|
|
|
36
37
|
"wof:lastmodified"?: number
|
|
37
38
|
"geom:latitude"?: number
|
|
38
39
|
"geom:longitude"?: number
|
|
40
|
+
/**
|
|
41
|
+
* The label centroid — where a human would drop the pin, distinct from the geometry's mathematical centroid. The
|
|
42
|
+
* difference is territorial: France's `geom:` centroid sits in Spain (42.19, -2.74) because the multipolygon spans
|
|
43
|
+
* the overseas territories, while `lbl:` is metropolitan France (46.71, 2.46). Prefer `lbl:` wherever a point stands
|
|
44
|
+
* in for the place.
|
|
45
|
+
*/
|
|
46
|
+
"lbl:latitude"?: number
|
|
47
|
+
"lbl:longitude"?: number
|
|
39
48
|
/**
|
|
40
49
|
* `"minLon,minLat,maxLon,maxLat"` — WOF writes the bbox as a comma-joined string, not an array. Read by the gazetteer
|
|
41
50
|
* ingest for the resolver's point-in-box proximity.
|
|
@@ -119,14 +119,15 @@ export type PlacetypeDefinitionInit = {
|
|
|
119
119
|
export function normalizePlacetypeDefinition(
|
|
120
120
|
initLike: PlacetypeDefinition | PlacetypeDefinitionInit
|
|
121
121
|
): PlacetypeDefinition {
|
|
122
|
-
const spec
|
|
122
|
+
const spec = {} as PlacetypeDefinition
|
|
123
123
|
|
|
124
124
|
for (const [key, value] of Object.entries(initLike)) {
|
|
125
125
|
const normalizedKey = key.startsWith(WOFPrefix) ? key.slice(WOFPrefix.length) : key
|
|
126
|
-
|
|
126
|
+
|
|
127
|
+
Reflect.set(spec, normalizedKey, value)
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
return spec
|
|
130
|
+
return spec
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
/**
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* How SPECIFIC a placetype is — the ordering `Placetype.ts` deliberately does not give you.
|
|
7
|
+
*
|
|
8
|
+
* WOF placetype ids are assignment order, and `Placetype.ts` says so in place ("these IDs are not in any specific
|
|
9
|
+
* order. Avoid using them for sorting."). Every consumer that needs "is this row finer or coarser than that one"
|
|
10
|
+
* therefore writes its own table, and two identical copies already existed — `eval-harness/oa-resolver-eval.ts` and
|
|
11
|
+
* `dev-tools/score-hard-slice-board.run.ts` — agreeing on seven placetypes and both missing everything below
|
|
12
|
+
* `localadmin`.
|
|
13
|
+
*
|
|
14
|
+
* THAT SHARED GAP IS WHY THIS FILE EXISTS. #1746: the currency backfill refused to
|
|
15
|
+
* resurrect a deprecated locality whenever ANY live same-name row sat within 10 km, "possibly under another
|
|
16
|
+
* placetype". For a place recorded twice that premise holds. For a placetype DEMOTION it does not — WOF retired
|
|
17
|
+
* `Gillingham` the locality (pop 101,187) and kept `Gillingham` the neighbourhood 3.2 km away, and the gate read the
|
|
18
|
+
* surviving CHILD as covering its own dead parent. Sixteen of seventeen GB refusals had exactly that shape. A rank
|
|
19
|
+
* comparison separates the two cases, and it needs the fine end of the scale that neither existing copy carried.
|
|
20
|
+
*
|
|
21
|
+
* IT IS NOT THE ONLY TABLE. `resolver-wof-sqlite/ancestry.ts` publishes `PLACETYPE_DEPTH` for hierarchical
|
|
22
|
+
* containment, and `eval-harness/gauntlet/ablation-expectation.ts` carries a deliberate copy of THAT one so an old
|
|
23
|
+
* artifact can be re-graded against the table it was built with. This scale ORDERS the eleven placetypes they share
|
|
24
|
+
* identically, and `specificity.test.ts` holds that agreement — the two differ only in offset and in what an
|
|
25
|
+
* unranked placetype means, never in which of two placetypes is finer.
|
|
26
|
+
*
|
|
27
|
+
* They did not always agree. This scale once put `borough` COARSER than `locality` and tied `county` with
|
|
28
|
+
* `macrocounty`, both wrong: a NYC borough sits inside its locality, and a macrocounty contains counties. The
|
|
29
|
+
* inversion mattered — it let a live borough read as covering its own dead parent locality, which is the same shape
|
|
30
|
+
* as the Gillingham defect above, one rung down.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import type { WhosOnFirstPlacetype } from "./definition.ts"
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Higher is finer. Absent placetypes are UNRANKED and must be handled by the caller rather than defaulted — a missing
|
|
37
|
+
* entry silently scoring 0 would rank an unknown placetype as coarse as `country`, which is the wrong direction for
|
|
38
|
+
* every gate that reads this.
|
|
39
|
+
*/
|
|
40
|
+
export const PLACETYPE_SPECIFICITY: Readonly<Partial<Record<WhosOnFirstPlacetype | (string & {}), number>>> = {
|
|
41
|
+
address: 11,
|
|
42
|
+
building: 10,
|
|
43
|
+
campus: 10,
|
|
44
|
+
venue: 10,
|
|
45
|
+
postalcode: 9,
|
|
46
|
+
microhood: 8,
|
|
47
|
+
neighbourhood: 7,
|
|
48
|
+
macrohood: 6,
|
|
49
|
+
borough: 5,
|
|
50
|
+
locality: 4,
|
|
51
|
+
localadmin: 3,
|
|
52
|
+
county: 2,
|
|
53
|
+
macrocounty: 1,
|
|
54
|
+
region: 0,
|
|
55
|
+
macroregion: -1,
|
|
56
|
+
country: -2,
|
|
57
|
+
dependency: -2,
|
|
58
|
+
continent: -3,
|
|
59
|
+
empire: -4,
|
|
60
|
+
planet: -5,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The rank of a placetype, or `undefined` when it carries none.
|
|
65
|
+
*
|
|
66
|
+
* Returning `undefined` rather than a number is the point: a caller that cannot rank a row has to decide what that
|
|
67
|
+
* means for its own gate, and the two reasonable answers (block conservatively, or ignore) differ per call site.
|
|
68
|
+
*/
|
|
69
|
+
export function placetypeSpecificity(placetype: string | null | undefined): number | undefined {
|
|
70
|
+
if (!placetype) return undefined
|
|
71
|
+
|
|
72
|
+
return PLACETYPE_SPECIFICITY[placetype]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Is `candidate` at least as fine-grained as `reference`?
|
|
77
|
+
*
|
|
78
|
+
* `undefined` when either placetype is unranked — the caller decides. The comparison is `>=` so an equal rung counts as
|
|
79
|
+
* covering, which is what a "this place is already represented" check wants.
|
|
80
|
+
*/
|
|
81
|
+
export function isAtLeastAsSpecific(
|
|
82
|
+
candidate: string | null | undefined,
|
|
83
|
+
reference: string | null | undefined
|
|
84
|
+
): boolean | undefined {
|
|
85
|
+
const a = placetypeSpecificity(candidate)
|
|
86
|
+
const b = placetypeSpecificity(reference)
|
|
87
|
+
|
|
88
|
+
if (a === undefined || b === undefined) return undefined
|
|
89
|
+
|
|
90
|
+
return a >= b
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Is `candidate` STRICTLY finer than `reference` — a child rung, not the same one?
|
|
95
|
+
*
|
|
96
|
+
* The distinction from {@link isAtLeastAsSpecific} is the whole bug it was written for. "Does this live row cover that
|
|
97
|
+
* dead one" wants the EQUAL case to count as covering: a live `locality` plainly covers a dead `locality` of the same
|
|
98
|
+
* name. Asking `isAtLeastAsSpecific(live, dead)` and negating it answers "is the live row strictly coarser", which
|
|
99
|
+
* quietly drops the equal case — measured on the real artifact, that turned 973 blocked rows into 18 and would have
|
|
100
|
+
* resurrected 955 places that are already alive.
|
|
101
|
+
*
|
|
102
|
+
* `undefined` when either placetype is unranked; a caller gating on this should treat that as "not strictly finer".
|
|
103
|
+
*/
|
|
104
|
+
export function isStrictlyFiner(
|
|
105
|
+
candidate: string | null | undefined,
|
|
106
|
+
reference: string | null | undefined
|
|
107
|
+
): boolean | undefined {
|
|
108
|
+
const a = placetypeSpecificity(candidate)
|
|
109
|
+
const b = placetypeSpecificity(reference)
|
|
110
|
+
|
|
111
|
+
if (a === undefined || b === undefined) return undefined
|
|
112
|
+
|
|
113
|
+
return a > b
|
|
114
|
+
}
|