@mailwoman/resolver 10.0.0 → 10.2.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 +31 -172
- package/lib/admin/containment.ts +15 -33
- package/lib/admin/jp-municipality.ts +21 -14
- package/lib/admin/winner.ts +37 -69
- package/lib/backend-capabilities.ts +28 -27
- package/lib/bare-toponym-race.ts +69 -37
- package/lib/decorate-node.ts +25 -49
- package/lib/fold-name.ts +5 -18
- package/lib/index.ts +5 -9
- package/lib/plausibility.ts +41 -68
- package/lib/postcode/country-coherence.ts +92 -296
- package/lib/postcode/prefix.ts +24 -86
- package/lib/postcode/shape-coherence.ts +26 -116
- package/lib/remote-resolver.ts +38 -33
- package/lib/rerank.ts +41 -54
- package/lib/resolve/passes.ts +188 -177
- package/lib/resolve.ts +744 -0
- package/lib/span-rescore.ts +219 -175
- package/lib/street/evidence.ts +65 -73
- package/lib/street/tier.ts +51 -194
- package/lib/toponym-prior.ts +54 -180
- package/out/admin/coherence-passes.d.ts +18 -69
- package/out/admin/coherence-passes.d.ts.map +1 -1
- package/out/admin/coherence-passes.js +24 -166
- package/out/admin/coherence-passes.js.map +1 -1
- package/out/admin/containment.d.ts +13 -31
- package/out/admin/containment.d.ts.map +1 -1
- package/out/admin/containment.js +13 -31
- package/out/admin/containment.js.map +1 -1
- package/out/admin/jp-municipality.d.ts +21 -14
- 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 +32 -64
- package/out/admin/winner.d.ts.map +1 -1
- package/out/admin/winner.js +23 -56
- 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 +19 -20
- package/out/backend-capabilities.d.ts.map +1 -1
- package/out/backend-capabilities.js +28 -26
- 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 +25 -49
- 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 +30 -60
- package/out/plausibility.d.ts.map +1 -1
- package/out/plausibility.js +19 -52
- package/out/plausibility.js.map +1 -1
- package/out/postcode/country-coherence.d.ts +53 -167
- package/out/postcode/country-coherence.d.ts.map +1 -1
- package/out/postcode/country-coherence.js +42 -259
- package/out/postcode/country-coherence.js.map +1 -1
- package/out/postcode/prefix.d.ts +18 -69
- package/out/postcode/prefix.d.ts.map +1 -1
- package/out/postcode/prefix.js +11 -78
- package/out/postcode/prefix.js.map +1 -1
- package/out/postcode/shape-coherence.d.ts +18 -85
- package/out/postcode/shape-coherence.d.ts.map +1 -1
- package/out/postcode/shape-coherence.js +11 -107
- 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 +32 -31
- package/out/remote-resolver.d.ts.map +1 -1
- package/out/remote-resolver.js +12 -20
- package/out/remote-resolver.js.map +1 -1
- package/out/rerank.d.ts +32 -46
- package/out/rerank.d.ts.map +1 -1
- package/out/rerank.js +16 -41
- package/out/rerank.js.map +1 -1
- package/out/resolve/passes.d.ts +108 -95
- package/out/resolve/passes.d.ts.map +1 -1
- package/out/resolve/passes.js +67 -126
- 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 +557 -0
- package/out/resolve.js.map +1 -0
- package/out/span-rescore.d.ts +56 -65
- package/out/span-rescore.d.ts.map +1 -1
- package/out/span-rescore.js +134 -132
- 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 +18 -30
- package/out/street/tier.d.ts.map +1 -1
- package/out/street/tier.js +43 -191
- 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 +22 -110
- 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/street/evidence.ts
CHANGED
|
@@ -2,62 +2,46 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* #727 stage-2 phase 4c — street-NAME existence as the k-best arbiter signal.
|
|
7
|
-
*
|
|
8
|
-
* Phase 4a measured the planned arbiter (full-geocode resolution tier) at exactly ZERO collected
|
|
9
|
-
* headroom: the failing class is context-free fragments, which never reach rooftop layers, so
|
|
10
|
-
* every hypothesis ties at admin tier. The corrected signal is street-NAME existence — "does this
|
|
11
|
-
* hypothesis's street surface exist as a street name in the national register?" — which IS
|
|
12
|
-
* queryable for a bare fragment. Measured on the FR fragment board over the v3.10.1 8k span model:
|
|
13
|
-
* the rerank collects +6.0pp street@1 (0.791 → 0.851), 96 fixes / 3 breaks (32:1), the value
|
|
14
|
-
* concentrated on the date-name class (+16.7pp). Receipts:
|
|
15
|
-
* `docs/articles/evals/2026-07-17-v3101-span-head-8k-result.md`, spec
|
|
16
|
-
* `docs/superpowers/specs/2026-07-17-727-phase4c-street-name-evidence.md`.
|
|
17
|
-
*
|
|
18
|
-
* THE ANTI-PELIAS RULE (shared with `rerank.ts`): ONE bit of evidence, not a score. We do NOT
|
|
19
|
-
* blend the name signal into the parse scores — those already share a partition function and rank
|
|
20
|
-
* fine within an input. The reranker's only job is to prefer a sibling hypothesis whose street the
|
|
21
|
-
* world confirms exists, over a rank-1 whose street it does not. Positive evidence only: the
|
|
22
|
-
* ABSENCE of a name is never evidence against a parse (index incompleteness is the default state
|
|
23
|
-
* of the world), so the policy always fails open to the model's own ranking.
|
|
24
|
-
*
|
|
25
|
-
* This module is PURE — the interface + the fold + the measured pick policy, no SQLite. The FR BAN
|
|
26
|
-
* backend lives in `@mailwoman/resolver-wof-sqlite` (`SQLiteStreetNameLookup`); callers inject it,
|
|
27
|
-
* mirroring the `PlaceLookup` pattern.
|
|
28
5
|
*/
|
|
29
6
|
|
|
30
7
|
import type { Exclusion } from "@mailwoman/evidence"
|
|
31
8
|
|
|
32
9
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
10
|
+
* Answers whether a street name exists, optionally within a locality or postcode,
|
|
11
|
+
* for the countries a backend such as BAN street centroids covers.
|
|
35
12
|
*/
|
|
36
13
|
export interface StreetLocalityEvidence {
|
|
37
14
|
/**
|
|
38
|
-
*
|
|
39
|
-
* carries one (fragments usually don't; unscoped is the measured mode). The implementation is responsible for folding
|
|
40
|
-
* the surface with {@link foldStreetSurface} so the caller passes raw text.
|
|
15
|
+
* Returns whether the raw street surface exists as a street name within `scope`, when provided.
|
|
41
16
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
17
|
+
* The implementation folds the surface itself.
|
|
18
|
+
* It returns `false` when an index is missing or a read fails.
|
|
19
|
+
* A `false` answer only withholds promotion.
|
|
44
20
|
*/
|
|
45
21
|
hasStreetName(streetSurface: string, scope?: StreetEvidenceScope): boolean
|
|
22
|
+
|
|
46
23
|
/**
|
|
47
|
-
*
|
|
24
|
+
* The upper-case ISO 3166-1 alpha-2 countries this instance covers.
|
|
48
25
|
*/
|
|
49
26
|
readonly countries: ReadonlySet<string>
|
|
50
27
|
}
|
|
51
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Narrows a street-name existence probe to a locality, a postcode, or both.
|
|
31
|
+
*/
|
|
52
32
|
export interface StreetEvidenceScope {
|
|
53
33
|
locality?: string
|
|
54
34
|
postcode?: string
|
|
55
35
|
}
|
|
56
36
|
|
|
57
37
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
38
|
+
* Folds a street surface the same way for index build and lookup.
|
|
39
|
+
*
|
|
40
|
+
* It strips diacritics and lowercases.
|
|
41
|
+
* It turns hyphens and dashes into spaces.
|
|
42
|
+
*
|
|
43
|
+
* It maps apostrophes to spaces too.
|
|
44
|
+
* It also collapses whitespace.
|
|
61
45
|
*/
|
|
62
46
|
export function foldStreetSurface(surface: string): string {
|
|
63
47
|
return surface
|
|
@@ -69,12 +53,6 @@ export function foldStreetSurface(surface: string): string {
|
|
|
69
53
|
.trim()
|
|
70
54
|
}
|
|
71
55
|
|
|
72
|
-
/**
|
|
73
|
-
* FR street-type + particle vocabulary — the G1 guard. A street surface made ONLY of these words carries no NAME (bare
|
|
74
|
-
* `rue`/`chemin` is a truncation, and it IS in the index), so it earns no evidence credit. Folded forms (particles are
|
|
75
|
-
* pre-folded: `l'` → `l`). Kept small and lexical — it is a dictionary fact, not a tuned weight (the anti-Pelias
|
|
76
|
-
* line).
|
|
77
|
-
*/
|
|
78
56
|
const FR_STREET_TYPE_WORDS: ReadonlySet<string> = new Set([
|
|
79
57
|
"rue",
|
|
80
58
|
"avenue",
|
|
@@ -112,10 +90,11 @@ const FR_STREET_TYPE_WORDS: ReadonlySet<string> = new Set([
|
|
|
112
90
|
])
|
|
113
91
|
|
|
114
92
|
/**
|
|
115
|
-
*
|
|
93
|
+
* Returns true when a folded street surface is empty or consists only of French
|
|
94
|
+
* street-type words and particles, such as "rue de la".
|
|
116
95
|
*/
|
|
117
96
|
export function isPureTypeVocabulary(foldedSurface: string): boolean {
|
|
118
|
-
const tokens = foldedSurface.split(" ").filter((value) => value.length
|
|
97
|
+
const tokens = foldedSurface.split(" ").filter((value) => value.length)
|
|
119
98
|
|
|
120
99
|
if (!tokens.length) return true
|
|
121
100
|
|
|
@@ -123,75 +102,93 @@ export function isPureTypeVocabulary(foldedSurface: string): boolean {
|
|
|
123
102
|
}
|
|
124
103
|
|
|
125
104
|
/**
|
|
126
|
-
* One candidate parse for
|
|
105
|
+
* One candidate parse for {@link pickByStreetEvidence}; scores are comparable
|
|
106
|
+
* only among candidates for the same input.
|
|
127
107
|
*/
|
|
128
108
|
export interface StreetCandidate<T = unknown> {
|
|
129
109
|
/**
|
|
130
|
-
* The candidate's
|
|
110
|
+
* The candidate's raw street surface.
|
|
111
|
+
*
|
|
112
|
+
* An empty string means the parse found no street.
|
|
113
|
+
* Evidence skips that candidate.
|
|
131
114
|
*/
|
|
132
115
|
streetSurface: string
|
|
116
|
+
|
|
133
117
|
/**
|
|
134
|
-
* The parse score,
|
|
118
|
+
* The parse score, where higher is better.
|
|
135
119
|
*/
|
|
136
120
|
score: number
|
|
121
|
+
|
|
137
122
|
/**
|
|
138
|
-
*
|
|
123
|
+
* An opaque caller value, such as the segmentation or tree, returned unchanged with the pick.
|
|
139
124
|
*/
|
|
140
125
|
payload?: T
|
|
141
126
|
}
|
|
142
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Options for {@link pickByStreetEvidence}.
|
|
130
|
+
*/
|
|
143
131
|
export interface PickByStreetEvidenceOpts {
|
|
144
132
|
/**
|
|
145
|
-
*
|
|
133
|
+
* The locality or postcode scope passed to {@link StreetLocalityEvidence.hasStreetName}.
|
|
146
134
|
*/
|
|
147
135
|
scope?: StreetEvidenceScope
|
|
136
|
+
|
|
148
137
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* v2 board measured (148 fixes / 3 breaks). UNCALIBRATED across models: re-fit when the span head retrains, since raw
|
|
152
|
-
* score margins are not comparable across models. (Plan #1134 pre-registers an isotonic ambiguity check to replace
|
|
153
|
-
* it.)
|
|
138
|
+
* The largest score gap below rank 1 at which evidence may still promote a candidate.
|
|
139
|
+
* it defaults to 2.5 and needs refitting when the span head is retrained.
|
|
154
140
|
*/
|
|
155
141
|
marginCap?: number
|
|
142
|
+
|
|
156
143
|
/**
|
|
157
|
-
* One entry per candidate,
|
|
158
|
-
* considered only after every un-excluded sibling. It is never removed: with every candidate excluded the pick is
|
|
159
|
-
* still rank-1, because the worst case this policy accepts is the model's own ranking.
|
|
144
|
+
* One entry per candidate, in the same order.
|
|
160
145
|
*
|
|
161
|
-
*
|
|
146
|
+
* A non-null entry moves that candidate behind every candidate without an exclusion.
|
|
147
|
+
* If every candidate has an exclusion, the fallback pick is rank 1.
|
|
162
148
|
*/
|
|
163
149
|
exclusions?: ReadonlyArray<Exclusion | null>
|
|
164
150
|
}
|
|
165
151
|
|
|
152
|
+
/**
|
|
153
|
+
* The result of {@link pickByStreetEvidence}.
|
|
154
|
+
*/
|
|
166
155
|
export interface StreetEvidencePick<T = unknown> {
|
|
167
156
|
/**
|
|
168
|
-
* The
|
|
157
|
+
* The first candidate that passes the evidence checks, or the first non-excluded
|
|
158
|
+
* candidate when none passes.
|
|
169
159
|
*/
|
|
170
160
|
candidate: StreetCandidate<T>
|
|
161
|
+
|
|
171
162
|
/**
|
|
172
|
-
*
|
|
163
|
+
* The chosen candidate's index in the input array.
|
|
173
164
|
*/
|
|
174
165
|
index: number
|
|
166
|
+
|
|
175
167
|
/**
|
|
176
|
-
*
|
|
168
|
+
* Whether the pick differs from rank 1, through evidence or because rank 1 was excluded.
|
|
177
169
|
*/
|
|
178
170
|
moved: boolean
|
|
171
|
+
|
|
179
172
|
/**
|
|
180
|
-
*
|
|
181
|
-
* coverage check licensed, distinct from what evidence found.
|
|
173
|
+
* The input indexes that exclusions demoted, in input order.
|
|
182
174
|
*/
|
|
183
175
|
demoted: number[]
|
|
184
176
|
}
|
|
185
177
|
|
|
186
178
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
179
|
+
* Checks candidates in score order.
|
|
180
|
+
*
|
|
181
|
+
* Selects the first candidate that meets all three checks.
|
|
182
|
+
* Its street name exists in the evidence index.
|
|
183
|
+
*
|
|
184
|
+
* The name contains more than street-type words.
|
|
185
|
+
* Its score falls within `marginCap` of rank 1.
|
|
186
|
+
*
|
|
187
|
+
* Excluded candidates are checked after all others.
|
|
188
|
+
* The first candidate without an exclusion wins when no candidate passes the evidence checks.
|
|
193
189
|
*
|
|
194
|
-
* @param candidates Parse candidates
|
|
190
|
+
* @param candidates Parse candidates sorted by score, rank 1 first.
|
|
191
|
+
* @throws When `candidates` is empty.
|
|
195
192
|
*/
|
|
196
193
|
export function pickByStreetEvidence<T>(
|
|
197
194
|
candidates: ReadonlyArray<StreetCandidate<T>>,
|
|
@@ -217,7 +214,6 @@ export function pickByStreetEvidence<T>(
|
|
|
217
214
|
}
|
|
218
215
|
}
|
|
219
216
|
|
|
220
|
-
// An excluded candidate is considered only after every un-excluded sibling; it is never dropped.
|
|
221
217
|
const order = demoted.length ? [...considered, ...demoted] : considered
|
|
222
218
|
|
|
223
219
|
for (const i of order) {
|
|
@@ -225,10 +221,8 @@ export function pickByStreetEvidence<T>(
|
|
|
225
221
|
|
|
226
222
|
if (!c.streetSurface) continue
|
|
227
223
|
|
|
228
|
-
// G2: the margin is measured from rank-1's score, whatever position the candidate is considered at.
|
|
229
224
|
if (topScore - c.score > marginCap) continue
|
|
230
225
|
|
|
231
|
-
// G1: a pure street-type/particle surface (bare `rue`) carries no name — no evidence credit.
|
|
232
226
|
if (isPureTypeVocabulary(foldStreetSurface(c.streetSurface))) continue
|
|
233
227
|
|
|
234
228
|
if (evidence.hasStreetName(c.streetSurface, opts.scope)) {
|
|
@@ -236,8 +230,6 @@ export function pickByStreetEvidence<T>(
|
|
|
236
230
|
}
|
|
237
231
|
}
|
|
238
232
|
|
|
239
|
-
// Fail-open: the first un-excluded candidate, which is rank-1 unless an exclusion demoted it, and rank-1 again when
|
|
240
|
-
// every candidate is excluded.
|
|
241
233
|
const fallback = order[0] ?? 0
|
|
242
234
|
|
|
243
235
|
return { candidate: candidates[fallback]!, index: fallback, moved: fallback > 0, demoted }
|