@mailwoman/resolver 10.0.0 → 10.1.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 +9 -7
- package/lib/admin/coherence-passes.ts +19 -160
- package/lib/admin/containment.ts +12 -30
- package/lib/admin/jp-municipality.ts +20 -13
- package/lib/admin/winner.ts +30 -62
- package/lib/backend-capabilities.ts +25 -24
- package/lib/bare-toponym-race.ts +69 -37
- package/lib/decorate-node.ts +17 -41
- package/lib/fold-name.ts +5 -18
- package/lib/index.ts +5 -9
- package/lib/plausibility.ts +35 -62
- package/lib/postcode/country-coherence.ts +64 -284
- package/lib/postcode/prefix.ts +20 -84
- package/lib/postcode/shape-coherence.ts +23 -113
- package/lib/remote-resolver.ts +32 -29
- package/lib/rerank.ts +34 -50
- package/lib/resolve/passes.ts +144 -147
- package/lib/resolve.ts +726 -0
- package/lib/span-rescore.ts +215 -172
- package/lib/street/evidence.ts +65 -73
- package/lib/street/tier.ts +33 -175
- package/lib/toponym-prior.ts +53 -179
- package/out/admin/coherence-passes.d.ts +17 -68
- package/out/admin/coherence-passes.d.ts.map +1 -1
- package/out/admin/coherence-passes.js +18 -160
- package/out/admin/coherence-passes.js.map +1 -1
- package/out/admin/containment.d.ts +11 -29
- package/out/admin/containment.d.ts.map +1 -1
- package/out/admin/containment.js +12 -30
- package/out/admin/containment.js.map +1 -1
- package/out/admin/jp-municipality.d.ts +20 -13
- package/out/admin/jp-municipality.d.ts.map +1 -1
- package/out/admin/jp-municipality.js +18 -12
- package/out/admin/jp-municipality.js.map +1 -1
- package/out/admin/winner.d.ts +30 -62
- package/out/admin/winner.d.ts.map +1 -1
- package/out/admin/winner.js +18 -51
- package/out/admin/winner.js.map +1 -1
- package/out/{admin/index.d.ts → admin.d.ts} +1 -1
- package/out/admin.d.ts.map +1 -0
- package/out/{admin/index.js → admin.js} +1 -1
- package/out/admin.js.map +1 -0
- package/out/backend-capabilities.d.ts +18 -19
- package/out/backend-capabilities.d.ts.map +1 -1
- package/out/backend-capabilities.js +25 -24
- package/out/backend-capabilities.js.map +1 -1
- package/out/bare-toponym-race.d.ts +54 -27
- package/out/bare-toponym-race.d.ts.map +1 -1
- package/out/bare-toponym-race.js +69 -37
- package/out/bare-toponym-race.js.map +1 -1
- package/out/decorate-node.d.ts +6 -8
- package/out/decorate-node.d.ts.map +1 -1
- package/out/decorate-node.js +17 -41
- package/out/decorate-node.js.map +1 -1
- package/out/fold-name.d.ts +5 -18
- package/out/fold-name.d.ts.map +1 -1
- package/out/fold-name.js +5 -18
- package/out/fold-name.js.map +1 -1
- package/out/index.d.ts +5 -6
- package/out/index.d.ts.map +1 -1
- package/out/index.js +5 -8
- package/out/index.js.map +1 -1
- package/out/plausibility.d.ts +27 -57
- package/out/plausibility.d.ts.map +1 -1
- package/out/plausibility.js +16 -49
- package/out/plausibility.js.map +1 -1
- package/out/postcode/country-coherence.d.ts +48 -162
- package/out/postcode/country-coherence.d.ts.map +1 -1
- package/out/postcode/country-coherence.js +19 -252
- package/out/postcode/country-coherence.js.map +1 -1
- package/out/postcode/prefix.d.ts +17 -68
- package/out/postcode/prefix.d.ts.map +1 -1
- package/out/postcode/prefix.js +8 -77
- package/out/postcode/prefix.js.map +1 -1
- package/out/postcode/shape-coherence.d.ts +17 -84
- package/out/postcode/shape-coherence.d.ts.map +1 -1
- package/out/postcode/shape-coherence.js +9 -105
- package/out/postcode/shape-coherence.js.map +1 -1
- package/out/{postcode/index.d.ts → postcode.d.ts} +1 -1
- package/out/postcode.d.ts.map +1 -0
- package/out/{postcode/index.js → postcode.js} +1 -1
- package/out/postcode.js.map +1 -0
- package/out/remote-resolver.d.ts +27 -28
- package/out/remote-resolver.d.ts.map +1 -1
- package/out/remote-resolver.js +9 -19
- package/out/remote-resolver.js.map +1 -1
- package/out/rerank.d.ts +28 -45
- package/out/rerank.d.ts.map +1 -1
- package/out/rerank.js +13 -38
- package/out/rerank.js.map +1 -1
- package/out/resolve/passes.d.ts +95 -85
- package/out/resolve/passes.d.ts.map +1 -1
- package/out/resolve/passes.js +40 -105
- package/out/resolve/passes.js.map +1 -1
- package/out/resolve.d.ts +15 -0
- package/out/resolve.d.ts.map +1 -0
- package/out/resolve.js +543 -0
- package/out/resolve.js.map +1 -0
- package/out/span-rescore.d.ts +51 -64
- package/out/span-rescore.d.ts.map +1 -1
- package/out/span-rescore.js +132 -130
- package/out/span-rescore.js.map +1 -1
- package/out/street/evidence.d.ts +56 -61
- package/out/street/evidence.d.ts.map +1 -1
- package/out/street/evidence.js +22 -46
- package/out/street/evidence.js.map +1 -1
- package/out/street/tier.d.ts +17 -29
- package/out/street/tier.d.ts.map +1 -1
- package/out/street/tier.js +27 -175
- package/out/street/tier.js.map +1 -1
- package/out/{street/index.d.ts → street.d.ts} +1 -1
- package/out/street.d.ts.map +1 -0
- package/out/{street/index.js → street.js} +1 -1
- package/out/street.js.map +1 -0
- package/out/toponym-prior.d.ts +21 -109
- package/out/toponym-prior.d.ts.map +1 -1
- package/out/toponym-prior.js +41 -170
- package/out/toponym-prior.js.map +1 -1
- package/package.json +44 -147
- package/lib/resolve/index.ts +0 -989
- package/out/admin/index.d.ts.map +0 -1
- package/out/admin/index.js.map +0 -1
- package/out/postcode/index.d.ts.map +0 -1
- package/out/postcode/index.js.map +0 -1
- package/out/resolve/index.d.ts +0 -20
- package/out/resolve/index.d.ts.map +0 -1
- package/out/resolve/index.js +0 -808
- package/out/resolve/index.js.map +0 -1
- package/out/street/index.d.ts.map +0 -1
- package/out/street/index.js.map +0 -1
- package/vitest.config.ts +0 -38
- /package/lib/{admin/index.ts → admin.ts} +0 -0
- /package/lib/{postcode/index.ts → postcode.ts} +0 -0
- /package/lib/{street/index.ts → street.ts} +0 -0
package/out/remote-resolver.js
CHANGED
|
@@ -2,26 +2,10 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* `RemoteResolver` — the `Resolver` interface (`resolveTree`) over HTTP. The adapter the interface
|
|
7
|
-
* docstring anticipated (Phase 4.4): a client POSTs a parsed `AddressTree` + the serializable
|
|
8
|
-
* `ResolveOpts` to a resolver service, which owns the gazetteer + situs/interpolation extracts,
|
|
9
|
-
* runs the cascade, and returns the resolved tree. Two payoffs:
|
|
10
|
-
*
|
|
11
|
-
* 1. **Multi-instance** — stateless parser nodes (the ~30 MB ONNX model) talk to ONE resolver service
|
|
12
|
-
* (the multi-GB gazetteer + extracts). `parse` locally, `new RemoteResolver(...).resolveTree`
|
|
13
|
-
* remotely — same interface the in-process `WOFResolver` satisfies, so it's a drop-in.
|
|
14
|
-
* 2. **Canary** — point it at a second resolver build (or an adapter fronting Pelias/Nominatim/BAN)
|
|
15
|
-
* and diff the resolved trees through the identical contract.
|
|
16
|
-
*
|
|
17
|
-
* Pure transport: `fetch` only, no node-specific deps (runs in the browser too). The
|
|
18
|
-
* `addressPoints` / `interpolation` opts are LIVE SQLite handles — not serializable — so they're
|
|
19
|
-
* stripped before the POST; the resolver service supplies its own from the tree's region (the
|
|
20
|
-
* data lives server-side, which is the whole point). All other opts (defaultCountry, calibration,
|
|
21
|
-
* hierarchyCompletion, …) ride along.
|
|
22
5
|
*/
|
|
6
|
+
import { stringifyJSON } from "@mailwoman/core/json";
|
|
23
7
|
/**
|
|
24
|
-
* Strip the live lookup handles from `ResolveOpts` so the rest can be JSON-serialized over
|
|
8
|
+
* Strip the live lookup handles from `ResolveOpts` so the rest can be JSON-serialized over http.
|
|
25
9
|
*/
|
|
26
10
|
export function serializableResolveOpts(opts) {
|
|
27
11
|
if (!opts)
|
|
@@ -29,6 +13,12 @@ export function serializableResolveOpts(opts) {
|
|
|
29
13
|
const { addressPoints: _ap, interpolation: _ip, ...rest } = opts;
|
|
30
14
|
return rest;
|
|
31
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolves address trees by POSTing them to a remote resolver endpoint, so a client
|
|
18
|
+
* can resolve without loading gazetteer databases itself.
|
|
19
|
+
*
|
|
20
|
+
* Live lookup handles in `ResolveOpts` are dropped before sending, so the server resolves with its own.
|
|
21
|
+
*/
|
|
32
22
|
export class RemoteResolver {
|
|
33
23
|
#endpoint;
|
|
34
24
|
#fetch;
|
|
@@ -50,7 +40,7 @@ export class RemoteResolver {
|
|
|
50
40
|
const res = await this.#fetch(this.#endpoint, {
|
|
51
41
|
method: "POST",
|
|
52
42
|
headers: { "Content-Type": "application/json", ...this.#headers },
|
|
53
|
-
body:
|
|
43
|
+
body: stringifyJSON(body),
|
|
54
44
|
signal: controller.signal,
|
|
55
45
|
});
|
|
56
46
|
if (!res.ok) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-resolver.js","sourceRoot":"","sources":["../lib/remote-resolver.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"remote-resolver.js","sourceRoot":"","sources":["../lib/remote-resolver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAWpD;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAkB;IACzD,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAA;IAC3B,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAA;IAEhE,OAAO,IAAI,CAAA;AACZ,CAAC;AAuDD;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IACjB,SAAS,CAAQ;IACjB,MAAM,CAAqB;IAC3B,UAAU,CAAQ;IAClB,QAAQ,CAAwB;IAEzC,YAAY,IAAwB;QACnC,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;QAC7E,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAA;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,C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A2D,CAAC,CAAA;YAC7E,CAAC;YAED,OAAO,IAAI,CAAC,IAAI,CAAA;QACjB,CAAC;gBAAS,CAAC;YACV,YAAY,CAAC,KAAK,CAAC,CAAA;QACpB,CAAC;IACF,CAAC;CACD"}
|
package/out/rerank.d.ts
CHANGED
|
@@ -3,47 +3,26 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* resolver, not hand-weights. A rank-2 parse that resolves to a real place beats a rank-1 that
|
|
10
|
-
* resolves to a country centroid.
|
|
11
|
-
*
|
|
12
|
-
* The measured case for this existing at all: on the triaged parity corpus the shipped decode gets
|
|
13
|
-
* street 0.573 while the span decode's top-10 CONTAINS the right answer 0.775 of the time
|
|
14
|
-
* (oracle@5 0.723). Rank-1 cannot reach that headroom; only a reranker can.
|
|
15
|
-
*
|
|
16
|
-
* ## Why this is deliberately, almost embarrassingly small
|
|
17
|
-
*
|
|
18
|
-
* The failure mode we are avoiding is Pelias's: a ladder of per-class hand-tuned weights that
|
|
19
|
-
* nobody can re-derive (see `docs/articles/evals/competitive-parity/2026-07-15-pelias-dictionary-overrides.md`
|
|
20
|
-
* — 94 of 276 dictionary lines are hand-written deletions, each resolving a collision in favour of
|
|
21
|
-
* whoever complained loudest). The moment this file grows a per-hypothesis score blend, we have
|
|
22
|
-
* rebuilt that with extra steps.
|
|
23
|
-
*
|
|
24
|
-
* So the rule is ONE bit of evidence, not a score: **drop hypotheses whose resolution is
|
|
25
|
-
* implausible; otherwise keep the model's own ranking.** The parse scores already share a partition
|
|
26
|
-
* function and are comparable within an input — the reranker's job is not to re-score them, it is to
|
|
27
|
-
* veto the ones the world says are wrong.
|
|
28
|
-
*
|
|
29
|
-
* Adding a second signal here requires the same bar the first one cleared: a MEASURED win on the
|
|
30
|
-
* parity + Paris fixtures, stated in a verdict doc. Not a plausible story.
|
|
6
|
+
* Rerank a k-best parse list on resolution evidence with one bit — drop hypotheses whose resolution
|
|
7
|
+
* is implausible, otherwise keep the model's own ranking — because a second signal here needs a
|
|
8
|
+
* measured win on the parity + Paris fixtures.
|
|
31
9
|
*/
|
|
32
10
|
import type { AddressTree } from "@mailwoman/core/decoder";
|
|
11
|
+
import type { CountryBBoxFact } from "@mailwoman/core/resolver";
|
|
33
12
|
/**
|
|
34
13
|
* One candidate parse from the k-best decode, with its (within-input comparable) score.
|
|
35
14
|
*/
|
|
36
15
|
export interface RerankCandidate<T = unknown> {
|
|
37
16
|
/**
|
|
38
|
-
* The parse's own score
|
|
17
|
+
* The parse's own score, comparable to its siblings from the same input and not across inputs.
|
|
39
18
|
*/
|
|
40
19
|
score: number;
|
|
41
20
|
/**
|
|
42
|
-
* The parse tree,
|
|
21
|
+
* The parse tree, unresolved — `rerankByResolution` resolves it via the injected resolver.
|
|
43
22
|
*/
|
|
44
23
|
tree: AddressTree;
|
|
45
24
|
/**
|
|
46
|
-
* Opaque caller payload
|
|
25
|
+
* Opaque caller payload passed through to the result (the segmentation, a surface string, …).
|
|
47
26
|
*/
|
|
48
27
|
payload?: T;
|
|
49
28
|
}
|
|
@@ -63,42 +42,46 @@ export interface RerankedCandidate<T = unknown> extends RerankCandidate<T> {
|
|
|
63
42
|
}
|
|
64
43
|
export interface RerankResult<T = unknown> {
|
|
65
44
|
/**
|
|
66
|
-
* Candidates in
|
|
45
|
+
* Candidates in final order: plausible ones first (model order preserved), vetoed ones after.
|
|
67
46
|
*/
|
|
68
47
|
ranked: Array<RerankedCandidate<T>>;
|
|
69
48
|
/**
|
|
70
|
-
* The winner — the first plausible candidate, or the model's rank-1 when
|
|
49
|
+
* The winner — the first plausible candidate, or the model's rank-1 when all were vetoed.
|
|
71
50
|
*/
|
|
72
51
|
best: RerankedCandidate<T>;
|
|
73
52
|
/**
|
|
74
|
-
* True when
|
|
75
|
-
* metric the arc is judged on (`rank-2-beats-rank-1 rate`); log it, because a rerank that never fires is a rerank
|
|
76
|
-
* that is not earning its resolver calls.
|
|
53
|
+
* True when resolution evidence actually changed the answer from the model's rank-1.
|
|
77
54
|
*/
|
|
78
55
|
changed: boolean;
|
|
79
56
|
}
|
|
80
57
|
/**
|
|
81
|
-
* Resolve a tree.
|
|
58
|
+
* Resolve a tree.
|
|
59
|
+
* Structural, so any `Resolver`-shaped thing satisfies it.
|
|
82
60
|
*/
|
|
83
61
|
export type ResolveTree = (tree: AddressTree) => Promise<AddressTree>;
|
|
84
62
|
export interface RerankOpts {
|
|
85
63
|
/**
|
|
86
|
-
* Resolve at most this many candidates (default 5)
|
|
87
|
-
*
|
|
88
|
-
* — the last 5 candidates cost 2x the resolves for ~5pp of ceiling.
|
|
64
|
+
* Resolve at most this many candidates (default 5); each costs a resolver round-trip,
|
|
65
|
+
* so this is the latency knob.
|
|
89
66
|
*/
|
|
90
67
|
maxResolve?: number;
|
|
68
|
+
/**
|
|
69
|
+
* ISO-2 country the resolutions are expected to land in, threaded to {@link isImplausibleResolution}
|
|
70
|
+
* as guard B so a coordinate outside that country's coarse box is vetoed.
|
|
71
|
+
* Omitted, only the bare-country-centroid guard runs.
|
|
72
|
+
*/
|
|
73
|
+
expectedCountry?: string;
|
|
74
|
+
/**
|
|
75
|
+
* The loaded artifact's own guard-B boxes, replacing the built-in table wholesale when supplied.
|
|
76
|
+
*/
|
|
77
|
+
countryBBoxes?: ReadonlyMap<string, CountryBBoxFact>;
|
|
91
78
|
}
|
|
92
79
|
/**
|
|
93
|
-
* Rerank a k-best parse list on resolution evidence
|
|
94
|
-
*
|
|
95
|
-
* Resolves up to `maxResolve` candidates IN MODEL ORDER and returns the first whose resolution is plausible. Candidates
|
|
96
|
-
* beyond `maxResolve` are never resolved (and never vetoed — they simply keep their model rank behind the resolved
|
|
97
|
-
* ones).
|
|
80
|
+
* Rerank a k-best parse list on resolution evidence: resolve up to `maxResolve`
|
|
81
|
+
* candidates in model order and return the first plausible one.
|
|
98
82
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* grounds to flag low confidence (the Phase-4b ambiguity check).
|
|
83
|
+
* Candidates beyond `maxResolve` are never resolved or vetoed. when every resolved
|
|
84
|
+
* candidate is implausible the model's rank-1 wins.
|
|
102
85
|
*/
|
|
103
86
|
export declare function rerankByResolution<T>(candidates: ReadonlyArray<RerankCandidate<T>>, resolveTree: ResolveTree, opts?: RerankOpts): Promise<RerankResult<T>>;
|
|
104
87
|
//# sourceMappingURL=rerank.d.ts.map
|
package/out/rerank.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rerank.d.ts","sourceRoot":"","sources":["../lib/rerank.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"rerank.d.ts","sourceRoot":"","sources":["../lib/rerank.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAI/D;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC3C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,IAAI,EAAE,WAAW,CAAA;IACjB;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,CAAA;CACX;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,eAAe,CAAC,CAAC,CAAC;IACzE;;OAEG;IACH,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAA;IAC5B;;OAEG;IACH,WAAW,EAAE,OAAO,CAAA;IACpB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACxC;;OAEG;IACH,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAA;IACnC;;OAEG;IACH,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAA;IAC1B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAA;CAChB;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,WAAW,CAAC,CAAA;AAErE,MAAM,WAAW,UAAU;IAC1B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;OAEG;IACH,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CACpD;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EACzC,UAAU,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAC7C,WAAW,EAAE,WAAW,EACxB,IAAI,GAAE,UAAe,GACnB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CA6C1B"}
|
package/out/rerank.js
CHANGED
|
@@ -3,43 +3,17 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* resolver, not hand-weights. A rank-2 parse that resolves to a real place beats a rank-1 that
|
|
10
|
-
* resolves to a country centroid.
|
|
11
|
-
*
|
|
12
|
-
* The measured case for this existing at all: on the triaged parity corpus the shipped decode gets
|
|
13
|
-
* street 0.573 while the span decode's top-10 CONTAINS the right answer 0.775 of the time
|
|
14
|
-
* (oracle@5 0.723). Rank-1 cannot reach that headroom; only a reranker can.
|
|
15
|
-
*
|
|
16
|
-
* ## Why this is deliberately, almost embarrassingly small
|
|
17
|
-
*
|
|
18
|
-
* The failure mode we are avoiding is Pelias's: a ladder of per-class hand-tuned weights that
|
|
19
|
-
* nobody can re-derive (see `docs/articles/evals/competitive-parity/2026-07-15-pelias-dictionary-overrides.md`
|
|
20
|
-
* — 94 of 276 dictionary lines are hand-written deletions, each resolving a collision in favour of
|
|
21
|
-
* whoever complained loudest). The moment this file grows a per-hypothesis score blend, we have
|
|
22
|
-
* rebuilt that with extra steps.
|
|
23
|
-
*
|
|
24
|
-
* So the rule is ONE bit of evidence, not a score: **drop hypotheses whose resolution is
|
|
25
|
-
* implausible; otherwise keep the model's own ranking.** The parse scores already share a partition
|
|
26
|
-
* function and are comparable within an input — the reranker's job is not to re-score them, it is to
|
|
27
|
-
* veto the ones the world says are wrong.
|
|
28
|
-
*
|
|
29
|
-
* Adding a second signal here requires the same bar the first one cleared: a MEASURED win on the
|
|
30
|
-
* parity + Paris fixtures, stated in a verdict doc. Not a plausible story.
|
|
6
|
+
* Rerank a k-best parse list on resolution evidence with one bit — drop hypotheses whose resolution
|
|
7
|
+
* is implausible, otherwise keep the model's own ranking — because a second signal here needs a
|
|
8
|
+
* measured win on the parity + Paris fixtures.
|
|
31
9
|
*/
|
|
32
10
|
import { isImplausibleResolution } from "#plausibility";
|
|
33
11
|
/**
|
|
34
|
-
* Rerank a k-best parse list on resolution evidence
|
|
12
|
+
* Rerank a k-best parse list on resolution evidence: resolve up to `maxResolve`
|
|
13
|
+
* candidates in model order and return the first plausible one.
|
|
35
14
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* ones).
|
|
39
|
-
*
|
|
40
|
-
* **When every resolved candidate is implausible, the model's rank-1 wins.** A reranker that returns nothing is worse
|
|
41
|
-
* than one that defers: "all my evidence says these are all bad" is not grounds to invent a different answer, only
|
|
42
|
-
* grounds to flag low confidence (the Phase-4b ambiguity check).
|
|
15
|
+
* Candidates beyond `maxResolve` are never resolved or vetoed. when every resolved
|
|
16
|
+
* candidate is implausible the model's rank-1 wins.
|
|
43
17
|
*/
|
|
44
18
|
export async function rerankByResolution(candidates, resolveTree, opts = {}) {
|
|
45
19
|
if (!candidates.length)
|
|
@@ -49,7 +23,6 @@ export async function rerankByResolution(candidates, resolveTree, opts = {}) {
|
|
|
49
23
|
for (let i = 0; i < candidates.length; i++) {
|
|
50
24
|
const candidate = candidates[i];
|
|
51
25
|
if (i >= maxResolve) {
|
|
52
|
-
// Beyond the resolve budget: carried through unresolved, never vetoed.
|
|
53
26
|
ranked.push({ ...candidate, resolved: null, implausible: false });
|
|
54
27
|
continue;
|
|
55
28
|
}
|
|
@@ -58,12 +31,15 @@ export async function rerankByResolution(candidates, resolveTree, opts = {}) {
|
|
|
58
31
|
resolved = await resolveTree(candidate.tree);
|
|
59
32
|
}
|
|
60
33
|
catch {
|
|
61
|
-
// A resolver failure is
|
|
62
|
-
//
|
|
34
|
+
// A resolver failure is not evidence against the parse, so the model's rank stands
|
|
35
|
+
// rather than vetoing a possibly-correct hypothesis on an outage.
|
|
63
36
|
ranked.push({ ...candidate, resolved: null, implausible: false });
|
|
64
37
|
continue;
|
|
65
38
|
}
|
|
66
|
-
const verdict = isImplausibleResolution(resolved
|
|
39
|
+
const verdict = isImplausibleResolution(resolved, {
|
|
40
|
+
...(opts.expectedCountry ? { expectedCountry: opts.expectedCountry } : {}),
|
|
41
|
+
...(opts.countryBBoxes ? { countryBBoxes: opts.countryBBoxes } : {}),
|
|
42
|
+
});
|
|
67
43
|
ranked.push({
|
|
68
44
|
...candidate,
|
|
69
45
|
resolved,
|
|
@@ -71,7 +47,6 @@ export async function rerankByResolution(candidates, resolveTree, opts = {}) {
|
|
|
71
47
|
...(verdict.reason ? { reason: verdict.reason } : {}),
|
|
72
48
|
});
|
|
73
49
|
}
|
|
74
|
-
// Stable partition: plausible first (model order preserved within each group), vetoed after.
|
|
75
50
|
const plausible = ranked.filter((r) => !r.implausible);
|
|
76
51
|
const vetoed = ranked.filter((r) => r.implausible);
|
|
77
52
|
const finalOrder = [...plausible, ...vetoed];
|
package/out/rerank.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rerank.js","sourceRoot":"","sources":["../lib/rerank.ts"],"names":[],"mappings":"AAAA
|
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EAAE;YACjD,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1E,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACpE,CAAC,CAAA;QAEF,MAAM,CAAC,IAAI,CAAC;YACX,GAAG,SAAS;YACZ,QAAQ;YACR,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACrD,CAAC,CAAA;IACH,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAA;IACtD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAA;IAClD,MAAM,UAAU,GAAG,CAAC,GAAG,SAAS,EAAE,GAAG,MAAM,CAAC,CAAA;IAC5C,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAE,CAAA;IAE3B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;AACjE,CAAC"}
|
package/out/resolve/passes.d.ts
CHANGED
|
@@ -2,25 +2,22 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
* @file The resolver walk's per-node machinery: the trace recorder and its diagnostic bands, the walk's
|
|
6
|
-
* `ResolutionState`, and the span-rescore / postcode-recovery / postcode-consistency passes the walk applies.
|
|
7
|
-
* Split from `resolve.ts`, which owns `WOFResolver` — the walk itself over what this module provides.
|
|
8
5
|
*/
|
|
9
6
|
import type { PlacetypeMap } from "@mailwoman/codex/placetype-map";
|
|
10
7
|
import { type AddressNode } from "@mailwoman/core/decoder";
|
|
11
8
|
import { type CoincidentLocality, type ResolveNodeTrace, type PostcodePrefixIndexLike, type ResolvedPlace, type ResolveOpts, type ResolverBackend } from "@mailwoman/core/resolver";
|
|
12
9
|
import type { CoordinateOptionalPlace } from "#postcode/prefix";
|
|
13
10
|
/**
|
|
14
|
-
* The admin
|
|
11
|
+
* The admin placetypes from country to microhood that `ResolveOpts.diagnoseUnreachable`
|
|
12
|
+
* re-probes, coarse to fine.
|
|
15
13
|
*
|
|
16
|
-
*
|
|
17
|
-
* remembering to.
|
|
14
|
+
* The list derives from `PLACETYPE_SPECIFICITY`, so a new placetype in that range is probed automatically.
|
|
18
15
|
*/
|
|
19
16
|
export declare const DIAGNOSTIC_BANDS: readonly string[];
|
|
20
17
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
18
|
+
* Collects the trace for one placetype lookup and emits it as a `ResolveNodeTrace`;
|
|
19
|
+
* the walk always calls one and uses {@link NOOP_TRACE_RECORDER} when no trace
|
|
20
|
+
* sink is set, so the hot path has no per-event branches.
|
|
24
21
|
*/
|
|
25
22
|
export interface NodeTraceRecorder {
|
|
26
23
|
bind(node: AddressNode, placetype: string, query: {
|
|
@@ -36,62 +33,79 @@ export interface NodeTraceRecorder {
|
|
|
36
33
|
emit(picked: NonNullable<ResolveNodeTrace["picked"]> | null): void;
|
|
37
34
|
}
|
|
38
35
|
/**
|
|
39
|
-
* A
|
|
36
|
+
* A {@link NodeTraceRecorder} that records no events, for walks without a trace sink.
|
|
40
37
|
*/
|
|
41
38
|
export declare const NOOP_TRACE_RECORDER: NodeTraceRecorder;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a {@link NodeTraceRecorder} that sends one `ResolveNodeTrace` to `sink` on `emit`,
|
|
41
|
+
* listing at most ten candidates from the last stage with each candidate's rank in every stage.
|
|
42
|
+
*/
|
|
42
43
|
export declare function createNodeTraceRecorder(sink: (record: ResolveNodeTrace) => void): NodeTraceRecorder;
|
|
44
|
+
/**
|
|
45
|
+
* The options and mutable state that one `resolveTree` call passes through its tree walk.
|
|
46
|
+
*/
|
|
43
47
|
export interface ResolutionState {
|
|
44
48
|
lookupsRemaining: number;
|
|
45
49
|
placetypeMap: PlacetypeMap;
|
|
46
50
|
minWinningScore: number;
|
|
51
|
+
/**
|
|
52
|
+
* The count of lookups rejected by {@link ResolutionState.minWinningScore}.
|
|
53
|
+
*
|
|
54
|
+
* A nonzero count skips the span-rescore pass.
|
|
55
|
+
* That pass would otherwise treat the refused node as unresolved and repeat the rejected lookup.
|
|
56
|
+
*/
|
|
57
|
+
minScoreRefusals: number;
|
|
47
58
|
candidatesPerLookup: number;
|
|
48
59
|
defaultCountry?: string;
|
|
49
60
|
/**
|
|
50
|
-
* Whether {@link defaultCountry} came from the locale
|
|
51
|
-
*
|
|
61
|
+
* Whether {@link ResolutionState.defaultCountry} came from the locale instead of the caller.
|
|
62
|
+
*
|
|
63
|
+
* `country` lookups ignore an inferred default.
|
|
52
64
|
*/
|
|
53
65
|
defaultCountryIsInferred: boolean;
|
|
54
66
|
/**
|
|
55
|
-
* The tree's
|
|
56
|
-
*
|
|
57
|
-
*
|
|
67
|
+
* The tree's only value-bearing node when it maps to `locality`, or null otherwise.
|
|
68
|
+
*
|
|
69
|
+
* Its lookup also probes countries and regions of the same name, because the locality
|
|
70
|
+
* placetype filter cannot reach a country that the parser tagged as a locality.
|
|
58
71
|
*/
|
|
59
72
|
bareLocalityNode: AddressNode | null;
|
|
60
73
|
parentFallback: boolean;
|
|
61
74
|
/**
|
|
62
|
-
* The
|
|
63
|
-
*
|
|
75
|
+
* The tree's first postcode value.
|
|
76
|
+
*
|
|
77
|
+
* Locality lookups send it to the backend.
|
|
78
|
+
* The backend can then favor nearby candidates.
|
|
64
79
|
*/
|
|
65
80
|
postcode?: string;
|
|
66
81
|
/**
|
|
67
|
-
*
|
|
68
|
-
* re-rank name candidates by proximity to the postcode's own centroid. Opt-in; OFF by default.
|
|
82
|
+
* Whether locality lookups ask the backend to re-rank candidates by distance to the postcode centroid.
|
|
69
83
|
*/
|
|
70
84
|
postcodeContainmentCoherence: boolean;
|
|
71
85
|
/**
|
|
72
|
-
*
|
|
73
|
-
* `postcodePrefixIndex`. Opt-in; OFF by default.
|
|
86
|
+
* Whether a `postalcode` lookup that misses falls back to {@link ResolutionState.postcodePrefixIndex}.
|
|
74
87
|
*/
|
|
75
88
|
postcodePrefixPrior: boolean;
|
|
76
89
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
90
|
+
* The countries implied by the postcode's format.
|
|
91
|
+
*
|
|
92
|
+
* A `postalcode` lookup without a country scope probes only these countries
|
|
93
|
+
* and abstains if all of them miss.
|
|
94
|
+
* An unscoped probe of a space-stripped code can match another country's postcode system.
|
|
81
95
|
*/
|
|
82
96
|
postcodeFormatCountries?: readonly string[];
|
|
83
97
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
98
|
+
* The locale hint's country, sent as `fuzzyCountry` on every lookup.
|
|
99
|
+
* It scopes only the typo-fuzzy tier.
|
|
86
100
|
*/
|
|
87
101
|
fuzzyCountryScope?: string;
|
|
88
102
|
/**
|
|
89
|
-
* The
|
|
90
|
-
* fire.
|
|
103
|
+
* The postcode prefix index that {@link ResolutionState.postcodePrefixPrior} requires.
|
|
91
104
|
*/
|
|
92
105
|
postcodePrefixIndex?: PostcodePrefixIndexLike;
|
|
93
106
|
/**
|
|
94
|
-
* Proximity-bias points
|
|
107
|
+
* Proximity-bias points, such as a viewport or user location, that every
|
|
108
|
+
* lookup uses to reorder candidates.
|
|
95
109
|
*/
|
|
96
110
|
bias?: Array<{
|
|
97
111
|
lat: number;
|
|
@@ -99,33 +113,39 @@ export interface ResolutionState {
|
|
|
99
113
|
weight?: number;
|
|
100
114
|
}>;
|
|
101
115
|
/**
|
|
102
|
-
*
|
|
116
|
+
* The postcode anchor's posterior over countries, used to re-rank region and locality candidates.
|
|
117
|
+
*
|
|
118
|
+
* When set, it also replaces the importance re-rank and capital promotion.
|
|
103
119
|
*/
|
|
104
120
|
anchorPosterior?: Record<string, number>;
|
|
105
121
|
/**
|
|
106
|
-
*
|
|
122
|
+
* The weight on {@link ResolutionState.anchorPosterior} in the re-rank key.
|
|
107
123
|
*/
|
|
108
124
|
anchorWeight: number;
|
|
109
125
|
/**
|
|
110
|
-
*
|
|
126
|
+
* The callback that receives one trace record per lookup.
|
|
127
|
+
* The walk records no events when it is absent.
|
|
111
128
|
*/
|
|
112
129
|
traceSink?: (record: ResolveNodeTrace) => void;
|
|
113
130
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
131
|
+
* Whether an empty lookup re-probes the other admin bands and traces which ones hold the value.
|
|
132
|
+
*
|
|
133
|
+
* It is set only when a trace sink exists.
|
|
134
|
+
* It never affects the pick.
|
|
116
135
|
*/
|
|
117
136
|
diagnoseUnreachable?: boolean;
|
|
118
137
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
138
|
+
* The locale country used as a soft prior on region and locality candidates
|
|
139
|
+
* when no default country or anchor posterior applies.
|
|
121
140
|
*/
|
|
122
141
|
localeCountryPrior?: string;
|
|
123
142
|
/**
|
|
124
|
-
*
|
|
143
|
+
* The weight of {@link ResolutionState.localeCountryPrior}, in log10-population units.
|
|
125
144
|
*/
|
|
126
145
|
localeCountryPriorWeight: number;
|
|
127
146
|
/**
|
|
128
|
-
*
|
|
147
|
+
* Returns a candidate's capital level for bounded capital promotion.
|
|
148
|
+
* Capital promotion is off when it is absent.
|
|
129
149
|
*/
|
|
130
150
|
capitalLevel?: (place: {
|
|
131
151
|
name: string;
|
|
@@ -134,86 +154,76 @@ export interface ResolutionState {
|
|
|
134
154
|
lon: number;
|
|
135
155
|
}) => number;
|
|
136
156
|
/**
|
|
137
|
-
*
|
|
157
|
+
* The country scope applied to a lookup when no parent, default country, or node hint supplies one.
|
|
138
158
|
*/
|
|
139
159
|
hardCountry?: string;
|
|
140
160
|
/**
|
|
141
|
-
*
|
|
161
|
+
* Whether a resolved region gains its coincident locality of the same name as an
|
|
162
|
+
* interpretation when the tree has no locality node.
|
|
142
163
|
*/
|
|
143
164
|
hierarchyCompletion: boolean;
|
|
144
165
|
/**
|
|
145
|
-
*
|
|
166
|
+
* Whether each resolved node gets its ancestor lineage in metadata, when the backend supports it.
|
|
146
167
|
*/
|
|
147
168
|
includeAncestors: boolean;
|
|
148
169
|
/**
|
|
149
|
-
*
|
|
170
|
+
* Whether locality candidates contained by {@link ResolutionState.regionQualifier}
|
|
171
|
+
* are ordered ahead of the rest.
|
|
150
172
|
*/
|
|
151
173
|
adminContainmentRerank: boolean;
|
|
152
174
|
/**
|
|
153
|
-
* The tree's first
|
|
154
|
-
*
|
|
155
|
-
*
|
|
175
|
+
* The tree's first region value.
|
|
176
|
+
*
|
|
177
|
+
* The region and locality nodes are siblings, so the walk would not otherwise
|
|
178
|
+
* pass the region to the locality lookup.
|
|
179
|
+
* It applies only with {@link ResolutionState.adminContainmentRerank}
|
|
180
|
+
* and no caller-supplied default country.
|
|
156
181
|
*/
|
|
157
182
|
regionQualifier?: string;
|
|
158
183
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
184
|
+
* Whether any node maps to the `locality` placetype.
|
|
185
|
+
* Hierarchy completion runs only when this is false.
|
|
161
186
|
*/
|
|
162
187
|
localityNodePresent: boolean;
|
|
163
188
|
/**
|
|
164
|
-
* The first region
|
|
189
|
+
* The first resolved region place, used to look up its coincident locality.
|
|
165
190
|
*/
|
|
166
191
|
resolvedRegion: CoordinateOptionalPlace | null;
|
|
167
192
|
/**
|
|
168
|
-
* The decorated
|
|
169
|
-
*
|
|
193
|
+
* The decorated node for {@link ResolutionState.resolvedRegion}.
|
|
194
|
+
*
|
|
195
|
+
* Hierarchy completion adds the locality interpretation to it in place.
|
|
170
196
|
*/
|
|
171
197
|
resolvedRegionNode: AddressNode | null;
|
|
172
198
|
}
|
|
173
199
|
/**
|
|
174
|
-
*
|
|
175
|
-
* likelihood is the PRIMARY signal — the principal city is the populous one, and it can sit FARTHER from the admin
|
|
176
|
-
* centroid than a tiny same-name hamlet (the Niigata case from #403). Nearest centroid breaks a referential tie; a
|
|
177
|
-
* genuine tie (same population AND distance) ABSTAINS rather than guess.
|
|
200
|
+
* Picks the completion locality among coincident candidates of the same name.
|
|
178
201
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* saturation and constant above it. The abstention check below still reads raw population, deliberately: two megacities
|
|
182
|
-
* that saturate to the same referential score are not tied, and abstaining there would be a new behavior.
|
|
202
|
+
* It prefers the most populous candidate, then the nearest candidate.
|
|
203
|
+
* It returns `null` on an exact tie.
|
|
183
204
|
*/
|
|
184
205
|
export declare function pickCompletion(candidates: readonly CoincidentLocality[]): CoincidentLocality | null;
|
|
185
206
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
207
|
+
* Returns the first postcode value anywhere in the tree, skipping shape-excluded postcodes.
|
|
208
|
+
* a locality lookup uses it because the postcode node is usually a sibling.
|
|
188
209
|
*/
|
|
189
210
|
export declare function firstPostcodeValue(roots: readonly AddressNode[]): string | undefined;
|
|
190
211
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* `opts.spanRescore: false`. Async (it queries the backend), so it's awaited.
|
|
212
|
+
* Recovers a locality from raw-text spans when the tree resolved no place,
|
|
213
|
+
* appending a resolved `locality` node on a hit.
|
|
214
|
+
*
|
|
215
|
+
* When no span matches, it tries the postcode node's code part.
|
|
196
216
|
*/
|
|
197
217
|
export declare function applySpanRescore(roots: AddressNode[], raw: string, backend: ResolverBackend, opts: ResolveOpts): Promise<void>;
|
|
198
218
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* 2. For each resolved locality node farther than `thresholdKm` from it: re-pick the same-named candidate from the node's
|
|
208
|
-
* already-captured `alternatives` that is NEAREST the postcode and within the radius. This keeps locality
|
|
209
|
-
* granularity at the CORRECT instance.
|
|
210
|
-
* 3. If no alternative reconciles, the locality instance is unreliable — fall its coordinate back to the postcode point
|
|
211
|
-
* (right area, the safe answer) and flag `postcode_city_mismatch`.
|
|
212
|
-
*
|
|
213
|
-
* Only fires where the postcode resolved to a point, so it composes with postcode coverage (#193) — add a country's
|
|
214
|
-
* postcodes and this immediately disambiguates its same-named towns. **Default-ON** since the #370 operator promotion
|
|
215
|
-
* (2026-07-04, commit `0010bb8c`) — `opts.postcodeConsistency: false` opts out, and the pass is byte-stable on every
|
|
216
|
-
* tree with no resolved postcode point (the `!anchor` early return below).
|
|
219
|
+
* The farthest distance, in kilometers, that {@link applyPostcodeConsistency}
|
|
220
|
+
* moves a locality onto its postcode's point.
|
|
221
|
+
*/
|
|
222
|
+
export declare const DEFAULT_POSTCODE_MAX_MOVE_KM = 300;
|
|
223
|
+
/**
|
|
224
|
+
* Reconciles each resolved locality that lies farther than `thresholdKm` from the tree's
|
|
225
|
+
* resolved postcode point, re-picking the nearest alternative within the threshold and otherwise
|
|
226
|
+
* moving the coordinate there, but skipping the move when the distance exceeds `maxMoveKm`.
|
|
217
227
|
*/
|
|
218
|
-
export declare function applyPostcodeConsistency(roots: readonly AddressNode[], thresholdKm: number): void;
|
|
228
|
+
export declare function applyPostcodeConsistency(roots: readonly AddressNode[], thresholdKm: number, maxMoveKm?: number): void;
|
|
219
229
|
//# sourceMappingURL=passes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"passes.d.ts","sourceRoot":"","sources":["../../lib/resolve/passes.ts"],"names":[],"mappings":"AAAA
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