@mailwoman/resolver 11.4.0 → 12.0.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/lib/bare-toponym-race.ts +31 -0
- package/lib/decorate-node.ts +6 -0
- package/lib/outcome/fetch.ts +82 -0
- package/lib/outcome/ordering.ts +224 -0
- package/lib/outcome/span.ts +106 -0
- package/lib/outcome/walk.ts +132 -0
- package/lib/resolve/landmark.ts +57 -8
- package/lib/resolve/passes.ts +14 -0
- package/lib/resolve/priors.ts +123 -0
- package/lib/resolve/region-city.ts +53 -11
- package/lib/resolve.ts +152 -170
- package/out/bare-toponym-race.d.ts +8 -0
- package/out/bare-toponym-race.d.ts.map +1 -1
- package/out/bare-toponym-race.js +27 -0
- package/out/bare-toponym-race.js.map +1 -1
- package/out/decorate-node.d.ts +1 -1
- package/out/decorate-node.d.ts.map +1 -1
- package/out/decorate-node.js +5 -0
- package/out/decorate-node.js.map +1 -1
- package/out/outcome/fetch.d.ts +39 -0
- package/out/outcome/fetch.d.ts.map +1 -0
- package/out/outcome/fetch.js +59 -0
- package/out/outcome/fetch.js.map +1 -0
- package/out/outcome/ordering.d.ts +56 -0
- package/out/outcome/ordering.d.ts.map +1 -0
- package/out/outcome/ordering.js +152 -0
- package/out/outcome/ordering.js.map +1 -0
- package/out/outcome/span.d.ts +52 -0
- package/out/outcome/span.d.ts.map +1 -0
- package/out/outcome/span.js +66 -0
- package/out/outcome/span.js.map +1 -0
- package/out/outcome/walk.d.ts +42 -0
- package/out/outcome/walk.d.ts.map +1 -0
- package/out/outcome/walk.js +83 -0
- package/out/outcome/walk.js.map +1 -0
- package/out/resolve/landmark.d.ts +14 -2
- package/out/resolve/landmark.d.ts.map +1 -1
- package/out/resolve/landmark.js +47 -8
- package/out/resolve/landmark.js.map +1 -1
- package/out/resolve/passes.d.ts +13 -1
- package/out/resolve/passes.d.ts.map +1 -1
- package/out/resolve/passes.js.map +1 -1
- package/out/resolve/priors.d.ts +17 -0
- package/out/resolve/priors.d.ts.map +1 -0
- package/out/resolve/priors.js +79 -0
- package/out/resolve/priors.js.map +1 -0
- package/out/resolve/region-city.d.ts +7 -0
- package/out/resolve/region-city.d.ts.map +1 -1
- package/out/resolve/region-city.js +45 -10
- package/out/resolve/region-city.js.map +1 -1
- package/out/resolve.d.ts.map +1 -1
- package/out/resolve.js +113 -122
- package/out/resolve.js.map +1 -1
- package/package.json +10 -10
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The outcome request's two fetches of each data layer: the usual fetch with the filter as its
|
|
3
|
+
* predicate, and a second fetch of the rows that satisfy the hint, or the head's first reading.
|
|
4
|
+
*/
|
|
5
|
+
import type { LandmarkHit, LandmarkLookup } from "@mailwoman/core/resolver";
|
|
6
|
+
import { type OutcomeQuery, type ResolveOutcome } from "@mailwoman/core/resolver/outcome";
|
|
7
|
+
import type { OutcomeOrder } from "#outcome/ordering";
|
|
8
|
+
/**
|
|
9
|
+
* The node metadata key that marks the span outcome ordering applied to.
|
|
10
|
+
*/
|
|
11
|
+
export declare const OUTCOME_TARGET_KEY = "outcome_target";
|
|
12
|
+
/**
|
|
13
|
+
* The node metadata key that holds the resolved place's outcome set.
|
|
14
|
+
*/
|
|
15
|
+
export declare const OUTCOME_SET_KEY = "outcomes";
|
|
16
|
+
/**
|
|
17
|
+
* The query of the usual fetch: every row's set is read, and the filter admits rows.
|
|
18
|
+
*/
|
|
19
|
+
export declare function filterQuery(outcome: ResolveOutcome): OutcomeQuery;
|
|
20
|
+
/**
|
|
21
|
+
* The reading the second fetch reads: the hint, or the head's first reading without one.
|
|
22
|
+
*/
|
|
23
|
+
export declare function secondFetchReading(outcome: ResolveOutcome): string | null;
|
|
24
|
+
/**
|
|
25
|
+
* The query of the second fetch, or null without a hint or a head order.
|
|
26
|
+
*
|
|
27
|
+
* Its rows satisfy the reading and, under a filter, the filter too.
|
|
28
|
+
*/
|
|
29
|
+
export declare function secondFetchQuery(outcome: ResolveOutcome): OutcomeQuery | null;
|
|
30
|
+
/**
|
|
31
|
+
* The order the partition reads: the hint, or the head's order without one.
|
|
32
|
+
*/
|
|
33
|
+
export declare function outcomeOrderOf(outcome: ResolveOutcome): OutcomeOrder;
|
|
34
|
+
/**
|
|
35
|
+
* A landmark layer's hits for a name under the outcome request: the filtered read,
|
|
36
|
+
* then the rows of the second fetch it missed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function findWithOutcome(lookup: LandmarkLookup, name: string, outcome: ResolveOutcome): Promise<LandmarkHit[]>;
|
|
39
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../lib/outcome/fetch.ts"],"names":[],"mappings":"AAGA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAC3E,OAAO,EAAsB,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,kCAAkC,CAAA;AAE7G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD;;GAEG;AACH,eAAO,MAAM,kBAAkB,mBAAmB,CAAA;AAElD;;GAEG;AACH,eAAO,MAAM,eAAe,aAAa,CAAA;AAEzC;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,YAAY,CAKjE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,YAAY,GAAG,IAAI,CAS7E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,YAAY,CAEpE;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACpC,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,cAAc,GACrB,OAAO,CAAC,WAAW,EAAE,CAAC,CAUxB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
import { admittedOutcomeIDs } from "@mailwoman/core/resolver/outcome";
|
|
4
|
+
/**
|
|
5
|
+
* The node metadata key that marks the span outcome ordering applied to.
|
|
6
|
+
*/
|
|
7
|
+
export const OUTCOME_TARGET_KEY = "outcome_target";
|
|
8
|
+
/**
|
|
9
|
+
* The node metadata key that holds the resolved place's outcome set.
|
|
10
|
+
*/
|
|
11
|
+
export const OUTCOME_SET_KEY = "outcomes";
|
|
12
|
+
/**
|
|
13
|
+
* The query of the usual fetch: every row's set is read, and the filter admits rows.
|
|
14
|
+
*/
|
|
15
|
+
export function filterQuery(outcome) {
|
|
16
|
+
return {
|
|
17
|
+
vocabulary: outcome.vocabulary,
|
|
18
|
+
admit: outcome.filter ? admittedOutcomeIDs(outcome.filter, outcome.vocabulary) : null,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The reading the second fetch reads: the hint, or the head's first reading without one.
|
|
23
|
+
*/
|
|
24
|
+
export function secondFetchReading(outcome) {
|
|
25
|
+
return outcome.hint ?? outcome.headOrder?.[0] ?? null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The query of the second fetch, or null without a hint or a head order.
|
|
29
|
+
*
|
|
30
|
+
* Its rows satisfy the reading and, under a filter, the filter too.
|
|
31
|
+
*/
|
|
32
|
+
export function secondFetchQuery(outcome) {
|
|
33
|
+
const reading = secondFetchReading(outcome);
|
|
34
|
+
if (reading == null)
|
|
35
|
+
return null;
|
|
36
|
+
const filtered = filterQuery(outcome).admit;
|
|
37
|
+
const ids = admittedOutcomeIDs([reading], outcome.vocabulary);
|
|
38
|
+
return { vocabulary: outcome.vocabulary, admit: filtered ? ids.filter((id) => filtered.includes(id)) : ids };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The order the partition reads: the hint, or the head's order without one.
|
|
42
|
+
*/
|
|
43
|
+
export function outcomeOrderOf(outcome) {
|
|
44
|
+
return { hint: outcome.hint, headOrder: outcome.hint == null ? outcome.headOrder : null };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A landmark layer's hits for a name under the outcome request: the filtered read,
|
|
48
|
+
* then the rows of the second fetch it missed.
|
|
49
|
+
*/
|
|
50
|
+
export async function findWithOutcome(lookup, name, outcome) {
|
|
51
|
+
const read = (query) => Promise.resolve(lookup.find.call(lookup, name, query));
|
|
52
|
+
const first = await read(filterQuery(outcome));
|
|
53
|
+
const second = secondFetchQuery(outcome);
|
|
54
|
+
if (!second)
|
|
55
|
+
return first;
|
|
56
|
+
const seen = new Set(first.map((hit) => hit.qid));
|
|
57
|
+
return [...first, ...(await read(second)).filter((hit) => !seen.has(hit.qid))];
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../lib/outcome/fetch.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAQlE,OAAO,EAAE,kBAAkB,EAA0C,MAAM,kCAAkC,CAAA;AAI7G;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAA;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAA;AAEzC;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAAuB;IAClD,OAAO;QACN,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI;KACrF,CAAA;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KAAK,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAA;IAC9C,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAExC,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IAEzB,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IAEjD,OAAO,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAC/E,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The outcome partition, order 4 in the pass table of `docs/engineering/reference/outcome-kinds.mdx`,
|
|
3
|
+
* and the cross-layer merge it runs over.
|
|
4
|
+
*
|
|
5
|
+
* The partition moves candidates only inside one conformance class.
|
|
6
|
+
* Each class keeps the positions its members held, so a candidate the stated
|
|
7
|
+
* geography doesn't admit never moves ahead of one it does.
|
|
8
|
+
*/
|
|
9
|
+
import type { ResolvedPlace } from "@mailwoman/core/resolver";
|
|
10
|
+
/**
|
|
11
|
+
* What the partition orders by: the request's hint, or the head's readings when no hint is set.
|
|
12
|
+
*/
|
|
13
|
+
export interface OutcomeOrder {
|
|
14
|
+
hint: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* The head's identity top levels, most probable first.
|
|
17
|
+
* Read only without a hint.
|
|
18
|
+
*/
|
|
19
|
+
headOrder: readonly string[] | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The key two candidates share when they're in one conformance class: the `exactMatch` tier,
|
|
23
|
+
* whether the postcode's country posterior gives the candidate's country mass, and
|
|
24
|
+
* whether the stated country and locality admit a landmark or OpenStreetMap candidate.
|
|
25
|
+
*/
|
|
26
|
+
export declare function conformanceKey(candidate: ResolvedPlace, posterior: Readonly<Record<string, number>> | null | undefined): string;
|
|
27
|
+
/**
|
|
28
|
+
* Whether a place satisfies a requested outcome id.
|
|
29
|
+
* A place whose set wasn't read satisfies none.
|
|
30
|
+
*/
|
|
31
|
+
export declare function placeSatisfies(place: Pick<ResolvedPlace, "outcomes">, requested: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The outcome partition.
|
|
34
|
+
*
|
|
35
|
+
* Inside each conformance class, the candidates are grouped by {@link OutcomeOrder},
|
|
36
|
+
* and the class's members refill the positions the class held.
|
|
37
|
+
* Without a hint or a head order, the list returns unchanged.
|
|
38
|
+
*/
|
|
39
|
+
export declare function partitionByOutcome(ranked: readonly ResolvedPlace[], order: OutcomeOrder, posterior: Readonly<Record<string, number>> | null | undefined): ResolvedPlace[];
|
|
40
|
+
/**
|
|
41
|
+
* Orders the rows of one data layer, all in one conformance class, by {@link OutcomeOrder},
|
|
42
|
+
* keeping the layer's order inside each group.
|
|
43
|
+
*/
|
|
44
|
+
export declare function orderWithinLayerByOutcome<T extends Pick<ResolvedPlace, "outcomes">>(rows: readonly T[], order: OutcomeOrder): T[];
|
|
45
|
+
/**
|
|
46
|
+
* Merges candidates that share a Wikidata item into one, keeping the first one's place and position.
|
|
47
|
+
*
|
|
48
|
+
* The merged candidate's set is the union of both sets, each member with the sources of both.
|
|
49
|
+
* Two candidates without a shared item stay two.
|
|
50
|
+
*/
|
|
51
|
+
export declare function mergeByWikidata(candidates: readonly ResolvedPlace[]): ResolvedPlace[];
|
|
52
|
+
/**
|
|
53
|
+
* Merges two fetches of one data layer by place id, the first fetch's rows first.
|
|
54
|
+
*/
|
|
55
|
+
export declare function mergeFetches(first: readonly ResolvedPlace[], second: readonly ResolvedPlace[]): ResolvedPlace[];
|
|
56
|
+
//# sourceMappingURL=ordering.d.ts.map
|
|
@@ -0,0 +1 @@
|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,EAAE,CAI/G"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
import { OutcomeLayer, outcomeSatisfies, outcomesSatisfy, unionOutcomes } from "@mailwoman/core/resolver/outcome";
|
|
4
|
+
/**
|
|
5
|
+
* The order of the data layers when cross-layer prominence is missing.
|
|
6
|
+
*/
|
|
7
|
+
const LAYER_ORDER = [OutcomeLayer.Candidate, OutcomeLayer.Landmarks, OutcomeLayer.OpenStreetMap];
|
|
8
|
+
/**
|
|
9
|
+
* The key two candidates share when they're in one conformance class: the `exactMatch` tier,
|
|
10
|
+
* whether the postcode's country posterior gives the candidate's country mass, and
|
|
11
|
+
* whether the stated country and locality admit a landmark or OpenStreetMap candidate.
|
|
12
|
+
*/
|
|
13
|
+
export function conformanceKey(candidate, posterior) {
|
|
14
|
+
const exact = candidate.exactMatch === true ? "1" : "0";
|
|
15
|
+
const mass = posterior ? (candidate.country && (posterior[candidate.country] ?? 0) > 0 ? "1" : "0") : "-";
|
|
16
|
+
const admitted = candidate.contextAdmits === false ? "0" : "1";
|
|
17
|
+
return `${exact}${mass}${admitted}`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Whether a place satisfies a requested outcome id.
|
|
21
|
+
* A place whose set wasn't read satisfies none.
|
|
22
|
+
*/
|
|
23
|
+
export function placeSatisfies(place, requested) {
|
|
24
|
+
return outcomesSatisfy([requested], place.outcomes ?? []);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The group a candidate falls in: 0 before 1, and so on.
|
|
28
|
+
*
|
|
29
|
+
* With a hint, the satisfying candidates are group 0 and the rest group 1.
|
|
30
|
+
* With the head's order, a candidate's group is the best rank among its identity top levels,
|
|
31
|
+
* and a candidate with none of them follows every reading.
|
|
32
|
+
*/
|
|
33
|
+
function groupOf(candidate, order) {
|
|
34
|
+
if (order.hint != null)
|
|
35
|
+
return placeSatisfies(candidate, order.hint) ? 0 : 1;
|
|
36
|
+
const readings = order.headOrder ?? [];
|
|
37
|
+
const ranks = (candidate.outcomes ?? [])
|
|
38
|
+
.map((m) => readings.findIndex((reading) => outcomeSatisfies(reading, m.outcome)))
|
|
39
|
+
.filter((rank) => rank >= 0);
|
|
40
|
+
return ranks.length ? Math.min(...ranks) : readings.length;
|
|
41
|
+
}
|
|
42
|
+
function layerRank(candidate) {
|
|
43
|
+
const rank = LAYER_ORDER.indexOf(candidate.layer ?? OutcomeLayer.Candidate);
|
|
44
|
+
return rank === -1 ? LAYER_ORDER.length : rank;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Orders one group: each layer keeps its own order, and the layers interleave by the
|
|
48
|
+
* comparable prominence `s(e)` when every member has it, or follow the layer order otherwise.
|
|
49
|
+
*/
|
|
50
|
+
function orderGroup(members) {
|
|
51
|
+
if (!members.every((m) => typeof m.sitelinkProminence === "number")) {
|
|
52
|
+
return members.toSorted((a, b) => layerRank(a) - layerRank(b));
|
|
53
|
+
}
|
|
54
|
+
// A merge of the per-layer runs: the next member is the run head with the largest `s(e)`.
|
|
55
|
+
// Any candidate whose layer sits outside `LAYER_ORDER` joins a trailing run
|
|
56
|
+
// so `orderGroup` stays a permutation.
|
|
57
|
+
const knownLayers = new Set(LAYER_ORDER);
|
|
58
|
+
const runs = [
|
|
59
|
+
...LAYER_ORDER.map((layer) => members.filter((m) => (m.layer ?? OutcomeLayer.Candidate) === layer)),
|
|
60
|
+
members.filter((m) => !knownLayers.has(m.layer ?? OutcomeLayer.Candidate)),
|
|
61
|
+
];
|
|
62
|
+
const merged = [];
|
|
63
|
+
while (runs.some((run) => run.length)) {
|
|
64
|
+
let best = -1;
|
|
65
|
+
for (let i = 0; i < runs.length; i++) {
|
|
66
|
+
if (!runs[i].length)
|
|
67
|
+
continue;
|
|
68
|
+
if (best < 0 || runs[i][0].sitelinkProminence > runs[best][0].sitelinkProminence) {
|
|
69
|
+
best = i;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
merged.push(runs[best].shift());
|
|
73
|
+
}
|
|
74
|
+
return merged;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The outcome partition.
|
|
78
|
+
*
|
|
79
|
+
* Inside each conformance class, the candidates are grouped by {@link OutcomeOrder},
|
|
80
|
+
* and the class's members refill the positions the class held.
|
|
81
|
+
* Without a hint or a head order, the list returns unchanged.
|
|
82
|
+
*/
|
|
83
|
+
export function partitionByOutcome(ranked, order, posterior) {
|
|
84
|
+
if (order.hint == null && !order.headOrder?.length)
|
|
85
|
+
return [...ranked];
|
|
86
|
+
const classes = new Map();
|
|
87
|
+
ranked.forEach((candidate, index) => {
|
|
88
|
+
const key = conformanceKey(candidate, posterior);
|
|
89
|
+
const slots = classes.get(key) ?? [];
|
|
90
|
+
slots.push(index);
|
|
91
|
+
classes.set(key, slots);
|
|
92
|
+
});
|
|
93
|
+
const out = [...ranked];
|
|
94
|
+
for (const slots of classes.values()) {
|
|
95
|
+
const members = slots.map((i) => ranked[i]);
|
|
96
|
+
const groups = new Map();
|
|
97
|
+
for (const member of members) {
|
|
98
|
+
const group = groupOf(member, order);
|
|
99
|
+
groups.set(group, [...(groups.get(group) ?? []), member]);
|
|
100
|
+
}
|
|
101
|
+
const reordered = [...groups.entries()].toSorted(([a], [b]) => a - b).flatMap(([, group]) => orderGroup(group));
|
|
102
|
+
slots.forEach((slot, i) => {
|
|
103
|
+
out[slot] = reordered[i];
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Orders the rows of one data layer, all in one conformance class, by {@link OutcomeOrder},
|
|
110
|
+
* keeping the layer's order inside each group.
|
|
111
|
+
*/
|
|
112
|
+
export function orderWithinLayerByOutcome(rows, order) {
|
|
113
|
+
if (order.hint == null && !order.headOrder?.length)
|
|
114
|
+
return [...rows];
|
|
115
|
+
return rows
|
|
116
|
+
.map((row, index) => ({ row, index, group: groupOf(row, order) }))
|
|
117
|
+
.toSorted((a, b) => a.group - b.group || a.index - b.index)
|
|
118
|
+
.map(({ row }) => row);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Merges candidates that share a Wikidata item into one, keeping the first one's place and position.
|
|
122
|
+
*
|
|
123
|
+
* The merged candidate's set is the union of both sets, each member with the sources of both.
|
|
124
|
+
* Two candidates without a shared item stay two.
|
|
125
|
+
*/
|
|
126
|
+
export function mergeByWikidata(candidates) {
|
|
127
|
+
const byItem = new Map();
|
|
128
|
+
const out = [];
|
|
129
|
+
for (const candidate of candidates) {
|
|
130
|
+
const item = candidate.wikidata;
|
|
131
|
+
const held = item ? byItem.get(item) : undefined;
|
|
132
|
+
if (!held) {
|
|
133
|
+
const kept = { ...candidate };
|
|
134
|
+
out.push(kept);
|
|
135
|
+
if (item) {
|
|
136
|
+
byItem.set(item, kept);
|
|
137
|
+
}
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
held.outcomes = unionOutcomes(held.outcomes ?? [], candidate.outcomes ?? []);
|
|
141
|
+
held.sitelinkProminence ??= candidate.sitelinkProminence ?? null;
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Merges two fetches of one data layer by place id, the first fetch's rows first.
|
|
147
|
+
*/
|
|
148
|
+
export function mergeFetches(first, second) {
|
|
149
|
+
const seen = new Set(first.map((c) => String(c.id)));
|
|
150
|
+
return [...first, ...second.filter((c) => !seen.has(String(c.id)))];
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=ordering.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ordering.js","sourceRoot":"","sources":["../../lib/outcome/ordering.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAYlE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,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AG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAEd,IAAI,IAAI,EAAE,CAAC;gBACV,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;YACvB,CAAC;YAED,SAAQ;QACT,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,EAAE,SAAS,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAA;QAC5E,IAAI,CAAC,kBAAkB,KAAK,SAAS,CAAC,kBAAkB,IAAI,IAAI,CAAA;IACjE,CAAC;IAED,OAAO,GAAG,CAAA;AACX,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAA+B,EAAE,MAAgC;IAC7F,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAEpD,OAAO,CAAC,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AACpE,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The span outcome ordering applies to, and the landmark candidates it reads beside the candidate table's.
|
|
3
|
+
*
|
|
4
|
+
* The hint and the filter describe the returned records, so they act on the input's
|
|
5
|
+
* leading name: the span that starts first among the spans the walk looks up.
|
|
6
|
+
* Every other span is context, ranked by the passes that exist today.
|
|
7
|
+
*/
|
|
8
|
+
import type { PlacetypeMap } from "@mailwoman/codex/labels/placetype-map";
|
|
9
|
+
import { type AddressNode } from "@mailwoman/core/decoder";
|
|
10
|
+
import type { LandmarkHit, LandmarkLookup, ResolvedPlace, ResolverBackend } from "@mailwoman/core/resolver";
|
|
11
|
+
import { type ResolveOutcome } from "@mailwoman/core/resolver/outcome";
|
|
12
|
+
/**
|
|
13
|
+
* The span outcome ordering applies to: the input's leading span, when the walk looks it up.
|
|
14
|
+
*
|
|
15
|
+
* A leading span the walk doesn't look up, such as the venue or category in `coffee near Mt. Tabor`,
|
|
16
|
+
* names the returned records, so every span after it is an anchor and keeps today's order.
|
|
17
|
+
* The landmark pass reads a leading venue under the request instead.
|
|
18
|
+
*/
|
|
19
|
+
export declare function outcomeTargetSpan(roots: readonly AddressNode[], placetypeMap: PlacetypeMap): AddressNode | null;
|
|
20
|
+
/**
|
|
21
|
+
* Refuses an outcome request when the gazetteer or a landmark layer predates the outcome tables.
|
|
22
|
+
*
|
|
23
|
+
* A data layer without a report of its tables reads no outcome sets, so it is refused with every table.
|
|
24
|
+
*
|
|
25
|
+
* @throws {OutcomeRequestError} Naming the data layer and its missing tables.
|
|
26
|
+
*/
|
|
27
|
+
export declare function refuseLayersWithoutOutcomeTables(backend: Pick<ResolverBackend, "missingOutcomeTables">, layers: ReadonlyArray<{
|
|
28
|
+
name: string;
|
|
29
|
+
lookup: LandmarkLookup;
|
|
30
|
+
}>): void;
|
|
31
|
+
/**
|
|
32
|
+
* The context a landmark candidate is admitted under: the lookup's country
|
|
33
|
+
* and the nearest resolved locality above the span.
|
|
34
|
+
*/
|
|
35
|
+
export interface LandmarkContext {
|
|
36
|
+
country: string | null;
|
|
37
|
+
locality: {
|
|
38
|
+
lat: number;
|
|
39
|
+
lon: number;
|
|
40
|
+
} | null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The landmark layers' candidates for a span, each marked whether the stated context admits it,
|
|
44
|
+
* under the layer's existing rule: the stated country, and 50 km of a stated locality.
|
|
45
|
+
*
|
|
46
|
+
* `hits` maps each candidate back to the hit it came from.
|
|
47
|
+
*/
|
|
48
|
+
export declare function landmarkSpanCandidates(layers: readonly LandmarkLookup[], value: string, outcome: ResolveOutcome, context: LandmarkContext): Promise<{
|
|
49
|
+
candidates: ResolvedPlace[];
|
|
50
|
+
hits: Map<string, LandmarkHit>;
|
|
51
|
+
}>;
|
|
52
|
+
//# sourceMappingURL=span.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span.d.ts","sourceRoot":"","sources":["../../lib/outcome/span.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAA;AACzE,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC3G,OAAO,EAA8C,KAAK,cAAc,EAAE,MAAM,kCAAkC,CAAA;AAMlH;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,EAAE,YAAY,EAAE,YAAY,GAAG,WAAW,GAAG,IAAI,CAI/G;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC/C,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,sBAAsB,CAAC,EACtD,MAAM,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,cAAc,CAAA;CAAE,CAAC,GAC7D,IAAI,CAMN;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,QAAQ,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;CAC7C;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC3C,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC;IAAE,UAAU,EAAE,aAAa,EAAE,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;CAAE,CAAC,CAkC1E"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
import { collectNodes } from "@mailwoman/core/decoder";
|
|
4
|
+
import { OUTCOME_TABLES, refuseMissingOutcomeTables } from "@mailwoman/core/resolver/outcome";
|
|
5
|
+
import { haversine } from "@mailwoman/spatial/geometries/point/distance";
|
|
6
|
+
import { findWithOutcome } from "#outcome/fetch";
|
|
7
|
+
import { placeOfLandmark, STATED_LOCALITY_RADIUS_KM } from "#resolve/landmark";
|
|
8
|
+
/**
|
|
9
|
+
* The span outcome ordering applies to: the input's leading span, when the walk looks it up.
|
|
10
|
+
*
|
|
11
|
+
* A leading span the walk doesn't look up, such as the venue or category in `coffee near Mt. Tabor`,
|
|
12
|
+
* names the returned records, so every span after it is an anchor and keeps today's order.
|
|
13
|
+
* The landmark pass reads a leading venue under the request instead.
|
|
14
|
+
*/
|
|
15
|
+
export function outcomeTargetSpan(roots, placetypeMap) {
|
|
16
|
+
const leading = collectNodes(roots, (node) => !!node.value.trim()).toSorted((a, b) => a.start - b.start)[0];
|
|
17
|
+
return leading && placetypeMap[leading.tag] ? leading : null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Refuses an outcome request when the gazetteer or a landmark layer predates the outcome tables.
|
|
21
|
+
*
|
|
22
|
+
* A data layer without a report of its tables reads no outcome sets, so it is refused with every table.
|
|
23
|
+
*
|
|
24
|
+
* @throws {OutcomeRequestError} Naming the data layer and its missing tables.
|
|
25
|
+
*/
|
|
26
|
+
export function refuseLayersWithoutOutcomeTables(backend, layers) {
|
|
27
|
+
refuseMissingOutcomeTables("the gazetteer database", backend.missingOutcomeTables?.() ?? OUTCOME_TABLES);
|
|
28
|
+
for (const { name, lookup } of layers) {
|
|
29
|
+
refuseMissingOutcomeTables(`the ${name} database`, lookup.missingOutcomeTables?.() ?? OUTCOME_TABLES);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The landmark layers' candidates for a span, each marked whether the stated context admits it,
|
|
34
|
+
* under the layer's existing rule: the stated country, and 50 km of a stated locality.
|
|
35
|
+
*
|
|
36
|
+
* `hits` maps each candidate back to the hit it came from.
|
|
37
|
+
*/
|
|
38
|
+
export async function landmarkSpanCandidates(layers, value, outcome, context) {
|
|
39
|
+
const hits = new Map();
|
|
40
|
+
const candidates = [];
|
|
41
|
+
for (const layer of layers) {
|
|
42
|
+
for (const hit of await findWithOutcome(layer, value, outcome)) {
|
|
43
|
+
// A settlement row is the admin ladder's to answer.
|
|
44
|
+
if (hit.kind !== "venue" || hits.has(hit.qid))
|
|
45
|
+
continue;
|
|
46
|
+
const inCountry = !context.country || hit.country === context.country;
|
|
47
|
+
const nearLocality = !context.locality ||
|
|
48
|
+
haversine(context.locality.lat, context.locality.lon, hit.lat, hit.lon) <= STATED_LOCALITY_RADIUS_KM;
|
|
49
|
+
const admits = inCountry && nearLocality;
|
|
50
|
+
hits.set(hit.qid, hit);
|
|
51
|
+
candidates.push({
|
|
52
|
+
...placeOfLandmark(hit),
|
|
53
|
+
exactMatch: hit.primary || hit.code,
|
|
54
|
+
contextAdmits: admits,
|
|
55
|
+
// A place within reach of the stated locality is inside it for the containment partition.
|
|
56
|
+
containedByQualifier: context.locality ? admits : null,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// A candidate the stated context doesn't admit follows every one it does.
|
|
61
|
+
return {
|
|
62
|
+
candidates: [...candidates.filter((c) => c.contextAdmits), ...candidates.filter((c) => !c.contextAdmits)],
|
|
63
|
+
hits,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=span.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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G,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;QACzG,IAAI;KACJ,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AddressNode, AddressTree } from "@mailwoman/core/decoder";
|
|
2
|
+
import type { LandmarkHit, ResolvedPlace, ResolveOpts, ResolverBackend } from "@mailwoman/core/resolver";
|
|
3
|
+
import { landmarkSpanCandidates } from "#outcome/span";
|
|
4
|
+
import type { CoordinateOptionalPlace } from "#postcode/prefix";
|
|
5
|
+
import type { ResolutionState } from "#resolve/passes";
|
|
6
|
+
/**
|
|
7
|
+
* The outcome state of one span: the request, the span and the landmark layers it reads.
|
|
8
|
+
*/
|
|
9
|
+
export type OutcomeSpan = NonNullable<ResolutionState["outcome"]>;
|
|
10
|
+
type FindPlaceQuery = Parameters<ResolverBackend["findPlace"]>[0];
|
|
11
|
+
/**
|
|
12
|
+
* The resolver state of an outcome request, or an empty object without a request or a leading span to order.
|
|
13
|
+
*
|
|
14
|
+
* @throws {OutcomeRequestError} When a data layer predates the outcome tables.
|
|
15
|
+
*/
|
|
16
|
+
export declare function outcomeState(tree: AddressTree, opts: ResolveOpts, backend: ResolverBackend): Pick<ResolutionState, "outcome">;
|
|
17
|
+
/**
|
|
18
|
+
* The candidate table's fetches beyond the usual one.
|
|
19
|
+
*
|
|
20
|
+
* The hint, or the head's first reading, adds one fetch of the rows that satisfy it.
|
|
21
|
+
* The bare-toponym race stands down on an outcome-ordered span, so a bare name also
|
|
22
|
+
* reads the sub-locality and admin bands the race would have probed.
|
|
23
|
+
*/
|
|
24
|
+
export declare function outcomeFetches(backend: ResolverBackend, query: FindPlaceQuery, span: OutcomeSpan, bareName: boolean, candidates: ResolvedPlace[]): Promise<ResolvedPlace[]>;
|
|
25
|
+
/**
|
|
26
|
+
* The landmark layers' candidates for the span, admitted under the lookup's country
|
|
27
|
+
* and the span's resolved locality parent.
|
|
28
|
+
*/
|
|
29
|
+
export declare function spanLayerCandidates(span: OutcomeSpan, node: AddressNode, country: string | null, parentResolved: CoordinateOptionalPlace | null): ReturnType<typeof landmarkSpanCandidates>;
|
|
30
|
+
/**
|
|
31
|
+
* Order 4: one candidate list across the data layers, one place per Wikidata item,
|
|
32
|
+
* then the outcome partition inside each conformance class.
|
|
33
|
+
*/
|
|
34
|
+
export declare function orderSpanByOutcome(ranked: readonly ResolvedPlace[], span: OutcomeSpan, layered: readonly ResolvedPlace[], posterior: Readonly<Record<string, number>> | null | undefined): ResolvedPlace[];
|
|
35
|
+
/**
|
|
36
|
+
* The metadata an outcome-ordered span's pick writes: the span's mark, the place's
|
|
37
|
+
* outcome set, and a landmark winner's sitelinks and source.
|
|
38
|
+
* The geocode result reads all four.
|
|
39
|
+
*/
|
|
40
|
+
export declare function outcomePickStamps(top: ResolvedPlace, hits: ReadonlyMap<string, LandmarkHit>): Record<string, unknown>;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=walk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../lib/outcome/walk.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAMxG,OAAO,EAAE,sBAAsB,EAAuD,MAAM,eAAe,CAAA;AAC3G,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,eAAe,C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icenseRef-Commercial
|
|
3
|
+
/**
|
|
4
|
+
* The steps the resolver walk runs on the span outcome ordering applies to:
|
|
5
|
+
* the request's state, the extra fetches of the candidate table, the landmark candidates,
|
|
6
|
+
* the order-4 partition and the pick's stamps.
|
|
7
|
+
*/
|
|
8
|
+
import { DEFAULT_PLACETYPE_MAP } from "@mailwoman/codex/labels/placetype-map";
|
|
9
|
+
import { OutcomeLayer } from "@mailwoman/core/resolver/outcome";
|
|
10
|
+
import { BARE_SUBLOCALITY_BANDS } from "#bare-toponym-race";
|
|
11
|
+
import { OUTCOME_SET_KEY, OUTCOME_TARGET_KEY, outcomeOrderOf, secondFetchQuery } from "#outcome/fetch";
|
|
12
|
+
import { mergeByWikidata, mergeFetches, partitionByOutcome } from "#outcome/ordering";
|
|
13
|
+
import { landmarkSpanCandidates, outcomeTargetSpan, refuseLayersWithoutOutcomeTables } from "#outcome/span";
|
|
14
|
+
/**
|
|
15
|
+
* The resolver state of an outcome request, or an empty object without a request or a leading span to order.
|
|
16
|
+
*
|
|
17
|
+
* @throws {OutcomeRequestError} When a data layer predates the outcome tables.
|
|
18
|
+
*/
|
|
19
|
+
export function outcomeState(tree, opts, backend) {
|
|
20
|
+
if (!opts.outcome)
|
|
21
|
+
return {};
|
|
22
|
+
const named = [
|
|
23
|
+
...(opts.landmarks ? [{ name: OutcomeLayer.Landmarks, lookup: opts.landmarks }] : []),
|
|
24
|
+
...(opts.osmPlaces ? [{ name: OutcomeLayer.OpenStreetMap, lookup: opts.osmPlaces }] : []),
|
|
25
|
+
];
|
|
26
|
+
refuseLayersWithoutOutcomeTables(backend, named);
|
|
27
|
+
const target = outcomeTargetSpan(tree.roots, opts.placetypeMap ?? DEFAULT_PLACETYPE_MAP);
|
|
28
|
+
if (!target)
|
|
29
|
+
return {};
|
|
30
|
+
return { outcome: { request: opts.outcome, target, layers: named.map((layer) => layer.lookup) } };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The candidate table's fetches beyond the usual one.
|
|
34
|
+
*
|
|
35
|
+
* The hint, or the head's first reading, adds one fetch of the rows that satisfy it.
|
|
36
|
+
* The bare-toponym race stands down on an outcome-ordered span, so a bare name also
|
|
37
|
+
* reads the sub-locality and admin bands the race would have probed.
|
|
38
|
+
*/
|
|
39
|
+
export async function outcomeFetches(backend, query, span, bareName, candidates) {
|
|
40
|
+
let merged = candidates;
|
|
41
|
+
const second = secondFetchQuery(span.request);
|
|
42
|
+
if (second) {
|
|
43
|
+
merged = mergeFetches(merged, await backend.findPlace({ ...query, outcome: second }));
|
|
44
|
+
}
|
|
45
|
+
if (bareName) {
|
|
46
|
+
const bands = [...BARE_SUBLOCALITY_BANDS, "region", "country"];
|
|
47
|
+
merged = mergeFetches(merged, await backend.findPlace({ ...query, placetype: bands }));
|
|
48
|
+
}
|
|
49
|
+
return merged;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The landmark layers' candidates for the span, admitted under the lookup's country
|
|
53
|
+
* and the span's resolved locality parent.
|
|
54
|
+
*/
|
|
55
|
+
export function spanLayerCandidates(span, node, country, parentResolved) {
|
|
56
|
+
const locality = parentResolved?.placetype === "locality" && parentResolved.lat != null && parentResolved.lon != null
|
|
57
|
+
? { lat: parentResolved.lat, lon: parentResolved.lon }
|
|
58
|
+
: null;
|
|
59
|
+
return landmarkSpanCandidates(span.layers, node.value, span.request, { country, locality });
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Order 4: one candidate list across the data layers, one place per Wikidata item,
|
|
63
|
+
* then the outcome partition inside each conformance class.
|
|
64
|
+
*/
|
|
65
|
+
export function orderSpanByOutcome(ranked, span, layered, posterior) {
|
|
66
|
+
const table = ranked.map((c) => ({ ...c, layer: OutcomeLayer.Candidate }));
|
|
67
|
+
return partitionByOutcome(mergeByWikidata([...table, ...layered]), outcomeOrderOf(span.request), posterior);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The metadata an outcome-ordered span's pick writes: the span's mark, the place's
|
|
71
|
+
* outcome set, and a landmark winner's sitelinks and source.
|
|
72
|
+
* The geocode result reads all four.
|
|
73
|
+
*/
|
|
74
|
+
export function outcomePickStamps(top, hits) {
|
|
75
|
+
const hit = top.layer && top.layer !== OutcomeLayer.Candidate ? hits.get(String(top.id)) : undefined;
|
|
76
|
+
return {
|
|
77
|
+
[OUTCOME_TARGET_KEY]: true,
|
|
78
|
+
[OUTCOME_SET_KEY]: top.outcomes ?? [],
|
|
79
|
+
...(hit ? { landmark_sitelinks: hit.sitelinks } : {}),
|
|
80
|
+
...(top.layer === OutcomeLayer.OpenStreetMap ? { landmark_source: "openstreetmap:planet" } : {}),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=walk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../../lib/outcome/walk.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;;;GAIG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAA;AAG7E,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAE/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACtG,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACrF,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,gCAAgC,EAAE,MAAM,eAAe,CAAA;AAW3G;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC3B,IAAiB,EACjB,IAAiB,EACjB,OAAwB;IAExB,IAAI,CAAC,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAA;IAE5B,MAAM,KAAK,GAAG;QACb,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CA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G,CAAC,KAAK,KAAK,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAEpG,OAAO;QACN,CAAC,kBAAkB,CAAC,EAAE,IAAI;QAC1B,CAAC,eAAe,CAAC,EAAE,GAAG,CAAC,QAAQ,IAAI,EAAE;QACrC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,GAAG,CAAC,GAAG,CAAC,KAAK,KAAK,YAAY,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,sBAAsB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChG,CAAA;AACF,CAAC"}
|
|
@@ -14,12 +14,24 @@
|
|
|
14
14
|
* `writtenCountryCode` states which codes a country claims.
|
|
15
15
|
*/
|
|
16
16
|
import { type AddressNode } from "@mailwoman/core/decoder";
|
|
17
|
-
import { type LandmarkLookup } from "@mailwoman/core/resolver";
|
|
17
|
+
import { type LandmarkHit, type LandmarkLookup, type ResolvedPlace } from "@mailwoman/core/resolver";
|
|
18
|
+
import { type ResolveOutcome } from "@mailwoman/core/resolver/outcome";
|
|
19
|
+
/**
|
|
20
|
+
* The farthest a landmark may lie from a locality the input states, matching span rescore's postcode radius.
|
|
21
|
+
*/
|
|
22
|
+
export declare const STATED_LOCALITY_RADIUS_KM = 50;
|
|
23
|
+
/**
|
|
24
|
+
* The place a landmark hit answers.
|
|
25
|
+
*
|
|
26
|
+
* A place from a hit read with an outcome query also holds its outcome set,
|
|
27
|
+
* its data layer, its Wikidata item and its comparable prominence.
|
|
28
|
+
*/
|
|
29
|
+
export declare function placeOfLandmark(hit: LandmarkHit): ResolvedPlace;
|
|
18
30
|
/**
|
|
19
31
|
* Replaces the parse's reading of a landmark name with a venue node that holds the answer.
|
|
20
32
|
*
|
|
21
33
|
* The first comma-separated part is the name, and any other part is context that has to have resolved.
|
|
22
34
|
* A settlement that leads the name stays with the admin ladder, because the ladder ranks settlements.
|
|
23
35
|
*/
|
|
24
|
-
export declare function applyLandmark(roots: AddressNode[], raw: string, landmarks: LandmarkLookup): Promise<void>;
|
|
36
|
+
export declare function applyLandmark(roots: AddressNode[], raw: string, landmarks: LandmarkLookup, outcome?: ResolveOutcome | null): Promise<void>;
|
|
25
37
|
//# sourceMappingURL=landmark.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"landmark.d.ts","sourceRoot":"","sources":["../../lib/resolve/landmark.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,
|
|
1
|
+
{"version":3,"file":"landmark.d.ts","sourceRoot":"","sources":["../../lib/resolve/landmark.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,EAIN,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,kCAAkC,CAAA;AA6BpF;;GAEG;AACH,eAAO,MAAM,yBAAyB,KAAK,CAAA;AAgC3C;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,WAAW,GAAG,aAAa,CA0B/D;AAiCD;;;;;GAKG;AACH,wBAAsB,aAAa,CAClC,KAAK,EAAE,WAAW,EAAE,EACpB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,cAAc,EACzB,OAAO,GAAE,cAAc,GAAG,IAAW,GACnC,OAAO,CAAC,IAAI,CAAC,CAkHf"}
|