@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/lib/admin/winner.ts
CHANGED
|
@@ -2,15 +2,10 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
* @file Which resolved admin place answers the query
|
|
5
|
+
* @file Which resolved admin place answers the query: the one ordering whose postcode rung is not a constant.
|
|
6
6
|
*
|
|
7
|
-
* `postalcode` is the only placetype whose specificity depends on the hit
|
|
8
|
-
*
|
|
9
|
-
* postal or a German PLZ covers a delivery AREA. `PLACETYPE_SPECIFICITY` answers "which placetype covers less ground"
|
|
10
|
-
* and cannot express that split, so a consumer that sorts by it alone promotes every postcode.
|
|
11
|
-
*
|
|
12
|
-
* Two consumers need the split in two shapes, and both live here so a divergence is a test failure rather than a
|
|
13
|
-
* silent disagreement: result assembly walks a TAG ladder, and the eval harnesses sort resolved nodes by placetype.
|
|
7
|
+
* `postalcode` is the only placetype whose specificity depends on the resolved hit.
|
|
8
|
+
* `PLACETYPE_SPECIFICITY` cannot express that split.
|
|
14
9
|
*/
|
|
15
10
|
|
|
16
11
|
import { areaPostcodeLeadsLocality, isUnitGradePostcodeHit } from "@mailwoman/codex"
|
|
@@ -18,16 +13,8 @@ import type { AddressNode } from "@mailwoman/core/decoder"
|
|
|
18
13
|
import { PLACETYPE_SPECIFICITY } from "@mailwoman/core/resources/whosonfirst/specificity"
|
|
19
14
|
|
|
20
15
|
/**
|
|
21
|
-
* The admin fallback order when the postcode leads
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* The JP rungs (`municipality`, `district`, `prefecture`) sit beside their Latin counterparts, and `municipality`
|
|
25
|
-
* stands ABOVE `district` on purpose. `subregion` (a county, a Korean 시군구) sits between the postcode and `region`:
|
|
26
|
-
* finer than the region it belongs to, coarser than any postcode. Absent from the ladder it was never the answer, and
|
|
27
|
-
* `부산광역시 해운대구 반송로 910-1` resolved both nodes and reported Busan's point, 3.3 km from the address, over Haeundae's. It
|
|
28
|
-
* stands ABOVE `district` on purpose: a district (大字 / 町名) resolves without its municipality as a parent more often
|
|
29
|
-
* than not, and the unscoped namesake it then picks can be another prefecture's (`市原市大作` → 921 km). Measured on 300 JP
|
|
30
|
-
* board rows @15 km: district-first 202 accepted, municipality-first 271.
|
|
16
|
+
* The admin fallback order when the postcode leads, with the JP rungs beside their
|
|
17
|
+
* Latin counterparts and `municipality` above `district`.
|
|
31
18
|
*/
|
|
32
19
|
export const ADMIN_LADDER_POSTCODE_FIRST: ReadonlyArray<string> = [
|
|
33
20
|
"postcode",
|
|
@@ -42,10 +29,8 @@ export const ADMIN_LADDER_POSTCODE_FIRST: ReadonlyArray<string> = [
|
|
|
42
29
|
]
|
|
43
30
|
|
|
44
31
|
/**
|
|
45
|
-
* The admin fallback order everywhere else: the locality tiers lead
|
|
46
|
-
*
|
|
47
|
-
* This is the #945 epoch convention and the DEFAULT rather than the universal answer — which address systems leave it
|
|
48
|
-
* is `AREA_POSTCODE_FINER_THAN_LOCALITY`'s question, and that table carries the per-country measurement.
|
|
32
|
+
* The admin fallback order everywhere else: the locality tiers lead
|
|
33
|
+
* and the postcode sits between them and `region`.
|
|
49
34
|
*/
|
|
50
35
|
export const ADMIN_LADDER_LOCALITY_FIRST: ReadonlyArray<string> = [
|
|
51
36
|
"locality",
|
|
@@ -60,29 +45,27 @@ export const ADMIN_LADDER_LOCALITY_FIRST: ReadonlyArray<string> = [
|
|
|
60
45
|
]
|
|
61
46
|
|
|
62
47
|
/**
|
|
63
|
-
* The resolved postcode a ladder decision reads
|
|
64
|
-
* placed it in.
|
|
48
|
+
* The resolved postcode a ladder decision reads.
|
|
65
49
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* is, but whether this address system's codes are tighter than its localities at all.
|
|
50
|
+
* It contains the parsed span and the resolver hit.
|
|
51
|
+
* It also contains the country where the resolver placed the postcode.
|
|
69
52
|
*/
|
|
70
53
|
export interface ResolvedPostcodeHit {
|
|
71
54
|
value: string
|
|
72
55
|
resolverName: string | undefined
|
|
73
56
|
/**
|
|
74
|
-
* ISO-3166 alpha-2 the
|
|
75
|
-
*
|
|
57
|
+
* ISO-3166 alpha-2 code where the resolver placed the postcode.
|
|
58
|
+
*
|
|
59
|
+
* The code is independent of the caller's requested scope.
|
|
60
|
+
* It is absent when the postcode did not resolve to a country.
|
|
61
|
+
* The ladder then defaults to locality-first.
|
|
76
62
|
*/
|
|
77
63
|
country?: string
|
|
78
64
|
}
|
|
79
65
|
|
|
80
66
|
/**
|
|
81
|
-
* Pick the admin fallback order for one resolved tree
|
|
82
|
-
*
|
|
83
|
-
* Two independent routes to postcode-first: the code itself is unit-grade, or the address system's area-grade codes are
|
|
84
|
-
* finer than its localities. Either one is sufficient and the second is what makes this per-country rather than
|
|
85
|
-
* global.
|
|
67
|
+
* Pick the admin fallback order for one resolved tree: postcode-first when the code is
|
|
68
|
+
* unit-grade or the address system's area-grade codes are finer than its localities.
|
|
86
69
|
*/
|
|
87
70
|
export function adminLadderFor(postcode: ResolvedPostcodeHit | undefined): ReadonlyArray<string> {
|
|
88
71
|
if (postcode === undefined) return ADMIN_LADDER_LOCALITY_FIRST
|
|
@@ -94,12 +77,8 @@ export function adminLadderFor(postcode: ResolvedPostcodeHit | undefined): Reado
|
|
|
94
77
|
}
|
|
95
78
|
|
|
96
79
|
/**
|
|
97
|
-
* The ladder for a flat list of resolved nodes
|
|
98
|
-
*
|
|
99
|
-
* Which node counts, and which of its fields the decision reads, is part of the ordering rather than the caller's
|
|
100
|
-
* business: `country` is the one the RESOLVER placed the code in, never a caller's requested scope, because the ladder
|
|
101
|
-
* is asking which address system this code belongs to and a scope is a filter on the answer rather than evidence about
|
|
102
|
-
* it. Getting that wrong at a call site would be invisible.
|
|
80
|
+
* The ladder for a flat list of resolved nodes, reading `country` from the resolver's
|
|
81
|
+
* placement rather than a caller's requested scope.
|
|
103
82
|
*/
|
|
104
83
|
export function adminLadderForNodes(nodes: readonly AddressNode[]): ReadonlyArray<string> {
|
|
105
84
|
const node = nodes.find((n) => n.tag === "postcode" && n.lat != null && n.lon != null)
|
|
@@ -116,15 +95,8 @@ export function adminLadderForNodes(nodes: readonly AddressNode[]): ReadonlyArra
|
|
|
116
95
|
}
|
|
117
96
|
|
|
118
97
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* The tier is `PLACETYPE_FILTER_GROUPS.locality` — `locality` (4), `borough` (5) and `localadmin` (3) — not the
|
|
122
|
-
* `locality` placetype alone, because that is what the resolver's own `locality` tag expands to. New England civil
|
|
123
|
-
* towns are `localadmin` in WOF, so a value between `locality` and `localadmin` would rank a US ZIP above the town it
|
|
124
|
-
* sits in and reproduce the defect on exactly the rows that motivated the group.
|
|
125
|
-
*
|
|
126
|
-
* Deliberately not an integer. The scale's rungs are placetypes and this is not one — it is the position
|
|
127
|
-
* {@link ADMIN_LADDER_LOCALITY_FIRST} puts a postcode in, expressed on the scale the sorting consumers already use.
|
|
98
|
+
* Deliberately non-integer position for an area-grade postal code on `PLACETYPE_SPECIFICITY`:
|
|
99
|
+
* below the whole locality tier and above `county` (2).
|
|
128
100
|
*/
|
|
129
101
|
export const AREA_GRADE_POSTALCODE_SPECIFICITY = 2.5
|
|
130
102
|
|
|
@@ -134,25 +106,23 @@ export const AREA_GRADE_POSTALCODE_SPECIFICITY = 2.5
|
|
|
134
106
|
export interface ResolvedSpecificityInput {
|
|
135
107
|
placetype: string
|
|
136
108
|
/**
|
|
137
|
-
* ISO-3166 alpha-2 the resolver placed this candidate in
|
|
138
|
-
* address system's area-grade codes outrank its localities.
|
|
109
|
+
* ISO-3166 alpha-2 the resolver placed this candidate in, read only for a `postalcode`.
|
|
139
110
|
*/
|
|
140
111
|
country?: string
|
|
141
112
|
/**
|
|
142
|
-
* The parsed span.
|
|
113
|
+
* The parsed span.
|
|
114
|
+
* Absent for a non-postcode candidate.
|
|
143
115
|
*/
|
|
144
116
|
value?: string
|
|
145
117
|
/**
|
|
146
|
-
* The resolver's own hit name, as `resolver_name` metadata
|
|
118
|
+
* The resolver's own hit name, as recorded in `resolver_name` metadata.
|
|
147
119
|
*/
|
|
148
120
|
resolverName?: string
|
|
149
121
|
}
|
|
150
122
|
|
|
151
123
|
/**
|
|
152
|
-
* Rank a resolved place for "whose coordinate answers the query"
|
|
153
|
-
* is ranked by its hit
|
|
154
|
-
*
|
|
155
|
-
* An unranked placetype returns `-Infinity` so it wins only when nothing else resolved.
|
|
124
|
+
* Rank a resolved place for "whose coordinate answers the query": `PLACETYPE_SPECIFICITY`,
|
|
125
|
+
* except that a `postalcode` is ranked by its hit and an unranked placetype returns `-Infinity`.
|
|
156
126
|
*/
|
|
157
127
|
export function resolvedSpecificity(candidate: ResolvedSpecificityInput): number {
|
|
158
128
|
if (candidate.placetype !== "postalcode") {
|
|
@@ -167,12 +137,10 @@ export function resolvedSpecificity(candidate: ResolvedSpecificityInput): number
|
|
|
167
137
|
}
|
|
168
138
|
|
|
169
139
|
/**
|
|
170
|
-
* The best of a resolved set under {@link resolvedSpecificity}, or `null` when the set is empty.
|
|
171
|
-
* which is document order.
|
|
140
|
+
* The best of a resolved set under {@link resolvedSpecificity}, or `null` when the set is empty.
|
|
172
141
|
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* site is where that mapping is visible.
|
|
142
|
+
* Ties keep the first.
|
|
143
|
+
* `toInput` is explicit because each consumer formats the resolver's hit differently.
|
|
176
144
|
*/
|
|
177
145
|
export function mostSpecificResolved<T>(
|
|
178
146
|
candidates: readonly T[],
|
|
@@ -3,26 +3,20 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* silently costs.
|
|
6
|
+
* Lists optional {@link ResolverBackend} methods that the loaded backend lacks and the cost of each omission.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* (`hierarchyCompletion`) defaults to ON, so a caller who never touched it gets a feature that reports success while
|
|
12
|
-
* doing nothing. That is absence read as a negative answer, and the rule is that a magnitude never carries its own
|
|
13
|
-
* absence: the gap has to be stated somewhere a caller can read it.
|
|
14
|
-
*
|
|
15
|
-
* This module states it. `describeCapabilityGaps` is pure and cheap enough to run at construction; the resolver
|
|
16
|
-
* exposes the result on `Resolver.capabilityGaps` and warns once so the gap appears in a log without a caller having
|
|
17
|
-
* to ask. It changes no resolution behavior — a gap that was silent is now legible, nothing more.
|
|
8
|
+
* Optional backend methods can make default-on resolver features no-op. This module exposes and
|
|
9
|
+
* reports those gaps without changing resolution behavior.
|
|
18
10
|
*/
|
|
19
11
|
|
|
20
12
|
import type { BackendCapabilityGap, ResolverBackend } from "@mailwoman/core/resolver"
|
|
21
13
|
|
|
22
14
|
/**
|
|
23
|
-
* The optional backend methods whose absence degrades a passing default, paired with what stops working.
|
|
24
|
-
*
|
|
25
|
-
*
|
|
15
|
+
* The optional backend methods whose absence degrades a passing default, paired with what stops working.
|
|
16
|
+
*
|
|
17
|
+
* A method whose absence is inert (or whose option is opt-in and therefore a
|
|
18
|
+
* deliberate caller choice) does not belong here.
|
|
19
|
+
* The list exists to name silent degradation rather than to inventory the interface.
|
|
26
20
|
*/
|
|
27
21
|
const CONSEQUENTIAL_CAPABILITIES: ReadonlyArray<Omit<BackendCapabilityGap, "backend">> = [
|
|
28
22
|
{
|
|
@@ -42,8 +36,9 @@ const CONSEQUENTIAL_CAPABILITIES: ReadonlyArray<Omit<BackendCapabilityGap, "back
|
|
|
42
36
|
]
|
|
43
37
|
|
|
44
38
|
/**
|
|
45
|
-
* Enumerate the consequential capabilities this backend does not implement.
|
|
46
|
-
*
|
|
39
|
+
* Enumerate the consequential capabilities this backend does not implement.
|
|
40
|
+
*
|
|
41
|
+
* Empty means every default-on option the resolver offers has the backend support it needs.
|
|
47
42
|
*/
|
|
48
43
|
export function describeCapabilityGaps(backend: ResolverBackend): readonly BackendCapabilityGap[] {
|
|
49
44
|
const name = backend.constructor?.name || "backend"
|
|
@@ -54,9 +49,14 @@ export function describeCapabilityGaps(backend: ResolverBackend): readonly Backe
|
|
|
54
49
|
}
|
|
55
50
|
|
|
56
51
|
/**
|
|
57
|
-
* One log line for a backend's whole set of gaps.
|
|
58
|
-
*
|
|
59
|
-
*
|
|
52
|
+
* One log line for a backend's whole set of gaps.
|
|
53
|
+
*
|
|
54
|
+
* Keep the log line short.
|
|
55
|
+
* It states the missing methods and affected options.
|
|
56
|
+
*
|
|
57
|
+
* A reference points to the document that describes their consequences.
|
|
58
|
+
* Each gap's `degrades` field retains details for consumers.
|
|
59
|
+
* Long log lines are harder for operators to scan.
|
|
60
60
|
*/
|
|
61
61
|
export function formatCapabilityGaps(gaps: readonly BackendCapabilityGap[]): string {
|
|
62
62
|
const [first] = gaps
|
|
@@ -68,15 +68,16 @@ export function formatCapabilityGaps(gaps: readonly BackendCapabilityGap[]): str
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
|
-
* Backends already reported, so a process that builds many resolvers over one artifact — the eval
|
|
72
|
-
* gauntlet, a batch worker — states the gap once rather than once per construction.
|
|
71
|
+
* Backends already reported, so a process that builds many resolvers over one artifact — the eval
|
|
72
|
+
* harness, the gauntlet, a batch worker — states the gap once rather than once per construction.
|
|
73
73
|
*/
|
|
74
74
|
const reported = new Set<string>()
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
* Report a backend's gaps to stderr the first time this process sees them.
|
|
78
|
-
*
|
|
79
|
-
*
|
|
77
|
+
* Report a backend's gaps to stderr the first time this process sees them.
|
|
78
|
+
*
|
|
79
|
+
* The gaps are data on `Resolver.capabilityGaps` regardless.
|
|
80
|
+
* This also reports them to an operator.
|
|
80
81
|
*/
|
|
81
82
|
export function reportCapabilityGaps(gaps: readonly BackendCapabilityGap[]): void {
|
|
82
83
|
const [first] = gaps
|
package/lib/bare-toponym-race.ts
CHANGED
|
@@ -3,45 +3,54 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* The bare-toponym
|
|
7
|
-
* The locality placetype filter makes country/region namesakes unreachable at any
|
|
8
|
-
* resolver's lookup runs these side races for the tree's lone locality-tagged span
|
|
9
|
-
* admin namesake under the rules each prober documents. Split from `resolve.ts`
|
|
10
|
-
* holds the walk and this one holds the race policy.
|
|
6
|
+
* The bare-toponym admin race. This is the policy for a query that is one bare name ("Japan",
|
|
7
|
+
* "Georgia"). The locality placetype filter makes country/region namesakes unreachable at any
|
|
8
|
+
* rank, so the resolver's lookup runs these side races for the tree's lone locality-tagged span
|
|
9
|
+
* and promotes an admin namesake under the rules each prober documents. Split from `resolve.ts`
|
|
10
|
+
* so the walk file holds the walk and this one holds the race policy.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import type { ComponentTag } from "@mailwoman/codex/component"
|
|
14
14
|
import type { PlacetypeMap } from "@mailwoman/codex/placetype-map"
|
|
15
15
|
import type { AddressNode, AddressTree } from "@mailwoman/core/decoder"
|
|
16
|
-
import {
|
|
16
|
+
import { loneValueNode } from "@mailwoman/core/decoder"
|
|
17
17
|
import type { ResolvedPlace, ResolverBackend } from "@mailwoman/core/resolver"
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* The tree's single value-
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
20
|
+
* The tree's single value-containing node when it is locality-tagged, else null.
|
|
21
|
+
*
|
|
22
|
+
* This is the bare-toponym shape whose country-placetype sibling race `#lookupAndPick` runs.
|
|
23
|
+
*
|
|
24
|
+
* A bare name the parser tagged `locality` can refer to a country ("Japan", "China", because
|
|
25
|
+
* single country toponyms are out of the parser's training distribution), and the locality
|
|
26
|
+
* placetype filter makes the country row unreachable regardless of how the ranking would order it.
|
|
27
|
+
* Any second value-containing node makes the input address-shaped and the race stays off.
|
|
28
|
+
*
|
|
29
|
+
* `dependent_locality` maps to the same placetype but is an address-interior tag,
|
|
30
|
+
* so only a literal `locality` qualifies.
|
|
26
31
|
*/
|
|
27
32
|
export function loneBareLocalityNode(tree: AddressTree, placetypeMap: PlacetypeMap): AddressNode | null {
|
|
28
33
|
if (placetypeMap["locality" as ComponentTag] !== "locality") return null
|
|
29
|
-
const lone =
|
|
34
|
+
const lone = loneValueNode(tree)
|
|
30
35
|
|
|
31
36
|
return lone?.tag === "locality" ? lone : null
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
/**
|
|
35
|
-
* The log-population dominance a bare
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
40
|
+
* The log-population dominance a bare region namesake must hold over the locality winner
|
|
41
|
+
* before the bare-toponym race promotes it.
|
|
42
|
+
*
|
|
43
|
+
* The value is DECISIVE_MARGIN_LOG10 from the ablation-expectation model, restated here
|
|
44
|
+
* because the resolver package cannot import the eval harness.
|
|
45
|
+
* If that measured value moves, move this with it.
|
|
39
46
|
*/
|
|
40
47
|
export const BARE_REGION_DOMINANCE_LOG10 = 0.5
|
|
41
48
|
|
|
42
49
|
/**
|
|
43
|
-
* Log10(population + 1), 0 when the backend
|
|
44
|
-
*
|
|
50
|
+
* Log10(population + 1), 0 when the backend has no population value.
|
|
51
|
+
*
|
|
52
|
+
* The saturation-free magnitude the bare-region dominance rule compares
|
|
53
|
+
* (prominence caps at the backend's populationBoost and erases exactly the margins this rule needs).
|
|
45
54
|
*/
|
|
46
55
|
export function logPopulation(place: ResolvedPlace): number {
|
|
47
56
|
return Math.log10((place.population ?? 0) + 1)
|
|
@@ -59,19 +68,30 @@ export function pickLargerAdmin(country: ResolvedPlace | null, region: ResolvedP
|
|
|
59
68
|
}
|
|
60
69
|
|
|
61
70
|
/**
|
|
62
|
-
* Alias roles the side races refuse to answer through
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
71
|
+
* Alias roles the side races refuse to answer through.
|
|
72
|
+
*
|
|
73
|
+
* A lone bare token that only reaches a place via an abbreviation row ("Tó" folds onto Toledo's "TO")
|
|
74
|
+
* or a translation-gloss row did not identify that place.
|
|
75
|
+
* The role-NULL exonym tier stays open, so 格鲁吉亚 can win the country race through its display-name alias.
|
|
76
|
+
*
|
|
77
|
+
* An artifact without the role column ignores the exclusion and the races behave as before.
|
|
66
78
|
*/
|
|
67
79
|
const BARE_RACE_EXCLUDED_NAME_ROLES: readonly string[] = ["abbr", "gloss"]
|
|
68
80
|
|
|
69
81
|
/**
|
|
70
|
-
* The best `country`-placetype row for a bare toponym span, or null.
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
82
|
+
* The best `country`-placetype row for a bare toponym span, or null.
|
|
83
|
+
*
|
|
84
|
+
* `scopedCountry` is the same hard filter the locality query ran under.
|
|
85
|
+
* An explicit caller scope therefore bounds this race too
|
|
86
|
+
* (a foreign country row cannot outrank inside an explicit scope), while the
|
|
87
|
+
* bare-locality posture's withheld scope leaves it worldwide.
|
|
88
|
+
*
|
|
89
|
+
* This race uses exact matches only.
|
|
90
|
+
* The fuzzy tier recovers typos in address spans.
|
|
91
|
+
*
|
|
92
|
+
* A fuzzy country match is a guess this race must never promote.
|
|
93
|
+
*
|
|
94
|
+
* Abbreviation/gloss alias rows never enter ({@link BARE_RACE_EXCLUDED_NAME_ROLES}).
|
|
75
95
|
*/
|
|
76
96
|
export async function bareCountryCandidate(
|
|
77
97
|
backend: ResolverBackend,
|
|
@@ -89,22 +109,34 @@ export async function bareCountryCandidate(
|
|
|
89
109
|
|
|
90
110
|
const top = hits[0]
|
|
91
111
|
|
|
92
|
-
// The placetype check is required
|
|
93
|
-
//
|
|
94
|
-
// race a
|
|
112
|
+
// The placetype check is required.
|
|
113
|
+
// A backend may ignore the filter, as test stubs or a partial implementation could.
|
|
114
|
+
// It could then hand this race a locality row wearing a country costume,
|
|
115
|
+
// The repick would then demote the real pick.
|
|
95
116
|
return top && top.placetype === "country" && top.exactMatch !== false ? top : null
|
|
96
117
|
} catch {
|
|
97
|
-
// A failed side race must never abort the primary lookup
|
|
118
|
+
// A failed side race must never abort the primary lookup.
|
|
119
|
+
// The locality answer stands.
|
|
98
120
|
return null
|
|
99
121
|
}
|
|
100
122
|
}
|
|
101
123
|
|
|
102
124
|
/**
|
|
103
|
-
* The best `region`-placetype row for a bare toponym span, or null
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
125
|
+
* The best `region`-placetype row for a bare toponym span, or null.
|
|
126
|
+
*
|
|
127
|
+
* The sibling of {@link #bareCountryCandidate} for the US-state class
|
|
128
|
+
* (bare "Georgia"/"Texas" the parser tags `locality`).
|
|
129
|
+
*
|
|
130
|
+
* Uses the same interface.
|
|
131
|
+
* The locality query's country filter bounds it.
|
|
132
|
+
*
|
|
133
|
+
* It accepts exact matches only with abbreviation and gloss rows excluded.
|
|
134
|
+
* The placetype check guards partial backends.
|
|
135
|
+
*
|
|
136
|
+
* The `place_abbr`-staged region abbreviations (bare "TX"/"CA") are role-NULL
|
|
137
|
+
* primaries and stay fully reachable.
|
|
138
|
+
*
|
|
139
|
+
* The exclusion removes only abbreviation aliases like Toledo's "TO".
|
|
108
140
|
*/
|
|
109
141
|
export async function bareRegionCandidate(
|
|
110
142
|
backend: ResolverBackend,
|
package/lib/decorate-node.ts
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* Node decoration shared by the resolver walk and its post-walk passes
|
|
7
|
-
*
|
|
8
|
-
* live in their own module without an import cycle back into the walk.
|
|
6
|
+
* Node decoration shared by the resolver walk and its post-walk passes, in its own module so the
|
|
7
|
+
* coherence passes do not import the walk.
|
|
9
8
|
*/
|
|
10
9
|
|
|
11
10
|
import type { AddressNode } from "@mailwoman/core/decoder"
|
|
@@ -14,17 +13,16 @@ import type { ResolvedPlace } from "@mailwoman/core/resolver"
|
|
|
14
13
|
import type { CoordinateOptionalPlace } from "#postcode/prefix"
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
|
-
* A resolved node
|
|
16
|
+
* A resolved node has a real coordinate (placeID set + non-zero lat/lon).
|
|
18
17
|
*/
|
|
19
18
|
export function isResolvedWithCoord(n: AddressNode): boolean {
|
|
20
19
|
return !!(n.placeID && typeof n.lat === "number" && typeof n.lon === "number" && (n.lat !== 0 || n.lon !== 0))
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
|
-
* Stamp a node with resolver-supplied attribution
|
|
25
|
-
* `metadata.classifier_source` / `metadata.classifier_source_id`
|
|
26
|
-
*
|
|
27
|
-
* failures, [#8 in the failure catalogue]).
|
|
23
|
+
* Stamp a node with resolver-supplied attribution, displacing any prior classifier `source`
|
|
24
|
+
* / `sourceID` into `metadata.classifier_source` / `metadata.classifier_source_id`
|
|
25
|
+
* and surfacing runner-up candidates on `alternatives`.
|
|
28
26
|
*/
|
|
29
27
|
export function decorateNode(
|
|
30
28
|
node: AddressNode,
|
|
@@ -48,14 +46,8 @@ export function decorateNode(
|
|
|
48
46
|
node.source = "resolver"
|
|
49
47
|
node.sourceID = `${resolved.placetype}:${resolved.id}`
|
|
50
48
|
|
|
51
|
-
// `0,0` is the gazetteer's
|
|
52
|
-
//
|
|
53
|
-
// "yes" to every `lat != null` guard downstream, including the admin ladder's. Absence is the representable form
|
|
54
|
-
// (`AddressNode.lat` is optional and {@link isResolvedWithCoord} already reads the sentinel this way), so the
|
|
55
|
-
// place resolves and identifies itself while stating it cannot say where it is.
|
|
56
|
-
//
|
|
57
|
-
// Both are cleared together rather than left stale: a coordinate from a previously-decorated place beside this
|
|
58
|
-
// one's `placeID` would be a worse answer than none.
|
|
49
|
+
// `0,0` is the gazetteer's unlocated sentinel, so an unlocated place gets both coordinates
|
|
50
|
+
// cleared rather than a coordinate that satisfies every `lat != null` guard downstream.
|
|
59
51
|
const located = resolved.lat !== undefined && resolved.lon !== undefined && (resolved.lat !== 0 || resolved.lon !== 0)
|
|
60
52
|
|
|
61
53
|
if (located) {
|
|
@@ -66,35 +58,21 @@ export function decorateNode(
|
|
|
66
58
|
delete node.lon
|
|
67
59
|
}
|
|
68
60
|
|
|
69
|
-
node.placeID = `wof:${resolved.id}` // v1: only WOF resolvers
|
|
70
|
-
// Record the resolver's ranking score AND the resolved place's CANONICAL name. The name is the
|
|
71
|
-
// gazetteer's truth for the place we picked — distinct from `node.value` (the raw input span). It
|
|
72
|
-
// lets consumers display the canonical name and lets the end-to-end eval check the resolver chose
|
|
73
|
-
// the right PLACE (gazetteer-name vs ground-truth) rather than merely echoing the parser's text.
|
|
61
|
+
node.placeID = `wof:${resolved.id}` // v1: only WOF resolvers. the URI scheme stays this simple
|
|
74
62
|
node.metadata = { ...node.metadata, resolver_score: resolved.score, resolver_name: resolved.name }
|
|
75
63
|
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
// which makes a top-1-vs-top-2 margin uncomputable from the tree — and that margin is what
|
|
79
|
-
// `mailwoman/query-intent.ts` reads to decide whether a bare-toponym answer was a clear win. Additive metadata
|
|
80
|
-
// only; nothing in the resolve reads it back.
|
|
64
|
+
// Additive metadata only.
|
|
65
|
+
// No part of the resolve reads it back.
|
|
81
66
|
if (resolved.prominence !== undefined) {
|
|
82
67
|
node.metadata["resolver_prominence"] = resolved.prominence
|
|
83
68
|
}
|
|
84
69
|
|
|
85
|
-
// The resolved place's ISO-3166 alpha-2 country (from the gazetteer/candidate row), when known. #1014: lets a
|
|
86
|
-
// forward consumer fill country/countrycode without an ancestry walk — the candidate backend carries this even
|
|
87
|
-
// though it has no `ancestors()` table.
|
|
88
70
|
if (resolved.country) {
|
|
89
71
|
node.metadata["resolver_country"] = resolved.country
|
|
90
72
|
}
|
|
91
73
|
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
// node would assert a measurement nobody made. Nothing in the resolve path reads these keys back —
|
|
95
|
-
// they exist for annotation / API surfaces downstream. `resolver_importance` is the blended #28
|
|
96
|
-
// prior (the value the ranking consulted); `resolver_encyclopedic` is the strict channel, reserved
|
|
97
|
-
// until a strict-channel source ships.
|
|
74
|
+
// Written only when the backend supplies a value, because `resolver_*: 0`
|
|
75
|
+
// would assert an unmeasured value.
|
|
98
76
|
if (resolved.referential !== undefined) {
|
|
99
77
|
node.metadata["resolver_referential"] = resolved.referential
|
|
100
78
|
}
|
|
@@ -107,16 +85,14 @@ export function decorateNode(
|
|
|
107
85
|
node.metadata["resolver_importance"] = resolved.importance
|
|
108
86
|
}
|
|
109
87
|
|
|
110
|
-
// The postcode
|
|
111
|
-
//
|
|
112
|
-
// than silently trust the resolved point.
|
|
88
|
+
// The postcode pointed to a geographically different place than the parsed city name,
|
|
89
|
+
// surfaced so callers can warn rather than silently trust the resolved point.
|
|
113
90
|
if (resolved.mismatch) {
|
|
114
91
|
node.metadata["postcode_city_mismatch"] = true
|
|
115
92
|
}
|
|
116
93
|
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
// resolved coordinate/identity above is untouched; this just lets a consumer / QA pass see it.
|
|
94
|
+
// A broader admin tier stood in for the true region/county because no exact-type candidate existed.
|
|
95
|
+
// Additive annotation only.
|
|
120
96
|
if (resolved.resolutionQuality) {
|
|
121
97
|
node.metadata["resolution_quality"] = resolved.resolutionQuality
|
|
122
98
|
}
|
package/lib/fold-name.ts
CHANGED
|
@@ -3,27 +3,14 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* One shared name fold
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `@mailwoman/codex`'s `foldName` (`packages/codex/lib/normalize.ts`) is a near twin and is also
|
|
11
|
-
* correct; it differs in collapsing every non-alphanumeric RUN, whitespace included. The two are
|
|
12
|
-
* equivalent on the inputs either sees today. They are kept apart because this one answers to a
|
|
13
|
-
* comparison contract the resolver owns, not because the codex copy is wrong.
|
|
6
|
+
* One shared name fold for the resolver's commune reconciliation, the street tier's locality
|
|
7
|
+
* comparison and span-rescore's key guards. Its own module because those would otherwise import
|
|
8
|
+
* each other for it.
|
|
14
9
|
*/
|
|
15
10
|
|
|
16
11
|
/**
|
|
17
|
-
* Case/diacritic-insensitive fold for commune-name comparison
|
|
18
|
-
*
|
|
19
|
-
* Marks are DELETED, never spaced. `[^a-z0-9 ]` alone maps the combining cedilla that NFD has just produced to a SPACE,
|
|
20
|
-
* so `Besançon` keys as `besanc on` and matches nothing it should. The gazetteer side of the same comparison deletes
|
|
21
|
-
* them — 0 of 32,539 distinct `locality_base` keys in `street-centroids-fr.db` carry a mark — so spacing puts the two
|
|
22
|
-
* halves of one comparison on different keys. Order is required: after the class filter the strip is a no-op.
|
|
23
|
-
*
|
|
24
|
-
* Not fixed here, and worth knowing before trusting the fold on a non-Latin-1 name: a letter with no decomposition is
|
|
25
|
-
* DROPPED rather than folded (`Łódź` → `odz`, `Đà Nẵng` → `a nang`). That needs a transliteration table, not a regex,
|
|
26
|
-
* and it is shared with every other fold in the repo.
|
|
12
|
+
* Case/diacritic-insensitive fold for commune-name comparison: marks are deleted, never spaced, so
|
|
13
|
+
* `Besançon` does not key as `besanc on`; a letter with no decomposition is dropped rather than folded.
|
|
27
14
|
*/
|
|
28
15
|
export function foldName(s: string): string {
|
|
29
16
|
return s
|
package/lib/index.ts
CHANGED
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* `@mailwoman/resolver`
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* what used to be `@mailwoman/core/resolver`.
|
|
6
|
+
* `@mailwoman/resolver` is the address resolver implementation. It depends on
|
|
7
|
+
* `@mailwoman/spatial` (haversine) and `@mailwoman/codex` (USPS directionals) instead of
|
|
8
|
+
* reinventing them. The type interface stays in `@mailwoman/core/resolver`, so `core/pipeline`
|
|
9
|
+
* composes the resolver structurally without a package cycle. This barrel re-exports it, so
|
|
10
|
+
* `@mailwoman/resolver` is a complete drop-in for `@mailwoman/core/resolver`.
|
|
12
11
|
*/
|
|
13
12
|
|
|
14
13
|
export { RemoteResolver, serializableResolveOpts } from "#remote-resolver"
|
|
@@ -60,7 +59,4 @@ export {
|
|
|
60
59
|
|
|
61
60
|
export type { ResolvedPostcodeHit, ResolvedSpecificityInput } from "#admin/winner"
|
|
62
61
|
|
|
63
|
-
// The type contract + placetype helpers live in core (pure types, keep core a leaf). Re-export so
|
|
64
|
-
// consumers get the whole surface from `@mailwoman/resolver`.
|
|
65
|
-
|
|
66
62
|
export * from "#rerank"
|