@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/plausibility.d.ts
CHANGED
|
@@ -2,68 +2,37 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Resolution-plausibility guard (#727 / v7 excision arc).
|
|
7
|
-
*
|
|
8
|
-
* The 2026-07-15 coordinate-parity study
|
|
9
|
-
* (`docs/articles/evals/2026-07-15-v7-parity-floor-diagnosis.md`) found the neural parser is
|
|
10
|
-
* coordinate-safe on well-formed input (98.6% within 1 km of the rules parser through the same
|
|
11
|
-
* resolver) but produces a garbage-geocode tail on the bare-fragment / bare-state-name / US-highway
|
|
12
|
-
* classes — inputs like `California` or `6000, NSW, Australia` that resolve to nothing finer than a
|
|
13
|
-
* country centroid.
|
|
14
|
-
*
|
|
15
|
-
* This guard is the cheap post-resolve check for that tail: a resolved tree whose finest resolved
|
|
16
|
-
* place is only a `country` centroid is implausible for a structured address. It reads only the
|
|
17
|
-
* decorated tree — no gazetteer, no extra query — so it is free to run on every resolve. It is
|
|
18
|
-
* deliberately DIRECTION-AGNOSTIC about what the caller does with the signal: serve the result with
|
|
19
|
-
* a low-confidence marker, prefer a sibling parse hypothesis (the #727 k-best rerank), or decline to
|
|
20
|
-
* emit a coordinate. It is NOT a rules-fallback trigger — the v7 excision deletes the rules parser
|
|
21
|
-
* outright (operator ruling 2026-07-15), so no consumer may route through legacy rules on a trip.
|
|
22
|
-
*
|
|
23
|
-
* It deliberately does NOT flag region-tier resolutions: a US state or a province centroid
|
|
24
|
-
* (`Texas` → the TX centroid) is a legitimate coarse geocode, not garbage. Only "resolved no finer
|
|
25
|
-
* than a country" trips it.
|
|
26
5
|
*/
|
|
27
6
|
import type { ComponentTag } from "@mailwoman/codex/component";
|
|
28
7
|
import type { AddressTree } from "@mailwoman/core/decoder";
|
|
29
8
|
import type { CountryBBoxFact } from "@mailwoman/core/resolver";
|
|
30
9
|
/**
|
|
31
|
-
*
|
|
10
|
+
* Holds the coordinate a caller would serve for a resolved tree, with the tag of the node that supplied it.
|
|
32
11
|
*/
|
|
33
12
|
export interface ResolvedCoordinate {
|
|
34
13
|
tag: ComponentTag;
|
|
35
14
|
lat: number;
|
|
36
15
|
lon: number;
|
|
37
16
|
/**
|
|
38
|
-
*
|
|
17
|
+
* The canonical place URI, such as `wof:…`, when the resolver supplied one.
|
|
39
18
|
*/
|
|
40
19
|
placeID?: string;
|
|
41
20
|
}
|
|
42
21
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
22
|
+
* Returns the resolved coordinate at the finest granularity tier in the tree,
|
|
23
|
+
* preferring the earliest node on a tie.
|
|
24
|
+
* It returns `null` when no node has a `lat`/`lon`.
|
|
46
25
|
*/
|
|
47
26
|
export declare function finestResolvedCoordinate(tree: AddressTree): ResolvedCoordinate | null;
|
|
48
27
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* the mainland east coast; continental FR only; etc. A country absent here simply never trips the guard (fail-open).
|
|
53
|
-
*
|
|
54
|
-
* FALLBACK ROLE (survey candidate #2): these boxes are also baked into the candidate gazetteer's `country_bbox`
|
|
55
|
-
* manifest table at build time (`mailwoman/gazetteer-pipeline/coverage-manifest.ts` owns the measured record). When a
|
|
56
|
-
* caller supplies artifact-declared boxes ({@link PlausibilityOpts.countryBBoxes}), those REPLACE this table wholesale
|
|
57
|
-
* — the artifact speaks for itself, and a country absent from the artifact's table fails open exactly like an absent
|
|
58
|
-
* key here. This constant is the fallback for artifacts predating the manifest; grow the manifest record, not this.
|
|
28
|
+
* Lists coarse per-country bounding boxes, as `[latMin, latMax, lonMin, lonMax]`,
|
|
29
|
+
* for artifacts whose manifest declares none.
|
|
30
|
+
* A country without a box never trips the guard.
|
|
59
31
|
*/
|
|
60
32
|
export declare const COUNTRY_BBOX: Readonly<Record<string, readonly [number, number, number, number]>>;
|
|
61
33
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* When `bboxes` (artifact-declared boxes, {@link GazetteerArtifactCoverage.countryBBoxes}) is supplied it REPLACES the
|
|
65
|
-
* built-in {@link COUNTRY_BBOX} table wholesale — absence from the artifact's table fails open, same semantic as an
|
|
66
|
-
* absent constant key. Omitted → the constant, byte-identical to the pre-manifest behavior.
|
|
34
|
+
* Reports whether a coordinate lies outside the country's bounding box, using `bboxes` in
|
|
35
|
+
* place of {@link COUNTRY_BBOX} when supplied and returning `false` for a country with no box.
|
|
67
36
|
*/
|
|
68
37
|
export declare function outsideExpectedCountry(countryCode: string, lat: number, lon: number, bboxes?: ReadonlyMap<string, CountryBBoxFact>): boolean;
|
|
69
38
|
/**
|
|
@@ -72,37 +41,38 @@ export declare function outsideExpectedCountry(countryCode: string, lat: number,
|
|
|
72
41
|
export interface PlausibilityVerdict {
|
|
73
42
|
implausible: boolean;
|
|
74
43
|
/**
|
|
75
|
-
*
|
|
76
|
-
* `
|
|
44
|
+
* Why the resolution is implausible, set only when `implausible` is true:
|
|
45
|
+
* `country-centroid` or `outside-expected-country`.
|
|
77
46
|
*/
|
|
78
47
|
reason?: "country-centroid" | "outside-expected-country";
|
|
79
48
|
/**
|
|
80
|
-
* The coordinate the verdict was
|
|
49
|
+
* The coordinate the verdict was based on, present when anything resolved.
|
|
81
50
|
*/
|
|
82
51
|
coordinate?: ResolvedCoordinate;
|
|
83
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Configures {@linkcode isImplausibleResolution} with the country the address should
|
|
55
|
+
* fall in and optional artifact-declared bounding boxes.
|
|
56
|
+
*/
|
|
84
57
|
export interface PlausibilityOpts {
|
|
85
58
|
/**
|
|
86
|
-
* ISO-2 country the resolution
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* only in the receipt harness, so the shipped residual read 5/321 while the receipt said 3/321).
|
|
59
|
+
* The ISO 3166-1 alpha-2 country the resolution should land in.
|
|
60
|
+
*
|
|
61
|
+
* A set `expectedCountry` enables the bounding-box check that catches cross-country
|
|
62
|
+
* jumps the country-centroid check cannot.
|
|
91
63
|
*/
|
|
92
64
|
expectedCountry?: string;
|
|
93
65
|
/**
|
|
94
|
-
* Artifact-declared
|
|
95
|
-
*
|
|
96
|
-
* wholesale; omitted → the constant (byte-identical fallback for artifacts predating the manifest).
|
|
66
|
+
* Artifact-declared country bounding boxes that replace the built-in
|
|
67
|
+
* {@link COUNTRY_BBOX} table entirely when supplied.
|
|
97
68
|
*/
|
|
98
69
|
countryBBoxes?: ReadonlyMap<string, CountryBBoxFact>;
|
|
99
70
|
}
|
|
100
71
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* to serve.
|
|
72
|
+
* Decides whether a resolved tree's coordinate is implausible: a bare country centroid,
|
|
73
|
+
* or a point outside `expectedCountry`'s bounding box.
|
|
74
|
+
*
|
|
75
|
+
* An unresolved tree is plausible because it serves no coordinate.
|
|
106
76
|
*/
|
|
107
77
|
export declare function isImplausibleResolution(tree: AddressTree, opts?: PlausibilityOpts): PlausibilityVerdict;
|
|
108
78
|
//# sourceMappingURL=plausibility.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plausibility.d.ts","sourceRoot":"","sources":["../lib/plausibility.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"plausibility.d.ts","sourceRoot":"","sources":["../lib/plausibility.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAgB/D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,GAAG,EAAE,YAAY,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IAEX;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,GAAG,kBAAkB,GAAG,IAAI,CAwBrF;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAuB5F,CAAA;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACrC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,GAC3C,OAAO,CAgBT;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IACnC,WAAW,EAAE,OAAO,CAAA;IAEpB;;;OAGG;IACH,MAAM,CAAC,EAAE,kBAAkB,GAAG,0BAA0B,CAAA;IAExD;;OAEG;IACH,UAAU,CAAC,EAAE,kBAAkB,CAAA;CAC/B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB;;;OAGG;IACH,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CACpD;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,GAAE,gBAAqB,GAAG,mBAAmB,CAgB3G"}
|
package/out/plausibility.js
CHANGED
|
@@ -2,32 +2,6 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Resolution-plausibility guard (#727 / v7 excision arc).
|
|
7
|
-
*
|
|
8
|
-
* The 2026-07-15 coordinate-parity study
|
|
9
|
-
* (`docs/articles/evals/2026-07-15-v7-parity-floor-diagnosis.md`) found the neural parser is
|
|
10
|
-
* coordinate-safe on well-formed input (98.6% within 1 km of the rules parser through the same
|
|
11
|
-
* resolver) but produces a garbage-geocode tail on the bare-fragment / bare-state-name / US-highway
|
|
12
|
-
* classes — inputs like `California` or `6000, NSW, Australia` that resolve to nothing finer than a
|
|
13
|
-
* country centroid.
|
|
14
|
-
*
|
|
15
|
-
* This guard is the cheap post-resolve check for that tail: a resolved tree whose finest resolved
|
|
16
|
-
* place is only a `country` centroid is implausible for a structured address. It reads only the
|
|
17
|
-
* decorated tree — no gazetteer, no extra query — so it is free to run on every resolve. It is
|
|
18
|
-
* deliberately DIRECTION-AGNOSTIC about what the caller does with the signal: serve the result with
|
|
19
|
-
* a low-confidence marker, prefer a sibling parse hypothesis (the #727 k-best rerank), or decline to
|
|
20
|
-
* emit a coordinate. It is NOT a rules-fallback trigger — the v7 excision deletes the rules parser
|
|
21
|
-
* outright (operator ruling 2026-07-15), so no consumer may route through legacy rules on a trip.
|
|
22
|
-
*
|
|
23
|
-
* It deliberately does NOT flag region-tier resolutions: a US state or a province centroid
|
|
24
|
-
* (`Texas` → the TX centroid) is a legitimate coarse geocode, not garbage. Only "resolved no finer
|
|
25
|
-
* than a country" trips it.
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* Resolution granularity, coarse → fine. A resolved node's {@link AddressNode.tag} places it on this ladder; the
|
|
29
|
-
* geocode a caller serves comes from the FINEST resolved node. Tags absent here (unit, po_box, intersection halves, …)
|
|
30
|
-
* are treated as street-tier specificity when resolved.
|
|
31
5
|
*/
|
|
32
6
|
const RESOLUTION_TIER = {
|
|
33
7
|
country: 0,
|
|
@@ -43,9 +17,9 @@ const RESOLUTION_TIER = {
|
|
|
43
17
|
house_number: 5,
|
|
44
18
|
};
|
|
45
19
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
20
|
+
* Returns the resolved coordinate at the finest granularity tier in the tree,
|
|
21
|
+
* preferring the earliest node on a tie.
|
|
22
|
+
* It returns `null` when no node has a `lat`/`lon`.
|
|
49
23
|
*/
|
|
50
24
|
export function finestResolvedCoordinate(tree) {
|
|
51
25
|
let best = null;
|
|
@@ -68,21 +42,15 @@ export function finestResolvedCoordinate(tree) {
|
|
|
68
42
|
return best;
|
|
69
43
|
}
|
|
70
44
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* the mainland east coast; continental FR only; etc. A country absent here simply never trips the guard (fail-open).
|
|
75
|
-
*
|
|
76
|
-
* FALLBACK ROLE (survey candidate #2): these boxes are also baked into the candidate gazetteer's `country_bbox`
|
|
77
|
-
* manifest table at build time (`mailwoman/gazetteer-pipeline/coverage-manifest.ts` owns the measured record). When a
|
|
78
|
-
* caller supplies artifact-declared boxes ({@link PlausibilityOpts.countryBBoxes}), those REPLACE this table wholesale
|
|
79
|
-
* — the artifact speaks for itself, and a country absent from the artifact's table fails open exactly like an absent
|
|
80
|
-
* key here. This constant is the fallback for artifacts predating the manifest; grow the manifest record, not this.
|
|
45
|
+
* Lists coarse per-country bounding boxes, as `[latMin, latMax, lonMin, lonMax]`,
|
|
46
|
+
* for artifacts whose manifest declares none.
|
|
47
|
+
* A country without a box never trips the guard.
|
|
81
48
|
*/
|
|
82
49
|
export const COUNTRY_BBOX = {
|
|
83
50
|
US: [18, 72, -180, -66],
|
|
84
51
|
AU: [-44, -10, 112, 154],
|
|
85
52
|
BR: [-34, 6, -74, -34],
|
|
53
|
+
CN: [15.7, 53.6, 73.4, 135.1],
|
|
86
54
|
CZ: [48, 51.5, 12, 19],
|
|
87
55
|
DE: [47, 55.5, 5.5, 15.5],
|
|
88
56
|
ES: [35, 44, -10, 5],
|
|
@@ -90,8 +58,11 @@ export const COUNTRY_BBOX = {
|
|
|
90
58
|
GB: [49, 61, -8.7, 2],
|
|
91
59
|
HR: [42, 46.6, 13, 19.5],
|
|
92
60
|
IN: [6, 36, 68, 98],
|
|
61
|
+
IT: [35.4, 47.1, 6.6, 18.6],
|
|
62
|
+
JP: [20.2, 45.7, 122.8, 154.1],
|
|
93
63
|
NL: [50.7, 53.7, 3.3, 7.3],
|
|
94
64
|
NO: [57, 71.5, 4, 31],
|
|
65
|
+
NZ: [-52.7, -29.1, -180, 180],
|
|
95
66
|
PL: [49, 55, 14, 24.2],
|
|
96
67
|
PT: [36.5, 42.2, -9.6, -6.1],
|
|
97
68
|
RO: [43.5, 48.3, 20, 30],
|
|
@@ -100,11 +71,8 @@ export const COUNTRY_BBOX = {
|
|
|
100
71
|
SI: [45.4, 46.9, 13.3, 16.6],
|
|
101
72
|
};
|
|
102
73
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* When `bboxes` (artifact-declared boxes, {@link GazetteerArtifactCoverage.countryBBoxes}) is supplied it REPLACES the
|
|
106
|
-
* built-in {@link COUNTRY_BBOX} table wholesale — absence from the artifact's table fails open, same semantic as an
|
|
107
|
-
* absent constant key. Omitted → the constant, byte-identical to the pre-manifest behavior.
|
|
74
|
+
* Reports whether a coordinate lies outside the country's bounding box, using `bboxes` in
|
|
75
|
+
* place of {@link COUNTRY_BBOX} when supplied and returning `false` for a country with no box.
|
|
108
76
|
*/
|
|
109
77
|
export function outsideExpectedCountry(countryCode, lat, lon, bboxes) {
|
|
110
78
|
const cc = countryCode.toUpperCase();
|
|
@@ -120,11 +88,10 @@ export function outsideExpectedCountry(countryCode, lat, lon, bboxes) {
|
|
|
120
88
|
return lat < b[0] || lat > b[1] || lon < b[2] || lon > b[3];
|
|
121
89
|
}
|
|
122
90
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* to serve.
|
|
91
|
+
* Decides whether a resolved tree's coordinate is implausible: a bare country centroid,
|
|
92
|
+
* or a point outside `expectedCountry`'s bounding box.
|
|
93
|
+
*
|
|
94
|
+
* An unresolved tree is plausible because it serves no coordinate.
|
|
128
95
|
*/
|
|
129
96
|
export function isImplausibleResolution(tree, opts = {}) {
|
|
130
97
|
const coordinate = finestResolvedCoordinate(tree);
|
package/out/plausibility.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plausibility.js","sourceRoot":"","sources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,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;AAC5D,CAAC;AAwCD;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAiB,EAAE,IAAI,GAAqB,EAAE;IACrF,MAAM,UAAU,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAA;IAEjD,IAAI,UAAU,IAAI,UAAU,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QAChD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAA;IACrE,CAAC;IAED,IACC,UAAU;QACV,IAAI,CAAC,eAAe;QACpB,sBAAsB,CAAC,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,CAAC,EAC/F,CAAC;QACF,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,0BAA0B,EAAE,UAAU,EAAE,CAAA;IAC7E,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,IAAI,SAAS,EAAE,CAAA;AACnE,CAAC"}
|
|
@@ -2,124 +2,24 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Postcode-country coherence (#42) — the joint-consistency resolve keyed on the (postcode, locality)
|
|
7
|
-
* PAIR, and the first mechanism in the tree allowed to override `defaultCountry`.
|
|
8
|
-
*
|
|
9
|
-
* The failing case: `12 Rue de Rivoli, 75001 Paris` under the en-US locale. `--locale` defaults to
|
|
10
|
-
* `en-US`, `localeToCountry` turns that into `ResolveOpts.defaultCountry = "US"`, and the backend
|
|
11
|
-
* turns THAT into a hard `spr.country = 'US'` WHERE clause. The candidate pool is all-US before
|
|
12
|
-
* ranking begins, so a coarse placer that already called this address FR at confidence
|
|
13
|
-
* 0.9999908844 has nothing to promote — a soft re-rank downstream of a hard filter is inert by
|
|
14
|
-
* construction. Population then picks Paris, Texas (pop 24,969). With the postal extracts attached
|
|
15
|
-
* the answer gets WORSE, not merely wrong: the postcode resolves to the US row (ZIP 75001,
|
|
16
|
-
* Addison TX), `applyPostcodeConsistency` finds no Paris within its 50 km check (the nearest is
|
|
17
|
-
* 143.8 km), and falls the locality coordinate back to the ZIP point. See
|
|
18
|
-
* `docs/records/evals/2026-08-03-postcode-locality-scoping.md` for the instrumented diagnosis.
|
|
19
|
-
*
|
|
20
|
-
* No pattern-only change can fix this. `75001` is NOT unambiguously French:
|
|
21
|
-
* `candidateSystemsForPostcode("75001")` returns `["us", "de", "fr"]`, and the 2026-08-04
|
|
22
|
-
* candidate gazetteer holds the literal string in FOUR countries — FR 48.863,2.336 (Paris 1er),
|
|
23
|
-
* US 32.960,-96.838 (Addison TX), DE 48.844,9.367, PL 54.190,16.188 (×2 rows). The SHAPE is
|
|
24
|
-
* ambiguous four ways. The GEOMETRY is not: Addison and Paris are ~8,000 km apart, and only one
|
|
25
|
-
* of the four has a same-named locality next to its 75001.
|
|
26
|
-
*
|
|
27
|
-
* So this pass asks the question the shape cannot answer — _in which country are this postcode and
|
|
28
|
-
* this locality geographically consistent?_ — over exactly the primitive the resolver already uses
|
|
29
|
-
* three times (`applyAdminCoherence` #263, `applyExplicitCountryCoherence` #822,
|
|
30
|
-
* `applyRegionCountryCoherence`), just keyed on the postcode instead of a region or country token.
|
|
31
|
-
*
|
|
32
|
-
* ## Why it runs BEFORE the walk, not after
|
|
33
|
-
*
|
|
34
|
-
* Its three siblings are post-walk re-picks: the walk resolves greedily, they swap the wrong node
|
|
35
|
-
* pair for the right one. That shape cannot work here, because the thing to correct is the walk's
|
|
36
|
-
* COUNTRY SCOPE, and the scope poisons three separate things a post-walk pass cannot reach — the
|
|
37
|
-
* postcode node's own resolution (Addison, not Paris 1er), the `applyPostcodeConsistency` fallback
|
|
38
|
-
* that then drags the locality onto it, and the `country` filter on every other admin lookup. So
|
|
39
|
-
* this pass is a pre-walk SCOPE decision: it runs once, before the first lookup, and replaces
|
|
40
|
-
* `state.defaultCountry` for the whole walk. Everything downstream — including the three post-walk
|
|
41
|
-
* coherence passes and the street/rooftop tiers — then sees the corrected country.
|
|
42
|
-
*
|
|
43
|
-
* ## Why it is not a hard veto (the doctrine check)
|
|
44
|
-
*
|
|
45
|
-
* Registries are SOFT priors here, positive evidence only. Two properties keep this one honest:
|
|
46
|
-
*
|
|
47
|
-
* 1. **The default country is tested FIRST, and a coherent default always wins.** If (postcode,
|
|
48
|
-
* locality) is consistent under `defaultCountry`, the pass returns `null` immediately, having
|
|
49
|
-
* spent at most two lookups, and the walk is byte-identical. Every correctly-scoped domestic
|
|
50
|
-
* parse exits here. It is not "US loses to FR"; it is "US had no answer".
|
|
51
|
-
* 2. **Abstention is the default outcome.** Zero coherent countries (a wrong-for-the-city
|
|
52
|
-
* postcode, or a recall gap in the gazetteer) and MORE than one coherent country (a genuine
|
|
53
|
-
* geographic tie) both return `null`. The mechanism only ever speaks when exactly one country
|
|
54
|
-
* makes the pair consistent, and only ever when the default country could not.
|
|
55
|
-
*
|
|
56
|
-
* ## What #24 changed (2026-08-10)
|
|
57
|
-
*
|
|
58
|
-
* Two structural gaps, both found by replaying the 420-row panel-v2 benchmark. The pass is default-ON,
|
|
59
|
-
* the eu-mixed block gave it 29 chances, and it fired **zero** times — while the right answer sat in
|
|
60
|
-
* the shipped gazetteer within 4 km of truth on 21 of them.
|
|
61
|
-
*
|
|
62
|
-
* 1. **The candidate countries came from a proxy.** `candidateSystemsForPostcode` is a shape test over
|
|
63
|
-
* the eight slices codex specifies (`us de fr ca gb jp au nz`), so CZ, CH, BE, DK, AT, NL and IT
|
|
64
|
-
* could never be PROPOSED, however good the evidence. `13000` shapes as `[us, de, fr]`; the
|
|
65
|
-
* gazetteer holds it in exactly one country, and that country is CZ. The candidate set now unions
|
|
66
|
-
* the shape list with the countries the gazetteer actually holds the postcode in — one unscoped
|
|
67
|
-
* lookup, exhaustive at the measured cardinality (the most-shared code in the artifact carries 12
|
|
68
|
-
* rows across 8 countries). Every candidate still has to pass the same geometric pair test, so the
|
|
69
|
-
* widening can only convert an abstention into a verdict or a verdict into an abstention, never a
|
|
70
|
-
* verdict into a different one.
|
|
71
|
-
* 2. **The pair was all-or-nothing.** Ten panel rows had unimpeachable one-sided evidence and no pair:
|
|
72
|
-
* the gazetteer carries no CH or BE postcodes at all (so `Sarnen` and `Kelmis` could never agree
|
|
73
|
-
* with anything), and `Praha 3` / `Praha 9` are municipal districts no admin gazetteer names (so
|
|
74
|
-
* `13000` had nothing to agree WITH). Each half may now speak alone — but only when the DEFAULT
|
|
75
|
-
* country corroborates NEITHER half, and only when the speaking half names exactly one country in
|
|
76
|
-
* the whole gazetteer. See {@link PostcodeCountryScopeEvidence}.
|
|
77
|
-
*
|
|
78
|
-
* The abstention doctrine is unchanged and is what bounds the new rungs: a two-country tie is a HARD
|
|
79
|
-
* abstention that never falls through to the single-sided rungs. Corroboration at home bounds them
|
|
80
|
-
* asymmetrically: the address's own POSTCODE existing in the default country stops the pass dead,
|
|
81
|
-
* while a LOCALITY value at home neutralizes that value as a foreign witness without silencing its
|
|
82
|
-
* siblings (the per-value rule in the single-sided section below).
|
|
83
|
-
*
|
|
84
|
-
* ## Evidence
|
|
85
|
-
*
|
|
86
|
-
* Prototyped out-of-tree against the live gazetteer over the public `findPlace` surface (2026-08-03):
|
|
87
|
-
* 400 real US (ZIP, city) pairs from `postalcode-us.db` + 400 real FR (CP, commune) pairs from
|
|
88
|
-
* `postcode-locality-fr.db` — 800 pairs, **zero** border crossings, at both the 15 km and 25 km
|
|
89
|
-
* checks. The 22 US abstentions were pairs whose ZIP parent name is not an exact-matching locality
|
|
90
|
-
* in the admin gazetteer (a recall gap; abstention is the safe outcome). The confound board's
|
|
91
|
-
* verdicts were identical at 15, 25 AND 50 km, so the mechanism is not check-tuned; the default
|
|
92
|
-
* below is the 25 km the scale run measured.
|
|
93
|
-
*
|
|
94
|
-
* Cost: 2 lookups on the byte-stable path (postcode + locality under the default country), and at
|
|
95
|
-
* most `2 × |candidateSystems| × |localityValues|` — candidates bounded at 12, locality values at 3,
|
|
96
|
-
* and the common tree carries exactly one — when the default is incoherent. Nothing runs at all
|
|
97
|
-
* unless the tree carries both a postcode and a locality.
|
|
98
|
-
*
|
|
99
|
-
* **Default-ON** since the operator promotion of 2026-08-05 (#1477) — the resolver gauntlet, pinned
|
|
100
|
-
* both ways, returned zero newly-failing conditional cases, and 56,000 pair evaluations across both
|
|
101
|
-
* backends returned zero false positives. `ResolveOpts.postcodeCountryCoherence: false` opts out,
|
|
102
|
-
* and the walk is byte-stable then. Receipts:
|
|
103
|
-
* `docs/records/evals/2026-08-05-postcode-coherence-default-on-evidence.md`.
|
|
104
5
|
*/
|
|
105
6
|
import { type AddressNode } from "@mailwoman/core/decoder";
|
|
106
7
|
import type { ResolvedPlace, ResolverBackend } from "@mailwoman/core/resolver";
|
|
107
8
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
9
|
+
* The default maximum distance, in kilometers, between a postcode and a locality
|
|
10
|
+
* for them to count as consistent.
|
|
11
|
+
*
|
|
12
|
+
* Verdicts did not change anywhere between 15 and 50 km, so the exact value matters little.
|
|
110
13
|
*/
|
|
111
14
|
export declare const POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM = 25;
|
|
112
15
|
/**
|
|
113
|
-
*
|
|
114
|
-
* tell a two-sided agreement from a one-sided uniqueness claim without re-deriving it.
|
|
16
|
+
* The part of the address that justified a country-scope verdict.
|
|
115
17
|
*
|
|
116
|
-
* - `pair
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* - `postcode` — the postcode is held in exactly one country and the locality is in no gazetteer at all. The `Praha 3`
|
|
122
|
-
* class: a municipal district nobody's admin gazetteer names.
|
|
18
|
+
* - `pair`: the postcode and the locality both resolve in the country, within the threshold distance.
|
|
19
|
+
* - `locality`: the locality exists in exactly one country.
|
|
20
|
+
* The postcode copy in that country does not contradict it.
|
|
21
|
+
* - `postcode`: the postcode exists in exactly one country.
|
|
22
|
+
* No gazetteer knows the locality.
|
|
123
23
|
*/
|
|
124
24
|
export type PostcodeCountryScopeEvidence = "pair" | "locality" | "postcode";
|
|
125
25
|
/**
|
|
@@ -127,106 +27,92 @@ export type PostcodeCountryScopeEvidence = "pair" | "locality" | "postcode";
|
|
|
127
27
|
*/
|
|
128
28
|
export interface PostcodeCountryScope {
|
|
129
29
|
/**
|
|
130
|
-
* ISO-
|
|
30
|
+
* The upper-case ISO 3166-1 alpha-2 country code.
|
|
131
31
|
*/
|
|
132
32
|
country: string;
|
|
133
33
|
/**
|
|
134
|
-
* The postcode
|
|
34
|
+
* The postcode the verdict used.
|
|
135
35
|
*/
|
|
136
36
|
postcode: string;
|
|
137
37
|
/**
|
|
138
|
-
* The locality
|
|
38
|
+
* The locality the verdict used.
|
|
139
39
|
*/
|
|
140
40
|
locality: string;
|
|
141
41
|
/**
|
|
142
|
-
*
|
|
42
|
+
* The evidence that supported the verdict.
|
|
143
43
|
*/
|
|
144
44
|
evidence: PostcodeCountryScopeEvidence;
|
|
145
45
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
46
|
+
* The distance in kilometers between the postcode point and the nearest locality with the same name.
|
|
47
|
+
*
|
|
48
|
+
* It is set only for `pair` evidence, because the other verdicts compare no second point.
|
|
149
49
|
*/
|
|
150
50
|
distanceKm?: number;
|
|
151
51
|
/**
|
|
152
|
-
* The postcode place
|
|
52
|
+
* The postcode place behind the verdict.
|
|
53
|
+
* It is absent for `locality` evidence.
|
|
153
54
|
*/
|
|
154
55
|
postcodePlace?: ResolvedPlace;
|
|
155
56
|
/**
|
|
156
|
-
* The locality place
|
|
57
|
+
* The locality place behind the verdict.
|
|
58
|
+
* It is absent for `postcode` evidence.
|
|
157
59
|
*/
|
|
158
60
|
localityPlace?: ResolvedPlace;
|
|
159
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Options for {@linkcode findPostcodeCountryScope}.
|
|
64
|
+
*/
|
|
160
65
|
export interface PostcodeCountryScopeOpts {
|
|
161
66
|
/**
|
|
162
|
-
* The postcode
|
|
163
|
-
*
|
|
67
|
+
* The address's postcode.
|
|
68
|
+
*
|
|
69
|
+
* Callers should pass the value from the resolver's own pre-scan, so that this pass
|
|
70
|
+
* and the walk use the same postcode.
|
|
164
71
|
*/
|
|
165
72
|
postcode: string;
|
|
166
73
|
/**
|
|
167
|
-
* The
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
74
|
+
* The caller's default country filter, or `undefined` when no default applies.
|
|
75
|
+
*
|
|
76
|
+
* Without a default, only the `pair` test runs.
|
|
77
|
+
* The pass returns a scope when exactly one country qualifies.
|
|
171
78
|
*/
|
|
172
79
|
defaultCountry: string | undefined;
|
|
173
80
|
/**
|
|
174
|
-
*
|
|
81
|
+
* The consistency radius in kilometers.
|
|
82
|
+
*
|
|
83
|
+
* It defaults to {@link POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM}.
|
|
175
84
|
*/
|
|
176
85
|
thresholdKm?: number;
|
|
177
86
|
/**
|
|
178
|
-
*
|
|
179
|
-
* CONFIRMED postcode span (see `resolver/postcode-shape-coherence.ts`, #31 Mechanism 1). When present it REPLACES
|
|
180
|
-
* `candidateSystemsForPostcode`'s own list; it is a pure subset of that list (codex systems ∩ confident sibling
|
|
181
|
-
* systems). Upper-case ISO-3166 alpha-2, e.g. `["US"]` for a 5-digit code whose siblings all say US.
|
|
87
|
+
* Upper-case ISO 3166-1 alpha-2 codes that replace the countries inferred from the postcode's shape.
|
|
182
88
|
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
* class of evidence the pair test itself runs on. Every candidate from either half still has to pass that test.
|
|
89
|
+
* The pass still adds countries whose gazetteer holds the postcode.
|
|
90
|
+
* Every candidate must pass the pair test.
|
|
186
91
|
*/
|
|
187
92
|
candidateSystems?: readonly string[];
|
|
188
93
|
}
|
|
189
94
|
/**
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* order.
|
|
193
|
-
*
|
|
194
|
-
* Document order is required, not cosmetic. The original stack-pop traversal visited the LAST node first, so on `92
|
|
195
|
-
* Laurell Road, Gander, NL A1V 0A9` — where the model tags both `Gander` and the province abbreviation `NL` as
|
|
196
|
-
* localities — the pass keyed its whole country verdict on "NL", whose only exact locality-band bearer is an alias of
|
|
197
|
-
* Nal, Afghanistan, and the walk resolved a Newfoundland street 10,000 km away. The FIRST-written locality is the one
|
|
198
|
-
* the address is about.
|
|
95
|
+
* Returns up to three distinct locality values in document order, listing every
|
|
96
|
+
* `locality` before any `dependent_locality`.
|
|
199
97
|
*
|
|
200
|
-
*
|
|
201
|
-
* `Madrid` as localities; `Aravaca` is a neighbourhood the locality band cannot see, while `Madrid` carries the ES pair
|
|
202
|
-
* verdict (the ES 28023 row sits 9.6 km from the Madrid locality row). A pass keyed on a single value bets the whole
|
|
203
|
-
* country verdict on whichever one a traversal order happens to pick — first-only re-scoped that address to the US ZIP
|
|
204
|
-
* 28023 centroid in North Carolina. So the verdict rungs try each value in order until one produces evidence.
|
|
98
|
+
* Order matters because the first locality written is the one the address is about.
|
|
205
99
|
*/
|
|
206
100
|
export declare function localityValuesInDocumentOrder(roots: readonly AddressNode[]): string[];
|
|
207
101
|
/**
|
|
208
|
-
*
|
|
102
|
+
* Returns the first value of {@link localityValuesInDocumentOrder}.
|
|
209
103
|
*/
|
|
210
104
|
export declare function firstLocalityValue(roots: readonly AddressNode[]): string | undefined;
|
|
211
105
|
/**
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* Order matters and is the whole safety argument. The caller's `defaultCountry` is tested FIRST; a coherent default
|
|
215
|
-
* short-circuits with `null` (nothing to correct, ≤2 lookups spent, the walk unchanged). Only when the default cannot
|
|
216
|
-
* make the pair consistent are the codex shape's other candidate systems tried, and only a UNIQUE coherent alternative
|
|
217
|
-
* produces a verdict — zero (no evidence) and two-or-more (a genuine tie) both abstain.
|
|
106
|
+
* Finds the one country, other than the caller's default, in which the address's
|
|
107
|
+
* postcode and locality are consistent.
|
|
218
108
|
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* below is the whole conversion. Note the corollary: a country with no codex slice can never be proposed (the gazetteer
|
|
222
|
-
* holds `75001` in PL, and this pass will never return PL), which bounds the mechanism to the systems whose postcode
|
|
223
|
-
* shapes are actually specified.
|
|
109
|
+
* It returns `null` when the address has a country node, when the default country is
|
|
110
|
+
* already consistent, or when more than one alternative qualifies.
|
|
224
111
|
*/
|
|
225
112
|
export declare function findPostcodeCountryScope(roots: readonly AddressNode[], backend: ResolverBackend, opts: PostcodeCountryScopeOpts): Promise<PostcodeCountryScope | null>;
|
|
226
113
|
/**
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* untouched, this only writes `metadata`.
|
|
114
|
+
* Records an adopted country scope and its evidence in the `metadata` of the
|
|
115
|
+
* tree's postcode and locality nodes.
|
|
230
116
|
*/
|
|
231
117
|
export declare function stampPostcodeCountryScope(roots: readonly AddressNode[], scope: PostcodeCountryScope): void;
|
|
232
118
|
//# sourceMappingURL=country-coherence.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"country-coherence.d.ts","sourceRoot":"","sources":["../../lib/postcode/country-coherence.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"country-coherence.d.ts","sourceRoot":"","sources":["../../lib/postcode/country-coherence.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrF,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAG9E;;;;;GAKG;AACH,eAAO,M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