@mailwoman/resolver 11.0.0 → 11.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +3 -3
  2. package/lib/admin/coherence-passes.ts +14 -20
  3. package/lib/admin/containment.ts +6 -5
  4. package/lib/admin/jp-municipality.ts +3 -3
  5. package/lib/admin/winner.ts +5 -5
  6. package/lib/admin.ts +2 -5
  7. package/lib/bare-toponym-race.ts +12 -10
  8. package/lib/decorate-node.ts +50 -8
  9. package/lib/fold-name.ts +8 -8
  10. package/lib/index.ts +11 -8
  11. package/lib/plausibility.ts +2 -5
  12. package/lib/postcode/country-coherence.ts +4 -7
  13. package/lib/postcode/prefix.ts +4 -7
  14. package/lib/postcode/shape-coherence.ts +3 -6
  15. package/lib/postcode.ts +2 -5
  16. package/lib/remote-resolver.ts +2 -5
  17. package/lib/rerank.ts +7 -8
  18. package/lib/resolve/country-code.ts +22 -18
  19. package/lib/resolve/landmark.ts +19 -12
  20. package/lib/resolve/passes.ts +13 -9
  21. package/lib/resolve/region-city.ts +192 -8
  22. package/lib/resolve/whole-input.ts +49 -0
  23. package/lib/resolve.ts +41 -8
  24. package/lib/span-rescore.ts +60 -27
  25. package/lib/street/evidence.ts +2 -5
  26. package/lib/street/tier.ts +9 -12
  27. package/lib/street.ts +2 -5
  28. package/lib/toponym-prior.ts +4 -7
  29. package/out/admin/coherence-passes.d.ts +2 -7
  30. package/out/admin/coherence-passes.d.ts.map +1 -1
  31. package/out/admin/coherence-passes.js +14 -20
  32. package/out/admin/coherence-passes.js.map +1 -1
  33. package/out/admin/containment.d.ts +3 -5
  34. package/out/admin/containment.d.ts.map +1 -1
  35. package/out/admin/containment.js +5 -5
  36. package/out/admin/containment.js.map +1 -1
  37. package/out/admin/jp-municipality.d.ts +0 -3
  38. package/out/admin/jp-municipality.d.ts.map +1 -1
  39. package/out/admin/jp-municipality.js +2 -15
  40. package/out/admin/jp-municipality.js.map +1 -1
  41. package/out/admin/winner.d.ts +2 -5
  42. package/out/admin/winner.d.ts.map +1 -1
  43. package/out/admin/winner.js +2 -9
  44. package/out/admin/winner.js.map +1 -1
  45. package/out/admin.d.ts +0 -5
  46. package/out/admin.d.ts.map +1 -1
  47. package/out/admin.js +2 -5
  48. package/out/admin.js.map +1 -1
  49. package/out/bare-toponym-race.d.ts +0 -11
  50. package/out/bare-toponym-race.d.ts.map +1 -1
  51. package/out/bare-toponym-race.js +3 -12
  52. package/out/bare-toponym-race.js.map +1 -1
  53. package/out/decorate-node.d.ts +14 -6
  54. package/out/decorate-node.d.ts.map +1 -1
  55. package/out/decorate-node.js +45 -10
  56. package/out/decorate-node.js.map +1 -1
  57. package/out/fold-name.d.ts +5 -8
  58. package/out/fold-name.d.ts.map +1 -1
  59. package/out/fold-name.js +7 -8
  60. package/out/fold-name.js.map +1 -1
  61. package/out/index.d.ts +8 -8
  62. package/out/index.d.ts.map +1 -1
  63. package/out/index.js +10 -8
  64. package/out/index.js.map +1 -1
  65. package/out/plausibility.d.ts +0 -5
  66. package/out/plausibility.d.ts.map +1 -1
  67. package/out/plausibility.js +2 -5
  68. package/out/plausibility.js.map +1 -1
  69. package/out/postcode/country-coherence.d.ts +2 -7
  70. package/out/postcode/country-coherence.d.ts.map +1 -1
  71. package/out/postcode/country-coherence.js +3 -6
  72. package/out/postcode/country-coherence.js.map +1 -1
  73. package/out/postcode/prefix.d.ts +2 -7
  74. package/out/postcode/prefix.d.ts.map +1 -1
  75. package/out/postcode/prefix.js +3 -6
  76. package/out/postcode/prefix.js.map +1 -1
  77. package/out/postcode/shape-coherence.d.ts +1 -6
  78. package/out/postcode/shape-coherence.d.ts.map +1 -1
  79. package/out/postcode/shape-coherence.js +2 -5
  80. package/out/postcode/shape-coherence.js.map +1 -1
  81. package/out/postcode.d.ts +0 -5
  82. package/out/postcode.d.ts.map +1 -1
  83. package/out/postcode.js +2 -5
  84. package/out/postcode.js.map +1 -1
  85. package/out/remote-resolver.d.ts +0 -5
  86. package/out/remote-resolver.d.ts.map +1 -1
  87. package/out/remote-resolver.js +2 -5
  88. package/out/remote-resolver.js.map +1 -1
  89. package/out/rerank.d.ts +3 -7
  90. package/out/rerank.d.ts.map +1 -1
  91. package/out/rerank.js +3 -10
  92. package/out/rerank.js.map +1 -1
  93. package/out/resolve/country-code.d.ts +3 -24
  94. package/out/resolve/country-code.d.ts.map +1 -1
  95. package/out/resolve/country-code.js +21 -18
  96. package/out/resolve/country-code.js.map +1 -1
  97. package/out/resolve/landmark.d.ts +10 -11
  98. package/out/resolve/landmark.d.ts.map +1 -1
  99. package/out/resolve/landmark.js +18 -12
  100. package/out/resolve/landmark.js.map +1 -1
  101. package/out/resolve/passes.d.ts +2 -7
  102. package/out/resolve/passes.d.ts.map +1 -1
  103. package/out/resolve/passes.js +11 -8
  104. package/out/resolve/passes.js.map +1 -1
  105. package/out/resolve/region-city.d.ts +34 -7
  106. package/out/resolve/region-city.d.ts.map +1 -1
  107. package/out/resolve/region-city.js +159 -8
  108. package/out/resolve/region-city.js.map +1 -1
  109. package/out/resolve/whole-input.d.ts +14 -0
  110. package/out/resolve/whole-input.d.ts.map +1 -0
  111. package/out/resolve/whole-input.js +37 -0
  112. package/out/resolve/whole-input.js.map +1 -0
  113. package/out/resolve.d.ts +0 -8
  114. package/out/resolve.d.ts.map +1 -1
  115. package/out/resolve.js +24 -12
  116. package/out/resolve.js.map +1 -1
  117. package/out/span-rescore.d.ts +12 -16
  118. package/out/span-rescore.d.ts.map +1 -1
  119. package/out/span-rescore.js +45 -18
  120. package/out/span-rescore.js.map +1 -1
  121. package/out/street/evidence.d.ts +0 -5
  122. package/out/street/evidence.d.ts.map +1 -1
  123. package/out/street/evidence.js +2 -5
  124. package/out/street/evidence.js.map +1 -1
  125. package/out/street/tier.d.ts +3 -8
  126. package/out/street/tier.d.ts.map +1 -1
  127. package/out/street/tier.js +7 -10
  128. package/out/street/tier.js.map +1 -1
  129. package/out/street.d.ts +0 -5
  130. package/out/street.d.ts.map +1 -1
  131. package/out/street.js +2 -5
  132. package/out/street.js.map +1 -1
  133. package/out/toponym-prior.d.ts +2 -7
  134. package/out/toponym-prior.d.ts.map +1 -1
  135. package/out/toponym-prior.js +4 -7
  136. package/out/toponym-prior.js.map +1 -1
  137. package/package.json +9 -9
package/README.md CHANGED
@@ -22,7 +22,7 @@ const resolver = createWOFResolver(backend)
22
22
  const decorated = await resolver.resolveTree(tree)
23
23
  ```
24
24
 
25
- `resolveTree` returns a new tree. Nodes that resolved have `lat`/`lon`, a `placeID`, and `resolver_*` metadata. Nodes that did not are returned untouched.
25
+ `resolveTree` returns a new tree. Nodes that resolved have `lat`/`lon`, a `placeID`, and `resolver_*` metadata. Nodes that didn't are returned untouched.
26
26
 
27
27
  ## Backend-agnostic on purpose
28
28
 
@@ -34,7 +34,7 @@ Two rules run through this package, and both exist because their opposites shipp
34
34
 
35
35
  **A coordinate the gazetteer cannot supply is absent, never `0,0`.** `0,0` is the unlocated sentinel in every WOF-lineage database, and those databases contain a great deal of it — 48,216 of 142,604 Japanese postcodes, 86,377 GB, 414 US. `decorateNode` leaves `lat`/`lon` unset for such a row, so the place still resolves and identifies itself while stating that it cannot say where it is. A consumer's `lat != null` check then means what it looks like it means.
36
36
 
37
- **A missing answer is not a wrong answer.** An unresolvable span is returned as parsed. The resolver invents no centroid to fill a hole.
37
+ **A missing answer isn't a wrong answer.** An unresolvable span is returned as parsed. The resolver invents no centroid to fill a hole.
38
38
 
39
39
  ## Which resolved place answers the query
40
40
 
@@ -58,7 +58,7 @@ Either an **exact hit on a unit-grade code** (`@mailwoman/codex`'s `UNIT_GRADE_P
58
58
 
59
59
  The two shapes live in one module deliberately. They express one claim and are consumed by different callers, and when they were separate the eval harnesses each froze one arm of the conditional as a constant — every grader correct on half the data and wrong on the other half, unconditionally, until a test compared them. `lib/admin/winner.test.ts` asserts they agree on every arm, and a mutation of either side fails it.
60
60
 
61
- A code system joins those tiers by measurement, never by its shape without a measurement. Canada is the worked example. Its urban LDU measures 78 m against rooftop truth and joined the tier, while its rural codes measure 2.08 km and did not. Canada Post already marks the difference with a `0` in the second character, so the code itself identifies its tier before any lookup runs.
61
+ A code system joins those tiers by measurement, never by its shape without a measurement. Canada is the worked example. Its urban LDU measures 78 m against rooftop truth and joined the tier, while its rural codes measure 2.08 km and didn't. Canada Post already marks the difference with a `0` in the second character, so the code itself identifies its tier before any lookup runs.
62
62
 
63
63
  ## Coherence passes
64
64
 
@@ -1,15 +1,12 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  import { matchCountry, matchSubdivision } from "@mailwoman/codex/country"
8
5
  import { PLACETYPE_FILTER_GROUPS } from "@mailwoman/codex/placetype-map"
9
6
  import type { AddressNode } from "@mailwoman/core/decoder"
10
7
  import type { ResolvedPlace, ResolverBackend } from "@mailwoman/core/resolver"
11
8
 
12
- import { decorateNode, isResolvedWithCoord } from "#decorate-node"
9
+ import { decorateNode, isResolvedWithCoord, PICK_METADATA_KEYS } from "#decorate-node"
13
10
 
14
11
  const REGION_LINEAGE_PLACETYPES: ReadonlySet<string> = new Set(PLACETYPE_FILTER_GROUPS["region"] ?? ["region"])
15
12
 
@@ -23,7 +20,7 @@ function placeIDValue(node: AddressNode): string | null {
23
20
  * Un-resolves a parent-fallback pick whose stamped ancestors name a region other than
24
21
  * the resolved region above it, marking it `parent_fallback_refused`.
25
22
  *
26
- * A pick whose ancestor chain names no region is kept, because the fallback
23
+ * A pick whose ancestor chain identifies no region is kept, because the fallback
27
24
  * exists for places with incomplete hierarchies.
28
25
  */
29
26
  export function applyParentFallbackContradiction(roots: readonly AddressNode[]): void {
@@ -199,17 +196,8 @@ function revertResolverDecoration(node: AddressNode): void {
199
196
  node.source = typeof priorSource === "string" ? priorSource : null
200
197
  node.sourceID = typeof priorSourceID === "string" ? priorSourceID : null
201
198
 
202
- for (const key of [
203
- "classifier_source",
204
- "classifier_source_id",
205
- "resolver_score",
206
- "resolver_prominence",
207
- "resolver_name",
208
- "resolver_country",
209
- "resolution_quality",
210
- "postcode_city_mismatch",
211
- ]) {
212
- // oxlint-disable-next-line typescript/no-dynamic-delete -- removing one key from a plain record. the object is not on a hot path
199
+ for (const key of ["classifier_source", "classifier_source_id", ...PICK_METADATA_KEYS]) {
200
+ // oxlint-disable-next-line typescript/no-dynamic-delete -- removing one key from a plain record. the object isn't on a hot path
213
201
  delete meta[key]
214
202
  }
215
203
 
@@ -224,7 +212,7 @@ function revertResolverDecoration(node: AddressNode): void {
224
212
  * Re-picks a locality to the place with the same name inside the country specified in
225
213
  * the address, when that country is the locality's nearest admin context.
226
214
  *
227
- * It leaves the locality unchanged when it already resolved to that place or
215
+ * It leaves the locality unchanged when it already resolved inside that country or
228
216
  * when that country has no locality with the same name.
229
217
  */
230
218
  export async function applyExplicitCountryCoherence(
@@ -256,11 +244,17 @@ async function reconcileExplicitCountry(
256
244
  backend: ResolverBackend
257
245
  ): Promise<void> {
258
246
  // A span tagged `country` may hold a constituent country such as `England`.
259
- // That is a subdivision of GB rather than a sovereign state, and it still fixes the country.
247
+ // That's a subdivision of GB rather than a sovereign state, and it still fixes the country.
260
248
  const iso2 = matchCountry(countryNode.value)?.iso2 ?? matchSubdivision(countryNode.value)?.country
261
249
 
262
250
  if (!iso2) return
263
251
 
252
+ // A pick already inside the written country agrees with it, so the pass keeps it.
253
+ // The re-query asks for the locality placetype only.
254
+ // Re-picking would replace a dependent locality's contained neighborhood with
255
+ // a same-name locality elsewhere in the country.
256
+ if (isResolvedWithCoord(localityNode) && localityNode.metadata?.["resolver_country"] === iso2) return
257
+
264
258
  const scoped = await backend.findPlace({
265
259
  text: localityNode.value,
266
260
  placetype: "locality",
@@ -1,10 +1,11 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
5
  * Both decision sites call this ordering function.
7
- * The candidate backend partitions rows before the limit window. The resolver walk partitions again after fame and anchor re-ranking.
6
+ *
7
+ * The candidate backend partitions rows before the limit window.
8
+ * The resolver walk partitions again after fame and anchor re-ranking.
8
9
  */
9
10
 
10
11
  import { firstNodeWhere, type AddressNode } from "@mailwoman/core/decoder"
@@ -1,7 +1,7 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
5
  * @file A compound Japanese municipality split into the two units the gazetteer keys separately.
6
6
  *
7
7
  * The JP model tags `神戸市西区` (city plus ward) and `猿島郡五霞町` (county plus town) as one
@@ -1,8 +1,8 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
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.
5
+ * @file Which resolved admin place answers the query: the one ordering whose postcode rung isn't a constant.
6
6
  *
7
7
  * `postalcode` is the only placetype whose specificity depends on the resolved hit.
8
8
  * `PLACETYPE_SPECIFICITY` cannot express that split.
@@ -77,7 +77,7 @@ export interface ResolvedPostcodeHit {
77
77
  * ISO-3166 alpha-2 code where the resolver placed the postcode.
78
78
  *
79
79
  * The code is independent of the caller's requested scope.
80
- * It is absent when the postcode did not resolve to a country.
80
+ * It is absent when the postcode didn't resolve to a country.
81
81
  * The ladder then defaults to locality-first.
82
82
  */
83
83
  country?: string | null
package/lib/admin.ts CHANGED
@@ -1,8 +1,5 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  export * from "#admin/coherence-passes"
8
5
  export * from "#admin/containment"
@@ -1,13 +1,15 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * The bare-toponym admin race. This is the policy for a query that is one bare name ("Japan",
7
- * "Georgia"). The locality placetype filter makes country/region namesakes unreachable at any
8
- * rank, so the resolver's lookup runs these side races for the tree's lone locality-tagged span
9
- * and promotes an admin namesake under the rules each prober documents. Split from `resolve.ts`
10
- * so the walk file holds the walk and this one holds the race policy.
5
+ * The bare-toponym admin race.
6
+ *
7
+ * This is the policy for a query that's one bare name ("Japan", "Georgia").
8
+ * The locality placetype filter makes country/region namesakes unreachable at any rank,
9
+ * so the resolver's lookup runs these side races for the tree's lone locality-tagged span
10
+ * and promotes an admin namesake under the rules each prober documents.
11
+ *
12
+ * Split from `resolve.ts` so the walk file holds the walk and this one holds the race policy.
11
13
  */
12
14
 
13
15
  import type { ComponentTag } from "@mailwoman/codex/component"
@@ -72,7 +74,7 @@ export function pickLargerAdmin(country: ResolvedPlace | null, region: ResolvedP
72
74
  * Alias roles the side races refuse to answer through.
73
75
  *
74
76
  * A lone bare token that only reaches a place via an abbreviation row ("Tó" folds onto Toledo's "TO")
75
- * or a translation-gloss row did not identify that place.
77
+ * or a translation-gloss row didn't identify that place.
76
78
  * The role-NULL exonym tier stays open, so 格鲁吉亚 can win the country race through its display-name alias.
77
79
  *
78
80
  * An artifact without the role column ignores the exclusion and the races behave as before.
@@ -1,10 +1,9 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
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, in its own module so the
7
- * coherence passes do not import the walk.
5
+ * Node decoration shared by the resolver walk and its post-walk passes,
6
+ * in its own module so the coherence passes do not import the walk.
8
7
  */
9
8
 
10
9
  import type { AddressNode } from "@mailwoman/core/decoder"
@@ -13,7 +12,7 @@ import type { ResolvedPlace } from "@mailwoman/core/resolver"
13
12
  import type { CoordinateOptionalPlace } from "#postcode/prefix"
14
13
 
15
14
  /**
16
- * The widest stored extent, in degrees, that is a single point: about 10 meters, narrower than any place.
15
+ * The widest stored extent, in degrees, that's a single point: about 10 meters, narrower than any place.
17
16
  */
18
17
  const POINT_EXTENT_DEGREES = 0.0001
19
18
 
@@ -29,17 +28,60 @@ export function isResolvedWithCoord(n: AddressNode): boolean {
29
28
  )
30
29
  }
31
30
 
31
+ /**
32
+ * The metadata keys that describe the place a node resolved to, or that place's
33
+ * relation to the node's parent.
34
+ *
35
+ * Each value is true of one place only.
36
+ * A pass that replaces the place removes them, because the new place may supply none of them.
37
+ */
38
+ export const PICK_METADATA_KEYS = [
39
+ "resolver_score",
40
+ "resolver_name",
41
+ "resolver_prominence",
42
+ "resolver_country",
43
+ "resolver_referential",
44
+ "resolver_encyclopedic",
45
+ "resolver_importance",
46
+ "resolver_matched_alias",
47
+ "resolver_bbox",
48
+ "postcode_city_mismatch",
49
+ "resolution_quality",
50
+ "ancestors",
51
+ "contained_by_parent",
52
+ "admin_containment",
53
+ "parent_fallback",
54
+ "variant_alias_exemption",
55
+ ] as const
56
+
32
57
  /**
33
58
  * Stamp a node with resolver-supplied attribution, displacing any prior classifier `source`
34
59
  * / `sourceID` into `metadata.classifier_source` / `metadata.classifier_source_id`
35
60
  * and surfacing runner-up candidates on `alternatives`.
61
+ *
62
+ * A node the resolver already decorated keeps its classifier stamps as the first decoration wrote them.
63
+ * When the new place differs from the one the node holds, the {@linkcode PICK_METADATA_KEYS}
64
+ * and `alternatives` of the previous place are removed before the new place is written.
36
65
  */
37
66
  export function decorateNode(
38
67
  node: AddressNode,
39
68
  resolved: CoordinateOptionalPlace,
40
69
  alternatives: ResolvedPlace[]
41
70
  ): void {
42
- if (node.source || node.sourceID) {
71
+ if (node.source === "resolver") {
72
+ // A pass can decorate a node again with the place it already holds, and that place's stamps stay true.
73
+ if (node.placeID !== `wof:${resolved.id}`) {
74
+ const meta = { ...node.metadata }
75
+
76
+ for (const key of PICK_METADATA_KEYS) {
77
+ // oxlint-disable-next-line typescript/no-dynamic-delete -- removing the listed keys from a copied plain record
78
+ delete meta[key]
79
+ }
80
+
81
+ node.metadata = meta
82
+ delete node.alternatives
83
+ }
84
+ } else if (node.source || node.sourceID) {
43
85
  const meta = { ...node.metadata }
44
86
 
45
87
  if (node.source) {
package/lib/fold-name.ts CHANGED
@@ -1,16 +1,16 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
+ * One shared name fold for the resolver's commune reconciliation, the street
6
+ * tier's locality comparison and span-rescore's key guards.
5
7
  *
6
- * One shared name fold for the resolver's commune reconciliation, the street tier's locality
7
- * comparison and span-rescore's key guards. Its own module because those would otherwise import
8
- * each other for it.
8
+ * Its own module because those would otherwise import each other for it.
9
9
  */
10
10
 
11
11
  /**
12
- * Case/diacritic-insensitive fold for commune-name comparison: marks are deleted, never spaced, so
13
- * `Besançon` does not key as `besanc on`; a letter with no decomposition is dropped rather than folded.
12
+ * Case/diacritic-insensitive fold for commune-name comparison: marks are deleted, never spaced,
13
+ * so `Besançon` doesn't key as `besanc on`; a letter with no decomposition is dropped rather than folded.
14
14
  */
15
15
  export function foldName(s: string): string {
16
16
  return s
package/lib/index.ts CHANGED
@@ -1,13 +1,16 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
+ * `@mailwoman/resolver` is the address resolver implementation.
6
+ *
7
+ * It depends on `@mailwoman/spatial` (haversine) and `@mailwoman/codex`
8
+ * (USPS directionals) instead of reinventing them.
9
+ * The type interface stays in `@mailwoman/core/resolver`, so `core/pipeline`
10
+ * composes the resolver structurally without a package cycle.
5
11
  *
6
- * `@mailwoman/resolver` is the address resolver implementation. It depends on
7
- * `@mailwoman/spatial` (haversine) and `@mailwoman/codex` (USPS directionals) instead of
8
- * reinventing them. The type interface stays in `@mailwoman/core/resolver`, so `core/pipeline`
9
- * composes the resolver structurally without a package cycle. This barrel re-exports it, so
10
- * `@mailwoman/resolver` is a complete drop-in for `@mailwoman/core/resolver`.
12
+ * This barrel re-exports it, so `@mailwoman/resolver` is a complete drop-in
13
+ * for `@mailwoman/core/resolver`.
11
14
  */
12
15
 
13
16
  export { RemoteResolver, serializableResolveOpts } from "#remote-resolver"
@@ -1,8 +1,5 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  import type { ComponentTag } from "@mailwoman/codex/component"
8
5
  import type { AddressNode, AddressTree } from "@mailwoman/core/decoder"
@@ -1,8 +1,5 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  import { firstNodeWhere, walkNodes, type AddressNode } from "@mailwoman/core/decoder"
8
5
  import type { ResolvedPlace, ResolverBackend } from "@mailwoman/core/resolver"
@@ -13,7 +10,7 @@ import { haversine } from "@mailwoman/spatial/geometries/point/distance"
13
10
  * The default maximum distance, in kilometers, between a postcode and a locality
14
11
  * for them to count as consistent.
15
12
  *
16
- * Verdicts did not change anywhere between 15 and 50 km, so the exact value matters little.
13
+ * Verdicts didn't change anywhere between 15 and 50 km, so the exact value matters little.
17
14
  */
18
15
  export const POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM = 25
19
16
 
@@ -22,7 +19,7 @@ export const POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM = 25
22
19
  *
23
20
  * - `pair`: the postcode and the locality both resolve in the country, within the threshold distance.
24
21
  * - `locality`: the locality exists in exactly one country.
25
- * The postcode copy in that country does not contradict it.
22
+ * The postcode copy in that country doesn't contradict it.
26
23
  * - `postcode`: the postcode exists in exactly one country.
27
24
  * No gazetteer knows the locality.
28
25
  */
@@ -1,8 +1,5 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  import { EMPTY_PLACE_FIELDS } from "@mailwoman/core/resolver"
8
5
  import type { PostcodePrefixIndexLike, PostcodePrefixNode, ResolvedPlace } from "@mailwoman/core/resolver"
@@ -12,7 +9,7 @@ import type { PostcodePrefixIndexLike, PostcodePrefixNode, ResolvedPlace } from
12
9
  * postcode-prefix hit with ancestry only.
13
10
  *
14
11
  * A missing coordinate stays `undefined`.
15
- * An invented centroid would place the postcode at a point the data does not support.
12
+ * An invented centroid would place the postcode at a point the data doesn't support.
16
13
  */
17
14
  export type CoordinateOptionalPlace = Omit<ResolvedPlace, "lat" | "lon"> & { lat?: number; lon?: number }
18
15
 
@@ -82,7 +79,7 @@ export function probePostcodePrefix(
82
79
  }
83
80
 
84
81
  /**
85
- * Builds the synthetic `postalcode` place for a prefix hit, with `id: 0` because it is not a gazetteer row.
82
+ * Builds the synthetic `postalcode` place for a prefix hit, with `id: 0` because it isn't a gazetteer row.
86
83
  * It includes a coordinate only when the prefix node has one.
87
84
  */
88
85
  export function postcodePrefixResolvedPlace(
@@ -1,8 +1,5 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  import { matchCountry, matchSubdivision, matchSubdivisionsAnywhere } from "@mailwoman/codex/country"
8
5
  import { collectNodes, POSTCODE_SHAPE_EXCLUDED_KEY, walkNodes, type AddressNode } from "@mailwoman/core/decoder"
@@ -40,7 +37,7 @@ export interface PostcodeShapeVerdict {
40
37
  excluded: string[]
41
38
 
42
39
  /**
43
- * Postcode values left undecided because the tree names no country
40
+ * Postcode values left undecided because the tree identifies no country
44
41
  * or region with a stated postcode syntax.
45
42
  */
46
43
  abstained: string[]
package/lib/postcode.ts CHANGED
@@ -1,8 +1,5 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  export * from "#postcode/country-coherence"
8
5
  export * from "#postcode/prefix"
@@ -1,8 +1,5 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  import type { AddressTree } from "@mailwoman/core/decoder"
8
5
  import { stringifyJSON } from "@mailwoman/core/json"
package/lib/rerank.ts CHANGED
@@ -1,11 +1,10 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * Rerank a k-best parse list on resolution evidence with one bit — drop hypotheses whose resolution
7
- * is implausible, otherwise keep the model's own ranking — because a second signal here needs a
8
- * measured win on the parity + Paris fixtures.
5
+ * Rerank a k-best parse list on resolution evidence with one bit — drop hypotheses
6
+ * whose resolution is implausible, otherwise keep the model's own ranking —
7
+ * because a second signal here needs a measured win on the parity + Paris fixtures.
9
8
  */
10
9
 
11
10
  import type { AddressTree } from "@mailwoman/core/decoder"
@@ -118,7 +117,7 @@ export async function rerankByResolution<T>(
118
117
  try {
119
118
  resolved = await resolveTree(candidate.tree)
120
119
  } catch {
121
- // A resolver failure is not evidence against the parse, so the model's rank stands
120
+ // A resolver failure isn't evidence against the parse, so the model's rank stands
122
121
  // rather than vetoing a possibly-correct hypothesis on an outage.
123
122
  ranked.push({ ...candidate, resolved: null, implausible: false, reason: null })
124
123
 
@@ -1,23 +1,27 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
5
  * Reads a country written as a code of three or more capitals: `USA`, `RUS`, `RMI`.
7
6
  *
8
7
  * Two-letter codes stay out, because `CA`, `IN` and `LA` are also regions and cities.
9
8
  *
10
- * The codes a country claims are its ISO 3166-1 alpha-3 code and the abbreviations the codex curates:
11
- * `COUNTRY_ABBREVIATIONS` (`UAE`, `PNG`, `RMI`) and the capitalized entries of `COUNTRY_SURFACE_FORMS` (`GER`, `ROM`).
12
- * With the ISO codes as the only claimed set, `UAE` would read as Mount Aue, an aerodrome in Papua New Guinea with
13
- * one Wikipedia edition, because IATA assigns that code too. The abbreviation table records what a country's own users write, and a code
14
- * written for a country is read as that country wherever it is written: as a whole input here, and as a region in
15
- * `readRegionCodeAsCountry`.
9
+ * The codes a country claims are its ISO 3166-1 alpha-3 code and the abbreviations
10
+ * the codex curates: `COUNTRY_ABBREVIATIONS` (`UAE`, `PNG`, `RMI`) and the
11
+ * capitalized entries of `COUNTRY_SURFACE_FORMS` (`GER`, `ROM`).
12
+ * With the ISO codes as the only claimed set, `UAE` would read as Mount Aue, an aerodrome
13
+ * in Papua New Guinea with one Wikipedia edition, because IATA assigns that code too.
14
+ *
15
+ * The abbreviation table records what a country's own users write, and a code written
16
+ * for a country is read as that country wherever it is written: as a whole input here,
17
+ * and as a region in `readRegionCodeAsCountry`.
18
+ *
19
+ * A code a country claims answers the country ahead of any airport holding the same IATA code.
20
+ * Of the 249 alpha-3 codes, 191 are also an airport's code in Wikidata's P238 file:
21
+ * `AUS` (Austin–Bergstrom), `FRA` (Frankfurt), `HND` (Tokyo Haneda), `USA` (Concord Regional).
16
22
  *
17
- * A code a country claims answers the country ahead of any airport holding the same IATA code. Of the 249 alpha-3
18
- * codes, 191 are also an airport's code in Wikidata's P238 file: `AUS` (Austin–Bergstrom), `FRA` (Frankfurt), `HND`
19
- * (Tokyo Haneda), `USA` (Concord Regional). `applyLandmark` lists that airport as the country's alternative. A code
20
- * no country claims answers the airport: `SFO`, `LHR`, `DTW`.
23
+ * `applyLandmark` lists that airport as the country's alternative.
24
+ * A code no country claims answers the airport: `SFO`, `LHR`, `DTW`.
21
25
  */
22
26
 
23
27
  import { COUNTRY_ABBREVIATIONS, matchCountry, matchSubdivision } from "@mailwoman/codex/country"
@@ -37,8 +41,8 @@ const ABBREVIATIONS: ReadonlySet<string> = new Set(Object.values(COUNTRY_ABBREVI
37
41
  * `SFO`, `Aus` and `IN` are not.
38
42
  *
39
43
  * The codex holds the ISO 3166-1 alpha-3 codes and the curated abbreviations.
40
- * The registry's country records stay out of this module, because they would add
41
- * 51 KB to every browser bundle that holds the resolver.
44
+ * The registry's country records stay out of this module, because they'd add 51
45
+ * KB to every browser bundle that holds the resolver.
42
46
  */
43
47
  export function writtenCountryCode(written: string): string | null {
44
48
  const value = written.trim()
@@ -70,7 +74,7 @@ export function readRegionCodeAsCountry(tree: AddressTree): AddressTree {
70
74
  }
71
75
 
72
76
  /**
73
- * Answers an input that is only a country code with that country, ahead of any reading the parse gave it.
77
+ * Answers an input that's only a country code with that country, ahead of any reading the parse gave it.
74
78
  */
75
79
  export async function applyCountryCode(roots: AddressNode[], raw: string, backend: ResolverBackend): Promise<void> {
76
80
  const written = raw.trim()
@@ -78,7 +82,7 @@ export async function applyCountryCode(roots: AddressNode[], raw: string, backen
78
82
 
79
83
  if (!iso2) return
80
84
 
81
- // The gazetteer does not hold every code, so the country's English names follow the written form.
85
+ // The gazetteer doesn't hold every code, so the country's English names follow the written form.
82
86
  for (const text of [written, ...countryDisplayNames(iso2, ["en"])]) {
83
87
  const places = await backend.findPlace({ text, placetype: "country", country: iso2 })
84
88
  const place = places.find((candidate) => candidate.country === iso2)
@@ -1,18 +1,20 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
+ * Answers a query that's a place's name, with no street or postcode, from the landmark layer.
5
6
  *
6
- * Answers a query that is a place's name, with no street or postcode, from the landmark layer.
7
+ * The place of that name with the most Wikipedia language editions answers,
8
+ * and the others stay as alternatives.
9
+ * A prominence of log10(sitelinks) puts the lead on the scale the admin tier's `declared_ambiguity`
10
+ * margin reads, so a close call is declared by the same rule that declares one between two towns.
7
11
  *
8
- * The place of that name with the most Wikipedia language editions answers, and the others stay as alternatives. A
9
- * prominence of log10(sitelinks) puts the lead on the scale the admin tier's `declared_ambiguity` margin reads, so a
10
- * close call is declared by the same rule that declares one between two towns.
12
+ * A code written in capitals reads by one rule.
13
+ * A code a country is written as answers the country, and the airport holding the same
14
+ * IATA code is listed as an alternative: `AUS` is Australia, then Austin–Bergstrom.
11
15
  *
12
- * A code written in capitals reads by one rule. A code a country is written as answers the country, and the airport
13
- * holding the same IATA code is listed as an alternative: `AUS` is Australia, then Austin–Bergstrom. Every other code
14
- * answers the place holding it: `SFO`, `LHR` and `DTW` are airports. `writtenCountryCode` states which codes a country
15
- * claims.
16
+ * Every other code answers the place holding it: `SFO`, `LHR` and `DTW` are airports.
17
+ * `writtenCountryCode` states which codes a country claims.
16
18
  */
17
19
 
18
20
  import { walkNodes, type AddressNode } from "@mailwoman/core/decoder"
@@ -102,7 +104,7 @@ function placeOf(hit: LandmarkHit): ResolvedPlace {
102
104
  * `AUS` answers Australia, and Austin–Bergstrom International Airport is the
103
105
  * reading a caller can pick instead.
104
106
  * A word spelled like the code, such as the town of Usa under `USA`,
105
- * is not a holder of the code and stays out.
107
+ * isn't a holder of the code and stays out.
106
108
  *
107
109
  * The list sits on a resolved country node, so a country the gazetteer left unresolved keeps its parse.
108
110
  *
@@ -185,6 +187,11 @@ export async function applyLandmark(roots: AddressNode[], raw: string, landmarks
185
187
  // OpenStreetMap holds a place spelled like a street in some other town: `Wall Street` also answers in Utah.
186
188
  if (readsAsStreet) return
187
189
 
190
+ // A bare name that several OpenStreetMap places hold names none of them: `bus stop`
191
+ // is held in India and Kiribati, and `The Big Apple` in South Carolina and Australia.
192
+ // With no context to choose, the layer abstains.
193
+ if (!hasContext && candidates.length > 1) return
194
+
188
195
  // A school or a park in OpenStreetMap can share its town's name,
189
196
  // so a place holding the whole name keeps it.
190
197
  // A park reading beats a row with no measured population, as `Piedmont Park`