Skip to content

Commit de7fae4

Browse files
authored
Merge pull request linkml#3272 from dalito/validate-tutorial
Validate tutorial as part of standard tests
2 parents 595b2d4 + 2baf8f2 commit de7fae4

33 files changed

Lines changed: 708 additions & 691 deletions

docs/intro/tutorial03.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ linkml-validate -s personinfo.yaml bad-data.yaml
7171

7272
Output:
7373

74-
```text
75-
[ERROR] [bad-data.yaml/0] '1-800-kryptonite' does not match '^[\\d\\(\\)\\-]+$' in /persons/0/phone
76-
[ERROR] [bad-data.yaml/0] 'full_name' is a required property in /persons/1
74+
```{literalinclude} ../../examples/tutorial/tutorial03/validate-bad-data-errors.txt
75+
:language: text
7776
```
7877

7978
This indicates there are two issues with our data. The first says that the phone number of the first entry in the persons list (`/persons/0/phone`) doesn’t conform to the regular expression syntax we stated. The second says that we are missing the required `full_name` slot on the second entry in the person list (`/persons/1`).
@@ -93,8 +92,8 @@ linkml-validate -s personinfo.yaml better-data.yaml
9392

9493
Output:
9594

96-
```text
97-
[ERROR] [better-data.yaml/0] '1-800-kryptonite' does not match '^[\\d\\(\\)\\-]+$' in /persons/0/phone
95+
```{literalinclude} ../../examples/tutorial/tutorial03/validate-better-data-errors.txt
96+
:language: text
9897
```
9998

10099
We have successfully fixed one of the issues with the data!

docs/intro/tutorial04.md

Lines changed: 10 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,8 @@ linkml-convert -s personinfo.yaml -t rdf data.yaml
4444

4545
Outputs:
4646

47-
```turtle
48-
@prefix ORCID: <https://orcid.org/> .
49-
@prefix personinfo: <https://w3id.org/linkml/examples/personinfo/> .
50-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
51-
52-
ORCID:1234 a personinfo:Person ;
53-
personinfo:age 33 ;
54-
personinfo:full_name "Clark Kent" ;
55-
personinfo:phone "555-555-5555" .
56-
57-
ORCID:4567 a personinfo:Person ;
58-
personinfo:age 34 ;
59-
personinfo:full_name "Lois Lane" .
60-
61-
[] a personinfo:Container ;
62-
personinfo:persons ORCID:1234,
63-
ORCID:4567 .
47+
```{literalinclude} ../../examples/tutorial/tutorial04/data.ttl
48+
:language: turtle
6449
```
6550

6651
Note that each person is now represented by an ORCID URI. This is a
@@ -90,25 +75,8 @@ linkml-convert -s personinfo-semantic.yaml -t rdf data.yaml
9075

9176
Outputs:
9277

93-
```turtle
94-
@prefix ORCID: <https://orcid.org/> .
95-
@prefix personinfo: <https://w3id.org/linkml/examples/personinfo/> .
96-
@prefix schema1: <http://schema.org/> .
97-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
98-
99-
ORCID:1234 a schema1:Person ;
100-
schema1:name "Clark Kent" ;
101-
schema1:telephone "555-555-5555" ;
102-
personinfo:age 33 .
103-
104-
ORCID:4567 a schema1:Person ;
105-
schema1:name "Lois Lane" ;
106-
personinfo:age 34 .
107-
108-
[] a personinfo:Container ;
109-
personinfo:persons ORCID:1234,
110-
ORCID:4567 .
111-
78+
```{literalinclude} ../../examples/tutorial/tutorial04/data-semantic.ttl
79+
:language: turtle
11280
```
11381

11482
Note that the prefixes are hidden but the effect is to reuse URIs such as [schema:telephone](http://schema.org/telephone)
@@ -127,41 +95,8 @@ gen-jsonld-context --no-metadata personinfo-semantic.yaml
12795

12896
Outputs:
12997

130-
```json
131-
{
132-
"@context": {
133-
"xsd": "http://www.w3.org/2001/XMLSchema#",
134-
"ORCID": "https://orcid.org/",
135-
"linkml": "https://w3id.org/linkml/",
136-
"personinfo": "https://w3id.org/linkml/examples/personinfo/",
137-
"schema": "http://schema.org/",
138-
"@vocab": "https://w3id.org/linkml/examples/personinfo/",
139-
"persons": {
140-
"@type": "schema:Person",
141-
"@id": "persons"
142-
},
143-
"age": {
144-
"@type": "xsd:integer",
145-
"@id": "age"
146-
},
147-
"aliases": {
148-
"@id": "aliases"
149-
},
150-
"full_name": {
151-
"@id": "schema:name"
152-
},
153-
"id": "@id",
154-
"phone": {
155-
"@id": "schema:telephone"
156-
},
157-
"Container": {
158-
"@id": "Container"
159-
},
160-
"Person": {
161-
"@id": "schema:Person"
162-
}
163-
}
164-
}
98+
```{literalinclude} ../../examples/tutorial/tutorial04/personinfo-semantic.context.jsonld
99+
:language: json
165100
```
166101

167102
NOTE: currently you need to declare your own type object and map this to `rdf:type` for typing information to be shown
@@ -177,68 +112,8 @@ gen-shex --no-metadata personinfo-semantic.yaml
177112

178113
Outputs:
179114

180-
```shex
181-
# metamodel_version: 1.7.0
182-
BASE <https://w3id.org/linkml/examples/personinfo/>
183-
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
184-
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
185-
PREFIX linkml: <https://w3id.org/linkml/>
186-
PREFIX schema1: <http://schema.org/>
187-
188-
189-
linkml:String xsd:string
190-
191-
linkml:Integer xsd:integer
192-
193-
linkml:Boolean xsd:boolean
194-
195-
linkml:Float xsd:float
196-
197-
linkml:Double xsd:double
198-
199-
linkml:Decimal xsd:decimal
200-
201-
linkml:Time xsd:time
202-
203-
linkml:Date xsd:date
204-
205-
linkml:Datetime xsd:dateTime
206-
207-
linkml:DateOrDatetime linkml:DateOrDatetime
208-
209-
linkml:Uriorcurie IRI
210-
211-
linkml:Curie xsd:string
212-
213-
linkml:Uri IRI
214-
215-
linkml:Ncname xsd:string
216-
217-
linkml:Objectidentifier IRI
218-
219-
linkml:Nodeidentifier NONLITERAL
220-
221-
linkml:Jsonpointer xsd:string
222-
223-
linkml:Jsonpath xsd:string
224-
225-
linkml:Sparqlpath xsd:string
226-
227-
<Container> CLOSED {
228-
( $<Container_tes> <persons> @<Person> * ;
229-
rdf:type [ <Container> ] ?
230-
)
231-
}
232-
233-
<Person> CLOSED {
234-
( $<Person_tes> ( schema1:name @linkml:String ;
235-
<aliases> @linkml:String * ;
236-
schema1:telephone @linkml:String ? ;
237-
<age> @linkml:Integer ?
238-
) ;
239-
rdf:type [ schema1:Person ]
240-
)
241-
}
115+
```{literalinclude} ../../examples/tutorial/tutorial04/personinfo-semantic.shex
116+
:language: shex
242117
```
243118

244119

@@ -250,46 +125,8 @@ Outputs:
250125

251126
<!-- compare_rdf -->
252127
<!-- NOTE: the order of properties is non-deterministic so we cannot compare string directly>
253-
```turtle
254-
@prefix personinfo: <https://w3id.org/linkml/examples/personinfo/> .
255-
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
256-
@prefix schema1: <http://schema.org/> .
257-
@prefix sh: <http://www.w3.org/ns/shacl#> .
258-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
259-
260-
personinfo:Container a sh:NodeShape ;
261-
sh:closed true ;
262-
sh:ignoredProperties ( rdf:type ) ;
263-
sh:property [ sh:class schema1:Person ;
264-
sh:nodeKind sh:IRI ;
265-
sh:order 0 ;
266-
sh:path personinfo:persons ] ;
267-
sh:targetClass personinfo:Container .
268-
269-
schema1:Person a sh:NodeShape ;
270-
sh:closed true ;
271-
sh:ignoredProperties ( rdf:type ) ;
272-
sh:property [ sh:maxCount 1 ;
273-
sh:maxInclusive 200 ;
274-
sh:minInclusive 0 ;
275-
sh:order 4 ;
276-
sh:path personinfo:age ],
277-
[ sh:description "name of the person" ;
278-
sh:maxCount 1 ;
279-
sh:minCount 1 ;
280-
sh:order 1 ;
281-
sh:path schema1:name ],
282-
[ sh:maxCount 1 ;
283-
sh:order 0 ;
284-
sh:path personinfo:id ],
285-
[ sh:description "other names for the person" ;
286-
sh:order 2 ;
287-
sh:path personinfo:aliases ],
288-
[ sh:maxCount 1 ;
289-
sh:order 3 ;
290-
sh:path schema1:telephone ;
291-
sh:pattern "^[\\d\\(\\)\\-]+$" ] ;
292-
sh:targetClass schema1:Person .
128+
```{literalinclude} ../../examples/tutorial/tutorial04/personinfo-semantic.shacl.ttl
129+
:language: turtle
293130
```
294131
295132
<!-- TODO: SPARQL -->

docs/intro/tutorial05.md

Lines changed: 10 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,8 @@ For illustration, we will take the schema we developed in the last section:
1313

1414
personinfo.yaml:
1515

16-
```yaml
17-
id: https://w3id.org/linkml/examples/personinfo
18-
name: personinfo
19-
prefixes: ## Note are adding 3 new ones here
20-
linkml: https://w3id.org/linkml/
21-
schema: http://schema.org/
22-
personinfo: https://w3id.org/linkml/examples/personinfo/
23-
ORCID: https://orcid.org/
24-
imports:
25-
- linkml:types
26-
default_range: string
27-
28-
classes:
29-
Person:
30-
class_uri: schema:Person ## reuse schema.org vocabulary
31-
attributes:
32-
id:
33-
identifier: true
34-
full_name:
35-
required: true
36-
description:
37-
name of the person
38-
slot_uri: schema:name ## reuse schema.org vocabulary
39-
aliases:
40-
multivalued: true
41-
description:
42-
other names for the person
43-
phone:
44-
pattern: "^[\\d\\(\\)\\-]+$"
45-
slot_uri: schema:telephone ## reuse schema.org vocabulary
46-
age:
47-
range: integer
48-
minimum_value: 0
49-
maximum_value: 200
50-
id_prefixes:
51-
- ORCID
52-
Container:
53-
attributes:
54-
persons:
55-
multivalued: true
56-
inlined_as_list: true
57-
range: Person
16+
```{literalinclude} ../../examples/tutorial/tutorial05/personinfo.yaml
17+
:language: yaml
5818
```
5919

6020
We can use a script that is distributed with LinkML to generate a python dataclasses model:
@@ -82,11 +42,8 @@ You can now write code like:
8242

8343
test.py:
8444

85-
```python
86-
from personinfo import Person
87-
88-
p1 = Person(id='ORCID:9876', full_name='Lex Luthor')
89-
print(p1)
45+
```{literalinclude} ../../examples/tutorial/tutorial05/test.py
46+
:language: python
9047
```
9148

9249
run this:
@@ -97,8 +54,8 @@ python test.py
9754

9855
Outputs:
9956

100-
```text
101-
Person(id='ORCID:9876', full_name='Lex Luthor', aliases=[], phone=None, age=None)
57+
```{literalinclude} ../../examples/tutorial/tutorial05/test-output.txt
58+
:language: text
10259
```
10360

10461
Hurray! Perhaps this is not very impressive in itself,
@@ -111,12 +68,8 @@ The LinkML runtime is a separate python library that provides methods needed by
11168

11269
test_runtime.py:
11370

114-
```python
115-
from linkml_runtime.dumpers import json_dumper
116-
from personinfo import Person
117-
118-
p1 = Person(id='ORCID:9876', full_name='Lex Luthor', aliases=["Bad Guy"])
119-
print(json_dumper.dumps(p1))
71+
```{literalinclude} ../../examples/tutorial/tutorial05/test_runtime.py
72+
:language: python
12073
```
12174

12275
```bash
@@ -125,15 +78,8 @@ python test_runtime.py
12578

12679
Outputs:
12780

128-
```text
129-
{
130-
"id": "ORCID:9876",
131-
"full_name": "Lex Luthor",
132-
"aliases": [
133-
"Bad Guy"
134-
],
135-
"@type": "Person"
136-
}
81+
```{literalinclude} ../../examples/tutorial/tutorial05/test-runtime-output.txt
82+
:language: text
13783
```
13884

13985
## Alternatives

0 commit comments

Comments
 (0)