@mailwoman/core 10.3.0 → 10.5.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/ckan.ts +1 -1
- 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/json.ts +1 -1
- package/lib/decoder/serialize/xml.ts +1 -1
- package/lib/env/env-file.ts +71 -0
- package/lib/env.ts +15 -9
- package/lib/fs/delimited.ts +3 -3
- package/lib/fs/formatters.ts +1 -1
- package/lib/fs/readers/stat.ts +16 -1
- package/lib/fs/readers.ts +18 -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/docs-site.ts +1 -1
- package/lib/license/record.ts +3 -4
- package/lib/module/compiled-freshness.ts +6 -2
- 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/types/classifier.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/ckan.d.ts +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/json.js +1 -1
- package/out/decoder/serialize/xml.d.ts +1 -1
- package/out/decoder/serialize/xml.js +1 -1
- package/out/env/env-file.d.ts +26 -0
- package/out/env/env-file.d.ts.map +1 -0
- package/out/env/env-file.js +60 -0
- package/out/env/env-file.js.map +1 -0
- package/out/env.d.ts.map +1 -1
- package/out/env.js +15 -10
- package/out/env.js.map +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/stat.d.ts +9 -1
- package/out/fs/readers/stat.d.ts.map +1 -1
- package/out/fs/readers/stat.js +16 -0
- package/out/fs/readers/stat.js.map +1 -1
- package/out/fs/readers.d.ts +14 -2
- package/out/fs/readers.d.ts.map +1 -1
- package/out/fs/readers.js +17 -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/docs-site.d.ts +1 -1
- package/out/license/docs-site.js +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.d.ts.map +1 -1
- package/out/module/compiled-freshness.js +6 -2
- package/out/module/compiled-freshness.js.map +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/tools/coarse-placer/paths.d.ts +2 -2
- package/out/tools/coarse-placer/paths.js +2 -2
- package/out/trust-policies.d.ts +1 -1
- package/out/trust-policies.js +1 -1
- package/out/types/classifier.d.ts +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/tools/coarse-placer/paths.ts +2 -2
package/lib/fs/readers/stat.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { AssertionError } from "node:assert"
|
|
8
|
-
import type
|
|
8
|
+
import { type Dirent, type Mode, type Stats, statSync } from "node:fs"
|
|
9
9
|
import {
|
|
10
10
|
open as openNative,
|
|
11
11
|
access,
|
|
@@ -201,6 +201,21 @@ export function isFile(path: PathBuilderLike | URL): Promise<boolean> {
|
|
|
201
201
|
return tryStat(path).then((stats) => stats?.isFile() ?? false)
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Whether a path exists and is a file, read synchronously.
|
|
206
|
+
*
|
|
207
|
+
* The env module folds `.env` into `process.env` when it is imported,
|
|
208
|
+
* ahead of any `await`, so it cannot use {@linkcode isFile}.
|
|
209
|
+
* Every other caller can, and should.
|
|
210
|
+
*/
|
|
211
|
+
export function isFileSync(path: PathBuilderLike): boolean {
|
|
212
|
+
try {
|
|
213
|
+
return statSync(resolvePath(path)).isFile()
|
|
214
|
+
} catch {
|
|
215
|
+
return false
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
204
219
|
/**
|
|
205
220
|
* Whether a path exists and is a symbolic link.
|
|
206
221
|
*/
|
package/lib/fs/readers.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* makes no blocking filesystem calls. The `debt` check in `lib/repo-health` counts any violations.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import { readFileSync } from "node:fs"
|
|
11
12
|
import { readFile } from "node:fs/promises"
|
|
12
13
|
|
|
13
14
|
import { type PathBuilderLike, resolvePath } from "path-ts"
|
|
@@ -24,7 +25,7 @@ export type { FileHandle } from "node:fs/promises"
|
|
|
24
25
|
* Read the first `byteSize` bytes of a file, or the whole file if it is smaller.
|
|
25
26
|
*
|
|
26
27
|
* @param path The file to read.
|
|
27
|
-
* @param byteSize [65536]
|
|
28
|
+
* @param byteSize [65536] The number of bytes to read.
|
|
28
29
|
* That size is enough to sniff a file's format.
|
|
29
30
|
*
|
|
30
31
|
* @returns The bytes read, as a UTF-8 string.
|
|
@@ -52,7 +53,8 @@ export async function readFileHead(path: PathBuilderLike, byteSize: number): Pro
|
|
|
52
53
|
* Three reads at three positions, where reading the whole file would mean loading
|
|
53
54
|
* a multi-gigabyte artifact to look at sixteen bytes.
|
|
54
55
|
*
|
|
55
|
-
* Returns the bytes it
|
|
56
|
+
* Returns the bytes it read.
|
|
57
|
+
* The count can be smaller than the requested size.
|
|
56
58
|
* The result is shorter than `length` at end of file.
|
|
57
59
|
*
|
|
58
60
|
* @throws Enoent when the file does not exist.
|
|
@@ -89,6 +91,20 @@ function readTarget(pathSegments: Array<PathBuilderLike | URL>): URL | string {
|
|
|
89
91
|
return resolvePath(...(pathSegments as PathBuilderLike[]))
|
|
90
92
|
}
|
|
91
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Read a local text file synchronously.
|
|
96
|
+
*
|
|
97
|
+
* The env module folds `.env` into `process.env` when it is imported, ahead of any `await`,
|
|
98
|
+
* so it cannot use {@linkcode readLocalTextFile}.
|
|
99
|
+
* Every other caller can, and should.
|
|
100
|
+
*
|
|
101
|
+
* @category Files
|
|
102
|
+
* @runtime node
|
|
103
|
+
*/
|
|
104
|
+
export function readLocalTextFileSync(...pathSegments: PathBuilderLike[]): string {
|
|
105
|
+
return readFileSync(resolvePath(...pathSegments), "utf8")
|
|
106
|
+
}
|
|
107
|
+
|
|
92
108
|
/**
|
|
93
109
|
* Read a local text file.
|
|
94
110
|
*
|
package/lib/fs/zip.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @file Zip readers for archives already in memory or stored on disk.
|
|
6
6
|
*
|
|
7
7
|
* {@link extractZip} and {@link extractSingleFileZip} take the whole archive as a `Buffer`.
|
|
8
|
-
* That suits a client that
|
|
8
|
+
* That suits a client that has downloaded one into memory (`bdc/sdk/download.ts`).
|
|
9
9
|
* It does not suit large archives because adm-zip keeps both the archive and decompressed member in memory.
|
|
10
10
|
* National address dumps under `$MAILWOMAN_DATA_ROOT` range from 0.5–2.9 GB compressed and reach 9 GB unpacked.
|
|
11
11
|
* The path-based readers stream them. Yauzl seeks the central directory through a file handle and inflates one member on demand.
|
package/lib/geocode/result.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* The geocode result: the data shape one geocoded input projects to.
|
|
7
7
|
*
|
|
8
|
-
* The schemas here
|
|
8
|
+
* The schemas here define the shapes, and each type is inferred from its schema.
|
|
9
9
|
* The `mailwoman` package computes the result and the HTTP surfaces serve it.
|
|
10
10
|
*/
|
|
11
11
|
|
|
@@ -139,13 +139,17 @@ export type AuthoritativeAssertion = z.infer<typeof AuthoritativeAssertionSchema
|
|
|
139
139
|
/**
|
|
140
140
|
* A parsed component that the answer's coordinate ignored.
|
|
141
141
|
*
|
|
142
|
-
*
|
|
143
|
-
* too far from the selected
|
|
142
|
+
* - `postcode_move_refused`: the postcode resolved too far from the selected locality.
|
|
143
|
+
* - `rooftop_outside_locality`: the address-point row lies too far from the selected
|
|
144
|
+
* locality, and no alternative locality lies near it.
|
|
145
|
+
* The coordinate is the rooftop.
|
|
146
|
+
* The hierarchy still holds the selected locality.
|
|
147
|
+
* The rooftop contradicts that locality.
|
|
144
148
|
*/
|
|
145
149
|
export const UnfollowedComponentSchema = z.object({
|
|
146
150
|
tag: ComponentTagSchema,
|
|
147
151
|
value: z.string(),
|
|
148
|
-
reason: z.
|
|
152
|
+
reason: z.enum(["postcode_move_refused", "rooftop_outside_locality"]),
|
|
149
153
|
/**
|
|
150
154
|
* The distance in kilometers that following this component would have moved the answer.
|
|
151
155
|
*/
|
package/lib/html/document.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* Narrows a document to the markup
|
|
6
|
+
* Narrows a document to the markup that holds content before downstream code parses it.
|
|
7
7
|
* An archive can wrap its payload in an envelope element. Its `<head>` title can contain a filename.
|
|
8
8
|
* Its `<script>` and `<style>` blocks do not contain document content.
|
|
9
9
|
* Downstream strategies should read the same narrowed window instead of deriving their own.
|
package/lib/html/elements.ts
CHANGED
|
@@ -88,8 +88,8 @@ export interface StreamMarkupOptions {
|
|
|
88
88
|
* The elements matching `name`, each complete, in document order.
|
|
89
89
|
*
|
|
90
90
|
* A nested element of the same name is not yielded separately: capture starts at the
|
|
91
|
-
* outermost occurrence and ends when that one closes, so one `ad:Address` arrives
|
|
92
|
-
*
|
|
91
|
+
* outermost occurrence and ends when that one closes, so one `ad:Address` arrives once
|
|
92
|
+
* whatever the number of `ad:Address` elements its own subtree contains.
|
|
93
93
|
*
|
|
94
94
|
* Several names read one document once.
|
|
95
95
|
* An INSPIRE collection writes the features an address references before the addresses
|
|
@@ -226,7 +226,7 @@ export async function* streamMarkupElements(
|
|
|
226
226
|
* A caller that buffers a whole document and yields it once would otherwise
|
|
227
227
|
* ask for a string past V8's maximum length.
|
|
228
228
|
* The decoder's state persists across the pieces, so a multi-byte character spanning
|
|
229
|
-
* a
|
|
229
|
+
* a piece boundary survives, as it does across chunks.
|
|
230
230
|
*/
|
|
231
231
|
const decodePieces = (chunk: Uint8Array): string[] => {
|
|
232
232
|
if (chunk.length <= MAX_DECODED_CHUNK) return [decoder.decode(chunk, { stream: true })]
|
package/lib/json.ts
CHANGED
|
@@ -116,7 +116,7 @@ export function parseJSONStrict<T = unknown>(input: string): T {
|
|
|
116
116
|
* because a non-array there is a schema change at the source rather than something to coerce.
|
|
117
117
|
* An empty array would read as "none", which is not what a differently-shaped value means.
|
|
118
118
|
*
|
|
119
|
-
* @param scope
|
|
119
|
+
* @param scope The reader the error message identifies, e.g. `coastal client`.
|
|
120
120
|
*/
|
|
121
121
|
export function parseJSONArray<T>(raw: string | null | undefined, scope: string): T[] {
|
|
122
122
|
if (!raw) return []
|
package/lib/layers/coverage.ts
CHANGED
|
@@ -75,7 +75,7 @@ export function designatedCoverageCells(
|
|
|
75
75
|
* writes a stronger basis without settling the footprint question, the build refuses
|
|
76
76
|
* rather than letting an absent polygon be read as a designation.
|
|
77
77
|
*
|
|
78
|
-
* @param scope
|
|
78
|
+
* @param scope The caller the refusal identifies, e.g. `coastal build`.
|
|
79
79
|
* @param limitSentence The product's own sentence saying why its coverage licenses no negative claim.
|
|
80
80
|
*/
|
|
81
81
|
export function assertNoNegativeClaim(scope: string, cells: ReadonlyArray<CoverageCell>, limitSentence: string): void {
|
|
@@ -139,7 +139,7 @@ export interface ResolutionMeasurementOptions {
|
|
|
139
139
|
resolutions: readonly number[]
|
|
140
140
|
onProgress?: (message: string) => void
|
|
141
141
|
/**
|
|
142
|
-
*
|
|
142
|
+
* The progress interval, in features.
|
|
143
143
|
*/
|
|
144
144
|
progressEvery?: number
|
|
145
145
|
}
|
|
@@ -249,7 +249,7 @@ export function areaAgreementFrom(streamed: StreamedAreaTotals, sourceM2: number
|
|
|
249
249
|
* The message includes the hole-blind total beside the nested one, because the gap between them
|
|
250
250
|
* is the diagnosis: a hole read as an exterior ring answers "inside" for every point in it.
|
|
251
251
|
*
|
|
252
|
-
* @param scope
|
|
252
|
+
* @param scope The builder the error message identifies, e.g. `coastal build`.
|
|
253
253
|
*/
|
|
254
254
|
export function assertAreaAgreement(scope: string, area: AreaAgreementReading, tolerance: number): void {
|
|
255
255
|
if (area.witness === "absent") return
|
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/docs-site.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
6
|
* Where the docs site lives, for every URL the license posture points at: the well-known key register and the
|
|
7
|
-
* `/license` page. One derivation, so a configured `MAILWOMAN_DOCS_URL` moves
|
|
7
|
+
* `/license` page. One derivation serves both, so a configured `MAILWOMAN_DOCS_URL` moves them together.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { $public } from "#env"
|
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
|
*/
|
|
@@ -124,6 +124,7 @@ export async function checkCompiledFreshness(
|
|
|
124
124
|
workspaces: readonly string[]
|
|
125
125
|
): Promise<CompiledFreshness> {
|
|
126
126
|
let newestSource: TimestampedFile | null = null
|
|
127
|
+
let newestSourceWorkspace: string | null = null
|
|
127
128
|
let newestCompiled: TimestampedFile | null = null
|
|
128
129
|
|
|
129
130
|
const root = PathBuilder.from(repoRoot)
|
|
@@ -142,6 +143,7 @@ export async function checkCompiledFreshness(
|
|
|
142
143
|
|
|
143
144
|
if (source && (!newestSource || source.mtimeMs > newestSource.mtimeMs)) {
|
|
144
145
|
newestSource = source
|
|
146
|
+
newestSourceWorkspace = workspace
|
|
145
147
|
}
|
|
146
148
|
|
|
147
149
|
if (compiled && (!newestCompiled || compiled.mtimeMs > newestCompiled.mtimeMs)) {
|
|
@@ -167,7 +169,9 @@ export async function checkCompiledFreshness(
|
|
|
167
169
|
newestCompiled,
|
|
168
170
|
reason:
|
|
169
171
|
`Compiled output is ${driftSeconds}s older than source: ${newestSource.path} was modified after ` +
|
|
170
|
-
`${newestCompiled.path}. Run \`yarn compile\` and re-run
|
|
172
|
+
`${newestCompiled.path}. Run \`yarn compile\` and re-run. When the source reverted to content ` +
|
|
173
|
+
`that is already compiled, \`tsc -b\` skips the emit and the output stays stale, so run ` +
|
|
174
|
+
`\`yarn tsc -b ${newestSourceWorkspace} --force\` instead.`,
|
|
171
175
|
}
|
|
172
176
|
}
|
|
173
177
|
|
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.
|