@mailwoman/resolver 8.1.0 → 8.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/fold-name.ts +20 -0
- package/index.ts +6 -0
- package/out/fold-name.d.ts +13 -0
- package/out/fold-name.d.ts.map +1 -0
- package/out/fold-name.js +20 -0
- package/out/fold-name.js.map +1 -0
- package/out/index.d.ts.map +1 -1
- package/out/index.js.map +1 -1
- package/out/plausibility.d.ts +12 -4
- package/out/plausibility.d.ts.map +1 -1
- package/out/plausibility.js.map +1 -1
- package/out/remote-resolver.d.ts +21 -7
- package/out/remote-resolver.d.ts.map +1 -1
- package/out/remote-resolver.js +3 -1
- package/out/remote-resolver.js.map +1 -1
- package/out/rerank.d.ts +30 -10
- 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.map +1 -1
- package/out/resolve.js +23 -414
- package/out/resolve.js.map +1 -1
- package/out/span-rescore.d.ts +18 -6
- package/out/span-rescore.d.ts.map +1 -1
- package/out/span-rescore.js +13 -6
- package/out/span-rescore.js.map +1 -1
- package/out/street-evidence.d.ts +30 -10
- package/out/street-evidence.d.ts.map +1 -1
- package/out/street-evidence.js +8 -6
- package/out/street-evidence.js.map +1 -1
- package/out/street-tier.d.ts +39 -0
- package/out/street-tier.d.ts.map +1 -0
- package/out/street-tier.js +415 -0
- package/out/street-tier.js.map +1 -0
- package/package.json +4 -4
- package/plausibility.ts +13 -4
- package/remote-resolver.ts +23 -7
- package/rerank.ts +37 -12
- package/resolve.ts +74 -485
- package/span-rescore.ts +33 -11
- package/street-evidence.ts +36 -15
- package/street-tier.ts +498 -0
package/rerank.ts
CHANGED
|
@@ -34,29 +34,47 @@ import type { AddressTree } from "@mailwoman/core/decoder"
|
|
|
34
34
|
|
|
35
35
|
import { isImplausibleResolution } from "./plausibility.ts"
|
|
36
36
|
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* One candidate parse from the k-best decode, with its (within-input comparable) score.
|
|
39
|
+
*/
|
|
38
40
|
export interface RerankCandidate<T = unknown> {
|
|
39
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* The parse's own score. Comparable to its siblings from the SAME input; not across inputs.
|
|
43
|
+
*/
|
|
40
44
|
score: number
|
|
41
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* The parse tree, UNRESOLVED — `rerankByResolution` resolves it via the injected resolver.
|
|
47
|
+
*/
|
|
42
48
|
tree: AddressTree
|
|
43
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Opaque caller payload carried through to the result (the segmentation, a surface string, …).
|
|
51
|
+
*/
|
|
44
52
|
payload?: T
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
export interface RerankedCandidate<T = unknown> extends RerankCandidate<T> {
|
|
48
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* The resolved tree (the resolver's output), or null when resolution threw.
|
|
58
|
+
*/
|
|
49
59
|
resolved: AddressTree | null
|
|
50
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* True when the resolution is implausible (today: resolves no finer than a country centroid).
|
|
62
|
+
*/
|
|
51
63
|
implausible: boolean
|
|
52
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* Why it was vetoed, when it was.
|
|
66
|
+
*/
|
|
53
67
|
reason?: string
|
|
54
68
|
}
|
|
55
69
|
|
|
56
70
|
export interface RerankResult<T = unknown> {
|
|
57
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* Candidates in FINAL order: plausible ones first (model order preserved), vetoed ones after.
|
|
73
|
+
*/
|
|
58
74
|
ranked: Array<RerankedCandidate<T>>
|
|
59
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* The winner — the first plausible candidate, or the model's rank-1 when ALL were vetoed.
|
|
77
|
+
*/
|
|
60
78
|
best: RerankedCandidate<T>
|
|
61
79
|
/**
|
|
62
80
|
* True when the winner is NOT the model's rank-1 — i.e. resolution evidence actually changed the answer. This is the
|
|
@@ -66,7 +84,9 @@ export interface RerankResult<T = unknown> {
|
|
|
66
84
|
changed: boolean
|
|
67
85
|
}
|
|
68
86
|
|
|
69
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Resolve a tree. Structural — any `Resolver`-shaped thing satisfies it.
|
|
89
|
+
*/
|
|
70
90
|
export type ResolveTree = (tree: AddressTree) => Promise<AddressTree>
|
|
71
91
|
|
|
72
92
|
export interface RerankOpts {
|
|
@@ -94,7 +114,7 @@ export async function rerankByResolution<T>(
|
|
|
94
114
|
resolveTree: ResolveTree,
|
|
95
115
|
opts: RerankOpts = {}
|
|
96
116
|
): Promise<RerankResult<T>> {
|
|
97
|
-
if (candidates.length
|
|
117
|
+
if (!candidates.length) throw new Error("rerankByResolution: candidates must not be empty")
|
|
98
118
|
const maxResolve = Math.max(1, Math.min(opts.maxResolve ?? 5, candidates.length))
|
|
99
119
|
const ranked: Array<RerankedCandidate<T>> = []
|
|
100
120
|
|
|
@@ -104,9 +124,11 @@ export async function rerankByResolution<T>(
|
|
|
104
124
|
if (i >= maxResolve) {
|
|
105
125
|
// Beyond the resolve budget: carried through unresolved, never vetoed.
|
|
106
126
|
ranked.push({ ...candidate, resolved: null, implausible: false })
|
|
127
|
+
|
|
107
128
|
continue
|
|
108
129
|
}
|
|
109
|
-
|
|
130
|
+
|
|
131
|
+
let resolved: AddressTree | null
|
|
110
132
|
|
|
111
133
|
try {
|
|
112
134
|
resolved = await resolveTree(candidate.tree)
|
|
@@ -114,9 +136,12 @@ export async function rerankByResolution<T>(
|
|
|
114
136
|
// A resolver failure is NOT evidence against the parse — treat it as "no evidence" and let
|
|
115
137
|
// the model's rank stand, rather than vetoing a possibly-correct hypothesis on an outage.
|
|
116
138
|
ranked.push({ ...candidate, resolved: null, implausible: false })
|
|
139
|
+
|
|
117
140
|
continue
|
|
118
141
|
}
|
|
142
|
+
|
|
119
143
|
const verdict = isImplausibleResolution(resolved)
|
|
144
|
+
|
|
120
145
|
ranked.push({
|
|
121
146
|
...candidate,
|
|
122
147
|
resolved,
|