Skip to content
This repository was archived by the owner on Sep 1, 2021. It is now read-only.

Commit d69690c

Browse files
committed
CLI
1 parent 05123f7 commit d69690c

File tree

7 files changed

+405
-18
lines changed

7 files changed

+405
-18
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,27 @@
33
Extension to linkml-runtime for converting between instances of LinkML models and CSVs. This may involve selective normalization/denormalization, plus serialization of selected elements as JSON/YAML
44

55
This builds on [json-flattener](https://github.com/cmungall/json-flattener)
6+
7+
## Command Line Usage
8+
9+
Denormalizing conversion from YAML instance data to TSV
10+
11+
```
12+
link-convert \
13+
-s examples/bookshop.schema.yaml \
14+
-C Shop \
15+
-S all_book_series \
16+
-o examples/shop1.instance.tsv \
17+
examples/shop1.instance.yaml
18+
```
19+
20+
Converting back to YAML/JSON:
21+
22+
```
23+
link-convert \
24+
-s examples/bookshop.schema.yaml \
25+
-C Shop \
26+
-S all_book_series \
27+
-o examples/shop1-troundtrip.instance.json \
28+
examples/shop1.instance.tsv
29+
```

examples/bookshop.schema.yaml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
id: https://w3id.org/example
2+
name: example
3+
description: example
4+
imports:
5+
- linkml:types
6+
prefixes:
7+
linkml: https://w3id.org/linkml/
8+
example: https://w3id.org/example
9+
default_prefix: example
10+
types: {}
11+
classes:
12+
creative work:
13+
slots:
14+
- id
15+
- name
16+
- genres
17+
- creator
18+
- genres
19+
- summary
20+
- reviews
21+
book:
22+
is_a: creative work
23+
slots:
24+
- price
25+
- inStock
26+
book series:
27+
is_a: creative work
28+
slots:
29+
- books
30+
- genres
31+
- price
32+
author:
33+
slots:
34+
- name
35+
- genres
36+
- from_country
37+
shop:
38+
slots:
39+
- all_book_series
40+
country:
41+
slots:
42+
- name
43+
slot_usage:
44+
name:
45+
identifier: true
46+
review:
47+
slots:
48+
- creator
49+
- rating
50+
- review_text
51+
52+
53+
slots:
54+
id:
55+
range: string
56+
identifier: true
57+
examples:
58+
- value: '123'
59+
book_category:
60+
range: string
61+
examples:
62+
- value: book
63+
multivalued: true
64+
name:
65+
range: string
66+
examples:
67+
- value: Consider Phlebas
68+
price:
69+
range: float
70+
examples:
71+
- value: '7.99'
72+
inStock:
73+
range: string
74+
examples:
75+
- value: 'true'
76+
creator:
77+
range: author
78+
examples:
79+
- value: Ian M Banks
80+
genres:
81+
#range: genre_enum
82+
range: string
83+
multivalued: true
84+
from_country:
85+
range: country
86+
books:
87+
range: book
88+
multivalued: true
89+
inlined: true
90+
inlined_as_list: true
91+
all_book_series:
92+
range: book series
93+
multivalued: true
94+
inlined: true
95+
inlined_as_list: true
96+
summary:
97+
reviews:
98+
multivalued: true
99+
range: review
100+
rating:
101+
range: integer
102+
review_text:
103+
104+
enums:
105+
genre_enum:
106+
permissible_values:
107+
scifi:
108+
fantasy:
109+
western:
110+
romance:
111+
modern:
112+
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"all_book_series": [
3+
{
4+
"id": "S001",
5+
"name": "Lord of the Rings",
6+
"genres": [
7+
"fantasy"
8+
],
9+
"creator": {
10+
"name": "JRR Tolkein",
11+
"from_country": "England"
12+
},
13+
"books": [
14+
{
15+
"id": "S001.1",
16+
"name": "Fellowship of the Ring",
17+
"summary": "Hobbits",
18+
"price": 5.99
19+
},
20+
{
21+
"id": "S001.2",
22+
"name": "The Two Towers",
23+
"summary": "More hobbits",
24+
"price": 5.99
25+
},
26+
{
27+
"id": "S001.3",
28+
"name": "Return of the King",
29+
"summary": "Yet more hobbits",
30+
"price": 6.99
31+
}
32+
]
33+
},
34+
{
35+
"id": "S002",
36+
"name": "The Culture Series",
37+
"genres": [
38+
"scifi"
39+
],
40+
"creator": {
41+
"name": "Ian M Banks",
42+
"from_country": "Scotland"
43+
},
44+
"books": [
45+
{
46+
"id": "S002.1",
47+
"name": "Consider Phlebas",
48+
"price": 5.99
49+
},
50+
{
51+
"id": "S002.2",
52+
"name": "Player of Games",
53+
"price": 5.99
54+
}
55+
]
56+
},
57+
{
58+
"id": "S003",
59+
"name": "Book of the New Sun",
60+
"genres": [
61+
"scifi",
62+
"fantasy"
63+
],
64+
"creator": {
65+
"name": "Gene Wolfe",
66+
"genres": [
67+
"scifi",
68+
"fantasy"
69+
],
70+
"from_country": "USA"
71+
},
72+
"books": [
73+
{
74+
"id": "S003.1",
75+
"name": "Shadow of the Torturer"
76+
},
77+
{
78+
"id": "S003.2",
79+
"name": "Claw of the Conciliator",
80+
"price": 6.99
81+
}
82+
]
83+
},
84+
{
85+
"id": "S004",
86+
"name": "Example with single book",
87+
"creator": {
88+
"name": "Ms Writer",
89+
"genres": [
90+
"romance"
91+
],
92+
"from_country": "USA"
93+
},
94+
"books": [
95+
{
96+
"id": "S004.1",
97+
"name": "Blah"
98+
}
99+
]
100+
},
101+
{
102+
"id": "S005",
103+
"name": "Example with no books",
104+
"creator": {
105+
"name": "Mr Unproductive",
106+
"genres": [
107+
"romance",
108+
"scifi",
109+
"fantasy"
110+
],
111+
"from_country": "USA"
112+
}
113+
}
114+
],
115+
"@type": "Shop"
116+
}

examples/shop1.instance.tsv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
id name genres creator_json creator_name creator_from_country books_json books_summary books_price books_name books_id creator_genres
2+
S001 Lord of the Rings [fantasy] {\"name\": \"JRR Tolkein\", \"from_country\": \"England\"} JRR Tolkein England [{\"id\": \"S001.1\", \"name\": \"Fellowship of the Ring\", \"summary\": \"Hobbits\", \"price\": 5.99}, {\"id\": \"S001.2\", \"name\": \"The Two Towers\", \"summary\": \"More hobbits\", \"price\": 5.99}, {\"id\": \"S001.3\", \"name\": \"Return of the King\", \"summary\": \"Yet more hobbits\", \"price\": 6.99}] [Hobbits|More hobbits|Yet more hobbits] [5.99|5.99|6.99] [Fellowship of the Ring|The Two Towers|Return of the King] [S001.1|S001.2|S001.3]
3+
S002 The Culture Series [scifi] {\"name\": \"Ian M Banks\", \"from_country\": \"Scotland\"} Ian M Banks Scotland [{\"id\": \"S002.1\", \"name\": \"Consider Phlebas\", \"price\": 5.99}, {\"id\": \"S002.2\", \"name\": \"Player of Games\", \"price\": 5.99}] [5.99|5.99] [Consider Phlebas|Player of Games] [S002.1|S002.2]
4+
S003 Book of the New Sun [scifi|fantasy] {\"name\": \"Gene Wolfe\", \"genres\": [\"scifi\", \"fantasy\"], \"from_country\": \"USA\"} Gene Wolfe USA [{\"id\": \"S003.1\", \"name\": \"Shadow of the Torturer\"}, {\"id\": \"S003.2\", \"name\": \"Claw of the Conciliator\", \"price\": 6.99}] [|6.99] [Shadow of the Torturer|Claw of the Conciliator] [S003.1|S003.2] [scifi|fantasy]
5+
S004 Example with single book {\"name\": \"Ms Writer\", \"genres\": [\"romance\"], \"from_country\": \"USA\"} Ms Writer USA [{\"id\": \"S004.1\", \"name\": \"Blah\"}] [Blah] [S004.1] [romance]
6+
S005 Example with no books {\"name\": \"Mr Unproductive\", \"genres\": [\"romance\", \"scifi\", \"fantasy\"], \"from_country\": \"USA\"} Mr Unproductive USA [romance|scifi|fantasy]

examples/shop1.instance.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
all_book_series:
2+
- id: S001
3+
name: Lord of the Rings
4+
genres:
5+
- fantasy
6+
creator:
7+
name: JRR Tolkein
8+
from_country: England
9+
books:
10+
- id: S001.1
11+
name: Fellowship of the Ring
12+
price: 5.99
13+
summary: Hobbits
14+
- id: S001.2
15+
name: The Two Towers
16+
price: 5.99
17+
summary: More hobbits
18+
- id: S001.3
19+
name: Return of the King
20+
price: 6.99
21+
summary: Yet more hobbits
22+
- id: S002
23+
name: The Culture Series
24+
genres:
25+
- scifi
26+
creator:
27+
name: Ian M Banks
28+
from_country: Scotland
29+
books:
30+
- id: S002.1
31+
name: Consider Phlebas
32+
price: 5.99
33+
- id: S002.2
34+
name: Player of Games
35+
price: 5.99
36+
- id: S003
37+
name: Book of the New Sun
38+
genres:
39+
- scifi
40+
- fantasy
41+
creator:
42+
name: Gene Wolfe
43+
from_country: USA
44+
genres:
45+
- scifi
46+
- fantasy
47+
books:
48+
- id: S003.1
49+
name: Shadow of the Torturer
50+
# deliberately omit price information
51+
- id: S003.2
52+
name: Claw of the Conciliator
53+
price: 6.99
54+
- id: S004
55+
name: Example with single book
56+
creator:
57+
name: Ms Writer
58+
from_country: USA
59+
genres:
60+
- romance
61+
books:
62+
- id: S004.1
63+
name: Blah
64+
- id: S005
65+
name: Example with no books
66+
creator:
67+
name: Mr Unproductive
68+
from_country: USA
69+
genres:
70+
- romance
71+
- scifi
72+
- fantasy
73+

0 commit comments

Comments
 (0)