@mailwoman/resolver 9.1.0 → 9.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -0
- package/lib/admin/coherence-passes.ts +435 -0
- package/lib/admin/containment.ts +92 -0
- package/lib/admin/index.ts +10 -0
- package/lib/admin/jp-municipality.ts +97 -0
- package/lib/admin/winner.ts +189 -0
- package/lib/backend-capabilities.ts +88 -0
- package/lib/bare-toponym-race.ts +129 -0
- package/lib/decorate-node.ts +127 -0
- package/lib/fold-name.ts +36 -0
- package/{index.ts → lib/index.ts} +27 -18
- package/{plausibility.ts → lib/plausibility.ts} +5 -4
- package/{postcode-country-coherence.ts → lib/postcode/country-coherence.ts} +173 -86
- package/lib/postcode/index.ts +9 -0
- package/{postcode-prefix.ts → lib/postcode/prefix.ts} +7 -6
- package/{postcode-shape-coherence.ts → lib/postcode/shape-coherence.ts} +10 -24
- package/{remote-resolver.ts → lib/remote-resolver.ts} +13 -4
- package/{rerank.ts → lib/rerank.ts} +2 -2
- package/lib/resolve/index.ts +982 -0
- package/lib/resolve/passes.ts +544 -0
- package/{span-rescore.ts → lib/span-rescore.ts} +114 -99
- package/{street-evidence.ts → lib/street/evidence.ts} +40 -7
- package/lib/street/index.ts +8 -0
- package/{street-tier.ts → lib/street/tier.ts} +138 -99
- package/{toponym-prior.ts → lib/toponym-prior.ts} +97 -8
- package/out/admin/coherence-passes.d.ts +70 -0
- package/out/admin/coherence-passes.d.ts.map +1 -0
- package/out/admin/coherence-passes.js +327 -0
- package/out/admin/coherence-passes.js.map +1 -0
- package/out/admin/containment.d.ts +48 -0
- package/out/admin/containment.d.ts.map +1 -0
- package/out/admin/containment.js +76 -0
- package/out/admin/containment.js.map +1 -0
- package/out/admin/index.d.ts +10 -0
- package/out/admin/index.d.ts.map +1 -0
- package/out/admin/index.js +10 -0
- package/out/admin/index.js.map +1 -0
- package/out/admin/jp-municipality.d.ts +50 -0
- package/out/admin/jp-municipality.d.ts.map +1 -0
- package/out/admin/jp-municipality.js +54 -0
- package/out/admin/jp-municipality.js.map +1 -0
- package/out/admin/winner.d.ts +114 -0
- package/out/admin/winner.d.ts.map +1 -0
- package/out/admin/winner.js +130 -0
- package/out/admin/winner.js.map +1 -0
- package/out/backend-capabilities.d.ts +37 -0
- package/out/backend-capabilities.d.ts.map +1 -0
- package/out/backend-capabilities.js +75 -0
- package/out/backend-capabilities.js.map +1 -0
- package/out/bare-toponym-race.d.ts +55 -0
- package/out/bare-toponym-race.d.ts.map +1 -0
- package/out/bare-toponym-race.js +110 -0
- package/out/bare-toponym-race.js.map +1 -0
- package/out/decorate-node.d.ts +24 -0
- package/out/decorate-node.d.ts.map +1 -0
- package/out/decorate-node.js +103 -0
- package/out/decorate-node.js.map +1 -0
- package/out/fold-name.d.ts +18 -3
- package/out/fold-name.d.ts.map +1 -1
- package/out/fold-name.js +19 -3
- package/out/fold-name.js.map +1 -1
- package/out/index.d.ts +15 -12
- package/out/index.d.ts.map +1 -1
- package/out/index.js +9 -7
- package/out/index.js.map +1 -1
- package/out/plausibility.d.ts +5 -4
- package/out/plausibility.d.ts.map +1 -1
- package/out/plausibility.js +5 -4
- package/out/plausibility.js.map +1 -1
- package/out/{postcode-country-coherence.d.ts → postcode/country-coherence.d.ts} +46 -25
- package/out/postcode/country-coherence.d.ts.map +1 -0
- package/out/{postcode-country-coherence.js → postcode/country-coherence.js} +157 -77
- package/out/postcode/country-coherence.js.map +1 -0
- package/out/postcode/index.d.ts +9 -0
- package/out/postcode/index.d.ts.map +1 -0
- package/out/postcode/index.js +9 -0
- package/out/postcode/index.js.map +1 -0
- package/out/{postcode-prefix.d.ts → postcode/prefix.d.ts} +4 -4
- package/out/postcode/prefix.d.ts.map +1 -0
- package/out/{postcode-prefix.js → postcode/prefix.js} +7 -6
- package/out/postcode/prefix.js.map +1 -0
- package/out/{postcode-shape-coherence.d.ts → postcode/shape-coherence.d.ts} +3 -3
- package/out/postcode/shape-coherence.d.ts.map +1 -0
- package/out/{postcode-shape-coherence.js → postcode/shape-coherence.js} +11 -20
- package/out/postcode/shape-coherence.js.map +1 -0
- package/out/remote-resolver.d.ts +18 -3
- package/out/remote-resolver.d.ts.map +1 -1
- package/out/remote-resolver.js +2 -2
- package/out/remote-resolver.js.map +1 -1
- package/out/rerank.d.ts +1 -1
- package/out/rerank.d.ts.map +1 -1
- package/out/rerank.js +2 -2
- package/out/rerank.js.map +1 -1
- package/out/{resolve.d.ts → resolve/index.d.ts} +2 -2
- package/out/resolve/index.d.ts.map +1 -0
- package/out/resolve/index.js +795 -0
- package/out/resolve/index.js.map +1 -0
- package/out/resolve/passes.d.ts +218 -0
- package/out/resolve/passes.d.ts.map +1 -0
- package/out/resolve/passes.js +333 -0
- package/out/resolve/passes.js.map +1 -0
- package/out/span-rescore.d.ts +16 -16
- package/out/span-rescore.d.ts.map +1 -1
- package/out/span-rescore.js +87 -71
- package/out/span-rescore.js.map +1 -1
- package/out/{street-evidence.d.ts → street/evidence.d.ts} +18 -3
- package/out/street/evidence.d.ts.map +1 -0
- package/out/{street-evidence.js → street/evidence.js} +23 -7
- package/out/street/evidence.js.map +1 -0
- package/out/street/index.d.ts +8 -0
- package/out/street/index.d.ts.map +1 -0
- package/out/street/index.js +8 -0
- package/out/street/index.js.map +1 -0
- package/out/{street-tier.d.ts → street/tier.d.ts} +14 -3
- package/out/street/tier.d.ts.map +1 -0
- package/out/{street-tier.js → street/tier.js} +127 -90
- package/out/street/tier.js.map +1 -0
- package/out/toponym-prior.d.ts +43 -19
- package/out/toponym-prior.d.ts.map +1 -1
- package/out/toponym-prior.js +76 -8
- package/out/toponym-prior.js.map +1 -1
- package/package.json +167 -19
- package/vitest.config.ts +5 -6
- package/fold-name.ts +0 -20
- package/out/postcode-country-coherence.d.ts.map +0 -1
- package/out/postcode-country-coherence.js.map +0 -1
- package/out/postcode-prefix.d.ts.map +0 -1
- package/out/postcode-prefix.js.map +0 -1
- package/out/postcode-shape-coherence.d.ts.map +0 -1
- package/out/postcode-shape-coherence.js.map +0 -1
- package/out/resolve.d.ts.map +0 -1
- package/out/resolve.js +0 -1049
- package/out/resolve.js.map +0 -1
- package/out/street-evidence.d.ts.map +0 -1
- package/out/street-evidence.js.map +0 -1
- package/out/street-tier.d.ts.map +0 -1
- package/out/street-tier.js.map +0 -1
- package/out/vitest.config.d.ts +0 -16
- package/out/vitest.config.d.ts.map +0 -1
- package/out/vitest.config.js +0 -36
- package/out/vitest.config.js.map +0 -1
- package/resolve.ts +0 -1369
|
@@ -69,23 +69,24 @@
|
|
|
69
69
|
* CONFIRMS it instead.
|
|
70
70
|
*
|
|
71
71
|
* **D-rule: opt-in behind `ResolveOpts.postcodeShapeCoherence`, default-OFF.** Demotion is the
|
|
72
|
-
* failure mode with teeth, so a default-on promotion needs the full pre-registered
|
|
72
|
+
* failure mode with teeth, so a default-on promotion needs the full pre-registered eval (B1-1
|
|
73
73
|
* byte-stability, B1-2 exclusion ≥90% with the correct sibling tag surviving, B1-3 confound ≤2%
|
|
74
74
|
* false exclusions; kill on any B1-3 δ).
|
|
75
75
|
*/
|
|
76
76
|
|
|
77
|
-
import { candidateSystemsForPostcode,
|
|
77
|
+
import { candidateSystemsForPostcode, SYSTEM_CODES } from "@mailwoman/codex"
|
|
78
78
|
import { matchCountry, matchSubdivision } from "@mailwoman/codex/country"
|
|
79
79
|
import { isUSStateAbbreviation } from "@mailwoman/codex/us"
|
|
80
|
-
import type
|
|
80
|
+
import { collectNodes, walkNodes, type AddressNode } from "@mailwoman/core/decoder"
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* The codex address systems a sibling signal can speak for — the universe `candidateSystemsForPostcode` can return, in
|
|
84
84
|
* the upper-case ISO form this module's signals are emitted in (`SystemCode` itself is lower-case). Signals from
|
|
85
85
|
* countries with no codex slice are filtered out BEFORE the intersection test, so a slice-less country can never
|
|
86
|
-
* manufacture an empty intersection (the false-exclusion trap; see the header).
|
|
86
|
+
* manufacture an empty intersection (the false-exclusion trap; see the header). Derived from codex's own list so a
|
|
87
|
+
* system added there is admitted here in the same change.
|
|
87
88
|
*/
|
|
88
|
-
const SYSTEM_UNIVERSE: ReadonlySet<string> = new Set<string>(
|
|
89
|
+
const SYSTEM_UNIVERSE: ReadonlySet<string> = new Set<string>(SYSTEM_CODES.map((system) => system.toUpperCase()))
|
|
89
90
|
|
|
90
91
|
/**
|
|
91
92
|
* The pass's per-tree verdict — the caller (and the B1 board tests) can see exactly which spans were confirmed,
|
|
@@ -119,12 +120,8 @@ export interface PostcodeShapeVerdict {
|
|
|
119
120
|
*/
|
|
120
121
|
function collectSiblingSystems(roots: readonly AddressNode[]): Set<string> {
|
|
121
122
|
const out = new Set<string>()
|
|
122
|
-
const stack: AddressNode[] = [...roots]
|
|
123
|
-
|
|
124
|
-
while (stack.length) {
|
|
125
|
-
const n = stack.pop()!
|
|
126
|
-
stack.push(...n.children)
|
|
127
123
|
|
|
124
|
+
for (const n of walkNodes(roots)) {
|
|
128
125
|
if (n.tag === "country") {
|
|
129
126
|
const matched = matchCountry(n.value)
|
|
130
127
|
|
|
@@ -143,7 +140,7 @@ function collectSiblingSystems(roots: readonly AddressNode[]): Set<string> {
|
|
|
143
140
|
if (n.tag === "region") {
|
|
144
141
|
// (a) The region's value as a subdivision ("CA" → US, "ON" → CA — the US-wins tiebreak for
|
|
145
142
|
// "CA" is matchSubdivision's own). (b) The `country_hint` stamp annotateUSRegions writes on
|
|
146
|
-
// 2-letter US state abbreviations — the same evidence via the pipeline's other
|
|
143
|
+
// 2-letter US state abbreviations — the same evidence via the pipeline's other path.
|
|
147
144
|
const sub = matchSubdivision(n.value)
|
|
148
145
|
|
|
149
146
|
if (sub && SYSTEM_UNIVERSE.has(sub.country.toUpperCase())) {
|
|
@@ -169,20 +166,9 @@ function collectSiblingSystems(roots: readonly AddressNode[]): Set<string> {
|
|
|
169
166
|
export function applyPostcodeShapeCoherence(roots: readonly AddressNode[]): PostcodeShapeVerdict {
|
|
170
167
|
const verdict: PostcodeShapeVerdict = { confirmed: [], excluded: [], abstained: [] }
|
|
171
168
|
|
|
172
|
-
// The postcode spans in
|
|
169
|
+
// The postcode spans in document order — the same walk `firstPostcodeValue` uses, so the verdict's
|
|
173
170
|
// "first confirmed" is the node `state.postcode` will read.
|
|
174
|
-
const postcodes
|
|
175
|
-
const stack: AddressNode[] = [...roots]
|
|
176
|
-
|
|
177
|
-
while (stack.length) {
|
|
178
|
-
const n = stack.pop()!
|
|
179
|
-
|
|
180
|
-
if (n.tag === "postcode" && n.value.trim().length) {
|
|
181
|
-
postcodes.push(n)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
stack.push(...n.children)
|
|
185
|
-
}
|
|
171
|
+
const postcodes = collectNodes(roots, (n) => n.tag === "postcode" && n.value.trim().length > 0)
|
|
186
172
|
|
|
187
173
|
if (!postcodes.length) return verdict
|
|
188
174
|
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
*
|
|
6
6
|
* `RemoteResolver` — the `Resolver` interface (`resolveTree`) over HTTP. The adapter the interface
|
|
7
7
|
* docstring anticipated (Phase 4.4): a client POSTs a parsed `AddressTree` + the serializable
|
|
8
|
-
* `ResolveOpts` to a resolver service, which owns the gazetteer + situs/interpolation
|
|
8
|
+
* `ResolveOpts` to a resolver service, which owns the gazetteer + situs/interpolation extracts,
|
|
9
9
|
* runs the cascade, and returns the resolved tree. Two payoffs:
|
|
10
10
|
*
|
|
11
11
|
* 1. **Multi-instance** — stateless parser nodes (the ~30 MB ONNX model) talk to ONE resolver service
|
|
12
|
-
* (the multi-GB gazetteer +
|
|
12
|
+
* (the multi-GB gazetteer + extracts). `parse` locally, `new RemoteResolver(...).resolveTree`
|
|
13
13
|
* remotely — same interface the in-process `WOFResolver` satisfies, so it's a drop-in.
|
|
14
14
|
* 2. **Canary** — point it at a second resolver build (or an adapter fronting Pelias/Nominatim/BAN)
|
|
15
15
|
* and diff the resolved trees through the identical contract.
|
|
@@ -39,6 +39,11 @@ export function serializableResolveOpts(opts?: ResolveOpts): SerializableResolve
|
|
|
39
39
|
return rest
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
export type RemoteResolverFetch = (
|
|
43
|
+
url: string,
|
|
44
|
+
init: { method: string; headers: Record<string, string>; body: string; signal?: AbortSignal }
|
|
45
|
+
) => Promise<{ ok: boolean; status: number; statusText: string; json(): Promise<unknown> }>
|
|
46
|
+
|
|
42
47
|
export interface RemoteResolverOpts {
|
|
43
48
|
/**
|
|
44
49
|
* Full URL of the resolver service's resolve-tree endpoint, e.g. `http://resolver:7081/v1/resolve`.
|
|
@@ -46,8 +51,12 @@ export interface RemoteResolverOpts {
|
|
|
46
51
|
endpoint: string
|
|
47
52
|
/**
|
|
48
53
|
* Injectable fetch (tests / custom agents). Defaults to the global `fetch`.
|
|
54
|
+
*
|
|
55
|
+
* Typed by what this module reads — `ok`, `status`, `statusText`, `json()` — rather than the full `fetch`, whose
|
|
56
|
+
* `Response` carries a body stream and headers no code here touches. The global `fetch` satisfies this shape, and a
|
|
57
|
+
* test double can be an object instead of an assertion.
|
|
49
58
|
*/
|
|
50
|
-
fetch?:
|
|
59
|
+
fetch?: RemoteResolverFetch
|
|
51
60
|
/**
|
|
52
61
|
* Per-request timeout in ms. Default 10000.
|
|
53
62
|
*/
|
|
@@ -75,7 +84,7 @@ export interface ResolveTreeResponse {
|
|
|
75
84
|
|
|
76
85
|
export class RemoteResolver implements Resolver {
|
|
77
86
|
readonly #endpoint: string
|
|
78
|
-
readonly #fetch:
|
|
87
|
+
readonly #fetch: RemoteResolverFetch
|
|
79
88
|
readonly #timeoutMs: number
|
|
80
89
|
readonly #headers: Record<string, string>
|
|
81
90
|
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
import type { AddressTree } from "@mailwoman/core/decoder"
|
|
34
34
|
|
|
35
|
-
import { isImplausibleResolution } from "
|
|
35
|
+
import { isImplausibleResolution } from "#plausibility"
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* One candidate parse from the k-best decode, with its (within-input comparable) score.
|
|
@@ -107,7 +107,7 @@ export interface RerankOpts {
|
|
|
107
107
|
*
|
|
108
108
|
* **When every resolved candidate is implausible, the model's rank-1 wins.** A reranker that returns nothing is worse
|
|
109
109
|
* than one that defers: "all my evidence says these are all bad" is not grounds to invent a different answer, only
|
|
110
|
-
* grounds to flag low confidence (the Phase-4b ambiguity
|
|
110
|
+
* grounds to flag low confidence (the Phase-4b ambiguity check).
|
|
111
111
|
*/
|
|
112
112
|
export async function rerankByResolution<T>(
|
|
113
113
|
candidates: ReadonlyArray<RerankCandidate<T>>,
|