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

Commit

Permalink
CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
cmungall committed Jul 30, 2021
1 parent 05123f7 commit d69690c
Show file tree
Hide file tree
Showing 7 changed files with 405 additions and 18 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,27 @@
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

This builds on [json-flattener](https://github.com/cmungall/json-flattener)

## Command Line Usage

Denormalizing conversion from YAML instance data to TSV

```
link-convert \
-s examples/bookshop.schema.yaml \
-C Shop \
-S all_book_series \
-o examples/shop1.instance.tsv \
examples/shop1.instance.yaml
```

Converting back to YAML/JSON:

```
link-convert \
-s examples/bookshop.schema.yaml \
-C Shop \
-S all_book_series \
-o examples/shop1-troundtrip.instance.json \
examples/shop1.instance.tsv
```
112 changes: 112 additions & 0 deletions examples/bookshop.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
id: https://w3id.org/example
name: example
description: example
imports:
- linkml:types
prefixes:
linkml: https://w3id.org/linkml/
example: https://w3id.org/example
default_prefix: example
types: {}
classes:
creative work:
slots:
- id
- name
- genres
- creator
- genres
- summary
- reviews
book:
is_a: creative work
slots:
- price
- inStock
book series:
is_a: creative work
slots:
- books
- genres
- price
author:
slots:
- name
- genres
- from_country
shop:
slots:
- all_book_series
country:
slots:
- name
slot_usage:
name:
identifier: true
review:
slots:
- creator
- rating
- review_text


slots:
id:
range: string
identifier: true
examples:
- value: '123'
book_category:
range: string
examples:
- value: book
multivalued: true
name:
range: string
examples:
- value: Consider Phlebas
price:
range: float
examples:
- value: '7.99'
inStock:
range: string
examples:
- value: 'true'
creator:
range: author
examples:
- value: Ian M Banks
genres:
#range: genre_enum
range: string
multivalued: true
from_country:
range: country
books:
range: book
multivalued: true
inlined: true
inlined_as_list: true
all_book_series:
range: book series
multivalued: true
inlined: true
inlined_as_list: true
summary:
reviews:
multivalued: true
range: review
rating:
range: integer
review_text:

enums:
genre_enum:
permissible_values:
scifi:
fantasy:
western:
romance:
modern:

116 changes: 116 additions & 0 deletions examples/shop1-troundtrip.instance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"all_book_series": [
{
"id": "S001",
"name": "Lord of the Rings",
"genres": [
"fantasy"
],
"creator": {
"name": "JRR Tolkein",
"from_country": "England"
},
"books": [
{
"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
}
]
},
{
"id": "S002",
"name": "The Culture Series",
"genres": [
"scifi"
],
"creator": {
"name": "Ian M Banks",
"from_country": "Scotland"
},
"books": [
{
"id": "S002.1",
"name": "Consider Phlebas",
"price": 5.99
},
{
"id": "S002.2",
"name": "Player of Games",
"price": 5.99
}
]
},
{
"id": "S003",
"name": "Book of the New Sun",
"genres": [
"scifi",
"fantasy"
],
"creator": {
"name": "Gene Wolfe",
"genres": [
"scifi",
"fantasy"
],
"from_country": "USA"
},
"books": [
{
"id": "S003.1",
"name": "Shadow of the Torturer"
},
{
"id": "S003.2",
"name": "Claw of the Conciliator",
"price": 6.99
}
]
},
{
"id": "S004",
"name": "Example with single book",
"creator": {
"name": "Ms Writer",
"genres": [
"romance"
],
"from_country": "USA"
},
"books": [
{
"id": "S004.1",
"name": "Blah"
}
]
},
{
"id": "S005",
"name": "Example with no books",
"creator": {
"name": "Mr Unproductive",
"genres": [
"romance",
"scifi",
"fantasy"
],
"from_country": "USA"
}
}
],
"@type": "Shop"
}
6 changes: 6 additions & 0 deletions examples/shop1.instance.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id name genres creator_json creator_name creator_from_country books_json books_summary books_price books_name books_id creator_genres
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]
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]
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]
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]
S005 Example with no books {\"name\": \"Mr Unproductive\", \"genres\": [\"romance\", \"scifi\", \"fantasy\"], \"from_country\": \"USA\"} Mr Unproductive USA [romance|scifi|fantasy]
73 changes: 73 additions & 0 deletions examples/shop1.instance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
all_book_series:
- id: S001
name: Lord of the Rings
genres:
- fantasy
creator:
name: JRR Tolkein
from_country: England
books:
- id: S001.1
name: Fellowship of the Ring
price: 5.99
summary: Hobbits
- id: S001.2
name: The Two Towers
price: 5.99
summary: More hobbits
- id: S001.3
name: Return of the King
price: 6.99
summary: Yet more hobbits
- id: S002
name: The Culture Series
genres:
- scifi
creator:
name: Ian M Banks
from_country: Scotland
books:
- id: S002.1
name: Consider Phlebas
price: 5.99
- id: S002.2
name: Player of Games
price: 5.99
- id: S003
name: Book of the New Sun
genres:
- scifi
- fantasy
creator:
name: Gene Wolfe
from_country: USA
genres:
- scifi
- fantasy
books:
- id: S003.1
name: Shadow of the Torturer
# deliberately omit price information
- id: S003.2
name: Claw of the Conciliator
price: 6.99
- id: S004
name: Example with single book
creator:
name: Ms Writer
from_country: USA
genres:
- romance
books:
- id: S004.1
name: Blah
- id: S005
name: Example with no books
creator:
name: Mr Unproductive
from_country: USA
genres:
- romance
- scifi
- fantasy

Loading

0 comments on commit d69690c

Please sign in to comment.