@mailwoman/core 5.5.0 → 5.7.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/data/chromium-i18n/ssl-address-download.ts +7 -11
- package/data/libpostal/resources-download.ts +9 -12
- package/out/coarse-placer/coarse-placer.d.ts.map +1 -1
- package/out/coarse-placer/coarse-placer.js +12 -7
- package/out/coarse-placer/coarse-placer.js.map +1 -1
- package/out/coarse-placer/tools/build-dataset.d.ts +21 -0
- package/out/coarse-placer/tools/build-dataset.d.ts.map +1 -0
- package/out/coarse-placer/tools/build-dataset.js +171 -0
- package/out/coarse-placer/tools/build-dataset.js.map +1 -0
- package/out/coarse-placer/tools/build-outlier-exposure.d.ts +19 -0
- package/out/coarse-placer/tools/build-outlier-exposure.d.ts.map +1 -0
- package/out/coarse-placer/tools/build-outlier-exposure.js +144 -0
- package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -0
- package/out/coarse-placer/tools/build-outlier-latin.d.ts +2 -0
- package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -0
- package/out/coarse-placer/tools/build-outlier-latin.js +155 -0
- package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -0
- package/out/coarse-placer/tools/build-outlier-oa.d.ts +2 -0
- package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -0
- package/out/coarse-placer/tools/build-outlier-oa.js +182 -0
- package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -0
- package/out/coarse-placer/tools/eval-latin-offmap.d.ts +2 -0
- package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -0
- package/out/coarse-placer/tools/eval-latin-offmap.js +103 -0
- package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -0
- package/out/coarse-placer/tools/eval-openset.d.ts +34 -0
- package/out/coarse-placer/tools/eval-openset.d.ts.map +1 -0
- package/out/coarse-placer/tools/eval-openset.js +394 -0
- package/out/coarse-placer/tools/eval-openset.js.map +1 -0
- package/out/coarse-placer/tools/eval-quant-compare.d.ts +2 -0
- package/out/coarse-placer/tools/eval-quant-compare.d.ts.map +1 -0
- package/out/coarse-placer/tools/eval-quant-compare.js +107 -0
- package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -0
- package/out/coarse-placer/tools/eval.d.ts +14 -0
- package/out/coarse-placer/tools/eval.d.ts.map +1 -0
- package/out/coarse-placer/tools/eval.js +131 -0
- package/out/coarse-placer/tools/eval.js.map +1 -0
- package/out/coarse-placer/tools/probe-frontier.d.ts +23 -0
- package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -0
- package/out/coarse-placer/tools/probe-frontier.js +159 -0
- package/out/coarse-placer/tools/probe-frontier.js.map +1 -0
- package/out/coarse-placer/tools/quantize.d.ts +2 -0
- package/out/coarse-placer/tools/quantize.d.ts.map +1 -0
- package/out/coarse-placer/tools/quantize.js +80 -0
- package/out/coarse-placer/tools/quantize.js.map +1 -0
- package/out/coarse-placer/tools/train.d.ts +16 -0
- package/out/coarse-placer/tools/train.d.ts.map +1 -0
- package/out/coarse-placer/tools/train.js +173 -0
- package/out/coarse-placer/tools/train.js.map +1 -0
- package/out/data/chromium-i18n/ssl-address-download.js +5 -11
- package/out/data/chromium-i18n/ssl-address-download.js.map +1 -1
- package/out/data/libpostal/resources-download.js +7 -12
- package/out/data/libpostal/resources-download.js.map +1 -1
- package/out/decoder/arbitrate-tree.d.ts.map +1 -1
- package/out/decoder/arbitrate-tree.js +8 -4
- package/out/decoder/arbitrate-tree.js.map +1 -1
- package/out/decoder/build-tree.d.ts.map +1 -1
- package/out/decoder/build-tree.js +17 -9
- package/out/decoder/build-tree.js.map +1 -1
- package/out/decoder/calibration.d.ts.map +1 -1
- package/out/decoder/calibration.js +4 -2
- package/out/decoder/calibration.js.map +1 -1
- package/out/decoder/proposals-to-tree.d.ts.map +1 -1
- package/out/decoder/proposals-to-tree.js +4 -2
- package/out/decoder/proposals-to-tree.js.map +1 -1
- package/out/decoder/serialize-json.d.ts.map +1 -1
- package/out/decoder/serialize-json.js +10 -5
- package/out/decoder/serialize-json.js.map +1 -1
- package/out/decoder/serialize-tuples.d.ts.map +1 -1
- package/out/decoder/serialize-tuples.js +6 -3
- package/out/decoder/serialize-tuples.js.map +1 -1
- package/out/decoder/serialize-xml.d.ts.map +1 -1
- package/out/decoder/serialize-xml.js +6 -3
- package/out/decoder/serialize-xml.js.map +1 -1
- package/out/decoder/unknown-spans.d.ts.map +1 -1
- package/out/decoder/unknown-spans.js +6 -3
- package/out/decoder/unknown-spans.js.map +1 -1
- package/out/env/index.d.ts +7 -0
- package/out/env/index.d.ts.map +1 -1
- package/out/env/index.js +1 -0
- package/out/env/index.js.map +1 -1
- package/out/env/paths.d.ts.map +1 -1
- package/out/env/paths.js +2 -1
- package/out/env/paths.js.map +1 -1
- package/out/env/schema.d.ts +7 -0
- package/out/env/schema.d.ts.map +1 -1
- package/out/env/schema.js +11 -0
- package/out/env/schema.js.map +1 -1
- package/out/parser/proposal-pipeline.d.ts.map +1 -1
- package/out/parser/proposal-pipeline.js +8 -4
- package/out/parser/proposal-pipeline.js.map +1 -1
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.js +12 -6
- package/out/pipeline/runtime-pipeline.js.map +1 -1
- package/out/pipeline/span-logit-aggregation.js +2 -1
- package/out/pipeline/span-logit-aggregation.js.map +1 -1
- package/out/pipeline/span-proposer.d.ts.map +1 -1
- package/out/pipeline/span-proposer.js +14 -7
- package/out/pipeline/span-proposer.js.map +1 -1
- package/out/resolver/types.d.ts.map +1 -1
- package/out/resolver/types.js +2 -1
- package/out/resolver/types.js.map +1 -1
- package/out/resources/fs.js +1 -1
- package/out/resources/fs.js.map +1 -1
- package/out/resources/git.js +1 -1
- package/out/resources/git.js.map +1 -1
- package/out/resources/libpostal.js +1 -1
- package/out/resources/libpostal.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/mermaid.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/mermaid.js +2 -1
- package/out/resources/whosonfirst/placetypes/mermaid.js.map +1 -1
- package/out/types/mapping.d.ts.map +1 -1
- package/out/types/mapping.js +2 -1
- package/out/types/mapping.js.map +1 -1
- package/out/utils/data-root.d.ts +1 -1
- package/out/utils/data-root.d.ts.map +1 -1
- package/out/utils/data-root.js +11 -9
- package/out/utils/data-root.js.map +1 -1
- package/out/utils/index.d.ts +4 -0
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +4 -0
- package/out/utils/index.js.map +1 -1
- package/out/utils/python-json.d.ts +38 -0
- package/out/utils/python-json.d.ts.map +1 -0
- package/out/utils/python-json.js +90 -0
- package/out/utils/python-json.js.map +1 -0
- package/out/utils/python-random.d.ts +41 -0
- package/out/utils/python-random.d.ts.map +1 -0
- package/out/utils/python-random.js +78 -0
- package/out/utils/python-random.js.map +1 -0
- package/out/utils/repo.d.ts +16 -1
- package/out/utils/repo.d.ts.map +1 -1
- package/out/utils/repo.js +18 -1
- package/out/utils/repo.js.map +1 -1
- package/out/utils/scripting.d.ts +50 -0
- package/out/utils/scripting.d.ts.map +1 -0
- package/out/utils/scripting.js +99 -0
- package/out/utils/scripting.js.map +1 -0
- package/out/utils/sealed-db.d.ts +20 -0
- package/out/utils/sealed-db.d.ts.map +1 -0
- package/out/utils/sealed-db.js +74 -0
- package/out/utils/sealed-db.js.map +1 -0
- package/out/vitest.config.d.ts.map +1 -1
- package/out/vitest.config.js +1 -2
- package/out/vitest.config.js.map +1 -1
- package/package.json +6 -3
|
@@ -31,15 +31,16 @@
|
|
|
31
31
|
|
|
32
32
|
import { mkdir, writeFile } from "node:fs/promises"
|
|
33
33
|
import { join } from "node:path"
|
|
34
|
-
import { fileURLToPath } from "node:url"
|
|
35
34
|
import { parseArgs } from "node:util"
|
|
36
35
|
|
|
36
|
+
import { corePackagePath, runIfScript } from "@mailwoman/core/utils"
|
|
37
|
+
|
|
37
38
|
const BASE_URL = "https://chromium-i18n.appspot.com/ssl-address/data"
|
|
38
39
|
|
|
39
40
|
function parseCLIArgs() {
|
|
40
41
|
const { values } = parseArgs({
|
|
41
42
|
options: {
|
|
42
|
-
"out-dir": { type: "string", default:
|
|
43
|
+
"out-dir": { type: "string", default: corePackagePath("data", "chromium-i18n", "ssl-address") },
|
|
43
44
|
concurrency: { type: "string", default: "8" },
|
|
44
45
|
},
|
|
45
46
|
})
|
|
@@ -97,14 +98,9 @@ async function main(): Promise<void> {
|
|
|
97
98
|
|
|
98
99
|
process.stderr.write(`\n=== done: ${codes.length - failures}/${codes.length} written, ${failures} failed\n`)
|
|
99
100
|
|
|
100
|
-
if (failures > 0)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Run main() only when invoked directly (the import-safe equivalent of Python's `if __name__ ==
|
|
104
|
-
// "__main__"`), so importing this module evaluates it without firing the download.
|
|
105
|
-
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
|
|
106
|
-
main().catch((err: Error) => {
|
|
107
|
-
process.stderr.write(`fatal: ${err.message}\n${err.stack}\n`)
|
|
101
|
+
if (failures > 0) {
|
|
108
102
|
process.exitCode = 1
|
|
109
|
-
}
|
|
103
|
+
}
|
|
110
104
|
}
|
|
105
|
+
|
|
106
|
+
runIfScript(import.meta, main)
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
import { cp, mkdtemp, readdir, readFile, rm, stat, writeFile } from "node:fs/promises"
|
|
32
32
|
import { tmpdir } from "node:os"
|
|
33
33
|
import { join } from "node:path"
|
|
34
|
-
import { fileURLToPath } from "node:url"
|
|
35
34
|
import { parseArgs } from "node:util"
|
|
36
35
|
|
|
36
|
+
import { resourceDictionaryPath, runIfScript } from "@mailwoman/core/utils"
|
|
37
37
|
import { $ } from "zx"
|
|
38
38
|
|
|
39
39
|
const REPO_URL = "https://github.com/openvenues/libpostal.git"
|
|
40
|
-
const DICTIONARIES_DIR =
|
|
40
|
+
const DICTIONARIES_DIR = resourceDictionaryPath("libpostal")
|
|
41
41
|
|
|
42
42
|
function parseCLIArgs() {
|
|
43
43
|
const { values } = parseArgs({
|
|
@@ -68,7 +68,9 @@ async function sortFileInPlace(path: string): Promise<void> {
|
|
|
68
68
|
const lines = text.split("\n")
|
|
69
69
|
|
|
70
70
|
// Drop the empty element produced by a trailing newline so it isn't re-sorted as a blank line.
|
|
71
|
-
if (hadTrailingNewline)
|
|
71
|
+
if (hadTrailingNewline) {
|
|
72
|
+
lines.pop()
|
|
73
|
+
}
|
|
72
74
|
lines.sort()
|
|
73
75
|
await writeFile(path, lines.join("\n") + (hadTrailingNewline ? "\n" : ""))
|
|
74
76
|
}
|
|
@@ -101,7 +103,9 @@ async function main(): Promise<void> {
|
|
|
101
103
|
|
|
102
104
|
// Alphabetize the contents of each dictionary file in place.
|
|
103
105
|
for (const entry of await readdir(sourceDicts, { withFileTypes: true })) {
|
|
104
|
-
if (entry.isFile())
|
|
106
|
+
if (entry.isFile()) {
|
|
107
|
+
await sortFileInPlace(join(sourceDicts, entry.name))
|
|
108
|
+
}
|
|
105
109
|
}
|
|
106
110
|
|
|
107
111
|
// Copy the (now-sorted) dictionaries tree next to this script.
|
|
@@ -111,11 +115,4 @@ async function main(): Promise<void> {
|
|
|
111
115
|
}
|
|
112
116
|
}
|
|
113
117
|
|
|
114
|
-
|
|
115
|
-
// "__main__"`), so importing this module evaluates it without cloning anything.
|
|
116
|
-
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
|
|
117
|
-
main().catch((err: Error) => {
|
|
118
|
-
process.stderr.write(`fatal: ${err.message}\n${err.stack}\n`)
|
|
119
|
-
process.exitCode = 1
|
|
120
|
-
})
|
|
121
|
-
}
|
|
118
|
+
runIfScript(import.meta, main)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coarse-placer.d.ts","sourceRoot":"","sources":["../../coarse-placer/coarse-placer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAA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GAAG,IAAI,CAkB/B;AAED,2FAA2F;AAC3F,wBAAsB,gBAAgB,CACrC,QAAQ,EAAE;IAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,EACxF,OAAO,EAAE,YAAY,EACrB,IAAI,CAAC,EAAE,gBAAgB,GACrB,OAAO,CAAC,YAAY,CAAC,CAEvB;AAED,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,CAAA"}
|
|
@@ -26,8 +26,9 @@ export function dequantizeInt8Weights(int8, scales, classCount, dim) {
|
|
|
26
26
|
for (let c = 0; c < classCount; c++) {
|
|
27
27
|
const s = scales[c];
|
|
28
28
|
const base = c * dim;
|
|
29
|
-
for (let i = 0; i < dim; i++)
|
|
29
|
+
for (let i = 0; i < dim; i++) {
|
|
30
30
|
out[base + i] = int8[base + i] * s;
|
|
31
|
+
}
|
|
31
32
|
}
|
|
32
33
|
return out;
|
|
33
34
|
}
|
|
@@ -89,8 +90,8 @@ export class CoarsePlacer {
|
|
|
89
90
|
const dir = $public.MAILWOMAN_COARSE_PLACER_DIR;
|
|
90
91
|
if (dir)
|
|
91
92
|
return CoarsePlacer.fromArtifactDir(dir, opts);
|
|
92
|
-
const {
|
|
93
|
-
return CoarsePlacer.fromArtifactDir(
|
|
93
|
+
const { corePackagePath } = await import("../utils/repo.js");
|
|
94
|
+
return CoarsePlacer.fromArtifactDir(corePackagePath("data", "coarse-placer"), opts);
|
|
94
95
|
}
|
|
95
96
|
predict(text) {
|
|
96
97
|
const feats = featurize(text);
|
|
@@ -99,15 +100,17 @@ export class CoarsePlacer {
|
|
|
99
100
|
for (let c = 0; c < C; c++) {
|
|
100
101
|
let s = this.#bias[c];
|
|
101
102
|
const base = c * this.#dim;
|
|
102
|
-
for (const i of feats)
|
|
103
|
+
for (const i of feats) {
|
|
103
104
|
s += this.#weights[base + i];
|
|
105
|
+
}
|
|
104
106
|
logits[c] = s / this.#temp;
|
|
105
107
|
}
|
|
106
108
|
// Numerically-stable softmax.
|
|
107
109
|
let maxLogit = -Infinity;
|
|
108
110
|
for (let c = 0; c < C; c++)
|
|
109
|
-
if (logits[c] > maxLogit)
|
|
111
|
+
if (logits[c] > maxLogit) {
|
|
110
112
|
maxLogit = logits[c];
|
|
113
|
+
}
|
|
111
114
|
let sum = 0;
|
|
112
115
|
const probs = new Float32Array(C);
|
|
113
116
|
for (let c = 0; c < C; c++) {
|
|
@@ -174,13 +177,15 @@ export function inMapPosterior(prediction, opts) {
|
|
|
174
177
|
const floor = opts?.epsilonFloor ?? 0;
|
|
175
178
|
const posterior = {};
|
|
176
179
|
for (const [cls, prob] of Object.entries(prediction.probs)) {
|
|
177
|
-
if (cls !== "OTHER" && prob >= floor)
|
|
180
|
+
if (cls !== "OTHER" && prob >= floor) {
|
|
178
181
|
posterior[cls] = prob;
|
|
182
|
+
}
|
|
179
183
|
}
|
|
180
184
|
// The argmax always survives (it is ≥ every other marginal; if even it fell below the floor the
|
|
181
185
|
// prediction would have abstained upstream) — but guard anyway so the posterior is never empty.
|
|
182
|
-
if (Object.keys(posterior).length === 0)
|
|
186
|
+
if (Object.keys(posterior).length === 0) {
|
|
183
187
|
posterior[prediction.country] = prediction.confidence;
|
|
188
|
+
}
|
|
184
189
|
return posterior;
|
|
185
190
|
}
|
|
186
191
|
/** Load a coarse-placer from a JSON metadata file + a sibling `.weights.bin` (Float32). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coarse-placer.js","sourceRoot":"","sources":["../../coarse-placer/coarse-placer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AA4BvE;;;;GAIG;AACH,MAAM,UAAU,qB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,OAAO,KAAK,IAAI,IAAI,UAAU,CAAC,OAAO,KAAK,OAAO;QAAE,OAAO,IAAI,CAAA;IAC9E,MAAM,KAAK,GAAG,IAAI,EAAE,YAAY,IAAI,CAAC,CAAA;IACrC,MAAM,SAAS,GAA2B,EAAE,CAAA;IAE5C,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5D,IAAI,GAAG,KAAK,OAAO,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;YACtC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;QACtB,CAAC;IACF,CAAC;IAED,gGAAgG;IAChG,gGAAgG;IAChG,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,UAAU,CAAA;IACtD,CAAC;IAED,OAAO,SAAS,CAAA;AACjB,CAAC;AAED,2FAA2F;AAC3F,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,QAAwF,EACxF,OAAqB,EACrB,IAAuB;IAEvB,OAAO,IAAI,YAAY,CAAC,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE,EAAE,IAAI,CAAC,CAAA;AACxD,CAAC;AAED,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Assemble a balanced (address → country) dataset for the #244 coarse-placer from the v0.5.0
|
|
7
|
+
* corpus. STRATIFIED: a flat random sample is 94% US+FR, so we sample up to N rows PER country
|
|
8
|
+
* and union.
|
|
9
|
+
*
|
|
10
|
+
* Two gotchas this handles:
|
|
11
|
+
*
|
|
12
|
+
* - DuckDB `USING SAMPLE n ROWS` samples the TABLE, then WHERE filters the sample — so we
|
|
13
|
+
* filter-THEN-sample in a subquery to get a true per-country sample.
|
|
14
|
+
* - The corpus val/test shards only carry US/FR/DE, so we draw ALL splits from the rich `train`
|
|
15
|
+
* shards and do our OWN per-country 80/10/10 split (dedup on raw → no row crosses splits).
|
|
16
|
+
*
|
|
17
|
+
* Usage: node core/coarse-placer/tools/build-dataset.ts [--per-country 50000] Output:
|
|
18
|
+
* data/coarse-placer/{train,val,test}.jsonl (rows: {raw, country})
|
|
19
|
+
*/
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=build-dataset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-dataset.d.ts","sourceRoot":"","sources":["../../../coarse-placer/tools/build-dataset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Assemble a balanced (address → country) dataset for the #244 coarse-placer from the v0.5.0
|
|
7
|
+
* corpus. STRATIFIED: a flat random sample is 94% US+FR, so we sample up to N rows PER country
|
|
8
|
+
* and union.
|
|
9
|
+
*
|
|
10
|
+
* Two gotchas this handles:
|
|
11
|
+
*
|
|
12
|
+
* - DuckDB `USING SAMPLE n ROWS` samples the TABLE, then WHERE filters the sample — so we
|
|
13
|
+
* filter-THEN-sample in a subquery to get a true per-country sample.
|
|
14
|
+
* - The corpus val/test shards only carry US/FR/DE, so we draw ALL splits from the rich `train`
|
|
15
|
+
* shards and do our OWN per-country 80/10/10 split (dedup on raw → no row crosses splits).
|
|
16
|
+
*
|
|
17
|
+
* Usage: node core/coarse-placer/tools/build-dataset.ts [--per-country 50000] Output:
|
|
18
|
+
* data/coarse-placer/{train,val,test}.jsonl (rows: {raw, country})
|
|
19
|
+
*/
|
|
20
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
21
|
+
import * as path from "node:path";
|
|
22
|
+
import { parseArgs } from "node:util";
|
|
23
|
+
import { DuckDBInstance } from "@duckdb/node-api";
|
|
24
|
+
import { dataRootPath } from "@mailwoman/core/utils";
|
|
25
|
+
const { values: args } = parseArgs({ options: { "per-country": { type: "string", default: "50000" } } });
|
|
26
|
+
const PER = Number(args["per-country"]);
|
|
27
|
+
const VAL_FRAC = 0.1;
|
|
28
|
+
const TEST_FRAC = 0.1;
|
|
29
|
+
const COUNTRIES = ["US", "FR", "GB", "CN", "NL", "IT", "DE", "JP", "ES", "KR", "TW"];
|
|
30
|
+
const TRAIN_GLOB = dataRootPath("corpus", "versioned", "v0.5.0", "corpus-v0.5.0", "train", "*.parquet");
|
|
31
|
+
// #244/#928 AU expansion: the v0.5.0 pin carries only ~5.9k AU rows; the v0.9.2 G-NAF shard carries
|
|
32
|
+
// 150k real Australian addresses. AU rides the SAME corpus sampling path as COUNTRIES, just from its
|
|
33
|
+
// own glob — the (country, glob) pairs below unify the two.
|
|
34
|
+
const AU_GLOB = dataRootPath("corpus", "versioned", "v0.9.2-multilocale-au", "corpus-v0.9.2-multilocale-au", "train", "*.parquet");
|
|
35
|
+
const OUT_DIR = path.resolve(import.meta.dirname, "../../data/coarse-placer");
|
|
36
|
+
// #743: the EU expansion. The v0.5.0 corpus carries zero rows for these locales, so they're drawn
|
|
37
|
+
// from the Overture per-country addresses theme (the same source build-eu-eval-set.ts uses). They
|
|
38
|
+
// were previously OTHER outlier exposure (PL/PT/CZ) or simply unrepresentable; here they become
|
|
39
|
+
// first-class in-map countries so the soft country prior can pin them.
|
|
40
|
+
const NEW_EU = ["AT", "BE", "CH", "CZ", "DK", "EE", "FI", "HR", "LT", "LU", "LV", "NO", "PL", "PT", "SI", "SK"];
|
|
41
|
+
// #743 in-map dilution fix: DE/ES/IT/NL are already in COUNTRIES (corpus format), but the eu-eval
|
|
42
|
+
// sets + every NEW_EU country are Overture format. Without an Overture sample of their OWN, their
|
|
43
|
+
// Overture-format eval rows scatter to the Overture-trained neighbours (measured: only 63% of ES
|
|
44
|
+
// eval rows routed ES, ~26% leaked to CH/PT/HR/IT/FR/CZ). SUPPLEMENT their corpus rows with an
|
|
45
|
+
// Overture sample so each owns its own format shape; the format then stops being discriminative and
|
|
46
|
+
// the model falls back to the linguistic n-grams. GB excluded — its Overture parquet is empty.
|
|
47
|
+
const IN_MAP_EU = ["DE", "ES", "IT", "NL"];
|
|
48
|
+
const OVERTURE_DIR = dataRootPath("overture", "2026-06-17.0");
|
|
49
|
+
mkdirSync(OUT_DIR, { recursive: true });
|
|
50
|
+
const duck = await (await DuckDBInstance.create()).connect();
|
|
51
|
+
await duck.run("SET memory_limit='4GB'; SET threads=4;");
|
|
52
|
+
const train = [], val = [], test = [];
|
|
53
|
+
const CORPUS_SOURCES = [
|
|
54
|
+
...COUNTRIES.map((c) => [c, String(TRAIN_GLOB)]),
|
|
55
|
+
["AU", String(AU_GLOB)],
|
|
56
|
+
];
|
|
57
|
+
for (const [country, glob] of CORPUS_SOURCES) {
|
|
58
|
+
// filter-THEN-sample: the subquery restricts to the country, SAMPLE draws from that filtered set.
|
|
59
|
+
const q = `SELECT raw FROM (
|
|
60
|
+
SELECT raw FROM read_parquet('${glob}') WHERE country = '${country}' AND nullif(trim(raw), '') IS NOT NULL
|
|
61
|
+
) USING SAMPLE ${Math.ceil(PER * 1.3)} ROWS`;
|
|
62
|
+
const res = await duck.runAndReadAll(q);
|
|
63
|
+
const seen = new Set();
|
|
64
|
+
const rows = [];
|
|
65
|
+
for (const r of res.getRowObjects()) {
|
|
66
|
+
if (rows.length >= PER)
|
|
67
|
+
break;
|
|
68
|
+
const raw = String(r.raw).trim();
|
|
69
|
+
if (!raw || seen.has(raw))
|
|
70
|
+
continue;
|
|
71
|
+
seen.add(raw);
|
|
72
|
+
rows.push(raw);
|
|
73
|
+
}
|
|
74
|
+
const nVal = Math.floor(rows.length * VAL_FRAC);
|
|
75
|
+
const nTest = Math.floor(rows.length * TEST_FRAC);
|
|
76
|
+
const valRows = rows.slice(0, nVal);
|
|
77
|
+
const testRows = rows.slice(nVal, nVal + nTest);
|
|
78
|
+
const trainRows = rows.slice(nVal + nTest);
|
|
79
|
+
for (const raw of trainRows) {
|
|
80
|
+
train.push({ raw, country });
|
|
81
|
+
}
|
|
82
|
+
for (const raw of valRows) {
|
|
83
|
+
val.push({ raw, country });
|
|
84
|
+
}
|
|
85
|
+
for (const raw of testRows) {
|
|
86
|
+
test.push({ raw, country });
|
|
87
|
+
}
|
|
88
|
+
console.log(` ${country}: train ${trainRows.length} val ${valRows.length} test ${testRows.length}`);
|
|
89
|
+
}
|
|
90
|
+
// #743 EU expansion: draw the new in-map countries from the Overture per-country addresses theme.
|
|
91
|
+
// The raw fields are formatted into native address strings with FORMAT VARIETY (4 templates picked
|
|
92
|
+
// deterministically per row) so the model can't shortcut on a single template shape — it must use
|
|
93
|
+
// the actual street-type words + locality n-grams (Finnish "katu/tie", Polish "ul.", Norwegian
|
|
94
|
+
// "veien") that carry the country signal. Same 80/10/10 dedup split as the corpus path.
|
|
95
|
+
function formatEu(street, number, postcode, loc, t) {
|
|
96
|
+
const s = String(street).trim();
|
|
97
|
+
const num = number != null && String(number).trim() !== "" ? ` ${String(number).trim()}` : "";
|
|
98
|
+
const pc = postcode != null && String(postcode).trim() !== "" ? String(postcode).trim() : "";
|
|
99
|
+
switch (t) {
|
|
100
|
+
case 1:
|
|
101
|
+
return `${s}${num} ${loc}`; // no postcode, no comma
|
|
102
|
+
case 2:
|
|
103
|
+
return `${s}${num}, ${loc}${pc ? `, ${pc}` : ""}`; // postcode trailing
|
|
104
|
+
case 3:
|
|
105
|
+
return `${s}, ${pc ? `${pc} ` : ""}${loc}`; // no house number
|
|
106
|
+
default:
|
|
107
|
+
return `${s}${num}, ${pc ? `${pc} ` : ""}${loc}`; // {street number, postcode locality}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
for (const country of [...NEW_EU, ...IN_MAP_EU]) {
|
|
111
|
+
const parquet = `${OVERTURE_DIR}/addresses-${country.toLowerCase()}.parquet`;
|
|
112
|
+
const q = `SELECT street, number, postcode,
|
|
113
|
+
COALESCE(NULLIF(trim(postal_city), ''), address_levels[len(address_levels)].value) AS loc
|
|
114
|
+
FROM read_parquet('${parquet}')
|
|
115
|
+
WHERE street IS NOT NULL AND trim(street) <> ''
|
|
116
|
+
USING SAMPLE ${Math.ceil(PER * 1.4)} ROWS`;
|
|
117
|
+
let res;
|
|
118
|
+
try {
|
|
119
|
+
res = await duck.runAndReadAll(q);
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
console.error(` ${country}: SKIPPED — ${e.message}`);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const seen = new Set();
|
|
126
|
+
const rows = [];
|
|
127
|
+
for (const r of res.getRowObjects()) {
|
|
128
|
+
if (rows.length >= PER)
|
|
129
|
+
break;
|
|
130
|
+
const loc = r.loc == null ? "" : String(r.loc).trim();
|
|
131
|
+
if (!loc)
|
|
132
|
+
continue;
|
|
133
|
+
const raw = formatEu(r.street, r.number, r.postcode, loc, hash(`${r.street}|${loc}`) % 4);
|
|
134
|
+
if (!raw || seen.has(raw))
|
|
135
|
+
continue;
|
|
136
|
+
seen.add(raw);
|
|
137
|
+
rows.push(raw);
|
|
138
|
+
}
|
|
139
|
+
const nVal = Math.floor(rows.length * VAL_FRAC);
|
|
140
|
+
const nTest = Math.floor(rows.length * TEST_FRAC);
|
|
141
|
+
for (const raw of rows.slice(0, nVal)) {
|
|
142
|
+
val.push({ raw, country });
|
|
143
|
+
}
|
|
144
|
+
for (const raw of rows.slice(nVal, nVal + nTest)) {
|
|
145
|
+
test.push({ raw, country });
|
|
146
|
+
}
|
|
147
|
+
for (const raw of rows.slice(nVal + nTest)) {
|
|
148
|
+
train.push({ raw, country });
|
|
149
|
+
}
|
|
150
|
+
console.log(` ${country} (overture): train ${rows.length - nVal - nTest} val ${nVal} test ${nTest}`);
|
|
151
|
+
}
|
|
152
|
+
const splits = [
|
|
153
|
+
["train", train],
|
|
154
|
+
["val", val],
|
|
155
|
+
["test", test],
|
|
156
|
+
];
|
|
157
|
+
for (const [name, rows] of splits) {
|
|
158
|
+
rows.sort((a, b) => hash(a.raw + a.country) - hash(b.raw + b.country)); // deterministic class-interleave
|
|
159
|
+
const p = path.join(OUT_DIR, `${name}.jsonl`);
|
|
160
|
+
writeFileSync(p, rows.map((r) => JSON.stringify(r)).join("\n") + "\n");
|
|
161
|
+
console.log(`→ ${p} (${rows.length} rows)`);
|
|
162
|
+
}
|
|
163
|
+
function hash(s) {
|
|
164
|
+
let h = 2166136261;
|
|
165
|
+
for (let i = 0; i < s.length; i++) {
|
|
166
|
+
h ^= s.charCodeAt(i);
|
|
167
|
+
h = Math.imul(h, 16777619);
|
|
168
|
+
}
|
|
169
|
+
return h >>> 0;
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=build-dataset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-dataset.js","sourceRoot":"","sources":["../../../coarse-placer/tools/build-dataset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAOpD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE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IACxG,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,QAAQ,CAAC,CAAA;IAC7C,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;IACtE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,MAAM,QAAQ,CAAC,CAAA;AAC7C,CAAC;AAED,SAAS,IAAI,CAAC,CAAS;IACtB,IAAI,CAAC,GAAG,UAAU,CAAA;IAElB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QACpB,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;IAC3B,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Outlier-exposure data for the #244 coarse-placer's explicit "OTHER" (off-map) class — milestone
|
|
7
|
+
* 2. The closed-set model is confidently wrong on scripts it never saw (Cyrillic→DE@0.71). The
|
|
8
|
+
* fix is to TRAIN an "off my loaded map" class on those scripts. Source: the WOF `names` table,
|
|
9
|
+
* which carries native-script alternate names in dozens of languages
|
|
10
|
+
* (rus/ukr/ara/ell/heb/hin/tha/kat/hye/…) — i.e. exactly the off-map scripts we want the model to
|
|
11
|
+
* learn to abstain on. Balanced per-language for script diversity, filtered to a genuinely
|
|
12
|
+
* off-map dominant script (not Latin, not CJK — those are the in-map countries), then APPENDED to
|
|
13
|
+
* the train/val/test splits as `country: "OTHER"`.
|
|
14
|
+
*
|
|
15
|
+
* Run AFTER build-dataset.ts. Usage: node core/coarse-placer/tools/build-outlier-exposure.ts
|
|
16
|
+
* [--per-lang 2500]
|
|
17
|
+
*/
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=build-outlier-exposure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-outlier-exposure.d.ts","sourceRoot":"","sources":["../../../coarse-placer/tools/build-outlier-exposure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Outlier-exposure data for the #244 coarse-placer's explicit "OTHER" (off-map) class — milestone
|
|
7
|
+
* 2. The closed-set model is confidently wrong on scripts it never saw (Cyrillic→DE@0.71). The
|
|
8
|
+
* fix is to TRAIN an "off my loaded map" class on those scripts. Source: the WOF `names` table,
|
|
9
|
+
* which carries native-script alternate names in dozens of languages
|
|
10
|
+
* (rus/ukr/ara/ell/heb/hin/tha/kat/hye/…) — i.e. exactly the off-map scripts we want the model to
|
|
11
|
+
* learn to abstain on. Balanced per-language for script diversity, filtered to a genuinely
|
|
12
|
+
* off-map dominant script (not Latin, not CJK — those are the in-map countries), then APPENDED to
|
|
13
|
+
* the train/val/test splits as `country: "OTHER"`.
|
|
14
|
+
*
|
|
15
|
+
* Run AFTER build-dataset.ts. Usage: node core/coarse-placer/tools/build-outlier-exposure.ts
|
|
16
|
+
* [--per-lang 2500]
|
|
17
|
+
*/
|
|
18
|
+
import { appendFileSync } from "node:fs";
|
|
19
|
+
import * as path from "node:path";
|
|
20
|
+
import { DatabaseSync } from "node:sqlite";
|
|
21
|
+
import { parseArgs } from "node:util";
|
|
22
|
+
import { dataRootPath } from "@mailwoman/core/utils";
|
|
23
|
+
const { values: args } = parseArgs({
|
|
24
|
+
options: {
|
|
25
|
+
"per-lang": { type: "string", default: "2500" },
|
|
26
|
+
wof: { type: "string", default: dataRootPath("wof", "admin-global-priority.db") },
|
|
27
|
+
data: { type: "string", default: path.resolve(import.meta.dirname, "../../data/coarse-placer") },
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
// Off-map languages whose `names` are written in a NON-Latin, NON-CJK script (CJK = the in-map CN/JP/KR/TW).
|
|
31
|
+
const OFF_MAP_LANGS = [
|
|
32
|
+
"rus",
|
|
33
|
+
"ukr",
|
|
34
|
+
"bel",
|
|
35
|
+
"bul",
|
|
36
|
+
"srp",
|
|
37
|
+
"mkd", // Cyrillic
|
|
38
|
+
"ell", // Greek
|
|
39
|
+
"ara",
|
|
40
|
+
"fas",
|
|
41
|
+
"urd",
|
|
42
|
+
"snd",
|
|
43
|
+
"pus", // Arabic-script
|
|
44
|
+
"heb",
|
|
45
|
+
"yid", // Hebrew
|
|
46
|
+
"hin",
|
|
47
|
+
"mar",
|
|
48
|
+
"nep",
|
|
49
|
+
"san", // Devanagari
|
|
50
|
+
"ben",
|
|
51
|
+
"tam",
|
|
52
|
+
"tel",
|
|
53
|
+
"kan",
|
|
54
|
+
"mal",
|
|
55
|
+
"sin", // Brahmic
|
|
56
|
+
"tha",
|
|
57
|
+
"lao",
|
|
58
|
+
"khm",
|
|
59
|
+
"mya", // SE-Asian
|
|
60
|
+
"kat",
|
|
61
|
+
"hye",
|
|
62
|
+
"amh", // Georgian / Armenian / Ethiopic
|
|
63
|
+
];
|
|
64
|
+
/** Dominant script must be off-map: has chars in a non-Latin, non-CJK, non-digit block. */
|
|
65
|
+
function isOffMapScript(s) {
|
|
66
|
+
let off = 0;
|
|
67
|
+
let total = 0;
|
|
68
|
+
for (const ch of s) {
|
|
69
|
+
const cp = ch.codePointAt(0);
|
|
70
|
+
if (cp <= 0x40 || (cp >= 0x5b && cp <= 0x60) || cp === 0x20)
|
|
71
|
+
continue; // punct/space/digits
|
|
72
|
+
total++;
|
|
73
|
+
const latin = (cp >= 0x41 && cp <= 0x5a) || (cp >= 0x61 && cp <= 0x7a) || (cp >= 0xc0 && cp <= 0x24f);
|
|
74
|
+
const cjk = (cp >= 0x3040 && cp <= 0x30ff) ||
|
|
75
|
+
(cp >= 0x4e00 && cp <= 0x9fff) ||
|
|
76
|
+
(cp >= 0xac00 && cp <= 0xd7af) ||
|
|
77
|
+
(cp >= 0x3400 && cp <= 0x4dbf);
|
|
78
|
+
if (!latin && !cjk && cp > 0x2ff) {
|
|
79
|
+
off++;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return total > 0 && off / total > 0.6;
|
|
83
|
+
}
|
|
84
|
+
// Mimic a real off-map ADDRESS: a pure-script place name isn't what we see at inference (those carry
|
|
85
|
+
// Latin digits + structure, e.g. "ул. Тверская, д. 1"). For each name we also emit an address-shaped
|
|
86
|
+
// variant — name + a house number, deterministically — so the model learns "off-map script + digits =
|
|
87
|
+
// still OTHER" and doesn't get pulled to a country by the numeric/punctuation n-grams.
|
|
88
|
+
function addressVariant(name, h) {
|
|
89
|
+
const n = (h % 4) + 1; // 1–4 digit house number
|
|
90
|
+
const num = String(h % Math.pow(10, n) || 7);
|
|
91
|
+
switch (h % 3) {
|
|
92
|
+
case 0:
|
|
93
|
+
return `${name} ${num}`;
|
|
94
|
+
case 1:
|
|
95
|
+
return `${num} ${name}`;
|
|
96
|
+
default:
|
|
97
|
+
return `${name}, ${num}`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const db = new DatabaseSync(args.wof, { readOnly: true });
|
|
101
|
+
const PER = Number(args["per-lang"]);
|
|
102
|
+
const pool = [];
|
|
103
|
+
const seen = new Set();
|
|
104
|
+
for (const lang of OFF_MAP_LANGS) {
|
|
105
|
+
const rows = db.prepare(`SELECT name FROM names WHERE language = ? AND length(name) >= 4 LIMIT ?`).all(lang, PER * 2);
|
|
106
|
+
let kept = 0;
|
|
107
|
+
for (const r of rows) {
|
|
108
|
+
if (kept >= PER)
|
|
109
|
+
break;
|
|
110
|
+
const name = String(r.name).trim();
|
|
111
|
+
if (!name || seen.has(name) || !isOffMapScript(name))
|
|
112
|
+
continue;
|
|
113
|
+
seen.add(name);
|
|
114
|
+
pool.push(name);
|
|
115
|
+
pool.push(addressVariant(name, hash(name))); // address-shaped sibling
|
|
116
|
+
kept++;
|
|
117
|
+
}
|
|
118
|
+
console.log(` ${lang}: ${kept}`);
|
|
119
|
+
}
|
|
120
|
+
db.close();
|
|
121
|
+
// Deterministic shuffle (FNV hash sort) + split 80/10/10, append as OTHER.
|
|
122
|
+
pool.sort((a, b) => hash(a) - hash(b));
|
|
123
|
+
const nVal = Math.floor(pool.length * 0.1);
|
|
124
|
+
const nTest = Math.floor(pool.length * 0.1);
|
|
125
|
+
const splits = {
|
|
126
|
+
val: pool.slice(0, nVal),
|
|
127
|
+
test: pool.slice(nVal, nVal + nTest),
|
|
128
|
+
train: pool.slice(nVal + nTest),
|
|
129
|
+
};
|
|
130
|
+
for (const [split, names] of Object.entries(splits)) {
|
|
131
|
+
const lines = names.map((raw) => JSON.stringify({ raw, country: "OTHER" })).join("\n") + "\n";
|
|
132
|
+
appendFileSync(path.join(args.data, `${split}.jsonl`), lines);
|
|
133
|
+
console.log(`appended ${names.length} OTHER → ${split}.jsonl`);
|
|
134
|
+
}
|
|
135
|
+
console.log(`total OTHER pool: ${pool.length}`);
|
|
136
|
+
function hash(s) {
|
|
137
|
+
let h = 2166136261;
|
|
138
|
+
for (let i = 0; i < s.length; i++) {
|
|
139
|
+
h ^= s.charCodeAt(i);
|
|
140
|
+
h = Math.imul(h, 16777619);
|
|
141
|
+
}
|
|
142
|
+
return h >>> 0;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=build-outlier-exposure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-outlier-exposure.js","sourceRoot":"","sources":["../../../coarse-placer/tools/build-outlier-exposure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEpD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC;IAClC,OAAO,EAAE;QACR,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE;QAC/C,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,CAAC,KAAK,EAAE,0BAA0B,CAAC,EAAE;QACjF,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,0BAA0B,CAAC,EAAE;KAChG;CACD,CAAC,CAAA;AAEF,6GAA6G;AAC7G,MAAM,aAAa,GAAG;IACrB,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK,EAAE,WAAW;IAClB,KAAK,EAAE,QAAQ;IACf,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK,EAAE,gBAAgB;IACvB,KAAK;IACL,KAAK,EAAE,SAAS;IAChB,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK,EAAE,aAAa;IACpB,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK,EAAE,UAAU;IACjB,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK,EAAE,WAAW;IAClB,KAAK;IACL,KAAK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