Skip to content

Commit d81db2b

Browse files
authored
Merge pull request #163 from linkml/implements-metaslot
Adding implements metaslot
2 parents 0228f50 + 0bda6ee commit d81db2b

File tree

3 files changed

+125
-4
lines changed

3 files changed

+125
-4
lines changed

linkml_model/model/docs/specification/05validation.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,68 @@ here `T.uri` is used to determine the type:
240240

241241
## Inference of new values
242242

243+
## Schema Validation
244+
245+
A LinkML schema is a LinkML instance that conforms to the LinkML metamodel. As such, it can be validated
246+
in the same way as any other LinkML instance.
247+
248+
### Metamodel refinement using annotations
249+
250+
#### Background
251+
252+
The LinkML model provides a fixed set of metamodel slots which can be applied to any schema element.
253+
Any schema that assigns slot values not in the metamodel is invalid.
254+
255+
Sometimes it is useful to attach additional information to elements in a schema, this is called
256+
schema *extension*. Alternatively, it may be useful to be able to make the metamodel more restrictive
257+
in some contexts; for example, making the `description` metamodel slot `required` rather than `recommended`.
258+
259+
The LinkML metamodel can be effectively extended through the use of `annotation` slot assignments.
260+
Annotations are `tag`-`value` pairs.
261+
262+
As an example, if we want to add a metamodel slot `review` intended to store a review of a schema element.
263+
264+
```yaml
265+
classes:
266+
Person:
267+
annotations:
268+
review: A very useful class that is well defined
269+
...
270+
```
271+
272+
#### Annotation validation
273+
274+
By default, all annotation tags and values are valid.
275+
276+
LinkML 1.6 introduces the ability to validate annotation tags and values.
277+
278+
This is done by adding an `instantiates` slot-value assignment onto any schema element. The range of
279+
the `instantiates` slot is a `uriorcurie` that references a class that serves as a metamodel extension class.
280+
281+
If a schema element instantiates at least one class then *all* annotations are validated.
282+
283+
For example:
284+
285+
```yaml
286+
classes:
287+
Person:
288+
instantiates:
289+
- mymetamodel:Reviewable
290+
annotations:
291+
review: A very useful class that is well defined
292+
...
293+
```
294+
295+
The `Reviewable` class is defined as follows:
296+
297+
```yaml
298+
classes:
299+
Reviewable:
300+
class_uri: mymetamodel:Reviewable
301+
slots:
302+
description: an expert review of a schema element
303+
review: string
304+
```
243305

244306

245307

linkml_model/model/schema/meta.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ slots:
186186
into the schema for the implementing element. However, the referenced schema may be used to check
187187
conformance of the implementing element.
188188
multivalued: true
189+
190+
instantiates:
191+
domain: element
192+
range: uriorcurie
193+
description: >-
194+
An element in another schema which this element instantiates.
195+
multivalued: true
189196

190197
categories:
191198
range: uriorcurie
@@ -1518,7 +1525,6 @@ slots:
15181525
range: integer
15191526
inherited: true
15201527
description: the minimum number of entries for a multivalued slot
1521-
status: testing
15221528
in_subset:
15231529
- SpecificationSubset
15241530

@@ -1527,7 +1533,6 @@ slots:
15271533
range: integer
15281534
inherited: true
15291535
description: the maximum number of entries for a multivalued slot
1530-
status: testing
15311536
in_subset:
15321537
- SpecificationSubset
15331538

@@ -2371,6 +2376,8 @@ classes:
23712376
- modified_by
23722377
- status
23732378
- rank
2379+
- categories
2380+
- keywords
23742381
in_subset:
23752382
- BasicSubset
23762383

@@ -2392,6 +2399,7 @@ classes:
23922399
- local_names
23932400
- conforms_to
23942401
- implements
2402+
- instantiates
23952403
see_also:
23962404
- https://en.wikipedia.org/wiki/Data_element
23972405
in_subset:
@@ -2432,8 +2440,6 @@ classes:
24322440
- generation_date
24332441
- slot_names_unique
24342442
- settings
2435-
- categories
2436-
- keywords
24372443
see_also:
24382444
- https://en.wikipedia.org/wiki/Data_dictionary
24392445
close_mappings:
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
id: https://w3id.org/linkml/examples/enums
2+
title: Dynamic Enums Example
3+
name: dynamicenums-example
4+
description: This demonstrates the use of dynamic enums
5+
license: https://creativecommons.org/publicdomain/zero/1.0/
6+
7+
prefixes:
8+
linkml: https://w3id.org/linkml/
9+
linkml.measurements: https://w3id.org/linkml/measurements
10+
ex: https://w3id.org/linkml/examples/enums/
11+
sh: https://w3id.org/shacl/
12+
bioregistry: https://bioregistry.io/registry/
13+
MONDO: http://purl.obolibrary.org/obo/MONDO_
14+
NCIT: http://purl.obolibrary.org/obo/NCIT_
15+
loinc: http://loinc.org/
16+
17+
default_prefix: ex
18+
default_range: string
19+
20+
default_curi_maps:
21+
- semweb_context
22+
23+
emit_prefixes:
24+
- linkml
25+
- rdf
26+
- rdfs
27+
- xsd
28+
- owl
29+
30+
imports:
31+
- linkml:types
32+
33+
34+
#==================================
35+
# Classes #
36+
#==================================
37+
38+
classes:
39+
Measurement:
40+
description: a measurement
41+
implements:
42+
- linkml.measurements:Measurement
43+
attributes:
44+
value:
45+
range: float
46+
description: the numeric value
47+
implements:
48+
- linkml.measurements:value
49+
unit:
50+
range: string
51+
description: the unit
52+
implements:
53+
- linkml.measurements:unit

0 commit comments

Comments
 (0)