@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.
Files changed (142) hide show
  1. package/README.md +89 -0
  2. package/lib/admin/coherence-passes.ts +435 -0
  3. package/lib/admin/containment.ts +92 -0
  4. package/lib/admin/index.ts +10 -0
  5. package/lib/admin/jp-municipality.ts +97 -0
  6. package/lib/admin/winner.ts +189 -0
  7. package/lib/backend-capabilities.ts +88 -0
  8. package/lib/bare-toponym-race.ts +129 -0
  9. package/lib/decorate-node.ts +127 -0
  10. package/lib/fold-name.ts +36 -0
  11. package/{index.ts → lib/index.ts} +27 -18
  12. package/{plausibility.ts → lib/plausibility.ts} +5 -4
  13. package/{postcode-country-coherence.ts → lib/postcode/country-coherence.ts} +173 -86
  14. package/lib/postcode/index.ts +9 -0
  15. package/{postcode-prefix.ts → lib/postcode/prefix.ts} +7 -6
  16. package/{postcode-shape-coherence.ts → lib/postcode/shape-coherence.ts} +10 -24
  17. package/{remote-resolver.ts → lib/remote-resolver.ts} +13 -4
  18. package/{rerank.ts → lib/rerank.ts} +2 -2
  19. package/lib/resolve/index.ts +982 -0
  20. package/lib/resolve/passes.ts +544 -0
  21. package/{span-rescore.ts → lib/span-rescore.ts} +114 -99
  22. package/{street-evidence.ts → lib/street/evidence.ts} +40 -7
  23. package/lib/street/index.ts +8 -0
  24. package/{street-tier.ts → lib/street/tier.ts} +138 -99
  25. package/{toponym-prior.ts → lib/toponym-prior.ts} +97 -8
  26. package/out/admin/coherence-passes.d.ts +70 -0
  27. package/out/admin/coherence-passes.d.ts.map +1 -0
  28. package/out/admin/coherence-passes.js +327 -0
  29. package/out/admin/coherence-passes.js.map +1 -0
  30. package/out/admin/containment.d.ts +48 -0
  31. package/out/admin/containment.d.ts.map +1 -0
  32. package/out/admin/containment.js +76 -0
  33. package/out/admin/containment.js.map +1 -0
  34. package/out/admin/index.d.ts +10 -0
  35. package/out/admin/index.d.ts.map +1 -0
  36. package/out/admin/index.js +10 -0
  37. package/out/admin/index.js.map +1 -0
  38. package/out/admin/jp-municipality.d.ts +50 -0
  39. package/out/admin/jp-municipality.d.ts.map +1 -0
  40. package/out/admin/jp-municipality.js +54 -0
  41. package/out/admin/jp-municipality.js.map +1 -0
  42. package/out/admin/winner.d.ts +114 -0
  43. package/out/admin/winner.d.ts.map +1 -0
  44. package/out/admin/winner.js +130 -0
  45. package/out/admin/winner.js.map +1 -0
  46. package/out/backend-capabilities.d.ts +37 -0
  47. package/out/backend-capabilities.d.ts.map +1 -0
  48. package/out/backend-capabilities.js +75 -0
  49. package/out/backend-capabilities.js.map +1 -0
  50. package/out/bare-toponym-race.d.ts +55 -0
  51. package/out/bare-toponym-race.d.ts.map +1 -0
  52. package/out/bare-toponym-race.js +110 -0
  53. package/out/bare-toponym-race.js.map +1 -0
  54. package/out/decorate-node.d.ts +24 -0
  55. package/out/decorate-node.d.ts.map +1 -0
  56. package/out/decorate-node.js +103 -0
  57. package/out/decorate-node.js.map +1 -0
  58. package/out/fold-name.d.ts +18 -3
  59. package/out/fold-name.d.ts.map +1 -1
  60. package/out/fold-name.js +19 -3
  61. package/out/fold-name.js.map +1 -1
  62. package/out/index.d.ts +15 -12
  63. package/out/index.d.ts.map +1 -1
  64. package/out/index.js +9 -7
  65. package/out/index.js.map +1 -1
  66. package/out/plausibility.d.ts +5 -4
  67. package/out/plausibility.d.ts.map +1 -1
  68. package/out/plausibility.js +5 -4
  69. package/out/plausibility.js.map +1 -1
  70. package/out/{postcode-country-coherence.d.ts → postcode/country-coherence.d.ts} +46 -25
  71. package/out/postcode/country-coherence.d.ts.map +1 -0
  72. package/out/{postcode-country-coherence.js → postcode/country-coherence.js} +157 -77
  73. package/out/postcode/country-coherence.js.map +1 -0
  74. package/out/postcode/index.d.ts +9 -0
  75. package/out/postcode/index.d.ts.map +1 -0
  76. package/out/postcode/index.js +9 -0
  77. package/out/postcode/index.js.map +1 -0
  78. package/out/{postcode-prefix.d.ts → postcode/prefix.d.ts} +4 -4
  79. package/out/postcode/prefix.d.ts.map +1 -0
  80. package/out/{postcode-prefix.js → postcode/prefix.js} +7 -6
  81. package/out/postcode/prefix.js.map +1 -0
  82. package/out/{postcode-shape-coherence.d.ts → postcode/shape-coherence.d.ts} +3 -3
  83. package/out/postcode/shape-coherence.d.ts.map +1 -0
  84. package/out/{postcode-shape-coherence.js → postcode/shape-coherence.js} +11 -20
  85. package/out/postcode/shape-coherence.js.map +1 -0
  86. package/out/remote-resolver.d.ts +18 -3
  87. package/out/remote-resolver.d.ts.map +1 -1
  88. package/out/remote-resolver.js +2 -2
  89. package/out/remote-resolver.js.map +1 -1
  90. package/out/rerank.d.ts +1 -1
  91. package/out/rerank.d.ts.map +1 -1
  92. package/out/rerank.js +2 -2
  93. package/out/rerank.js.map +1 -1
  94. package/out/{resolve.d.ts → resolve/index.d.ts} +2 -2
  95. package/out/resolve/index.d.ts.map +1 -0
  96. package/out/resolve/index.js +795 -0
  97. package/out/resolve/index.js.map +1 -0
  98. package/out/resolve/passes.d.ts +218 -0
  99. package/out/resolve/passes.d.ts.map +1 -0
  100. package/out/resolve/passes.js +333 -0
  101. package/out/resolve/passes.js.map +1 -0
  102. package/out/span-rescore.d.ts +16 -16
  103. package/out/span-rescore.d.ts.map +1 -1
  104. package/out/span-rescore.js +87 -71
  105. package/out/span-rescore.js.map +1 -1
  106. package/out/{street-evidence.d.ts → street/evidence.d.ts} +18 -3
  107. package/out/street/evidence.d.ts.map +1 -0
  108. package/out/{street-evidence.js → street/evidence.js} +23 -7
  109. package/out/street/evidence.js.map +1 -0
  110. package/out/street/index.d.ts +8 -0
  111. package/out/street/index.d.ts.map +1 -0
  112. package/out/street/index.js +8 -0
  113. package/out/street/index.js.map +1 -0
  114. package/out/{street-tier.d.ts → street/tier.d.ts} +14 -3
  115. package/out/street/tier.d.ts.map +1 -0
  116. package/out/{street-tier.js → street/tier.js} +127 -90
  117. package/out/street/tier.js.map +1 -0
  118. package/out/toponym-prior.d.ts +43 -19
  119. package/out/toponym-prior.d.ts.map +1 -1
  120. package/out/toponym-prior.js +76 -8
  121. package/out/toponym-prior.js.map +1 -1
  122. package/package.json +167 -19
  123. package/vitest.config.ts +5 -6
  124. package/fold-name.ts +0 -20
  125. package/out/postcode-country-coherence.d.ts.map +0 -1
  126. package/out/postcode-country-coherence.js.map +0 -1
  127. package/out/postcode-prefix.d.ts.map +0 -1
  128. package/out/postcode-prefix.js.map +0 -1
  129. package/out/postcode-shape-coherence.d.ts.map +0 -1
  130. package/out/postcode-shape-coherence.js.map +0 -1
  131. package/out/resolve.d.ts.map +0 -1
  132. package/out/resolve.js +0 -1049
  133. package/out/resolve.js.map +0 -1
  134. package/out/street-evidence.d.ts.map +0 -1
  135. package/out/street-evidence.js.map +0 -1
  136. package/out/street-tier.d.ts.map +0 -1
  137. package/out/street-tier.js.map +0 -1
  138. package/out/vitest.config.d.ts +0 -16
  139. package/out/vitest.config.d.ts.map +0 -1
  140. package/out/vitest.config.js +0 -36
  141. package/out/vitest.config.js.map +0 -1
  142. package/resolve.ts +0 -1369
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Node decoration shared by the resolver walk and its post-walk passes — split from `resolve.ts`
7
+ * (the `bare-toponym-race.ts` precedent: the walk file holds the walk) so the coherence passes can
8
+ * live in their own module without an import cycle back into the walk.
9
+ */
10
+ /**
11
+ * A resolved node carries a real coordinate (placeID set + non-zero lat/lon).
12
+ */
13
+ export function isResolvedWithCoord(n) {
14
+ return !!(n.placeID && typeof n.lat === "number" && typeof n.lon === "number" && (n.lat !== 0 || n.lon !== 0));
15
+ }
16
+ /**
17
+ * Stamp a node with resolver-supplied attribution. Displaces any prior classifier `source` / `sourceID` into
18
+ * `metadata.classifier_source` / `metadata.classifier_source_id` so debugging tools can still see who made the original
19
+ * assertion. Surfaces the runner-up candidates on `alternatives` so callers can disambiguate (Springfield-class
20
+ * failures, [#8 in the failure catalogue]).
21
+ */
22
+ export function decorateNode(node, resolved, alternatives) {
23
+ if (node.source !== undefined || node.sourceID !== undefined) {
24
+ const meta = { ...node.metadata };
25
+ if (node.source !== undefined) {
26
+ meta["classifier_source"] = node.source;
27
+ }
28
+ if (node.sourceID !== undefined) {
29
+ meta["classifier_source_id"] = node.sourceID;
30
+ }
31
+ node.metadata = meta;
32
+ }
33
+ node.source = "resolver";
34
+ node.sourceID = `${resolved.placetype}:${resolved.id}`;
35
+ // `0,0` is the gazetteer's UNLOCATED sentinel, not a location in the Gulf of Guinea. Extracts carry a lot of it —
36
+ // 48,216 of 142,604 JP postcodes, 86,377 GB, 9,708 intl, 414 US — and stamping it produces a node that answers
37
+ // "yes" to every `lat != null` guard downstream, including the admin ladder's. Absence is the representable form
38
+ // (`AddressNode.lat` is optional and {@link isResolvedWithCoord} already reads the sentinel this way), so the
39
+ // place resolves and identifies itself while stating it cannot say where it is.
40
+ //
41
+ // Both are cleared together rather than left stale: a coordinate from a previously-decorated place beside this
42
+ // one's `placeID` would be a worse answer than none.
43
+ const located = resolved.lat !== undefined && resolved.lon !== undefined && (resolved.lat !== 0 || resolved.lon !== 0);
44
+ if (located) {
45
+ node.lat = resolved.lat;
46
+ node.lon = resolved.lon;
47
+ }
48
+ else {
49
+ delete node.lat;
50
+ delete node.lon;
51
+ }
52
+ node.placeID = `wof:${resolved.id}`; // v1: only WOF resolvers; the URI scheme stays this simple
53
+ // Record the resolver's ranking score AND the resolved place's CANONICAL name. The name is the
54
+ // gazetteer's truth for the place we picked — distinct from `node.value` (the raw input span). It
55
+ // lets consumers display the canonical name and lets the end-to-end eval check the resolver chose
56
+ // the right PLACE (gazetteer-name vs ground-truth) rather than merely echoing the parser's text.
57
+ node.metadata = { ...node.metadata, resolver_score: resolved.score, resolver_name: resolved.name };
58
+ // The winner's PROMINENCE, when the backend computed one. `alternatives` below are full `ResolvedPlace`s and
59
+ // already carry theirs; without this stamp the WINNER's is the one value in the ranked list that gets dropped,
60
+ // which makes a top-1-vs-top-2 margin uncomputable from the tree — and that margin is what
61
+ // `mailwoman/query-intent.ts` reads to decide whether a bare-toponym answer was a clear win. Additive metadata
62
+ // only; nothing in the resolve reads it back.
63
+ if (resolved.prominence !== undefined) {
64
+ node.metadata["resolver_prominence"] = resolved.prominence;
65
+ }
66
+ // The resolved place's ISO-3166 alpha-2 country (from the gazetteer/candidate row), when known. #1014: lets a
67
+ // forward consumer fill country/countrycode without an ancestry walk — the candidate backend carries this even
68
+ // though it has no `ancestors()` table.
69
+ if (resolved.country) {
70
+ node.metadata["resolver_country"] = resolved.country;
71
+ }
72
+ // The score-channel carries (ROAD_TO_V9 §2 + #28). Written ONLY when the backend actually has a
73
+ // value: an absent score means "unmeasured" or "pre-split gazetteer", and a `resolver_*: 0` on the
74
+ // node would assert a measurement nobody made. Nothing in the resolve path reads these keys back —
75
+ // they exist for annotation / API surfaces downstream. `resolver_importance` is the blended #28
76
+ // prior (the value the ranking consulted); `resolver_encyclopedic` is the strict channel, reserved
77
+ // until a strict-channel source ships.
78
+ if (resolved.referential !== undefined) {
79
+ node.metadata["resolver_referential"] = resolved.referential;
80
+ }
81
+ if (resolved.encyclopedic !== undefined) {
82
+ node.metadata["resolver_encyclopedic"] = resolved.encyclopedic;
83
+ }
84
+ if (resolved.importance !== undefined) {
85
+ node.metadata["resolver_importance"] = resolved.importance;
86
+ }
87
+ // The postcode/locality conflict flag (the falsehood differentiator): the postcode pointed to a
88
+ // geographically different place than the parsed city name. Surface it so callers can warn rather
89
+ // than silently trust the resolved point.
90
+ if (resolved.mismatch) {
91
+ node.metadata["postcode_city_mismatch"] = true;
92
+ }
93
+ // Fallback-observability (#718): a broader admin tier (macroregion/macrocounty) stood in for the
94
+ // true region/county because no exact-type candidate existed. Additive annotation only — the
95
+ // resolved coordinate/identity above is untouched; this just lets a consumer / QA pass see it.
96
+ if (resolved.resolutionQuality) {
97
+ node.metadata["resolution_quality"] = resolved.resolutionQuality;
98
+ }
99
+ if (alternatives.length) {
100
+ node.alternatives = alternatives;
101
+ }
102
+ }
103
+ //# sourceMappingURL=decorate-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorate-node.js","sourceRoot":"","sources":["../lib/decorate-node.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,CAAc;IACjD,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,GAAG,KAAK,QAAQ,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;AAC/G,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC3B,IAAiB,EACjB,QAAiC,EACjC,YAA6B;IAE7B,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC9D,MAAM,IAAI,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAA;QAEjC,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC,MAAM,CAAA;QACxC,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,sBAAsB,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAA;QAC7C,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;IACrB,CAAC;IAED,IAAI,CAAC,MAAM,GAAG,UAAU,CAAA;IACxB,IAAI,CAAC,QAAQ,GAAG,GAAG,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAA;IAEtD,kHAAkH;IAClH,+GAA+G;IAC/G,iHAAiH;IACjH,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nG,gGAAgG;IAChG,mGAAmG;IACnG,uCAAuC;IACvC,IAAI,QAAQ,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACxC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAA;IAC7D,CAAC;IAED,IAAI,QAAQ,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACzC,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAA;IAC/D,CAAC;IAED,IAAI,QAAQ,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACvC,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAA;IAC3D,CAAC;IAED,gGAAgG;IAChG,kGAAkG;IAClG,0CAA0C;IAC1C,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,wBAAwB,CAAC,GAAG,IAAI,CAAA;IAC/C,CAAC;IAED,iGAAiG;IACjG,6FAA6F;IAC7F,+FAA+F;IAC/F,IAAI,QAAQ,CAAC,iBAAiB,EAAE,CAAC;QAChC,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,GAAG,QAAQ,CAAC,iBAAiB,CAAA;IACjE,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,EAAE,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IACjC,CAAC;AACF,CAAC"}
@@ -3,11 +3,26 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * One shared name fold, used by the resolver's commune reconciliation and by the street tier's
7
- * locality comparison. Its own module because both would otherwise import each other for it.
6
+ * One shared name fold, used by the resolver's commune reconciliation, by the street tier's
7
+ * locality comparison and by span-rescore's key guards. Its own module because those would
8
+ * otherwise import each other for it.
9
+ *
10
+ * `@mailwoman/codex`'s `foldName` (`packages/codex/lib/normalize.ts`) is a near twin and is also
11
+ * correct; it differs in collapsing every non-alphanumeric RUN, whitespace included. The two are
12
+ * equivalent on the inputs either sees today. They are kept apart because this one answers to a
13
+ * comparison contract the resolver owns, not because the codex copy is wrong.
8
14
  */
9
15
  /**
10
- * Case/diacritic-insensitive fold for commune-name comparison (#1058) — mirrors span-rescore's `norm`.
16
+ * Case/diacritic-insensitive fold for commune-name comparison (#1058).
17
+ *
18
+ * Marks are DELETED, never spaced. `[^a-z0-9 ]` alone maps the combining cedilla that NFD has just produced to a SPACE,
19
+ * so `Besançon` keys as `besanc on` and matches nothing it should. The gazetteer side of the same comparison deletes
20
+ * them — 0 of 32,539 distinct `locality_base` keys in `street-centroids-fr.db` carry a mark — so spacing puts the two
21
+ * halves of one comparison on different keys. Order is required: after the class filter the strip is a no-op.
22
+ *
23
+ * Not fixed here, and worth knowing before trusting the fold on a non-Latin-1 name: a letter with no decomposition is
24
+ * DROPPED rather than folded (`Łódź` → `odz`, `Đà Nẵng` → `a nang`). That needs a transliteration table, not a regex,
25
+ * and it is shared with every other fold in the repo.
11
26
  */
12
27
  export declare function foldName(s: string): string;
13
28
  //# sourceMappingURL=fold-name.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fold-name.d.ts","sourceRoot":"","sources":["../fold-name.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAO1C"}
1
+ {"version":3,"file":"fold-name.d.ts","sourceRoot":"","sources":["../lib/fold-name.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ1C"}
package/out/fold-name.js CHANGED
@@ -3,16 +3,32 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * One shared name fold, used by the resolver's commune reconciliation and by the street tier's
7
- * locality comparison. Its own module because both would otherwise import each other for it.
6
+ * One shared name fold, used by the resolver's commune reconciliation, by the street tier's
7
+ * locality comparison and by span-rescore's key guards. Its own module because those would
8
+ * otherwise import each other for it.
9
+ *
10
+ * `@mailwoman/codex`'s `foldName` (`packages/codex/lib/normalize.ts`) is a near twin and is also
11
+ * correct; it differs in collapsing every non-alphanumeric RUN, whitespace included. The two are
12
+ * equivalent on the inputs either sees today. They are kept apart because this one answers to a
13
+ * comparison contract the resolver owns, not because the codex copy is wrong.
8
14
  */
9
15
  /**
10
- * Case/diacritic-insensitive fold for commune-name comparison (#1058) — mirrors span-rescore's `norm`.
16
+ * Case/diacritic-insensitive fold for commune-name comparison (#1058).
17
+ *
18
+ * Marks are DELETED, never spaced. `[^a-z0-9 ]` alone maps the combining cedilla that NFD has just produced to a SPACE,
19
+ * so `Besançon` keys as `besanc on` and matches nothing it should. The gazetteer side of the same comparison deletes
20
+ * them — 0 of 32,539 distinct `locality_base` keys in `street-centroids-fr.db` carry a mark — so spacing puts the two
21
+ * halves of one comparison on different keys. Order is required: after the class filter the strip is a no-op.
22
+ *
23
+ * Not fixed here, and worth knowing before trusting the fold on a non-Latin-1 name: a letter with no decomposition is
24
+ * DROPPED rather than folded (`Łódź` → `odz`, `Đà Nẵng` → `a nang`). That needs a transliteration table, not a regex,
25
+ * and it is shared with every other fold in the repo.
11
26
  */
12
27
  export function foldName(s) {
13
28
  return s
14
29
  .toLowerCase()
15
30
  .normalize("NFD")
31
+ .replaceAll(/\p{M}/gu, "")
16
32
  .replaceAll(/[^a-z0-9 ]/g, " ")
17
33
  .replaceAll(/\s+/g, " ")
18
34
  .trim();
@@ -1 +1 @@
1
- {"version":3,"file":"fold-name.js","sourceRoot":"","sources":["../fold-name.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAS;IACjC,OAAO,CAAC;SACN,WAAW,EAAE;SACb,SAAS,CAAC,KAAK,CAAC;SAChB,UAAU,CAAC,aAAa,EAAE,GAAG,CAAC;SAC9B,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC;SACvB,IAAI,EAAE,CAAA;AACT,CAAC"}
1
+ {"version":3,"file":"fold-name.js","sourceRoot":"","sources":["../lib/fold-name.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAS;IACjC,OAAO,CAAC;SACN,WAAW,EAAE;SACb,SAAS,CAAC,KAAK,CAAC;SAChB,UAAU,CAAC,SAAS,EAAE,EAAE,CAAC;SACzB,UAAU,CAAC,aAAa,EAAE,GAAG,CAAC;SAC9B,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC;SACvB,IAAI,EAAE,CAAA;AACT,CAAC"}
package/out/index.d.ts CHANGED
@@ -10,17 +10,20 @@
10
10
  * package cycle); this barrel re-exports it, so `@mailwoman/resolver` is a complete drop-in for
11
11
  * what used to be `@mailwoman/core/resolver`.
12
12
  */
13
- export { RemoteResolver, serializableResolveOpts } from "./remote-resolver.ts";
14
- export type { RemoteResolverOpts, ResolveTreeRequest, ResolveTreeResponse, SerializableResolveOpts, } from "./remote-resolver.ts";
15
- export { createWOFResolver } from "./resolve.ts";
16
- export { COUNTRY_BBOX, finestResolvedCoordinate, isImplausibleResolution, outsideExpectedCountry, } from "./plausibility.ts";
17
- export type { PlausibilityOpts, 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";
20
- export { findPostcodeCountryScope, firstLocalityValue, POSTCODE_COUNTRY_COHERENCE_GATE_KM, stampPostcodeCountryScope, } from "./postcode-country-coherence.ts";
21
- export type { PostcodeCountryScope, PostcodeCountryScopeOpts } from "./postcode-country-coherence.ts";
22
- export { findRescoreCandidate, hasResolvedPlace } from "./span-rescore.ts";
23
- export type { RescoreCandidate, SpanRescoreOptions } from "./span-rescore.ts";
13
+ export { RemoteResolver, serializableResolveOpts } from "#remote-resolver";
14
+ export type { RemoteResolverOpts, ResolveTreeRequest, ResolveTreeResponse, SerializableResolveOpts, } from "#remote-resolver";
15
+ export { createWOFResolver } from "#resolve";
16
+ export { COUNTRY_BBOX, finestResolvedCoordinate, isImplausibleResolution, outsideExpectedCountry } from "#plausibility";
17
+ export type { PlausibilityOpts, PlausibilityVerdict, ResolvedCoordinate } from "#plausibility";
18
+ export { foldStreetSurface, isPureTypeVocabulary, pickByStreetEvidence } from "#street/evidence";
19
+ export type { PickByStreetEvidenceOpts, StreetCandidate, StreetEvidencePick, StreetEvidenceScope, StreetLocalityEvidence, } from "#street/evidence";
20
+ export { findPostcodeCountryScope, firstLocalityValue, localityValuesInDocumentOrder, POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM, stampPostcodeCountryScope, } from "#postcode/country-coherence";
21
+ export type { PostcodeCountryScope, PostcodeCountryScopeOpts } from "#postcode/country-coherence";
22
+ export { findRescoreCandidate, hasResolvedPlace } from "#span-rescore";
23
+ export type { RescoreCandidate, SpanRescoreOptions } from "#span-rescore";
24
+ export { adminContainmentVerdict, partitionByContainment } from "#admin/containment";
25
+ export { ADMIN_LADDER_LOCALITY_FIRST, ADMIN_LADDER_POSTCODE_FIRST, adminLadderFor, adminLadderForNodes, AREA_GRADE_POSTALCODE_SPECIFICITY, mostSpecificResolved, resolvedSpecificity, } from "#admin/winner";
26
+ export type { ResolvedPostcodeHit, ResolvedSpecificityInput } from "#admin/winner";
24
27
  export * from "@mailwoman/core/resolver";
25
- export * from "./rerank.ts";
28
+ export * from "#rerank";
26
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,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E5C,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAEvH,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAC9F,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAEhG,YAAY,EACX,wBAAwB,EACxB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,GACtB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EACN,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,EAC7B,uCAAuC,EACvC,yBAAyB,GACzB,MAAM,6BAA6B,CAAA;AAEpC,YAAY,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAA;AACjG,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AACtE,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AACzE,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAEpF,OAAO,EACN,2BAA2B,EAC3B,2BAA2B,EAC3B,cAAc,EACd,mBAAmB,EACnB,iCAAiC,EACjC,oBAAoB,EACpB,mBAAmB,GACnB,MAAM,eAAe,CAAA;AAEtB,YAAY,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AAIlF,cAAc,0BAA0B,CAAA;AAExC,cAAc,SAAS,CAAA"}
package/out/index.js CHANGED
@@ -10,14 +10,16 @@
10
10
  * package cycle); this barrel re-exports it, so `@mailwoman/resolver` is a complete drop-in for
11
11
  * what used to be `@mailwoman/core/resolver`.
12
12
  */
13
- export { RemoteResolver, serializableResolveOpts } from "./remote-resolver.js";
14
- export { createWOFResolver } from "./resolve.js";
15
- export { COUNTRY_BBOX, finestResolvedCoordinate, isImplausibleResolution, outsideExpectedCountry, } from "./plausibility.js";
16
- export { foldStreetSurface, isPureTypeVocabulary, pickByStreetEvidence } from "./street-evidence.js";
17
- export { findPostcodeCountryScope, firstLocalityValue, POSTCODE_COUNTRY_COHERENCE_GATE_KM, stampPostcodeCountryScope, } from "./postcode-country-coherence.js";
18
- export { findRescoreCandidate, hasResolvedPlace } from "./span-rescore.js";
13
+ export { RemoteResolver, serializableResolveOpts } from "#remote-resolver";
14
+ export { createWOFResolver } from "#resolve";
15
+ export { COUNTRY_BBOX, finestResolvedCoordinate, isImplausibleResolution, outsideExpectedCountry } from "#plausibility";
16
+ export { foldStreetSurface, isPureTypeVocabulary, pickByStreetEvidence } from "#street/evidence";
17
+ export { findPostcodeCountryScope, firstLocalityValue, localityValuesInDocumentOrder, POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM, stampPostcodeCountryScope, } from "#postcode/country-coherence";
18
+ export { findRescoreCandidate, hasResolvedPlace } from "#span-rescore";
19
+ export { adminContainmentVerdict, partitionByContainment } from "#admin/containment";
20
+ export { ADMIN_LADDER_LOCALITY_FIRST, ADMIN_LADDER_POSTCODE_FIRST, adminLadderFor, adminLadderForNodes, AREA_GRADE_POSTALCODE_SPECIFICITY, mostSpecificResolved, resolvedSpecificity, } from "#admin/winner";
19
21
  // The type contract + placetype helpers live in core (pure types, keep core a leaf). Re-export so
20
22
  // consumers get the whole surface from `@mailwoman/resolver`.
21
23
  export * from "@mailwoman/core/resolver";
22
- export * from "./rerank.js";
24
+ export * from "#rerank";
23
25
  //# 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;AAS9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD,OAAO,EACN,YAAY,EACZ,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CAAA"}
@@ -97,10 +97,11 @@ export interface PlausibilityOpts {
97
97
  countryBBoxes?: ReadonlyMap<string, CountryBBoxFact>;
98
98
  }
99
99
  /**
100
- * Decide whether a resolved tree's geocode is implausible for a structured address — the cheap guard the v7 hybrid gate
101
- * runs after routing an input to the neural parser (#38). Trips when the finest resolved place is a bare `country`
102
- * centroid (guard A), or — when the caller supplies `expectedCountry` — when the served coordinate falls outside that
103
- * country's coarse bbox (guard B). An unresolved tree (nothing to serve) is plausible: there is no garbage to serve.
100
+ * Decide whether a resolved tree's geocode is implausible for a structured address — the cheap guard the v7 hybrid
101
+ * check runs after routing an input to the neural parser (#38). Trips when the finest resolved place is a bare
102
+ * `country` centroid (guard A), or — when the caller supplies `expectedCountry` — when the served coordinate falls
103
+ * outside that country's coarse bbox (guard B). An unresolved tree (nothing to serve) is plausible: there is no garbage
104
+ * to serve.
104
105
  */
105
106
  export declare function isImplausibleResolution(tree: AddressTree, opts?: PlausibilityOpts): PlausibilityVerdict;
106
107
  //# 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;AACrF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAqB/D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,GAAG,EAAE,YAAY,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,GAAG,kBAAkB,GAAG,IAAI,CAwBrF;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,EAAE,Q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B,CAAC,IAAI,EAAE,WAAW,GAAG,kBAAkB,GAAG,IAAI,CAwBrF;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAmB5F,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACrC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,GAC3C,OAAO,CAgBT;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IACnC,WAAW,EAAE,OAAO,CAAA;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,kBAAkB,GAAG,0BAA0B,CAAA;IACxD;;OAEG;IACH,UAAU,CAAC,EAAE,kBAAkB,CAAA;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAChC;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;OAIG;IACH,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CACpD;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,GAAE,gBAAqB,GAAG,mBAAmB,CAgB3G"}
@@ -120,10 +120,11 @@ export function outsideExpectedCountry(countryCode, lat, lon, bboxes) {
120
120
  return lat < b[0] || lat > b[1] || lon < b[2] || lon > b[3];
121
121
  }
122
122
  /**
123
- * Decide whether a resolved tree's geocode is implausible for a structured address — the cheap guard the v7 hybrid gate
124
- * runs after routing an input to the neural parser (#38). Trips when the finest resolved place is a bare `country`
125
- * centroid (guard A), or — when the caller supplies `expectedCountry` — when the served coordinate falls outside that
126
- * country's coarse bbox (guard B). An unresolved tree (nothing to serve) is plausible: there is no garbage to serve.
123
+ * Decide whether a resolved tree's geocode is implausible for a structured address — the cheap guard the v7 hybrid
124
+ * check runs after routing an input to the neural parser (#38). Trips when the finest resolved place is a bare
125
+ * `country` centroid (guard A), or — when the caller supplies `expectedCountry` — when the served coordinate falls
126
+ * outside that country's coarse bbox (guard B). An unresolved tree (nothing to serve) is plausible: there is no garbage
127
+ * to serve.
127
128
  */
128
129
  export function isImplausibleResolution(tree, opts = {}) {
129
130
  const coordinate = finestResolvedCoordinate(tree);
@@ -1 +1 @@
1
- {"version":3,"file":"plausibility.js","sourceRoot":"","sources":["../plausibility.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAKH;;;;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;AAeD;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAiB;IACzD,IAAI,IAAI,GAA8B,IAAI,CAAA;IAC1C,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAA;IAEjB,MAAM,KAAK,GAAG,CAAC,IAAiB,EAAQ,EAAE;QACzC,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;YACtD,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YAE3C,IAAI,IAAI,GAAG,QAAQ,EAAE,CAAC;gBACrB,QAAQ,GAAG,IAAI,CAAA;gBACf,IAAI,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,I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AAK,EAAE,UAAU,EAAE,UAAU,IAAI,SAAS,EAAE,CAAA;AACnE,CAAC"}
@@ -11,13 +11,13 @@
11
11
  * turns THAT into a hard `spr.country = 'US'` WHERE clause. The candidate pool is all-US before
12
12
  * ranking begins, so a coarse placer that already called this address FR at confidence
13
13
  * 0.9999908844 has nothing to promote — a soft re-rank downstream of a hard filter is inert by
14
- * construction. Population then picks Paris, Texas (pop 24,969). With the postal shards attached
14
+ * construction. Population then picks Paris, Texas (pop 24,969). With the postal extracts attached
15
15
  * the answer gets WORSE, not merely wrong: the postcode resolves to the US row (ZIP 75001,
16
- * Addison TX), `applyPostcodeConsistency` finds no Paris within its 50 km gate (the nearest is
16
+ * Addison TX), `applyPostcodeConsistency` finds no Paris within its 50 km check (the nearest is
17
17
  * 143.8 km), and falls the locality coordinate back to the ZIP point. See
18
18
  * `docs/records/evals/2026-08-03-postcode-locality-scoping.md` for the instrumented diagnosis.
19
19
  *
20
- * No pattern-only lever can fix this. `75001` is NOT unambiguously French:
20
+ * No pattern-only change can fix this. `75001` is NOT unambiguously French:
21
21
  * `candidateSystemsForPostcode("75001")` returns `["us", "de", "fr"]`, and the 2026-08-04
22
22
  * candidate gazetteer holds the literal string in FOUR countries — FR 48.863,2.336 (Paris 1er),
23
23
  * US 32.960,-96.838 (Addison TX), DE 48.844,9.367, PL 54.190,16.188 (×2 rows). The SHAPE is
@@ -40,7 +40,7 @@
40
40
  * `state.defaultCountry` for the whole walk. Everything downstream — including the three post-walk
41
41
  * coherence passes and the street/rooftop tiers — then sees the corrected country.
42
42
  *
43
- * ## Why it is not a hard veto (the doctrine gate)
43
+ * ## Why it is not a hard veto (the doctrine check)
44
44
  *
45
45
  * Registries are SOFT priors here, positive evidence only. Two properties keep this one honest:
46
46
  *
@@ -76,42 +76,44 @@
76
76
  * the whole gazetteer. See {@link PostcodeCountryScopeEvidence}.
77
77
  *
78
78
  * The abstention doctrine is unchanged and is what bounds the new rungs: a two-country tie is a HARD
79
- * abstention that never falls through to the single-sided rungs, and any corroboration at home — the
80
- * address's own city or its own postcode existing in the default country — stops the pass dead.
79
+ * abstention that never falls through to the single-sided rungs. Corroboration at home bounds them
80
+ * asymmetrically: the address's own POSTCODE existing in the default country stops the pass dead,
81
+ * while a LOCALITY value at home neutralizes that value as a foreign witness without silencing its
82
+ * siblings (the per-value rule in the single-sided section below).
81
83
  *
82
84
  * ## Evidence
83
85
  *
84
86
  * Prototyped out-of-tree against the live gazetteer over the public `findPlace` surface (2026-08-03):
85
87
  * 400 real US (ZIP, city) pairs from `postalcode-us.db` + 400 real FR (CP, commune) pairs from
86
88
  * `postcode-locality-fr.db` — 800 pairs, **zero** border crossings, at both the 15 km and 25 km
87
- * gates. The 22 US abstentions were pairs whose ZIP parent name is not an exact-matching locality
89
+ * checks. The 22 US abstentions were pairs whose ZIP parent name is not an exact-matching locality
88
90
  * in the admin gazetteer (a recall gap; abstention is the safe outcome). The confound board's
89
- * verdicts were identical at 15, 25 AND 50 km, so the mechanism is not gate-tuned; the default
91
+ * verdicts were identical at 15, 25 AND 50 km, so the mechanism is not check-tuned; the default
90
92
  * below is the 25 km the scale run measured.
91
93
  *
92
94
  * Cost: 2 lookups on the byte-stable path (postcode + locality under the default country), and at
93
- * most `2 × |candidateSystems|` — bounded at 8, since a numeric shape matches at most `us`/`de`/`fr`
94
- * — when the default is incoherent. Nothing runs at all unless a `defaultCountry` is in force AND
95
- * the tree carries both a postcode and a locality.
95
+ * most `2 × |candidateSystems| × |localityValues|` — candidates bounded at 12, locality values at 3,
96
+ * and the common tree carries exactly one — when the default is incoherent. Nothing runs at all
97
+ * unless the tree carries both a postcode and a locality.
96
98
  *
97
99
  * **Default-ON** since the operator promotion of 2026-08-05 (#1477) — the resolver gauntlet, pinned
98
- * both ways, returned zero newly-failing gated cases, and 56,000 pair evaluations across both
100
+ * both ways, returned zero newly-failing conditional cases, and 56,000 pair evaluations across both
99
101
  * backends returned zero false positives. `ResolveOpts.postcodeCountryCoherence: false` opts out,
100
102
  * and the walk is byte-stable then. Receipts:
101
103
  * `docs/records/evals/2026-08-05-postcode-coherence-default-on-evidence.md`.
102
104
  */
103
- import type { AddressNode } from "@mailwoman/core/decoder";
105
+ import { type AddressNode } from "@mailwoman/core/decoder";
104
106
  import type { ResolvedPlace, ResolverBackend } from "@mailwoman/core/resolver";
105
107
  /**
106
- * Default gate radius (km) for the postcode↔locality consistency test. 25 km is what the 800-pair scale run measured;
108
+ * Default check radius (km) for the postcode↔locality consistency test. 25 km is what the 800-pair scale run measured;
107
109
  * the confound board returned identical verdicts at 15, 25 and 50, so this is a floor choice, not a tuned one.
108
110
  */
109
- export declare const POSTCODE_COUNTRY_COHERENCE_GATE_KM = 25;
111
+ export declare const POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM = 25;
110
112
  /**
111
113
  * Which half (or halves) of the address bought the verdict — the firing receipt, so a reader of a scoped result can
112
114
  * tell a two-sided agreement from a one-sided uniqueness claim without re-deriving it.
113
115
  *
114
- * - `pair` — postcode AND locality both resolve in this country, within the gate. The strongest rung and the only one
116
+ * - `pair` — postcode AND locality both resolve in this country, within the radius. The strongest rung and the only one
115
117
  * that existed before #24.
116
118
  * - `locality` — the locality names exactly one country in the whole gazetteer, and the postcode names none that
117
119
  * contradict it. This is the CH/BE class: the gazetteer carries no Swiss or Belgian postcodes at all, so the pair
@@ -141,7 +143,7 @@ export interface PostcodeCountryScope {
141
143
  */
142
144
  evidence: PostcodeCountryScopeEvidence;
143
145
  /**
144
- * Distance between the resolved postcode point and the nearest same-named locality, in km. Always `<= gateKm`.
146
+ * Distance between the resolved postcode point and the nearest same-named locality, in km. Always `<= thresholdKm`.
145
147
  * Present ONLY for the `pair` rung — a single-sided verdict has no two points to measure between, and reporting a `0`
146
148
  * there would assert an agreement nobody tested (the meaning-of-zero rule).
147
149
  */
@@ -162,14 +164,16 @@ export interface PostcodeCountryScopeOpts {
162
164
  */
163
165
  postcode: string;
164
166
  /**
165
- * The country the caller's `defaultCountry` would hard-filter to. Required: this pass exists to correct a wrong one,
166
- * so with no default there is nothing to correct and the caller should not be calling.
167
+ * The country the caller's `defaultCountry` would hard-filter to — or `undefined` when no default is in force (the
168
+ * browser cascade), where the pass CONSTRAINS instead of overriding: the default-coherence short-circuit is vacuous
169
+ * and the exactly-one-country abstention carries the safety alone. Historically required: this pass was built to
170
+ * correct a wrong one, so with no default there is nothing to correct and the caller should not be calling.
167
171
  */
168
- defaultCountry: string;
172
+ defaultCountry: string | undefined;
169
173
  /**
170
- * Consistency gate radius in km. Defaults to {@link POSTCODE_COUNTRY_COHERENCE_GATE_KM}.
174
+ * Consistency check radius in km. Defaults to {@link POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM}.
171
175
  */
172
- gateKm?: number;
176
+ thresholdKm?: number;
173
177
  /**
174
178
  * Optional narrowing of the SHAPE half of the candidate-country set — the shape-coherence pass's intersection for a
175
179
  * CONFIRMED postcode span (see `resolver/postcode-shape-coherence.ts`, #31 Mechanism 1). When present it REPLACES
@@ -183,8 +187,25 @@ export interface PostcodeCountryScopeOpts {
183
187
  candidateSystems?: readonly string[];
184
188
  }
185
189
  /**
186
- * The address's locality string: the first `locality` node anywhere in the tree, else the first `dependent_locality`.
187
- * Two passes so a real locality always beats a dependent one regardless of tree order.
190
+ * The address's locality strings in DOCUMENT ORDER — every `locality` value first, then every `dependent_locality`,
191
+ * case-insensitively deduplicated. Two passes so a real locality always beats a dependent one regardless of tree
192
+ * order.
193
+ *
194
+ * Document order is required, not cosmetic. The original stack-pop traversal visited the LAST node first, so on `92
195
+ * Laurell Road, Gander, NL A1V 0A9` — where the model tags both `Gander` and the province abbreviation `NL` as
196
+ * localities — the pass keyed its whole country verdict on "NL", whose only exact locality-band bearer is an alias of
197
+ * Nal, Afghanistan, and the walk resolved a Newfoundland street 10,000 km away. The FIRST-written locality is the one
198
+ * the address is about.
199
+ *
200
+ * ALL values matter, not just the first. On `Calle Mayor 12, Aravaca, 28023 Madrid` the model tags both `Aravaca` and
201
+ * `Madrid` as localities; `Aravaca` is a neighbourhood the locality band cannot see, while `Madrid` carries the ES pair
202
+ * verdict (the ES 28023 row sits 9.6 km from the Madrid locality row). A pass keyed on a single value bets the whole
203
+ * country verdict on whichever one a traversal order happens to pick — first-only re-scoped that address to the US ZIP
204
+ * 28023 centroid in North Carolina. So the verdict rungs try each value in order until one produces evidence.
205
+ */
206
+ export declare function localityValuesInDocumentOrder(roots: readonly AddressNode[]): string[];
207
+ /**
208
+ * The first of {@link localityValuesInDocumentOrder} — the locality the address is about.
188
209
  */
189
210
  export declare function firstLocalityValue(roots: readonly AddressNode[]): string | undefined;
190
211
  /**
@@ -208,4 +229,4 @@ export declare function findPostcodeCountryScope(roots: readonly AddressNode[],
208
229
  * untouched, this only writes `metadata`.
209
230
  */
210
231
  export declare function stampPostcodeCountryScope(roots: readonly AddressNode[], scope: PostcodeCountryScope): void;
211
- //# sourceMappingURL=postcode-country-coherence.d.ts.map
232
+ //# sourceMappingURL=country-coherence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"country-coherence.d.ts","sourceRoot":"","sources":["../../lib/postcode/country-coherence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuGG;AAKH,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAG9E;;;GAGG;AACH,eAAO,MAAM,uCAAuC,KAAK,CAAA;AAEzD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,4BAA4B,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAA;AAE3E;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;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