@mailwoman/resolver 11.1.0 → 11.3.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 +1 -1
- package/lib/admin/coherence-passes.ts +1 -1
- package/lib/admin/county-designator.ts +91 -0
- package/lib/admin/former-division.ts +116 -0
- package/lib/bare-toponym-race.ts +1 -1
- package/lib/decorate-node.ts +103 -2
- package/lib/postcode/prefix.ts +7 -16
- package/lib/postcode/shape-coherence.ts +2 -2
- package/lib/remote-resolver.ts +1 -1
- package/lib/resolve/parent-place.ts +109 -0
- package/lib/resolve/passes.ts +68 -11
- package/lib/resolve/sibling-locality.ts +150 -0
- package/lib/resolve.ts +407 -78
- package/lib/scope-retrieval.ts +91 -0
- package/lib/span-rescore.ts +65 -14
- package/lib/toponym-prior.ts +57 -6
- package/out/admin/coherence-passes.js +1 -1
- package/out/admin/coherence-passes.js.map +1 -1
- package/out/admin/county-designator.d.ts +33 -0
- package/out/admin/county-designator.d.ts.map +1 -0
- package/out/admin/county-designator.js +65 -0
- package/out/admin/county-designator.js.map +1 -0
- package/out/admin/former-division.d.ts +47 -0
- package/out/admin/former-division.d.ts.map +1 -0
- package/out/admin/former-division.js +74 -0
- package/out/admin/former-division.js.map +1 -0
- package/out/bare-toponym-race.d.ts +1 -1
- package/out/bare-toponym-race.d.ts.map +1 -1
- package/out/decorate-node.d.ts +22 -3
- package/out/decorate-node.d.ts.map +1 -1
- package/out/decorate-node.js +85 -1
- package/out/decorate-node.js.map +1 -1
- package/out/postcode/prefix.d.ts +4 -2
- package/out/postcode/prefix.d.ts.map +1 -1
- package/out/postcode/prefix.js +7 -13
- package/out/postcode/prefix.js.map +1 -1
- package/out/postcode/shape-coherence.js +2 -2
- package/out/postcode/shape-coherence.js.map +1 -1
- package/out/remote-resolver.d.ts.map +1 -1
- package/out/remote-resolver.js +1 -1
- package/out/remote-resolver.js.map +1 -1
- package/out/resolve/parent-place.d.ts +34 -0
- package/out/resolve/parent-place.d.ts.map +1 -0
- package/out/resolve/parent-place.js +76 -0
- package/out/resolve/parent-place.js.map +1 -0
- package/out/resolve/passes.d.ts +44 -8
- package/out/resolve/passes.d.ts.map +1 -1
- package/out/resolve/passes.js +17 -6
- package/out/resolve/passes.js.map +1 -1
- package/out/resolve/sibling-locality.d.ts +34 -0
- package/out/resolve/sibling-locality.d.ts.map +1 -0
- package/out/resolve/sibling-locality.js +95 -0
- package/out/resolve/sibling-locality.js.map +1 -0
- package/out/resolve.d.ts.map +1 -1
- package/out/resolve.js +273 -69
- package/out/resolve.js.map +1 -1
- package/out/scope-retrieval.d.ts +44 -0
- package/out/scope-retrieval.d.ts.map +1 -0
- package/out/scope-retrieval.js +52 -0
- package/out/scope-retrieval.js.map +1 -0
- package/out/span-rescore.d.ts +15 -1
- package/out/span-rescore.d.ts.map +1 -1
- package/out/span-rescore.js +36 -9
- package/out/span-rescore.js.map +1 -1
- package/out/toponym-prior.d.ts +15 -0
- package/out/toponym-prior.d.ts.map +1 -1
- package/out/toponym-prior.js +37 -6
- package/out/toponym-prior.js.map +1 -1
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bare-toponym-race.d.ts","sourceRoot":"","sources":["../lib/bare-toponym-race.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"bare-toponym-race.d.ts","sourceRoot":"","sources":["../lib/bare-toponym-race.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAA;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAEvE,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAG9E;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,GAAG,WA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AAA;IAC1C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,GAAG,IAAI,CAAC,CAsBR"}
|
package/out/decorate-node.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* in its own module so the coherence passes do not import the walk.
|
|
4
4
|
*/
|
|
5
5
|
import type { AddressNode } from "@mailwoman/core/decoder";
|
|
6
|
-
import type
|
|
6
|
+
import { type ResolvedPlace } from "@mailwoman/core/resolver";
|
|
7
7
|
import type { CoordinateOptionalPlace } from "#postcode/prefix";
|
|
8
8
|
/**
|
|
9
9
|
* A resolved node has a real coordinate (placeID set + non-zero lat/lon).
|
|
@@ -16,7 +16,22 @@ export declare function isResolvedWithCoord(n: AddressNode): boolean;
|
|
|
16
16
|
* Each value is true of one place only.
|
|
17
17
|
* A pass that replaces the place removes them, because the new place may supply none of them.
|
|
18
18
|
*/
|
|
19
|
-
export declare const PICK_METADATA_KEYS: readonly ["resolver_score", "resolver_name", "resolver_prominence", "resolver_country", "resolver_referential", "resolver_encyclopedic", "resolver_importance", "resolver_matched_alias", "resolver_bbox", "postcode_city_mismatch", "resolution_quality", "ancestors", "contained_by_parent", "admin_containment", "parent_fallback", "variant_alias_exemption"];
|
|
19
|
+
export declare const PICK_METADATA_KEYS: readonly ["resolver_score", "resolver_score_unmeasured", "resolver_name", "resolver_prominence", "resolver_country", "resolver_referential", "resolver_encyclopedic", "resolver_importance", "resolver_matched_alias", "resolver_bbox", "postcode_city_mismatch", "resolution_quality", "ancestors", "contained_by_parent", "admin_containment", "parent_fallback", "variant_alias_exemption", "county_designator_fallback", "sibling_locality_containment"];
|
|
20
|
+
/**
|
|
21
|
+
* The most places {@linkcode decorateNode} keeps on a node's `considered` list.
|
|
22
|
+
*
|
|
23
|
+
* A default lookup retrieves 5 rows and the bare-toponym race adds 2, so 10 holds one
|
|
24
|
+
* re-pick's displaced place and runner-ups beside the probe losers.
|
|
25
|
+
* Passes that re-pick the same node repeatedly drop the oldest entries first.
|
|
26
|
+
*/
|
|
27
|
+
export declare const CONSIDERED_LIMIT = 10;
|
|
28
|
+
/**
|
|
29
|
+
* The place a resolver-decorated node holds, read back from its decoration, or null
|
|
30
|
+
* when the node holds no located place with an identifier.
|
|
31
|
+
*
|
|
32
|
+
* `sourceID` is `<placetype>:<id>` as {@linkcode decorateNode} writes it.
|
|
33
|
+
*/
|
|
34
|
+
export declare function placeOfNode(node: AddressNode): ResolvedPlace | null;
|
|
20
35
|
/**
|
|
21
36
|
* Stamp a node with resolver-supplied attribution, displacing any prior classifier `source`
|
|
22
37
|
* / `sourceID` into `metadata.classifier_source` / `metadata.classifier_source_id`
|
|
@@ -25,6 +40,10 @@ export declare const PICK_METADATA_KEYS: readonly ["resolver_score", "resolver_n
|
|
|
25
40
|
* A node the resolver already decorated keeps its classifier stamps as the first decoration wrote them.
|
|
26
41
|
* When the new place differs from the one the node holds, the {@linkcode PICK_METADATA_KEYS}
|
|
27
42
|
* and `alternatives` of the previous place are removed before the new place is written.
|
|
43
|
+
*
|
|
44
|
+
* The previous place and its alternatives move to `considered`, with the `considered`
|
|
45
|
+
* places the caller passes, so the geocode result still reports them.
|
|
46
|
+
* No ranking stage reads `considered`, so moving a place there changes no answer.
|
|
28
47
|
*/
|
|
29
|
-
export declare function decorateNode(node: AddressNode, resolved: CoordinateOptionalPlace, alternatives: ResolvedPlace[]): void;
|
|
48
|
+
export declare function decorateNode(node: AddressNode, resolved: CoordinateOptionalPlace, alternatives: ResolvedPlace[], considered?: readonly ResolvedPlace[]): void;
|
|
30
49
|
//# sourceMappingURL=decorate-node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorate-node.d.ts","sourceRoot":"","sources":["../lib/decorate-node.ts"],"names":[],"mappings":"AAGA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"decorate-node.d.ts","sourceRoot":"","sources":["../lib/decorate-node.ts"],"names":[],"mappings":"AAGA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAsB,KAAK,aAAa,EAAyB,MAAM,0BAA0B,CAAA;AAGxG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAO/D;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,WAAW,GAAG,OAAO,CAO3D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,YAC9B,gBAAgB,EAChB,2BAA2B,EAC3B,eAAe,EACf,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,wBAAwB,EACxB,eAAe,EACf,wBAAwB,EACxB,oBAAoB,EACpB,WAAW,EACX,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,4BAA4B,EAC5B,8BAA8B,CACrB,CAAA;AAEV;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,KAAK,CAAA;AAElC;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,aAAa,GAAG,IAAI,CA+BnE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC3B,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,uBAAuB,EACjC,YAAY,EAAE,aAAa,EAAE,EAC7B,UAAU,GAAE,SAAS,aAAa,EAAO,GACvC,IAAI,CAoHN"}
|
package/out/decorate-node.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
import { EMPTY_PLACE_FIELDS, ScoreUnmeasuredReason } from "@mailwoman/core/resolver";
|
|
4
|
+
import { isPresent } from "@mailwoman/core/values/objects";
|
|
3
5
|
/**
|
|
4
6
|
* The widest stored extent, in degrees, that's a single point: about 10 meters, narrower than any place.
|
|
5
7
|
*/
|
|
@@ -22,6 +24,7 @@ export function isResolvedWithCoord(n) {
|
|
|
22
24
|
*/
|
|
23
25
|
export const PICK_METADATA_KEYS = [
|
|
24
26
|
"resolver_score",
|
|
27
|
+
"resolver_score_unmeasured",
|
|
25
28
|
"resolver_name",
|
|
26
29
|
"resolver_prominence",
|
|
27
30
|
"resolver_country",
|
|
@@ -37,7 +40,52 @@ export const PICK_METADATA_KEYS = [
|
|
|
37
40
|
"admin_containment",
|
|
38
41
|
"parent_fallback",
|
|
39
42
|
"variant_alias_exemption",
|
|
43
|
+
"county_designator_fallback",
|
|
44
|
+
"sibling_locality_containment",
|
|
40
45
|
];
|
|
46
|
+
/**
|
|
47
|
+
* The most places {@linkcode decorateNode} keeps on a node's `considered` list.
|
|
48
|
+
*
|
|
49
|
+
* A default lookup retrieves 5 rows and the bare-toponym race adds 2, so 10 holds one
|
|
50
|
+
* re-pick's displaced place and runner-ups beside the probe losers.
|
|
51
|
+
* Passes that re-pick the same node repeatedly drop the oldest entries first.
|
|
52
|
+
*/
|
|
53
|
+
export const CONSIDERED_LIMIT = 10;
|
|
54
|
+
/**
|
|
55
|
+
* The place a resolver-decorated node holds, read back from its decoration, or null
|
|
56
|
+
* when the node holds no located place with an identifier.
|
|
57
|
+
*
|
|
58
|
+
* `sourceID` is `<placetype>:<id>` as {@linkcode decorateNode} writes it.
|
|
59
|
+
*/
|
|
60
|
+
export function placeOfNode(node) {
|
|
61
|
+
if (node.source !== "resolver" || !node.sourceID || !isResolvedWithCoord(node))
|
|
62
|
+
return null;
|
|
63
|
+
const separator = node.sourceID.indexOf(":");
|
|
64
|
+
const rawID = node.sourceID.slice(separator + 1);
|
|
65
|
+
if (separator < 1 || !rawID || rawID === "0")
|
|
66
|
+
return null;
|
|
67
|
+
const meta = node.metadata ?? {};
|
|
68
|
+
const number = (key) => (typeof meta[key] === "number" ? meta[key] : null);
|
|
69
|
+
const unmeasured = meta["resolver_score_unmeasured"];
|
|
70
|
+
return {
|
|
71
|
+
...EMPTY_PLACE_FIELDS,
|
|
72
|
+
id: /^\d+$/u.test(rawID) ? Number(rawID) : rawID,
|
|
73
|
+
name: typeof meta["resolver_name"] === "string" ? meta["resolver_name"] : node.value,
|
|
74
|
+
placetype: node.sourceID.slice(0, separator),
|
|
75
|
+
country: typeof meta["resolver_country"] === "string" ? meta["resolver_country"] : null,
|
|
76
|
+
lat: node.lat,
|
|
77
|
+
lon: node.lon,
|
|
78
|
+
score: number("resolver_score") ?? 0,
|
|
79
|
+
scoreUnmeasured: typeof unmeasured === "string"
|
|
80
|
+
? unmeasured
|
|
81
|
+
: number("resolver_score") == null
|
|
82
|
+
? ScoreUnmeasuredReason.Unrecorded
|
|
83
|
+
: null,
|
|
84
|
+
prominence: number("resolver_prominence"),
|
|
85
|
+
importance: number("resolver_importance"),
|
|
86
|
+
...(meta["resolver_matched_alias"] ? { matchedAlias: true } : {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
41
89
|
/**
|
|
42
90
|
* Stamp a node with resolver-supplied attribution, displacing any prior classifier `source`
|
|
43
91
|
* / `sourceID` into `metadata.classifier_source` / `metadata.classifier_source_id`
|
|
@@ -46,11 +94,17 @@ export const PICK_METADATA_KEYS = [
|
|
|
46
94
|
* A node the resolver already decorated keeps its classifier stamps as the first decoration wrote them.
|
|
47
95
|
* When the new place differs from the one the node holds, the {@linkcode PICK_METADATA_KEYS}
|
|
48
96
|
* and `alternatives` of the previous place are removed before the new place is written.
|
|
97
|
+
*
|
|
98
|
+
* The previous place and its alternatives move to `considered`, with the `considered`
|
|
99
|
+
* places the caller passes, so the geocode result still reports them.
|
|
100
|
+
* No ranking stage reads `considered`, so moving a place there changes no answer.
|
|
49
101
|
*/
|
|
50
|
-
export function decorateNode(node, resolved, alternatives) {
|
|
102
|
+
export function decorateNode(node, resolved, alternatives, considered = []) {
|
|
103
|
+
let displaced = [];
|
|
51
104
|
if (node.source === "resolver") {
|
|
52
105
|
// A pass can decorate a node again with the place it already holds, and that place's stamps stay true.
|
|
53
106
|
if (node.placeID !== `wof:${resolved.id}`) {
|
|
107
|
+
displaced = [placeOfNode(node), ...(node.alternatives ?? [])].filter(isPresent);
|
|
54
108
|
const meta = { ...node.metadata };
|
|
55
109
|
for (const key of PICK_METADATA_KEYS) {
|
|
56
110
|
// oxlint-disable-next-line typescript/no-dynamic-delete -- removing the listed keys from a copied plain record
|
|
@@ -90,6 +144,11 @@ export function decorateNode(node, resolved, alternatives) {
|
|
|
90
144
|
if (resolved.prominence != null) {
|
|
91
145
|
node.metadata["resolver_prominence"] = resolved.prominence;
|
|
92
146
|
}
|
|
147
|
+
// `resolver_score` keeps the ranking key the passes compare.
|
|
148
|
+
// This stamp records that the key is unmeasured.
|
|
149
|
+
if (resolved.scoreUnmeasured) {
|
|
150
|
+
node.metadata["resolver_score_unmeasured"] = resolved.scoreUnmeasured;
|
|
151
|
+
}
|
|
93
152
|
if (resolved.country) {
|
|
94
153
|
node.metadata["resolver_country"] = resolved.country;
|
|
95
154
|
}
|
|
@@ -127,5 +186,30 @@ export function decorateNode(node, resolved, alternatives) {
|
|
|
127
186
|
if (alternatives.length) {
|
|
128
187
|
node.alternatives = alternatives;
|
|
129
188
|
}
|
|
189
|
+
const kept = consideredPlaces([...considered, ...displaced, ...(node.considered ?? [])], resolved.id, alternatives);
|
|
190
|
+
if (kept.length) {
|
|
191
|
+
node.considered = kept;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
delete node.considered;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The places of `candidates` that aren't the node's pick or one of its alternatives,
|
|
199
|
+
* first occurrence of each identifier kept, at most {@linkcode CONSIDERED_LIMIT}.
|
|
200
|
+
*/
|
|
201
|
+
function consideredPlaces(candidates, pickID, alternatives) {
|
|
202
|
+
const seen = new Set([String(pickID), ...alternatives.map((a) => String(a.id))]);
|
|
203
|
+
const kept = [];
|
|
204
|
+
for (const candidate of candidates) {
|
|
205
|
+
const id = candidate?.id;
|
|
206
|
+
if (id == null || seen.has(String(id)))
|
|
207
|
+
continue;
|
|
208
|
+
seen.add(String(id));
|
|
209
|
+
kept.push(candidate);
|
|
210
|
+
if (kept.length === CONSIDERED_LIMIT)
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
return kept;
|
|
130
214
|
}
|
|
131
215
|
//# sourceMappingURL=decorate-node.js.map
|
package/out/decorate-node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorate-node.js","sourceRoot":"","sources":["../lib/decorate-node.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;
|
|
1
|
+
{"version":3,"file":"decorate-node.js","sourceRoot":"","sources":["../lib/decorate-node.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAQlE,OAAO,EAAE,kBAAkB,EAAsB,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AACxG,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAI1D;;GAEG;AACH,MAAM,oBAAoB,GAAG,MAAM,CAAA;AAEnC;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,CAAc;IACjD,OAAO,CACN,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ;QAC7B,OAAO,CAAC,CAAC,GAAG,KAAK,QAAQ;QACzB,OAAO,CAAC,CAAC,GAAG,KAAK,QAAQ;QACzB,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAC5B,CAAA;AACF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IACjC,gBAAgB;IAChB,2BAA2B;IAC3B,eAAe;IACf,qBAAqB;IACrB,kBAAkB;IAClB,sBAAsB;IACtB,uBAAuB;IACvB,qBAAqB;IACr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,UAAU,CAAA;IACvB,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CACxB,UAA8B,EAC9B,MAAuB,EACvB,YAAsC;IAEtC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAChF,MAAM,IAAI,GAAc,EAAE,CAAA;IAE1B,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,MAAM,EAAE,GAAI,SAA2C,EAAE,EAAE,CAAA;QAE3D,IAAI,EAAE,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAAE,SAAQ;QAEhD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;QACpB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAEpB,IAAI,IAAI,CAAC,MAAM,KAAK,gBAAgB;YAAE,MAAK;IAC5C,CAAC;IAED,OAAO,IAAI,CAAA;AACZ,CAAC"}
|
package/out/postcode/prefix.d.ts
CHANGED
|
@@ -11,8 +11,10 @@ export type CoordinateOptionalPlace = Omit<ResolvedPlace, "lat" | "lon"> & {
|
|
|
11
11
|
lon?: number;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
* Derives the key a postcode prefix index uses for `code
|
|
15
|
-
*
|
|
14
|
+
* Derives the key a postcode prefix index uses for `code`, at the prefix level
|
|
15
|
+
* the codex states for `country`.
|
|
16
|
+
*
|
|
17
|
+
* White space in the code is dropped first.
|
|
16
18
|
*
|
|
17
19
|
* @returns `null` for a country with no rule or a code too short to contain a prefix.
|
|
18
20
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefix.d.ts","sourceRoot":"","sources":["../../lib/postcode/prefix.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prefix.d.ts","sourceRoot":"","sources":["../../lib/postcode/prefix.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAE1G;;;;;;GAMG;AACH,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,aAAa,EAAE,KAAK,GAAG,KAAK,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEzG;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMlF;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACzC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;;;OAIG;IACH,IAAI,EAAE,kBAAkB,CAAA;CACxB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,uBAAuB,EAC9B,YAAY,CAAC,EAAE,MAAM,GACnB,yBAAyB,GAAG,IAAI,CAYlC;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAC1C,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,kBAAkB,EACxB,KAAK,EAAE,uBAAuB,GAC5B,uBAAuB,CAYzB"}
|
package/out/postcode/prefix.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
import { postcodePrefixAt, postcodePrefixLevel } from "@mailwoman/codex/labels/postcode/prefix";
|
|
3
4
|
import { EMPTY_PLACE_FIELDS } from "@mailwoman/core/resolver";
|
|
4
|
-
const MIN_GB_OUTWARD_CODE_LENGTH = 5;
|
|
5
|
-
const MIN_US_SECTION_CODE_LENGTH = 3;
|
|
6
5
|
/**
|
|
7
|
-
* Derives the key a postcode prefix index uses for `code
|
|
8
|
-
*
|
|
6
|
+
* Derives the key a postcode prefix index uses for `code`, at the prefix level
|
|
7
|
+
* the codex states for `country`.
|
|
8
|
+
*
|
|
9
|
+
* White space in the code is dropped first.
|
|
9
10
|
*
|
|
10
11
|
* @returns `null` for a country with no rule or a code too short to contain a prefix.
|
|
11
12
|
*/
|
|
12
13
|
export function derivePostcodePrefix(code, country) {
|
|
13
14
|
if (!code || !country)
|
|
14
15
|
return null;
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
case "GB":
|
|
18
|
-
return compact.length >= MIN_GB_OUTWARD_CODE_LENGTH ? compact.slice(0, -3) : null;
|
|
19
|
-
case "US":
|
|
20
|
-
return compact.length >= MIN_US_SECTION_CODE_LENGTH ? compact.slice(0, 3) : null;
|
|
21
|
-
default:
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
16
|
+
const level = postcodePrefixLevel(country);
|
|
17
|
+
return level ? postcodePrefixAt(code.replaceAll(/\s+/g, ""), level) : null;
|
|
24
18
|
}
|
|
25
19
|
/**
|
|
26
20
|
* Looks up `code`'s prefix in the index, returning `null` when the query's country
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefix.js","sourceRoot":"","sources":["../../lib/postcode/prefix.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"prefix.js","sourceRoot":"","sources":["../../lib/postcode/prefix.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAA;AAC/F,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAY7D;;;;;;;GAOG;AAC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G,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjF,KAAK,EAAE,CAAC;QACR,UAAU,EAAE,KAAK;KACjB,CAAA;AACF,CAAC"}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
3
|
import { matchCountry, matchSubdivision, matchSubdivisionsAnywhere } from "@mailwoman/codex/country";
|
|
4
4
|
import { collectNodes, POSTCODE_SHAPE_EXCLUDED_KEY, walkNodes } from "@mailwoman/core/decoder";
|
|
5
|
-
import { acceptPostcode,
|
|
5
|
+
import { acceptPostcode, statesPostcodeSyntax } from "@mailwoman/postcode/country-formats";
|
|
6
6
|
/**
|
|
7
7
|
* Whether libaddressinput states a postcode syntax for `country`, so a span can be checked against it.
|
|
8
8
|
*/
|
|
9
9
|
function statesSyntax(country) {
|
|
10
|
-
return
|
|
10
|
+
return statesPostcodeSyntax(country);
|
|
11
11
|
}
|
|
12
12
|
function collectSiblingCountries(roots) {
|
|
13
13
|
const out = new Set();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape-coherence.js","sourceRoot":"","sources":["../../lib/postcode/shape-coherence.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAA;AACpG,OAAO,EAAE,YAAY,EAAE,2BAA2B,EAAE,SAAS,EAAoB,MAAM,yBAAyB,CAAA;AAChH,OAAO,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"shape-coherence.js","sourceRoot":"","sources":["../../lib/postcode/shape-coherence.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAA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AC,IAAI,CAAC,IAAI,CAAC,CAAA;YAE5B,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,wBAAwB,EAAE,YAAY,EAAE,CAAA;YAE5E,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;gBACxB,OAAO,CAAC,SAAS,GAAG,YAAY,CAAA;YACjC,CAAC;YAED,SAAQ;QACT,CAAC;QAED,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC;YAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAE3B,mFAAmF;YACnF,sFAAsF;YACtF,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,2BAA2B,CAAC,EAAE,IAAI,EAAE,CAAA;YAEzE,SAAQ;QACT,CAAC;QAED,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC;IAED,OAAO,OAAO,CAAA;AACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-resolver.d.ts","sourceRoot":"","sources":["../lib/remote-resolver.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"remote-resolver.d.ts","sourceRoot":"","sources":["../lib/remote-resolver.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,yBAAyB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAGhG;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,WAAW,EAAE,eAAe,GAAG,eAAe,CAAC,CAAA;AAE1F;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,uBAAuB,GAAG,IAA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FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
-
import { stringifyJSON } from "@mailwoman/core/json";
|
|
3
|
+
import { stringifyJSON } from "@mailwoman/core/values/json";
|
|
4
4
|
/**
|
|
5
5
|
* Strip the live lookup handles from `ResolveOpts` so the rest can be JSON-serialized over http.
|
|
6
6
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-resolver.js","sourceRoot":"","sources":["../lib/remote-resolver.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;
|
|
1
|
+
{"version":3,"file":"remote-resolver.js","sourceRoot":"","sources":["../lib/remote-resolver.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAIlE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAU3D;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAkB;IACzD,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAA;IACtB,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;IAChC,gBAAgB,GAAqC,IAAI,CAAA;IAElE,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,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAA;QAC5C,IAAI,CAAC,UAAU,GAAG,IAA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;gBAAS,CAAC;YACV,YAAY,CAAC,KAAK,CAAC,CAAA;QACpB,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The caller's parent place: reading it from the backend, and the lineage test a hard parent applies.
|
|
3
|
+
*/
|
|
4
|
+
import { type ParentPlaceScope, type ResolvedPlace, type ResolverBackend } from "@mailwoman/core/resolver";
|
|
5
|
+
import type { ResolutionState, ResolvedParentPlace } from "#resolve/passes";
|
|
6
|
+
/**
|
|
7
|
+
* Applies the country of the caller's parent place: a hard parent's as a caller default
|
|
8
|
+
* country, a soft parent's as the soft scope when no hard scope is set.
|
|
9
|
+
*
|
|
10
|
+
* It throws when a hard parent lies outside the caller's default country.
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyParentPlaceCountry(state: ResolutionState): void;
|
|
13
|
+
/**
|
|
14
|
+
* Passes the caller's parent place as the containment qualifier of a lookup the
|
|
15
|
+
* walk's own parent doesn't qualify, and reports whether it did.
|
|
16
|
+
*/
|
|
17
|
+
export declare function applyCallerParentQualifier(query: Parameters<ResolverBackend["findPlace"]>[0], state: Pick<ResolutionState, "parentPlace">): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Reads the parent place's record and its ancestors' ids.
|
|
20
|
+
*
|
|
21
|
+
* It throws when the backend can't look a place up by id or read lineage,
|
|
22
|
+
* when the gazetteer holds no place with the id, or when the place has no country,
|
|
23
|
+
* because a scope it can't apply would answer as if the caller had set none.
|
|
24
|
+
*/
|
|
25
|
+
export declare function readParentPlace(backend: ResolverBackend, scope: ParentPlaceScope): ResolvedParentPlace;
|
|
26
|
+
/**
|
|
27
|
+
* Whether a candidate agrees with the parent's lineage: it is the parent,
|
|
28
|
+
* lies inside it, or is one of its ancestors.
|
|
29
|
+
*
|
|
30
|
+
* When the lookup's containment qualifier was the parent, a candidate the backend
|
|
31
|
+
* marked contained needs no lineage read.
|
|
32
|
+
*/
|
|
33
|
+
export declare function agreesWithParent(candidate: Pick<ResolvedPlace, "id" | "containedByQualifier">, parent: ResolvedParentPlace, ancestors: NonNullable<ResolverBackend["ancestors"]>, qualifierIsParent: boolean): boolean;
|
|
34
|
+
//# sourceMappingURL=parent-place.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parent-place.d.ts","sourceRoot":"","sources":["../../lib/resolve/parent-place.ts"],"names":[],"mappings":"AAGA;;GAEG;AAEH,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,eAAe,EAEpB,MAAM,0BAA0B,CAAA;AAEjC,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAE3E;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAyBpE;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACzC,KAAK,EAAE,UAAU,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EAClD,KAAK,EAAE,IAAI,CAAC,eAAe,EAAE,aAAa,CAAC,GACzC,OAAO,CAMT;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,CActG;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC/B,SAAS,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,sBAAsB,CAAC,EAC7D,MAAM,EAAE,mBAAmB,EAC3B,SAAS,EAAE,WAAW,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,EACpD,iBAAiB,EAAE,OAAO,GACxB,OAAO,CAST"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
/**
|
|
4
|
+
* The caller's parent place: reading it from the backend, and the lineage test a hard parent applies.
|
|
5
|
+
*/
|
|
6
|
+
import { ScopeStrength, } from "@mailwoman/core/resolver";
|
|
7
|
+
/**
|
|
8
|
+
* Applies the country of the caller's parent place: a hard parent's as a caller default
|
|
9
|
+
* country, a soft parent's as the soft scope when no hard scope is set.
|
|
10
|
+
*
|
|
11
|
+
* It throws when a hard parent lies outside the caller's default country.
|
|
12
|
+
*/
|
|
13
|
+
export function applyParentPlaceCountry(state) {
|
|
14
|
+
const parent = state.parentPlace;
|
|
15
|
+
if (!parent)
|
|
16
|
+
return;
|
|
17
|
+
const country = parent.place.country.toUpperCase();
|
|
18
|
+
if (parent.scope.strength === ScopeStrength.Hard) {
|
|
19
|
+
const stated = state.defaultCountry;
|
|
20
|
+
if (stated?.source === "caller" && stated.country.toUpperCase() !== country) {
|
|
21
|
+
throw new Error(`parent place ${parent.scope.id} (${parent.place.name}) lies in ${country}, outside the default country ${stated.country}`);
|
|
22
|
+
}
|
|
23
|
+
state.defaultCountry = { country, source: parent.scope.source };
|
|
24
|
+
state.softCountry = null;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!state.defaultCountry) {
|
|
28
|
+
state.softCountry = { country, source: parent.scope.source, strength: ScopeStrength.Soft };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Passes the caller's parent place as the containment qualifier of a lookup the
|
|
33
|
+
* walk's own parent doesn't qualify, and reports whether it did.
|
|
34
|
+
*/
|
|
35
|
+
export function applyCallerParentQualifier(query, state) {
|
|
36
|
+
if (!state.parentPlace || query.parentQualifierID != null)
|
|
37
|
+
return false;
|
|
38
|
+
query.parentQualifierID = state.parentPlace.scope.id;
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Reads the parent place's record and its ancestors' ids.
|
|
43
|
+
*
|
|
44
|
+
* It throws when the backend can't look a place up by id or read lineage,
|
|
45
|
+
* when the gazetteer holds no place with the id, or when the place has no country,
|
|
46
|
+
* because a scope it can't apply would answer as if the caller had set none.
|
|
47
|
+
*/
|
|
48
|
+
export function readParentPlace(backend, scope) {
|
|
49
|
+
if (!backend.place || !backend.ancestors) {
|
|
50
|
+
throw new Error(`parent place ${scope.id}: the resolver backend can't look up a place by id and its lineage`);
|
|
51
|
+
}
|
|
52
|
+
const place = backend.place(scope.id);
|
|
53
|
+
if (!place)
|
|
54
|
+
throw new Error(`parent place ${scope.id}: the gazetteer holds no place with this id`);
|
|
55
|
+
if (!place.country)
|
|
56
|
+
throw new Error(`parent place ${scope.id} (${place.name}): the gazetteer records no country`);
|
|
57
|
+
const ancestorIDs = new Set(backend.ancestors(scope.id).map((ancestor) => Number(ancestor.id)));
|
|
58
|
+
return { scope, place, ancestorIDs };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Whether a candidate agrees with the parent's lineage: it is the parent,
|
|
62
|
+
* lies inside it, or is one of its ancestors.
|
|
63
|
+
*
|
|
64
|
+
* When the lookup's containment qualifier was the parent, a candidate the backend
|
|
65
|
+
* marked contained needs no lineage read.
|
|
66
|
+
*/
|
|
67
|
+
export function agreesWithParent(candidate, parent, ancestors, qualifierIsParent) {
|
|
68
|
+
const id = Number(candidate.id);
|
|
69
|
+
const parentID = parent.scope.id;
|
|
70
|
+
if (qualifierIsParent && candidate.containedByQualifier === true)
|
|
71
|
+
return true;
|
|
72
|
+
if (id === parentID || parent.ancestorIDs.has(id))
|
|
73
|
+
return true;
|
|
74
|
+
return ancestors(candidate.id).some((ancestor) => Number(ancestor.id) === parentID);
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=parent-place.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parent-place.js","sourceRoot":"","sources":["../../lib/resolve/parent-place.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;GAEG;AAEH,OAAO,EAIN,aAAa,GACb,MAAM,0BAA0B,CAAA;AAIjC;;;;;GA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CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;QAAE,OAAO,IAAI,CAAA;IAE9D,OAAO,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAA;AACpF,CAAC"}
|
package/out/resolve/passes.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { PlacetypeMap } from "@mailwoman/codex/placetype-map";
|
|
1
|
+
import type { PlacetypeMap } from "@mailwoman/codex/labels/placetype-map";
|
|
2
2
|
import { type AddressNode } from "@mailwoman/core/decoder";
|
|
3
|
-
import { type DefaultCountry, type ResolveNodeTrace, type PostcodePrefixIndexLike, type ResolvedPlace, type ResolveOpts, type ResolverBackend, type ResolveSwitches } from "@mailwoman/core/resolver";
|
|
3
|
+
import { type DefaultCountry, type FormerDivisionLookup, type FormerDivisionMatch, type ParentPlaceScope, type ResolveNodeTrace, type PostcodePrefixIndexLike, type ResolvedPlace, type ResolveOpts, type ResolverBackend, type ResolveSwitches } from "@mailwoman/core/resolver";
|
|
4
4
|
/**
|
|
5
5
|
* {@link ResolveOpts} with every {@link ResolveSwitches} key resolved against its default.
|
|
6
6
|
*/
|
|
@@ -43,6 +43,14 @@ export declare function createNodeTraceRecorder(sink: (record: ResolveNodeTrace)
|
|
|
43
43
|
/**
|
|
44
44
|
* The options and mutable state that one `resolveTree` call passes through its tree walk.
|
|
45
45
|
*/
|
|
46
|
+
/**
|
|
47
|
+
* A caller's parent place as the walk reads it: the scope, the place's record, and its ancestors' ids.
|
|
48
|
+
*/
|
|
49
|
+
export interface ResolvedParentPlace {
|
|
50
|
+
scope: ParentPlaceScope;
|
|
51
|
+
place: ResolvedPlace;
|
|
52
|
+
ancestorIDs: ReadonlySet<number>;
|
|
53
|
+
}
|
|
46
54
|
export interface ResolutionState {
|
|
47
55
|
lookupsRemaining: number;
|
|
48
56
|
placetypeMap: PlacetypeMap;
|
|
@@ -133,14 +141,25 @@ export interface ResolutionState {
|
|
|
133
141
|
*/
|
|
134
142
|
diagnoseUnreachable?: boolean;
|
|
135
143
|
/**
|
|
136
|
-
* The
|
|
137
|
-
*
|
|
144
|
+
* The soft country scope: a prior on region and locality candidates that applies
|
|
145
|
+
* while {@link ResolutionState.defaultCountry} is null and no anchor posterior applies.
|
|
146
|
+
*
|
|
147
|
+
* {@link ResolutionState.defaultCountry} holds only a hard scope.
|
|
148
|
+
*/
|
|
149
|
+
softCountry: DefaultCountry | null;
|
|
150
|
+
/**
|
|
151
|
+
* The weight of {@link ResolutionState.softCountry}, in log10-population units.
|
|
152
|
+
*/
|
|
153
|
+
softCountryWeight: number;
|
|
154
|
+
/**
|
|
155
|
+
* Whether a soft scope acts inside retrieval, and a hard default country
|
|
156
|
+
* probes for the places it excluded.
|
|
138
157
|
*/
|
|
139
|
-
|
|
158
|
+
scopeCountryRetrieval: boolean;
|
|
140
159
|
/**
|
|
141
|
-
* The
|
|
160
|
+
* The caller's parent place with its record and the ids of its ancestors, or null.
|
|
142
161
|
*/
|
|
143
|
-
|
|
162
|
+
parentPlace: ResolvedParentPlace | null;
|
|
144
163
|
/**
|
|
145
164
|
* Returns a candidate's capital level for bounded capital promotion.
|
|
146
165
|
* Capital promotion is off when it is absent.
|
|
@@ -169,6 +188,20 @@ export interface ResolutionState {
|
|
|
169
188
|
* qualifier and a contained pick is stamped to answer ahead of the locality.
|
|
170
189
|
*/
|
|
171
190
|
dependentLocalityContainment: boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Whether a `locality` node is looked up as its region's WOF `county` when no locality in
|
|
193
|
+
* the region matches it and its value is written with its country's county designator.
|
|
194
|
+
*/
|
|
195
|
+
countyDesignatorFallback: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* The former divisions a `subregion` or `region` value is checked against when no
|
|
198
|
+
* current division answers it, present only under the `formerDivisions` switch.
|
|
199
|
+
*/
|
|
200
|
+
formerDivisionLookup?: FormerDivisionLookup;
|
|
201
|
+
/**
|
|
202
|
+
* The walked nodes no current division answered, with the former divisions their values name.
|
|
203
|
+
*/
|
|
204
|
+
pendingFormerDivisions?: Map<AddressNode, readonly FormerDivisionMatch[]>;
|
|
172
205
|
/**
|
|
173
206
|
* The tree's first region value.
|
|
174
207
|
*
|
|
@@ -190,8 +223,11 @@ export declare function firstPostcodeValue(roots: readonly AddressNode[]): strin
|
|
|
190
223
|
* appending a resolved `locality` node on a hit.
|
|
191
224
|
*
|
|
192
225
|
* When no span matches, it tries the postcode node's code part.
|
|
226
|
+
*
|
|
227
|
+
* A hard default country filters the probes, and a bare whole-input span reads it as a prior.
|
|
228
|
+
* `softCountry` is a soft scope that acts inside retrieval: span probes read it only as a prior.
|
|
193
229
|
*/
|
|
194
|
-
export declare function applySpanRescore(roots: AddressNode[], raw: string, backend: ResolverBackend, opts: ResolvedOpts): Promise<void>;
|
|
230
|
+
export declare function applySpanRescore(roots: AddressNode[], raw: string, backend: ResolverBackend, opts: ResolvedOpts, softCountry?: string | null): Promise<void>;
|
|
195
231
|
/**
|
|
196
232
|
* Reconciles each resolved locality that lies farther than `thresholdKm` from the street's
|
|
197
233
|
* address-point coordinate, re-picking the nearest alternative within the threshold.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"passes.d.ts","sourceRoot":"","sources":["../../lib/resolve/passes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"passes.d.ts","sourceRoot":"","sources":["../../lib/resolve/passes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAA;AACzE,OAAO,EAAsC,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC9F,OAAO,EACN,KAAK,cAAc,EAEnB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EAExB,KAAK,gBAAgB,EAErB,KAAK,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