Skip to content

Commit

Permalink
Merge pull request #163 from linkml/implements-metaslot
Browse files Browse the repository at this point in the history
Adding implements metaslot
  • Loading branch information
cmungall committed Jul 12, 2023
2 parents 0228f50 + 0bda6ee commit d81db2b
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 4 deletions.
62 changes: 62 additions & 0 deletions linkml_model/model/docs/specification/05validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,68 @@ here `T.uri` is used to determine the type:

## Inference of new values

## Schema Validation

A LinkML schema is a LinkML instance that conforms to the LinkML metamodel. As such, it can be validated
in the same way as any other LinkML instance.

### Metamodel refinement using annotations

#### Background

The LinkML model provides a fixed set of metamodel slots which can be applied to any schema element.
Any schema that assigns slot values not in the metamodel is invalid.

Sometimes it is useful to attach additional information to elements in a schema, this is called
schema *extension*. Alternatively, it may be useful to be able to make the metamodel more restrictive
in some contexts; for example, making the `description` metamodel slot `required` rather than `recommended`.

The LinkML metamodel can be effectively extended through the use of `annotation` slot assignments.
Annotations are `tag`-`value` pairs.

As an example, if we want to add a metamodel slot `review` intended to store a review of a schema element.

```yaml
classes:
Person:
annotations:
review: A very useful class that is well defined
...
```

#### Annotation validation

By default, all annotation tags and values are valid.

LinkML 1.6 introduces the ability to validate annotation tags and values.

This is done by adding an `instantiates` slot-value assignment onto any schema element. The range of
the `instantiates` slot is a `uriorcurie` that references a class that serves as a metamodel extension class.

If a schema element instantiates at least one class then *all* annotations are validated.

For example:

```yaml
classes:
Person:
instantiates:
- mymetamodel:Reviewable
annotations:
review: A very useful class that is well defined
...
```

The `Reviewable` class is defined as follows:

```yaml
classes:
Reviewable:
class_uri: mymetamodel:Reviewable
slots:
description: an expert review of a schema element
review: string
```



14 changes: 10 additions & 4 deletions linkml_model/model/schema/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ slots:
into the schema for the implementing element. However, the referenced schema may be used to check
conformance of the implementing element.
multivalued: true

instantiates:
domain: element
range: uriorcurie
description: >-
An element in another schema which this element instantiates.
multivalued: true

categories:
range: uriorcurie
Expand Down Expand Up @@ -1518,7 +1525,6 @@ slots:
range: integer
inherited: true
description: the minimum number of entries for a multivalued slot
status: testing
in_subset:
- SpecificationSubset

Expand All @@ -1527,7 +1533,6 @@ slots:
range: integer
inherited: true
description: the maximum number of entries for a multivalued slot
status: testing
in_subset:
- SpecificationSubset

Expand Down Expand Up @@ -2371,6 +2376,8 @@ classes:
- modified_by
- status
- rank
- categories
- keywords
in_subset:
- BasicSubset

Expand All @@ -2392,6 +2399,7 @@ classes:
- local_names
- conforms_to
- implements
- instantiates
see_also:
- https://en.wikipedia.org/wiki/Data_element
in_subset:
Expand Down Expand Up @@ -2432,8 +2440,6 @@ classes:
- generation_date
- slot_names_unique
- settings
- categories
- keywords
see_also:
- https://en.wikipedia.org/wiki/Data_dictionary
close_mappings:
Expand Down
53 changes: 53 additions & 0 deletions tests/input/examples/schema_definition-implements.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
id: https://w3id.org/linkml/examples/enums
title: Dynamic Enums Example
name: dynamicenums-example
description: This demonstrates the use of dynamic enums
license: https://creativecommons.org/publicdomain/zero/1.0/

prefixes:
linkml: https://w3id.org/linkml/
linkml.measurements: https://w3id.org/linkml/measurements
ex: https://w3id.org/linkml/examples/enums/
sh: https://w3id.org/shacl/
bioregistry: https://bioregistry.io/registry/
MONDO: http://purl.obolibrary.org/obo/MONDO_
NCIT: http://purl.obolibrary.org/obo/NCIT_
loinc: http://loinc.org/

default_prefix: ex
default_range: string

default_curi_maps:
- semweb_context

emit_prefixes:
- linkml
- rdf
- rdfs
- xsd
- owl

imports:
- linkml:types


#==================================
# Classes #
#==================================

classes:
Measurement:
description: a measurement
implements:
- linkml.measurements:Measurement
attributes:
value:
range: float
description: the numeric value
implements:
- linkml.measurements:value
unit:
range: string
description: the unit
implements:
- linkml.measurements:unit

0 comments on commit d81db2b

Please sign in to comment.