@mailwoman/resolver 6.5.0 → 7.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/out/index.d.ts +3 -0
- package/out/index.d.ts.map +1 -1
- package/out/index.js +2 -0
- package/out/index.js.map +1 -1
- package/out/plausibility.d.ts +21 -5
- package/out/plausibility.d.ts.map +1 -1
- package/out/plausibility.js +42 -3
- package/out/plausibility.js.map +1 -1
- package/out/rerank.d.ts +84 -0
- package/out/rerank.d.ts.map +1 -0
- package/out/rerank.js +81 -0
- package/out/rerank.js.map +1 -0
- package/out/street-evidence.d.ts +97 -0
- package/out/street-evidence.d.ts.map +1 -0
- package/out/street-evidence.js +123 -0
- package/out/street-evidence.js.map +1 -0
- package/package.json +4 -4
package/out/index.d.ts
CHANGED
|
@@ -15,7 +15,10 @@ export type { RemoteResolverOpts, ResolveTreeRequest, ResolveTreeResponse, Seria
|
|
|
15
15
|
export { createWOFResolver } from "./resolve.ts";
|
|
16
16
|
export { finestResolvedCoordinate, isImplausibleResolution } from "./plausibility.ts";
|
|
17
17
|
export type { PlausibilityVerdict, ResolvedCoordinate } from "./plausibility.ts";
|
|
18
|
+
export { foldStreetSurface, isPureTypeVocabulary, pickByStreetEvidence } from "./street-evidence.ts";
|
|
19
|
+
export type { PickByStreetEvidenceOpts, StreetCandidate, StreetEvidencePick, StreetEvidenceScope, StreetLocalityEvidence, } from "./street-evidence.ts";
|
|
18
20
|
export { findRescoreCandidate, hasResolvedPlace } from "./span-rescore.ts";
|
|
19
21
|
export type { RescoreCandidate, SpanRescoreOptions } from "./span-rescore.ts";
|
|
20
22
|
export * from "@mailwoman/core/resolver";
|
|
23
|
+
export * from "./rerank.ts";
|
|
21
24
|
//# sourceMappingURL=index.d.ts.map
|
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;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AAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAI7E,cAAc,0BAA0B,CAAA;AAExC,cAAc,aAAa,CAAA"}
|
package/out/index.js
CHANGED
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
export { RemoteResolver, serializableResolveOpts } from "./remote-resolver.js";
|
|
14
14
|
export { createWOFResolver } from "./resolve.js";
|
|
15
15
|
export { finestResolvedCoordinate, isImplausibleResolution } from "./plausibility.js";
|
|
16
|
+
export { foldStreetSurface, isPureTypeVocabulary, pickByStreetEvidence } from "./street-evidence.js";
|
|
16
17
|
export { findRescoreCandidate, hasResolvedPlace } from "./span-rescore.js";
|
|
17
18
|
// The type contract + placetype helpers live in core (pure types, keep core a leaf). Re-export so
|
|
18
19
|
// consumers get the whole surface from `@mailwoman/resolver`.
|
|
19
20
|
export * from "@mailwoman/core/resolver";
|
|
21
|
+
export * from "./rerank.js";
|
|
20
22
|
//# sourceMappingURL=index.js.map
|
package/out/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAO9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAErF,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAG1E,kGAAkG;AAClG,8DAA8D;AAC9D,cAAc,0BAA0B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAO9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAErF,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAQpG,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAG1E,kGAAkG;AAClG,8DAA8D;AAC9D,cAAc,0BAA0B,CAAA;AAExC,cAAc,aAAa,CAAA"}
|
package/out/plausibility.d.ts
CHANGED
|
@@ -39,18 +39,34 @@ export interface ResolvedCoordinate {
|
|
|
39
39
|
* Ties break toward the first node in document order.
|
|
40
40
|
*/
|
|
41
41
|
export declare function finestResolvedCoordinate(tree: AddressTree): ResolvedCoordinate | null;
|
|
42
|
+
/** True when the coordinate lies outside `countryCode`'s coarse bbox. Unknown country codes are fail-open (false). */
|
|
43
|
+
export declare function outsideExpectedCountry(countryCode: string, lat: number, lon: number): boolean;
|
|
42
44
|
/** Result of {@link isImplausibleResolution} — the boolean plus the reason, for telemetry + fallback logs. */
|
|
43
45
|
export interface PlausibilityVerdict {
|
|
44
46
|
implausible: boolean;
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Set when `implausible` is true. `country-centroid` = resolved no finer than a country (guard A);
|
|
49
|
+
* `outside-expected-country` = the served coordinate lies outside the expected country's bbox (guard B).
|
|
50
|
+
*/
|
|
51
|
+
reason?: "country-centroid" | "outside-expected-country";
|
|
47
52
|
/** The coordinate the verdict was drawn from, when anything resolved. */
|
|
48
53
|
coordinate?: ResolvedCoordinate;
|
|
49
54
|
}
|
|
55
|
+
export interface PlausibilityOpts {
|
|
56
|
+
/**
|
|
57
|
+
* ISO-2 country the resolution is EXPECTED to land in, when the caller knows it (a locale hint, a parsed country, a
|
|
58
|
+
* fixture's gold country). Enables guard B: a coordinate outside this country's coarse bbox is implausible — the
|
|
59
|
+
* cross-country-jump class guard A structurally cannot catch (`1210a IA 10 W IA` → a coordinate ~10,000 km from the
|
|
60
|
+
* US was country-centroid-free and sailed through until guard B landed here, 2026-07-17; previously the check lived
|
|
61
|
+
* only in the receipt harness, so the shipped residual read 5/321 while the receipt said 3/321).
|
|
62
|
+
*/
|
|
63
|
+
expectedCountry?: string;
|
|
64
|
+
}
|
|
50
65
|
/**
|
|
51
66
|
* Decide whether a resolved tree's geocode is implausible for a structured address — the cheap guard the v7 hybrid gate
|
|
52
|
-
* runs after routing an input to the neural parser (#38). Trips
|
|
53
|
-
* centroid
|
|
67
|
+
* runs after routing an input to the neural parser (#38). Trips when the finest resolved place is a bare `country`
|
|
68
|
+
* centroid (guard A), or — when the caller supplies `expectedCountry` — when the served coordinate falls outside that
|
|
69
|
+
* country's coarse bbox (guard B). An unresolved tree (nothing to serve) is plausible: there is no garbage to serve.
|
|
54
70
|
*/
|
|
55
|
-
export declare function isImplausibleResolution(tree: AddressTree): PlausibilityVerdict;
|
|
71
|
+
export declare function isImplausibleResolution(tree: AddressTree, opts?: PlausibilityOpts): PlausibilityVerdict;
|
|
56
72
|
//# sourceMappingURL=plausibility.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plausibility.d.ts","sourceRoot":"","sources":["../plausibility.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAe,WAAW,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAqBrF,4GAA4G;AAC5G,MAAM,WAAW,kBAAkB;IAClC,GAAG,EAAE,YAAY,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,GAAG,kBAAkB,GAAG,IAAI,CAwBrF;AAED,8GAA8G;AAC9G,MAAM,WAAW,mBAAmB;IACnC,WAAW,EAAE,OAAO,CAAA;IACpB
|
|
1
|
+
{"version":3,"file":"plausibility.d.ts","sourceRoot":"","sources":["../plausibility.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAe,WAAW,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAqBrF,4GAA4G;AAC5G,MAAM,WAAW,kBAAkB;IAClC,GAAG,EAAE,YAAY,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,GAAG,kBAAkB,GAAG,IAAI,CAwBrF;AA6BD,sHAAsH;AACtH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAM7F;AAED,8GAA8G;AAC9G,MAAM,WAAW,mBAAmB;IACnC,WAAW,EAAE,OAAO,CAAA;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,kBAAkB,GAAG,0BAA0B,CAAA;IACxD,yEAAyE;IACzE,UAAU,CAAC,EAAE,kBAAkB,CAAA;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAChC;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,GAAE,gBAAqB,GAAG,mBAAmB,CAgB3G"}
|
package/out/plausibility.js
CHANGED
|
@@ -67,16 +67,55 @@ export function finestResolvedCoordinate(tree) {
|
|
|
67
67
|
}
|
|
68
68
|
return best;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Coarse per-country bounding boxes `[latMin, latMax, lonMin, lonMax]` for the cross-country guard (guard B). These are
|
|
72
|
+
* DELIBERATELY rough — a guard needs "obviously the wrong country", not cartography — and they mirror the boxes the
|
|
73
|
+
* 2026-07-15 coordinate-parity receipt harness measured with (`scratchpad/coord-parity.mjs`). The US box spans Alaska →
|
|
74
|
+
* the mainland east coast; continental FR only; etc. A country absent here simply never trips the guard (fail-open).
|
|
75
|
+
*/
|
|
76
|
+
const COUNTRY_BBOX = {
|
|
77
|
+
US: [18, 72, -180, -66],
|
|
78
|
+
AU: [-44, -10, 112, 154],
|
|
79
|
+
BR: [-34, 6, -74, -34],
|
|
80
|
+
CZ: [48, 51.5, 12, 19],
|
|
81
|
+
DE: [47, 55.5, 5.5, 15.5],
|
|
82
|
+
ES: [35, 44, -10, 5],
|
|
83
|
+
FR: [41, 51.5, -5.5, 9.8],
|
|
84
|
+
GB: [49, 61, -8.7, 2],
|
|
85
|
+
HR: [42, 46.6, 13, 19.5],
|
|
86
|
+
IN: [6, 36, 68, 98],
|
|
87
|
+
NL: [50.7, 53.7, 3.3, 7.3],
|
|
88
|
+
NO: [57, 71.5, 4, 31],
|
|
89
|
+
PL: [49, 55, 14, 24.2],
|
|
90
|
+
PT: [36.5, 42.2, -9.6, -6.1],
|
|
91
|
+
RO: [43.5, 48.3, 20, 30],
|
|
92
|
+
SE: [55, 69.1, 10.9, 24.2],
|
|
93
|
+
SK: [47.7, 49.7, 16.8, 22.6],
|
|
94
|
+
SI: [45.4, 46.9, 13.3, 16.6],
|
|
95
|
+
};
|
|
96
|
+
/** True when the coordinate lies outside `countryCode`'s coarse bbox. Unknown country codes are fail-open (false). */
|
|
97
|
+
export function outsideExpectedCountry(countryCode, lat, lon) {
|
|
98
|
+
const b = COUNTRY_BBOX[countryCode.toUpperCase()];
|
|
99
|
+
if (!b)
|
|
100
|
+
return false;
|
|
101
|
+
return lat < b[0] || lat > b[1] || lon < b[2] || lon > b[3];
|
|
102
|
+
}
|
|
70
103
|
/**
|
|
71
104
|
* Decide whether a resolved tree's geocode is implausible for a structured address — the cheap guard the v7 hybrid gate
|
|
72
|
-
* runs after routing an input to the neural parser (#38). Trips
|
|
73
|
-
* centroid
|
|
105
|
+
* runs after routing an input to the neural parser (#38). Trips when the finest resolved place is a bare `country`
|
|
106
|
+
* centroid (guard A), or — when the caller supplies `expectedCountry` — when the served coordinate falls outside that
|
|
107
|
+
* country's coarse bbox (guard B). An unresolved tree (nothing to serve) is plausible: there is no garbage to serve.
|
|
74
108
|
*/
|
|
75
|
-
export function isImplausibleResolution(tree) {
|
|
109
|
+
export function isImplausibleResolution(tree, opts = {}) {
|
|
76
110
|
const coordinate = finestResolvedCoordinate(tree);
|
|
77
111
|
if (coordinate && coordinate.tag === "country") {
|
|
78
112
|
return { implausible: true, reason: "country-centroid", coordinate };
|
|
79
113
|
}
|
|
114
|
+
if (coordinate &&
|
|
115
|
+
opts.expectedCountry &&
|
|
116
|
+
outsideExpectedCountry(opts.expectedCountry, coordinate.lat, coordinate.lon)) {
|
|
117
|
+
return { implausible: true, reason: "outside-expected-country", coordinate };
|
|
118
|
+
}
|
|
80
119
|
return { implausible: false, coordinate: coordinate ?? undefined };
|
|
81
120
|
}
|
|
82
121
|
//# sourceMappingURL=plausibility.js.map
|
package/out/plausibility.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plausibility.js","sourceRoot":"","sources":["../plausibility.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH;;;;GAIG;AACH,MAAM,eAAe,GAA0C;IAC9D,OAAO,EAAE,CAAC;IACV,MAAM,EAAE,CAAC;IACT,SAAS,EAAE,CAAC;IACZ,kBAAkB,EAAE,CAAC;IACrB,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,CAAC;IAChB,YAAY,EAAE,CAAC;CACf,CAAA;AAWD;;;;G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mB,EAAE,GAAW,EAAE,GAAW;IACnF,MAAM,CAAC,GAAG,YAAY,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,CAAA;IAEjD,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAA;IAEpB,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;AAC5D,CAAC;AAyBD;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAiB,EAAE,OAAyB,EAAE;IACrF,MAAM,UAAU,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAA;IAEjD,IAAI,UAAU,IAAI,UAAU,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QAChD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAA;IACrE,CAAC;IAED,IACC,UAAU;QACV,IAAI,CAAC,eAAe;QACpB,sBAAsB,CAAC,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,EAC3E,CAAC;QACF,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,0BAA0B,EAAE,UAAU,EAAE,CAAA;IAC7E,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,IAAI,SAAS,EAAE,CAAA;AACnE,CAAC"}
|
package/out/rerank.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* #727 stage-2 Phase 4a — reranking a k-best parse list on RESOLUTION EVIDENCE.
|
|
7
|
+
*
|
|
8
|
+
* The arc's thesis, stated by the operator (2026-07-15): the arbiter for a k-best list is the
|
|
9
|
+
* resolver, not hand-weights. A rank-2 parse that resolves to a real place beats a rank-1 that
|
|
10
|
+
* resolves to a country centroid.
|
|
11
|
+
*
|
|
12
|
+
* The measured case for this existing at all: on the triaged parity corpus the shipped decode gets
|
|
13
|
+
* street 0.573 while the span decode's top-10 CONTAINS the right answer 0.775 of the time
|
|
14
|
+
* (oracle@5 0.723). Rank-1 cannot reach that headroom; only a reranker can.
|
|
15
|
+
*
|
|
16
|
+
* ## Why this is deliberately, almost embarrassingly small
|
|
17
|
+
*
|
|
18
|
+
* The failure mode we are avoiding is Pelias's: a ladder of per-class hand-tuned weights that
|
|
19
|
+
* nobody can re-derive (see `docs/articles/evals/competitive-parity/2026-07-15-pelias-dictionary-overrides.md`
|
|
20
|
+
* — 94 of 276 dictionary lines are hand-written deletions, each resolving a collision in favour of
|
|
21
|
+
* whoever complained loudest). The moment this file grows a per-hypothesis score blend, we have
|
|
22
|
+
* rebuilt that with extra steps.
|
|
23
|
+
*
|
|
24
|
+
* So the rule is ONE bit of evidence, not a score: **drop hypotheses whose resolution is
|
|
25
|
+
* implausible; otherwise keep the model's own ranking.** The parse scores already share a partition
|
|
26
|
+
* function and are comparable within an input — the reranker's job is not to re-score them, it is to
|
|
27
|
+
* veto the ones the world says are wrong.
|
|
28
|
+
*
|
|
29
|
+
* Adding a second signal here requires the same bar the first one cleared: a MEASURED win on the
|
|
30
|
+
* parity + Paris fixtures, stated in a verdict doc. Not a plausible story.
|
|
31
|
+
*/
|
|
32
|
+
import type { AddressTree } from "@mailwoman/core/decoder";
|
|
33
|
+
/** One candidate parse from the k-best decode, with its (within-input comparable) score. */
|
|
34
|
+
export interface RerankCandidate<T = unknown> {
|
|
35
|
+
/** The parse's own score. Comparable to its siblings from the SAME input; not across inputs. */
|
|
36
|
+
score: number;
|
|
37
|
+
/** The parse tree, UNRESOLVED — `rerankByResolution` resolves it via the injected resolver. */
|
|
38
|
+
tree: AddressTree;
|
|
39
|
+
/** Opaque caller payload carried through to the result (the segmentation, a surface string, …). */
|
|
40
|
+
payload?: T;
|
|
41
|
+
}
|
|
42
|
+
export interface RerankedCandidate<T = unknown> extends RerankCandidate<T> {
|
|
43
|
+
/** The resolved tree (the resolver's output), or null when resolution threw. */
|
|
44
|
+
resolved: AddressTree | null;
|
|
45
|
+
/** True when the resolution is implausible (today: resolves no finer than a country centroid). */
|
|
46
|
+
implausible: boolean;
|
|
47
|
+
/** Why it was vetoed, when it was. */
|
|
48
|
+
reason?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface RerankResult<T = unknown> {
|
|
51
|
+
/** Candidates in FINAL order: plausible ones first (model order preserved), vetoed ones after. */
|
|
52
|
+
ranked: Array<RerankedCandidate<T>>;
|
|
53
|
+
/** The winner — the first plausible candidate, or the model's rank-1 when ALL were vetoed. */
|
|
54
|
+
best: RerankedCandidate<T>;
|
|
55
|
+
/**
|
|
56
|
+
* True when the winner is NOT the model's rank-1 — i.e. resolution evidence actually changed the answer. This is the
|
|
57
|
+
* metric the arc is judged on (`rank-2-beats-rank-1 rate`); log it, because a rerank that never fires is a rerank
|
|
58
|
+
* that is not earning its resolver calls.
|
|
59
|
+
*/
|
|
60
|
+
changed: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** Resolve a tree. Structural — any `Resolver`-shaped thing satisfies it. */
|
|
63
|
+
export type ResolveTree = (tree: AddressTree) => Promise<AddressTree>;
|
|
64
|
+
export interface RerankOpts {
|
|
65
|
+
/**
|
|
66
|
+
* Resolve at most this many candidates (default 5). Each costs a resolver round-trip, so this is the latency knob.
|
|
67
|
+
* oracle@5 (0.723) captures nearly all the measured headroom of oracle@10 (0.775), so 5 is the default rather than 10
|
|
68
|
+
* — the last 5 candidates cost 2x the resolves for ~5pp of ceiling.
|
|
69
|
+
*/
|
|
70
|
+
maxResolve?: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Rerank a k-best parse list on resolution evidence.
|
|
74
|
+
*
|
|
75
|
+
* Resolves up to `maxResolve` candidates IN MODEL ORDER and returns the first whose resolution is plausible. Candidates
|
|
76
|
+
* beyond `maxResolve` are never resolved (and never vetoed — they simply keep their model rank behind the resolved
|
|
77
|
+
* ones).
|
|
78
|
+
*
|
|
79
|
+
* **When every resolved candidate is implausible, the model's rank-1 wins.** A reranker that returns nothing is worse
|
|
80
|
+
* than one that defers: "all my evidence says these are all bad" is not grounds to invent a different answer, only
|
|
81
|
+
* grounds to flag low confidence (the Phase-4b ambiguity gate).
|
|
82
|
+
*/
|
|
83
|
+
export declare function rerankByResolution<T>(candidates: ReadonlyArray<RerankCandidate<T>>, resolveTree: ResolveTree, opts?: RerankOpts): Promise<RerankResult<T>>;
|
|
84
|
+
//# sourceMappingURL=rerank.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rerank.d.ts","sourceRoot":"","sources":["../rerank.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAI1D,4FAA4F;AAC5F,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC3C,gGAAgG;IAChG,KAAK,EAAE,MAAM,CAAA;IACb,+FAA+F;IAC/F,IAAI,EAAE,WAAW,CAAA;IACjB,mGAAmG;IACnG,OAAO,CAAC,EAAE,CAAC,CAAA;CACX;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,eAAe,CAAC,CAAC,CAAC;IACzE,gFAAgF;IAChF,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAA;IAC5B,kGAAkG;IAClG,WAAW,EAAE,OAAO,CAAA;IACpB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACxC,kGAAkG;IAClG,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAA;IACnC,8FAA8F;IAC9F,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAA;IAC1B;;;;OAIG;IACH,OAAO,EAAE,OAAO,CAAA;CAChB;AAED,6EAA6E;AAC7E,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,WAAW,CAAC,CAAA;AAErE,MAAM,WAAW,UAAU;IAC1B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EACzC,UAAU,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAC7C,WAAW,EAAE,WAAW,EACxB,IAAI,GAAE,UAAe,GACnB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAuC1B"}
|
package/out/rerank.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* #727 stage-2 Phase 4a — reranking a k-best parse list on RESOLUTION EVIDENCE.
|
|
7
|
+
*
|
|
8
|
+
* The arc's thesis, stated by the operator (2026-07-15): the arbiter for a k-best list is the
|
|
9
|
+
* resolver, not hand-weights. A rank-2 parse that resolves to a real place beats a rank-1 that
|
|
10
|
+
* resolves to a country centroid.
|
|
11
|
+
*
|
|
12
|
+
* The measured case for this existing at all: on the triaged parity corpus the shipped decode gets
|
|
13
|
+
* street 0.573 while the span decode's top-10 CONTAINS the right answer 0.775 of the time
|
|
14
|
+
* (oracle@5 0.723). Rank-1 cannot reach that headroom; only a reranker can.
|
|
15
|
+
*
|
|
16
|
+
* ## Why this is deliberately, almost embarrassingly small
|
|
17
|
+
*
|
|
18
|
+
* The failure mode we are avoiding is Pelias's: a ladder of per-class hand-tuned weights that
|
|
19
|
+
* nobody can re-derive (see `docs/articles/evals/competitive-parity/2026-07-15-pelias-dictionary-overrides.md`
|
|
20
|
+
* — 94 of 276 dictionary lines are hand-written deletions, each resolving a collision in favour of
|
|
21
|
+
* whoever complained loudest). The moment this file grows a per-hypothesis score blend, we have
|
|
22
|
+
* rebuilt that with extra steps.
|
|
23
|
+
*
|
|
24
|
+
* So the rule is ONE bit of evidence, not a score: **drop hypotheses whose resolution is
|
|
25
|
+
* implausible; otherwise keep the model's own ranking.** The parse scores already share a partition
|
|
26
|
+
* function and are comparable within an input — the reranker's job is not to re-score them, it is to
|
|
27
|
+
* veto the ones the world says are wrong.
|
|
28
|
+
*
|
|
29
|
+
* Adding a second signal here requires the same bar the first one cleared: a MEASURED win on the
|
|
30
|
+
* parity + Paris fixtures, stated in a verdict doc. Not a plausible story.
|
|
31
|
+
*/
|
|
32
|
+
import { isImplausibleResolution } from "./plausibility.js";
|
|
33
|
+
/**
|
|
34
|
+
* Rerank a k-best parse list on resolution evidence.
|
|
35
|
+
*
|
|
36
|
+
* Resolves up to `maxResolve` candidates IN MODEL ORDER and returns the first whose resolution is plausible. Candidates
|
|
37
|
+
* beyond `maxResolve` are never resolved (and never vetoed — they simply keep their model rank behind the resolved
|
|
38
|
+
* ones).
|
|
39
|
+
*
|
|
40
|
+
* **When every resolved candidate is implausible, the model's rank-1 wins.** A reranker that returns nothing is worse
|
|
41
|
+
* than one that defers: "all my evidence says these are all bad" is not grounds to invent a different answer, only
|
|
42
|
+
* grounds to flag low confidence (the Phase-4b ambiguity gate).
|
|
43
|
+
*/
|
|
44
|
+
export async function rerankByResolution(candidates, resolveTree, opts = {}) {
|
|
45
|
+
if (candidates.length === 0)
|
|
46
|
+
throw new Error("rerankByResolution: candidates must not be empty");
|
|
47
|
+
const maxResolve = Math.max(1, Math.min(opts.maxResolve ?? 5, candidates.length));
|
|
48
|
+
const ranked = [];
|
|
49
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
50
|
+
const candidate = candidates[i];
|
|
51
|
+
if (i >= maxResolve) {
|
|
52
|
+
// Beyond the resolve budget: carried through unresolved, never vetoed.
|
|
53
|
+
ranked.push({ ...candidate, resolved: null, implausible: false });
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
let resolved = null;
|
|
57
|
+
try {
|
|
58
|
+
resolved = await resolveTree(candidate.tree);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// A resolver failure is NOT evidence against the parse — treat it as "no evidence" and let
|
|
62
|
+
// the model's rank stand, rather than vetoing a possibly-correct hypothesis on an outage.
|
|
63
|
+
ranked.push({ ...candidate, resolved: null, implausible: false });
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const verdict = isImplausibleResolution(resolved);
|
|
67
|
+
ranked.push({
|
|
68
|
+
...candidate,
|
|
69
|
+
resolved,
|
|
70
|
+
implausible: verdict.implausible,
|
|
71
|
+
...(verdict.reason ? { reason: verdict.reason } : {}),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// Stable partition: plausible first (model order preserved within each group), vetoed after.
|
|
75
|
+
const plausible = ranked.filter((r) => !r.implausible);
|
|
76
|
+
const vetoed = ranked.filter((r) => r.implausible);
|
|
77
|
+
const finalOrder = [...plausible, ...vetoed];
|
|
78
|
+
const best = finalOrder[0];
|
|
79
|
+
return { ranked: finalOrder, best, changed: best !== ranked[0] };
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=rerank.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rerank.js","sourceRoot":"","sources":["../rerank.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAIH,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AA8C3D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,UAA6C,EAC7C,WAAwB,EACxB,OAAmB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C,CAAC,EAAE,CAAC;SACrD,CAAC,CAAA;IACH,CAAC;IAED,6FAA6F;IAC7F,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAA;IACtD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAA;IAClD,MAAM,UAAU,GAAG,CAAC,GAAG,SAAS,EAAE,GAAG,MAAM,CAAC,CAAA;IAC5C,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAE,CAAA;IAE3B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;AACjE,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
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
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* A street-name existence probe. Backend-agnostic; the FR instance is BAN street-centroids, a future US instance is
|
|
31
|
+
* TIGER, etc. (per the registry-backed-structured-prediction doctrine tiers).
|
|
32
|
+
*/
|
|
33
|
+
export interface StreetLocalityEvidence {
|
|
34
|
+
/**
|
|
35
|
+
* True when `streetSurface` exists as a street name — optionally scoped to a locality or postcode when the hypothesis
|
|
36
|
+
* carries one (fragments usually don't; unscoped is the measured mode). The implementation is responsible for folding
|
|
37
|
+
* the surface with {@link foldStreetSurface} so the caller passes raw text.
|
|
38
|
+
*
|
|
39
|
+
* POSITIVE EVIDENCE ONLY: return `false` on any doubt — a missing index, an unsupported country, a read error — so
|
|
40
|
+
* {@link pickByStreetEvidence} fails open to the model's ranking. Absence is never a veto.
|
|
41
|
+
*/
|
|
42
|
+
hasStreetName(streetSurface: string, scope?: StreetEvidenceScope): boolean;
|
|
43
|
+
/** ISO-2 (upper-case) countries this instance can answer for. Anything else → no evidence, never a veto. */
|
|
44
|
+
readonly countries: ReadonlySet<string>;
|
|
45
|
+
}
|
|
46
|
+
export interface StreetEvidenceScope {
|
|
47
|
+
locality?: string;
|
|
48
|
+
postcode?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The fold CONTRACT — the index builder and every runtime prober MUST share this exact function, or lookups silently
|
|
52
|
+
* miss (the 4 v1-policy breaks were fold mismatches: `pillet-will` stored unhyphenated). NFD strip-diacritics,
|
|
53
|
+
* lowercase, hyphen/apostrophe → space, whitespace-collapse. Import this beside the interface; never re-implement it.
|
|
54
|
+
*/
|
|
55
|
+
export declare function foldStreetSurface(surface: string): string;
|
|
56
|
+
/** True when the folded surface contains no token outside {@link FR_STREET_TYPE_WORDS} — i.e. it is pure type/particle. */
|
|
57
|
+
export declare function isPureTypeVocabulary(foldedSurface: string): boolean;
|
|
58
|
+
/** One candidate parse for the street-evidence rerank — its street surface + its (within-input comparable) score. */
|
|
59
|
+
export interface StreetCandidate<T = unknown> {
|
|
60
|
+
/** The candidate's street surface (raw; folded internally). Empty string = no street parsed → never the evidence pick. */
|
|
61
|
+
streetSurface: string;
|
|
62
|
+
/** The parse score, comparable to its siblings from the SAME input. Higher is better. */
|
|
63
|
+
score: number;
|
|
64
|
+
/** Opaque caller payload carried through to the result (the segmentation, the tree, …). */
|
|
65
|
+
payload?: T;
|
|
66
|
+
}
|
|
67
|
+
export interface PickByStreetEvidenceOpts {
|
|
68
|
+
/** Locality/postcode scope forwarded to {@link StreetLocalityEvidence.hasStreetName} (fragments usually carry none). */
|
|
69
|
+
scope?: StreetEvidenceScope;
|
|
70
|
+
/**
|
|
71
|
+
* G2 — the margin cap. A candidate whose score is more than this far below rank-1 is never promoted by evidence
|
|
72
|
+
* (without it, evidence reaches deep down the list and moves off correct rank-1 parses). Default 2.5 — the value the
|
|
73
|
+
* v2 board measured (148 fixes / 3 breaks). UNCALIBRATED across models: re-fit when the span head retrains, since raw
|
|
74
|
+
* score margins are not comparable across models. (Plan #1134 pre-registers an isotonic ambiguity gate to replace
|
|
75
|
+
* it.)
|
|
76
|
+
*/
|
|
77
|
+
marginCap?: number;
|
|
78
|
+
}
|
|
79
|
+
export interface StreetEvidencePick<T = unknown> {
|
|
80
|
+
/** The chosen candidate — the first evidence-passing sibling, or rank-1 when none passes (fail-open). */
|
|
81
|
+
candidate: StreetCandidate<T>;
|
|
82
|
+
/** Index of the chosen candidate in the input array. */
|
|
83
|
+
index: number;
|
|
84
|
+
/** True when evidence MOVED the pick off rank-1 (a rank-2-beats-rank-1 correction — loggable training signal). */
|
|
85
|
+
moved: boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The measured v2 rerank policy. Given candidates in PARSE-SCORE order (rank-1 first) and an evidence probe, return the
|
|
89
|
+
* first candidate whose street surface passes ALL of: (1) exists in the index, (2) G1 — not pure type vocabulary, (3)
|
|
90
|
+
* G2 — within `marginCap` of rank-1. If none passes, return rank-1 (fail-open). Positive evidence only; the model's
|
|
91
|
+
* order is preserved among equal-evidence candidates. This is the `resolver/rerank.ts` anti-Pelias discipline applied
|
|
92
|
+
* to the name signal: one bit, no blending.
|
|
93
|
+
*
|
|
94
|
+
* @param candidates Parse candidates, rank-1 FIRST (the caller sorts by score descending).
|
|
95
|
+
*/
|
|
96
|
+
export declare function pickByStreetEvidence<T>(candidates: ReadonlyArray<StreetCandidate<T>>, evidence: StreetLocalityEvidence, opts?: PickByStreetEvidenceOpts): StreetEvidencePick<T>;
|
|
97
|
+
//# sourceMappingURL=street-evidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"street-evidence.d.ts","sourceRoot":"","sources":["../street-evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACtC;;;;;;;OAOG;IACH,aAAa,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAA;IAC1E,4GAA4G;IAC5G,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQzD;AA4CD,2HAA2H;AAC3H,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAMnE;AAED,qHAAqH;AACrH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC3C,0HAA0H;IAC1H,aAAa,EAAE,MAAM,CAAA;IACrB,yFAAyF;IACzF,KAAK,EAAE,MAAM,CAAA;IACb,2FAA2F;IAC3F,OAAO,CAAC,EAAE,CAAC,CAAA;CACX;AAED,MAAM,WAAW,wBAAwB;IACxC,wHAAwH;IACxH,KAAK,CAAC,EAAE,mBAAmB,CAAA;IAC3B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,OAAO;IAC9C,yGAAyG;IACzG,SAAS,EAAE,eAAe,CAAC,CAAC,CAAC,CAAA;IAC7B,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAA;IACb,kHAAkH;IAClH,KAAK,EAAE,OAAO,CAAA;CACd;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACrC,UAAU,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAC7C,QAAQ,EAAE,sBAAsB,EAChC,IAAI,GAAE,wBAA6B,GACjC,kBAAkB,CAAC,CAAC,CAAC,CA0BvB"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
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
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* The fold CONTRACT — the index builder and every runtime prober MUST share this exact function, or lookups silently
|
|
31
|
+
* miss (the 4 v1-policy breaks were fold mismatches: `pillet-will` stored unhyphenated). NFD strip-diacritics,
|
|
32
|
+
* lowercase, hyphen/apostrophe → space, whitespace-collapse. Import this beside the interface; never re-implement it.
|
|
33
|
+
*/
|
|
34
|
+
export function foldStreetSurface(surface) {
|
|
35
|
+
return surface
|
|
36
|
+
.normalize("NFD")
|
|
37
|
+
.replace(/[̀-ͯ]/g, "")
|
|
38
|
+
.toLowerCase()
|
|
39
|
+
.replace(/['’‐-―-]/g, " ")
|
|
40
|
+
.replace(/\s+/g, " ")
|
|
41
|
+
.trim();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* FR street-type + particle vocabulary — the G1 guard. A street surface made ONLY of these words carries no NAME (bare
|
|
45
|
+
* `rue`/`chemin` is a truncation, and it IS in the index), so it earns no evidence credit. Folded forms (particles are
|
|
46
|
+
* pre-folded: `l'` → `l`). Kept small and lexical — it is a dictionary fact, not a tuned weight (the anti-Pelias
|
|
47
|
+
* line).
|
|
48
|
+
*/
|
|
49
|
+
const FR_STREET_TYPE_WORDS = new Set([
|
|
50
|
+
"rue",
|
|
51
|
+
"avenue",
|
|
52
|
+
"boulevard",
|
|
53
|
+
"chemin",
|
|
54
|
+
"route",
|
|
55
|
+
"allee",
|
|
56
|
+
"impasse",
|
|
57
|
+
"place",
|
|
58
|
+
"quai",
|
|
59
|
+
"passage",
|
|
60
|
+
"sentier",
|
|
61
|
+
"square",
|
|
62
|
+
"cours",
|
|
63
|
+
"voie",
|
|
64
|
+
"chaussee",
|
|
65
|
+
"rond",
|
|
66
|
+
"point",
|
|
67
|
+
"clos",
|
|
68
|
+
"villa",
|
|
69
|
+
"cite",
|
|
70
|
+
"de",
|
|
71
|
+
"du",
|
|
72
|
+
"des",
|
|
73
|
+
"la",
|
|
74
|
+
"le",
|
|
75
|
+
"les",
|
|
76
|
+
"l",
|
|
77
|
+
"d",
|
|
78
|
+
"en",
|
|
79
|
+
"aux",
|
|
80
|
+
"au",
|
|
81
|
+
"sur",
|
|
82
|
+
"sous",
|
|
83
|
+
]);
|
|
84
|
+
/** True when the folded surface contains no token outside {@link FR_STREET_TYPE_WORDS} — i.e. it is pure type/particle. */
|
|
85
|
+
export function isPureTypeVocabulary(foldedSurface) {
|
|
86
|
+
const tokens = foldedSurface.split(" ").filter(Boolean);
|
|
87
|
+
if (tokens.length === 0)
|
|
88
|
+
return true;
|
|
89
|
+
return tokens.every((t) => FR_STREET_TYPE_WORDS.has(t));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The measured v2 rerank policy. Given candidates in PARSE-SCORE order (rank-1 first) and an evidence probe, return the
|
|
93
|
+
* first candidate whose street surface passes ALL of: (1) exists in the index, (2) G1 — not pure type vocabulary, (3)
|
|
94
|
+
* G2 — within `marginCap` of rank-1. If none passes, return rank-1 (fail-open). Positive evidence only; the model's
|
|
95
|
+
* order is preserved among equal-evidence candidates. This is the `resolver/rerank.ts` anti-Pelias discipline applied
|
|
96
|
+
* to the name signal: one bit, no blending.
|
|
97
|
+
*
|
|
98
|
+
* @param candidates Parse candidates, rank-1 FIRST (the caller sorts by score descending).
|
|
99
|
+
*/
|
|
100
|
+
export function pickByStreetEvidence(candidates, evidence, opts = {}) {
|
|
101
|
+
const marginCap = opts.marginCap ?? 2.5;
|
|
102
|
+
if (candidates.length === 0) {
|
|
103
|
+
throw new Error("pickByStreetEvidence: no candidates");
|
|
104
|
+
}
|
|
105
|
+
const rank1 = candidates[0];
|
|
106
|
+
const topScore = rank1.score;
|
|
107
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
108
|
+
const c = candidates[i];
|
|
109
|
+
if (!c.streetSurface)
|
|
110
|
+
continue;
|
|
111
|
+
// G2: candidates are score-ordered, so once one falls past the cap nothing deeper qualifies either.
|
|
112
|
+
if (topScore - c.score > marginCap)
|
|
113
|
+
break;
|
|
114
|
+
// G1: a pure street-type/particle surface (bare `rue`) carries no name — no evidence credit.
|
|
115
|
+
if (isPureTypeVocabulary(foldStreetSurface(c.streetSurface)))
|
|
116
|
+
continue;
|
|
117
|
+
if (evidence.hasStreetName(c.streetSurface, opts.scope)) {
|
|
118
|
+
return { candidate: c, index: i, moved: i > 0 };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return { candidate: rank1, index: 0, moved: false };
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=street-evidence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"street-evidence.js","sourceRoot":"","sources":["../street-evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAyBH;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAChD,OAAO,OAAO;SACZ,SAAS,CAAC,KAAK,CAAC;SAChB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;SACrB,WAAW,EAAE;SACb,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC;SACzB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAA;AACT,CAAC;AAED;;;;;GAKG;AACH,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC;IACzD,KAAK;IACL,QAAQ;IACR,WAAW;IACX,QAAQ;IACR,OAAO;IACP,OAAO;IACP,SAAS;IACT,OAAO;IACP,MAAM;IACN,SAAS;IACT,SAAS;IACT,QAAQ;IACR,OAAO;IACP,MAAM;IACN,UAAU;IACV,MAAM;IACN,OAAO;IACP,MAAM;IACN,OAAO;IACP,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,GAAG;IACH,GAAG;IACH,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;IACL,MAAM;CACN,CAAC,CAAA;AAEF,2HAA2H;AAC3H,MAAM,UAAU,oBAAoB,CAAC,aAAqB;IACzD,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAEvD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAEpC,OAAO,MAAM,CAAC,KAAK,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1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mailwoman/resolver",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "The address resolver: walk an AddressTree, decorate nodes with gazetteer-supplied coordinates + attribution. Backend-agnostic (any ResolverBackend), with the span-rescore + postcode-consistency levers. Lifted out of @mailwoman/core so it can depend on @mailwoman/spatial (haversine) + @mailwoman/codex (USPS directionals) instead of reinventing them; the type contract stays in core so the pipeline composes it without a cycle.",
|
|
5
5
|
"license": "AGPL-3.0-only OR LicenseRef-Commercial",
|
|
6
6
|
"repository": {
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@mailwoman/codex": "
|
|
53
|
-
"@mailwoman/core": "
|
|
54
|
-
"@mailwoman/spatial": "
|
|
52
|
+
"@mailwoman/codex": "7.1.0",
|
|
53
|
+
"@mailwoman/core": "7.1.0",
|
|
54
|
+
"@mailwoman/spatial": "7.1.0"
|
|
55
55
|
}
|
|
56
56
|
}
|