@mailwoman/core 8.1.0 → 8.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/api/APIClient.ts +3 -4
- package/api/responses.ts +6 -3
- package/coarse-placer/coarse-placer.ts +26 -11
- package/coarse-placer/featurize.ts +25 -16
- package/coarse-placer/tools/build-dataset.ts +42 -18
- package/coarse-placer/tools/build-outlier-exposure.ts +51 -18
- package/coarse-placer/tools/build-outlier-latin.ts +48 -22
- package/coarse-placer/tools/build-outlier-oa.ts +52 -20
- package/coarse-placer/tools/eval-latin-offmap.ts +37 -12
- package/coarse-placer/tools/eval-openset.ts +104 -37
- package/coarse-placer/tools/eval-quant-compare.ts +41 -11
- package/coarse-placer/tools/eval.ts +51 -13
- package/coarse-placer/tools/fnv-hash.ts +5 -3
- package/coarse-placer/tools/probe-frontier.ts +63 -32
- package/coarse-placer/tools/quantize.ts +30 -8
- package/coarse-placer/tools/train.ts +63 -17
- package/collections.ts +2 -2
- package/decoder/build-tree.ts +16 -3
- package/decoder/calibration.ts +23 -7
- package/decoder/containment.ts +3 -1
- package/decoder/proposals-to-tree.ts +2 -0
- package/decoder/resolve-proposal-overlaps.ts +5 -1
- package/decoder/serialize-json.ts +8 -2
- package/decoder/serialize-tuples.ts +7 -2
- package/decoder/serialize-xml.ts +29 -11
- package/decoder/types.ts +34 -12
- package/decoder/unknown-spans.ts +14 -5
- package/decoder/validate-tree.ts +6 -1
- package/env/index.ts +1 -1
- package/env/load.ts +1 -1
- package/env/paths.ts +1 -1
- package/env/schema.ts +12 -4
- package/errors/schema.ts +1 -1
- package/fs/node.ts +9 -10
- package/identifiers.ts +3 -3
- package/kysley/adapter.ts +1 -1
- package/layers/manifest.ts +22 -8
- package/layers/schema.ts +59 -19
- package/locale/locale.ts +6 -2
- package/locale/profiles/en-us.ts +3 -0
- package/locale/profiles/fr-fr.ts +3 -0
- package/locale/profiles/ja-jp.ts +3 -0
- package/locale/registry.ts +3 -1
- package/logging/shared.ts +1 -0
- package/logging/utils.ts +1 -1
- package/objects.ts +7 -2
- package/out/api/APIClient.d.ts +1 -1
- package/out/api/APIClient.d.ts.map +1 -1
- package/out/api/APIClient.js +3 -2
- package/out/api/APIClient.js.map +1 -1
- package/out/api/responses.d.ts.map +1 -1
- package/out/api/responses.js +3 -3
- package/out/api/responses.js.map +1 -1
- package/out/coarse-placer/coarse-placer.d.ts +19 -9
- package/out/coarse-placer/coarse-placer.d.ts.map +1 -1
- package/out/coarse-placer/coarse-placer.js +6 -4
- package/out/coarse-placer/coarse-placer.js.map +1 -1
- package/out/coarse-placer/featurize.d.ts.map +1 -1
- package/out/coarse-placer/featurize.js +20 -16
- package/out/coarse-placer/featurize.js.map +1 -1
- package/out/coarse-placer/tools/build-dataset.d.ts +15 -5
- package/out/coarse-placer/tools/build-dataset.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-dataset.js +19 -14
- package/out/coarse-placer/tools/build-dataset.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-exposure.d.ts +21 -7
- package/out/coarse-placer/tools/build-outlier-exposure.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-exposure.js +24 -12
- package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-latin.d.ts +18 -6
- package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-latin.js +27 -17
- package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-oa.d.ts +18 -6
- package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-oa.js +29 -15
- package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
- package/out/coarse-placer/tools/eval-latin-offmap.d.ts +18 -6
- package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-latin-offmap.js +13 -7
- package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
- package/out/coarse-placer/tools/eval-openset.d.ts +24 -8
- package/out/coarse-placer/tools/eval-openset.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-openset.js +52 -31
- package/out/coarse-placer/tools/eval-openset.js.map +1 -1
- package/out/coarse-placer/tools/eval-quant-compare.d.ts +30 -10
- package/out/coarse-placer/tools/eval-quant-compare.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-quant-compare.js +4 -2
- package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
- package/out/coarse-placer/tools/eval.d.ts +24 -8
- package/out/coarse-placer/tools/eval.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval.js +16 -6
- package/out/coarse-placer/tools/eval.js.map +1 -1
- package/out/coarse-placer/tools/fnv-hash.d.ts +3 -1
- package/out/coarse-placer/tools/fnv-hash.d.ts.map +1 -1
- package/out/coarse-placer/tools/fnv-hash.js +5 -3
- package/out/coarse-placer/tools/fnv-hash.js.map +1 -1
- package/out/coarse-placer/tools/probe-frontier.d.ts +18 -6
- package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
- package/out/coarse-placer/tools/probe-frontier.js +39 -23
- package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
- package/out/coarse-placer/tools/quantize.d.ts +15 -5
- package/out/coarse-placer/tools/quantize.d.ts.map +1 -1
- package/out/coarse-placer/tools/quantize.js +11 -4
- package/out/coarse-placer/tools/quantize.js.map +1 -1
- package/out/coarse-placer/tools/train.d.ts +24 -8
- package/out/coarse-placer/tools/train.d.ts.map +1 -1
- package/out/coarse-placer/tools/train.js +24 -10
- package/out/coarse-placer/tools/train.js.map +1 -1
- package/out/collections.js +2 -2
- package/out/collections.js.map +1 -1
- package/out/decoder/build-tree.d.ts.map +1 -1
- package/out/decoder/build-tree.js +9 -3
- package/out/decoder/build-tree.js.map +1 -1
- package/out/decoder/calibration.d.ts +17 -3
- package/out/decoder/calibration.d.ts.map +1 -1
- package/out/decoder/calibration.js +12 -4
- package/out/decoder/calibration.js.map +1 -1
- package/out/decoder/containment.d.ts +3 -1
- package/out/decoder/containment.d.ts.map +1 -1
- package/out/decoder/containment.js +3 -1
- package/out/decoder/containment.js.map +1 -1
- package/out/decoder/proposals-to-tree.d.ts.map +1 -1
- package/out/decoder/proposals-to-tree.js.map +1 -1
- package/out/decoder/resolve-proposal-overlaps.d.ts.map +1 -1
- package/out/decoder/resolve-proposal-overlaps.js +5 -1
- package/out/decoder/resolve-proposal-overlaps.js.map +1 -1
- package/out/decoder/serialize-json.d.ts +6 -2
- package/out/decoder/serialize-json.d.ts.map +1 -1
- package/out/decoder/serialize-json.js.map +1 -1
- package/out/decoder/serialize-tuples.d.ts +6 -2
- package/out/decoder/serialize-tuples.d.ts.map +1 -1
- package/out/decoder/serialize-tuples.js.map +1 -1
- package/out/decoder/serialize-xml.d.ts +21 -7
- package/out/decoder/serialize-xml.d.ts.map +1 -1
- package/out/decoder/serialize-xml.js +7 -5
- package/out/decoder/serialize-xml.js.map +1 -1
- package/out/decoder/types.d.ts +34 -12
- package/out/decoder/types.d.ts.map +1 -1
- package/out/decoder/types.js +1 -1
- package/out/decoder/types.js.map +1 -1
- package/out/decoder/unknown-spans.d.ts +9 -3
- package/out/decoder/unknown-spans.d.ts.map +1 -1
- package/out/decoder/unknown-spans.js +4 -2
- package/out/decoder/unknown-spans.js.map +1 -1
- package/out/decoder/validate-tree.d.ts +3 -1
- package/out/decoder/validate-tree.d.ts.map +1 -1
- package/out/decoder/validate-tree.js +3 -1
- package/out/decoder/validate-tree.js.map +1 -1
- package/out/env/index.js +0 -1
- package/out/env/index.js.map +1 -1
- package/out/env/load.js +1 -1
- package/out/env/load.js.map +1 -1
- package/out/env/paths.js +1 -1
- package/out/env/paths.js.map +1 -1
- package/out/env/schema.d.ts.map +1 -1
- package/out/env/schema.js +12 -4
- package/out/env/schema.js.map +1 -1
- package/out/errors/schema.js +1 -1
- package/out/errors/schema.js.map +1 -1
- package/out/fs/node.d.ts +1 -2
- package/out/fs/node.d.ts.map +1 -1
- package/out/fs/node.js +7 -8
- package/out/fs/node.js.map +1 -1
- package/out/identifiers.js +3 -3
- package/out/identifiers.js.map +1 -1
- package/out/kysley/adapter.d.ts +1 -1
- package/out/kysley/adapter.d.ts.map +1 -1
- package/out/kysley/adapter.js +1 -1
- package/out/kysley/adapter.js.map +1 -1
- package/out/layers/manifest.d.ts +18 -6
- package/out/layers/manifest.d.ts.map +1 -1
- package/out/layers/manifest.js +8 -4
- package/out/layers/manifest.js.map +1 -1
- package/out/layers/schema.d.ts +57 -19
- package/out/layers/schema.d.ts.map +1 -1
- package/out/layers/schema.js +24 -8
- package/out/layers/schema.js.map +1 -1
- package/out/locale/locale.d.ts +6 -2
- package/out/locale/locale.d.ts.map +1 -1
- package/out/locale/profiles/en-us.d.ts +3 -0
- package/out/locale/profiles/en-us.d.ts.map +1 -1
- package/out/locale/profiles/en-us.js +3 -0
- package/out/locale/profiles/en-us.js.map +1 -1
- package/out/locale/profiles/fr-fr.d.ts +3 -0
- package/out/locale/profiles/fr-fr.d.ts.map +1 -1
- package/out/locale/profiles/fr-fr.js +3 -0
- package/out/locale/profiles/fr-fr.js.map +1 -1
- package/out/locale/profiles/ja-jp.d.ts +3 -0
- package/out/locale/profiles/ja-jp.d.ts.map +1 -1
- package/out/locale/profiles/ja-jp.js +3 -0
- package/out/locale/profiles/ja-jp.js.map +1 -1
- package/out/locale/registry.d.ts +3 -1
- package/out/locale/registry.d.ts.map +1 -1
- package/out/locale/registry.js +3 -1
- package/out/locale/registry.js.map +1 -1
- package/out/logging/shared.d.ts.map +1 -1
- package/out/logging/shared.js +1 -0
- package/out/logging/shared.js.map +1 -1
- package/out/logging/utils.js +1 -1
- package/out/logging/utils.js.map +1 -1
- package/out/objects.d.ts.map +1 -1
- package/out/objects.js +2 -2
- package/out/objects.js.map +1 -1
- package/out/pipeline/index.d.ts +2 -2
- package/out/pipeline/index.d.ts.map +1 -1
- package/out/pipeline/index.js +1 -1
- package/out/pipeline/index.js.map +1 -1
- package/out/pipeline/reconcile-lookups.d.ts.map +1 -1
- package/out/pipeline/reconcile-lookups.js.map +1 -1
- package/out/pipeline/reconcile.d.ts +30 -10
- package/out/pipeline/reconcile.d.ts.map +1 -1
- package/out/pipeline/reconcile.js +12 -9
- package/out/pipeline/reconcile.js.map +1 -1
- package/out/pipeline/runtime-pipeline.d.ts +18 -0
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.js +73 -46
- package/out/pipeline/runtime-pipeline.js.map +1 -1
- package/out/pipeline/span-logit-aggregation.d.ts.map +1 -1
- package/out/pipeline/span-logit-aggregation.js +5 -2
- package/out/pipeline/span-logit-aggregation.js.map +1 -1
- package/out/pipeline/span-proposer.d.ts +19 -9
- package/out/pipeline/span-proposer.d.ts.map +1 -1
- package/out/pipeline/span-proposer.js +42 -22
- package/out/pipeline/span-proposer.js.map +1 -1
- package/out/pipeline/types.d.ts +77 -19
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js +16 -0
- package/out/pipeline/types.js.map +1 -1
- package/out/policy/proposal-collection.d.ts +1 -1
- package/out/policy/proposal-collection.d.ts.map +1 -1
- package/out/policy/proposal-collection.js +2 -3
- package/out/policy/proposal-collection.js.map +1 -1
- package/out/policy/registry.d.ts +9 -3
- package/out/policy/registry.d.ts.map +1 -1
- package/out/policy/registry.js +9 -3
- package/out/policy/registry.js.map +1 -1
- package/out/resolver/index.d.ts.map +1 -1
- package/out/resolver/types.d.ts +94 -30
- package/out/resolver/types.d.ts.map +1 -1
- package/out/resolver/types.js +7 -1
- package/out/resolver/types.js.map +1 -1
- package/out/resources/LocaleIndex.d.ts +1 -1
- package/out/resources/LocaleIndex.d.ts.map +1 -1
- package/out/resources/LocaleIndex.js +1 -2
- package/out/resources/LocaleIndex.js.map +1 -1
- package/out/resources/ResourceMapCache.d.ts.map +1 -1
- package/out/resources/ResourceMapCache.js +1 -1
- package/out/resources/ResourceMapCache.js.map +1 -1
- package/out/resources/collections.d.ts.map +1 -1
- package/out/resources/collections.js +3 -1
- package/out/resources/collections.js.map +1 -1
- package/out/resources/languages/index.d.ts +1 -1
- package/out/resources/languages/index.d.ts.map +1 -1
- package/out/resources/languages/index.js +1 -1
- package/out/resources/languages/index.js.map +1 -1
- package/out/resources/libpostal.d.ts +1 -1
- package/out/resources/libpostal.d.ts.map +1 -1
- package/out/resources/libpostal.js +7 -5
- package/out/resources/libpostal.js.map +1 -1
- package/out/resources/set.js +6 -6
- package/out/resources/set.js.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.d.ts +1 -4
- package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.js +1 -20
- package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.js +2 -2
- package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
- package/out/resources/whosonfirst/backoff.d.ts +19 -0
- package/out/resources/whosonfirst/backoff.d.ts.map +1 -0
- package/out/resources/whosonfirst/backoff.js +35 -0
- package/out/resources/whosonfirst/backoff.js.map +1 -0
- package/out/resources/whosonfirst/loader.d.ts +1 -1
- package/out/resources/whosonfirst/loader.d.ts.map +1 -1
- package/out/resources/whosonfirst/loader.js +0 -1
- package/out/resources/whosonfirst/loader.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.d.ts +4 -1
- package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.js +8 -6
- package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.d.ts +6 -4
- package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.js +8 -4
- package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/definition.d.ts +5 -6
- package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/definition.js +3 -0
- package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/graph.d.ts +4 -2
- package/out/resources/whosonfirst/placetypes/graph.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/graph.js +0 -0
- package/out/resources/whosonfirst/placetypes/graph.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/mermaid.d.ts +4 -2
- package/out/resources/whosonfirst/placetypes/mermaid.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/mermaid.js +0 -1
- package/out/resources/whosonfirst/placetypes/mermaid.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/tree.d.ts +1 -1
- package/out/resources/whosonfirst/placetypes/tree.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/tree.js +0 -1
- package/out/resources/whosonfirst/placetypes/tree.js.map +1 -1
- package/out/routing/index.d.ts.map +1 -1
- package/out/routing/index.js +1 -1
- package/out/routing/index.js.map +1 -1
- package/out/scripting/utils/index.d.ts +3 -1
- package/out/scripting/utils/index.d.ts.map +1 -1
- package/out/scripting/utils/index.js +3 -1
- package/out/scripting/utils/index.js.map +1 -1
- package/out/tokenization/Span.js.map +1 -1
- package/out/tokenization/normalizer.js +11 -11
- package/out/tokenization/normalizer.js.map +1 -1
- package/out/tools/download-libpostal-resources.d.ts.map +1 -1
- package/out/tools/download-libpostal-resources.js.map +1 -1
- package/out/tools/download-ssl-address.d.ts +9 -3
- package/out/tools/download-ssl-address.d.ts.map +1 -1
- package/out/tools/download-ssl-address.js +8 -4
- package/out/tools/download-ssl-address.js.map +1 -1
- package/out/tools/generate-language-types.d.ts +12 -4
- package/out/tools/generate-language-types.d.ts.map +1 -1
- package/out/tools/generate-language-types.js +3 -1
- package/out/tools/generate-language-types.js.map +1 -1
- package/out/types/Classification.d.ts.map +1 -1
- package/out/types/Classification.js.map +1 -1
- package/out/types/classifier.d.ts +27 -9
- package/out/types/classifier.d.ts.map +1 -1
- package/out/types/component.d.ts +6 -2
- package/out/types/component.d.ts.map +1 -1
- package/out/types/component.js.map +1 -1
- package/out/utils/data-root.d.ts +3 -1
- package/out/utils/data-root.d.ts.map +1 -1
- package/out/utils/data-root.js +3 -1
- package/out/utils/data-root.js.map +1 -1
- package/out/utils/hash.d.ts +6 -2
- package/out/utils/hash.d.ts.map +1 -1
- package/out/utils/hash.js +6 -2
- package/out/utils/hash.js.map +1 -1
- package/out/utils/jsonl.d.ts +9 -3
- package/out/utils/jsonl.d.ts.map +1 -1
- package/out/utils/jsonl.js +9 -3
- package/out/utils/jsonl.js.map +1 -1
- package/out/utils/python-json.d.ts +6 -2
- package/out/utils/python-json.d.ts.map +1 -1
- package/out/utils/python-json.js +9 -3
- package/out/utils/python-json.js.map +1 -1
- package/out/utils/python-random.d.ts +15 -5
- package/out/utils/python-random.d.ts.map +1 -1
- package/out/utils/python-random.js +17 -7
- package/out/utils/python-random.js.map +1 -1
- package/out/utils/repo.d.ts +4 -0
- package/out/utils/repo.d.ts.map +1 -1
- package/out/utils/repo.js +4 -0
- package/out/utils/repo.js.map +1 -1
- package/out/utils/sealed-db.d.ts +6 -2
- package/out/utils/sealed-db.d.ts.map +1 -1
- package/out/utils/sealed-db.js +6 -2
- package/out/utils/sealed-db.js.map +1 -1
- package/out/utils/stats.d.ts +9 -3
- package/out/utils/stats.d.ts.map +1 -1
- package/out/utils/stats.js +11 -5
- package/out/utils/stats.js.map +1 -1
- package/package.json +2 -2
- package/pipeline/index.ts +5 -1
- package/pipeline/reconcile-lookups.ts +3 -0
- package/pipeline/reconcile.ts +65 -24
- package/pipeline/runtime-pipeline.ts +95 -46
- package/pipeline/span-logit-aggregation.ts +7 -2
- package/pipeline/span-proposer.ts +95 -34
- package/pipeline/types.ts +88 -19
- package/policy/proposal-collection.ts +4 -3
- package/policy/registry.ts +13 -3
- package/resolver/index.ts +1 -0
- package/resolver/types.ts +95 -30
- package/resources/LocaleIndex.ts +2 -2
- package/resources/ResourceMapCache.ts +3 -2
- package/resources/collections.ts +4 -1
- package/resources/languages/index.ts +2 -1
- package/resources/libpostal.ts +6 -3
- package/resources/set.ts +6 -6
- package/resources/whosonfirst/DataSourceCache.ts +2 -24
- package/resources/whosonfirst/PlacetypeDataSource.ts +2 -2
- package/resources/whosonfirst/backoff.ts +39 -0
- package/resources/whosonfirst/loader.ts +2 -1
- package/resources/whosonfirst/placetypes/Placetype.ts +9 -6
- package/resources/whosonfirst/placetypes/admin.ts +12 -7
- package/resources/whosonfirst/placetypes/definition.ts +6 -6
- package/resources/whosonfirst/placetypes/graph.ts +0 -0
- package/resources/whosonfirst/placetypes/mermaid.ts +5 -2
- package/resources/whosonfirst/placetypes/tree.ts +1 -1
- package/routing/index.ts +5 -1
- package/scripting/utils/index.ts +3 -1
- package/tokenization/Span.ts +1 -1
- package/tokenization/normalizer.ts +11 -11
- package/tools/download-libpostal-resources.ts +1 -0
- package/tools/download-ssl-address.ts +19 -7
- package/tools/generate-language-types.ts +12 -4
- package/types/Classification.ts +5 -0
- package/types/classifier.ts +27 -9
- package/types/component.ts +6 -2
- package/utils/data-root.ts +3 -1
- package/utils/hash.ts +6 -2
- package/utils/jsonl.ts +11 -3
- package/utils/python-json.ts +13 -4
- package/utils/python-random.ts +17 -7
- package/utils/repo.ts +8 -0
- package/utils/sealed-db.ts +10 -2
- package/utils/stats.ts +11 -5
package/api/APIClient.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
|
|
17
17
|
import { delegateAxiosError } from "./responses.ts"
|
|
18
18
|
|
|
19
|
-
export type
|
|
19
|
+
export { type IRuntimeLogger } from "@mailwoman/core/logging"
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Configuration for an API client.
|
|
@@ -78,6 +78,7 @@ export class APIClient<C extends APIClientConfig = APIClientConfig> extends Even
|
|
|
78
78
|
...config.axios,
|
|
79
79
|
})
|
|
80
80
|
|
|
81
|
+
// oxlint-disable-next-line unicorn/prefer-ternary -- the branches are multi-line client constructions
|
|
81
82
|
if (config.caching) {
|
|
82
83
|
this.axios = setupCache(axiosInstance, {
|
|
83
84
|
debug: (msg) => {
|
|
@@ -102,7 +103,7 @@ export class APIClient<C extends APIClientConfig = APIClientConfig> extends Even
|
|
|
102
103
|
|
|
103
104
|
this.axios.interceptors.response.use(undefined, delegateAxiosError)
|
|
104
105
|
|
|
105
|
-
this.#requestInterval = typeof config.requestsPerMinute === "number" ?
|
|
106
|
+
this.#requestInterval = typeof config.requestsPerMinute === "number" ? 60_000 / config.requestsPerMinute : 0
|
|
106
107
|
|
|
107
108
|
if (this.#requestInterval) {
|
|
108
109
|
this.axios.interceptors.response.use(this.updateCooldownAfterResponse)
|
|
@@ -165,8 +166,6 @@ export class APIClient<C extends APIClientConfig = APIClientConfig> extends Even
|
|
|
165
166
|
if (isAsyncDisposable(storedCache)) {
|
|
166
167
|
await storedCache[Symbol.asyncDispose]()
|
|
167
168
|
}
|
|
168
|
-
|
|
169
|
-
return Promise.resolve()
|
|
170
169
|
}
|
|
171
170
|
|
|
172
171
|
public override toString() {
|
package/api/responses.ts
CHANGED
|
@@ -31,6 +31,7 @@ export type ExtractResponseData<T> = T extends ResponseContainer<infer Body> ? B
|
|
|
31
31
|
|
|
32
32
|
function isResponseContainer<Body>(responseContainer: ResponseLike<Body>): responseContainer is ResponseContainer<Body>
|
|
33
33
|
function isResponseContainer<Body>(body: Body): body is Body
|
|
34
|
+
|
|
34
35
|
function isResponseContainer<Body>(input: ResponseLike<Body>): input is ResponseContainer<Body> {
|
|
35
36
|
return typeof input === "object" && input !== null && "data" in input
|
|
36
37
|
}
|
|
@@ -40,6 +41,7 @@ function isResponseContainer<Body>(input: ResponseLike<Body>): input is Response
|
|
|
40
41
|
*/
|
|
41
42
|
function pluckResponseBody<Body>(responseContainer: ResponseContainer<Body>): Body
|
|
42
43
|
function pluckResponseBody<Body>(rawBody: Body): Body
|
|
44
|
+
|
|
43
45
|
function pluckResponseBody<Body>(input: ResponseContainer<Body> | Body): Body {
|
|
44
46
|
if (isResponseContainer(input)) return input.data
|
|
45
47
|
|
|
@@ -67,6 +69,7 @@ export type ExtractResponseBodyData<Body> = Body extends {
|
|
|
67
69
|
* @internal
|
|
68
70
|
*/
|
|
69
71
|
export function pluckResponseData<Body>(responseContainer: ResponseContainer<Body>): ExtractResponseBodyData<Body>
|
|
72
|
+
|
|
70
73
|
export function pluckResponseData<Body>(input: ResponseContainer<Body> | Body): ExtractResponseBodyData<Body> {
|
|
71
74
|
const body = pluckResponseBody(input)
|
|
72
75
|
|
|
@@ -92,7 +95,7 @@ export function checkConnectivity(
|
|
|
92
95
|
*/
|
|
93
96
|
export async function delegateAxiosError(error: unknown): Promise<unknown> {
|
|
94
97
|
{
|
|
95
|
-
if (!isAxiosError(error))
|
|
98
|
+
if (!isAxiosError(error)) throw error
|
|
96
99
|
|
|
97
100
|
const { response, code: networkErrorCode } = error
|
|
98
101
|
|
|
@@ -125,11 +128,11 @@ export async function delegateAxiosError(error: unknown): Promise<unknown> {
|
|
|
125
128
|
case AxiosError.ERR_CANCELED:
|
|
126
129
|
case AxiosError.ECONNABORTED:
|
|
127
130
|
case AxiosError.ETIMEDOUT:
|
|
128
|
-
return
|
|
131
|
+
return
|
|
129
132
|
default:
|
|
130
133
|
ConsoleLogger.warn(`Unhandled network error: ${networkErrorCode}`)
|
|
131
134
|
}
|
|
132
135
|
|
|
133
|
-
|
|
136
|
+
throw error
|
|
134
137
|
}
|
|
135
138
|
}
|
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { $public } from "../env/index.ts"
|
|
14
|
-
import {
|
|
14
|
+
import { featurize } from "./featurize.ts"
|
|
15
|
+
|
|
16
|
+
export { COARSE_CLASSES, FEATURE_DIM, featurize } from "./featurize.ts"
|
|
15
17
|
|
|
16
|
-
/** Serialized model: metadata in JSON, the dense `weights` (row-major [class][feature]) alongside. */
|
|
17
18
|
export interface CoarsePlacerArtifact {
|
|
18
19
|
/**
|
|
19
20
|
* The coarse placer's classes (the country/region codes it routes to).
|
|
@@ -47,7 +48,9 @@ export interface CoarsePlacerMeta {
|
|
|
47
48
|
temperature: number
|
|
48
49
|
bias: number[]
|
|
49
50
|
quantization?: "int8-per-row"
|
|
50
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Per-class dequantization scale; present iff `quantization === "int8-per-row"`.
|
|
53
|
+
*/
|
|
51
54
|
scales?: number[]
|
|
52
55
|
}
|
|
53
56
|
|
|
@@ -82,17 +85,25 @@ export function dequantizeInt8Weights(
|
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
export interface CoarsePrediction {
|
|
85
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* The predicted class, or `null` when the model abstained (confidence below the threshold).
|
|
90
|
+
*/
|
|
86
91
|
country: string | null
|
|
87
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Calibrated probability of the top class (the abstention signal).
|
|
94
|
+
*/
|
|
88
95
|
confidence: number
|
|
89
96
|
abstained: boolean
|
|
90
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* The full calibrated class distribution.
|
|
99
|
+
*/
|
|
91
100
|
probs: Record<string, number>
|
|
92
101
|
}
|
|
93
102
|
|
|
94
103
|
export interface CoarsePlacerOpts {
|
|
95
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* Abstain when the calibrated top-class confidence is below this (default 0.5).
|
|
106
|
+
*/
|
|
96
107
|
abstainBelow?: number
|
|
97
108
|
/**
|
|
98
109
|
* Open-set reject rule (#244 M2). When `true`, the ABSTAIN decision uses the total IN-MAP probability mass `1 -
|
|
@@ -189,8 +200,10 @@ export class CoarsePlacer {
|
|
|
189
200
|
for (const i of feats) {
|
|
190
201
|
s += this.#weights[base + i]!
|
|
191
202
|
}
|
|
203
|
+
|
|
192
204
|
logits[c] = s / this.#temp
|
|
193
205
|
}
|
|
206
|
+
|
|
194
207
|
// Numerically-stable softmax.
|
|
195
208
|
let maxLogit = -Infinity
|
|
196
209
|
|
|
@@ -198,6 +211,7 @@ export class CoarsePlacer {
|
|
|
198
211
|
if (logits[c]! > maxLogit) {
|
|
199
212
|
maxLogit = logits[c]!
|
|
200
213
|
}
|
|
214
|
+
|
|
201
215
|
let sum = 0
|
|
202
216
|
const probs = new Float32Array(C)
|
|
203
217
|
|
|
@@ -206,6 +220,7 @@ export class CoarsePlacer {
|
|
|
206
220
|
probs[c] = e
|
|
207
221
|
sum += e
|
|
208
222
|
}
|
|
223
|
+
|
|
209
224
|
let topIdx = 0
|
|
210
225
|
let topProb = -1
|
|
211
226
|
let otherProb = 0
|
|
@@ -293,14 +308,16 @@ export function inMapPosterior(
|
|
|
293
308
|
|
|
294
309
|
// The argmax always survives (it is ≥ every other marginal; if even it fell below the floor the
|
|
295
310
|
// prediction would have abstained upstream) — but guard anyway so the posterior is never empty.
|
|
296
|
-
if (Object.keys(posterior).length
|
|
311
|
+
if (!Object.keys(posterior).length) {
|
|
297
312
|
posterior[prediction.country] = prediction.confidence
|
|
298
313
|
}
|
|
299
314
|
|
|
300
315
|
return posterior
|
|
301
316
|
}
|
|
302
317
|
|
|
303
|
-
/**
|
|
318
|
+
/**
|
|
319
|
+
* Load a coarse-placer from a JSON metadata file + a sibling `.weights.bin` (Float32).
|
|
320
|
+
*/
|
|
304
321
|
export async function loadCoarsePlacer(
|
|
305
322
|
metaJson: { classes: string[]; featureDim: number; temperature: number; bias: number[] },
|
|
306
323
|
weights: Float32Array,
|
|
@@ -308,5 +325,3 @@ export async function loadCoarsePlacer(
|
|
|
308
325
|
): Promise<CoarsePlacer> {
|
|
309
326
|
return new CoarsePlacer({ ...metaJson, weights }, opts)
|
|
310
327
|
}
|
|
311
|
-
|
|
312
|
-
export { COARSE_CLASSES, FEATURE_DIM, featurize }
|
|
@@ -64,6 +64,7 @@ export const COARSE_CLASSES = [
|
|
|
64
64
|
"AU",
|
|
65
65
|
"OTHER",
|
|
66
66
|
] as const
|
|
67
|
+
|
|
67
68
|
export type CoarseClass = (typeof COARSE_CLASSES)[number]
|
|
68
69
|
|
|
69
70
|
/**
|
|
@@ -72,7 +73,9 @@ export type CoarseClass = (typeof COARSE_CLASSES)[number]
|
|
|
72
73
|
*/
|
|
73
74
|
export const FEATURE_DIM = 1 << 16
|
|
74
75
|
|
|
75
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Coarse Unicode-script buckets — strong priors the n-grams refine.
|
|
78
|
+
*/
|
|
76
79
|
const SCRIPTS = [
|
|
77
80
|
"latin",
|
|
78
81
|
"cjk",
|
|
@@ -85,43 +88,47 @@ const SCRIPTS = [
|
|
|
85
88
|
"digit",
|
|
86
89
|
"other",
|
|
87
90
|
] as const
|
|
91
|
+
|
|
88
92
|
type Script = (typeof SCRIPTS)[number]
|
|
89
93
|
|
|
90
94
|
function scriptOf(cp: number): Script {
|
|
91
95
|
if (cp >= 0x30 && cp <= 0x39) return "digit"
|
|
92
96
|
|
|
93
|
-
if ((cp >= 0x41 && cp <= 0x5a) || (cp >= 0x61 && cp <= 0x7a) || (cp >= 0xc0 && cp <=
|
|
97
|
+
if ((cp >= 0x41 && cp <= 0x5a) || (cp >= 0x61 && cp <= 0x7a) || (cp >= 0xc0 && cp <= 0x2_4f)) return "latin"
|
|
94
98
|
|
|
95
99
|
if (
|
|
96
|
-
(cp >=
|
|
97
|
-
(cp >=
|
|
98
|
-
(cp >=
|
|
99
|
-
(cp >=
|
|
100
|
+
(cp >= 0x30_40 && cp <= 0x30_ff) ||
|
|
101
|
+
(cp >= 0x4e_00 && cp <= 0x9f_ff) ||
|
|
102
|
+
(cp >= 0xac_00 && cp <= 0xd7_af) ||
|
|
103
|
+
(cp >= 0x34_00 && cp <= 0x4d_bf)
|
|
100
104
|
)
|
|
101
105
|
return "cjk"
|
|
102
106
|
|
|
103
|
-
if ((cp >=
|
|
107
|
+
if ((cp >= 0x4_00 && cp <= 0x5_2f) || (cp >= 0x2d_e0 && cp <= 0x2d_ff)) return "cyrillic"
|
|
104
108
|
|
|
105
|
-
if ((cp >=
|
|
109
|
+
if ((cp >= 0x6_00 && cp <= 0x6_ff) || (cp >= 0x7_50 && cp <= 0x7_7f) || (cp >= 0xfb_50 && cp <= 0xfe_ff))
|
|
110
|
+
return "arabic"
|
|
106
111
|
|
|
107
|
-
if (cp >=
|
|
112
|
+
if (cp >= 0x3_70 && cp <= 0x3_ff) return "greek"
|
|
108
113
|
|
|
109
|
-
if (cp >=
|
|
114
|
+
if (cp >= 0x5_90 && cp <= 0x5_ff) return "hebrew"
|
|
110
115
|
|
|
111
|
-
if (cp >=
|
|
116
|
+
if (cp >= 0x9_00 && cp <= 0x9_7f) return "devanagari"
|
|
112
117
|
|
|
113
|
-
if (cp >=
|
|
118
|
+
if (cp >= 0xe_00 && cp <= 0xe_7f) return "thai"
|
|
114
119
|
|
|
115
120
|
return "other"
|
|
116
121
|
}
|
|
117
122
|
|
|
118
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* FNV-1a → a feature bucket in [0, FEATURE_DIM).
|
|
125
|
+
*/
|
|
119
126
|
function bucket(s: string, salt: number): number {
|
|
120
|
-
let h = (
|
|
127
|
+
let h = (2_166_136_261 ^ salt) >>> 0
|
|
121
128
|
|
|
122
129
|
for (let i = 0; i < s.length; i++) {
|
|
123
130
|
h ^= s.charCodeAt(i)
|
|
124
|
-
h = Math.imul(h,
|
|
131
|
+
h = Math.imul(h, 16_777_619)
|
|
125
132
|
}
|
|
126
133
|
|
|
127
134
|
return (h >>> 0) % FEATURE_DIM
|
|
@@ -133,7 +140,7 @@ function bucket(s: string, salt: number): number {
|
|
|
133
140
|
* PRESERVED (lowercasing only touches cased scripts).
|
|
134
141
|
*/
|
|
135
142
|
export function featurize(text: string): number[] {
|
|
136
|
-
const norm = text.toLowerCase().
|
|
143
|
+
const norm = text.toLowerCase().replaceAll(/\s+/g, " ").trim()
|
|
137
144
|
|
|
138
145
|
if (!norm) return []
|
|
139
146
|
const active = new Set<number>()
|
|
@@ -145,6 +152,7 @@ export function featurize(text: string): number[] {
|
|
|
145
152
|
const sc = scriptOf(ch.codePointAt(0)!)
|
|
146
153
|
counts.set(sc, (counts.get(sc) ?? 0) + 1)
|
|
147
154
|
}
|
|
155
|
+
|
|
148
156
|
let dominant: Script = "other"
|
|
149
157
|
let max = -1
|
|
150
158
|
|
|
@@ -156,6 +164,7 @@ export function featurize(text: string): number[] {
|
|
|
156
164
|
dominant = sc
|
|
157
165
|
}
|
|
158
166
|
}
|
|
167
|
+
|
|
159
168
|
active.add(bucket(`__dom_${dominant}`, 2))
|
|
160
169
|
|
|
161
170
|
// Char n-grams (3,4,5) over the boundary-marked string.
|
|
@@ -30,15 +30,23 @@ interface DatasetRow {
|
|
|
30
30
|
country: string
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Options for {@linkcode buildDataset}.
|
|
35
|
+
*/
|
|
34
36
|
export interface BuildDatasetOptions {
|
|
35
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Rows sampled per country. Default 50000.
|
|
39
|
+
*/
|
|
36
40
|
perCountry?: number
|
|
37
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Dataset output dir. Default `<repo>/data/coarse-placer`.
|
|
43
|
+
*/
|
|
38
44
|
data?: string
|
|
39
45
|
}
|
|
40
46
|
|
|
41
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Result of {@linkcode buildDataset}.
|
|
49
|
+
*/
|
|
42
50
|
export interface BuildDatasetResult {
|
|
43
51
|
outDir: string
|
|
44
52
|
train: number
|
|
@@ -51,17 +59,20 @@ const TEST_FRAC = 0.1
|
|
|
51
59
|
|
|
52
60
|
const COUNTRIES = ["US", "FR", "GB", "CN", "NL", "IT", "DE", "JP", "ES", "KR", "TW"]
|
|
53
61
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
/**
|
|
63
|
+
* #743: the EU expansion. The v0.5.0 corpus carries zero rows for these locales, so they're drawn from the Overture
|
|
64
|
+
* per-country addresses theme (the same source build-eu-eval-set.ts uses). They were previously OTHER outlier exposure
|
|
65
|
+
* (PL/PT/CZ) or simply unrepresentable; here they become first-class in-map countries so the soft country prior can pin
|
|
66
|
+
* them.
|
|
67
|
+
*/
|
|
58
68
|
const NEW_EU = ["AT", "BE", "CH", "CZ", "DK", "EE", "FI", "HR", "LT", "LU", "LV", "NO", "PL", "PT", "SI", "SK"]
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
/**
|
|
70
|
+
* #743 in-map dilution fix: DE/ES/IT/NL are already in COUNTRIES (corpus format), but the eu-eval sets + every NEW_EU
|
|
71
|
+
* country are Overture format. Without an Overture sample of their OWN, their Overture-format eval rows scatter to the
|
|
72
|
+
* Overture-trained neighbours (measured: only 63% of ES eval rows routed ES, ~26% leaked to CH/PT/HR/IT/FR/CZ).
|
|
73
|
+
* SUPPLEMENT their corpus rows with an Overture sample so each owns its own format shape; the format then stops being
|
|
74
|
+
* discriminative and the model falls back to the linguistic n-grams. GB excluded — its Overture parquet is empty.
|
|
75
|
+
*/
|
|
65
76
|
const IN_MAP_EU = ["DE", "ES", "IT", "NL"]
|
|
66
77
|
|
|
67
78
|
// #743 EU expansion: draw the new in-map countries from the Overture per-country addresses theme.
|
|
@@ -86,15 +97,18 @@ function formatEu(street: unknown, number: unknown, postcode: unknown, loc: stri
|
|
|
86
97
|
}
|
|
87
98
|
}
|
|
88
99
|
|
|
89
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Coarse-placer dataset builder — see the module doc.
|
|
102
|
+
*/
|
|
90
103
|
export async function buildDataset(
|
|
91
104
|
options: BuildDatasetOptions = {},
|
|
92
105
|
report?: (line: string) => void
|
|
93
106
|
): Promise<BuildDatasetResult> {
|
|
94
|
-
const PER = options.perCountry ??
|
|
107
|
+
const PER = options.perCountry ?? 50_000
|
|
95
108
|
const OUT_DIR = options.data || repoRootPath("data", "coarse-placer")
|
|
96
109
|
|
|
97
110
|
const TRAIN_GLOB = dataRootPath("corpus", "versioned", "v0.5.0", "corpus-v0.5.0", "train", "*.parquet")
|
|
111
|
+
|
|
98
112
|
// #244/#928 AU expansion: the v0.5.0 pin carries only ~5.9k AU rows; the v0.9.2 G-NAF shard carries
|
|
99
113
|
// 150k real Australian addresses. AU rides the SAME corpus sampling path as COUNTRIES, just from its
|
|
100
114
|
// own glob — the (country, glob) pairs below unify the two.
|
|
@@ -106,6 +120,7 @@ export async function buildDataset(
|
|
|
106
120
|
"train",
|
|
107
121
|
"*.parquet"
|
|
108
122
|
)
|
|
123
|
+
|
|
109
124
|
const OVERTURE_DIR = dataRootPath("overture", "2026-06-17.0")
|
|
110
125
|
mkdirSync(OUT_DIR, { recursive: true })
|
|
111
126
|
|
|
@@ -128,6 +143,7 @@ export async function buildDataset(
|
|
|
128
143
|
const q = `SELECT raw FROM (
|
|
129
144
|
SELECT raw FROM read_parquet('${glob}') WHERE country = '${country}' AND nullif(trim(raw), '') IS NOT NULL
|
|
130
145
|
) USING SAMPLE ${Math.ceil(PER * 1.3)} ROWS`
|
|
146
|
+
|
|
131
147
|
const res = await duck.runAndReadAll(q)
|
|
132
148
|
const seen = new Set<string>()
|
|
133
149
|
const rows: string[] = []
|
|
@@ -140,6 +156,7 @@ export async function buildDataset(
|
|
|
140
156
|
seen.add(raw)
|
|
141
157
|
rows.push(raw)
|
|
142
158
|
}
|
|
159
|
+
|
|
143
160
|
const nVal = Math.floor(rows.length * VAL_FRAC)
|
|
144
161
|
const nTest = Math.floor(rows.length * TEST_FRAC)
|
|
145
162
|
const valRows = rows.slice(0, nVal)
|
|
@@ -157,24 +174,29 @@ export async function buildDataset(
|
|
|
157
174
|
for (const raw of testRows) {
|
|
158
175
|
test.push({ raw, country })
|
|
159
176
|
}
|
|
177
|
+
|
|
160
178
|
report?.(` ${country}: train ${trainRows.length} val ${valRows.length} test ${testRows.length}`)
|
|
161
179
|
}
|
|
162
180
|
|
|
163
181
|
for (const country of [...NEW_EU, ...IN_MAP_EU]) {
|
|
164
182
|
const parquet = `${OVERTURE_DIR}/addresses-${country.toLowerCase()}.parquet`
|
|
183
|
+
|
|
165
184
|
const q = `SELECT street, number, postcode,
|
|
166
185
|
COALESCE(NULLIF(trim(postal_city), ''), address_levels[len(address_levels)].value) AS loc
|
|
167
186
|
FROM read_parquet('${parquet}')
|
|
168
187
|
WHERE street IS NOT NULL AND trim(street) <> ''
|
|
169
188
|
USING SAMPLE ${Math.ceil(PER * 1.4)} ROWS`
|
|
189
|
+
|
|
170
190
|
let res
|
|
171
191
|
|
|
172
192
|
try {
|
|
173
193
|
res = await duck.runAndReadAll(q)
|
|
174
|
-
} catch (
|
|
175
|
-
report?.(` ${country}: SKIPPED — ${(
|
|
194
|
+
} catch (error) {
|
|
195
|
+
report?.(` ${country}: SKIPPED — ${(error as Error).message}`)
|
|
196
|
+
|
|
176
197
|
continue
|
|
177
198
|
}
|
|
199
|
+
|
|
178
200
|
const seen = new Set<string>()
|
|
179
201
|
const rows: string[] = []
|
|
180
202
|
|
|
@@ -189,6 +211,7 @@ export async function buildDataset(
|
|
|
189
211
|
seen.add(raw)
|
|
190
212
|
rows.push(raw)
|
|
191
213
|
}
|
|
214
|
+
|
|
192
215
|
const nVal = Math.floor(rows.length * VAL_FRAC)
|
|
193
216
|
const nTest = Math.floor(rows.length * TEST_FRAC)
|
|
194
217
|
|
|
@@ -203,6 +226,7 @@ export async function buildDataset(
|
|
|
203
226
|
for (const raw of rows.slice(nVal + nTest)) {
|
|
204
227
|
train.push({ raw, country })
|
|
205
228
|
}
|
|
229
|
+
|
|
206
230
|
report?.(` ${country} (overture): train ${rows.length - nVal - nTest} val ${nVal} test ${nTest}`)
|
|
207
231
|
}
|
|
208
232
|
|
|
@@ -24,23 +24,42 @@ import { dataRootPath } from "../../utils/data-root.ts"
|
|
|
24
24
|
import { repoRootPath } from "../../utils/repo.ts"
|
|
25
25
|
import { hashFNV1a } from "./fnv-hash.ts"
|
|
26
26
|
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Share of a bucket that must be off-map before it is treated as an exposure case rather than noise.
|
|
29
|
+
*/
|
|
30
|
+
const OFFMAP_DOMINANCE = 0.6
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Options for {@linkcode buildOutlierExposure}.
|
|
34
|
+
*/
|
|
28
35
|
export interface BuildOutlierExposureOptions {
|
|
29
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Names sampled per off-map language. Default 2500.
|
|
38
|
+
*/
|
|
30
39
|
perLang?: number
|
|
31
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* WOF admin SQLite path. Default `$MAILWOMAN_DATA_ROOT/wof/admin-global-priority.db`.
|
|
42
|
+
*/
|
|
32
43
|
wof?: string
|
|
33
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Dataset dir the OTHER rows append to. Default `<repo>/data/coarse-placer`.
|
|
46
|
+
*/
|
|
34
47
|
data?: string
|
|
35
48
|
}
|
|
36
49
|
|
|
37
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Result of {@linkcode buildOutlierExposure}.
|
|
52
|
+
*/
|
|
38
53
|
export interface BuildOutlierExposureResult {
|
|
39
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* Total OTHER pool size (names + address-shaped variants).
|
|
56
|
+
*/
|
|
40
57
|
total: number
|
|
41
58
|
}
|
|
42
59
|
|
|
43
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Off-map languages whose `names` are written in a NON-Latin, NON-CJK script (CJK = the in-map CN/JP/KR/TW).
|
|
62
|
+
*/
|
|
44
63
|
const OFF_MAP_LANGS = [
|
|
45
64
|
"rus",
|
|
46
65
|
"ukr",
|
|
@@ -75,7 +94,9 @@ const OFF_MAP_LANGS = [
|
|
|
75
94
|
"amh", // Georgian / Armenian / Ethiopic
|
|
76
95
|
]
|
|
77
96
|
|
|
78
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Dominant script must be off-map: has chars in a non-Latin, non-CJK, non-digit block.
|
|
99
|
+
*/
|
|
79
100
|
function isOffMapScript(s: string): boolean {
|
|
80
101
|
let off = 0
|
|
81
102
|
let total = 0
|
|
@@ -83,21 +104,24 @@ function isOffMapScript(s: string): boolean {
|
|
|
83
104
|
for (const ch of s) {
|
|
84
105
|
const cp = ch.codePointAt(0)!
|
|
85
106
|
|
|
86
|
-
if (cp <= 0x40 || (cp >= 0x5b && cp <= 0x60) || cp === 0x20) continue
|
|
107
|
+
if (cp <= 0x40 || (cp >= 0x5b && cp <= 0x60) || cp === 0x20) continue
|
|
108
|
+
|
|
109
|
+
// punct/space/digits
|
|
87
110
|
total++
|
|
88
|
-
const latin = (cp >= 0x41 && cp <= 0x5a) || (cp >= 0x61 && cp <= 0x7a) || (cp >= 0xc0 && cp <=
|
|
111
|
+
const latin = (cp >= 0x41 && cp <= 0x5a) || (cp >= 0x61 && cp <= 0x7a) || (cp >= 0xc0 && cp <= 0x2_4f)
|
|
112
|
+
|
|
89
113
|
const cjk =
|
|
90
|
-
(cp >=
|
|
91
|
-
(cp >=
|
|
92
|
-
(cp >=
|
|
93
|
-
(cp >=
|
|
114
|
+
(cp >= 0x30_40 && cp <= 0x30_ff) ||
|
|
115
|
+
(cp >= 0x4e_00 && cp <= 0x9f_ff) ||
|
|
116
|
+
(cp >= 0xac_00 && cp <= 0xd7_af) ||
|
|
117
|
+
(cp >= 0x34_00 && cp <= 0x4d_bf)
|
|
94
118
|
|
|
95
|
-
if (!latin && !cjk && cp >
|
|
119
|
+
if (!latin && !cjk && cp > 0x2_ff) {
|
|
96
120
|
off++
|
|
97
121
|
}
|
|
98
122
|
}
|
|
99
123
|
|
|
100
|
-
return total > 0 && off / total >
|
|
124
|
+
return total > 0 && off / total > OFFMAP_DOMINANCE
|
|
101
125
|
}
|
|
102
126
|
|
|
103
127
|
// Mimic a real off-map ADDRESS: a pure-script place name isn't what we see at inference (those carry
|
|
@@ -118,7 +142,9 @@ function addressVariant(name: string, h: number): string {
|
|
|
118
142
|
}
|
|
119
143
|
}
|
|
120
144
|
|
|
121
|
-
/**
|
|
145
|
+
/**
|
|
146
|
+
* Coarse-placer non-Latin outlier-exposure builder — see the module doc.
|
|
147
|
+
*/
|
|
122
148
|
export async function buildOutlierExposure(
|
|
123
149
|
options: BuildOutlierExposureOptions = {},
|
|
124
150
|
report?: (line: string) => void
|
|
@@ -135,6 +161,7 @@ export async function buildOutlierExposure(
|
|
|
135
161
|
const rows = db
|
|
136
162
|
.prepare(`SELECT name FROM names WHERE language = ? AND length(name) >= 4 LIMIT ?`)
|
|
137
163
|
.all(lang, PER * 2)
|
|
164
|
+
|
|
138
165
|
let kept = 0
|
|
139
166
|
|
|
140
167
|
for (const r of rows) {
|
|
@@ -144,17 +171,22 @@ export async function buildOutlierExposure(
|
|
|
144
171
|
if (!name || seen.has(name) || !isOffMapScript(name)) continue
|
|
145
172
|
seen.add(name)
|
|
146
173
|
pool.push(name)
|
|
147
|
-
pool.push(addressVariant(name, hashFNV1a(name)))
|
|
174
|
+
pool.push(addressVariant(name, hashFNV1a(name)))
|
|
175
|
+
|
|
176
|
+
// address-shaped sibling
|
|
148
177
|
kept++
|
|
149
178
|
}
|
|
179
|
+
|
|
150
180
|
report?.(` ${lang}: ${kept}`)
|
|
151
181
|
}
|
|
182
|
+
|
|
152
183
|
db.close()
|
|
153
184
|
|
|
154
185
|
// Deterministic shuffle (FNV hash sort) + split 80/10/10, append as OTHER.
|
|
155
186
|
pool.sort((a, b) => hashFNV1a(a) - hashFNV1a(b))
|
|
156
187
|
const nVal = Math.floor(pool.length * 0.1)
|
|
157
188
|
const nTest = Math.floor(pool.length * 0.1)
|
|
189
|
+
|
|
158
190
|
const splits: Record<string, string[]> = {
|
|
159
191
|
val: pool.slice(0, nVal),
|
|
160
192
|
test: pool.slice(nVal, nVal + nTest),
|
|
@@ -166,6 +198,7 @@ export async function buildOutlierExposure(
|
|
|
166
198
|
appendFileSync(path.join(dataDir, `${split}.jsonl`), lines)
|
|
167
199
|
report?.(`appended ${names.length} OTHER → ${split}.jsonl`)
|
|
168
200
|
}
|
|
201
|
+
|
|
169
202
|
report?.(`total OTHER pool: ${pool.length}`)
|
|
170
203
|
|
|
171
204
|
return { total: pool.length }
|