@mailwoman/corpus 11.4.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 (162) hide show
  1. package/data/address-source-register.json +9 -1
  2. package/data/builds/v0.8.22-nz-overlay/OVERLAY_PLAN.json +19 -0
  3. package/data/builds/v0.8.22-wofrank-overlay/OVERLAY_PLAN.json +51 -0
  4. package/data/builds/v0.8.24-everyplace/inputs.json +35 -0
  5. package/data/license-decisions.json +9 -1
  6. package/data/training-configs/v8.14.0-base-c6-wofreps-cursor-v0822-s42.yaml +926 -0
  7. package/data/training-configs/v8.15.0-base-c6-wofreps-cursor-emit-v0822-s42.yaml +973 -0
  8. package/data/training-configs/v8.16.0-base-c6-wofreps-positions-v0822-s42.yaml +988 -0
  9. package/data/training-configs/v8.17.0-stage1-gazetteer-v0822-s42.yaml +557 -0
  10. package/data/training-configs/v8.17.0-stage2-corpus-v0822-s42.yaml +1008 -0
  11. package/data/training-configs/v8.18.0-gazetteer-then-mixture-v0822-s42.yaml +1225 -0
  12. package/data/training-configs/v8.19.0-nz-v0822-s42.yaml +870 -0
  13. package/data/training-configs/v8.20.0-wofrank-v0822-s42.yaml +863 -0
  14. package/data/training-configs/v8.21.0-outcomes-v0822-s42.yaml +873 -0
  15. package/data/training-configs/v8.22.0-stage1-everyplace-v0824-s42.yaml +374 -0
  16. package/data/training-configs/v8.22.0-stage2-corpus-v0824-s42.yaml +808 -0
  17. package/data/training-configs/v8.22.1-stage1-everyplace-v0824-s42.yaml +376 -0
  18. package/data/training-configs/v8.22.1-stage2-corpus-v0824-s42.yaml +793 -0
  19. package/data/training-configs/v9.0.0-bytestem-v090-s42.yaml +665 -0
  20. package/data/training-manifests/v0.8.22-nz-overlay.effective.json +2556 -0
  21. package/data/training-manifests/v0.8.22-nz-overlay.json +9000 -0
  22. package/data/training-manifests/v0.8.22-wofrank-overlay.json +9000 -0
  23. package/data/training-manifests/v0.8.24-everyplace-overlay.json +9000 -0
  24. package/data/training-manifests/v0.9.0-compact.effective.json +2556 -0
  25. package/data/training-manifests/v0.9.0-compact.json +9000 -0
  26. package/lib/adapters/wof/admin/json/adapter.ts +38 -3
  27. package/lib/adapters/wof/json-rows.ts +84 -5
  28. package/lib/adapters/wof/sample.ts +42 -6
  29. package/lib/build/code-hash.ts +1 -1
  30. package/lib/cjk/foreign-places.ts +1 -1
  31. package/lib/kr/adapters/localdata/permit-rows.ts +1 -1
  32. package/lib/parquet/schema.ts +7 -0
  33. package/lib/tools/anthropic/batches.ts +221 -0
  34. package/lib/tools/anthropic/labeling.ts +263 -0
  35. package/lib/tools/compact-v9.ts +872 -0
  36. package/lib/tools/fetch/wikidata/vital-places/entities.ts +20 -2
  37. package/lib/tools/fetch/wikidata/vital-places/qrank.ts +5 -4
  38. package/lib/tools/fragment-assay.run.ts +2 -1
  39. package/lib/tools/name-roles/name-roles.run.ts +296 -0
  40. package/lib/tools/name-roles/prompt.ts +253 -0
  41. package/lib/tools/overlay/deletions.ts +1 -1
  42. package/lib/tools/overlay/draw-weight.ts +275 -0
  43. package/lib/tools/overlay/manifest.ts +36 -5
  44. package/lib/tools/place-twins/place-twins.run.ts +528 -0
  45. package/lib/tools/place-twins/prompt.ts +276 -0
  46. package/lib/tools/prominent-shapes/prominent-shapes.run.ts +420 -0
  47. package/lib/tools/prominent-shapes/prompt.ts +189 -0
  48. package/lib/tools/prominent-shapes/read-seeds.ts +286 -0
  49. package/lib/tools/prominent-shapes/seeds.ts +281 -0
  50. package/lib/tools/prominent-shapes/validate.ts +563 -0
  51. package/lib/training/config/admission.ts +9 -2
  52. package/lib/training/config/schema.ts +84 -0
  53. package/lib/types.ts +23 -0
  54. package/lib/us/adapters/usgov/nad/adapter.ts +8 -3
  55. package/lib/utils/split.ts +1 -1
  56. package/out/adapters/wof/admin/json/adapter.d.ts +7 -0
  57. package/out/adapters/wof/admin/json/adapter.d.ts.map +1 -1
  58. package/out/adapters/wof/admin/json/adapter.js +28 -3
  59. package/out/adapters/wof/admin/json/adapter.js.map +1 -1
  60. package/out/adapters/wof/json-rows.d.ts +8 -0
  61. package/out/adapters/wof/json-rows.d.ts.map +1 -1
  62. package/out/adapters/wof/json-rows.js +56 -4
  63. package/out/adapters/wof/json-rows.js.map +1 -1
  64. package/out/adapters/wof/sample.d.ts +12 -0
  65. package/out/adapters/wof/sample.d.ts.map +1 -1
  66. package/out/adapters/wof/sample.js +37 -6
  67. package/out/adapters/wof/sample.js.map +1 -1
  68. package/out/build/code-hash.js +1 -1
  69. package/out/build/code-hash.js.map +1 -1
  70. package/out/cjk/foreign-places.js +1 -1
  71. package/out/cjk/foreign-places.js.map +1 -1
  72. package/out/kr/adapters/localdata/permit-rows.js +1 -1
  73. package/out/kr/adapters/localdata/permit-rows.js.map +1 -1
  74. package/out/parquet/schema.d.ts +6 -0
  75. package/out/parquet/schema.d.ts.map +1 -1
  76. package/out/parquet/schema.js +6 -0
  77. package/out/parquet/schema.js.map +1 -1
  78. package/out/tools/anthropic/batches.d.ts +117 -0
  79. package/out/tools/anthropic/batches.d.ts.map +1 -0
  80. package/out/tools/anthropic/batches.js +141 -0
  81. package/out/tools/anthropic/batches.js.map +1 -0
  82. package/out/tools/anthropic/labeling.d.ts +97 -0
  83. package/out/tools/anthropic/labeling.d.ts.map +1 -0
  84. package/out/tools/anthropic/labeling.js +146 -0
  85. package/out/tools/anthropic/labeling.js.map +1 -0
  86. package/out/tools/compact-v9.d.ts +117 -0
  87. package/out/tools/compact-v9.d.ts.map +1 -0
  88. package/out/tools/compact-v9.js +494 -0
  89. package/out/tools/compact-v9.js.map +1 -0
  90. package/out/tools/fetch/wikidata/vital-places/entities.d.ts +3 -0
  91. package/out/tools/fetch/wikidata/vital-places/entities.d.ts.map +1 -1
  92. package/out/tools/fetch/wikidata/vital-places/entities.js +19 -1
  93. package/out/tools/fetch/wikidata/vital-places/entities.js.map +1 -1
  94. package/out/tools/fetch/wikidata/vital-places/qrank.d.ts.map +1 -1
  95. package/out/tools/fetch/wikidata/vital-places/qrank.js +4 -4
  96. package/out/tools/fetch/wikidata/vital-places/qrank.js.map +1 -1
  97. package/out/tools/fragment-assay.run.js +1 -1
  98. package/out/tools/fragment-assay.run.js.map +1 -1
  99. package/out/tools/name-roles/name-roles.run.d.ts +2 -0
  100. package/out/tools/name-roles/name-roles.run.d.ts.map +1 -0
  101. package/out/tools/name-roles/name-roles.run.js +230 -0
  102. package/out/tools/name-roles/name-roles.run.js.map +1 -0
  103. package/out/tools/name-roles/prompt.d.ts +166 -0
  104. package/out/tools/name-roles/prompt.d.ts.map +1 -0
  105. package/out/tools/name-roles/prompt.js +176 -0
  106. package/out/tools/name-roles/prompt.js.map +1 -0
  107. package/out/tools/overlay/deletions.js +1 -1
  108. package/out/tools/overlay/deletions.js.map +1 -1
  109. package/out/tools/overlay/draw-weight.d.ts +86 -0
  110. package/out/tools/overlay/draw-weight.d.ts.map +1 -0
  111. package/out/tools/overlay/draw-weight.js +131 -0
  112. package/out/tools/overlay/draw-weight.js.map +1 -0
  113. package/out/tools/overlay/manifest.d.ts.map +1 -1
  114. package/out/tools/overlay/manifest.js +29 -5
  115. package/out/tools/overlay/manifest.js.map +1 -1
  116. package/out/tools/place-twins/place-twins.run.d.ts +2 -0
  117. package/out/tools/place-twins/place-twins.run.d.ts.map +1 -0
  118. package/out/tools/place-twins/place-twins.run.js +385 -0
  119. package/out/tools/place-twins/place-twins.run.js.map +1 -0
  120. package/out/tools/place-twins/prompt.d.ts +169 -0
  121. package/out/tools/place-twins/prompt.d.ts.map +1 -0
  122. package/out/tools/place-twins/prompt.js +183 -0
  123. package/out/tools/place-twins/prompt.js.map +1 -0
  124. package/out/tools/prominent-shapes/prominent-shapes.run.d.ts +2 -0
  125. package/out/tools/prominent-shapes/prominent-shapes.run.d.ts.map +1 -0
  126. package/out/tools/prominent-shapes/prominent-shapes.run.js +302 -0
  127. package/out/tools/prominent-shapes/prominent-shapes.run.js.map +1 -0
  128. package/out/tools/prominent-shapes/prompt.d.ts +74 -0
  129. package/out/tools/prominent-shapes/prompt.d.ts.map +1 -0
  130. package/out/tools/prominent-shapes/prompt.js +156 -0
  131. package/out/tools/prominent-shapes/prompt.js.map +1 -0
  132. package/out/tools/prominent-shapes/read-seeds.d.ts +23 -0
  133. package/out/tools/prominent-shapes/read-seeds.d.ts.map +1 -0
  134. package/out/tools/prominent-shapes/read-seeds.js +219 -0
  135. package/out/tools/prominent-shapes/read-seeds.js.map +1 -0
  136. package/out/tools/prominent-shapes/seeds.d.ts +132 -0
  137. package/out/tools/prominent-shapes/seeds.d.ts.map +1 -0
  138. package/out/tools/prominent-shapes/seeds.js +178 -0
  139. package/out/tools/prominent-shapes/seeds.js.map +1 -0
  140. package/out/tools/prominent-shapes/validate.d.ts +152 -0
  141. package/out/tools/prominent-shapes/validate.d.ts.map +1 -0
  142. package/out/tools/prominent-shapes/validate.js +389 -0
  143. package/out/tools/prominent-shapes/validate.js.map +1 -0
  144. package/out/training/config/admission.d.ts +2 -1
  145. package/out/training/config/admission.d.ts.map +1 -1
  146. package/out/training/config/admission.js +9 -2
  147. package/out/training/config/admission.js.map +1 -1
  148. package/out/training/config/schema.d.ts +321 -0
  149. package/out/training/config/schema.d.ts.map +1 -1
  150. package/out/training/config/schema.js +76 -0
  151. package/out/training/config/schema.js.map +1 -1
  152. package/out/types.d.ts +21 -0
  153. package/out/types.d.ts.map +1 -1
  154. package/out/types.js +13 -0
  155. package/out/types.js.map +1 -1
  156. package/out/us/adapters/usgov/nad/adapter.d.ts +4 -0
  157. package/out/us/adapters/usgov/nad/adapter.d.ts.map +1 -1
  158. package/out/us/adapters/usgov/nad/adapter.js +8 -3
  159. package/out/us/adapters/usgov/nad/adapter.js.map +1 -1
  160. package/out/utils/split.js +1 -1
  161. package/out/utils/split.js.map +1 -1
  162. package/package.json +24 -24
@@ -0,0 +1,178 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+ /**
4
+ * @file The seed of one prominent place: the verified surfaces a query form may be written from (#3156).
5
+ *
6
+ * A seed lists every surface a form may contain, each under one slot and with the record it came from.
7
+ * The language model that writes the forms chooses among these surfaces and supplies none of its own,
8
+ * so a form's labels are the seed's.
9
+ *
10
+ * The slots follow the #3156 label policy (`prominentPlaceTag` in `#recipes/prominent/places`):
11
+ * a locality is a `locality` in every form, a sub-locality is a `dependent_locality` beside its parent
12
+ * locality, and a postal pair is a `locality` beside its parent's name as a `region`.
13
+ */
14
+ import { foldCaseWhitespace } from "@mailwoman/normalize/fold";
15
+ /**
16
+ * The slots a surface fills, by the letter its key starts with.
17
+ */
18
+ export const SurfaceSlot = {
19
+ /**
20
+ * The place's own name.
21
+ */
22
+ Name: "n",
23
+ /**
24
+ * The parent locality of a sub-locality.
25
+ */
26
+ Parent: "p",
27
+ /**
28
+ * The region's name.
29
+ */
30
+ Region: "r",
31
+ /**
32
+ * The region's abbreviation.
33
+ */
34
+ RegionAbbreviation: "a",
35
+ /**
36
+ * The country.
37
+ */
38
+ Country: "c",
39
+ };
40
+ /**
41
+ * The reasons a prominent place gets no seed.
42
+ */
43
+ export const SeedSkip = {
44
+ /**
45
+ * A sub-locality without a parent locality: the label policy writes it only beside one.
46
+ */
47
+ NoParent: "sublocality_without_parent",
48
+ /**
49
+ * A sub-locality whose name equals its parent's, so every query form reads the same for both.
50
+ */
51
+ ParentNamesake: "sublocality_named_as_parent",
52
+ /**
53
+ * Every name of the place is refused as a typed surface, so no form could cite a name.
54
+ */
55
+ NoName: "no_typed_name",
56
+ };
57
+ /**
58
+ * A region abbreviation a form may write: one to three Latin letters or digits, the #3156 census's filter.
59
+ */
60
+ function isWritableRegionAbbreviation(abbreviation) {
61
+ return /^[A-Za-z0-9]{1,3}$/u.test(abbreviation);
62
+ }
63
+ /**
64
+ * Text that marks a name as an article title or a rendering artifact rather than a typed surface:
65
+ * a parenthesized qualifier (`Vaticano (disambigua)`) or a bidirectional control character.
66
+ */
67
+ const UNTYPED_SURFACE = /[()‎‏‪-‮]/u;
68
+ /**
69
+ * The drafts with a typed, non-empty text, one per folded text, in the order given.
70
+ */
71
+ function distinctDrafts(drafts) {
72
+ const seen = new Set();
73
+ const kept = [];
74
+ for (const draft of drafts) {
75
+ const fold = foldCaseWhitespace(draft.text);
76
+ if (fold === "" || seen.has(fold) || UNTYPED_SURFACE.test(draft.text))
77
+ continue;
78
+ seen.add(fold);
79
+ kept.push({ ...draft, text: draft.text.trim() });
80
+ }
81
+ return kept;
82
+ }
83
+ function keyed(slot, drafts) {
84
+ return distinctDrafts(drafts).map((draft, index) => ({ key: `${slot}${index + 1}`, slot, ...draft }));
85
+ }
86
+ /**
87
+ * Builds a place's seed, or returns the reason the label policy writes no form for it.
88
+ *
89
+ * A place whose every name is refused gets no seed in either band, because every form needs one name.
90
+ * A locality has no parent slot.
91
+ *
92
+ * A postal pair writes its parent's name in the region slot, and keeps the region's
93
+ * abbreviations only when the region is that same name (`Brooklyn, NY`).
94
+ */
95
+ export function assembleSeed(input) {
96
+ const names = keyed(SurfaceSlot.Name, input.names);
97
+ if (!names.length)
98
+ return SeedSkip.NoName;
99
+ const parents = distinctDrafts(input.parents);
100
+ const base = {
101
+ wof_id: input.wof_id,
102
+ country: input.country,
103
+ band: input.band,
104
+ rank: input.rank,
105
+ capital: input.capital,
106
+ };
107
+ const countries = keyed(SurfaceSlot.Country, input.countries);
108
+ const abbreviations = input.region_abbreviations.filter((draft) => isWritableRegionAbbreviation(draft.text));
109
+ if (input.band === "locality") {
110
+ return {
111
+ ...base,
112
+ place_tag: "locality",
113
+ parent_tag: null,
114
+ surfaces: [
115
+ ...names,
116
+ ...keyed(SurfaceSlot.Region, input.regions),
117
+ ...keyed(SurfaceSlot.RegionAbbreviation, abbreviations),
118
+ ...countries,
119
+ ],
120
+ };
121
+ }
122
+ if (!parents.length)
123
+ return SeedSkip.NoParent;
124
+ const nameFolds = new Set(names.map((name) => foldCaseWhitespace(name.text)));
125
+ if (parents.some((parent) => nameFolds.has(foldCaseWhitespace(parent.text))))
126
+ return SeedSkip.ParentNamesake;
127
+ if (input.postal_pair) {
128
+ const parentFolds = new Set(parents.map((parent) => foldCaseWhitespace(parent.text)));
129
+ const regionIsParent = input.regions.some((region) => parentFolds.has(foldCaseWhitespace(region.text)));
130
+ return {
131
+ ...base,
132
+ place_tag: "locality",
133
+ parent_tag: "region",
134
+ surfaces: [
135
+ ...names,
136
+ ...keyed(SurfaceSlot.Parent, parents),
137
+ ...(regionIsParent ? keyed(SurfaceSlot.RegionAbbreviation, abbreviations) : []),
138
+ ...countries,
139
+ ],
140
+ };
141
+ }
142
+ return {
143
+ ...base,
144
+ place_tag: "dependent_locality",
145
+ parent_tag: "locality",
146
+ surfaces: [
147
+ ...names,
148
+ ...keyed(SurfaceSlot.Parent, parents),
149
+ ...keyed(SurfaceSlot.Region, input.regions),
150
+ ...keyed(SurfaceSlot.RegionAbbreviation, abbreviations),
151
+ ...countries,
152
+ ],
153
+ };
154
+ }
155
+ /**
156
+ * Keeps each country and band's highest-ranked `limit` seeds, and every capital.
157
+ */
158
+ export function limitSeedsPerBand(seeds, limit) {
159
+ return [...Map.groupBy(seeds, (seed) => `${seed.country}\u0000${seed.band}`).values()].flatMap((group) => group
160
+ .toSorted((a, b) => (a.rank ?? Infinity) - (b.rank ?? Infinity))
161
+ .filter((seed, index) => index < limit || seed.capital));
162
+ }
163
+ /**
164
+ * Groups seeds into requests of at most `size` places, each of one country,
165
+ * so a request lists its country's surfaces once.
166
+ */
167
+ export function chunkSeedsByCountry(seeds, size) {
168
+ const chunks = [];
169
+ const byCountry = Map.groupBy(seeds, (seed) => seed.country);
170
+ for (const country of [...byCountry.keys()].toSorted()) {
171
+ const group = byCountry.get(country);
172
+ for (let start = 0; start < group.length; start += size) {
173
+ chunks.push(group.slice(start, start + size));
174
+ }
175
+ }
176
+ return chunks;
177
+ }
178
+ //# sourceMappingURL=seeds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seeds.js","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AK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAE5D,KAAK,MAAM,OAAO,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;QACxD,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAE,CAAA;QAErC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,IAAI,EAAE,CAAC;YACzD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC,CAAA;QAC9C,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAA;AACd,CAAC"}
@@ -0,0 +1,152 @@
1
+ import { type ShapeSeed, SurfaceSlot } from "#tools/prominent-shapes/seeds";
2
+ /**
3
+ * One form as the model returns it: the text and the keys of the surfaces it contains.
4
+ */
5
+ export interface ReturnedForm {
6
+ raw: string;
7
+ uses: string[];
8
+ }
9
+ /**
10
+ * The forms the model returned for one place.
11
+ */
12
+ export interface ReturnedPlace {
13
+ id: string;
14
+ forms: ReturnedForm[];
15
+ }
16
+ /**
17
+ * The reasons a returned form is dropped.
18
+ */
19
+ export declare const FormDrop: {
20
+ /**
21
+ * The form cites a key the seed doesn't hold.
22
+ */
23
+ readonly UnknownSurface: "unknown_surface_key";
24
+ /**
25
+ * The form cites a bare slot letter, and no choice of that slot's keys passes every other rule.
26
+ */
27
+ readonly LetterUnresolved: "slot_letter_without_passing_key";
28
+ /**
29
+ * The form cites a bare slot letter, and more than one choice of that slot's keys passes every other rule.
30
+ */
31
+ readonly LetterAmbiguous: "slot_letter_with_several_passing_keys";
32
+ /**
33
+ * The cited slots are a combination the label policy doesn't write.
34
+ */
35
+ readonly SlotsNotAllowed: "slots_not_allowed";
36
+ /**
37
+ * A cited surface isn't in the text, so its span has no offsets.
38
+ */
39
+ readonly UnresolvableSpan: "unresolvable_span";
40
+ /**
41
+ * The text holds letters or digits outside every cited surface.
42
+ */
43
+ readonly UnsuppliedText: "text_outside_supplied_surfaces";
44
+ /**
45
+ * Two spans touch without a separator in a script that separates words.
46
+ */
47
+ readonly UnseparatedSpans: "unseparated_spans";
48
+ /**
49
+ * The form writes one surface in Latin script beside another in a different script.
50
+ */
51
+ readonly MixedScript: "mixed_script";
52
+ /**
53
+ * The text is empty or longer than a search-box query.
54
+ */
55
+ readonly Length: "raw_length";
56
+ /**
57
+ * The same text was already kept for this place.
58
+ */
59
+ readonly Duplicate: "duplicate_raw";
60
+ };
61
+ /**
62
+ * One drop reason.
63
+ */
64
+ export type FormDrop = (typeof FormDrop)[keyof typeof FormDrop];
65
+ /**
66
+ * One labeled span of a kept form.
67
+ */
68
+ export interface CandidateSpan {
69
+ tag: "locality" | "dependent_locality" | "region" | "country";
70
+ /**
71
+ * The span's text as the form writes it.
72
+ */
73
+ value: string;
74
+ /**
75
+ * UTF-16 offsets into `raw`, `end` exclusive.
76
+ */
77
+ start: number;
78
+ end: number;
79
+ /**
80
+ * The supplied surface the span writes, and the record it came from.
81
+ */
82
+ surface: string;
83
+ origin: string;
84
+ }
85
+ /**
86
+ * A kept form before the run's model and batch are added to it.
87
+ */
88
+ export interface ValidatedForm {
89
+ wof_id: number;
90
+ country: string;
91
+ band: ShapeSeed["band"];
92
+ shape: string;
93
+ raw: string;
94
+ spans: CandidateSpan[];
95
+ /**
96
+ * Whether the form cited a bare slot letter (`n`) rather than a key (`n2`),
97
+ * and the letter was resolved to the one key of that slot the text passes with.
98
+ */
99
+ keys_from_letters: boolean;
100
+ }
101
+ /**
102
+ * The shape id of a set of cited slots: the second segments in a fixed order,
103
+ * or `bare` for a form that cites only the name.
104
+ */
105
+ export declare function shapeOfSlots(slots: ReadonlySet<SurfaceSlot>): string;
106
+ /**
107
+ * Checks one returned form against its seed.
108
+ *
109
+ * A bare slot letter cited as a key stands for a key of that slot.
110
+ * Each choice of keys is checked under the rules a numbered citation passes.
111
+ *
112
+ * The form is kept only when exactly one choice passes, so a letter never decides
113
+ * between two surfaces the text could both be.
114
+ */
115
+ export declare function validateForm(seed: ShapeSeed, form: ReturnedForm): ValidatedForm | FormDrop;
116
+ /**
117
+ * The kept forms of one place and its drops by reason, with a repeated text kept once.
118
+ */
119
+ export declare function validatePlaceForms(seed: ShapeSeed, forms: readonly ReturnedForm[]): {
120
+ kept: ValidatedForm[];
121
+ drops: Partial<Record<FormDrop, number>>;
122
+ };
123
+ /**
124
+ * What one request's response held: the kept forms, the drops by reason,
125
+ * the forms returned and the places answered.
126
+ */
127
+ export interface ValidatedResponse {
128
+ kept: ValidatedForm[];
129
+ drops: Partial<Record<string, number>>;
130
+ returned: number;
131
+ answered: Set<number>;
132
+ }
133
+ /**
134
+ * Validates the response text of one request against the request's seeds,
135
+ * or returns `null` when the text isn't the schema's shape.
136
+ */
137
+ export declare function validateResponse(text: string, seeds: readonly ShapeSeed[]): ValidatedResponse | null;
138
+ /**
139
+ * The reason every form of a response dropped under, or `null` when a form was kept,
140
+ * the response held no form, or its forms dropped under more than one reason.
141
+ *
142
+ * One reason taking a whole response is a fault of the request or of the validator rather than of a form.
143
+ */
144
+ export declare function wholeResponseDropReason(response: ValidatedResponse): string | null;
145
+ /**
146
+ * Parses a response's text into its places, or returns `null` when the text isn't the schema's shape.
147
+ *
148
+ * A place or form of another shape makes the whole response unreadable rather than a
149
+ * shorter list, so a caller never counts a partly read response as a complete one.
150
+ */
151
+ export declare function parseShapeResponse(text: string): ReturnedPlace[] | null;
152
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../lib/tools/prominent-shapes/validate.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAoB,KAAK,SAAS,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAE7F;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,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