1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
//! The value types the dimension axes are built from: a set of names
//! compared as a set, and a scalar label compared exactly.
//!
//! Five dimensions need a value and three comparison rules sit between them.
//! `organism` and `source_set` are both "which of these things is the data
//! about", where order is noise and a missing member is the whole point, so
//! both are [`NameSet`]; `release`, `subject` and `identifier_namespace` are
//! all "one label, and a different label is a different thing", so all three
//! are [`Label`]. What the two sets do *not* share is how two members are
//! compared, and that is the one thing [`NameSet`] is generic over: an
//! organism folds ASCII case, a source does not ([`Organism`],
//! [`SourceSet`]).
//!
//! Decision D36 forbids *one dimension* carrying *two* comparison rules,
//! because that is how a pipeline ends up passing `check()` under one rule
//! and failing under another. It says nothing against *two dimensions*
//! sharing *one* rule, and the rule is the thing worth having exactly once.
//! The set *algebra* — insertion-order dedup, difference, English rendering,
//! equality by length and containment — is therefore written once for both
//! sets, while the member comparison is written once per rule. The wording an
//! error uses still differs per dimension, because that lives on
//! `Dimension::leading_question`, not on the value.
use fmt;
use PhantomData;
/// How two members of a [`NameSet`] are compared.
///
/// A type parameter rather than a field, because a field would let one
/// dimension carry two rules at runtime — the thing D36 forbids outright —
/// and would make the choice an argument a caller can get wrong silently.
/// As a parameter it is the compiler's business: [`Organism`] and
/// [`SourceSet`] are different types, so a `check::compare` arm that read
/// the wrong axis's field no longer builds. Before the split they were one
/// type, and only a test over a kind that applied the axis could catch it
/// (M7's standing requirement).
/// Members differing only in ASCII case are one member.
///
/// Right for a closed conventional vocabulary. Latin binomials are one:
/// `HIV-1` and `hiv-1` are one organism by convention, and nothing is lost
/// by folding them.
;
/// Members are the same only if they are spelled the same.
///
/// Right for anything a specification makes case-sensitive.
/// `s3://bucket/A.vcf` and `s3://bucket/a.vcf` are two objects, and a URL
/// path is case-sensitive wherever it is served — so folding the case here
/// would *drop* a member, turning two sets that differ into two that agree.
/// That is a false agreement, which is the thing this engine exists to
/// refuse. Not folding it can only *add* a member, which turns agreement
/// into a loud refusal, fixed by one consistent spelling.
;
/// An ordered set of names, compared as a set.
///
/// Order never matters, and surrounding space is always forgiven. Whether
/// case matters is the type parameter's business: see [`Matching`],
/// [`Organism`] and [`SourceSet`]. A host–pathogen dataset about `HIV-1` and
/// `Homo sapiens` is the same dataset however the two were listed. There is
/// no alias table — equating "human" with "Homo sapiens" would mean
/// guessing, and a wrong guess passes `check()` silently. Declare one
/// spelling and use it.
///
/// Insertion order is kept (so a message can echo what the user wrote) but
/// is not part of the identity, and a name given twice is recorded once in
/// its first spelling. Blank names are dropped rather than stored, since an
/// empty member would compare equal to every other empty member and mean
/// nothing.
///
/// # An empty set must never be a known dimension
///
/// An empty set is a legal *value*: it is what [`NameSet::of`] returns for
/// no names, and `Display` renders it as an empty string. It must never reach
/// a `Dim::known`, because two known empty sets compare equal, and that is a
/// false agreement, the thing this engine exists to refuse. The type does not
/// enforce this; the loaders do, by building the dimension through
/// `load::organism` and `load::source_set`, which turn an empty declaration
/// into an unknown one with a reason. A new loader of a set-valued dimension
/// must go through that path (or an equivalent that checks
/// [`NameSet::is_empty`] first), and `tests/declared_dimensions.rs` fails if
/// one does not.
///
/// # There is no default rule
///
/// `M` has no default, so this type cannot be named without naming the rule
/// it compares by. That is deliberate: the two axes differ in exactly that
/// rule, and a `NameSet` written without one would be whichever rule the
/// default happened to be, which is how the axes came to share a rule
/// nobody had chosen for both. Write [`Organism`] or [`SourceSet`].
/// Join names as English does: `a`, `a and b`, `a, b and c`.
///
/// Shared with the error text in `check`, which lists the members one input
/// has and the other lacks. Defining the join once means a set and the
/// difference between two sets can never be punctuated differently.
pub
/// The organisms the data is about.
///
/// Folds ASCII case, because Latin binomials are a closed conventional
/// vocabulary in which `HIV-1` and `hiv-1` are one organism (D37).
pub type Organism = ;
/// The sources a dataset was assembled from.
///
/// Compared **exactly**, which is D36's reserved right carried out. The two
/// failures are not symmetric: folding case *drops* a member, turning two
/// sets that differ into two that agree — a false agreement, which is the
/// thing this engine exists to refuse. Not folding it can only *add* a
/// member, which turns agreement into a refusal: loud, legible, and fixed by
/// declaring one spelling. This project has taken that trade twice already,
/// in D37's refusal to equate `human` with `Homo sapiens` and in D38's
/// refusal of an alias table.
///
/// The folding is also the unusual rule rather than the default. [`Release`],
/// [`Subject`] and [`IdentifierNamespace`] are all [`Label`] and compared
/// case-sensitively, because a label is a name the user chose. [`Organism`]
/// folds because of the closed vocabulary above. Sources are not that:
/// `s3://bucket/A.vcf` and `s3://bucket/a.vcf` are two objects *by
/// specification*, and a URL path is case-sensitive wherever it is served.
/// `GSE12345` matching `gse12345` is real but is the minority case, and it
/// costs a user one consistent spelling.
///
/// M10a settled this rule and left it unimplemented, because until a kind
/// applied the axis `check_step` never reached its arms and shipping an
/// unexercised value type is the condition M7's standing requirement exists
/// to prevent. `KnowledgeGraph` applies it, so the split lands with it,
/// together with that axis's `check::compare` and `graph::propagate` arms.
pub type SourceSet = ;
/// A scalar label, compared exactly.
///
/// Only surrounding space is forgiven. Case is not: `hgnc 2026-09` and
/// `HGNC 2026-09` may well be different releases, and a label is a name the
/// user chose, not a free-text description to be fuzzily matched.
;
/// The release of an annotation or database the data is on.
pub type Release = Label;
/// Who or what the data is about, when that is one named thing.
pub type Subject = Label;
/// Which identifier space a set of entities is named in.
///
/// A [`Label`] because the rule is the same as `release`'s: one name, and a
/// different name is a different space. It is deliberately not a closed set
/// of the namespaces the engine recognises — a curated list's own spelling
/// is a namespace too, and refusing it would make the dimension unusable for
/// exactly the in-house truth sets that most need it
/// ([`KnownNamespace`](crate::dim::KnownNamespace) is what inference reads,
/// not what a declaration is checked against).
pub type IdentifierNamespace = Label;