@mailwoman/corpus 11.5.0 → 12.0.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/builds/v0.8.22-wofrank-overlay/OVERLAY_PLAN.json +51 -0
- package/data/builds/v0.8.24-everyplace/inputs.json +35 -0
- package/data/training-configs/v8.17.0-stage1-gazetteer-v0822-s42.yaml +557 -0
- package/data/training-configs/v8.17.0-stage2-corpus-v0822-s42.yaml +1008 -0
- package/data/training-configs/v8.18.0-gazetteer-then-mixture-v0822-s42.yaml +1225 -0
- package/data/training-configs/v8.20.0-wofrank-v0822-s42.yaml +863 -0
- package/data/training-configs/v8.21.0-outcomes-v0822-s42.yaml +873 -0
- package/data/training-configs/v8.22.0-stage1-everyplace-v0824-s42.yaml +374 -0
- package/data/training-configs/v8.22.0-stage2-corpus-v0824-s42.yaml +808 -0
- package/data/training-configs/v8.22.1-stage1-everyplace-v0824-s42.yaml +376 -0
- package/data/training-configs/v8.22.1-stage2-corpus-v0824-s42.yaml +793 -0
- package/data/training-configs/v9.0.0-bytestem-v090-s42.yaml +665 -0
- package/data/training-manifests/v0.8.22-wofrank-overlay.json +9000 -0
- package/data/training-manifests/v0.8.24-everyplace-overlay.json +9000 -0
- package/data/training-manifests/v0.9.0-compact.effective.json +2556 -0
- package/data/training-manifests/v0.9.0-compact.json +9000 -0
- package/lib/adapters/wof/admin/json/adapter.ts +38 -3
- package/lib/adapters/wof/json-rows.ts +84 -5
- package/lib/adapters/wof/sample.ts +42 -6
- package/lib/build/code-hash.ts +1 -1
- package/lib/cjk/foreign-places.ts +1 -1
- package/lib/kr/adapters/localdata/permit-rows.ts +1 -1
- package/lib/parquet/schema.ts +7 -0
- package/lib/tools/anthropic/batches.ts +221 -0
- package/lib/tools/anthropic/labeling.ts +263 -0
- package/lib/tools/compact-v9.ts +872 -0
- package/lib/tools/fetch/wikidata/vital-places/entities.ts +20 -2
- package/lib/tools/fetch/wikidata/vital-places/qrank.ts +5 -4
- package/lib/tools/fragment-assay.run.ts +2 -1
- package/lib/tools/name-roles/name-roles.run.ts +296 -0
- package/lib/tools/name-roles/prompt.ts +253 -0
- package/lib/tools/overlay/deletions.ts +1 -1
- package/lib/tools/overlay/draw-weight.ts +275 -0
- package/lib/tools/place-twins/place-twins.run.ts +528 -0
- package/lib/tools/place-twins/prompt.ts +276 -0
- package/lib/tools/prominent-shapes/prominent-shapes.run.ts +420 -0
- package/lib/tools/prominent-shapes/prompt.ts +189 -0
- package/lib/tools/prominent-shapes/read-seeds.ts +286 -0
- package/lib/tools/prominent-shapes/seeds.ts +281 -0
- package/lib/tools/prominent-shapes/validate.ts +563 -0
- package/lib/training/config/admission.ts +9 -2
- package/lib/training/config/schema.ts +68 -1
- package/lib/types.ts +23 -0
- package/lib/utils/split.ts +1 -1
- package/out/adapters/wof/admin/json/adapter.d.ts +7 -0
- package/out/adapters/wof/admin/json/adapter.d.ts.map +1 -1
- package/out/adapters/wof/admin/json/adapter.js +28 -3
- package/out/adapters/wof/admin/json/adapter.js.map +1 -1
- package/out/adapters/wof/json-rows.d.ts +8 -0
- package/out/adapters/wof/json-rows.d.ts.map +1 -1
- package/out/adapters/wof/json-rows.js +56 -4
- package/out/adapters/wof/json-rows.js.map +1 -1
- package/out/adapters/wof/sample.d.ts +12 -0
- package/out/adapters/wof/sample.d.ts.map +1 -1
- package/out/adapters/wof/sample.js +37 -6
- package/out/adapters/wof/sample.js.map +1 -1
- package/out/build/code-hash.js +1 -1
- package/out/build/code-hash.js.map +1 -1
- package/out/cjk/foreign-places.js +1 -1
- package/out/cjk/foreign-places.js.map +1 -1
- package/out/kr/adapters/localdata/permit-rows.js +1 -1
- package/out/kr/adapters/localdata/permit-rows.js.map +1 -1
- package/out/parquet/schema.d.ts +6 -0
- package/out/parquet/schema.d.ts.map +1 -1
- package/out/parquet/schema.js +6 -0
- package/out/parquet/schema.js.map +1 -1
- package/out/tools/anthropic/batches.d.ts +117 -0
- package/out/tools/anthropic/batches.d.ts.map +1 -0
- package/out/tools/anthropic/batches.js +141 -0
- package/out/tools/anthropic/batches.js.map +1 -0
- package/out/tools/anthropic/labeling.d.ts +97 -0
- package/out/tools/anthropic/labeling.d.ts.map +1 -0
- package/out/tools/anthropic/labeling.js +146 -0
- package/out/tools/anthropic/labeling.js.map +1 -0
- package/out/tools/compact-v9.d.ts +117 -0
- package/out/tools/compact-v9.d.ts.map +1 -0
- package/out/tools/compact-v9.js +494 -0
- package/out/tools/compact-v9.js.map +1 -0
- package/out/tools/fetch/wikidata/vital-places/entities.d.ts +3 -0
- package/out/tools/fetch/wikidata/vital-places/entities.d.ts.map +1 -1
- package/out/tools/fetch/wikidata/vital-places/entities.js +19 -1
- package/out/tools/fetch/wikidata/vital-places/entities.js.map +1 -1
- package/out/tools/fetch/wikidata/vital-places/qrank.d.ts.map +1 -1
- package/out/tools/fetch/wikidata/vital-places/qrank.js +4 -4
- package/out/tools/fetch/wikidata/vital-places/qrank.js.map +1 -1
- package/out/tools/fragment-assay.run.js +1 -1
- package/out/tools/fragment-assay.run.js.map +1 -1
- package/out/tools/name-roles/name-roles.run.d.ts +2 -0
- package/out/tools/name-roles/name-roles.run.d.ts.map +1 -0
- package/out/tools/name-roles/name-roles.run.js +230 -0
- package/out/tools/name-roles/name-roles.run.js.map +1 -0
- package/out/tools/name-roles/prompt.d.ts +166 -0
- package/out/tools/name-roles/prompt.d.ts.map +1 -0
- package/out/tools/name-roles/prompt.js +176 -0
- package/out/tools/name-roles/prompt.js.map +1 -0
- package/out/tools/overlay/deletions.js +1 -1
- package/out/tools/overlay/deletions.js.map +1 -1
- package/out/tools/overlay/draw-weight.d.ts +86 -0
- package/out/tools/overlay/draw-weight.d.ts.map +1 -0
- package/out/tools/overlay/draw-weight.js +131 -0
- package/out/tools/overlay/draw-weight.js.map +1 -0
- package/out/tools/place-twins/place-twins.run.d.ts +2 -0
- package/out/tools/place-twins/place-twins.run.d.ts.map +1 -0
- package/out/tools/place-twins/place-twins.run.js +385 -0
- package/out/tools/place-twins/place-twins.run.js.map +1 -0
- package/out/tools/place-twins/prompt.d.ts +169 -0
- package/out/tools/place-twins/prompt.d.ts.map +1 -0
- package/out/tools/place-twins/prompt.js +183 -0
- package/out/tools/place-twins/prompt.js.map +1 -0
- package/out/tools/prominent-shapes/prominent-shapes.run.d.ts +2 -0
- package/out/tools/prominent-shapes/prominent-shapes.run.d.ts.map +1 -0
- package/out/tools/prominent-shapes/prominent-shapes.run.js +302 -0
- package/out/tools/prominent-shapes/prominent-shapes.run.js.map +1 -0
- package/out/tools/prominent-shapes/prompt.d.ts +74 -0
- package/out/tools/prominent-shapes/prompt.d.ts.map +1 -0
- package/out/tools/prominent-shapes/prompt.js +156 -0
- package/out/tools/prominent-shapes/prompt.js.map +1 -0
- package/out/tools/prominent-shapes/read-seeds.d.ts +23 -0
- package/out/tools/prominent-shapes/read-seeds.d.ts.map +1 -0
- package/out/tools/prominent-shapes/read-seeds.js +219 -0
- package/out/tools/prominent-shapes/read-seeds.js.map +1 -0
- package/out/tools/prominent-shapes/seeds.d.ts +132 -0
- package/out/tools/prominent-shapes/seeds.d.ts.map +1 -0
- package/out/tools/prominent-shapes/seeds.js +178 -0
- package/out/tools/prominent-shapes/seeds.js.map +1 -0
- package/out/tools/prominent-shapes/validate.d.ts +152 -0
- package/out/tools/prominent-shapes/validate.d.ts.map +1 -0
- package/out/tools/prominent-shapes/validate.js +389 -0
- package/out/tools/prominent-shapes/validate.js.map +1 -0
- package/out/training/config/admission.d.ts +2 -1
- package/out/training/config/admission.d.ts.map +1 -1
- package/out/training/config/admission.js +9 -2
- package/out/training/config/admission.js.map +1 -1
- package/out/training/config/schema.d.ts +276 -1
- package/out/training/config/schema.d.ts.map +1 -1
- package/out/training/config/schema.js +64 -1
- package/out/training/config/schema.js.map +1 -1
- package/out/types.d.ts +21 -0
- package/out/types.d.ts.map +1 -1
- package/out/types.js +13 -0
- package/out/types.js.map +1 -1
- package/out/utils/split.js +1 -1
- package/out/utils/split.js.map +1 -1
- package/package.json +24 -24
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @file The seed of one prominent place: the verified surfaces a query form may be written from (#3156).
|
|
6
|
+
*
|
|
7
|
+
* A seed lists every surface a form may contain, each under one slot and with the record it came from.
|
|
8
|
+
* The language model that writes the forms chooses among these surfaces and supplies none of its own,
|
|
9
|
+
* so a form's labels are the seed's.
|
|
10
|
+
*
|
|
11
|
+
* The slots follow the #3156 label policy (`prominentPlaceTag` in `#recipes/prominent/places`):
|
|
12
|
+
* a locality is a `locality` in every form, a sub-locality is a `dependent_locality` beside its parent
|
|
13
|
+
* locality, and a postal pair is a `locality` beside its parent's name as a `region`.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { foldCaseWhitespace } from "@mailwoman/normalize/fold"
|
|
17
|
+
|
|
18
|
+
import type { PlaceBand } from "#recipes/prominent/places"
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The slots a surface fills, by the letter its key starts with.
|
|
22
|
+
*/
|
|
23
|
+
export const SurfaceSlot = {
|
|
24
|
+
/**
|
|
25
|
+
* The place's own name.
|
|
26
|
+
*/
|
|
27
|
+
Name: "n",
|
|
28
|
+
/**
|
|
29
|
+
* The parent locality of a sub-locality.
|
|
30
|
+
*/
|
|
31
|
+
Parent: "p",
|
|
32
|
+
/**
|
|
33
|
+
* The region's name.
|
|
34
|
+
*/
|
|
35
|
+
Region: "r",
|
|
36
|
+
/**
|
|
37
|
+
* The region's abbreviation.
|
|
38
|
+
*/
|
|
39
|
+
RegionAbbreviation: "a",
|
|
40
|
+
/**
|
|
41
|
+
* The country.
|
|
42
|
+
*/
|
|
43
|
+
Country: "c",
|
|
44
|
+
} as const
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* One slot.
|
|
48
|
+
*/
|
|
49
|
+
export type SurfaceSlot = (typeof SurfaceSlot)[keyof typeof SurfaceSlot]
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* One surface a form may contain.
|
|
53
|
+
*/
|
|
54
|
+
export interface SeedSurface {
|
|
55
|
+
/**
|
|
56
|
+
* The slot letter and a one-based index, the key the model cites: `n1`, `c3`.
|
|
57
|
+
*/
|
|
58
|
+
key: string
|
|
59
|
+
slot: SurfaceSlot
|
|
60
|
+
text: string
|
|
61
|
+
/**
|
|
62
|
+
* The ISO 639-3 language of a WOF `names` row, or `null` for a surface recorded without one.
|
|
63
|
+
*/
|
|
64
|
+
language: string | null
|
|
65
|
+
/**
|
|
66
|
+
* The record the surface was read from, such as `wof:names:85922583:eng:preferred`.
|
|
67
|
+
*/
|
|
68
|
+
origin: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A surface before it has a key.
|
|
73
|
+
*/
|
|
74
|
+
export type SurfaceDraft = Omit<SeedSurface, "key" | "slot">
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* One prominent place and the surfaces its forms are written from.
|
|
78
|
+
*/
|
|
79
|
+
export interface ShapeSeed {
|
|
80
|
+
wof_id: number
|
|
81
|
+
country: string
|
|
82
|
+
band: PlaceBand
|
|
83
|
+
/**
|
|
84
|
+
* The place's rank within its country and band, or `null` for a capital the rank left out.
|
|
85
|
+
*/
|
|
86
|
+
rank: number | null
|
|
87
|
+
capital: boolean
|
|
88
|
+
/**
|
|
89
|
+
* The tag of the place's own span.
|
|
90
|
+
*/
|
|
91
|
+
place_tag: "locality" | "dependent_locality"
|
|
92
|
+
/**
|
|
93
|
+
* The tag of a parent span, or `null` when the seed has no parent slot.
|
|
94
|
+
*/
|
|
95
|
+
parent_tag: "locality" | "region" | null
|
|
96
|
+
surfaces: SeedSurface[]
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The reasons a prominent place gets no seed.
|
|
101
|
+
*/
|
|
102
|
+
export const SeedSkip = {
|
|
103
|
+
/**
|
|
104
|
+
* A sub-locality without a parent locality: the label policy writes it only beside one.
|
|
105
|
+
*/
|
|
106
|
+
NoParent: "sublocality_without_parent",
|
|
107
|
+
/**
|
|
108
|
+
* A sub-locality whose name equals its parent's, so every query form reads the same for both.
|
|
109
|
+
*/
|
|
110
|
+
ParentNamesake: "sublocality_named_as_parent",
|
|
111
|
+
/**
|
|
112
|
+
* Every name of the place is refused as a typed surface, so no form could cite a name.
|
|
113
|
+
*/
|
|
114
|
+
NoName: "no_typed_name",
|
|
115
|
+
} as const
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* One skip reason.
|
|
119
|
+
*/
|
|
120
|
+
export type SeedSkip = (typeof SeedSkip)[keyof typeof SeedSkip]
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* What one prominent place contributes to a seed, as read from the census and Who's On First.
|
|
124
|
+
*/
|
|
125
|
+
export interface SeedInput {
|
|
126
|
+
wof_id: number
|
|
127
|
+
country: string
|
|
128
|
+
band: PlaceBand
|
|
129
|
+
rank: number | null
|
|
130
|
+
capital: boolean
|
|
131
|
+
postal_pair: boolean
|
|
132
|
+
names: readonly SurfaceDraft[]
|
|
133
|
+
parents: readonly SurfaceDraft[]
|
|
134
|
+
regions: readonly SurfaceDraft[]
|
|
135
|
+
region_abbreviations: readonly SurfaceDraft[]
|
|
136
|
+
countries: readonly SurfaceDraft[]
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* A region abbreviation a form may write: one to three Latin letters or digits, the #3156 census's filter.
|
|
141
|
+
*/
|
|
142
|
+
function isWritableRegionAbbreviation(abbreviation: string): boolean {
|
|
143
|
+
return /^[A-Za-z0-9]{1,3}$/u.test(abbreviation)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Text that marks a name as an article title or a rendering artifact rather than a typed surface:
|
|
148
|
+
* a parenthesized qualifier (`Vaticano (disambigua)`) or a bidirectional control character.
|
|
149
|
+
*/
|
|
150
|
+
const UNTYPED_SURFACE = /[()-]/u
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The drafts with a typed, non-empty text, one per folded text, in the order given.
|
|
154
|
+
*/
|
|
155
|
+
function distinctDrafts(drafts: readonly SurfaceDraft[]): SurfaceDraft[] {
|
|
156
|
+
const seen = new Set<string>()
|
|
157
|
+
const kept: SurfaceDraft[] = []
|
|
158
|
+
|
|
159
|
+
for (const draft of drafts) {
|
|
160
|
+
const fold = foldCaseWhitespace(draft.text)
|
|
161
|
+
|
|
162
|
+
if (fold === "" || seen.has(fold) || UNTYPED_SURFACE.test(draft.text)) continue
|
|
163
|
+
|
|
164
|
+
seen.add(fold)
|
|
165
|
+
kept.push({ ...draft, text: draft.text.trim() })
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return kept
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function keyed(slot: SurfaceSlot, drafts: readonly SurfaceDraft[]): SeedSurface[] {
|
|
172
|
+
return distinctDrafts(drafts).map((draft, index) => ({ key: `${slot}${index + 1}`, slot, ...draft }))
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Builds a place's seed, or returns the reason the label policy writes no form for it.
|
|
177
|
+
*
|
|
178
|
+
* A place whose every name is refused gets no seed in either band, because every form needs one name.
|
|
179
|
+
* A locality has no parent slot.
|
|
180
|
+
*
|
|
181
|
+
* A postal pair writes its parent's name in the region slot, and keeps the region's
|
|
182
|
+
* abbreviations only when the region is that same name (`Brooklyn, NY`).
|
|
183
|
+
*/
|
|
184
|
+
export function assembleSeed(input: SeedInput): ShapeSeed | SeedSkip {
|
|
185
|
+
const names = keyed(SurfaceSlot.Name, input.names)
|
|
186
|
+
|
|
187
|
+
if (!names.length) return SeedSkip.NoName
|
|
188
|
+
|
|
189
|
+
const parents = distinctDrafts(input.parents)
|
|
190
|
+
|
|
191
|
+
const base = {
|
|
192
|
+
wof_id: input.wof_id,
|
|
193
|
+
country: input.country,
|
|
194
|
+
band: input.band,
|
|
195
|
+
rank: input.rank,
|
|
196
|
+
capital: input.capital,
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const countries = keyed(SurfaceSlot.Country, input.countries)
|
|
200
|
+
const abbreviations = input.region_abbreviations.filter((draft) => isWritableRegionAbbreviation(draft.text))
|
|
201
|
+
|
|
202
|
+
if (input.band === "locality") {
|
|
203
|
+
return {
|
|
204
|
+
...base,
|
|
205
|
+
place_tag: "locality",
|
|
206
|
+
parent_tag: null,
|
|
207
|
+
surfaces: [
|
|
208
|
+
...names,
|
|
209
|
+
...keyed(SurfaceSlot.Region, input.regions),
|
|
210
|
+
...keyed(SurfaceSlot.RegionAbbreviation, abbreviations),
|
|
211
|
+
...countries,
|
|
212
|
+
],
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!parents.length) return SeedSkip.NoParent
|
|
217
|
+
|
|
218
|
+
const nameFolds = new Set(names.map((name) => foldCaseWhitespace(name.text)))
|
|
219
|
+
|
|
220
|
+
if (parents.some((parent) => nameFolds.has(foldCaseWhitespace(parent.text)))) return SeedSkip.ParentNamesake
|
|
221
|
+
|
|
222
|
+
if (input.postal_pair) {
|
|
223
|
+
const parentFolds = new Set(parents.map((parent) => foldCaseWhitespace(parent.text)))
|
|
224
|
+
const regionIsParent = input.regions.some((region) => parentFolds.has(foldCaseWhitespace(region.text)))
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
...base,
|
|
228
|
+
place_tag: "locality",
|
|
229
|
+
parent_tag: "region",
|
|
230
|
+
surfaces: [
|
|
231
|
+
...names,
|
|
232
|
+
...keyed(SurfaceSlot.Parent, parents),
|
|
233
|
+
...(regionIsParent ? keyed(SurfaceSlot.RegionAbbreviation, abbreviations) : []),
|
|
234
|
+
...countries,
|
|
235
|
+
],
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
...base,
|
|
241
|
+
place_tag: "dependent_locality",
|
|
242
|
+
parent_tag: "locality",
|
|
243
|
+
surfaces: [
|
|
244
|
+
...names,
|
|
245
|
+
...keyed(SurfaceSlot.Parent, parents),
|
|
246
|
+
...keyed(SurfaceSlot.Region, input.regions),
|
|
247
|
+
...keyed(SurfaceSlot.RegionAbbreviation, abbreviations),
|
|
248
|
+
...countries,
|
|
249
|
+
],
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Keeps each country and band's highest-ranked `limit` seeds, and every capital.
|
|
255
|
+
*/
|
|
256
|
+
export function limitSeedsPerBand(seeds: readonly ShapeSeed[], limit: number): ShapeSeed[] {
|
|
257
|
+
return [...Map.groupBy(seeds, (seed) => `${seed.country}\u0000${seed.band}`).values()].flatMap((group) =>
|
|
258
|
+
group
|
|
259
|
+
.toSorted((a, b) => (a.rank ?? Infinity) - (b.rank ?? Infinity))
|
|
260
|
+
.filter((seed, index) => index < limit || seed.capital)
|
|
261
|
+
)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Groups seeds into requests of at most `size` places, each of one country,
|
|
266
|
+
* so a request lists its country's surfaces once.
|
|
267
|
+
*/
|
|
268
|
+
export function chunkSeedsByCountry(seeds: readonly ShapeSeed[], size: number): ShapeSeed[][] {
|
|
269
|
+
const chunks: ShapeSeed[][] = []
|
|
270
|
+
const byCountry = Map.groupBy(seeds, (seed) => seed.country)
|
|
271
|
+
|
|
272
|
+
for (const country of [...byCountry.keys()].toSorted()) {
|
|
273
|
+
const group = byCountry.get(country)!
|
|
274
|
+
|
|
275
|
+
for (let start = 0; start < group.length; start += size) {
|
|
276
|
+
chunks.push(group.slice(start, start + size))
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return chunks
|
|
281
|
+
}
|