@mailwoman/resolver 9.4.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 +21 -161
- 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 +73 -39
- package/lib/decorate-node.ts +17 -41
- package/lib/fold-name.ts +5 -18
- package/lib/index.ts +5 -9
- package/lib/plausibility.ts +37 -63
- 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 +145 -148
- 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 +18 -69
- package/out/admin/coherence-passes.d.ts.map +1 -1
- package/out/admin/coherence-passes.js +19 -161
- 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 +56 -28
- 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 +29 -58
- 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 +97 -86
- 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 -995
- 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 -807
- 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,24 +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
|
*/
|
|
6
|
+
import type { PlacetypeMap } from "@mailwoman/codex/placetype-map";
|
|
9
7
|
import { type AddressNode } from "@mailwoman/core/decoder";
|
|
10
|
-
import { type CoincidentLocality, type ResolveNodeTrace, type
|
|
8
|
+
import { type CoincidentLocality, type ResolveNodeTrace, type PostcodePrefixIndexLike, type ResolvedPlace, type ResolveOpts, type ResolverBackend } from "@mailwoman/core/resolver";
|
|
11
9
|
import type { CoordinateOptionalPlace } from "#postcode/prefix";
|
|
12
10
|
/**
|
|
13
|
-
* The admin
|
|
11
|
+
* The admin placetypes from country to microhood that `ResolveOpts.diagnoseUnreachable`
|
|
12
|
+
* re-probes, coarse to fine.
|
|
14
13
|
*
|
|
15
|
-
*
|
|
16
|
-
* remembering to.
|
|
14
|
+
* The list derives from `PLACETYPE_SPECIFICITY`, so a new placetype in that range is probed automatically.
|
|
17
15
|
*/
|
|
18
16
|
export declare const DIAGNOSTIC_BANDS: readonly string[];
|
|
19
17
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
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.
|
|
23
21
|
*/
|
|
24
22
|
export interface NodeTraceRecorder {
|
|
25
23
|
bind(node: AddressNode, placetype: string, query: {
|
|
@@ -35,62 +33,79 @@ export interface NodeTraceRecorder {
|
|
|
35
33
|
emit(picked: NonNullable<ResolveNodeTrace["picked"]> | null): void;
|
|
36
34
|
}
|
|
37
35
|
/**
|
|
38
|
-
* A
|
|
36
|
+
* A {@link NodeTraceRecorder} that records no events, for walks without a trace sink.
|
|
39
37
|
*/
|
|
40
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
|
+
*/
|
|
41
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
|
+
*/
|
|
42
47
|
export interface ResolutionState {
|
|
43
48
|
lookupsRemaining: number;
|
|
44
49
|
placetypeMap: PlacetypeMap;
|
|
45
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;
|
|
46
58
|
candidatesPerLookup: number;
|
|
47
59
|
defaultCountry?: string;
|
|
48
60
|
/**
|
|
49
|
-
* Whether {@link defaultCountry} came from the locale
|
|
50
|
-
*
|
|
61
|
+
* Whether {@link ResolutionState.defaultCountry} came from the locale instead of the caller.
|
|
62
|
+
*
|
|
63
|
+
* `country` lookups ignore an inferred default.
|
|
51
64
|
*/
|
|
52
65
|
defaultCountryIsInferred: boolean;
|
|
53
66
|
/**
|
|
54
|
-
* The tree's
|
|
55
|
-
*
|
|
56
|
-
*
|
|
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.
|
|
57
71
|
*/
|
|
58
72
|
bareLocalityNode: AddressNode | null;
|
|
59
73
|
parentFallback: boolean;
|
|
60
74
|
/**
|
|
61
|
-
* The
|
|
62
|
-
*
|
|
75
|
+
* The tree's first postcode value.
|
|
76
|
+
*
|
|
77
|
+
* Locality lookups send it to the backend.
|
|
78
|
+
* The backend can then favor nearby candidates.
|
|
63
79
|
*/
|
|
64
80
|
postcode?: string;
|
|
65
81
|
/**
|
|
66
|
-
*
|
|
67
|
-
* 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.
|
|
68
83
|
*/
|
|
69
84
|
postcodeContainmentCoherence: boolean;
|
|
70
85
|
/**
|
|
71
|
-
*
|
|
72
|
-
* `postcodePrefixIndex`. Opt-in; OFF by default.
|
|
86
|
+
* Whether a `postalcode` lookup that misses falls back to {@link ResolutionState.postcodePrefixIndex}.
|
|
73
87
|
*/
|
|
74
88
|
postcodePrefixPrior: boolean;
|
|
75
89
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
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.
|
|
80
95
|
*/
|
|
81
96
|
postcodeFormatCountries?: readonly string[];
|
|
82
97
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
98
|
+
* The locale hint's country, sent as `fuzzyCountry` on every lookup.
|
|
99
|
+
* It scopes only the typo-fuzzy tier.
|
|
85
100
|
*/
|
|
86
101
|
fuzzyCountryScope?: string;
|
|
87
102
|
/**
|
|
88
|
-
* The
|
|
89
|
-
* fire.
|
|
103
|
+
* The postcode prefix index that {@link ResolutionState.postcodePrefixPrior} requires.
|
|
90
104
|
*/
|
|
91
105
|
postcodePrefixIndex?: PostcodePrefixIndexLike;
|
|
92
106
|
/**
|
|
93
|
-
* Proximity-bias points
|
|
107
|
+
* Proximity-bias points, such as a viewport or user location, that every
|
|
108
|
+
* lookup uses to reorder candidates.
|
|
94
109
|
*/
|
|
95
110
|
bias?: Array<{
|
|
96
111
|
lat: number;
|
|
@@ -98,33 +113,39 @@ export interface ResolutionState {
|
|
|
98
113
|
weight?: number;
|
|
99
114
|
}>;
|
|
100
115
|
/**
|
|
101
|
-
*
|
|
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.
|
|
102
119
|
*/
|
|
103
120
|
anchorPosterior?: Record<string, number>;
|
|
104
121
|
/**
|
|
105
|
-
*
|
|
122
|
+
* The weight on {@link ResolutionState.anchorPosterior} in the re-rank key.
|
|
106
123
|
*/
|
|
107
124
|
anchorWeight: number;
|
|
108
125
|
/**
|
|
109
|
-
*
|
|
126
|
+
* The callback that receives one trace record per lookup.
|
|
127
|
+
* The walk records no events when it is absent.
|
|
110
128
|
*/
|
|
111
129
|
traceSink?: (record: ResolveNodeTrace) => void;
|
|
112
130
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
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.
|
|
115
135
|
*/
|
|
116
136
|
diagnoseUnreachable?: boolean;
|
|
117
137
|
/**
|
|
118
|
-
*
|
|
119
|
-
*
|
|
138
|
+
* The locale country used as a soft prior on region and locality candidates
|
|
139
|
+
* when no default country or anchor posterior applies.
|
|
120
140
|
*/
|
|
121
141
|
localeCountryPrior?: string;
|
|
122
142
|
/**
|
|
123
|
-
*
|
|
143
|
+
* The weight of {@link ResolutionState.localeCountryPrior}, in log10-population units.
|
|
124
144
|
*/
|
|
125
145
|
localeCountryPriorWeight: number;
|
|
126
146
|
/**
|
|
127
|
-
*
|
|
147
|
+
* Returns a candidate's capital level for bounded capital promotion.
|
|
148
|
+
* Capital promotion is off when it is absent.
|
|
128
149
|
*/
|
|
129
150
|
capitalLevel?: (place: {
|
|
130
151
|
name: string;
|
|
@@ -133,86 +154,76 @@ export interface ResolutionState {
|
|
|
133
154
|
lon: number;
|
|
134
155
|
}) => number;
|
|
135
156
|
/**
|
|
136
|
-
*
|
|
157
|
+
* The country scope applied to a lookup when no parent, default country, or node hint supplies one.
|
|
137
158
|
*/
|
|
138
159
|
hardCountry?: string;
|
|
139
160
|
/**
|
|
140
|
-
*
|
|
161
|
+
* Whether a resolved region gains its coincident locality of the same name as an
|
|
162
|
+
* interpretation when the tree has no locality node.
|
|
141
163
|
*/
|
|
142
164
|
hierarchyCompletion: boolean;
|
|
143
165
|
/**
|
|
144
|
-
*
|
|
166
|
+
* Whether each resolved node gets its ancestor lineage in metadata, when the backend supports it.
|
|
145
167
|
*/
|
|
146
168
|
includeAncestors: boolean;
|
|
147
169
|
/**
|
|
148
|
-
*
|
|
170
|
+
* Whether locality candidates contained by {@link ResolutionState.regionQualifier}
|
|
171
|
+
* are ordered ahead of the rest.
|
|
149
172
|
*/
|
|
150
173
|
adminContainmentRerank: boolean;
|
|
151
174
|
/**
|
|
152
|
-
* The tree's first
|
|
153
|
-
*
|
|
154
|
-
*
|
|
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.
|
|
155
181
|
*/
|
|
156
182
|
regionQualifier?: string;
|
|
157
183
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
184
|
+
* Whether any node maps to the `locality` placetype.
|
|
185
|
+
* Hierarchy completion runs only when this is false.
|
|
160
186
|
*/
|
|
161
187
|
localityNodePresent: boolean;
|
|
162
188
|
/**
|
|
163
|
-
* The first region
|
|
189
|
+
* The first resolved region place, used to look up its coincident locality.
|
|
164
190
|
*/
|
|
165
191
|
resolvedRegion: CoordinateOptionalPlace | null;
|
|
166
192
|
/**
|
|
167
|
-
* The decorated
|
|
168
|
-
*
|
|
193
|
+
* The decorated node for {@link ResolutionState.resolvedRegion}.
|
|
194
|
+
*
|
|
195
|
+
* Hierarchy completion adds the locality interpretation to it in place.
|
|
169
196
|
*/
|
|
170
197
|
resolvedRegionNode: AddressNode | null;
|
|
171
198
|
}
|
|
172
199
|
/**
|
|
173
|
-
*
|
|
174
|
-
* likelihood is the PRIMARY signal — the principal city is the populous one, and it can sit FARTHER from the admin
|
|
175
|
-
* centroid than a tiny same-name hamlet (the Niigata case from #403). Nearest centroid breaks a referential tie; a
|
|
176
|
-
* genuine tie (same population AND distance) ABSTAINS rather than guess.
|
|
200
|
+
* Picks the completion locality among coincident candidates of the same name.
|
|
177
201
|
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* saturation and constant above it. The abstention check below still reads raw population, deliberately: two megacities
|
|
181
|
-
* 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.
|
|
182
204
|
*/
|
|
183
205
|
export declare function pickCompletion(candidates: readonly CoincidentLocality[]): CoincidentLocality | null;
|
|
184
206
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
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.
|
|
187
209
|
*/
|
|
188
210
|
export declare function firstPostcodeValue(roots: readonly AddressNode[]): string | undefined;
|
|
189
211
|
/**
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* `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.
|
|
195
216
|
*/
|
|
196
217
|
export declare function applySpanRescore(roots: AddressNode[], raw: string, backend: ResolverBackend, opts: ResolveOpts): Promise<void>;
|
|
197
218
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* 2. For each resolved locality node farther than `thresholdKm` from it: re-pick the same-named candidate from the node's
|
|
207
|
-
* already-captured `alternatives` that is NEAREST the postcode and within the radius. This keeps locality
|
|
208
|
-
* granularity at the CORRECT instance.
|
|
209
|
-
* 3. If no alternative reconciles, the locality instance is unreliable — fall its coordinate back to the postcode point
|
|
210
|
-
* (right area, the safe answer) and flag `postcode_city_mismatch`.
|
|
211
|
-
*
|
|
212
|
-
* Only fires where the postcode resolved to a point, so it composes with postcode coverage (#193) — add a country's
|
|
213
|
-
* postcodes and this immediately disambiguates its same-named towns. **Default-ON** since the #370 operator promotion
|
|
214
|
-
* (2026-07-04, commit `0010bb8c`) — `opts.postcodeConsistency: false` opts out, and the pass is byte-stable on every
|
|
215
|
-
* 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`.
|
|
216
227
|
*/
|
|
217
|
-
export declare function applyPostcodeConsistency(roots: readonly AddressNode[], thresholdKm: number): void;
|
|
228
|
+
export declare function applyPostcodeConsistency(roots: readonly AddressNode[], thresholdKm: number, maxMoveKm?: number): void;
|
|
218
229
|
//# sourceMappingURL=passes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"passes.d.ts","sourceRoot":"","sources":["../../lib/resolve/passes.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"passes.d.ts","sourceRoot":"","sources":["../../lib/resolve/passes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,EACN,KAAK,kBAAkB,EAGvB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAE5B,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,MAAM,0BAA0B,CAAA;AAKjC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAU/D;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAGb,CAAA;AAEjC;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IACjC,IAAI,CACH,IAAI,EAAE,WAAW,EACjB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE;QACN,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;QAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,eAAe,CAAC,EAAE,MAAM,CAAA;QACxB,KAAK,CAAC,EAAE,MAAM,CAAA;KACd,EACD,YAAY,EAAE,MAAM,GAClB,IAAI,CAAA;IACP,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,IAAI,CAAA;IAC1D,SAAS,CAAC,KAAK,EAAE,WAAW,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC,GAAG,IAAI,CAAA;IACpE,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG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