@mailwoman/core 10.2.2 → 10.4.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/data/PROVENANCE.md +14 -14
- package/data/libpostal/README.md +15 -15
- package/data/libpostal/dictionaries/README.md +3 -3
- package/lib/api/APIClient.ts +3 -3
- package/lib/api/clock.ts +1 -1
- package/lib/api/disk-storage.ts +4 -4
- package/lib/api/ogc.ts +9 -9
- package/lib/api/pacer.ts +1 -1
- package/lib/api/responses.ts +6 -6
- package/lib/api/retry.ts +2 -2
- package/lib/api/test/clocks.ts +2 -2
- package/lib/api/test/transport.ts +1 -1
- package/lib/coarse-placer/coarse-placer.ts +1 -1
- package/lib/decoder/build-tree.ts +1 -1
- package/lib/decoder/parse-diff.ts +3 -3
- package/lib/decoder/serialize/xml.ts +1 -1
- package/lib/fs/delimited.ts +3 -3
- package/lib/fs/formatters.ts +1 -1
- package/lib/fs/readers.ts +3 -2
- package/lib/fs/zip.ts +1 -1
- package/lib/geocode/result.ts +8 -4
- package/lib/html/document.ts +1 -1
- package/lib/html/elements.ts +3 -3
- package/lib/json.ts +1 -1
- package/lib/layers/coverage.ts +3 -3
- package/lib/layers/manifest.ts +2 -2
- package/lib/layers/publication.ts +1 -1
- package/lib/layers/schema.ts +1 -1
- package/lib/license/record.ts +3 -4
- package/lib/module/compiled-freshness.ts +1 -1
- package/lib/numeric.ts +2 -2
- package/lib/pipeline/runtime-pipeline.ts +47 -9
- package/lib/pipeline/span-proposer.ts +2 -2
- package/lib/pipeline/types.ts +153 -6
- package/lib/pipeline.ts +6 -0
- package/lib/postcode-prefix-files.ts +87 -0
- package/lib/promises.ts +12 -0
- package/lib/release-config.ts +7 -0
- package/lib/resolver/coverage-facts.ts +3 -3
- package/lib/resolver/lookup-types.ts +7 -6
- package/lib/resolver/referential.ts +1 -1
- package/lib/resolver/types.ts +6 -0
- package/lib/resources/libpostal.ts +51 -3
- package/lib/resources/whosonfirst/placetypes/graph.ts +2 -2
- package/lib/resources/whosonfirst/placetypes/specificity.ts +2 -2
- package/lib/scripting/utils.ts +1 -1
- package/lib/tokenization/normalizer.ts +1 -1
- package/lib/trust-policies.ts +1 -1
- package/lib/utils/chunk-process.ts +1 -1
- package/lib/utils/system.ts +1 -1
- package/out/api/APIClient.d.ts +2 -2
- package/out/api/APIClient.js +1 -1
- package/out/api/APIClient.js.map +1 -1
- package/out/api/clock.d.ts +1 -1
- package/out/api/clock.js +1 -1
- package/out/api/disk-storage.js +4 -4
- package/out/api/disk-storage.js.map +1 -1
- package/out/api/ogc.d.ts +8 -8
- package/out/api/ogc.js +8 -8
- package/out/api/ogc.js.map +1 -1
- package/out/api/pacer.d.ts +1 -1
- package/out/api/pacer.js +1 -1
- package/out/api/responses.d.ts +4 -4
- package/out/api/responses.js +6 -6
- package/out/api/responses.js.map +1 -1
- package/out/api/retry.d.ts +2 -2
- package/out/api/retry.js +1 -1
- package/out/api/test/clocks.js +2 -2
- package/out/api/test/transport.d.ts +1 -1
- package/out/coarse-placer/coarse-placer.d.ts +1 -1
- package/out/coarse-placer/coarse-placer.js +1 -1
- package/out/decoder/build-tree.js +1 -1
- package/out/decoder/build-tree.js.map +1 -1
- package/out/decoder/parse-diff.d.ts +3 -3
- package/out/decoder/parse-diff.js +2 -2
- package/out/decoder/serialize/xml.d.ts +1 -1
- package/out/decoder/serialize/xml.js +1 -1
- package/out/fs/delimited.d.ts +3 -3
- package/out/fs/delimited.js +3 -3
- package/out/fs/formatters.d.ts +1 -1
- package/out/fs/formatters.js +1 -1
- package/out/fs/readers.d.ts +3 -2
- package/out/fs/readers.d.ts.map +1 -1
- package/out/fs/readers.js +3 -2
- package/out/fs/readers.js.map +1 -1
- package/out/fs/zip.d.ts +1 -1
- package/out/fs/zip.js +1 -1
- package/out/geocode/result.d.ts +17 -5
- package/out/geocode/result.d.ts.map +1 -1
- package/out/geocode/result.js +8 -4
- package/out/geocode/result.js.map +1 -1
- package/out/html/document.d.ts +1 -1
- package/out/html/document.js +1 -1
- package/out/html/elements.d.ts +2 -2
- package/out/html/elements.js +3 -3
- package/out/json.d.ts +1 -1
- package/out/json.js +1 -1
- package/out/layers/coverage.d.ts +3 -3
- package/out/layers/coverage.js +2 -2
- package/out/layers/manifest.d.ts +2 -2
- package/out/layers/publication.d.ts +1 -1
- package/out/layers/publication.js +1 -1
- package/out/layers/schema.d.ts +1 -1
- package/out/license/record.d.ts.map +1 -1
- package/out/license/record.js +3 -4
- package/out/license/record.js.map +1 -1
- package/out/module/compiled-freshness.d.ts +1 -1
- package/out/module/compiled-freshness.js +1 -1
- package/out/numeric.js +2 -2
- package/out/pipeline/runtime-pipeline.d.ts +15 -0
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.js +25 -5
- package/out/pipeline/runtime-pipeline.js.map +1 -1
- package/out/pipeline/span-proposer.d.ts +1 -1
- package/out/pipeline/span-proposer.js +1 -1
- package/out/pipeline/types.d.ts +150 -6
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js +1 -1
- package/out/pipeline/types.js.map +1 -1
- package/out/pipeline.d.ts +2 -2
- package/out/pipeline.d.ts.map +1 -1
- package/out/pipeline.js +1 -1
- package/out/pipeline.js.map +1 -1
- package/out/postcode-prefix-files.d.ts +45 -0
- package/out/postcode-prefix-files.d.ts.map +1 -0
- package/out/postcode-prefix-files.js +64 -0
- package/out/postcode-prefix-files.js.map +1 -0
- package/out/promises.d.ts +7 -0
- package/out/promises.d.ts.map +1 -1
- package/out/promises.js +10 -0
- package/out/promises.js.map +1 -1
- package/out/release-config.d.ts +7 -0
- package/out/release-config.d.ts.map +1 -1
- package/out/release-config.js.map +1 -1
- package/out/resolver/coverage-facts.d.ts +3 -3
- package/out/resolver/lookup-types.d.ts +7 -6
- package/out/resolver/lookup-types.d.ts.map +1 -1
- package/out/resolver/referential.d.ts +1 -1
- package/out/resolver/referential.js +1 -1
- package/out/resolver/types.d.ts +11 -1
- package/out/resolver/types.d.ts.map +1 -1
- package/out/resolver/types.js.map +1 -1
- package/out/resources/libpostal.d.ts +22 -3
- package/out/resources/libpostal.d.ts.map +1 -1
- package/out/resources/libpostal.js +44 -4
- package/out/resources/libpostal.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/graph.d.ts +2 -2
- package/out/resources/whosonfirst/placetypes/graph.js +1 -1
- package/out/resources/whosonfirst/placetypes/specificity.d.ts +2 -2
- package/out/resources/whosonfirst/placetypes/specificity.js +2 -2
- package/out/scripting/utils.d.ts +1 -1
- package/out/scripting/utils.js +1 -1
- package/out/tokenization/normalizer.js +1 -1
- package/out/tools/coarse-placer/outlier-rows.js +1 -1
- package/out/trust-policies.d.ts +1 -1
- package/out/trust-policies.js +1 -1
- package/out/utils/chunk-process.d.ts +1 -1
- package/out/utils/chunk-process.js +1 -1
- package/out/utils/system.d.ts +1 -1
- package/out/utils/system.js +1 -1
- package/package.json +28 -8
- package/tools/coarse-placer/outlier-rows.ts +1 -1
package/lib/layers/manifest.ts
CHANGED
|
@@ -51,7 +51,7 @@ export interface LayerManifest {
|
|
|
51
51
|
spineKeys: SpineKeys
|
|
52
52
|
createdAt: string
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
54
|
+
* The number of records each input publisher supplied to this build, keyed by the publisher's own name.
|
|
55
55
|
*
|
|
56
56
|
* The count is of the input rather than the rows the artifact kept.
|
|
57
57
|
* It is recorded here because it cannot be recovered afterwards.
|
|
@@ -71,7 +71,7 @@ export interface CoverageCell {
|
|
|
71
71
|
h3Cell: number
|
|
72
72
|
completeness: number
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
74
|
+
* The evidence basis of `completeness`.
|
|
75
75
|
*
|
|
76
76
|
* @defaultValue `SourcePresent`
|
|
77
77
|
*/
|
|
@@ -36,7 +36,7 @@ import { carriesShareAlike, LicenseResolution, readLicenseRecord } from "#licens
|
|
|
36
36
|
* `private` makes no claim about the license.
|
|
37
37
|
*
|
|
38
38
|
* @param subject The tier and license expression about to be stamped.
|
|
39
|
-
* @param context
|
|
39
|
+
* @param context The build the error message identifies.
|
|
40
40
|
* @param detail Appended to the message where the caller knows why the license reads as it does.
|
|
41
41
|
* @throws When the tier and the license disagree.
|
|
42
42
|
*/
|
package/lib/layers/schema.ts
CHANGED
package/lib/license/record.ts
CHANGED
|
@@ -129,7 +129,7 @@ const EXPRESSION_ALIASES: ReadonlyMap<string, string> = new Map([
|
|
|
129
129
|
])
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
|
-
* License identifiers
|
|
132
|
+
* License identifiers this reader recognizes inside prose, with the spelling each one appears under.
|
|
133
133
|
*
|
|
134
134
|
* Ordered longest-first so `CC-BY-SA` is found before `CC-BY`.
|
|
135
135
|
*/
|
|
@@ -263,9 +263,8 @@ const LICENSE_FAMILY_WORDS =
|
|
|
263
263
|
* The caller keeps the verbatim entry beside the result.
|
|
264
264
|
*/
|
|
265
265
|
export function licenseNamedIn(entry: string): string | null {
|
|
266
|
-
// An entry
|
|
267
|
-
//
|
|
268
|
-
// parenthetical is read rather than the first.
|
|
266
|
+
// An entry can open with a parenthetical belonging to the dataset's own name, such as "OpenAddresses
|
|
267
|
+
// PL — GUGiK / PRG (public, BDOT-derived)", so every parenthetical is read rather than the first.
|
|
269
268
|
for (const match of entry.matchAll(/\(([^()]{1,120})\)/gu)) {
|
|
270
269
|
const inner = match[1]!.trim()
|
|
271
270
|
|
|
@@ -115,7 +115,7 @@ export interface CompiledFreshness {
|
|
|
115
115
|
* Compares the newest source file against the newest compiled `.js` file across the given workspaces.
|
|
116
116
|
*
|
|
117
117
|
* `workspaces` are repo-relative directories.
|
|
118
|
-
* Each caller passes the workspaces it
|
|
118
|
+
* Each caller passes the workspaces it loads.
|
|
119
119
|
*
|
|
120
120
|
* A set that omits a loaded workspace can report `fresh` while that workspace is stale.
|
|
121
121
|
*/
|
package/lib/numeric.ts
CHANGED
|
@@ -22,8 +22,8 @@ export function clamp(value: number, min: number, max: number): number {
|
|
|
22
22
|
*
|
|
23
23
|
* These exist because the gazetteer pipeline was ported from Python and its outputs have to match
|
|
24
24
|
* the originals bit for bit. A postcode centroid that rounds differently is a different centroid.
|
|
25
|
-
* The extract containing it then differs from the reference. Divergence here never throws. It surfaces as
|
|
26
|
-
* extract that
|
|
25
|
+
* The extract containing it then differs from the reference. Divergence here never throws. It surfaces as an
|
|
26
|
+
* extract that disagrees with the reference and raises no error.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
import type {
|
|
24
24
|
AddressClassifier,
|
|
25
25
|
CaseNormalization,
|
|
26
|
+
AnchorRegionLookupLike,
|
|
26
27
|
FSTMatcherLike,
|
|
27
28
|
InputMode,
|
|
28
29
|
LocaleHint,
|
|
@@ -34,6 +35,7 @@ import type {
|
|
|
34
35
|
QueryKindResult,
|
|
35
36
|
QueryShapeLite,
|
|
36
37
|
RuntimePipelineStages,
|
|
38
|
+
VenueHeadStage,
|
|
37
39
|
} from "#pipeline/types"
|
|
38
40
|
import type { ResolveOpts } from "#resolver/types"
|
|
39
41
|
|
|
@@ -43,7 +45,7 @@ import type { ResolveOpts } from "#resolver/types"
|
|
|
43
45
|
const SHORT_CIRCUIT_MIN_CONFIDENCE = 0.95
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
* A locality-only input longer than this
|
|
48
|
+
* A locality-only input longer than this number of characters takes the full pipeline.
|
|
47
49
|
*/
|
|
48
50
|
const SHORT_CIRCUIT_MAX_LOCALITY_LENGTH = 30
|
|
49
51
|
|
|
@@ -399,6 +401,9 @@ export async function runPipeline(
|
|
|
399
401
|
caseNormalization: opts?.caseNormalization ?? DEFAULT_CASE_NORMALIZATION,
|
|
400
402
|
placetypePair: opts?.placetypePair ?? "inherit",
|
|
401
403
|
streetMorphology: stages.streetMorphology ?? null,
|
|
404
|
+
streetMorphologyPrior: stages.streetMorphologyPrior ?? false,
|
|
405
|
+
anchorRegions: stages.anchorRegions ?? null,
|
|
406
|
+
venueHead: stages.venueHead?.(locale) ?? null,
|
|
402
407
|
inputMode: deriveInputMode(opts?.inputMode ?? "auto", kind.kind),
|
|
403
408
|
})
|
|
404
409
|
|
|
@@ -477,10 +482,22 @@ async function safeClassify(
|
|
|
477
482
|
caseNormalization: CaseNormalization
|
|
478
483
|
placetypePair: PlacetypePairSelection
|
|
479
484
|
streetMorphology: FSTMatcherLike | null
|
|
485
|
+
streetMorphologyPrior: boolean
|
|
486
|
+
anchorRegions: AnchorRegionLookupLike | null
|
|
487
|
+
venueHead: VenueHeadStage | null
|
|
480
488
|
inputMode: InputMode
|
|
481
489
|
}
|
|
482
490
|
): Promise<AddressTree> {
|
|
483
|
-
const {
|
|
491
|
+
const {
|
|
492
|
+
fst,
|
|
493
|
+
caseNormalization,
|
|
494
|
+
placetypePair,
|
|
495
|
+
streetMorphology,
|
|
496
|
+
streetMorphologyPrior,
|
|
497
|
+
anchorRegions,
|
|
498
|
+
venueHead,
|
|
499
|
+
inputMode,
|
|
500
|
+
} = knobs
|
|
484
501
|
|
|
485
502
|
try {
|
|
486
503
|
return await classifier.parse(text, {
|
|
@@ -491,7 +508,10 @@ async function safeClassify(
|
|
|
491
508
|
caseNormalization,
|
|
492
509
|
enforceWordConsistency: WORD_CONSISTENCY_SHIP_DEFAULT,
|
|
493
510
|
placetypePair,
|
|
494
|
-
...streetContextRequirementFor({ fst, streetMorphology }),
|
|
511
|
+
...streetContextRequirementFor({ fst, streetMorphology }, { streetMorphologyPrior }),
|
|
512
|
+
...(fst && anchorRegions ? { anchorRegions } : {}),
|
|
513
|
+
...(venueHead ? { venueHead: venueHead.venueHead } : {}),
|
|
514
|
+
...(venueHead?.venueHeadOpts ? { venueHeadOpts: venueHead.venueHeadOpts } : {}),
|
|
495
515
|
})
|
|
496
516
|
} catch (error) {
|
|
497
517
|
recordFault(faults, PipelineFaultStage.Classifier, error)
|
|
@@ -506,6 +526,16 @@ async function safeClassify(
|
|
|
506
526
|
*/
|
|
507
527
|
export const ZEROED_MORPHOLOGY_OPTS = { biasScale: 0, dependentLocalityPenalty: 0 } as const
|
|
508
528
|
|
|
529
|
+
/**
|
|
530
|
+
* The street-morphology options that bias a street affix at the prior's own weights,
|
|
531
|
+
* on a segment that opens with a house number only.
|
|
532
|
+
*/
|
|
533
|
+
export const NUMBERED_MORPHOLOGY_OPTS = {
|
|
534
|
+
biasScale: 1,
|
|
535
|
+
dependentLocalityPenalty: 2,
|
|
536
|
+
numberedSegmentOnly: true,
|
|
537
|
+
} as const
|
|
538
|
+
|
|
509
539
|
/**
|
|
510
540
|
* The scale for positive street-context emissions.
|
|
511
541
|
* Zero disables the positive boost.
|
|
@@ -515,19 +545,27 @@ export const STREET_CONTEXT_POSITIVE_SCALE = 0
|
|
|
515
545
|
/**
|
|
516
546
|
* Returns the street-context classifier options, or an empty object unless both the FST
|
|
517
547
|
* and the street-morphology matcher are available.
|
|
548
|
+
*
|
|
549
|
+
* With `streetMorphologyPrior` the matcher also biases a street affix on a numbered segment.
|
|
550
|
+
* Without it the matcher serves the street-context check at zero emission weight.
|
|
518
551
|
*/
|
|
519
|
-
export function streetContextRequirementFor(
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
552
|
+
export function streetContextRequirementFor(
|
|
553
|
+
stages: {
|
|
554
|
+
fst?: FSTMatcherLike | null
|
|
555
|
+
streetMorphology?: FSTMatcherLike | null
|
|
556
|
+
},
|
|
557
|
+
options: { streetMorphologyPrior?: boolean } = {}
|
|
558
|
+
): {
|
|
523
559
|
fstStreetMorphology?: FSTMatcherLike
|
|
524
|
-
fstStreetMorphologyOpts?: { biasScale: number; dependentLocalityPenalty: number }
|
|
560
|
+
fstStreetMorphologyOpts?: { biasScale: number; dependentLocalityPenalty: number; numberedSegmentOnly?: boolean }
|
|
525
561
|
fstStreetContextPositiveScale?: number
|
|
526
562
|
} {
|
|
527
563
|
return stages.fst && stages.streetMorphology
|
|
528
564
|
? {
|
|
529
565
|
fstStreetMorphology: stages.streetMorphology,
|
|
530
|
-
fstStreetMorphologyOpts:
|
|
566
|
+
fstStreetMorphologyOpts: options.streetMorphologyPrior
|
|
567
|
+
? { ...NUMBERED_MORPHOLOGY_OPTS }
|
|
568
|
+
: { ...ZEROED_MORPHOLOGY_OPTS },
|
|
531
569
|
fstStreetContextPositiveScale: STREET_CONTEXT_POSITIVE_SCALE,
|
|
532
570
|
}
|
|
533
571
|
: {}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* A bracketed tail with at most this
|
|
11
|
+
* A bracketed tail with at most this number of tokens gets the lower short-tail confidence.
|
|
12
12
|
*/
|
|
13
13
|
const SHORT_INPUT_MAX_TOKENS = 3
|
|
14
14
|
|
|
@@ -88,7 +88,7 @@ export interface SpanProposerLexicon {
|
|
|
88
88
|
*/
|
|
89
89
|
levelDesignators: ReadonlySet<string>
|
|
90
90
|
/**
|
|
91
|
-
* Designators that
|
|
91
|
+
* Designators that can introduce descriptive text.
|
|
92
92
|
* Their unit phrases get lower confidence.
|
|
93
93
|
*/
|
|
94
94
|
weakDesignators: ReadonlySet<string>
|
package/lib/pipeline/types.ts
CHANGED
|
@@ -42,7 +42,8 @@ export type CaseNormalization = "title-case" | "preserve"
|
|
|
42
42
|
/**
|
|
43
43
|
* How a caller sources an optional stage.
|
|
44
44
|
*
|
|
45
|
-
* - `"auto"` loads the bundled default
|
|
45
|
+
* - `"auto"` loads the bundled default when it is first needed.
|
|
46
|
+
* For a typical caller that is the first parse.
|
|
46
47
|
* - `"none"` disables the stage.
|
|
47
48
|
* - Any other value is the stage itself.
|
|
48
49
|
*/
|
|
@@ -186,7 +187,7 @@ export interface QueryShapeLite {
|
|
|
186
187
|
segments: ReadonlyArray<{ body: string; index: number; span: { start: number; end: number } | null }> | null
|
|
187
188
|
characterClass: string | null
|
|
188
189
|
/**
|
|
189
|
-
* ISO 15924 scripts ranked by share of script
|
|
190
|
+
* ISO 15924 scripts ranked by share of characters that belong to a script.
|
|
190
191
|
*/
|
|
191
192
|
scripts: ReadonlyArray<{ script: string; share: number }> | null
|
|
192
193
|
/**
|
|
@@ -212,7 +213,7 @@ export interface LocaleHint {
|
|
|
212
213
|
/**
|
|
213
214
|
* ISO 15924 scripts in the input, ranked by character share.
|
|
214
215
|
*
|
|
215
|
-
* The array is empty when the input
|
|
216
|
+
* The array is empty when no character of the input belongs to a script.
|
|
216
217
|
* `locale` stays a BCP-47 language tag.
|
|
217
218
|
*/
|
|
218
219
|
script: ReadonlyArray<{ script: string; confidence: number }>
|
|
@@ -263,7 +264,7 @@ export type QueryKind = z.infer<typeof QueryKindSchema>
|
|
|
263
264
|
*/
|
|
264
265
|
export const QueryIntentCode = {
|
|
265
266
|
/**
|
|
266
|
-
* Resolution found no
|
|
267
|
+
* Resolution found no single candidate that outranks the rest for a place with a recognized name.
|
|
267
268
|
*/
|
|
268
269
|
DeclaredAmbiguity: "declared_ambiguity",
|
|
269
270
|
/**
|
|
@@ -531,7 +532,112 @@ export interface FSTMatcherLike {
|
|
|
531
532
|
prev: { stateID: number; depth: number },
|
|
532
533
|
token: string
|
|
533
534
|
): { stateID: number; accepted: boolean; depth: number } | null
|
|
534
|
-
accepting(stateID: number): Array<{ wofID: number; placetype: string; referential: number }>
|
|
535
|
+
accepting(stateID: number): Array<{ wofID: number; placetype: string; referential: number; name?: string }>
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* One admin ancestor an anchored postcode asserts.
|
|
540
|
+
*/
|
|
541
|
+
export interface AnchorRegionAncestor {
|
|
542
|
+
/**
|
|
543
|
+
* The WOF placetype, such as `"region"`.
|
|
544
|
+
*/
|
|
545
|
+
placetype: string
|
|
546
|
+
wofID: number
|
|
547
|
+
/**
|
|
548
|
+
* The place's name in the gazetteer, which the prior compares with the written surface.
|
|
549
|
+
*/
|
|
550
|
+
name: string
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* The admin ancestry a postcode's anchor asserts, read by the anchor-region prior.
|
|
555
|
+
*/
|
|
556
|
+
export interface AnchorRegionLookupLike {
|
|
557
|
+
/**
|
|
558
|
+
* Returns the ancestors the index asserts for `postcode` in `country`, coarsest first.
|
|
559
|
+
*
|
|
560
|
+
* The array is empty when no index covers the country or the index holds no unanimous
|
|
561
|
+
* answer for the postcode, as for a prefix whose units sit in two regions.
|
|
562
|
+
*/
|
|
563
|
+
ancestorsFor(postcode: string, country: string): readonly AnchorRegionAncestor[]
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Venue-head lookups for one country.
|
|
568
|
+
* Each method returns a bias in natural-log units or `null`.
|
|
569
|
+
*/
|
|
570
|
+
export interface VenueHeadLexiconLike {
|
|
571
|
+
/**
|
|
572
|
+
* The bias of `word` as the first word of a venue name.
|
|
573
|
+
*/
|
|
574
|
+
first(word: string): number | null
|
|
575
|
+
/**
|
|
576
|
+
* The bias of `word` as the last word of a venue name.
|
|
577
|
+
*/
|
|
578
|
+
last(word: string): number | null
|
|
579
|
+
/**
|
|
580
|
+
* The bias of the longest suffix of `word`, shorter than `word`, that marks a venue name.
|
|
581
|
+
*/
|
|
582
|
+
suffix(word: string): number | null
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Overrides for the venue-head prior.
|
|
587
|
+
*/
|
|
588
|
+
export interface VenueHeadPriorOpts {
|
|
589
|
+
/**
|
|
590
|
+
* Multiplier on the lexicon's bias.
|
|
591
|
+
*
|
|
592
|
+
* The prior's own default applies when this is absent.
|
|
593
|
+
*/
|
|
594
|
+
biasScale?: number
|
|
595
|
+
/**
|
|
596
|
+
* Maximum bias, in logits, on any one cell.
|
|
597
|
+
*
|
|
598
|
+
* The table's biases are log rate ratios and seldom exceed 6.
|
|
599
|
+
* The cap bounds a scaled bias.
|
|
600
|
+
*
|
|
601
|
+
* @defaultValue `6`
|
|
602
|
+
*/
|
|
603
|
+
maxBias?: number
|
|
604
|
+
/**
|
|
605
|
+
* The most words the venue span extends from its head.
|
|
606
|
+
*
|
|
607
|
+
* @defaultValue `3`
|
|
608
|
+
*/
|
|
609
|
+
extensionWords?: number
|
|
610
|
+
/**
|
|
611
|
+
* Factor applied to the bias once for each word between a word and its head.
|
|
612
|
+
*
|
|
613
|
+
* The shipped model's venue logits trail the winning label by a near-constant margin
|
|
614
|
+
* across a landmark name's pieces, so the default extends the head's bias undiminished.
|
|
615
|
+
*
|
|
616
|
+
* @defaultValue `1`
|
|
617
|
+
*/
|
|
618
|
+
extensionDecay?: number
|
|
619
|
+
/**
|
|
620
|
+
* Whether a word is a street-type affix, in `normalizeFSTToken` form.
|
|
621
|
+
*
|
|
622
|
+
* A head followed by one is a street name (`Museum Street`) and gets no bias,
|
|
623
|
+
* and an extension stops at one.
|
|
624
|
+
*/
|
|
625
|
+
isStreetAffix?: (word: string) => boolean
|
|
626
|
+
/**
|
|
627
|
+
* Whether a segment's words, joined by single spaces in `normalizeFSTToken` form,
|
|
628
|
+
* are a country name, as `united states of america` is.
|
|
629
|
+
*
|
|
630
|
+
* No word of such a segment heads a venue, so `of America` keeps its country reading.
|
|
631
|
+
*/
|
|
632
|
+
isCountryName?: (segment: string) => boolean
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* The venue-head lexicon a pipeline stage selects for one parse, with the prior's overrides.
|
|
637
|
+
*/
|
|
638
|
+
export interface VenueHeadStage {
|
|
639
|
+
venueHead: VenueHeadLexiconLike
|
|
640
|
+
venueHeadOpts?: VenueHeadPriorOpts
|
|
535
641
|
}
|
|
536
642
|
|
|
537
643
|
/**
|
|
@@ -554,7 +660,30 @@ export interface ClassifierOpts {
|
|
|
554
660
|
/**
|
|
555
661
|
* Emission-prior weights for the street-morphology matcher.
|
|
556
662
|
*/
|
|
557
|
-
fstStreetMorphologyOpts?: { biasScale?: number; dependentLocalityPenalty?: number }
|
|
663
|
+
fstStreetMorphologyOpts?: { biasScale?: number; dependentLocalityPenalty?: number; numberedSegmentOnly?: boolean }
|
|
664
|
+
/**
|
|
665
|
+
* The scale for positive street-context emissions.
|
|
666
|
+
*/
|
|
667
|
+
fstStreetContextPositiveScale?: number
|
|
668
|
+
/**
|
|
669
|
+
* The admin ancestry of an anchored postcode, for the anchor-region prior.
|
|
670
|
+
*
|
|
671
|
+
* The prior raises an FST region match to the full bias when the postcode the anchor
|
|
672
|
+
* channel fired on asserts that region and the written name is the region's own name.
|
|
673
|
+
* It runs only with `fst` and the classifier's postcode anchor lookup.
|
|
674
|
+
*/
|
|
675
|
+
anchorRegions?: AnchorRegionLookupLike
|
|
676
|
+
/**
|
|
677
|
+
* Venue-head lookups for the input's country.
|
|
678
|
+
*
|
|
679
|
+
* Their prior biases a venue head word and the words of its phrase toward `venue`.
|
|
680
|
+
* Absent, the prior does not run.
|
|
681
|
+
*/
|
|
682
|
+
venueHead?: VenueHeadLexiconLike
|
|
683
|
+
/**
|
|
684
|
+
* Overrides for the venue-head prior's bias magnitudes and extension.
|
|
685
|
+
*/
|
|
686
|
+
venueHeadOpts?: VenueHeadPriorOpts
|
|
558
687
|
/**
|
|
559
688
|
* Applies deterministic postcode repair after decoding.
|
|
560
689
|
*/
|
|
@@ -646,6 +775,24 @@ export interface RuntimePipelineStages {
|
|
|
646
775
|
* The street-context check runs only when `fst` is also set.
|
|
647
776
|
*/
|
|
648
777
|
streetMorphology?: FSTMatcherLike
|
|
778
|
+
/**
|
|
779
|
+
* Whether the street-morphology matcher also biases a street affix on a segment that
|
|
780
|
+
* opens with a house number, as `Plaza` in `30 Rockefeller Plaza, New York, NY 10112`.
|
|
781
|
+
*
|
|
782
|
+
* Absent, the matcher serves the street-context check at zero emission weight.
|
|
783
|
+
*/
|
|
784
|
+
streetMorphologyPrior?: boolean
|
|
785
|
+
/**
|
|
786
|
+
* The admin ancestry of an anchored postcode, for the anchor-region prior.
|
|
787
|
+
* The prior runs only when `fst` is also set.
|
|
788
|
+
*/
|
|
789
|
+
anchorRegions?: AnchorRegionLookupLike
|
|
790
|
+
/**
|
|
791
|
+
* The venue-head lexicon for the detected locale with the prior's overrides, or `null` for none.
|
|
792
|
+
*
|
|
793
|
+
* The pipeline calls it once per parse with the locale hint and passes both to the classifier.
|
|
794
|
+
*/
|
|
795
|
+
venueHead?: (locale: LocaleHint) => VenueHeadStage | null
|
|
649
796
|
resolver?: Resolver
|
|
650
797
|
/**
|
|
651
798
|
* The backend for resolver candidate and parent-chain lookups during reconciliation.
|
package/lib/pipeline.ts
CHANGED
|
@@ -11,6 +11,7 @@ export {
|
|
|
11
11
|
HARD_PLACE_COUNTRY_SAFELIST,
|
|
12
12
|
hardCountryFor,
|
|
13
13
|
STREET_CONTEXT_POSITIVE_SCALE,
|
|
14
|
+
NUMBERED_MORPHOLOGY_OPTS,
|
|
14
15
|
streetContextRequirementFor,
|
|
15
16
|
ZEROED_MORPHOLOGY_OPTS,
|
|
16
17
|
isBareLocalityTree,
|
|
@@ -45,6 +46,8 @@ export type {
|
|
|
45
46
|
AddressClassifier,
|
|
46
47
|
CaseNormalization,
|
|
47
48
|
ClassifierOpts,
|
|
49
|
+
AnchorRegionAncestor,
|
|
50
|
+
AnchorRegionLookupLike,
|
|
48
51
|
FSTMatcherLike,
|
|
49
52
|
InputMode,
|
|
50
53
|
InputModeSelection,
|
|
@@ -68,6 +71,9 @@ export type {
|
|
|
68
71
|
RuntimePipelineStages,
|
|
69
72
|
StageSource,
|
|
70
73
|
UserLocation,
|
|
74
|
+
VenueHeadLexiconLike,
|
|
75
|
+
VenueHeadPriorOpts,
|
|
76
|
+
VenueHeadStage,
|
|
71
77
|
WordConsistencyOpts,
|
|
72
78
|
WordConsistencySetting,
|
|
73
79
|
} from "#pipeline/types"
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The file names of PFX1 postcode-prefix indexes. The data root holds one dated file per build
|
|
7
|
+
* under `postcode-prefix/`, and a weights package ships the newest of each scope under the
|
|
8
|
+
* scope's own name. The loaders, the dev overlay linker and the release copy read the same
|
|
9
|
+
* listing here so they agree on which file a scope resolves to.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { PathBuilder, type PathBuilderLike } from "path-ts"
|
|
13
|
+
import { Globerator } from "spliterator/node/fs"
|
|
14
|
+
|
|
15
|
+
import { dataRootPath } from "#data-root"
|
|
16
|
+
import { tryStat } from "#fs/readers/stat"
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The data-root directory that holds the dated PFX1 postcode-prefix indexes.
|
|
20
|
+
*/
|
|
21
|
+
export const POSTCODE_PREFIX_DIRECTORY = dataRootPath("postcode-prefix")
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The glob that matches a postcode-prefix index file, dated or shipped.
|
|
25
|
+
*/
|
|
26
|
+
export const POSTCODE_PREFIX_FILE_GLOB = "postcode-prefix-*.bin"
|
|
27
|
+
|
|
28
|
+
const DATED_FILE = /^postcode-prefix-(?<scope>.+)-(?<date>\d{4}-\d{2}-\d{2})\.bin$/
|
|
29
|
+
const SHIPPED_FILE = /^postcode-prefix-(?<scope>.+)\.bin$/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns the file name a weights package ships a scope's index under, such as `postcode-prefix-us.bin`.
|
|
33
|
+
*/
|
|
34
|
+
export function shippedPostcodePrefixName(scope: string): string {
|
|
35
|
+
return `postcode-prefix-${scope}.bin`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns the scope a postcode-prefix file name belongs to, such as `gb-esw`
|
|
40
|
+
* for `postcode-prefix-gb-esw-2026-08-05.bin` or `postcode-prefix-gb-esw.bin`,
|
|
41
|
+
* or `null` for a name of another shape.
|
|
42
|
+
*/
|
|
43
|
+
export function postcodePrefixScopeOf(fileName: string): string | null {
|
|
44
|
+
return DATED_FILE.exec(fileName)?.groups?.scope ?? SHIPPED_FILE.exec(fileName)?.groups?.scope ?? null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* One postcode-prefix index file chosen for its scope.
|
|
49
|
+
*/
|
|
50
|
+
export interface PostcodePrefixFile {
|
|
51
|
+
scope: string
|
|
52
|
+
path: PathBuilder
|
|
53
|
+
mtimeMs: number
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Lists the newest postcode-prefix index of each scope under `directory`, by modification time.
|
|
58
|
+
*
|
|
59
|
+
* An absent directory lists no file.
|
|
60
|
+
* A file whose name has no scope is skipped.
|
|
61
|
+
*/
|
|
62
|
+
export async function newestPostcodePrefixFiles(
|
|
63
|
+
directory: PathBuilderLike = POSTCODE_PREFIX_DIRECTORY
|
|
64
|
+
): Promise<Map<string, PostcodePrefixFile>> {
|
|
65
|
+
const newest = new Map<string, PostcodePrefixFile>()
|
|
66
|
+
|
|
67
|
+
if (!(await tryStat(directory))) return newest
|
|
68
|
+
|
|
69
|
+
for await (const entry of Globerator.from(POSTCODE_PREFIX_FILE_GLOB, { cwd: directory.toString() })) {
|
|
70
|
+
const scope = postcodePrefixScopeOf(entry)
|
|
71
|
+
|
|
72
|
+
if (!scope) continue
|
|
73
|
+
|
|
74
|
+
const path = PathBuilder.from(directory, entry)
|
|
75
|
+
const stat = await tryStat(path)
|
|
76
|
+
|
|
77
|
+
if (!stat) continue
|
|
78
|
+
|
|
79
|
+
const current = newest.get(scope)
|
|
80
|
+
|
|
81
|
+
if (!current || stat.mtimeMs > current.mtimeMs) {
|
|
82
|
+
newest.set(scope, { scope, path, mtimeMs: stat.mtimeMs })
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return newest
|
|
87
|
+
}
|
package/lib/promises.ts
CHANGED
|
@@ -5,6 +5,18 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Marks a promise started ahead of the await that reads it as handled, and returns it unchanged.
|
|
10
|
+
*
|
|
11
|
+
* A rejection still reaches the later await.
|
|
12
|
+
* Before that await, or when the result goes unused, it is not reported as unhandled.
|
|
13
|
+
*/
|
|
14
|
+
export function startEarly<T>(promise: Promise<T>): Promise<T> {
|
|
15
|
+
promise.catch(() => {})
|
|
16
|
+
|
|
17
|
+
return promise
|
|
18
|
+
}
|
|
19
|
+
|
|
8
20
|
/**
|
|
9
21
|
* Await every enumerable own property of an object while preserving its keys.
|
|
10
22
|
*/
|
package/lib/release-config.ts
CHANGED
|
@@ -48,6 +48,13 @@ export interface SoftFeedRecipe {
|
|
|
48
48
|
localitySurfaceLexicon?: string
|
|
49
49
|
pairIndexByCountry?: Record<string, PairIndexInputs>
|
|
50
50
|
postcodeDBByCountry?: Record<string, string>
|
|
51
|
+
/**
|
|
52
|
+
* The PFX1 postcode-prefix index scopes each country ships, such as `["gb-esw"]` for `gb`.
|
|
53
|
+
*
|
|
54
|
+
* The copy takes the newest dated file of each scope under the data root's
|
|
55
|
+
* `postcode-prefix` directory and refuses one whose header tier is `build-local`.
|
|
56
|
+
*/
|
|
57
|
+
postcodePrefixByCountry?: Record<string, string[]>
|
|
51
58
|
[key: string]: unknown
|
|
52
59
|
}
|
|
53
60
|
|
|
@@ -27,7 +27,7 @@ export interface CountryCoverageFact {
|
|
|
27
27
|
country: string
|
|
28
28
|
/**
|
|
29
29
|
* The promotion-eval verdict that hard-filtering this country is a pure win.
|
|
30
|
-
* A hard-filter miss is almost always a
|
|
30
|
+
* A hard-filter miss is almost always a true non-match.
|
|
31
31
|
*
|
|
32
32
|
* Stored as a verdict rather than re-derived from `hardResolveRate` at read time,
|
|
33
33
|
* since it is a judgment over a panel.
|
|
@@ -73,8 +73,8 @@ export interface CountryBBoxFact {
|
|
|
73
73
|
* Facts a loaded gazetteer artifact declares about itself.
|
|
74
74
|
*
|
|
75
75
|
* Read from the artifact's own manifest tables at open time, stored on the
|
|
76
|
-
* {@link ResolverBackend}/{@link Resolver} handle so consumers read the facts
|
|
77
|
-
* the artifact they
|
|
76
|
+
* {@link ResolverBackend}/{@link Resolver} handle so consumers read the facts
|
|
77
|
+
* from the artifact they resolve against.
|
|
78
78
|
*
|
|
79
79
|
* `null` on the handle means the artifact predates the manifest.
|
|
80
80
|
* Consumers then use the code constants.
|
|
@@ -70,7 +70,7 @@ export interface AddressPointLookup {
|
|
|
70
70
|
* Optional bbox scope (`minLat`/`maxLat`/`minLon`/`maxLon`), tried after postcode and locality.
|
|
71
71
|
*
|
|
72
72
|
* For extracts whose points contain no postcode or locality of their own
|
|
73
|
-
* (
|
|
73
|
+
* (some OSM addr nodes do not) but include a coordinate, the resolved locality's
|
|
74
74
|
* bounding box scopes the `(street, number)` probe instead.
|
|
75
75
|
* US situs never passes it, so the Latin path stays byte-stable.
|
|
76
76
|
*/
|
|
@@ -80,7 +80,7 @@ export interface AddressPointLookup {
|
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* One interpolated coordinate estimate, never an exact situs point.
|
|
83
|
-
* `uncertaintyM`
|
|
83
|
+
* `uncertaintyM` states the estimate's radius in meters.
|
|
84
84
|
*
|
|
85
85
|
* A structural mirror of `InterpolatedHit` in `resolver-wof-sqlite/interpolation.ts`.
|
|
86
86
|
* Keep this a subset of that shape so the concrete `StreetInterpolator`
|
|
@@ -107,7 +107,7 @@ export interface InterpolatedPointHit {
|
|
|
107
107
|
*/
|
|
108
108
|
bracket: "both" | "single" | null
|
|
109
109
|
/**
|
|
110
|
-
*
|
|
110
|
+
* Uncertainty radius in meters, measured as half the matched segment length.
|
|
111
111
|
*/
|
|
112
112
|
uncertaintyM: number
|
|
113
113
|
source: string
|
|
@@ -159,20 +159,21 @@ export interface InterpolationLookup {
|
|
|
159
159
|
* One street-centroid hit, the street-level tier below the exact address-point tier
|
|
160
160
|
* and above admin-centroid resolution.
|
|
161
161
|
*
|
|
162
|
-
* A street's centroid and
|
|
162
|
+
* A street's centroid and a radius derived from the street's extent,
|
|
163
|
+
* for a street-only query with no house number.
|
|
163
164
|
* An address-point tier cannot serve that query.
|
|
164
165
|
*
|
|
165
166
|
* Derived from a national register's rooftop points in `street-centroids-<cc>.db`,
|
|
166
167
|
* a `group BY street` roll-up.
|
|
167
168
|
*
|
|
168
|
-
* `uncertaintyM`
|
|
169
|
+
* `uncertaintyM` states the coarseness in meters as half the street's bbox diagonal,
|
|
169
170
|
* so a consumer never mistakes it for a rooftop.
|
|
170
171
|
*/
|
|
171
172
|
export interface StreetCentroidHit {
|
|
172
173
|
lat: number
|
|
173
174
|
lon: number
|
|
174
175
|
/**
|
|
175
|
-
*
|
|
176
|
+
* Coarse radius in meters, measured as half the street's bounding-box diagonal.
|
|
176
177
|
*/
|
|
177
178
|
uncertaintyM: number
|
|
178
179
|
source: string
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* Population divisor in {@link referentialFromPopulation}.
|
|
26
26
|
*
|
|
27
27
|
* A 1,000-person place scores `log2(2)/14` — the curve starts counting at the scale
|
|
28
|
-
* where WOF
|
|
28
|
+
* where WOF records a population value.
|
|
29
29
|
*/
|
|
30
30
|
export const REFERENTIAL_POPULATION_DIVISOR = 1000
|
|
31
31
|
|
package/lib/resolver/types.ts
CHANGED
|
@@ -92,6 +92,11 @@ export interface ResolvedPlace {
|
|
|
92
92
|
* Optional marker for variant-alias exemption.
|
|
93
93
|
*/
|
|
94
94
|
variantAliasExempted?: true | null
|
|
95
|
+
/**
|
|
96
|
+
* Optional stored extent.
|
|
97
|
+
* A point-only row stores its coordinate as both corners.
|
|
98
|
+
*/
|
|
99
|
+
bbox?: { minLat: number; maxLat: number; minLon: number; maxLon: number } | null
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
/**
|
|
@@ -535,6 +540,7 @@ export interface ResolveNodeTrace {
|
|
|
535
540
|
| "ranked"
|
|
536
541
|
| "bare_country"
|
|
537
542
|
| "bare_region"
|
|
543
|
+
| "bare_sublocality"
|
|
538
544
|
| "postcode_prefix"
|
|
539
545
|
| "postcode_format_probe"
|
|
540
546
|
| "empty_admin"
|