@mailwoman/resolver-wof-sqlite 12.0.0 → 12.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/lib/address/keys/build.ts +35 -0
- package/lib/address/keys/lookup.ts +318 -6
- package/lib/address/keys/open.ts +1 -0
- package/lib/address/keys/point-lookup.ts +61 -2
- package/lib/address/keys/schema.ts +37 -0
- package/lib/address/number-forms.ts +32 -13
- package/lib/address/point/interpolation.ts +23 -6
- package/lib/address/point/schema.ts +198 -2
- package/lib/address/point/scope-search.ts +179 -0
- package/lib/address/point.ts +365 -32
- package/lib/build/candidate.ts +36 -9
- package/lib/candidate/ancestors/sidecar.ts +73 -4
- package/lib/candidate/del1.ts +218 -0
- package/lib/candidate/lookup.ts +159 -100
- package/lib/candidate/schema.ts +14 -2
- package/lib/fst/binary-matcher.ts +9 -1
- package/lib/fst/builder.ts +7 -0
- package/lib/fst/del1-sidecar.ts +782 -0
- package/lib/fst/deserialize-web.ts +14 -2
- package/lib/fst/matcher.ts +7 -1
- package/lib/fst/types.ts +8 -0
- package/lib/fst.ts +1 -0
- package/lib/index.ts +22 -2
- package/lib/labels/street/canonical.ts +333 -0
- package/lib/labels/street/centroid/schema.ts +23 -1
- package/lib/labels/street/interpolation.ts +32 -6
- package/lib/labels/street/morphology/fst/builder.ts +13 -0
- package/lib/labels/street/morphology/fst/loader.ts +32 -2
- package/lib/labels/street/normalize.ts +153 -4
- package/lib/labels/street.ts +1 -0
- package/lib/landmark.ts +43 -2
- package/lib/lookup/types.ts +0 -6
- package/lib/poi/lookup.ts +148 -52
- package/lib/poi/schema.ts +9 -1
- package/lib/schema/overture-match.ts +2 -1
- package/lib/weights/overlay-linker.ts +6 -2
- package/out/address/keys/build.d.ts.map +1 -1
- package/out/address/keys/build.js +28 -1
- package/out/address/keys/build.js.map +1 -1
- package/out/address/keys/lookup.d.ts +42 -0
- package/out/address/keys/lookup.d.ts.map +1 -1
- package/out/address/keys/lookup.js +182 -6
- package/out/address/keys/lookup.js.map +1 -1
- package/out/address/keys/open.d.ts.map +1 -1
- package/out/address/keys/open.js +1 -0
- package/out/address/keys/open.js.map +1 -1
- package/out/address/keys/point-lookup.d.ts +6 -1
- package/out/address/keys/point-lookup.d.ts.map +1 -1
- package/out/address/keys/point-lookup.js +43 -1
- package/out/address/keys/point-lookup.js.map +1 -1
- package/out/address/keys/schema.d.ts +21 -0
- package/out/address/keys/schema.d.ts.map +1 -1
- package/out/address/keys/schema.js +18 -0
- package/out/address/keys/schema.js.map +1 -1
- package/out/address/number-forms.d.ts +10 -1
- package/out/address/number-forms.d.ts.map +1 -1
- package/out/address/number-forms.js +20 -11
- package/out/address/number-forms.js.map +1 -1
- package/out/address/point/interpolation.d.ts.map +1 -1
- package/out/address/point/interpolation.js +15 -5
- package/out/address/point/interpolation.js.map +1 -1
- package/out/address/point/schema.d.ts +45 -2
- package/out/address/point/schema.d.ts.map +1 -1
- package/out/address/point/schema.js +129 -0
- package/out/address/point/schema.js.map +1 -1
- package/out/address/point/scope-search.d.ts +77 -0
- package/out/address/point/scope-search.d.ts.map +1 -0
- package/out/address/point/scope-search.js +107 -0
- package/out/address/point/scope-search.js.map +1 -0
- package/out/address/point.d.ts +24 -1
- package/out/address/point.d.ts.map +1 -1
- package/out/address/point.js +231 -30
- package/out/address/point.js.map +1 -1
- package/out/build/candidate.d.ts +8 -0
- package/out/build/candidate.d.ts.map +1 -1
- package/out/build/candidate.js +17 -7
- package/out/build/candidate.js.map +1 -1
- package/out/candidate/ancestors/sidecar.d.ts +7 -3
- package/out/candidate/ancestors/sidecar.d.ts.map +1 -1
- package/out/candidate/ancestors/sidecar.js +56 -4
- package/out/candidate/ancestors/sidecar.js.map +1 -1
- package/out/candidate/del1.d.ts +61 -0
- package/out/candidate/del1.d.ts.map +1 -0
- package/out/candidate/del1.js +158 -0
- package/out/candidate/del1.js.map +1 -0
- package/out/candidate/lookup.d.ts +2 -14
- package/out/candidate/lookup.d.ts.map +1 -1
- package/out/candidate/lookup.js +122 -84
- package/out/candidate/lookup.js.map +1 -1
- package/out/candidate/schema.d.ts +8 -2
- package/out/candidate/schema.d.ts.map +1 -1
- package/out/candidate/schema.js +8 -2
- package/out/candidate/schema.js.map +1 -1
- package/out/fst/binary-matcher.d.ts +7 -1
- package/out/fst/binary-matcher.d.ts.map +1 -1
- package/out/fst/binary-matcher.js +7 -1
- package/out/fst/binary-matcher.js.map +1 -1
- package/out/fst/builder.d.ts +2 -0
- package/out/fst/builder.d.ts.map +1 -1
- package/out/fst/builder.js +5 -0
- package/out/fst/builder.js.map +1 -1
- package/out/fst/del1-sidecar.d.ts +158 -0
- package/out/fst/del1-sidecar.d.ts.map +1 -0
- package/out/fst/del1-sidecar.js +581 -0
- package/out/fst/del1-sidecar.js.map +1 -0
- package/out/fst/deserialize-web.d.ts +3 -1
- package/out/fst/deserialize-web.d.ts.map +1 -1
- package/out/fst/deserialize-web.js +9 -2
- package/out/fst/deserialize-web.js.map +1 -1
- package/out/fst/matcher.d.ts +6 -1
- package/out/fst/matcher.d.ts.map +1 -1
- package/out/fst/matcher.js +6 -1
- package/out/fst/matcher.js.map +1 -1
- package/out/fst/types.d.ts +7 -0
- package/out/fst/types.d.ts.map +1 -1
- package/out/fst.d.ts +1 -0
- package/out/fst.d.ts.map +1 -1
- package/out/fst.js +1 -0
- package/out/fst.js.map +1 -1
- package/out/index.d.ts +4 -3
- package/out/index.d.ts.map +1 -1
- package/out/index.js +3 -2
- package/out/index.js.map +1 -1
- package/out/labels/street/canonical.d.ts +68 -0
- package/out/labels/street/canonical.d.ts.map +1 -0
- package/out/labels/street/canonical.js +234 -0
- package/out/labels/street/canonical.js.map +1 -0
- package/out/labels/street/centroid/schema.d.ts +10 -1
- package/out/labels/street/centroid/schema.d.ts.map +1 -1
- package/out/labels/street/centroid/schema.js +12 -0
- package/out/labels/street/centroid/schema.js.map +1 -1
- package/out/labels/street/interpolation.d.ts +9 -1
- package/out/labels/street/interpolation.d.ts.map +1 -1
- package/out/labels/street/interpolation.js +8 -5
- package/out/labels/street/interpolation.js.map +1 -1
- package/out/labels/street/morphology/fst/builder.d.ts +8 -0
- package/out/labels/street/morphology/fst/builder.d.ts.map +1 -1
- package/out/labels/street/morphology/fst/builder.js +5 -0
- package/out/labels/street/morphology/fst/builder.js.map +1 -1
- package/out/labels/street/morphology/fst/loader.d.ts +12 -0
- package/out/labels/street/morphology/fst/loader.d.ts.map +1 -1
- package/out/labels/street/morphology/fst/loader.js +18 -2
- package/out/labels/street/morphology/fst/loader.js.map +1 -1
- package/out/labels/street/normalize.d.ts +8 -0
- package/out/labels/street/normalize.d.ts.map +1 -1
- package/out/labels/street/normalize.js +138 -4
- package/out/labels/street/normalize.js.map +1 -1
- package/out/labels/street.d.ts +1 -0
- package/out/labels/street.d.ts.map +1 -1
- package/out/labels/street.js +1 -0
- package/out/labels/street.js.map +1 -1
- package/out/landmark.d.ts +8 -0
- package/out/landmark.d.ts.map +1 -1
- package/out/landmark.js +25 -2
- package/out/landmark.js.map +1 -1
- package/out/lookup/types.d.ts +0 -5
- package/out/lookup/types.d.ts.map +1 -1
- package/out/poi/lookup.d.ts +9 -1
- package/out/poi/lookup.d.ts.map +1 -1
- package/out/poi/lookup.js +111 -53
- package/out/poi/lookup.js.map +1 -1
- package/out/poi/schema.d.ts +7 -2
- package/out/poi/schema.d.ts.map +1 -1
- package/out/poi/schema.js +3 -0
- package/out/poi/schema.js.map +1 -1
- package/out/schema/overture-match.d.ts +2 -1
- package/out/schema/overture-match.d.ts.map +1 -1
- package/out/schema/overture-match.js.map +1 -1
- package/out/weights/overlay-linker.d.ts +1 -1
- package/out/weights/overlay-linker.d.ts.map +1 -1
- package/out/weights/overlay-linker.js +5 -1
- package/out/weights/overlay-linker.js.map +1 -1
- package/package.json +12 -12
|
@@ -26,6 +26,7 @@ import { pathExists } from "@mailwoman/core/fs/readers/stat"
|
|
|
26
26
|
import { resourceDictionaryPath } from "@mailwoman/dictionaries/paths"
|
|
27
27
|
import type { PathBuilder, PathBuilderLike } from "path-ts"
|
|
28
28
|
|
|
29
|
+
import { BinaryFSTDel1Lookup, del1SidecarPathFor } from "#fst/del1-sidecar"
|
|
29
30
|
import type { FSTMatcher } from "#fst/matcher"
|
|
30
31
|
import { deserializeFST, readFSTProvenance } from "#fst/serialize"
|
|
31
32
|
import type { FSTProvenance } from "#fst/types"
|
|
@@ -59,6 +60,12 @@ export interface LoadStreetMorphologyFSTOpts {
|
|
|
59
60
|
* @defaultValue the libpostal dictionaries `@mailwoman/dictionaries` ships.
|
|
60
61
|
*/
|
|
61
62
|
dictionariesDir?: PathBuilderLike
|
|
63
|
+
/**
|
|
64
|
+
* When true, builds an in-memory `FD1\0` sidecar on the dictionary-build fallback path.
|
|
65
|
+
*
|
|
66
|
+
* @defaultValue `false`
|
|
67
|
+
*/
|
|
68
|
+
buildDel1Sidecar?: boolean
|
|
62
69
|
/**
|
|
63
70
|
* Unreadable-artifact diagnostics.
|
|
64
71
|
*
|
|
@@ -69,6 +76,11 @@ export interface LoadStreetMorphologyFSTOpts {
|
|
|
69
76
|
|
|
70
77
|
export interface LoadedStreetMorphologyFST {
|
|
71
78
|
matcher: FSTMatcher
|
|
79
|
+
/**
|
|
80
|
+
* Companion `FD1\0` 1-delete sidecar loaded from `<artifact>.del1.bin`
|
|
81
|
+
* or built on fallback, or `null` when absent.
|
|
82
|
+
*/
|
|
83
|
+
del1Sidecar: BinaryFSTDel1Lookup | null
|
|
72
84
|
/**
|
|
73
85
|
* Which rung produced the matcher: a sealed-artifact deserialize, or the per-process dictionary build.
|
|
74
86
|
*/
|
|
@@ -98,8 +110,22 @@ export async function loadStreetMorphologyFST(
|
|
|
98
110
|
const buf = await readLocalBuffer(artifactPath)
|
|
99
111
|
const matcher = deserializeFST(buf)
|
|
100
112
|
const provenance = readFSTProvenance(buf)
|
|
113
|
+
let del1Sidecar: BinaryFSTDel1Lookup | null = null
|
|
114
|
+
const sidecarPath = del1SidecarPathFor(artifactPath)
|
|
115
|
+
|
|
116
|
+
if (await pathExists(sidecarPath)) {
|
|
117
|
+
try {
|
|
118
|
+
const sidecarBuf = await readLocalBuffer(sidecarPath)
|
|
119
|
+
del1Sidecar = new BinaryFSTDel1Lookup(sidecarBuf)
|
|
120
|
+
matcher.del1Sidecar = del1Sidecar
|
|
121
|
+
} catch (sidecarError) {
|
|
122
|
+
warn(
|
|
123
|
+
`street-morphology del1 sidecar at ${sidecarPath} unreadable (${(sidecarError as Error).message}) — continuing without fuzzy sidecar`
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
101
127
|
|
|
102
|
-
return { matcher, source: "artifact", path: artifactPath, provenance }
|
|
128
|
+
return { matcher, del1Sidecar, source: "artifact", path: artifactPath, provenance }
|
|
103
129
|
} catch (error) {
|
|
104
130
|
warn(
|
|
105
131
|
`street-morphology artifact at ${artifactPath} unreadable (${(error as Error).message}) — falling back to the dictionary build`
|
|
@@ -109,7 +135,11 @@ export async function loadStreetMorphologyFST(
|
|
|
109
135
|
|
|
110
136
|
const built = await buildStreetMorphologyFST({
|
|
111
137
|
dictionariesDir: (opts.dictionariesDir ?? resourceDictionaryPath("libpostal")).toString(),
|
|
138
|
+
...(opts.buildDel1Sidecar ? { buildDel1Sidecar: true } : {}),
|
|
112
139
|
})
|
|
113
140
|
|
|
114
|
-
|
|
141
|
+
const del1Sidecar = built.del1Sidecar ? new BinaryFSTDel1Lookup(built.del1Sidecar.bytes) : null
|
|
142
|
+
built.matcher.del1Sidecar = del1Sidecar
|
|
143
|
+
|
|
144
|
+
return { matcher: built.matcher, del1Sidecar, source: "built", path: null, provenance: built.provenance }
|
|
115
145
|
}
|
|
@@ -5,6 +5,8 @@ import { HOUSE_NUMBER_REPETITION_INDEXES } from "@mailwoman/codex/labels/house-n
|
|
|
5
5
|
import { AbbreviationToDirectional, US_STREET_SUFFIX_LOOKUP } from "@mailwoman/codex/us"
|
|
6
6
|
import type { Tagged } from "type-fest"
|
|
7
7
|
|
|
8
|
+
import { addressPostcodeKey } from "#address/keys/postcode"
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* A place name folded by {@link normalizeLocalityForKey}, minted only by calling the fold.
|
|
10
12
|
*/
|
|
@@ -271,6 +273,14 @@ export interface StreetKeyRules {
|
|
|
271
273
|
* Builds the key a house number is stored and probed under.
|
|
272
274
|
*/
|
|
273
275
|
houseNumberKey: (number: string) => string
|
|
276
|
+
/**
|
|
277
|
+
* Builds the normalized scope key a postcode is indexed and compared under.
|
|
278
|
+
*/
|
|
279
|
+
postcodeKey: (postcode: string | null | undefined) => string | null
|
|
280
|
+
/**
|
|
281
|
+
* Street-type morphology used by `canonicalStreetKey` when classifying thoroughfare types.
|
|
282
|
+
*/
|
|
283
|
+
canonicalMorphology: "leading" | "trailing-english" | "germanic-fused" | "han"
|
|
274
284
|
/**
|
|
275
285
|
* Matches a house number written as a base number with joined sub-numbers, and captures the base.
|
|
276
286
|
* A reader probes the base after the written number misses.
|
|
@@ -347,6 +357,14 @@ function expandStreetSuffix(full: string): (words: string[]) => void {
|
|
|
347
357
|
}
|
|
348
358
|
}
|
|
349
359
|
|
|
360
|
+
/**
|
|
361
|
+
* Matches a Central European dual house number (`conscription/orientation` or `building/flat`),
|
|
362
|
+
* such as Czech `481/32` or Polish `12/4`, capturing the leading building number.
|
|
363
|
+
*
|
|
364
|
+
* Kept off `en` and `us`, where `12/345` denotes unit 12 at house number 345.
|
|
365
|
+
*/
|
|
366
|
+
const SLASH_HOUSE_NUMBER_BASE = /^(\d+[a-z]?)\/\d+[a-z]?$/
|
|
367
|
+
|
|
350
368
|
/**
|
|
351
369
|
* The rules every locale has unless its row states another.
|
|
352
370
|
*/
|
|
@@ -359,6 +377,8 @@ const SHARED_KEY_RULES: StreetKeyRules = {
|
|
|
359
377
|
arrondissementAtBaseCity: false,
|
|
360
378
|
localityFromRegionAndSubregion: false,
|
|
361
379
|
houseNumberKey: (number) => number.trim().toLowerCase(),
|
|
380
|
+
postcodeKey: (postcode) => addressPostcodeKey("", postcode),
|
|
381
|
+
canonicalMorphology: "leading",
|
|
362
382
|
houseNumberBase: null,
|
|
363
383
|
houseNumberRepetition: null,
|
|
364
384
|
}
|
|
@@ -377,13 +397,21 @@ const SHARED_KEY_RULES: StreetKeyRules = {
|
|
|
377
397
|
* - `und` has the shared rules only, for a country whose official languages select no one row.
|
|
378
398
|
*/
|
|
379
399
|
const STREET_KEY_RULES: Readonly<Record<string, StreetKeyRules>> = {
|
|
380
|
-
us: {
|
|
400
|
+
us: {
|
|
401
|
+
...SHARED_KEY_RULES,
|
|
402
|
+
streetKey: normalizeStreetForKey,
|
|
403
|
+
englishRespellings: true,
|
|
404
|
+
localityKeys: "abbreviated",
|
|
405
|
+
postcodeKey: (postcode) => addressPostcodeKey("US", postcode),
|
|
406
|
+
canonicalMorphology: "trailing-english",
|
|
407
|
+
},
|
|
381
408
|
en: {
|
|
382
409
|
...SHARED_KEY_RULES,
|
|
383
410
|
streetKey: normalizeStreetForKey,
|
|
384
411
|
// The route reads the surface and never the province, so a bilingual Canadian extract keys each street one way.
|
|
385
412
|
surfaceRoute: { pattern: FRENCH_LEAD_TYPE, locale: "fr" },
|
|
386
413
|
englishRespellings: true,
|
|
414
|
+
canonicalMorphology: "trailing-english",
|
|
387
415
|
},
|
|
388
416
|
es: { ...SHARED_KEY_RULES, streetKey: (street) => wordStreetKey(street, expandLeadingWord(ES_STREET_TYPE_ABBREV)) },
|
|
389
417
|
fr: {
|
|
@@ -393,9 +421,18 @@ const STREET_KEY_RULES: Readonly<Record<string, StreetKeyRules>> = {
|
|
|
393
421
|
// BAN writes `3 bis` across most of France and `3 b` in Paris, and a query may write either joined.
|
|
394
422
|
houseNumberRepetition: HOUSE_NUMBER_REPETITION_INDEXES,
|
|
395
423
|
},
|
|
396
|
-
de: {
|
|
424
|
+
de: {
|
|
425
|
+
...SHARED_KEY_RULES,
|
|
426
|
+
streetKey: (street) => wordStreetKey(street, expandStreetSuffix("strasse")),
|
|
427
|
+
canonicalMorphology: "germanic-fused",
|
|
428
|
+
houseNumberBase: SLASH_HOUSE_NUMBER_BASE,
|
|
429
|
+
},
|
|
397
430
|
it: { ...SHARED_KEY_RULES, streetKey: (street) => wordStreetKey(street, expandLeadingWord(IT_STREET_TYPE_ABBREV)) },
|
|
398
|
-
nl: {
|
|
431
|
+
nl: {
|
|
432
|
+
...SHARED_KEY_RULES,
|
|
433
|
+
streetKey: (street) => wordStreetKey(street, expandStreetSuffix("straat")),
|
|
434
|
+
canonicalMorphology: "germanic-fused",
|
|
435
|
+
},
|
|
399
436
|
pl: {
|
|
400
437
|
...SHARED_KEY_RULES,
|
|
401
438
|
streetKey: (street) =>
|
|
@@ -408,6 +445,7 @@ const STREET_KEY_RULES: Readonly<Record<string, StreetKeyRules>> = {
|
|
|
408
445
|
words.shift()
|
|
409
446
|
}
|
|
410
447
|
}),
|
|
448
|
+
houseNumberBase: SLASH_HOUSE_NUMBER_BASE,
|
|
411
449
|
},
|
|
412
450
|
vn: {
|
|
413
451
|
...SHARED_KEY_RULES,
|
|
@@ -425,6 +463,7 @@ const STREET_KEY_RULES: Readonly<Record<string, StreetKeyRules>> = {
|
|
|
425
463
|
streetKey: (street) => foldHan(street) as StreetKey,
|
|
426
464
|
localityKey: (locality) => foldHan(locality) as NameKey,
|
|
427
465
|
localityFromRegionAndSubregion: true,
|
|
466
|
+
canonicalMorphology: "han",
|
|
428
467
|
// A Taiwanese house number ends in 號 and may be written in full-width digits.
|
|
429
468
|
houseNumberKey: (number) =>
|
|
430
469
|
foldHan(number)
|
|
@@ -433,7 +472,10 @@ const STREET_KEY_RULES: Readonly<Record<string, StreetKeyRules>> = {
|
|
|
433
472
|
// 之 and 附 join a sub-number to a base number, and the Taiwanese register stores the base.
|
|
434
473
|
houseNumberBase: /^(\d+)(?:[之附]\d+)+$/u,
|
|
435
474
|
},
|
|
436
|
-
und:
|
|
475
|
+
und: {
|
|
476
|
+
...SHARED_KEY_RULES,
|
|
477
|
+
houseNumberBase: SLASH_HOUSE_NUMBER_BASE,
|
|
478
|
+
},
|
|
437
479
|
}
|
|
438
480
|
|
|
439
481
|
/**
|
|
@@ -674,6 +716,88 @@ export function directionalRelaxedKeys(key: StreetKey): StreetKey[] {
|
|
|
674
716
|
return forms.filter((form) => form !== key) as StreetKey[]
|
|
675
717
|
}
|
|
676
718
|
|
|
719
|
+
/**
|
|
720
|
+
* Canonical USPS topographic and natural-feature words that appear abbreviated mid-street before a
|
|
721
|
+
* thoroughfare suffix (`Little Crk Xing` → `little creek crossing`, `Oak Rdg Rd` → `oak ridge road`).
|
|
722
|
+
*
|
|
723
|
+
* This restriction to feature words keeps doubled road-suffix tails
|
|
724
|
+
* (`Saint Pauls PL St` → `saint pauls place`) unchanged.
|
|
725
|
+
*/
|
|
726
|
+
const INTERIOR_FEATURE_CANONICALS: ReadonlySet<string> = new Set([
|
|
727
|
+
"beach",
|
|
728
|
+
"bluff",
|
|
729
|
+
"bluffs",
|
|
730
|
+
"branch",
|
|
731
|
+
"brook",
|
|
732
|
+
"brooks",
|
|
733
|
+
"burg",
|
|
734
|
+
"canyon",
|
|
735
|
+
"cliff",
|
|
736
|
+
"cliffs",
|
|
737
|
+
"cove",
|
|
738
|
+
"coves",
|
|
739
|
+
"creek",
|
|
740
|
+
"crest",
|
|
741
|
+
"dale",
|
|
742
|
+
"falls",
|
|
743
|
+
"field",
|
|
744
|
+
"fields",
|
|
745
|
+
"ford",
|
|
746
|
+
"fords",
|
|
747
|
+
"forest",
|
|
748
|
+
"fork",
|
|
749
|
+
"forks",
|
|
750
|
+
"glen",
|
|
751
|
+
"glens",
|
|
752
|
+
"grove",
|
|
753
|
+
"groves",
|
|
754
|
+
"harbor",
|
|
755
|
+
"harbors",
|
|
756
|
+
"haven",
|
|
757
|
+
"hill",
|
|
758
|
+
"hills",
|
|
759
|
+
"hollow",
|
|
760
|
+
"island",
|
|
761
|
+
"islands",
|
|
762
|
+
"knoll",
|
|
763
|
+
"knolls",
|
|
764
|
+
"lake",
|
|
765
|
+
"lakes",
|
|
766
|
+
"meadow",
|
|
767
|
+
"meadows",
|
|
768
|
+
"mill",
|
|
769
|
+
"mills",
|
|
770
|
+
"mountain",
|
|
771
|
+
"mountains",
|
|
772
|
+
"orchard",
|
|
773
|
+
"pine",
|
|
774
|
+
"pines",
|
|
775
|
+
"plain",
|
|
776
|
+
"plains",
|
|
777
|
+
"point",
|
|
778
|
+
"points",
|
|
779
|
+
"prairie",
|
|
780
|
+
"ranch",
|
|
781
|
+
"rapids",
|
|
782
|
+
"ridge",
|
|
783
|
+
"ridges",
|
|
784
|
+
"river",
|
|
785
|
+
"shoal",
|
|
786
|
+
"shoals",
|
|
787
|
+
"shore",
|
|
788
|
+
"shores",
|
|
789
|
+
"spring",
|
|
790
|
+
"springs",
|
|
791
|
+
"stream",
|
|
792
|
+
"summit",
|
|
793
|
+
"valley",
|
|
794
|
+
"valleys",
|
|
795
|
+
"view",
|
|
796
|
+
"views",
|
|
797
|
+
"well",
|
|
798
|
+
"wells",
|
|
799
|
+
])
|
|
800
|
+
|
|
677
801
|
/**
|
|
678
802
|
* Lists the lookup keys to probe for a street span, most literal first, adding the
|
|
679
803
|
* English respellings for a locale whose rules probe them.
|
|
@@ -704,6 +828,31 @@ export function streetKeyVariants(street: string, locale: StreetLocale): StreetK
|
|
|
704
828
|
}
|
|
705
829
|
}
|
|
706
830
|
|
|
831
|
+
// `normalizeStreetForKey` stops after expanding the trailing suffix, leaving abbreviated
|
|
832
|
+
// topographic words before it unexpanded ("Little Crk Xing" → "little crk crossing").
|
|
833
|
+
// Probe the interior-expanded form as a query-side variant so pre-built databases stay valid.
|
|
834
|
+
if (tokens.length >= MIN_TOKENS_FOR_TAIL_MERGE) {
|
|
835
|
+
let expandedAny = false
|
|
836
|
+
|
|
837
|
+
const expanded = tokens.map((token, i) => {
|
|
838
|
+
if (i === 0 || i === tokens.length - 1) return token
|
|
839
|
+
const canonical = US_STREET_SUFFIX_LOOKUP.get(token)?.toLowerCase()
|
|
840
|
+
|
|
841
|
+
if (!canonical || canonical === token || !INTERIOR_FEATURE_CANONICALS.has(canonical)) return token
|
|
842
|
+
expandedAny = true
|
|
843
|
+
|
|
844
|
+
return canonical
|
|
845
|
+
})
|
|
846
|
+
|
|
847
|
+
if (expandedAny) {
|
|
848
|
+
const candidate = expanded.join(" ") as StreetKey
|
|
849
|
+
|
|
850
|
+
if (!variants.includes(candidate)) {
|
|
851
|
+
variants.push(candidate)
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
707
856
|
// NAD writes a numbered street with its ordinal suffix ("48th St")
|
|
708
857
|
// and NYC Open Data writes the bare number ("48 ST").
|
|
709
858
|
// The build keys each row as written, so the reader probes both forms.
|
package/lib/labels/street.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
3
|
|
|
4
|
+
export * from "#labels/street/canonical"
|
|
4
5
|
export * from "#labels/street/centroid"
|
|
5
6
|
export * from "#labels/street/centroid/schema"
|
|
6
7
|
export * from "#labels/street/morphology/fst/builder"
|
package/lib/landmark.ts
CHANGED
|
@@ -19,8 +19,17 @@ import { missingOutcomeTablesIn, OutcomeMembershipReader, outcomeAdmitPredicate
|
|
|
19
19
|
import type { LandmarkOutcomeDatabase } from "#outcome/schema"
|
|
20
20
|
import { prepareAll, type PreparedAll } from "#sqlite-utils"
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* One country that a border or single-country landmark spans.
|
|
24
|
+
*/
|
|
25
|
+
export interface LandmarkCountryTable {
|
|
26
|
+
qid: string
|
|
27
|
+
country: string
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
export interface LandmarkDatabase extends LandmarkOutcomeDatabase {
|
|
23
31
|
landmark_name: LandmarkNameTable
|
|
32
|
+
landmark_country: LandmarkCountryTable
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
/**
|
|
@@ -64,6 +73,14 @@ export async function createLandmarkTables(db: Kysely<LandmarkDatabase>): Promis
|
|
|
64
73
|
.addPrimaryKeyConstraint("landmark_name_pk", ["name_key", "qid"])
|
|
65
74
|
.modifyEnd(sql`without rowid`)
|
|
66
75
|
.execute()
|
|
76
|
+
|
|
77
|
+
await db.schema
|
|
78
|
+
.createTable("landmark_country")
|
|
79
|
+
.addColumn("qid", "text", (c) => c.notNull())
|
|
80
|
+
.addColumn("country", "text", (c) => c.notNull())
|
|
81
|
+
.addPrimaryKeyConstraint("landmark_country_pk", ["qid", "country"])
|
|
82
|
+
.modifyEnd(sql`without rowid`)
|
|
83
|
+
.execute()
|
|
67
84
|
}
|
|
68
85
|
|
|
69
86
|
/**
|
|
@@ -81,6 +98,7 @@ export class LandmarkSqliteLookup implements LandmarkLookup, Disposable {
|
|
|
81
98
|
readonly #db: DatabaseClient<LandmarkDatabase>
|
|
82
99
|
|
|
83
100
|
readonly #byName: PreparedAll<[nameKey: string], LandmarkNameTable>
|
|
101
|
+
readonly #countriesByQID: PreparedAll<[qid: string], Pick<LandmarkCountryTable, "country">> | null
|
|
84
102
|
|
|
85
103
|
readonly #layer: string
|
|
86
104
|
readonly #missingOutcomeTables: readonly string[]
|
|
@@ -94,6 +112,15 @@ export class LandmarkSqliteLookup implements LandmarkLookup, Disposable {
|
|
|
94
112
|
this.#db = new DatabaseClient<LandmarkDatabase>(path, { readOnly: true })
|
|
95
113
|
|
|
96
114
|
this.#byName = prepareAll(this.#db, LANDMARK_BY_NAME_SQL)
|
|
115
|
+
|
|
116
|
+
const hasCountryTable = Boolean(
|
|
117
|
+
this.#db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'landmark_country'").get()
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
this.#countriesByQID = hasCountryTable
|
|
121
|
+
? prepareAll(this.#db, "SELECT country FROM landmark_country WHERE qid = ? ORDER BY country")
|
|
122
|
+
: null
|
|
123
|
+
|
|
97
124
|
this.#layer = layer
|
|
98
125
|
this.#missingOutcomeTables = missingOutcomeTablesIn(this.#db)
|
|
99
126
|
this.#outcomes = OutcomeMembershipReader.open(this.#db, { recordColumn: "qid", layer })
|
|
@@ -107,19 +134,33 @@ export class LandmarkSqliteLookup implements LandmarkLookup, Disposable {
|
|
|
107
134
|
find(name: string, outcome?: OutcomeQuery): LandmarkHit[] {
|
|
108
135
|
const key = landmarkNameKey(name)
|
|
109
136
|
|
|
110
|
-
if (!outcome) return landmarkHitsFromRows(this.#byName(key), name)
|
|
137
|
+
if (!outcome) return this.#attachCountries(landmarkHitsFromRows(this.#byName(key), name))
|
|
111
138
|
|
|
112
139
|
refuseMissingOutcomeTables(`the ${this.#layer} database`, this.#missingOutcomeTables)
|
|
113
140
|
|
|
114
141
|
const rows = outcome.admit ? this.#admittedRows(key, outcome.admit) : this.#byName(key)
|
|
115
142
|
|
|
116
143
|
// A landmark row's defaults are keyed by its `kind`, as a candidate row's are by its placetype.
|
|
117
|
-
return landmarkHitsFromRows(rows, name).map((hit) => ({
|
|
144
|
+
return this.#attachCountries(landmarkHitsFromRows(rows, name)).map((hit) => ({
|
|
118
145
|
...hit,
|
|
119
146
|
outcomes: this.#outcomes!.read(hit.qid, hit.kind, outcome),
|
|
120
147
|
}))
|
|
121
148
|
}
|
|
122
149
|
|
|
150
|
+
#attachCountries(hits: LandmarkHit[]): LandmarkHit[] {
|
|
151
|
+
if (!this.#countriesByQID || !hits.length) return hits
|
|
152
|
+
|
|
153
|
+
return hits.map((hit) => {
|
|
154
|
+
const stored = this.#countriesByQID!(hit.qid).map((row) => row.country)
|
|
155
|
+
|
|
156
|
+
if (!stored.length) return hit
|
|
157
|
+
|
|
158
|
+
const ordered = hit.country ? [hit.country, ...stored.filter((code) => code !== hit.country)] : stored
|
|
159
|
+
|
|
160
|
+
return { ...hit, countries: ordered }
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
|
|
123
164
|
missingOutcomeTables(): readonly string[] {
|
|
124
165
|
return this.#missingOutcomeTables
|
|
125
166
|
}
|
package/lib/lookup/types.ts
CHANGED
|
@@ -200,12 +200,6 @@ export interface FindPlaceQuery {
|
|
|
200
200
|
*/
|
|
201
201
|
postcode?: string
|
|
202
202
|
|
|
203
|
-
/**
|
|
204
|
-
* Whether a locality query with `postcode` moves candidates near the postcode's centroid
|
|
205
|
-
* to the front, sorted by distance, with the rest keeping their order.
|
|
206
|
-
*/
|
|
207
|
-
postcodeContainmentCoherence?: boolean
|
|
208
|
-
|
|
209
203
|
/**
|
|
210
204
|
* The parsed region qualifier for a locality lookup.
|
|
211
205
|
*
|