@mailwoman/core 7.1.0 → 7.2.1
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/api/APIClient.ts +175 -0
- package/api/headless.ts +23 -0
- package/api/index.ts +11 -0
- package/api/responses.ts +135 -0
- package/coarse-placer/coarse-placer.ts +300 -0
- package/coarse-placer/featurize.ts +171 -0
- package/coarse-placer/tools/build-dataset.ts +223 -0
- package/coarse-placer/tools/build-outlier-exposure.ts +172 -0
- package/coarse-placer/tools/build-outlier-latin.ts +200 -0
- package/coarse-placer/tools/build-outlier-oa.ts +231 -0
- package/coarse-placer/tools/eval-latin-offmap.ts +140 -0
- package/coarse-placer/tools/eval-openset.ts +519 -0
- package/coarse-placer/tools/eval-quant-compare.ts +151 -0
- package/coarse-placer/tools/eval.ts +187 -0
- package/coarse-placer/tools/fnv-hash.ts +24 -0
- package/coarse-placer/tools/index.ts +23 -0
- package/coarse-placer/tools/probe-frontier.ts +216 -0
- package/coarse-placer/tools/quantize.ts +116 -0
- package/coarse-placer/tools/train.ts +244 -0
- package/collections.ts +134 -0
- package/db/schema.ts +21 -0
- package/decoder/build-tree.ts +228 -0
- package/decoder/calibration.ts +101 -0
- package/decoder/containment.ts +87 -0
- package/decoder/index.ts +17 -0
- package/decoder/proposals-to-tree.ts +83 -0
- package/decoder/resolve-proposal-overlaps.ts +79 -0
- package/decoder/serialize-json.ts +70 -0
- package/decoder/serialize-tuples.ts +61 -0
- package/decoder/serialize-xml.ts +209 -0
- package/decoder/types.ts +159 -0
- package/decoder/unknown-spans.ts +103 -0
- package/decoder/validate-tree.ts +100 -0
- package/env/index.ts +42 -0
- package/env/load.ts +14 -0
- package/env/paths.ts +40 -0
- package/env/schema.ts +125 -0
- package/errors/index.ts +9 -0
- package/errors/schema.ts +155 -0
- package/fs/node.ts +38 -0
- package/identifiers.ts +58 -0
- package/index.ts +13 -0
- package/kysley/adapter.ts +29 -0
- package/kysley/client.ts +30 -0
- package/kysley/dialect-config.ts +30 -0
- package/kysley/dialect.ts +67 -0
- package/kysley/driver.ts +175 -0
- package/layers/index.ts +12 -0
- package/layers/manifest.ts +154 -0
- package/layers/schema.ts +105 -0
- package/lifecycle/ServiceSymbol.ts +95 -0
- package/lifecycle/index.ts +11 -0
- package/lifecycle/lru-cache.ts +44 -0
- package/lifecycle/services.ts +322 -0
- package/locale/index.ts +9 -0
- package/locale/locale.ts +49 -0
- package/locale/profiles/en-us.ts +69 -0
- package/locale/profiles/fr-fr.ts +75 -0
- package/locale/profiles/index.ts +9 -0
- package/locale/profiles/ja-jp.ts +33 -0
- package/locale/registry.ts +68 -0
- package/logging/index.ts +8 -0
- package/logging/shared.ts +145 -0
- package/logging/utils.ts +46 -0
- package/objects.ts +211 -0
- package/out/layers/index.d.ts +12 -0
- package/out/layers/index.d.ts.map +1 -0
- package/out/layers/index.js +12 -0
- package/out/layers/index.js.map +1 -0
- package/out/layers/manifest.d.ts +64 -0
- package/out/layers/manifest.d.ts.map +1 -0
- package/out/layers/manifest.js +102 -0
- package/out/layers/manifest.js.map +1 -0
- package/out/layers/schema.d.ts +72 -0
- package/out/layers/schema.d.ts.map +1 -0
- package/out/layers/schema.js +61 -0
- package/out/layers/schema.js.map +1 -0
- package/out/pipeline/index.d.ts +1 -1
- package/out/pipeline/index.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.js +27 -0
- package/out/pipeline/runtime-pipeline.js.map +1 -1
- package/out/pipeline/types.d.ts +74 -4
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js.map +1 -1
- package/package.json +21 -21
- package/pipeline/index.ts +46 -0
- package/pipeline/reconcile-lookups.ts +108 -0
- package/pipeline/reconcile.ts +542 -0
- package/pipeline/runtime-pipeline.ts +732 -0
- package/pipeline/span-logit-aggregation.ts +151 -0
- package/pipeline/span-proposer.ts +587 -0
- package/pipeline/types.ts +348 -0
- package/policy/defaults.ts +35 -0
- package/policy/index.ts +10 -0
- package/policy/policy.ts +60 -0
- package/policy/proposal-collection.ts +64 -0
- package/policy/registry.ts +149 -0
- package/resolver/index.ts +29 -0
- package/resolver/types.ts +584 -0
- package/resources/LocaleIndex.ts +124 -0
- package/resources/ResourceMapCache.ts +126 -0
- package/resources/collections.ts +93 -0
- package/resources/debugging.ts +19 -0
- package/resources/git.ts +54 -0
- package/resources/index.ts +17 -0
- package/resources/languages/index.ts +49 -0
- package/resources/languages/types.gen.ts +1368 -0
- package/resources/libaddressinput.ts +105 -0
- package/resources/libpostal.ts +182 -0
- package/resources/locale.ts +23 -0
- package/resources/set.ts +179 -0
- package/resources/whosonfirst/DataSourceCache.ts +72 -0
- package/resources/whosonfirst/PlacetypeDataSource.ts +199 -0
- package/resources/whosonfirst/index.ts +10 -0
- package/resources/whosonfirst/loader.ts +157 -0
- package/resources/whosonfirst/placetypes/Placetype.ts +438 -0
- package/resources/whosonfirst/placetypes/admin.ts +173 -0
- package/resources/whosonfirst/placetypes/definition.ts +135 -0
- package/resources/whosonfirst/placetypes/graph.ts +0 -0
- package/resources/whosonfirst/placetypes/index.ts +12 -0
- package/resources/whosonfirst/placetypes/mermaid.ts +168 -0
- package/resources/whosonfirst/placetypes/tree.ts +46 -0
- package/routing/index.ts +208 -0
- package/scripting/index.ts +40 -0
- package/scripting/utils/index.ts +106 -0
- package/tokenization/Graph.ts +50 -0
- package/tokenization/Span.ts +297 -0
- package/tokenization/index.ts +9 -0
- package/tokenization/normalizer.ts +123 -0
- package/tools/download-libpostal-resources.ts +98 -0
- package/tools/download-ssl-address.ts +99 -0
- package/tools/generate-language-types.ts +194 -0
- package/tools/index.ts +13 -0
- package/types/Classification.ts +211 -0
- package/types/classifier.ts +133 -0
- package/types/component.ts +75 -0
- package/types/index.ts +10 -0
- package/types/mapping.ts +81 -0
- package/utils/data-root.ts +56 -0
- package/utils/hash.ts +27 -0
- package/utils/index.ts +14 -0
- package/utils/jsonl.ts +43 -0
- package/utils/python-json.ts +105 -0
- package/utils/python-random.ts +90 -0
- package/utils/repo.ts +118 -0
- package/utils/sealed-db.ts +85 -0
- package/utils/stats.ts +32 -0
- package/vitest.config.ts +53 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Utilities for creating branded nominal types.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { ResourceError } from "../errors/schema.ts"
|
|
10
|
+
import { ConsoleLogger } from "../logging/index.ts"
|
|
11
|
+
import { ServiceSymbol } from "./ServiceSymbol.ts"
|
|
12
|
+
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
14
|
+
|
|
15
|
+
//#region Asynchronous
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Type definition for a class which implements the AsyncDisposable interface.
|
|
19
|
+
*
|
|
20
|
+
* @category Utilities
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export type ServiceConstructor<T> = new (...args: any[]) => T & AsyncDisposable
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Type-predicate to determine if a given input is a ServiceConstructor, i.e. a function which is a constructor for a
|
|
27
|
+
* class which implements the AsyncDisposable interface.
|
|
28
|
+
*/
|
|
29
|
+
export function isServiceConstructor<T>(input: unknown): input is ServiceConstructor<T> {
|
|
30
|
+
if (typeof input !== "function") return false
|
|
31
|
+
|
|
32
|
+
if (!input.prototype || typeof input.prototype !== "object") return false
|
|
33
|
+
|
|
34
|
+
return Object.hasOwn(input.prototype, Symbol.asyncDispose) || Object.hasOwn(input.prototype, ServiceSymbol.asyncInit)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
|
|
39
|
+
//#region Service Registry
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Stateful context for a service registry.
|
|
43
|
+
*
|
|
44
|
+
* This is used to provide a context for services during resolution.
|
|
45
|
+
*/
|
|
46
|
+
export interface ServiceRegistryContext {
|
|
47
|
+
abortController: AbortController
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Type definition for a function which returns an instance which implements the AsyncDisposable interface.
|
|
52
|
+
*
|
|
53
|
+
* @category Utilities
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export type ServiceCallback<T extends AsyncDisposable> = {
|
|
57
|
+
(context: ServiceRegistryContext): Promise<T> | T
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type ServiceResolver<T extends AsyncDisposable = AsyncDisposable> =
|
|
61
|
+
| T
|
|
62
|
+
| ServiceCallback<T>
|
|
63
|
+
| ServiceConstructor<T>
|
|
64
|
+
|
|
65
|
+
const kInstance = Symbol.for("ServiceInstance")
|
|
66
|
+
const kResolver = Symbol.for("ServiceResolver")
|
|
67
|
+
const kRegistryMap = Symbol.for("ServiceRepositoryMap")
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Given a service which may not yet be resolved, intercept any method calls and resolve the service before invoking the
|
|
71
|
+
* method.
|
|
72
|
+
*
|
|
73
|
+
* @category Services
|
|
74
|
+
*/
|
|
75
|
+
export type ServiceMethodResolver<T> = {
|
|
76
|
+
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<Awaited<R>> : T[K]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Promise-like wrapper for asynchronous services.
|
|
81
|
+
*
|
|
82
|
+
* @see {@linkcode ServiceRepository} for usage.
|
|
83
|
+
*/
|
|
84
|
+
export class Service<T extends AsyncDisposable = AsyncDisposable> implements PromiseLike<T>, AsyncDisposable {
|
|
85
|
+
/**
|
|
86
|
+
* Instance of the service.
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
public [kInstance]: T | null = null
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Resolver for the service.
|
|
94
|
+
*
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
public [kResolver]?: ServiceResolver<T>
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Context for the parent service registry.
|
|
101
|
+
*/
|
|
102
|
+
public readonly context: ServiceRegistryContext
|
|
103
|
+
|
|
104
|
+
protected constructor(resolver: ServiceResolver<T>) {
|
|
105
|
+
this[kResolver] = resolver
|
|
106
|
+
|
|
107
|
+
this.context = {
|
|
108
|
+
abortController: ServiceRepository.abortController,
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Given an instance of a service, attach it to the resolver.
|
|
114
|
+
*
|
|
115
|
+
* This can be used to attach a service that was created outside of the resolver, such as when a resolver is defined
|
|
116
|
+
* from a TypeScript interface.
|
|
117
|
+
*
|
|
118
|
+
* @internal
|
|
119
|
+
*/
|
|
120
|
+
public attach(service: T): void {
|
|
121
|
+
this[kInstance] = service
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Resolve the service instance.
|
|
126
|
+
*
|
|
127
|
+
* This method is called implicitly when the service is awaited.
|
|
128
|
+
*/
|
|
129
|
+
protected async resolve(): Promise<T> {
|
|
130
|
+
if (this[kInstance]) return this[kInstance]
|
|
131
|
+
|
|
132
|
+
if (!this[kResolver])
|
|
133
|
+
throw ResourceError.from(
|
|
134
|
+
500,
|
|
135
|
+
"Cannot resolve service without a resolver. Did you mean to call `attach` before calling `resolve`?"
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
if (typeof this[kResolver] === "function") {
|
|
139
|
+
if (isServiceConstructor(this[kResolver])) {
|
|
140
|
+
this[kInstance] = new this[kResolver]()
|
|
141
|
+
|
|
142
|
+
return this[kInstance]
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const nextInstance = await this[kResolver](this.context)
|
|
146
|
+
|
|
147
|
+
if (ServiceSymbol.isAsyncInitializable(nextInstance)) {
|
|
148
|
+
await nextInstance[ServiceSymbol.asyncInit]()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
this[kInstance] = nextInstance
|
|
152
|
+
|
|
153
|
+
return this[kInstance]
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (typeof this[kResolver] === "object") {
|
|
157
|
+
const nextInstance = this[kResolver]
|
|
158
|
+
|
|
159
|
+
if (ServiceSymbol.isAsyncInitializable(nextInstance)) {
|
|
160
|
+
await nextInstance[ServiceSymbol.asyncInit]()
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this[kInstance] = nextInstance
|
|
164
|
+
|
|
165
|
+
return this[kInstance]
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
throw ResourceError.from(500, `Invalid resolver type. ${this[kResolver]}`)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Resolve the service instance. Called implicitly when the service is awaited.
|
|
173
|
+
*/
|
|
174
|
+
// oxlint-disable-next-line unicorn/no-thenable -- intentional: a Service is awaitable by design (the await resolves the instance)
|
|
175
|
+
public then<TResult1 = T, TResult2 = never>(
|
|
176
|
+
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,
|
|
177
|
+
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined
|
|
178
|
+
): Promise<TResult1 | TResult2> {
|
|
179
|
+
return this.resolve()
|
|
180
|
+
.then((instance) => {
|
|
181
|
+
if (!this[kResolver]) {
|
|
182
|
+
throw ResourceError.from(500, "Service resolver was disposed before service was resolved.")
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
ServiceRepository[kRegistryMap].set(this[kResolver], this)
|
|
186
|
+
|
|
187
|
+
return instance
|
|
188
|
+
})
|
|
189
|
+
.then(onfulfilled, onrejected)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public async [Symbol.asyncDispose](): Promise<void> {
|
|
193
|
+
if (!this[kInstance]) {
|
|
194
|
+
ConsoleLogger.warn("Attempted to dispose a service resolver without a service!")
|
|
195
|
+
|
|
196
|
+
return
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (typeof this[kInstance][Symbol.asyncDispose] !== "function") {
|
|
200
|
+
ConsoleLogger.warn("Attempted to dispose a service resolver without a disposable service!")
|
|
201
|
+
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
await this[kInstance][Symbol.asyncDispose]()
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Service repository for managing asynchronous services.
|
|
211
|
+
*
|
|
212
|
+
* @singleton
|
|
213
|
+
*/
|
|
214
|
+
export class ServiceRepository extends Service<AsyncDisposable> {
|
|
215
|
+
static readonly [kRegistryMap] = new Map<ServiceResolver<any>, Service<any>>()
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Abort controller for the service repository.
|
|
219
|
+
*/
|
|
220
|
+
static readonly abortController = new AbortController()
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Inspect the current state of the service registry.
|
|
224
|
+
*/
|
|
225
|
+
static inspect(): Service<any>[] {
|
|
226
|
+
const services = [...this[kRegistryMap].values()].reverse()
|
|
227
|
+
|
|
228
|
+
return services
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Dispose of all services in the registry.
|
|
233
|
+
*/
|
|
234
|
+
static async [Symbol.asyncDispose](): Promise<void> {
|
|
235
|
+
const services = ServiceRepository.inspect()
|
|
236
|
+
|
|
237
|
+
ConsoleLogger.debug(`🚮 Disposing ${services.length} services...`)
|
|
238
|
+
|
|
239
|
+
for (const service of services) {
|
|
240
|
+
const label = String(service[kInstance])
|
|
241
|
+
ConsoleLogger.debug(`[${label}] Disposing...`)
|
|
242
|
+
|
|
243
|
+
const marked = ServiceSymbol.markAsDisposed(service[kInstance])
|
|
244
|
+
|
|
245
|
+
if (!marked) continue
|
|
246
|
+
|
|
247
|
+
await service[Symbol.asyncDispose]()
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
this[kRegistryMap].clear()
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Dispose of all services in the registry.
|
|
255
|
+
*/
|
|
256
|
+
static dispose(): Promise<void> {
|
|
257
|
+
return this[Symbol.asyncDispose]()
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Register a pre-initialized service with the service repository.
|
|
262
|
+
*
|
|
263
|
+
* @param service - An instance of a service.
|
|
264
|
+
*/
|
|
265
|
+
static register<T extends AsyncDisposable>(service: T): Service<T> & ServiceMethodResolver<T>
|
|
266
|
+
/**
|
|
267
|
+
* Register a service resolver with the service repository.
|
|
268
|
+
*
|
|
269
|
+
* @param serviceCallback - A callback which returns a service instance.
|
|
270
|
+
*/
|
|
271
|
+
static register<T extends AsyncDisposable>(serviceCallback: ServiceCallback<T>): Service<T> & ServiceMethodResolver<T>
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Register a service constructor with the service repository.
|
|
275
|
+
*
|
|
276
|
+
* @param ServiceConstructor - A constructor which returns a service instance.
|
|
277
|
+
*/
|
|
278
|
+
static register<T extends AsyncDisposable>(
|
|
279
|
+
ServiceConstructor: ServiceConstructor<T>
|
|
280
|
+
): Service<T> & ServiceMethodResolver<T>
|
|
281
|
+
/**
|
|
282
|
+
* Register a service with the service repository.
|
|
283
|
+
*
|
|
284
|
+
* @param resolver - A service resolver, instance, or constructor.
|
|
285
|
+
*/
|
|
286
|
+
static register<T extends AsyncDisposable>(resolver: ServiceResolver<T>): Service<T> & ServiceMethodResolver<T>
|
|
287
|
+
static register<T extends AsyncDisposable>(resolver: ServiceResolver<T>): Service<T> & ServiceMethodResolver<T> {
|
|
288
|
+
const service = new Service<T>(resolver)
|
|
289
|
+
|
|
290
|
+
const serviceMethodResolver = new Proxy(service as Service<T> & T, {
|
|
291
|
+
get(target, prop) {
|
|
292
|
+
if (prop in target) {
|
|
293
|
+
return (target as any)[prop]
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return async (...args: any[]) => {
|
|
297
|
+
const instance = (await target) as T
|
|
298
|
+
|
|
299
|
+
if (typeof (instance as any)[prop] === "function") {
|
|
300
|
+
return (instance as any)[prop](...args)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return (instance as any)[prop]
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
308
|
+
return "ServiceMethodResolver"
|
|
309
|
+
},
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
return serviceMethodResolver as Service<T> & ServiceMethodResolver<T>
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
constructor() {
|
|
316
|
+
if (new.target === ServiceRepository) {
|
|
317
|
+
throw new TypeError("Cannot instantiate static class `ServiceRepository`.")
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
super(null as never)
|
|
321
|
+
}
|
|
322
|
+
}
|
package/locale/index.ts
ADDED
package/locale/locale.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Locale-profile types (per #6 §LocaleProfile). A `LocaleProfile` declares everything
|
|
7
|
+
* locale-specific about classification: which weights package (if any) backs the neural
|
|
8
|
+
* classifier, which rule classifier IDs are active, which `ComponentTag`s the locale actually
|
|
9
|
+
* uses, and any per-component policy overrides.
|
|
10
|
+
*
|
|
11
|
+
* The classifier IDs in `ruleClassifiers` are the stable `ProposalClassifier.id` values that
|
|
12
|
+
* `wrapLegacyClassifier` assigns when the legacy classifier registry lands (see the Phase 0
|
|
13
|
+
* task-3 follow-up in DECISIONS.md).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { ComponentTag } from "@mailwoman/core/types"
|
|
17
|
+
|
|
18
|
+
import type { ClassifierPolicy } from "../policy/policy.ts"
|
|
19
|
+
|
|
20
|
+
export interface LocaleProfile {
|
|
21
|
+
/** BCP-47 locale tag (e.g. `"en-US"`, `"fr-FR"`, `"ja-JP"`). */
|
|
22
|
+
locale: string
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Npm package providing ONNX weights and tokenizer for the neural classifier in this locale. Optional — Phase 0 ships
|
|
26
|
+
* no weights; a locale without a weights package runs rule-only.
|
|
27
|
+
*/
|
|
28
|
+
weightsPackage?: string
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Rule classifier IDs active in this locale. Stable identifiers declared by `ProposalClassifier.id`. An empty list
|
|
32
|
+
* means the locale relies entirely on neural inference.
|
|
33
|
+
*/
|
|
34
|
+
ruleClassifiers: string[]
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Components this locale uses. Must be a subset of `COMPONENT_TAGS`. The system validates this at registration.
|
|
38
|
+
*/
|
|
39
|
+
componentsSupported: ComponentTag[]
|
|
40
|
+
|
|
41
|
+
/** Per-component policy overrides for this locale. */
|
|
42
|
+
policy: ClassifierPolicy[]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface LocaleRegistry {
|
|
46
|
+
register(profile: LocaleProfile): void
|
|
47
|
+
get(locale: string): LocaleProfile | undefined
|
|
48
|
+
list(): LocaleProfile[]
|
|
49
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* En-US locale profile (per Phase 0 task 5). Lists the rule classifier IDs the legacy registry will
|
|
7
|
+
* assign and the `ComponentTag`s the US locale actually uses. No `weightsPackage` is set in Phase
|
|
8
|
+
* 0 — neural weights ship in Phase 3.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { LocaleProfile } from "../locale.ts"
|
|
12
|
+
|
|
13
|
+
export const enUS: LocaleProfile = {
|
|
14
|
+
locale: "en-US",
|
|
15
|
+
ruleClassifiers: [
|
|
16
|
+
"alpha_numeric",
|
|
17
|
+
"chain",
|
|
18
|
+
"compound_level",
|
|
19
|
+
"compound_street",
|
|
20
|
+
"compound_unit_designator",
|
|
21
|
+
"directional",
|
|
22
|
+
"given_name",
|
|
23
|
+
"house_number",
|
|
24
|
+
"intersection",
|
|
25
|
+
"level",
|
|
26
|
+
"level_designator",
|
|
27
|
+
"middle_initial",
|
|
28
|
+
"ordinal",
|
|
29
|
+
"person",
|
|
30
|
+
"personal_suffix",
|
|
31
|
+
"personal_title",
|
|
32
|
+
"place",
|
|
33
|
+
"postcode",
|
|
34
|
+
"road_type",
|
|
35
|
+
"stop_word",
|
|
36
|
+
"street_prefix",
|
|
37
|
+
"street_proper_name",
|
|
38
|
+
"street_suffix",
|
|
39
|
+
"surname",
|
|
40
|
+
"token_position",
|
|
41
|
+
"toponym",
|
|
42
|
+
"unit",
|
|
43
|
+
"unit_designator",
|
|
44
|
+
"whos_on_first",
|
|
45
|
+
"composite_intersection",
|
|
46
|
+
"composite_person",
|
|
47
|
+
"composite_street",
|
|
48
|
+
"composite_street_name",
|
|
49
|
+
"composite_venue",
|
|
50
|
+
"subdivision",
|
|
51
|
+
],
|
|
52
|
+
componentsSupported: [
|
|
53
|
+
"country",
|
|
54
|
+
"region",
|
|
55
|
+
"locality",
|
|
56
|
+
"postcode",
|
|
57
|
+
"house_number",
|
|
58
|
+
"street",
|
|
59
|
+
"street_prefix",
|
|
60
|
+
"street_suffix",
|
|
61
|
+
"unit",
|
|
62
|
+
"venue",
|
|
63
|
+
"attention",
|
|
64
|
+
"po_box",
|
|
65
|
+
"intersection_a",
|
|
66
|
+
"intersection_b",
|
|
67
|
+
],
|
|
68
|
+
policy: [],
|
|
69
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Fr-FR locale profile (per Phase 0 task 5). Uses the same rule classifier set as en-US for
|
|
7
|
+
* locale-agnostic primitives, with the French-specific component set: cedex (postal routing),
|
|
8
|
+
* street_prefix_particle (de la / du / des), and dependent_locality (arrondissement). The
|
|
9
|
+
* `central_european_street_name` classifier lives in the registry for FR / DE / etc. and is
|
|
10
|
+
* included here.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { LocaleProfile } from "../locale.ts"
|
|
14
|
+
|
|
15
|
+
export const frFR: LocaleProfile = {
|
|
16
|
+
locale: "fr-FR",
|
|
17
|
+
ruleClassifiers: [
|
|
18
|
+
"alpha_numeric",
|
|
19
|
+
"central_european_street_name",
|
|
20
|
+
"chain",
|
|
21
|
+
"compound_level",
|
|
22
|
+
"compound_street",
|
|
23
|
+
"compound_unit_designator",
|
|
24
|
+
"directional",
|
|
25
|
+
"given_name",
|
|
26
|
+
"house_number",
|
|
27
|
+
"intersection",
|
|
28
|
+
"level",
|
|
29
|
+
"level_designator",
|
|
30
|
+
"middle_initial",
|
|
31
|
+
"ordinal",
|
|
32
|
+
"person",
|
|
33
|
+
"personal_suffix",
|
|
34
|
+
"personal_title",
|
|
35
|
+
"place",
|
|
36
|
+
"postcode",
|
|
37
|
+
"road_type",
|
|
38
|
+
"stop_word",
|
|
39
|
+
"street_prefix",
|
|
40
|
+
"street_proper_name",
|
|
41
|
+
"street_suffix",
|
|
42
|
+
"surname",
|
|
43
|
+
"token_position",
|
|
44
|
+
"toponym",
|
|
45
|
+
"unit",
|
|
46
|
+
"unit_designator",
|
|
47
|
+
"whos_on_first",
|
|
48
|
+
"composite_intersection",
|
|
49
|
+
"composite_person",
|
|
50
|
+
"composite_street",
|
|
51
|
+
"composite_street_name",
|
|
52
|
+
"composite_venue",
|
|
53
|
+
"subdivision",
|
|
54
|
+
],
|
|
55
|
+
componentsSupported: [
|
|
56
|
+
"country",
|
|
57
|
+
"region",
|
|
58
|
+
"locality",
|
|
59
|
+
"postcode",
|
|
60
|
+
"house_number",
|
|
61
|
+
"street",
|
|
62
|
+
"street_prefix",
|
|
63
|
+
"street_prefix_particle",
|
|
64
|
+
"street_suffix",
|
|
65
|
+
"unit",
|
|
66
|
+
"venue",
|
|
67
|
+
"attention",
|
|
68
|
+
"po_box",
|
|
69
|
+
"intersection_a",
|
|
70
|
+
"intersection_b",
|
|
71
|
+
"cedex",
|
|
72
|
+
"dependent_locality",
|
|
73
|
+
],
|
|
74
|
+
policy: [],
|
|
75
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Ja-JP locale profile, used in Phase 0 §8 for the forward-compat sanity check (#8 task 8): does
|
|
7
|
+
* the core abstraction accept a locale that omits `street` and `house_number` entirely without
|
|
8
|
+
* throwing or tripping a type assertion? If this profile registers cleanly today, Phase 6 (Japan)
|
|
9
|
+
* does not need a core refactor.
|
|
10
|
+
*
|
|
11
|
+
* Note: no rule classifiers are listed because the JP profile is neural-only in Phase 6. The rule
|
|
12
|
+
* pipeline does not produce Japanese-specific tags; declaring an empty list here verifies the
|
|
13
|
+
* system does not assume there are rule classifiers for every locale.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { LocaleProfile } from "../locale.ts"
|
|
17
|
+
|
|
18
|
+
export const jaJP: LocaleProfile = {
|
|
19
|
+
locale: "ja-JP",
|
|
20
|
+
ruleClassifiers: [],
|
|
21
|
+
componentsSupported: [
|
|
22
|
+
"country",
|
|
23
|
+
"postcode",
|
|
24
|
+
"prefecture",
|
|
25
|
+
"municipality",
|
|
26
|
+
"district",
|
|
27
|
+
"block",
|
|
28
|
+
"sub_block",
|
|
29
|
+
"building_number",
|
|
30
|
+
"building_name",
|
|
31
|
+
],
|
|
32
|
+
policy: [],
|
|
33
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* In-memory `LocaleRegistry`. Validates that every `LocaleProfile.componentsSupported` entry is a
|
|
7
|
+
* known `ComponentTag`, and that each policy override targets a component inside
|
|
8
|
+
* `componentsSupported`. Fails loudly at registration when either invariant is broken (#6
|
|
9
|
+
* §LocaleProfile validation rule).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { COMPONENT_TAGS, type ComponentTag } from "@mailwoman/core/types"
|
|
13
|
+
|
|
14
|
+
import type { LocaleProfile, LocaleRegistry } from "./locale.ts"
|
|
15
|
+
|
|
16
|
+
const COMPONENT_TAG_SET = new Set<ComponentTag>(COMPONENT_TAGS)
|
|
17
|
+
|
|
18
|
+
export class InMemoryLocaleRegistry implements LocaleRegistry {
|
|
19
|
+
#profiles = new Map<string, LocaleProfile>()
|
|
20
|
+
|
|
21
|
+
register(profile: LocaleProfile): void {
|
|
22
|
+
assertValidProfile(profile)
|
|
23
|
+
this.#profiles.set(profile.locale, profile)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get(locale: string): LocaleProfile | undefined {
|
|
27
|
+
return this.#profiles.get(locale)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
list(): LocaleProfile[] {
|
|
31
|
+
return Array.from(this.#profiles.values())
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Remove a locale. No-op if not present. */
|
|
35
|
+
unregister(locale: string): void {
|
|
36
|
+
this.#profiles.delete(locale)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function assertValidProfile(profile: LocaleProfile): void {
|
|
41
|
+
if (!profile.locale) {
|
|
42
|
+
throw new TypeError("LocaleProfile.locale must be a non-empty BCP-47 tag")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const supported = new Set<ComponentTag>(profile.componentsSupported)
|
|
46
|
+
|
|
47
|
+
for (const tag of supported) {
|
|
48
|
+
if (!COMPONENT_TAG_SET.has(tag)) {
|
|
49
|
+
throw new RangeError(
|
|
50
|
+
`LocaleProfile ${profile.locale}: componentsSupported contains unknown ComponentTag ${JSON.stringify(tag)}`
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (const policy of profile.policy) {
|
|
56
|
+
if (!COMPONENT_TAG_SET.has(policy.component)) {
|
|
57
|
+
throw new RangeError(
|
|
58
|
+
`LocaleProfile ${profile.locale}: policy targets unknown ComponentTag ${JSON.stringify(policy.component)}`
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!supported.has(policy.component)) {
|
|
63
|
+
throw new RangeError(
|
|
64
|
+
`LocaleProfile ${profile.locale}: policy targets ${policy.component} which is not in componentsSupported`
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|