@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.
Files changed (162) hide show
  1. package/data/PROVENANCE.md +14 -14
  2. package/data/libpostal/README.md +15 -15
  3. package/data/libpostal/dictionaries/README.md +3 -3
  4. package/lib/api/APIClient.ts +3 -3
  5. package/lib/api/clock.ts +1 -1
  6. package/lib/api/disk-storage.ts +4 -4
  7. package/lib/api/ogc.ts +9 -9
  8. package/lib/api/pacer.ts +1 -1
  9. package/lib/api/responses.ts +6 -6
  10. package/lib/api/retry.ts +2 -2
  11. package/lib/api/test/clocks.ts +2 -2
  12. package/lib/api/test/transport.ts +1 -1
  13. package/lib/coarse-placer/coarse-placer.ts +1 -1
  14. package/lib/decoder/build-tree.ts +1 -1
  15. package/lib/decoder/parse-diff.ts +3 -3
  16. package/lib/decoder/serialize/xml.ts +1 -1
  17. package/lib/fs/delimited.ts +3 -3
  18. package/lib/fs/formatters.ts +1 -1
  19. package/lib/fs/readers.ts +3 -2
  20. package/lib/fs/zip.ts +1 -1
  21. package/lib/geocode/result.ts +8 -4
  22. package/lib/html/document.ts +1 -1
  23. package/lib/html/elements.ts +3 -3
  24. package/lib/json.ts +1 -1
  25. package/lib/layers/coverage.ts +3 -3
  26. package/lib/layers/manifest.ts +2 -2
  27. package/lib/layers/publication.ts +1 -1
  28. package/lib/layers/schema.ts +1 -1
  29. package/lib/license/record.ts +3 -4
  30. package/lib/module/compiled-freshness.ts +1 -1
  31. package/lib/numeric.ts +2 -2
  32. package/lib/pipeline/runtime-pipeline.ts +47 -9
  33. package/lib/pipeline/span-proposer.ts +2 -2
  34. package/lib/pipeline/types.ts +153 -6
  35. package/lib/pipeline.ts +6 -0
  36. package/lib/postcode-prefix-files.ts +87 -0
  37. package/lib/promises.ts +12 -0
  38. package/lib/release-config.ts +7 -0
  39. package/lib/resolver/coverage-facts.ts +3 -3
  40. package/lib/resolver/lookup-types.ts +7 -6
  41. package/lib/resolver/referential.ts +1 -1
  42. package/lib/resolver/types.ts +6 -0
  43. package/lib/resources/libpostal.ts +51 -3
  44. package/lib/resources/whosonfirst/placetypes/graph.ts +2 -2
  45. package/lib/resources/whosonfirst/placetypes/specificity.ts +2 -2
  46. package/lib/scripting/utils.ts +1 -1
  47. package/lib/tokenization/normalizer.ts +1 -1
  48. package/lib/trust-policies.ts +1 -1
  49. package/lib/utils/chunk-process.ts +1 -1
  50. package/lib/utils/system.ts +1 -1
  51. package/out/api/APIClient.d.ts +2 -2
  52. package/out/api/APIClient.js +1 -1
  53. package/out/api/APIClient.js.map +1 -1
  54. package/out/api/clock.d.ts +1 -1
  55. package/out/api/clock.js +1 -1
  56. package/out/api/disk-storage.js +4 -4
  57. package/out/api/disk-storage.js.map +1 -1
  58. package/out/api/ogc.d.ts +8 -8
  59. package/out/api/ogc.js +8 -8
  60. package/out/api/ogc.js.map +1 -1
  61. package/out/api/pacer.d.ts +1 -1
  62. package/out/api/pacer.js +1 -1
  63. package/out/api/responses.d.ts +4 -4
  64. package/out/api/responses.js +6 -6
  65. package/out/api/responses.js.map +1 -1
  66. package/out/api/retry.d.ts +2 -2
  67. package/out/api/retry.js +1 -1
  68. package/out/api/test/clocks.js +2 -2
  69. package/out/api/test/transport.d.ts +1 -1
  70. package/out/coarse-placer/coarse-placer.d.ts +1 -1
  71. package/out/coarse-placer/coarse-placer.js +1 -1
  72. package/out/decoder/build-tree.js +1 -1
  73. package/out/decoder/build-tree.js.map +1 -1
  74. package/out/decoder/parse-diff.d.ts +3 -3
  75. package/out/decoder/parse-diff.js +2 -2
  76. package/out/decoder/serialize/xml.d.ts +1 -1
  77. package/out/decoder/serialize/xml.js +1 -1
  78. package/out/fs/delimited.d.ts +3 -3
  79. package/out/fs/delimited.js +3 -3
  80. package/out/fs/formatters.d.ts +1 -1
  81. package/out/fs/formatters.js +1 -1
  82. package/out/fs/readers.d.ts +3 -2
  83. package/out/fs/readers.d.ts.map +1 -1
  84. package/out/fs/readers.js +3 -2
  85. package/out/fs/readers.js.map +1 -1
  86. package/out/fs/zip.d.ts +1 -1
  87. package/out/fs/zip.js +1 -1
  88. package/out/geocode/result.d.ts +17 -5
  89. package/out/geocode/result.d.ts.map +1 -1
  90. package/out/geocode/result.js +8 -4
  91. package/out/geocode/result.js.map +1 -1
  92. package/out/html/document.d.ts +1 -1
  93. package/out/html/document.js +1 -1
  94. package/out/html/elements.d.ts +2 -2
  95. package/out/html/elements.js +3 -3
  96. package/out/json.d.ts +1 -1
  97. package/out/json.js +1 -1
  98. package/out/layers/coverage.d.ts +3 -3
  99. package/out/layers/coverage.js +2 -2
  100. package/out/layers/manifest.d.ts +2 -2
  101. package/out/layers/publication.d.ts +1 -1
  102. package/out/layers/publication.js +1 -1
  103. package/out/layers/schema.d.ts +1 -1
  104. package/out/license/record.d.ts.map +1 -1
  105. package/out/license/record.js +3 -4
  106. package/out/license/record.js.map +1 -1
  107. package/out/module/compiled-freshness.d.ts +1 -1
  108. package/out/module/compiled-freshness.js +1 -1
  109. package/out/numeric.js +2 -2
  110. package/out/pipeline/runtime-pipeline.d.ts +15 -0
  111. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  112. package/out/pipeline/runtime-pipeline.js +25 -5
  113. package/out/pipeline/runtime-pipeline.js.map +1 -1
  114. package/out/pipeline/span-proposer.d.ts +1 -1
  115. package/out/pipeline/span-proposer.js +1 -1
  116. package/out/pipeline/types.d.ts +150 -6
  117. package/out/pipeline/types.d.ts.map +1 -1
  118. package/out/pipeline/types.js +1 -1
  119. package/out/pipeline/types.js.map +1 -1
  120. package/out/pipeline.d.ts +2 -2
  121. package/out/pipeline.d.ts.map +1 -1
  122. package/out/pipeline.js +1 -1
  123. package/out/pipeline.js.map +1 -1
  124. package/out/postcode-prefix-files.d.ts +45 -0
  125. package/out/postcode-prefix-files.d.ts.map +1 -0
  126. package/out/postcode-prefix-files.js +64 -0
  127. package/out/postcode-prefix-files.js.map +1 -0
  128. package/out/promises.d.ts +7 -0
  129. package/out/promises.d.ts.map +1 -1
  130. package/out/promises.js +10 -0
  131. package/out/promises.js.map +1 -1
  132. package/out/release-config.d.ts +7 -0
  133. package/out/release-config.d.ts.map +1 -1
  134. package/out/release-config.js.map +1 -1
  135. package/out/resolver/coverage-facts.d.ts +3 -3
  136. package/out/resolver/lookup-types.d.ts +7 -6
  137. package/out/resolver/lookup-types.d.ts.map +1 -1
  138. package/out/resolver/referential.d.ts +1 -1
  139. package/out/resolver/referential.js +1 -1
  140. package/out/resolver/types.d.ts +11 -1
  141. package/out/resolver/types.d.ts.map +1 -1
  142. package/out/resolver/types.js.map +1 -1
  143. package/out/resources/libpostal.d.ts +22 -3
  144. package/out/resources/libpostal.d.ts.map +1 -1
  145. package/out/resources/libpostal.js +44 -4
  146. package/out/resources/libpostal.js.map +1 -1
  147. package/out/resources/whosonfirst/placetypes/graph.d.ts +2 -2
  148. package/out/resources/whosonfirst/placetypes/graph.js +1 -1
  149. package/out/resources/whosonfirst/placetypes/specificity.d.ts +2 -2
  150. package/out/resources/whosonfirst/placetypes/specificity.js +2 -2
  151. package/out/scripting/utils.d.ts +1 -1
  152. package/out/scripting/utils.js +1 -1
  153. package/out/tokenization/normalizer.js +1 -1
  154. package/out/tools/coarse-placer/outlier-rows.js +1 -1
  155. package/out/trust-policies.d.ts +1 -1
  156. package/out/trust-policies.js +1 -1
  157. package/out/utils/chunk-process.d.ts +1 -1
  158. package/out/utils/chunk-process.js +1 -1
  159. package/out/utils/system.d.ts +1 -1
  160. package/out/utils/system.js +1 -1
  161. package/package.json +28 -8
  162. package/tools/coarse-placer/outlier-rows.ts +1 -1
@@ -51,7 +51,7 @@ export interface LayerManifest {
51
51
  spineKeys: SpineKeys
52
52
  createdAt: string
53
53
  /**
54
- * How many records each input publisher supplied to this build, keyed by the publisher's own name.
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
- * Evidence basis for completeness.
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 Names the build in the error message.
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
  */
@@ -146,7 +146,7 @@ export interface LayerCoverageTable {
146
146
  */
147
147
  basis: CoverageBasis | null
148
148
  /**
149
- * Rows this layer actually holds in the cell.
149
+ * Rows this layer stores in the cell.
150
150
  */
151
151
  observed_rows: number
152
152
  }
@@ -129,7 +129,7 @@ const EXPRESSION_ALIASES: ReadonlyMap<string, string> = new Map([
129
129
  ])
130
130
 
131
131
  /**
132
- * License identifiers worth recognizing inside prose, with the spelling each one appears under.
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 often opens with a parenthetical belonging to the dataset's own name,
267
- // such as "OpenAddresses PL — GUGiK / PRG (public, BDOT-derived)", so every
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 actually loads.
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 a
26
- * extract that quietly disagrees with the reference.
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 many characters takes the full pipeline.
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 { fst, caseNormalization, placetypePair, streetMorphology, inputMode } = knobs
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(stages: {
520
- fst?: FSTMatcherLike | null
521
- streetMorphology?: FSTMatcherLike | null
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: { ...ZEROED_MORPHOLOGY_OPTS },
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 many tokens gets the lower short-tail confidence.
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 usually introduce descriptive text.
91
+ * Designators that can introduce descriptive text.
92
92
  * Their unit phrases get lower confidence.
93
93
  */
94
94
  weakDesignators: ReadonlySet<string>
@@ -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, usually on the first parse.
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-bearing characters.
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 has no script-bearing text.
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 decisive candidate for a place with a recognized name.
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
  */
@@ -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 genuine non-match.
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 from
77
- * the artifact they are actually resolving against.
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
- * (many OSM addr nodes do not) but include a coordinate, the resolved locality's
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` prices the estimate honestly.
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
- * Honest uncertainty radius in meters (half the matched segment length).
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 an honest extent-derived radius, for a street-only query with no house number.
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` prices the coarseness as half the street's bbox diagonal,
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
- * Honest coarse radius in meters, half the street's bounding-box diagonal.
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 actually records population.
28
+ * where WOF records a population value.
29
29
  */
30
30
  export const REFERENTIAL_POPULATION_DIVISOR = 1000
31
31
 
@@ -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"