@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.
Files changed (144) hide show
  1. package/data/builds/v0.8.22-wofrank-overlay/OVERLAY_PLAN.json +51 -0
  2. package/data/builds/v0.8.24-everyplace/inputs.json +35 -0
  3. package/data/training-configs/v8.17.0-stage1-gazetteer-v0822-s42.yaml +557 -0
  4. package/data/training-configs/v8.17.0-stage2-corpus-v0822-s42.yaml +1008 -0
  5. package/data/training-configs/v8.18.0-gazetteer-then-mixture-v0822-s42.yaml +1225 -0
  6. package/data/training-configs/v8.20.0-wofrank-v0822-s42.yaml +863 -0
  7. package/data/training-configs/v8.21.0-outcomes-v0822-s42.yaml +873 -0
  8. package/data/training-configs/v8.22.0-stage1-everyplace-v0824-s42.yaml +374 -0
  9. package/data/training-configs/v8.22.0-stage2-corpus-v0824-s42.yaml +808 -0
  10. package/data/training-configs/v8.22.1-stage1-everyplace-v0824-s42.yaml +376 -0
  11. package/data/training-configs/v8.22.1-stage2-corpus-v0824-s42.yaml +793 -0
  12. package/data/training-configs/v9.0.0-bytestem-v090-s42.yaml +665 -0
  13. package/data/training-manifests/v0.8.22-wofrank-overlay.json +9000 -0
  14. package/data/training-manifests/v0.8.24-everyplace-overlay.json +9000 -0
  15. package/data/training-manifests/v0.9.0-compact.effective.json +2556 -0
  16. package/data/training-manifests/v0.9.0-compact.json +9000 -0
  17. package/lib/adapters/wof/admin/json/adapter.ts +38 -3
  18. package/lib/adapters/wof/json-rows.ts +84 -5
  19. package/lib/adapters/wof/sample.ts +42 -6
  20. package/lib/build/code-hash.ts +1 -1
  21. package/lib/cjk/foreign-places.ts +1 -1
  22. package/lib/kr/adapters/localdata/permit-rows.ts +1 -1
  23. package/lib/parquet/schema.ts +7 -0
  24. package/lib/tools/anthropic/batches.ts +221 -0
  25. package/lib/tools/anthropic/labeling.ts +263 -0
  26. package/lib/tools/compact-v9.ts +872 -0
  27. package/lib/tools/fetch/wikidata/vital-places/entities.ts +20 -2
  28. package/lib/tools/fetch/wikidata/vital-places/qrank.ts +5 -4
  29. package/lib/tools/fragment-assay.run.ts +2 -1
  30. package/lib/tools/name-roles/name-roles.run.ts +296 -0
  31. package/lib/tools/name-roles/prompt.ts +253 -0
  32. package/lib/tools/overlay/deletions.ts +1 -1
  33. package/lib/tools/overlay/draw-weight.ts +275 -0
  34. package/lib/tools/place-twins/place-twins.run.ts +528 -0
  35. package/lib/tools/place-twins/prompt.ts +276 -0
  36. package/lib/tools/prominent-shapes/prominent-shapes.run.ts +420 -0
  37. package/lib/tools/prominent-shapes/prompt.ts +189 -0
  38. package/lib/tools/prominent-shapes/read-seeds.ts +286 -0
  39. package/lib/tools/prominent-shapes/seeds.ts +281 -0
  40. package/lib/tools/prominent-shapes/validate.ts +563 -0
  41. package/lib/training/config/admission.ts +9 -2
  42. package/lib/training/config/schema.ts +68 -1
  43. package/lib/types.ts +23 -0
  44. package/lib/utils/split.ts +1 -1
  45. package/out/adapters/wof/admin/json/adapter.d.ts +7 -0
  46. package/out/adapters/wof/admin/json/adapter.d.ts.map +1 -1
  47. package/out/adapters/wof/admin/json/adapter.js +28 -3
  48. package/out/adapters/wof/admin/json/adapter.js.map +1 -1
  49. package/out/adapters/wof/json-rows.d.ts +8 -0
  50. package/out/adapters/wof/json-rows.d.ts.map +1 -1
  51. package/out/adapters/wof/json-rows.js +56 -4
  52. package/out/adapters/wof/json-rows.js.map +1 -1
  53. package/out/adapters/wof/sample.d.ts +12 -0
  54. package/out/adapters/wof/sample.d.ts.map +1 -1
  55. package/out/adapters/wof/sample.js +37 -6
  56. package/out/adapters/wof/sample.js.map +1 -1
  57. package/out/build/code-hash.js +1 -1
  58. package/out/build/code-hash.js.map +1 -1
  59. package/out/cjk/foreign-places.js +1 -1
  60. package/out/cjk/foreign-places.js.map +1 -1
  61. package/out/kr/adapters/localdata/permit-rows.js +1 -1
  62. package/out/kr/adapters/localdata/permit-rows.js.map +1 -1
  63. package/out/parquet/schema.d.ts +6 -0
  64. package/out/parquet/schema.d.ts.map +1 -1
  65. package/out/parquet/schema.js +6 -0
  66. package/out/parquet/schema.js.map +1 -1
  67. package/out/tools/anthropic/batches.d.ts +117 -0
  68. package/out/tools/anthropic/batches.d.ts.map +1 -0
  69. package/out/tools/anthropic/batches.js +141 -0
  70. package/out/tools/anthropic/batches.js.map +1 -0
  71. package/out/tools/anthropic/labeling.d.ts +97 -0
  72. package/out/tools/anthropic/labeling.d.ts.map +1 -0
  73. package/out/tools/anthropic/labeling.js +146 -0
  74. package/out/tools/anthropic/labeling.js.map +1 -0
  75. package/out/tools/compact-v9.d.ts +117 -0
  76. package/out/tools/compact-v9.d.ts.map +1 -0
  77. package/out/tools/compact-v9.js +494 -0
  78. package/out/tools/compact-v9.js.map +1 -0
  79. package/out/tools/fetch/wikidata/vital-places/entities.d.ts +3 -0
  80. package/out/tools/fetch/wikidata/vital-places/entities.d.ts.map +1 -1
  81. package/out/tools/fetch/wikidata/vital-places/entities.js +19 -1
  82. package/out/tools/fetch/wikidata/vital-places/entities.js.map +1 -1
  83. package/out/tools/fetch/wikidata/vital-places/qrank.d.ts.map +1 -1
  84. package/out/tools/fetch/wikidata/vital-places/qrank.js +4 -4
  85. package/out/tools/fetch/wikidata/vital-places/qrank.js.map +1 -1
  86. package/out/tools/fragment-assay.run.js +1 -1
  87. package/out/tools/fragment-assay.run.js.map +1 -1
  88. package/out/tools/name-roles/name-roles.run.d.ts +2 -0
  89. package/out/tools/name-roles/name-roles.run.d.ts.map +1 -0
  90. package/out/tools/name-roles/name-roles.run.js +230 -0
  91. package/out/tools/name-roles/name-roles.run.js.map +1 -0
  92. package/out/tools/name-roles/prompt.d.ts +166 -0
  93. package/out/tools/name-roles/prompt.d.ts.map +1 -0
  94. package/out/tools/name-roles/prompt.js +176 -0
  95. package/out/tools/name-roles/prompt.js.map +1 -0
  96. package/out/tools/overlay/deletions.js +1 -1
  97. package/out/tools/overlay/deletions.js.map +1 -1
  98. package/out/tools/overlay/draw-weight.d.ts +86 -0
  99. package/out/tools/overlay/draw-weight.d.ts.map +1 -0
  100. package/out/tools/overlay/draw-weight.js +131 -0
  101. package/out/tools/overlay/draw-weight.js.map +1 -0
  102. package/out/tools/place-twins/place-twins.run.d.ts +2 -0
  103. package/out/tools/place-twins/place-twins.run.d.ts.map +1 -0
  104. package/out/tools/place-twins/place-twins.run.js +385 -0
  105. package/out/tools/place-twins/place-twins.run.js.map +1 -0
  106. package/out/tools/place-twins/prompt.d.ts +169 -0
  107. package/out/tools/place-twins/prompt.d.ts.map +1 -0
  108. package/out/tools/place-twins/prompt.js +183 -0
  109. package/out/tools/place-twins/prompt.js.map +1 -0
  110. package/out/tools/prominent-shapes/prominent-shapes.run.d.ts +2 -0
  111. package/out/tools/prominent-shapes/prominent-shapes.run.d.ts.map +1 -0
  112. package/out/tools/prominent-shapes/prominent-shapes.run.js +302 -0
  113. package/out/tools/prominent-shapes/prominent-shapes.run.js.map +1 -0
  114. package/out/tools/prominent-shapes/prompt.d.ts +74 -0
  115. package/out/tools/prominent-shapes/prompt.d.ts.map +1 -0
  116. package/out/tools/prominent-shapes/prompt.js +156 -0
  117. package/out/tools/prominent-shapes/prompt.js.map +1 -0
  118. package/out/tools/prominent-shapes/read-seeds.d.ts +23 -0
  119. package/out/tools/prominent-shapes/read-seeds.d.ts.map +1 -0
  120. package/out/tools/prominent-shapes/read-seeds.js +219 -0
  121. package/out/tools/prominent-shapes/read-seeds.js.map +1 -0
  122. package/out/tools/prominent-shapes/seeds.d.ts +132 -0
  123. package/out/tools/prominent-shapes/seeds.d.ts.map +1 -0
  124. package/out/tools/prominent-shapes/seeds.js +178 -0
  125. package/out/tools/prominent-shapes/seeds.js.map +1 -0
  126. package/out/tools/prominent-shapes/validate.d.ts +152 -0
  127. package/out/tools/prominent-shapes/validate.d.ts.map +1 -0
  128. package/out/tools/prominent-shapes/validate.js +389 -0
  129. package/out/tools/prominent-shapes/validate.js.map +1 -0
  130. package/out/training/config/admission.d.ts +2 -1
  131. package/out/training/config/admission.d.ts.map +1 -1
  132. package/out/training/config/admission.js +9 -2
  133. package/out/training/config/admission.js.map +1 -1
  134. package/out/training/config/schema.d.ts +276 -1
  135. package/out/training/config/schema.d.ts.map +1 -1
  136. package/out/training/config/schema.js +64 -1
  137. package/out/training/config/schema.js.map +1 -1
  138. package/out/types.d.ts +21 -0
  139. package/out/types.d.ts.map +1 -1
  140. package/out/types.js +13 -0
  141. package/out/types.js.map +1 -1
  142. package/out/utils/split.js +1 -1
  143. package/out/utils/split.js.map +1 -1
  144. package/package.json +24 -24
@@ -0,0 +1,389 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+ /**
4
+ * @file Checks the query forms a language model wrote for a prominent place against the place's seed.
5
+ *
6
+ * A form is kept only when it cites surfaces the seed supplied, each cited surface is found in the
7
+ * form's text under the case and whitespace fold, and the text outside those spans is separators.
8
+ * A form that cites a slot letter in place of a numbered key is kept when one key of that slot passes.
9
+ * The last rule is what refuses a name the seed didn't supply: an alias, an exonym or a typo
10
+ * leaves letters outside every span.
11
+ * A refused form is dropped and counted under its reason.
12
+ */
13
+ import { tryParsingJSON } from "@mailwoman/core/values/json";
14
+ import { SurfaceSlot } from "#tools/prominent-shapes/seeds";
15
+ /**
16
+ * The reasons a returned form is dropped.
17
+ */
18
+ export const FormDrop = {
19
+ /**
20
+ * The form cites a key the seed doesn't hold.
21
+ */
22
+ UnknownSurface: "unknown_surface_key",
23
+ /**
24
+ * The form cites a bare slot letter, and no choice of that slot's keys passes every other rule.
25
+ */
26
+ LetterUnresolved: "slot_letter_without_passing_key",
27
+ /**
28
+ * The form cites a bare slot letter, and more than one choice of that slot's keys passes every other rule.
29
+ */
30
+ LetterAmbiguous: "slot_letter_with_several_passing_keys",
31
+ /**
32
+ * The cited slots are a combination the label policy doesn't write.
33
+ */
34
+ SlotsNotAllowed: "slots_not_allowed",
35
+ /**
36
+ * A cited surface isn't in the text, so its span has no offsets.
37
+ */
38
+ UnresolvableSpan: "unresolvable_span",
39
+ /**
40
+ * The text holds letters or digits outside every cited surface.
41
+ */
42
+ UnsuppliedText: "text_outside_supplied_surfaces",
43
+ /**
44
+ * Two spans touch without a separator in a script that separates words.
45
+ */
46
+ UnseparatedSpans: "unseparated_spans",
47
+ /**
48
+ * The form writes one surface in Latin script beside another in a different script.
49
+ */
50
+ MixedScript: "mixed_script",
51
+ /**
52
+ * The text is empty or longer than a search-box query.
53
+ */
54
+ Length: "raw_length",
55
+ /**
56
+ * The same text was already kept for this place.
57
+ */
58
+ Duplicate: "duplicate_raw",
59
+ };
60
+ /**
61
+ * The longest text kept, in UTF-16 units.
62
+ */
63
+ const MAX_RAW_LENGTH = 120;
64
+ /**
65
+ * The characters a form may hold outside its spans.
66
+ */
67
+ const SEPARATORS = /^[\s,.;/()\-–·、,]*$/u;
68
+ /**
69
+ * A character of a script written without spaces between words, where two spans may touch.
70
+ */
71
+ const UNSPACED_SCRIPT = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}]/u;
72
+ /**
73
+ * Folds case and whitespace as `foldCaseWhitespace` does, keeping where each folded unit came from.
74
+ *
75
+ * Each code point is lower-cased on its own, so a final sigma folds as a medial one does
76
+ * and `ΠΑΦΟΣ` matches `Πάφος`'s letters where the context-sensitive mapping wouldn't.
77
+ */
78
+ function foldWithOffsets(input) {
79
+ const fold = { text: "", starts: [], ends: [] };
80
+ let offset = 0;
81
+ // The source offsets of a whitespace run not yet written, or -1 outside one.
82
+ let spaceStart = -1;
83
+ let spaceEnd = -1;
84
+ for (const char of input) {
85
+ const start = offset;
86
+ offset += char.length;
87
+ if (/\s/u.test(char)) {
88
+ if (fold.text !== "") {
89
+ spaceStart = spaceStart < 0 ? start : spaceStart;
90
+ spaceEnd = offset;
91
+ }
92
+ continue;
93
+ }
94
+ if (spaceStart >= 0) {
95
+ fold.text += " ";
96
+ fold.starts.push(spaceStart);
97
+ fold.ends.push(spaceEnd);
98
+ spaceStart = -1;
99
+ }
100
+ const lowered = char.toLowerCase().replaceAll("ς", "σ");
101
+ fold.text += lowered;
102
+ // One offset pair per UTF-16 unit, so an index into the folded text reads its source offsets.
103
+ fold.starts.push(...Array.from({ length: lowered.length }).fill(start));
104
+ fold.ends.push(...Array.from({ length: lowered.length }).fill(offset));
105
+ }
106
+ return fold;
107
+ }
108
+ /**
109
+ * The tag a surface takes in a form of `seed`.
110
+ */
111
+ function surfaceTag(seed, surface) {
112
+ switch (surface.slot) {
113
+ case SurfaceSlot.Name:
114
+ return seed.place_tag;
115
+ case SurfaceSlot.Parent:
116
+ return seed.parent_tag ?? "locality";
117
+ case SurfaceSlot.Region:
118
+ case SurfaceSlot.RegionAbbreviation:
119
+ return "region";
120
+ case SurfaceSlot.Country:
121
+ return "country";
122
+ }
123
+ }
124
+ /**
125
+ * The shape id of a set of cited slots: the second segments in a fixed order,
126
+ * or `bare` for a form that cites only the name.
127
+ */
128
+ export function shapeOfSlots(slots) {
129
+ const parts = [
130
+ slots.has(SurfaceSlot.Parent) ? "parent" : null,
131
+ slots.has(SurfaceSlot.Region) ? "region" : null,
132
+ slots.has(SurfaceSlot.RegionAbbreviation) ? "region_abbr" : null,
133
+ slots.has(SurfaceSlot.Country) ? "country" : null,
134
+ ].filter((part) => part != null);
135
+ return parts.length ? parts.join("+") : "bare";
136
+ }
137
+ /**
138
+ * Whether the label policy writes a form with these slots for `seed`: one name, at most one surface per
139
+ * other slot, a region written once, and a parent beside every place the seed has a parent slot for.
140
+ */
141
+ function slotsAllowed(seed, surfaces) {
142
+ const count = (slot) => surfaces.filter((surface) => surface.slot === slot).length;
143
+ if (count(SurfaceSlot.Name) !== 1)
144
+ return false;
145
+ if (Object.values(SurfaceSlot).some((slot) => count(slot) > 1))
146
+ return false;
147
+ if (count(SurfaceSlot.Region) + count(SurfaceSlot.RegionAbbreviation) > 1)
148
+ return false;
149
+ // A postal pair's parent is its region, so an abbreviation replaces the parent rather than joining it.
150
+ if (seed.parent_tag === "region") {
151
+ return count(SurfaceSlot.Parent) + count(SurfaceSlot.RegionAbbreviation) === 1;
152
+ }
153
+ return seed.parent_tag === "locality" ? count(SurfaceSlot.Parent) === 1 : count(SurfaceSlot.Parent) === 0;
154
+ }
155
+ function isLatin(text) {
156
+ return /\p{Script=Latin}/u.test(text);
157
+ }
158
+ function hasOtherScript(text) {
159
+ return /[^\p{Script=Latin}\p{Script=Common}\p{Script=Inherited}]/u.test(text);
160
+ }
161
+ /**
162
+ * Every order of `items`, the given order first.
163
+ */
164
+ function* orderings(items) {
165
+ if (items.length <= 1) {
166
+ yield [...items];
167
+ return;
168
+ }
169
+ for (let index = 0; index < items.length; index++) {
170
+ for (const rest of orderings([...items.slice(0, index), ...items.slice(index + 1)])) {
171
+ yield [items[index], ...rest];
172
+ }
173
+ }
174
+ }
175
+ /**
176
+ * Finds each surface in `fold` from left to right in the order given, or `null` when one is absent.
177
+ */
178
+ function locateInOrder(fold, surfaces) {
179
+ const located = [];
180
+ let from = 0;
181
+ for (const surface of surfaces) {
182
+ const needle = foldWithOffsets(surface.text).text;
183
+ const at = needle === "" ? -1 : fold.text.indexOf(needle, from);
184
+ if (at < 0)
185
+ return null;
186
+ from = at + needle.length;
187
+ located.push({ surface, start: fold.starts[at], end: fold.ends[from - 1] });
188
+ }
189
+ return located;
190
+ }
191
+ /**
192
+ * Every choice of one item from each list, in the lists' order.
193
+ * A list without an item leaves no choice.
194
+ */
195
+ function* choices(lists) {
196
+ const [head, ...rest] = lists;
197
+ if (!head) {
198
+ yield [];
199
+ return;
200
+ }
201
+ for (const item of head) {
202
+ for (const tail of choices(rest)) {
203
+ yield [item, ...tail];
204
+ }
205
+ }
206
+ }
207
+ function isSurfaceSlot(key) {
208
+ return Object.values(SurfaceSlot).includes(key);
209
+ }
210
+ /**
211
+ * Checks one returned form against its seed.
212
+ *
213
+ * A bare slot letter cited as a key stands for a key of that slot.
214
+ * Each choice of keys is checked under the rules a numbered citation passes.
215
+ *
216
+ * The form is kept only when exactly one choice passes, so a letter never decides
217
+ * between two surfaces the text could both be.
218
+ */
219
+ export function validateForm(seed, form) {
220
+ const raw = form.raw.trim();
221
+ if (raw === "" || raw.length > MAX_RAW_LENGTH || /[\n\r\t]/u.test(raw))
222
+ return FormDrop.Length;
223
+ const byKey = new Map(seed.surfaces.map((surface) => [surface.key, surface]));
224
+ const options = [];
225
+ let fromLetters = false;
226
+ for (const key of form.uses) {
227
+ const surface = byKey.get(key);
228
+ if (surface) {
229
+ options.push([surface]);
230
+ }
231
+ else if (isSurfaceSlot(key)) {
232
+ fromLetters = true;
233
+ options.push(seed.surfaces.filter((candidate) => candidate.slot === key));
234
+ }
235
+ else {
236
+ return FormDrop.UnknownSurface;
237
+ }
238
+ }
239
+ if (!options.length)
240
+ return FormDrop.UnknownSurface;
241
+ if (!fromLetters)
242
+ return validateCitedSurfaces(seed, raw, options.flat(), false);
243
+ let passing = null;
244
+ for (const surfaces of choices(options)) {
245
+ const result = validateCitedSurfaces(seed, raw, surfaces, true);
246
+ if (typeof result === "string")
247
+ continue;
248
+ if (passing)
249
+ return FormDrop.LetterAmbiguous;
250
+ passing = result;
251
+ }
252
+ return passing ?? FormDrop.LetterUnresolved;
253
+ }
254
+ /**
255
+ * Checks a form's text against the surfaces it cites.
256
+ *
257
+ * The surfaces are located in the cited order first and then in every other order,
258
+ * and the first order that leaves only separators outside the spans is kept.
259
+ */
260
+ function validateCitedSurfaces(seed, raw, surfaces, fromLetters) {
261
+ if (!slotsAllowed(seed, surfaces))
262
+ return FormDrop.SlotsNotAllowed;
263
+ if (surfaces.some((surface) => hasOtherScript(surface.text)) &&
264
+ surfaces.some((surface) => !hasOtherScript(surface.text) && isLatin(surface.text))) {
265
+ return FormDrop.MixedScript;
266
+ }
267
+ const fold = foldWithOffsets(raw);
268
+ let failure = FormDrop.UnresolvableSpan;
269
+ for (const order of orderings(surfaces)) {
270
+ const located = locateInOrder(fold, order);
271
+ if (!located)
272
+ continue;
273
+ const gaps = located.map((span, index) => raw.slice(index === 0 ? 0 : located[index - 1].end, span.start));
274
+ const tail = raw.slice(located.at(-1).end);
275
+ if (gaps[0] !== "" || ![...gaps, tail].every((gap) => SEPARATORS.test(gap)) || !/^[).]?$/u.test(tail)) {
276
+ failure = FormDrop.UnsuppliedText;
277
+ continue;
278
+ }
279
+ const touching = gaps.some((gap, index) => index > 0 &&
280
+ gap === "" &&
281
+ !(UNSPACED_SCRIPT.test(raw[located[index].start]) || UNSPACED_SCRIPT.test(raw[located[index].start - 1])));
282
+ if (touching) {
283
+ failure = FormDrop.UnseparatedSpans;
284
+ continue;
285
+ }
286
+ return {
287
+ wof_id: seed.wof_id,
288
+ country: seed.country,
289
+ band: seed.band,
290
+ shape: shapeOfSlots(new Set(surfaces.map((surface) => surface.slot))),
291
+ raw,
292
+ spans: located.map(({ surface, start, end }) => ({
293
+ tag: surfaceTag(seed, surface),
294
+ value: raw.slice(start, end),
295
+ start,
296
+ end,
297
+ surface: surface.text,
298
+ origin: surface.origin,
299
+ })),
300
+ keys_from_letters: fromLetters,
301
+ };
302
+ }
303
+ return failure;
304
+ }
305
+ /**
306
+ * The kept forms of one place and its drops by reason, with a repeated text kept once.
307
+ */
308
+ export function validatePlaceForms(seed, forms) {
309
+ const kept = [];
310
+ const drops = {};
311
+ const seen = new Set();
312
+ for (const form of forms) {
313
+ const result = validateForm(seed, form);
314
+ const drop = typeof result === "string" ? result : seen.has(result.raw) ? FormDrop.Duplicate : null;
315
+ if (drop || typeof result === "string") {
316
+ drops[drop] = (drops[drop] ?? 0) + 1;
317
+ continue;
318
+ }
319
+ seen.add(result.raw);
320
+ kept.push(result);
321
+ }
322
+ return { kept, drops };
323
+ }
324
+ /**
325
+ * Validates the response text of one request against the request's seeds,
326
+ * or returns `null` when the text isn't the schema's shape.
327
+ */
328
+ export function validateResponse(text, seeds) {
329
+ const places = parseShapeResponse(text);
330
+ if (!places)
331
+ return null;
332
+ const byID = new Map(seeds.map((seed) => [String(seed.wof_id), seed]));
333
+ const kept = [];
334
+ const drops = {};
335
+ const answered = new Set();
336
+ let returned = 0;
337
+ for (const place of places) {
338
+ const seed = byID.get(place.id);
339
+ returned += place.forms.length;
340
+ if (!seed || answered.has(seed.wof_id)) {
341
+ const reason = seed ? "repeated_place" : "place_not_in_request";
342
+ drops[reason] = (drops[reason] ?? 0) + place.forms.length;
343
+ continue;
344
+ }
345
+ answered.add(seed.wof_id);
346
+ const result = validatePlaceForms(seed, place.forms);
347
+ kept.push(...result.kept);
348
+ for (const [reason, n] of Object.entries(result.drops)) {
349
+ drops[reason] = (drops[reason] ?? 0) + n;
350
+ }
351
+ }
352
+ return { kept, drops, returned, answered };
353
+ }
354
+ /**
355
+ * The reason every form of a response dropped under, or `null` when a form was kept,
356
+ * the response held no form, or its forms dropped under more than one reason.
357
+ *
358
+ * One reason taking a whole response is a fault of the request or of the validator rather than of a form.
359
+ */
360
+ export function wholeResponseDropReason(response) {
361
+ const reasons = Object.entries(response.drops).filter(([, n]) => (n ?? 0) > 0);
362
+ if (response.kept.length || response.returned === 0 || reasons.length !== 1)
363
+ return null;
364
+ return reasons[0][0];
365
+ }
366
+ /**
367
+ * Parses a response's text into its places, or returns `null` when the text isn't the schema's shape.
368
+ *
369
+ * A place or form of another shape makes the whole response unreadable rather than a
370
+ * shorter list, so a caller never counts a partly read response as a complete one.
371
+ */
372
+ export function parseShapeResponse(text) {
373
+ const parsed = tryParsingJSON(text);
374
+ if (!parsed || !Array.isArray(parsed.places))
375
+ return null;
376
+ const places = [];
377
+ for (const place of parsed.places) {
378
+ if (typeof place?.id !== "string" || !Array.isArray(place.forms))
379
+ return null;
380
+ for (const form of place.forms) {
381
+ const readable = typeof form?.raw === "string" && Array.isArray(form.uses) && form.uses.every((key) => typeof key === "string");
382
+ if (!readable)
383
+ return null;
384
+ }
385
+ places.push({ id: place.id, forms: place.forms });
386
+ }
387
+ return places;
388
+ }
389
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../lib/tools/prominent-shapes/validate.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;;;;;;;;GASG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAE5D,OAAO,EAAoC,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAkB7F;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB;;OAEG;IACH,cAAc,EAAE,qBAAqB;IACrC;;OAEG;IACH,gBAAgB,EAAE,iCAAiC;IACnD;;OAEG;IACH,eAAe,EAAE,uCAAuC;IACxD;;OAEG;IACH,eAAe,EAAE,mBAAmB;IACpC;;OAEG;IACH,gBAAgB,EAAE,mBAAmB;IACrC;;OAEG;IACH,cAAc,EAAE,gCAAgC;IAChD;;OAEG;IACH,gBAAgB,EAAE,mBAAmB;IACrC;;OAEG;IACH,WAAW,EAAE,cAAc;IAC3B;;OAEG;IACH,MAAM,EAAE,YAAY;IACpB;;OAEG;IACH,SAAS,EAAE,eAAe;CACjB,CAAA;AA6CV;;GAEG;AACH,MAAM,cAAc,GAAG,GAAG,CAAA;AAE1B;;GAEG;AACH,MAAM,UAAU,GAAG,sBAAsB,CAAA;AAEzC;;GAEG;AACH,MAAM,eAAe,GACpB,wHAAwH,CAAA;AAWzH;;;;;GAKG;AACH,SAAS,eAAe,CAAC,KAAa;IACrC,MAAM,IAAI,GAAe,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAA;IAC3D,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,6EAA6E;IAC7E,IAAI,UAAU,GAAG,CAAC,CAAC,CAAA;IACnB,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAA;IAEjB,KAAK,MAAM,IAAI,IAAI,KAAK,EA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2
  import type { AddressSourceRegister } from "#source-register/types";
3
3
  import type { TrainingConfig } from "#training/config/schema";
4
4
  /**
5
- * The corpus sources a config admits: every positive `source_weights` or `source_reps` key, sorted.
5
+ * The corpus sources a config admits: every positive `source_weights` or `source_reps` key,
6
+ * plus any source listed in `tier1_sources`, sorted.
6
7
  *
7
8
  * A config without `source_weights` admits every source its corpus holds and lists none of them.
8
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"admission.d.ts","sourceRoot":"","sources":["../../../lib/training/config/admission.ts"],"names":[],"mappings":"AAUA,OAAO,EAIN,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,MAAM,gCAAgC,CAAA;AAEvC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE7D;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,EAAE,CAOxE;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC,QAAQ,EAAE,qBAAqB,CAAA;IAC/B,MAAM,EAAE,kBAAkB,CAAA;CAC1B;AAOD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,MAAM,CAAC,EAAE,uBAAuB,CAAA;IAChC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAC5B;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACxC,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,0BAA0B,GACjC,OAAO,CAAC,kBAAkB,CAAC,CAuC7B"}
1
+ {"version":3,"file":"admission.d.ts","sourceRoot":"","sources":["../../../lib/training/config/admission.ts"],"names":[],"mappings":"AAUA,OAAO,EAIN,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,MAAM,gCAAgC,CAAA;AAEvC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE7D;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,EAAE,CAaxE;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC,QAAQ,EAAE,qBAAqB,CAAA;IAC/B,MAAM,EAAE,kBAAkB,CAAA;CAC1B;AAOD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,MAAM,CAAC,EAAE,uBAAuB,CAAA;IAChC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAC5B;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACxC,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,0BAA0B,GACjC,OAAO,CAAC,kBAAkB,CAAC,CAuC7B"}
@@ -9,7 +9,8 @@ import { createSourceRightsAdmission, readCorpusSourceInputs, SourceRightsError,
9
9
  import { readAddressSourceRegister } from "#source-register/register";
10
10
  import { trainingCorpusVersion } from "#training/config/load";
11
11
  /**
12
- * The corpus sources a config admits: every positive `source_weights` or `source_reps` key, sorted.
12
+ * The corpus sources a config admits: every positive `source_weights` or `source_reps` key,
13
+ * plus any source listed in `tier1_sources`, sorted.
13
14
  *
14
15
  * A config without `source_weights` admits every source its corpus holds and lists none of them.
15
16
  */
@@ -17,7 +18,13 @@ export function admittedTrainingSources(config) {
17
18
  const positive = (weights) => Object.entries(weights ?? {})
18
19
  .filter(([, weight]) => weight > 0)
19
20
  .map(([source]) => source);
20
- return [...new Set([...positive(config.data.source_weights), ...positive(config.data.source_reps)])].toSorted();
21
+ return [
22
+ ...new Set([
23
+ ...positive(config.data.source_weights),
24
+ ...positive(config.data.source_reps),
25
+ ...config.data.tier1_sources,
26
+ ]),
27
+ ].toSorted();
21
28
  }
22
29
  /**
23
30
  * Where a training config sets the override a refusal names.
@@ -1 +1 @@
1
- {"version":3,"file":"admission.js","sourceRoot":"","sources":["../../../lib/training/config/admission.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE5E,OAAO,EACN,2BAA2B,EAC3B,sBAAsB,EACtB,iBAAiB,GAGjB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AAErE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAG7D;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAsB;IAC7D,MAAM,QAAQ,GAAG,CAAC,OAAsC,EAAE,EAAE,CAC3D,MAAM,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;SAC3B,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;SAClC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAA;IAE5B,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;AAChH,CAAC;AAUD;;GAEG;AACH,MAAM,oBAAoB,GAAG,uDAAuD,CAAA;AAiBpF;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,MAAsB,EACtB,OAAmC;IAEnC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAA;IAE7C,IAAI,MAAM,CAA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