@mailwoman/resolver 8.0.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.
Files changed (45) hide show
  1. package/fold-name.ts +20 -0
  2. package/index.ts +13 -2
  3. package/out/fold-name.d.ts +13 -0
  4. package/out/fold-name.d.ts.map +1 -0
  5. package/out/fold-name.js +20 -0
  6. package/out/fold-name.js.map +1 -0
  7. package/out/index.d.ts +2 -2
  8. package/out/index.d.ts.map +1 -1
  9. package/out/index.js +1 -1
  10. package/out/index.js.map +1 -1
  11. package/out/plausibility.d.ts +40 -6
  12. package/out/plausibility.d.ts.map +1 -1
  13. package/out/plausibility.js +24 -5
  14. package/out/plausibility.js.map +1 -1
  15. package/out/remote-resolver.d.ts +21 -7
  16. package/out/remote-resolver.d.ts.map +1 -1
  17. package/out/remote-resolver.js +3 -1
  18. package/out/remote-resolver.js.map +1 -1
  19. package/out/rerank.d.ts +30 -10
  20. package/out/rerank.d.ts.map +1 -1
  21. package/out/rerank.js +2 -2
  22. package/out/rerank.js.map +1 -1
  23. package/out/resolve.d.ts.map +1 -1
  24. package/out/resolve.js +29 -410
  25. package/out/resolve.js.map +1 -1
  26. package/out/span-rescore.d.ts +18 -6
  27. package/out/span-rescore.d.ts.map +1 -1
  28. package/out/span-rescore.js +13 -6
  29. package/out/span-rescore.js.map +1 -1
  30. package/out/street-evidence.d.ts +30 -10
  31. package/out/street-evidence.d.ts.map +1 -1
  32. package/out/street-evidence.js +8 -6
  33. package/out/street-evidence.js.map +1 -1
  34. package/out/street-tier.d.ts +39 -0
  35. package/out/street-tier.d.ts.map +1 -0
  36. package/out/street-tier.js +415 -0
  37. package/out/street-tier.js.map +1 -0
  38. package/package.json +4 -4
  39. package/plausibility.ts +51 -9
  40. package/remote-resolver.ts +23 -7
  41. package/rerank.ts +37 -12
  42. package/resolve.ts +80 -481
  43. package/span-rescore.ts +33 -11
  44. package/street-evidence.ts +36 -15
  45. 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
- /** One candidate parse from the k-best decode, with its (within-input comparable) score. */
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
- /** The parse's own score. Comparable to its siblings from the SAME input; not across inputs. */
41
+ /**
42
+ * The parse's own score. Comparable to its siblings from the SAME input; not across inputs.
43
+ */
40
44
  score: number
41
- /** The parse tree, UNRESOLVED — `rerankByResolution` resolves it via the injected resolver. */
45
+ /**
46
+ * The parse tree, UNRESOLVED — `rerankByResolution` resolves it via the injected resolver.
47
+ */
42
48
  tree: AddressTree
43
- /** Opaque caller payload carried through to the result (the segmentation, a surface string, …). */
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
- /** The resolved tree (the resolver's output), or null when resolution threw. */
56
+ /**
57
+ * The resolved tree (the resolver's output), or null when resolution threw.
58
+ */
49
59
  resolved: AddressTree | null
50
- /** True when the resolution is implausible (today: resolves no finer than a country centroid). */
60
+ /**
61
+ * True when the resolution is implausible (today: resolves no finer than a country centroid).
62
+ */
51
63
  implausible: boolean
52
- /** Why it was vetoed, when it was. */
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
- /** Candidates in FINAL order: plausible ones first (model order preserved), vetoed ones after. */
71
+ /**
72
+ * Candidates in FINAL order: plausible ones first (model order preserved), vetoed ones after.
73
+ */
58
74
  ranked: Array<RerankedCandidate<T>>
59
- /** The winner — the first plausible candidate, or the model's rank-1 when ALL were vetoed. */
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
- /** Resolve a tree. Structural — any `Resolver`-shaped thing satisfies it. */
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 === 0) throw new Error("rerankByResolution: candidates must not be empty")
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
- let resolved: AddressTree | null = null
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,