@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,114 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file Which resolved admin place answers the query — the one ordering whose postcode rung is not a constant.
6
+ *
7
+ * `postalcode` is the only placetype whose specificity depends on the hit rather than the name. An NL PC6 or a GB unit
8
+ * postcode covers ~8 and ~15 addresses, categorically tighter than any locality centroid; a US ZIP, a French code
9
+ * postal or a German PLZ covers a delivery AREA. `PLACETYPE_SPECIFICITY` answers "which placetype covers less ground"
10
+ * and cannot express that split, so a consumer that sorts by it alone promotes every postcode.
11
+ *
12
+ * Two consumers need the split in two shapes, and both live here so a divergence is a test failure rather than a
13
+ * silent disagreement: result assembly walks a TAG ladder, and the eval harnesses sort resolved nodes by placetype.
14
+ */
15
+ import type { AddressNode } from "@mailwoman/core/decoder";
16
+ /**
17
+ * The admin fallback order when the postcode leads — a unit-grade exact hit, or an address system whose area-grade code
18
+ * is still finer than its locality ({@link areaPostcodeLeadsLocality}).
19
+ *
20
+ * The JP rungs (`municipality`, `district`, `prefecture`) sit beside their Latin counterparts, and `municipality`
21
+ * stands ABOVE `district` on purpose: a district (大字 / 町名) resolves without its municipality as a parent more often
22
+ * than not, and the unscoped namesake it then picks can be another prefecture's (`市原市大作` → 921 km). Measured on 300 JP
23
+ * board rows @15 km: district-first 202 accepted, municipality-first 271.
24
+ */
25
+ export declare const ADMIN_LADDER_POSTCODE_FIRST: ReadonlyArray<string>;
26
+ /**
27
+ * The admin fallback order everywhere else: the locality tiers lead and the postcode sits between them and `region`.
28
+ *
29
+ * This is the #945 epoch convention and the DEFAULT rather than the universal answer — which address systems leave it
30
+ * is `AREA_POSTCODE_FINER_THAN_LOCALITY`'s question, and that table carries the per-country measurement.
31
+ */
32
+ export declare const ADMIN_LADDER_LOCALITY_FIRST: ReadonlyArray<string>;
33
+ /**
34
+ * The resolved postcode a ladder decision reads: the PARSED span, the resolver's own hit, and the country the resolver
35
+ * placed it in.
36
+ *
37
+ * The first two are needed together because a full unit shape the resolver answered with a coarser stem is area-grade,
38
+ * whatever the user typed. `country` is separate evidence and answers a different question — not how tight this code
39
+ * is, but whether this address system's codes are tighter than its localities at all.
40
+ */
41
+ export interface ResolvedPostcodeHit {
42
+ value: string;
43
+ resolverName: string | undefined;
44
+ /**
45
+ * ISO-3166 alpha-2 the RESOLVER placed the postcode in, not a caller's requested scope. Absent when the postcode did
46
+ * not resolve to a country, which reads as the locality-first default.
47
+ */
48
+ country?: string;
49
+ }
50
+ /**
51
+ * Pick the admin fallback order for one resolved tree.
52
+ *
53
+ * Two independent routes to postcode-first: the code itself is unit-grade, or the address system's area-grade codes are
54
+ * finer than its localities. Either one is sufficient and the second is what makes this per-country rather than
55
+ * global.
56
+ */
57
+ export declare function adminLadderFor(postcode: ResolvedPostcodeHit | undefined): ReadonlyArray<string>;
58
+ /**
59
+ * The ladder for a flat list of resolved nodes — the shape result assembly holds.
60
+ *
61
+ * Which node counts, and which of its fields the decision reads, is part of the ordering rather than the caller's
62
+ * business: `country` is the one the RESOLVER placed the code in, never a caller's requested scope, because the ladder
63
+ * is asking which address system this code belongs to and a scope is a filter on the answer rather than evidence about
64
+ * it. Getting that wrong at a call site would be invisible.
65
+ */
66
+ export declare function adminLadderForNodes(nodes: readonly AddressNode[]): ReadonlyArray<string>;
67
+ /**
68
+ * Where an AREA-grade postal code sits on `PLACETYPE_SPECIFICITY`: below the whole locality tier, above `county` (2).
69
+ *
70
+ * The tier is `PLACETYPE_FILTER_GROUPS.locality` — `locality` (4), `borough` (5) and `localadmin` (3) — not the
71
+ * `locality` placetype alone, because that is what the resolver's own `locality` tag expands to. New England civil
72
+ * towns are `localadmin` in WOF, so a value between `locality` and `localadmin` would rank a US ZIP above the town it
73
+ * sits in and reproduce the defect on exactly the rows that motivated the group.
74
+ *
75
+ * Deliberately not an integer. The scale's rungs are placetypes and this is not one — it is the position
76
+ * {@link ADMIN_LADDER_LOCALITY_FIRST} puts a postcode in, expressed on the scale the sorting consumers already use.
77
+ */
78
+ export declare const AREA_GRADE_POSTALCODE_SPECIFICITY = 2.5;
79
+ /**
80
+ * A resolved place, as much of it as an ordering decision reads.
81
+ */
82
+ export interface ResolvedSpecificityInput {
83
+ placetype: string;
84
+ /**
85
+ * ISO-3166 alpha-2 the resolver placed this candidate in. Read only for a `postalcode`, where it decides whether the
86
+ * address system's area-grade codes outrank its localities.
87
+ */
88
+ country?: string;
89
+ /**
90
+ * The parsed span. Absent for a non-postcode candidate, where nothing conditional applies.
91
+ */
92
+ value?: string;
93
+ /**
94
+ * The resolver's own hit name, as `resolver_name` metadata carries it.
95
+ */
96
+ resolverName?: string;
97
+ }
98
+ /**
99
+ * Rank a resolved place for "whose coordinate answers the query" — `PLACETYPE_SPECIFICITY`, except that a `postalcode`
100
+ * is ranked by its hit.
101
+ *
102
+ * An unranked placetype returns `-Infinity` so it wins only when nothing else resolved.
103
+ */
104
+ export declare function resolvedSpecificity(candidate: ResolvedSpecificityInput): number;
105
+ /**
106
+ * The best of a resolved set under {@link resolvedSpecificity}, or `null` when the set is empty. Ties keep the first,
107
+ * which is document order.
108
+ *
109
+ * `toInput` is explicit rather than structural because each consumer spells the resolver's hit differently — the eval
110
+ * harnesses carry it as `name`, result assembly reads it off `resolver_name` metadata — and a projection at the call
111
+ * site is where that mapping is visible.
112
+ */
113
+ export declare function mostSpecificResolved<T>(candidates: readonly T[], toInput: (candidate: T) => ResolvedSpecificityInput): T | null;
114
+ //# sourceMappingURL=winner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"winner.d.ts","sourceRoot":"","sources":["../../lib/admin/winner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAG1D;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,EAAE,aAAa,CAAC,MAAM,CAS7D,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,aAAa,CAAC,MAAM,CAS7D,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IACnC,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,mBAAmB,GAAG,SAAS,GAAG,aAAa,CAAC,MAAM,CAAC,CAO/F;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,CAYxF;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iCAAiC,MAAM,CAAA;AAEpD;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC,SAAS,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,wBAAwB,GAAG,MAAM,CAU/E;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACrC,UAAU,EAAE,SAAS,CAAC,EAAE,EACxB,OAAO,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,wBAAwB,GACjD,CAAC,GAAG,IAAI,CAcV"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file Which resolved admin place answers the query — the one ordering whose postcode rung is not a constant.
6
+ *
7
+ * `postalcode` is the only placetype whose specificity depends on the hit rather than the name. An NL PC6 or a GB unit
8
+ * postcode covers ~8 and ~15 addresses, categorically tighter than any locality centroid; a US ZIP, a French code
9
+ * postal or a German PLZ covers a delivery AREA. `PLACETYPE_SPECIFICITY` answers "which placetype covers less ground"
10
+ * and cannot express that split, so a consumer that sorts by it alone promotes every postcode.
11
+ *
12
+ * Two consumers need the split in two shapes, and both live here so a divergence is a test failure rather than a
13
+ * silent disagreement: result assembly walks a TAG ladder, and the eval harnesses sort resolved nodes by placetype.
14
+ */
15
+ import { areaPostcodeLeadsLocality, isUnitGradePostcodeHit } from "@mailwoman/codex";
16
+ import { PLACETYPE_SPECIFICITY } from "@mailwoman/core/resources/whosonfirst/specificity";
17
+ /**
18
+ * The admin fallback order when the postcode leads — a unit-grade exact hit, or an address system whose area-grade code
19
+ * is still finer than its locality ({@link areaPostcodeLeadsLocality}).
20
+ *
21
+ * The JP rungs (`municipality`, `district`, `prefecture`) sit beside their Latin counterparts, and `municipality`
22
+ * stands ABOVE `district` on purpose: a district (大字 / 町名) resolves without its municipality as a parent more often
23
+ * than not, and the unscoped namesake it then picks can be another prefecture's (`市原市大作` → 921 km). Measured on 300 JP
24
+ * board rows @15 km: district-first 202 accepted, municipality-first 271.
25
+ */
26
+ export const ADMIN_LADDER_POSTCODE_FIRST = [
27
+ "postcode",
28
+ "locality",
29
+ "municipality",
30
+ "dependent_locality",
31
+ "district",
32
+ "region",
33
+ "prefecture",
34
+ "country",
35
+ ];
36
+ /**
37
+ * The admin fallback order everywhere else: the locality tiers lead and the postcode sits between them and `region`.
38
+ *
39
+ * This is the #945 epoch convention and the DEFAULT rather than the universal answer — which address systems leave it
40
+ * is `AREA_POSTCODE_FINER_THAN_LOCALITY`'s question, and that table carries the per-country measurement.
41
+ */
42
+ export const ADMIN_LADDER_LOCALITY_FIRST = [
43
+ "locality",
44
+ "municipality",
45
+ "dependent_locality",
46
+ "district",
47
+ "postcode",
48
+ "region",
49
+ "prefecture",
50
+ "country",
51
+ ];
52
+ /**
53
+ * Pick the admin fallback order for one resolved tree.
54
+ *
55
+ * Two independent routes to postcode-first: the code itself is unit-grade, or the address system's area-grade codes are
56
+ * finer than its localities. Either one is sufficient and the second is what makes this per-country rather than
57
+ * global.
58
+ */
59
+ export function adminLadderFor(postcode) {
60
+ if (postcode === undefined)
61
+ return ADMIN_LADDER_LOCALITY_FIRST;
62
+ const leads = isUnitGradePostcodeHit(postcode.value, postcode.resolverName) || areaPostcodeLeadsLocality(postcode.country);
63
+ return leads ? ADMIN_LADDER_POSTCODE_FIRST : ADMIN_LADDER_LOCALITY_FIRST;
64
+ }
65
+ /**
66
+ * The ladder for a flat list of resolved nodes — the shape result assembly holds.
67
+ *
68
+ * Which node counts, and which of its fields the decision reads, is part of the ordering rather than the caller's
69
+ * business: `country` is the one the RESOLVER placed the code in, never a caller's requested scope, because the ladder
70
+ * is asking which address system this code belongs to and a scope is a filter on the answer rather than evidence about
71
+ * it. Getting that wrong at a call site would be invisible.
72
+ */
73
+ export function adminLadderForNodes(nodes) {
74
+ const node = nodes.find((n) => n.tag === "postcode" && n.lat != null && n.lon != null);
75
+ if (!node)
76
+ return ADMIN_LADDER_LOCALITY_FIRST;
77
+ const country = node.metadata?.["resolver_country"];
78
+ return adminLadderFor({
79
+ value: node.value,
80
+ resolverName: node.metadata?.["resolver_name"],
81
+ ...(typeof country === "string" ? { country } : {}),
82
+ });
83
+ }
84
+ /**
85
+ * Where an AREA-grade postal code sits on `PLACETYPE_SPECIFICITY`: below the whole locality tier, above `county` (2).
86
+ *
87
+ * The tier is `PLACETYPE_FILTER_GROUPS.locality` — `locality` (4), `borough` (5) and `localadmin` (3) — not the
88
+ * `locality` placetype alone, because that is what the resolver's own `locality` tag expands to. New England civil
89
+ * towns are `localadmin` in WOF, so a value between `locality` and `localadmin` would rank a US ZIP above the town it
90
+ * sits in and reproduce the defect on exactly the rows that motivated the group.
91
+ *
92
+ * Deliberately not an integer. The scale's rungs are placetypes and this is not one — it is the position
93
+ * {@link ADMIN_LADDER_LOCALITY_FIRST} puts a postcode in, expressed on the scale the sorting consumers already use.
94
+ */
95
+ export const AREA_GRADE_POSTALCODE_SPECIFICITY = 2.5;
96
+ /**
97
+ * Rank a resolved place for "whose coordinate answers the query" — `PLACETYPE_SPECIFICITY`, except that a `postalcode`
98
+ * is ranked by its hit.
99
+ *
100
+ * An unranked placetype returns `-Infinity` so it wins only when nothing else resolved.
101
+ */
102
+ export function resolvedSpecificity(candidate) {
103
+ if (candidate.placetype !== "postalcode") {
104
+ return PLACETYPE_SPECIFICITY[candidate.placetype] ?? Number.NEGATIVE_INFINITY;
105
+ }
106
+ const leads = isUnitGradePostcodeHit(candidate.value ?? "", candidate.resolverName) ||
107
+ areaPostcodeLeadsLocality(candidate.country);
108
+ return leads ? (PLACETYPE_SPECIFICITY["postalcode"] ?? Number.NEGATIVE_INFINITY) : AREA_GRADE_POSTALCODE_SPECIFICITY;
109
+ }
110
+ /**
111
+ * The best of a resolved set under {@link resolvedSpecificity}, or `null` when the set is empty. Ties keep the first,
112
+ * which is document order.
113
+ *
114
+ * `toInput` is explicit rather than structural because each consumer spells the resolver's hit differently — the eval
115
+ * harnesses carry it as `name`, result assembly reads it off `resolver_name` metadata — and a projection at the call
116
+ * site is where that mapping is visible.
117
+ */
118
+ export function mostSpecificResolved(candidates, toInput) {
119
+ let best = null;
120
+ let bestRank = Number.NEGATIVE_INFINITY;
121
+ for (const candidate of candidates) {
122
+ const rank = resolvedSpecificity(toInput(candidate));
123
+ if (best === null || rank > bestRank) {
124
+ best = candidate;
125
+ bestRank = rank;
126
+ }
127
+ }
128
+ return best;
129
+ }
130
+ //# sourceMappingURL=winner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"winner.js","sourceRoot":"","sources":["../../lib/admin/winner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAEpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AAEzF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAA0B;IACjE,UAAU;IACV,UAAU;IACV,cAAc;IACd,oBAAoB;IACpB,UAAU;IACV,QAAQ;IACR,YAAY;IACZ,SAAS;CACT,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAA0B;IACjE,UAAU;IACV,cAAc;IACd,oBAAoB;IACpB,UAAU;IACV,UAAU;IACV,QAAQ;IACR,YAAY;IACZ,SAAS;CACT,CAAA;AAoBD;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,QAAyC;IACvE,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,2BAA2B,CAAA;IAE9D,MAAM,KAAK,GACV,sBAAsB,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,IAAI,yBAAyB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IAE7G,OAAO,KAAK,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,2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,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CACnC,UAAwB,EACxB,OAAmD;IAEnD,IAAI,IAAI,GAAa,IAAI,CAAA;IACzB,IAAI,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAA;IAEvC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,mBAAmB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;QAEpD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,GAAG,QAAQ,EAAE,CAAC;YACtC,IAAI,GAAG,SAAS,CAAA;YAChB,QAAQ,GAAG,IAAI,CAAA;QAChB,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAA;AACZ,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Which optional {@link ResolverBackend} methods the loaded backend does not implement, and what each absence
7
+ * silently costs.
8
+ *
9
+ * `ancestors` and `coincidentLocalitiesFor` are optional on the backend contract, so a backend that omits them is
10
+ * valid — but the resolver passes that lack through as a guard that simply returns. The option those guards serve
11
+ * (`hierarchyCompletion`) defaults to ON, so a caller who never touched it gets a feature that reports success while
12
+ * doing nothing. That is absence read as a negative answer, and the rule is that a magnitude never carries its own
13
+ * absence: the gap has to be stated somewhere a caller can read it.
14
+ *
15
+ * This module states it. `describeCapabilityGaps` is pure and cheap enough to run at construction; the resolver
16
+ * exposes the result on `Resolver.capabilityGaps` and warns once so the gap appears in a log without a caller having
17
+ * to ask. It changes no resolution behavior — a gap that was silent is now legible, nothing more.
18
+ */
19
+ import type { BackendCapabilityGap, ResolverBackend } from "@mailwoman/core/resolver";
20
+ /**
21
+ * Enumerate the consequential capabilities this backend does not implement. Empty means every default-ON option the
22
+ * resolver offers has the backend support it needs.
23
+ */
24
+ export declare function describeCapabilityGaps(backend: ResolverBackend): readonly BackendCapabilityGap[];
25
+ /**
26
+ * One log line for a backend's whole set of gaps. Deliberately short: what is missing, which option that costs, and
27
+ * where the consequences are written down. The per-gap `degrades` prose stays on the data for a consumer that wants it,
28
+ * because a line long enough to carry it is a line an operator learns to skip.
29
+ */
30
+ export declare function formatCapabilityGaps(gaps: readonly BackendCapabilityGap[]): string;
31
+ /**
32
+ * Report a backend's gaps to stderr the first time this process sees them. The gaps are data on
33
+ * `Resolver.capabilityGaps` regardless; this exists so they also reach an operator who never thought to look. The line
34
+ * disappears on its own once the backend implements the methods, so it cannot become permanent wallpaper.
35
+ */
36
+ export declare function reportCapabilityGaps(gaps: readonly BackendCapabilityGap[]): void;
37
+ //# sourceMappingURL=backend-capabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-capabilities.d.ts","sourceRoot":"","sources":["../lib/backend-capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAwBrF;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,eAAe,GAAG,SAAS,oBAAoB,EAAE,CAMhG;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,oBAAoB,EAAE,GAAG,MAAM,CAOlF;AAQD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,oBAAoB,EAAE,GAAG,IAAI,CAOhF"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Which optional {@link ResolverBackend} methods the loaded backend does not implement, and what each absence
7
+ * silently costs.
8
+ *
9
+ * `ancestors` and `coincidentLocalitiesFor` are optional on the backend contract, so a backend that omits them is
10
+ * valid — but the resolver passes that lack through as a guard that simply returns. The option those guards serve
11
+ * (`hierarchyCompletion`) defaults to ON, so a caller who never touched it gets a feature that reports success while
12
+ * doing nothing. That is absence read as a negative answer, and the rule is that a magnitude never carries its own
13
+ * absence: the gap has to be stated somewhere a caller can read it.
14
+ *
15
+ * This module states it. `describeCapabilityGaps` is pure and cheap enough to run at construction; the resolver
16
+ * exposes the result on `Resolver.capabilityGaps` and warns once so the gap appears in a log without a caller having
17
+ * to ask. It changes no resolution behavior — a gap that was silent is now legible, nothing more.
18
+ */
19
+ /**
20
+ * The optional backend methods whose absence degrades a passing default, paired with what stops working. A method whose
21
+ * absence is inert (or whose option is opt-in and therefore a deliberate caller choice) does not belong here — the list
22
+ * exists to name silent degradation, not to inventory the interface.
23
+ */
24
+ const CONSEQUENTIAL_CAPABILITIES = [
25
+ {
26
+ capability: "ancestors",
27
+ option: "hierarchyCompletion",
28
+ defaultOn: true,
29
+ degrades: "the containment lineage is never read: a parse that drops the locality of a city-state or dependent locality keeps the gap, and `metadata.ancestors` (the lineage the Nominatim and Photon drop-ins expose) is never populated",
30
+ },
31
+ {
32
+ capability: "coincidentLocalitiesFor",
33
+ option: "hierarchyCompletion",
34
+ defaultOn: true,
35
+ degrades: "the dual-role pass never runs: a region that is also a locality under the same name resolves to one role only",
36
+ },
37
+ ];
38
+ /**
39
+ * Enumerate the consequential capabilities this backend does not implement. Empty means every default-ON option the
40
+ * resolver offers has the backend support it needs.
41
+ */
42
+ export function describeCapabilityGaps(backend) {
43
+ const name = backend.constructor?.name || "backend";
44
+ return CONSEQUENTIAL_CAPABILITIES.filter((c) => typeof backend[c.capability] !== "function").map((c) => ({ ...c, backend: name }));
45
+ }
46
+ /**
47
+ * One log line for a backend's whole set of gaps. Deliberately short: what is missing, which option that costs, and
48
+ * where the consequences are written down. The per-gap `degrades` prose stays on the data for a consumer that wants it,
49
+ * because a line long enough to carry it is a line an operator learns to skip.
50
+ */
51
+ export function formatCapabilityGaps(gaps) {
52
+ const [first] = gaps;
53
+ const names = gaps.map((g) => `${g.capability}()`).join(", ");
54
+ const options = [...new Set(gaps.map((g) => g.option))].join(", ");
55
+ const posture = gaps.some((g) => g.defaultOn) ? "default-ON" : "opt-in";
56
+ return `[resolver] ${first?.backend} lacks ${names} — ${options} (${posture}) silently no-ops; see docs/engineering/reference/resolver-backends.mdx`;
57
+ }
58
+ /**
59
+ * Backends already reported, so a process that builds many resolvers over one artifact — the eval harness, the
60
+ * gauntlet, a batch worker — states the gap once rather than once per construction.
61
+ */
62
+ const reported = new Set();
63
+ /**
64
+ * Report a backend's gaps to stderr the first time this process sees them. The gaps are data on
65
+ * `Resolver.capabilityGaps` regardless; this exists so they also reach an operator who never thought to look. The line
66
+ * disappears on its own once the backend implements the methods, so it cannot become permanent wallpaper.
67
+ */
68
+ export function reportCapabilityGaps(gaps) {
69
+ const [first] = gaps;
70
+ if (!first || reported.has(first.backend))
71
+ return;
72
+ reported.add(first.backend);
73
+ console.error(formatCapabilityGaps(gaps));
74
+ }
75
+ //# sourceMappingURL=backend-capabilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-capabilities.js","sourceRoot":"","sources":["../lib/backend-capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH;;;;GAIG;AACH,MAAM,0BAA0B,GAAyD;IACxF;QACC,UAAU,EAAE,WAAW;QACvB,MAAM,EAAE,qBAAqB;QAC7B,SAAS,EAAE,IAAI;QACf,QAAQ,EACP,gOAAgO;KACjO;IACD;QACC,UAAU,EAAE,yBAAyB;QACrC,MAAM,EAAE,qBAAqB;QAC7B,SAAS,EAAE,IAAI;QACf,QAAQ,EACP,+GAA+G;KAChH;CACD,CAAA;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAwB;IAC9D,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,IAAI,IAAI,SAAS,CAAA;IAEnD,OAAO,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,U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AAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * The bare-toponym ADMIN race — the policy for a query that is one bare name ("Japan", "Georgia").
7
+ * The locality placetype filter makes country/region namesakes unreachable at any rank, so the
8
+ * resolver's lookup runs these side races for the tree's lone locality-tagged span and promotes an
9
+ * admin namesake under the rules each prober documents. Split from `resolve.ts` so the walk file
10
+ * holds the walk and this one holds the race policy.
11
+ */
12
+ import type { AddressNode, AddressTree } from "@mailwoman/core/decoder";
13
+ import type { PlacetypeMap, ResolvedPlace, ResolverBackend } from "@mailwoman/core/resolver";
14
+ /**
15
+ * The tree's single value-bearing node when it is locality-tagged, else null — the bare-toponym shape whose
16
+ * country-placetype sibling race `#lookupAndPick` runs. A bare name the parser tagged `locality` can name a country
17
+ * ("Japan", "China" — single country names are out of the parser's training distribution), and the locality placetype
18
+ * filter makes the country row unreachable regardless of how the ranking would order it. Any second value-bearing node
19
+ * makes the input address-shaped and the race stays off; `dependent_locality` maps to the same placetype but is an
20
+ * address-interior tag, so only a literal `locality` qualifies.
21
+ */
22
+ export declare function loneBareLocalityNode(tree: AddressTree, placetypeMap: PlacetypeMap): AddressNode | null;
23
+ /**
24
+ * The log-population dominance a bare REGION namesake must hold over the locality winner before the bare-toponym race
25
+ * promotes it. The value is DECISIVE_MARGIN_LOG10 from the ablation-expectation model (0.5 — below it the top-ranked
26
+ * place is the intended one 52.4% of the time, above it 89.1%); restated here because the resolver package cannot
27
+ * import the eval harness. If that measured value moves, move this with it.
28
+ */
29
+ export declare const BARE_REGION_DOMINANCE_LOG10 = 0.5;
30
+ /**
31
+ * Log10(population + 1), 0 when the backend carries none — the saturation-free magnitude the bare-region dominance rule
32
+ * compares (prominence caps at the backend's populationBoost and erases exactly the margins this rule needs).
33
+ */
34
+ export declare function logPopulation(place: ResolvedPlace): number;
35
+ /**
36
+ * The larger-population admin namesake of the two side races, or null when neither ran or hit.
37
+ */
38
+ export declare function pickLargerAdmin(country: ResolvedPlace | null, region: ResolvedPlace | null): ResolvedPlace | null;
39
+ /**
40
+ * The best `country`-placetype row for a bare toponym span, or null. `scopedCountry` is the same hard filter the
41
+ * locality query ran under — an EXPLICIT caller scope therefore bounds this race too (a foreign country row cannot
42
+ * outrank inside an explicit scope), while the bare-locality posture's withheld scope leaves it worldwide. Exact
43
+ * matches only: the fuzzy tier exists for typo recovery on address spans, and a fuzzy country is a guess this race must
44
+ * never promote. Abbreviation/gloss alias rows never enter ({@link BARE_RACE_EXCLUDED_NAME_ROLES}).
45
+ */
46
+ export declare function bareCountryCandidate(backend: ResolverBackend, text: string, scopedCountry: string | undefined): Promise<ResolvedPlace | null>;
47
+ /**
48
+ * The best `region`-placetype row for a bare toponym span, or null — the sibling of {@link #bareCountryCandidate} for
49
+ * the US-state class (bare "Georgia"/"Texas" the parser tags `locality`). Same contract: the locality query's own
50
+ * country filter bounds it, exact matches only with abbreviation/gloss rows excluded, and the placetype check guards
51
+ * partial backends. (The `place_abbr`-staged region abbreviations — bare "TX"/"CA" — are role-NULL primaries and stay
52
+ * fully reachable; the exclusion removes only the names-table abbreviation ALIASES like Toledo's "TO".)
53
+ */
54
+ export declare function bareRegionCandidate(backend: ResolverBackend, text: string, scopedCountry: string | undefined): Promise<ResolvedPlace | null>;
55
+ //# sourceMappingURL=bare-toponym-race.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bare-toponym-race.d.ts","sourceRoot":"","sources":["../lib/bare-toponym-race.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAgB,MAAM,yBAAyB,CAAA;AAErF,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE5F;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,GAAG,WAAW,GAAG,IAAI,CAKtG;AAED;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAA;AAE9C;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CAE1D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,GAAG,aAAa,GAAG,IAAI,CAMjH;AAUD;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACzC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,GAAG,SAAS,GAC/B,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAoB/B;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACxC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,GAAG,SAAS,GAC/B,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAkB/B"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * The bare-toponym ADMIN race — the policy for a query that is one bare name ("Japan", "Georgia").
7
+ * The locality placetype filter makes country/region namesakes unreachable at any rank, so the
8
+ * resolver's lookup runs these side races for the tree's lone locality-tagged span and promotes an
9
+ * admin namesake under the rules each prober documents. Split from `resolve.ts` so the walk file
10
+ * holds the walk and this one holds the race policy.
11
+ */
12
+ import { loneValueBearingNode } from "@mailwoman/core/decoder";
13
+ /**
14
+ * The tree's single value-bearing node when it is locality-tagged, else null — the bare-toponym shape whose
15
+ * country-placetype sibling race `#lookupAndPick` runs. A bare name the parser tagged `locality` can name a country
16
+ * ("Japan", "China" — single country names are out of the parser's training distribution), and the locality placetype
17
+ * filter makes the country row unreachable regardless of how the ranking would order it. Any second value-bearing node
18
+ * makes the input address-shaped and the race stays off; `dependent_locality` maps to the same placetype but is an
19
+ * address-interior tag, so only a literal `locality` qualifies.
20
+ */
21
+ export function loneBareLocalityNode(tree, placetypeMap) {
22
+ if (placetypeMap["locality"] !== "locality")
23
+ return null;
24
+ const lone = loneValueBearingNode(tree);
25
+ return lone?.tag === "locality" ? lone : null;
26
+ }
27
+ /**
28
+ * The log-population dominance a bare REGION namesake must hold over the locality winner before the bare-toponym race
29
+ * promotes it. The value is DECISIVE_MARGIN_LOG10 from the ablation-expectation model (0.5 — below it the top-ranked
30
+ * place is the intended one 52.4% of the time, above it 89.1%); restated here because the resolver package cannot
31
+ * import the eval harness. If that measured value moves, move this with it.
32
+ */
33
+ export const BARE_REGION_DOMINANCE_LOG10 = 0.5;
34
+ /**
35
+ * Log10(population + 1), 0 when the backend carries none — the saturation-free magnitude the bare-region dominance rule
36
+ * compares (prominence caps at the backend's populationBoost and erases exactly the margins this rule needs).
37
+ */
38
+ export function logPopulation(place) {
39
+ return Math.log10((place.population ?? 0) + 1);
40
+ }
41
+ /**
42
+ * The larger-population admin namesake of the two side races, or null when neither ran or hit.
43
+ */
44
+ export function pickLargerAdmin(country, region) {
45
+ if (!country)
46
+ return region;
47
+ if (!region)
48
+ return country;
49
+ return logPopulation(region) > logPopulation(country) ? region : country;
50
+ }
51
+ /**
52
+ * Alias roles the side races refuse to answer through (#1730): a lone bare token that only reaches a place via an
53
+ * ABBREVIATION row ("Tó" folds onto Toledo's "TO") or a translation-gloss row did not name that place — while the
54
+ * role-NULL exonym tier stays open, which is what lets 格鲁吉亚 win the country race through its display-name alias. An
55
+ * artifact without the role column ignores the exclusion and the races behave as before.
56
+ */
57
+ const BARE_RACE_EXCLUDED_NAME_ROLES = ["abbr", "gloss"];
58
+ /**
59
+ * The best `country`-placetype row for a bare toponym span, or null. `scopedCountry` is the same hard filter the
60
+ * locality query ran under — an EXPLICIT caller scope therefore bounds this race too (a foreign country row cannot
61
+ * outrank inside an explicit scope), while the bare-locality posture's withheld scope leaves it worldwide. Exact
62
+ * matches only: the fuzzy tier exists for typo recovery on address spans, and a fuzzy country is a guess this race must
63
+ * never promote. Abbreviation/gloss alias rows never enter ({@link BARE_RACE_EXCLUDED_NAME_ROLES}).
64
+ */
65
+ export async function bareCountryCandidate(backend, text, scopedCountry) {
66
+ try {
67
+ const hits = await backend.findPlace({
68
+ text,
69
+ placetype: "country",
70
+ limit: 1,
71
+ excludeNameRoles: BARE_RACE_EXCLUDED_NAME_ROLES,
72
+ ...(scopedCountry ? { country: scopedCountry } : {}),
73
+ });
74
+ const top = hits[0];
75
+ // The placetype check is required, not paranoia: a backend that ignores the filter
76
+ // (several test stubs, and any future partial implementation) would otherwise hand this
77
+ // race a LOCALITY row wearing a country costume, and the repick would demote the real pick.
78
+ return top && top.placetype === "country" && top.exactMatch !== false ? top : null;
79
+ }
80
+ catch {
81
+ // A failed side race must never abort the primary lookup — the locality answer stands.
82
+ return null;
83
+ }
84
+ }
85
+ /**
86
+ * The best `region`-placetype row for a bare toponym span, or null — the sibling of {@link #bareCountryCandidate} for
87
+ * the US-state class (bare "Georgia"/"Texas" the parser tags `locality`). Same contract: the locality query's own
88
+ * country filter bounds it, exact matches only with abbreviation/gloss rows excluded, and the placetype check guards
89
+ * partial backends. (The `place_abbr`-staged region abbreviations — bare "TX"/"CA" — are role-NULL primaries and stay
90
+ * fully reachable; the exclusion removes only the names-table abbreviation ALIASES like Toledo's "TO".)
91
+ */
92
+ export async function bareRegionCandidate(backend, text, scopedCountry) {
93
+ try {
94
+ const hits = await backend.findPlace({
95
+ text,
96
+ placetype: "region",
97
+ limit: 1,
98
+ excludeNameRoles: BARE_RACE_EXCLUDED_NAME_ROLES,
99
+ ...(scopedCountry ? { country: scopedCountry } : {}),
100
+ });
101
+ const top = hits[0];
102
+ return top && (top.placetype === "region" || top.placetype === "macroregion") && top.exactMatch !== false
103
+ ? top
104
+ : null;
105
+ }
106
+ catch {
107
+ return null;
108
+ }
109
+ }
110
+ //# sourceMappingURL=bare-toponym-race.js.map
@@ -0,0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AAA;IACZ,CAAC;AACF,CAAC"}
@@ -0,0 +1,24 @@
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
+ import type { AddressNode } from "@mailwoman/core/decoder";
11
+ import type { ResolvedPlace } from "@mailwoman/core/resolver";
12
+ import type { CoordinateOptionalPlace } from "#postcode/prefix";
13
+ /**
14
+ * A resolved node carries a real coordinate (placeID set + non-zero lat/lon).
15
+ */
16
+ export declare function isResolvedWithCoord(n: AddressNode): boolean;
17
+ /**
18
+ * Stamp a node with resolver-supplied attribution. Displaces any prior classifier `source` / `sourceID` into
19
+ * `metadata.classifier_source` / `metadata.classifier_source_id` so debugging tools can still see who made the original
20
+ * assertion. Surfaces the runner-up candidates on `alternatives` so callers can disambiguate (Springfield-class
21
+ * failures, [#8 in the failure catalogue]).
22
+ */
23
+ export declare function decorateNode(node: AddressNode, resolved: CoordinateOptionalPlace, alternatives: ResolvedPlace[]): void;
24
+ //# sourceMappingURL=decorate-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorate-node.d.ts","sourceRoot":"","sources":["../lib/decorate-node.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAE7D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAE/D;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,WAAW,GAAG,OAAO,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC3B,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,uBAAuB,EACjC,YAAY,EAAE,aAAa,EAAE,GAC3B,IAAI,CA8FN"}