@mailwoman/resolver 9.0.0 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +89 -0
  2. package/admin-coherence-passes.ts +435 -0
  3. package/admin-containment.ts +101 -0
  4. package/admin-winner.ts +178 -0
  5. package/backend-capabilities.ts +88 -0
  6. package/bare-toponym-race.ts +129 -0
  7. package/decorate-node.ts +127 -0
  8. package/fold-name.ts +19 -3
  9. package/index.ts +14 -0
  10. package/out/admin-coherence-passes.d.ts +70 -0
  11. package/out/admin-coherence-passes.d.ts.map +1 -0
  12. package/out/admin-coherence-passes.js +327 -0
  13. package/out/admin-coherence-passes.js.map +1 -0
  14. package/out/admin-containment.d.ts +48 -0
  15. package/out/admin-containment.d.ts.map +1 -0
  16. package/out/admin-containment.js +82 -0
  17. package/out/admin-containment.js.map +1 -0
  18. package/out/admin-winner.d.ts +109 -0
  19. package/out/admin-winner.d.ts.map +1 -0
  20. package/out/admin-winner.js +119 -0
  21. package/out/admin-winner.js.map +1 -0
  22. package/out/backend-capabilities.d.ts +37 -0
  23. package/out/backend-capabilities.d.ts.map +1 -0
  24. package/out/backend-capabilities.js +75 -0
  25. package/out/backend-capabilities.js.map +1 -0
  26. package/out/bare-toponym-race.d.ts +55 -0
  27. package/out/bare-toponym-race.d.ts.map +1 -0
  28. package/out/bare-toponym-race.js +110 -0
  29. package/out/bare-toponym-race.js.map +1 -0
  30. package/out/decorate-node.d.ts +24 -0
  31. package/out/decorate-node.d.ts.map +1 -0
  32. package/out/decorate-node.js +103 -0
  33. package/out/decorate-node.js.map +1 -0
  34. package/out/fold-name.d.ts +18 -3
  35. package/out/fold-name.d.ts.map +1 -1
  36. package/out/fold-name.js +19 -3
  37. package/out/fold-name.js.map +1 -1
  38. package/out/index.d.ts +4 -1
  39. package/out/index.d.ts.map +1 -1
  40. package/out/index.js +3 -1
  41. package/out/index.js.map +1 -1
  42. package/out/postcode-country-coherence.d.ts +91 -14
  43. package/out/postcode-country-coherence.d.ts.map +1 -1
  44. package/out/postcode-country-coherence.js +279 -42
  45. package/out/postcode-country-coherence.js.map +1 -1
  46. package/out/postcode-prefix.d.ts +101 -0
  47. package/out/postcode-prefix.d.ts.map +1 -0
  48. package/out/postcode-prefix.js +125 -0
  49. package/out/postcode-prefix.js.map +1 -0
  50. package/out/postcode-shape-coherence.d.ts +113 -0
  51. package/out/postcode-shape-coherence.d.ts.map +1 -0
  52. package/out/postcode-shape-coherence.js +193 -0
  53. package/out/postcode-shape-coherence.js.map +1 -0
  54. package/out/resolve.d.ts +1 -1
  55. package/out/resolve.d.ts.map +1 -1
  56. package/out/resolve.js +592 -410
  57. package/out/resolve.js.map +1 -1
  58. package/out/span-rescore.d.ts +28 -0
  59. package/out/span-rescore.d.ts.map +1 -1
  60. package/out/span-rescore.js +151 -17
  61. package/out/span-rescore.js.map +1 -1
  62. package/out/street-evidence.js +1 -1
  63. package/out/street-evidence.js.map +1 -1
  64. package/out/street-tier.d.ts.map +1 -1
  65. package/out/street-tier.js +28 -5
  66. package/out/street-tier.js.map +1 -1
  67. package/out/toponym-prior.d.ts +139 -0
  68. package/out/toponym-prior.d.ts.map +1 -0
  69. package/out/toponym-prior.js +308 -0
  70. package/out/toponym-prior.js.map +1 -0
  71. package/package.json +98 -7
  72. package/postcode-country-coherence.ts +355 -50
  73. package/postcode-prefix.ts +166 -0
  74. package/postcode-shape-coherence.ts +248 -0
  75. package/resolve.ts +809 -527
  76. package/span-rescore.ts +206 -19
  77. package/street-evidence.ts +1 -1
  78. package/street-tier.ts +31 -5
  79. package/toponym-prior.ts +367 -0
@@ -0,0 +1,119 @@
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
+ export const ADMIN_LADDER_POSTCODE_FIRST = [
22
+ "postcode",
23
+ "locality",
24
+ "dependent_locality",
25
+ "region",
26
+ "country",
27
+ ];
28
+ /**
29
+ * The admin fallback order everywhere else: the locality tiers lead and the postcode sits between them and `region`.
30
+ *
31
+ * This is the #945 epoch convention, and it is the DEFAULT rather than the universal answer — which address systems
32
+ * leave it is `AREA_POSTCODE_FINER_THAN_LOCALITY`'s question, and that table carries the per-country measurement.
33
+ */
34
+ export const ADMIN_LADDER_LOCALITY_FIRST = [
35
+ "locality",
36
+ "dependent_locality",
37
+ "postcode",
38
+ "region",
39
+ "country",
40
+ ];
41
+ /**
42
+ * Pick the admin fallback order for one resolved tree.
43
+ *
44
+ * Two independent routes to postcode-first: the code itself is unit-grade, or the address system's area-grade codes are
45
+ * finer than its localities. Either one is sufficient and the second is what makes this per-country rather than
46
+ * global.
47
+ */
48
+ export function adminLadderFor(postcode) {
49
+ if (postcode === undefined)
50
+ return ADMIN_LADDER_LOCALITY_FIRST;
51
+ const leads = isUnitGradePostcodeHit(postcode.value, postcode.resolverName) || areaPostcodeLeadsLocality(postcode.country);
52
+ return leads ? ADMIN_LADDER_POSTCODE_FIRST : ADMIN_LADDER_LOCALITY_FIRST;
53
+ }
54
+ /**
55
+ * The ladder for a flat list of resolved nodes — the shape result assembly holds.
56
+ *
57
+ * Which node counts, and which of its fields the decision reads, is part of the ordering rather than the caller's
58
+ * business: `country` is the one the RESOLVER placed the code in, never a caller's requested scope, because the ladder
59
+ * is asking which address system this code belongs to and a scope is a filter on the answer rather than evidence about
60
+ * it. Getting that wrong at a call site would be invisible.
61
+ */
62
+ export function adminLadderForNodes(nodes) {
63
+ const node = nodes.find((n) => n.tag === "postcode" && n.lat != null && n.lon != null);
64
+ if (!node)
65
+ return ADMIN_LADDER_LOCALITY_FIRST;
66
+ const country = node.metadata?.["resolver_country"];
67
+ return adminLadderFor({
68
+ value: node.value,
69
+ resolverName: node.metadata?.["resolver_name"],
70
+ ...(typeof country === "string" ? { country } : {}),
71
+ });
72
+ }
73
+ /**
74
+ * Where an AREA-grade postal code sits on `PLACETYPE_SPECIFICITY`: below the whole locality tier, above `county` (2).
75
+ *
76
+ * The tier is `PLACETYPE_FILTER_GROUPS.locality` — `locality` (4), `borough` (5) and `localadmin` (3) — not the
77
+ * `locality` placetype alone, because that is what the resolver's own `locality` tag expands to. New England civil
78
+ * towns are `localadmin` in WOF, so a value between `locality` and `localadmin` would rank a US ZIP above the town it
79
+ * sits in and reproduce the defect on exactly the rows that motivated the group.
80
+ *
81
+ * Deliberately not an integer. The scale's rungs are placetypes and this is not one — it is the position
82
+ * {@link ADMIN_LADDER_LOCALITY_FIRST} puts a postcode in, expressed on the scale the sorting consumers already use.
83
+ */
84
+ export const AREA_GRADE_POSTALCODE_SPECIFICITY = 2.5;
85
+ /**
86
+ * Rank a resolved place for "whose coordinate answers the query" — `PLACETYPE_SPECIFICITY`, except that a `postalcode`
87
+ * is ranked by its hit.
88
+ *
89
+ * An unranked placetype returns `-Infinity` so it wins only when nothing else resolved.
90
+ */
91
+ export function resolvedSpecificity(candidate) {
92
+ if (candidate.placetype !== "postalcode") {
93
+ return PLACETYPE_SPECIFICITY[candidate.placetype] ?? Number.NEGATIVE_INFINITY;
94
+ }
95
+ const leads = isUnitGradePostcodeHit(candidate.value ?? "", candidate.resolverName) ||
96
+ areaPostcodeLeadsLocality(candidate.country);
97
+ return leads ? (PLACETYPE_SPECIFICITY["postalcode"] ?? Number.NEGATIVE_INFINITY) : AREA_GRADE_POSTALCODE_SPECIFICITY;
98
+ }
99
+ /**
100
+ * The best of a resolved set under {@link resolvedSpecificity}, or `null` when the set is empty. Ties keep the first,
101
+ * which is document order.
102
+ *
103
+ * `toInput` is explicit rather than structural because each consumer spells the resolver's hit differently — the eval
104
+ * harnesses carry it as `name`, result assembly reads it off `resolver_name` metadata — and a projection at the call
105
+ * site is where that mapping is visible.
106
+ */
107
+ export function mostSpecificResolved(candidates, toInput) {
108
+ let best = null;
109
+ let bestRank = Number.NEGATIVE_INFINITY;
110
+ for (const candidate of candidates) {
111
+ const rank = resolvedSpecificity(toInput(candidate));
112
+ if (best === null || rank > bestRank) {
113
+ best = candidate;
114
+ bestRank = rank;
115
+ }
116
+ }
117
+ return best;
118
+ }
119
+ //# sourceMappingURL=admin-winner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin-winner.js","sourceRoot":"","sources":["../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;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAA0B;IACjE,UAAU;IACV,UAAU;IACV,oBAAoB;IACpB,QAAQ;IACR,SAAS;CACT,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAA0B;IACjE,UAAU;IACV,oBAAoB;IACpB,UAAU;IACV,QAAQ;IACR,SAAS;CACT,CAAA;AAoBD;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,QAAyC;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BAAsB,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,EAAE,SAAS,CAAC,YAAY,CAAC;QACrE,yBAAyB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IAE7C,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,YAAY,CAAC,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,iCAAiC,CAAA;AACrH,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":["../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
+ gates: "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
+ gates: "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.gates))].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":["../backend-capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH;;;;GAIG;AACH,MAAM,0BAA0B,GAAyD;IACxF;QACC,UAAU,EAAE,WAAW;QACvB,KAAK,EAAE,qBAAqB;QAC5B,SAAS,EAAE,IAAI;QACf,QAAQ,EACP,gOAAgO;KACjO;IACD;QACC,UAAU,EAAE,yBAAyB;QACrC,KAAK,EAAE,qBAAqB;QAC5B,SAAS,EAAE,IAAI;QACf,QAAQ,EACP,+GAA+G;K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AK,CAAC,GAAG,IAAI,CAAA;IAEpB,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC;QAAE,OAAM;IACjD,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAE3B,OAAO,CAAC,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAA;AAC1C,CAAC"}
@@ -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":["../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 load-bearing, 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 +1 @@
1
+ {"version":3,"file":"bare-toponym-race.js","sourceRoot":"","sources":["../bare-toponym-race.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAG9D;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAiB,EAAE,YAA0B;IACjF,IAAI,YAAY,CAAC,UAA0B,CAAC,KAAK,UAAU;QAAE,OAAO,IAAI,CAAA;IACxE,MAAM,IAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAA;IAEvC,OAAO,IAAI,EAAE,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA;AAC9C,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAA;AAE9C;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAoB;IACjD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;AAC/C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAA6B,EAAE,MAA4B;IAC1F,IAAI,CAAC,OAAO;QAAE,OAAO,MAAM,CAAA;IAE3B,IAAI,CAAC,MAAM;QAAE,OAAO,OAAO,CAAA;IAE3B,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CA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AAC,CAAC,CAAA;QAEnB,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,KAAK,QAAQ,IAAI,GAAG,CAAC,SAAS,KAAK,aAAa,CAAC,IAAI,GAAG,CAAC,UAAU,KAAK,KAAK;YACxG,CAAC,CAAC,GAAG;YACL,CAAC,CAAC,IAAI,CAAA;IACR,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAA;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.ts";
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":["../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,sBAAsB,CAAA;AAEnE;;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"}
@@ -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. Shards 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":["../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,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,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/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 load-bearing: 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":["../fold-name.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ1C"}