@mailwoman/resolver 11.0.0 → 11.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.
- package/README.md +4 -4
- package/lib/admin/coherence-passes.ts +14 -20
- package/lib/admin/containment.ts +6 -5
- package/lib/admin/county-designator.ts +91 -0
- package/lib/admin/jp-municipality.ts +3 -3
- package/lib/admin/winner.ts +5 -5
- package/lib/admin.ts +2 -5
- package/lib/bare-toponym-race.ts +12 -10
- package/lib/decorate-node.ts +51 -8
- package/lib/fold-name.ts +8 -8
- package/lib/index.ts +11 -8
- package/lib/plausibility.ts +2 -5
- package/lib/postcode/country-coherence.ts +4 -7
- package/lib/postcode/prefix.ts +4 -7
- package/lib/postcode/shape-coherence.ts +5 -8
- package/lib/postcode.ts +2 -5
- package/lib/remote-resolver.ts +2 -5
- package/lib/rerank.ts +7 -8
- package/lib/resolve/country-code.ts +22 -18
- package/lib/resolve/landmark.ts +19 -12
- package/lib/resolve/passes.ts +19 -9
- package/lib/resolve/region-city.ts +192 -8
- package/lib/resolve/whole-input.ts +49 -0
- package/lib/resolve.ts +197 -48
- package/lib/span-rescore.ts +61 -28
- package/lib/street/evidence.ts +2 -5
- package/lib/street/tier.ts +9 -12
- package/lib/street.ts +2 -5
- package/lib/toponym-prior.ts +4 -7
- package/out/admin/coherence-passes.d.ts +2 -7
- package/out/admin/coherence-passes.d.ts.map +1 -1
- package/out/admin/coherence-passes.js +14 -20
- package/out/admin/coherence-passes.js.map +1 -1
- package/out/admin/containment.d.ts +3 -5
- package/out/admin/containment.d.ts.map +1 -1
- package/out/admin/containment.js +5 -5
- package/out/admin/containment.js.map +1 -1
- package/out/admin/county-designator.d.ts +33 -0
- package/out/admin/county-designator.d.ts.map +1 -0
- package/out/admin/county-designator.js +65 -0
- package/out/admin/county-designator.js.map +1 -0
- package/out/admin/jp-municipality.d.ts +0 -3
- package/out/admin/jp-municipality.d.ts.map +1 -1
- package/out/admin/jp-municipality.js +2 -15
- package/out/admin/jp-municipality.js.map +1 -1
- package/out/admin/winner.d.ts +2 -5
- package/out/admin/winner.d.ts.map +1 -1
- package/out/admin/winner.js +2 -9
- package/out/admin/winner.js.map +1 -1
- package/out/admin.d.ts +0 -5
- package/out/admin.d.ts.map +1 -1
- package/out/admin.js +2 -5
- package/out/admin.js.map +1 -1
- package/out/bare-toponym-race.d.ts +0 -11
- package/out/bare-toponym-race.d.ts.map +1 -1
- package/out/bare-toponym-race.js +3 -12
- package/out/bare-toponym-race.js.map +1 -1
- package/out/decorate-node.d.ts +14 -6
- package/out/decorate-node.d.ts.map +1 -1
- package/out/decorate-node.js +46 -10
- package/out/decorate-node.js.map +1 -1
- package/out/fold-name.d.ts +5 -8
- package/out/fold-name.d.ts.map +1 -1
- package/out/fold-name.js +7 -8
- package/out/fold-name.js.map +1 -1
- package/out/index.d.ts +8 -8
- package/out/index.d.ts.map +1 -1
- package/out/index.js +10 -8
- package/out/index.js.map +1 -1
- package/out/plausibility.d.ts +0 -5
- package/out/plausibility.d.ts.map +1 -1
- package/out/plausibility.js +2 -5
- package/out/plausibility.js.map +1 -1
- package/out/postcode/country-coherence.d.ts +2 -7
- package/out/postcode/country-coherence.d.ts.map +1 -1
- package/out/postcode/country-coherence.js +3 -6
- package/out/postcode/country-coherence.js.map +1 -1
- package/out/postcode/prefix.d.ts +2 -7
- package/out/postcode/prefix.d.ts.map +1 -1
- package/out/postcode/prefix.js +3 -6
- package/out/postcode/prefix.js.map +1 -1
- package/out/postcode/shape-coherence.d.ts +1 -6
- package/out/postcode/shape-coherence.d.ts.map +1 -1
- package/out/postcode/shape-coherence.js +4 -7
- package/out/postcode/shape-coherence.js.map +1 -1
- package/out/postcode.d.ts +0 -5
- package/out/postcode.d.ts.map +1 -1
- package/out/postcode.js +2 -5
- package/out/postcode.js.map +1 -1
- package/out/remote-resolver.d.ts +0 -5
- package/out/remote-resolver.d.ts.map +1 -1
- package/out/remote-resolver.js +2 -5
- package/out/remote-resolver.js.map +1 -1
- package/out/rerank.d.ts +3 -7
- package/out/rerank.d.ts.map +1 -1
- package/out/rerank.js +3 -10
- package/out/rerank.js.map +1 -1
- package/out/resolve/country-code.d.ts +3 -24
- package/out/resolve/country-code.d.ts.map +1 -1
- package/out/resolve/country-code.js +21 -18
- package/out/resolve/country-code.js.map +1 -1
- package/out/resolve/landmark.d.ts +10 -11
- package/out/resolve/landmark.d.ts.map +1 -1
- package/out/resolve/landmark.js +18 -12
- package/out/resolve/landmark.js.map +1 -1
- package/out/resolve/passes.d.ts +7 -7
- package/out/resolve/passes.d.ts.map +1 -1
- package/out/resolve/passes.js +11 -8
- package/out/resolve/passes.js.map +1 -1
- package/out/resolve/region-city.d.ts +34 -7
- package/out/resolve/region-city.d.ts.map +1 -1
- package/out/resolve/region-city.js +159 -8
- package/out/resolve/region-city.js.map +1 -1
- package/out/resolve/whole-input.d.ts +14 -0
- package/out/resolve/whole-input.d.ts.map +1 -0
- package/out/resolve/whole-input.js +37 -0
- package/out/resolve/whole-input.js.map +1 -0
- package/out/resolve.d.ts +0 -8
- package/out/resolve.d.ts.map +1 -1
- package/out/resolve.js +124 -46
- package/out/resolve.js.map +1 -1
- package/out/span-rescore.d.ts +12 -16
- package/out/span-rescore.d.ts.map +1 -1
- package/out/span-rescore.js +46 -19
- package/out/span-rescore.js.map +1 -1
- package/out/street/evidence.d.ts +0 -5
- package/out/street/evidence.d.ts.map +1 -1
- package/out/street/evidence.js +2 -5
- package/out/street/evidence.js.map +1 -1
- package/out/street/tier.d.ts +3 -8
- package/out/street/tier.d.ts.map +1 -1
- package/out/street/tier.js +7 -10
- package/out/street/tier.js.map +1 -1
- package/out/street.d.ts +0 -5
- package/out/street.d.ts.map +1 -1
- package/out/street.js +2 -5
- package/out/street.js.map +1 -1
- package/out/toponym-prior.d.ts +2 -7
- package/out/toponym-prior.d.ts.map +1 -1
- package/out/toponym-prior.js +4 -7
- package/out/toponym-prior.js.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ This is the half of [mailwoman](https://www.npmjs.com/package/mailwoman) that tu
|
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
|
-
```
|
|
9
|
+
```sh npm2yarn
|
|
10
10
|
npm install @mailwoman/resolver
|
|
11
11
|
```
|
|
12
12
|
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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",
|
package/lib/admin/containment.ts
CHANGED
|
@@ -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
|
-
*
|
|
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"
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @file A `locality` span written as a county with its designator, resolved as the WOF `county` of its region.
|
|
6
|
+
*
|
|
7
|
+
* The model labels `Harris County` in `Harris County, TX` as `locality`, and no locality of that name is in
|
|
8
|
+
* Texas, so the lookup returns no candidate or a namesake elsewhere and the region answers. The codex maps
|
|
9
|
+
* `subregion` to the WOF `county` placetype, and the county's row stores the same name.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { countyDesignatorsFor, countyNameWithoutDesignator } from "@mailwoman/codex/county-designators"
|
|
13
|
+
import type { ResolvedPlace, ResolverBackend } from "@mailwoman/core/resolver"
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The metadata key the walk stamps on a node this fallback resolved.
|
|
17
|
+
* The walk retags such a node `subregion`.
|
|
18
|
+
*/
|
|
19
|
+
export const COUNTY_DESIGNATOR_FALLBACK = "county_designator_fallback"
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Where the county is looked for: its country, and the region either as a resolved place id
|
|
23
|
+
* or as the written region qualifier the walk read from the tree.
|
|
24
|
+
*/
|
|
25
|
+
export interface CountyDesignatorScope {
|
|
26
|
+
country: string
|
|
27
|
+
regionID: number | string | null
|
|
28
|
+
regionQualifier: string | null
|
|
29
|
+
limit: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The county of the designated value's name inside its region, with the other counties of that name there.
|
|
34
|
+
*
|
|
35
|
+
* It is `null` when the value has no designator for the country, when the country's
|
|
36
|
+
* counties take a tag other than `subregion` (IE's are WOF regions), when the region
|
|
37
|
+
* is unknown, or when no county of that name is inside it.
|
|
38
|
+
*
|
|
39
|
+
* The whole value is probed first, because WOF keys most US counties as `<name> county` too.
|
|
40
|
+
* The name without its designator is probed second.
|
|
41
|
+
*
|
|
42
|
+
* A hit the backend admitted outside the region (`regionScopeMiss`) is refused.
|
|
43
|
+
*/
|
|
44
|
+
export async function countyFromDesignatedLocality(
|
|
45
|
+
backend: ResolverBackend,
|
|
46
|
+
value: string,
|
|
47
|
+
scope: CountyDesignatorScope
|
|
48
|
+
): Promise<{ top: ResolvedPlace; alternatives: ResolvedPlace[] } | null> {
|
|
49
|
+
// The walk retags a hit `subregion`, the tag of a WOF `county`.
|
|
50
|
+
if (countyDesignatorsFor(scope.country)?.tag !== "subregion") return null
|
|
51
|
+
|
|
52
|
+
const bare = countyNameWithoutDesignator(value, scope.country)
|
|
53
|
+
|
|
54
|
+
if (!bare) return null
|
|
55
|
+
|
|
56
|
+
const regionIDs = await regionIDsFor(backend, scope)
|
|
57
|
+
|
|
58
|
+
for (const parentID of regionIDs) {
|
|
59
|
+
for (const text of [value, bare]) {
|
|
60
|
+
const hits = await backend.findPlace({
|
|
61
|
+
text,
|
|
62
|
+
placetype: "county",
|
|
63
|
+
country: scope.country,
|
|
64
|
+
parentID,
|
|
65
|
+
limit: scope.limit,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const inside = hits.filter((hit) => hit.regionScopeMiss !== true)
|
|
69
|
+
|
|
70
|
+
if (inside.length) return { top: inside[0]!, alternatives: inside.slice(1) }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The region ids to scope the county probe by: the resolved parent's, or else the
|
|
79
|
+
* exact-match regions the written qualifier names in the country.
|
|
80
|
+
*/
|
|
81
|
+
async function regionIDsFor(backend: ResolverBackend, scope: CountyDesignatorScope): Promise<Array<number | string>> {
|
|
82
|
+
if (scope.regionID != null) return [scope.regionID]
|
|
83
|
+
|
|
84
|
+
const qualifier = scope.regionQualifier?.trim()
|
|
85
|
+
|
|
86
|
+
if (!qualifier) return []
|
|
87
|
+
|
|
88
|
+
const regions = await backend.findPlace({ text: qualifier, placetype: "region", country: scope.country, limit: 3 })
|
|
89
|
+
|
|
90
|
+
return regions.filter((region) => region.exactMatch === true && region.regionScopeMiss !== true).map((r) => r.id)
|
|
91
|
+
}
|
|
@@ -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
|
package/lib/admin/winner.ts
CHANGED
|
@@ -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
|
-
* @
|
|
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
|
|
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
|
-
|
|
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"
|
package/lib/bare-toponym-race.ts
CHANGED
|
@@ -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
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
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.
|
package/lib/decorate-node.ts
CHANGED
|
@@ -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
|
-
*
|
|
3
|
-
*
|
|
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
|
|
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,61 @@ 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
|
+
"county_designator_fallback",
|
|
56
|
+
] as const
|
|
57
|
+
|
|
32
58
|
/**
|
|
33
59
|
* Stamp a node with resolver-supplied attribution, displacing any prior classifier `source`
|
|
34
60
|
* / `sourceID` into `metadata.classifier_source` / `metadata.classifier_source_id`
|
|
35
61
|
* and surfacing runner-up candidates on `alternatives`.
|
|
62
|
+
*
|
|
63
|
+
* A node the resolver already decorated keeps its classifier stamps as the first decoration wrote them.
|
|
64
|
+
* When the new place differs from the one the node holds, the {@linkcode PICK_METADATA_KEYS}
|
|
65
|
+
* and `alternatives` of the previous place are removed before the new place is written.
|
|
36
66
|
*/
|
|
37
67
|
export function decorateNode(
|
|
38
68
|
node: AddressNode,
|
|
39
69
|
resolved: CoordinateOptionalPlace,
|
|
40
70
|
alternatives: ResolvedPlace[]
|
|
41
71
|
): void {
|
|
42
|
-
if (node.source
|
|
72
|
+
if (node.source === "resolver") {
|
|
73
|
+
// A pass can decorate a node again with the place it already holds, and that place's stamps stay true.
|
|
74
|
+
if (node.placeID !== `wof:${resolved.id}`) {
|
|
75
|
+
const meta = { ...node.metadata }
|
|
76
|
+
|
|
77
|
+
for (const key of PICK_METADATA_KEYS) {
|
|
78
|
+
// oxlint-disable-next-line typescript/no-dynamic-delete -- removing the listed keys from a copied plain record
|
|
79
|
+
delete meta[key]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
node.metadata = meta
|
|
83
|
+
delete node.alternatives
|
|
84
|
+
}
|
|
85
|
+
} else if (node.source || node.sourceID) {
|
|
43
86
|
const meta = { ...node.metadata }
|
|
44
87
|
|
|
45
88
|
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
|
-
*
|
|
3
|
-
*
|
|
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
|
-
*
|
|
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,
|
|
13
|
-
* `Besançon`
|
|
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
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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
|
|
7
|
-
*
|
|
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"
|
package/lib/plausibility.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
*/
|
package/lib/postcode/prefix.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
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
|
|
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,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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"
|
|
9
|
-
import { acceptPostcode,
|
|
6
|
+
import { acceptPostcode, statesPostcodeSyntax } from "@mailwoman/postcode/country-formats"
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* Whether libaddressinput states a postcode syntax for `country`, so a span can be checked against it.
|
|
13
10
|
*/
|
|
14
11
|
function statesSyntax(country: string): boolean {
|
|
15
|
-
return
|
|
12
|
+
return statesPostcodeSyntax(country)
|
|
16
13
|
}
|
|
17
14
|
|
|
18
15
|
/**
|
|
@@ -40,7 +37,7 @@ export interface PostcodeShapeVerdict {
|
|
|
40
37
|
excluded: string[]
|
|
41
38
|
|
|
42
39
|
/**
|
|
43
|
-
* Postcode values left undecided because the tree
|
|
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
|
-
|
|
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"
|
package/lib/remote-resolver.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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
|
|
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
|
|