Skip to content

Commit 96f18e5

Browse files
authored
Use LinkML for the ontologies (#36)
* fix * fix
1 parent fe04744 commit 96f18e5

25 files changed

Lines changed: 487 additions & 331 deletions

.github/workflows/ci.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,27 @@ jobs:
2222

2323
- uses: Jelly-RDF/setup-cli@v1
2424

25+
# We can't use the linkml-scala action because it doesn't support Turtle output...
26+
# which breaks our pretty prefixes.
27+
- name: Install linkml-scala
28+
run: |
29+
. <(curl -sSfL https://raw.githubusercontent.com/NeverBlink-OSS/linkml-scala/refs/heads/main/cli/install.sh)
30+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
31+
2532
- name: Install dependencies
2633
run: pip install -r requirements.txt
2734

35+
- name: 'Validate ontologies'
36+
run: |
37+
for f in ontology/*.yaml; do
38+
linkml-scala validate "$f"
39+
done
40+
2841
- name: 'Convert ontologies, prepare for publishing'
2942
run: |
3043
bin/build_ontology.sh
31-
rm docs/ontology/files/*.ttl
32-
cp publish/*.ttl docs/ontology/files/
44+
rm docs/ontology/files/turtle/*.ttl
45+
cp publish/*.ttl docs/ontology/files/turtle/
3346
ls -la publish/*
3447
3548
- name: Compile docs

.github/workflows/publish-dev.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,19 @@ jobs:
2424

2525
- uses: Jelly-RDF/setup-cli@v1
2626

27+
- name: Install linkml-scala
28+
run: |
29+
. <(curl -sSfL https://raw.githubusercontent.com/NeverBlink-OSS/linkml-scala/refs/heads/main/cli/install.sh)
30+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
31+
2732
- name: Install dependencies
2833
run: pip install -r requirements.txt
2934

3035
- name: 'Convert ontologies, prepare for publishing'
3136
run: |
3237
bin/build_ontology.sh
33-
rm docs/ontology/files/*.ttl
34-
cp publish/*.ttl docs/ontology/files/
38+
rm docs/ontology/files/turtle/*.ttl
39+
cp publish/*.ttl docs/ontology/files/turtle/
3540
3641
- name: Deploy site
3742
run: |

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,6 @@ __marimo__/
209209
# RDF-tensor
210210
*.code-workspace
211211
.idea/
212+
213+
# Generated ontology artifacts
214+
/publish/

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ authors:
1010
email: contact@neverblink.eu
1111
- name: Piotr Marciniak
1212
- name: Piotr Sowiński
13-
website: 'https://ostrzyciel.eu'
13+
website: 'https://github.com/Ostrzyciel'
1414
- name: RDF-tensor contributors
1515
website: >-
1616
https://github.com/NeverBlink-OSS/rdf-tensor/graphs/contributors

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,37 @@ This is an extension to RDF and SPARQL that introduces 2 new datatypes, dozens o
2222

2323
**[See the website](https://w3id.org/rdf-tensor) for more details.**
2424

25+
## Editing the ontology
26+
27+
The vocabulary (datatypes, functions, aggregates) is authored in [LinkML](https://linkml.io/) YAML files in the `ontology/` directory. The published RDF artifacts (RDFS in Turtle, N-Triples, JSON-LD, RDF/XML, and [Jelly](https://w3id.org/jelly)) are generated from these sources.
28+
29+
To regenerate the published files locally you need two tools in your `PATH`:
30+
31+
- [`linkml-scala`](https://github.com/NeverBlink-OSS/linkml-scala) – generates RDFS from the LinkML sources.
32+
- [`jelly-cli`](https://github.com/Jelly-RDF/cli) – converts between RDF serializations.
33+
34+
Then run, from the root of the repository:
35+
36+
```bash
37+
bin/build_ontology.sh
38+
```
39+
40+
The generated files are written to the `publish/` directory. CI runs the same script.
41+
2542
## Editing the documentation
2643

2744
1. Clone the repository: `git clone git@github.com:NeverBlink-OSS/rdf-tensor.git`
2845
2. Create a new Python virtual environment using your favorite tool (e.g., [`venv`](https://docs.python.org/3/library/venv.html)).
2946
3. Install the dependencies: `pip install -r requirements.txt`
30-
4. Compile the docs and host them locally for testing: `mkdocs serve`
31-
5. Whenever you make changes to the documentation pages (they reside in the `docs` directory), the docs will be automatically recompiled.
47+
4. Generate the ontology files so the docs can embed them: `bin/build_ontology.sh` (see above).
48+
5. Compile the docs and host them locally for testing: `mkdocs serve`
49+
6. Whenever you make changes to the documentation pages (they reside in the `docs` directory), the docs will be automatically recompiled.
3250

3351
## Authors, licensing
3452

35-
The original SPARQL extension and implementation for Jena were done by **[Piotr Marciniak](https://github.com/cinekele)** – see the [original repository](https://github.com/RDF-tensor/jena-datatensor).
53+
This repository is maintained and developed by **[NeverBlink](https://neverblink.eu)**.
3654

37-
The work is continued in this repository under the stewardship of [NeverBlink](https://neverblink.eu). The current maintainers are **[Piotr Sowiński (Ostrzyciel)](https://github.com/Ostrzyciel)** and **[Nik Kozlov](https://github.com/nk2ishere)**.
55+
The original SPARQL extension and implementation for Jena were done by **[Piotr Marciniak](https://github.com/cinekele)** – see the [original repository](https://github.com/RDF-tensor/jena-datatensor).
3856

3957
This repository is licensed under [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).
4058

bin/build_ontology.sh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/bin/bash
2+
set -euo pipefail
23

3-
# This script prepares the ontology files for publishing.
4-
# You need jelly-cli in your PATH for this script to work.
5-
# See: https://github.com/Jelly-RDF/cli
6-
4+
# This script generates the ontology files from the LinkML sources in ontology/
5+
# and prepares them for publishing.
6+
#
7+
# You need the following tools in your PATH for this script to work:
8+
# - linkml-scala (RDFS generation) https://github.com/NeverBlink-OSS/linkml-scala
9+
# - jelly-cli (format conversion) https://github.com/Jelly-RDF/cli
10+
#
711
# Run this script from the root of the repository.
812

913
formats=(
@@ -14,10 +18,15 @@ formats=(
1418
)
1519

1620
mkdir -p publish
17-
for file in ontology/*.ttl; do
18-
base_name=$(basename "$file" .ttl)
19-
jelly-cli rdf to-jelly --enable-namespace-declarations "$file" > publish/"$base_name".jelly
20-
# For each format, convert the jelly file to the desired format
21+
tmpdir=$(mktemp -d)
22+
trap 'rm -rf "$tmpdir"' EXIT
23+
24+
for file in ontology/*.yaml; do
25+
base_name=$(basename "$file" .yaml)
26+
# Generate RDFS (Turtle, so namespace prefixes are preserved) into an intermediate file.
27+
linkml-scala generate rdfs --format ttl --to "$tmpdir/$base_name.ttl" "$file"
28+
# Round-trip through Jelly to produce all published serializations consistently.
29+
jelly-cli rdf to-jelly --enable-namespace-declarations "$tmpdir/$base_name.ttl" > publish/"$base_name".jelly
2130
for format in "${formats[@]}"; do
2231
jelly-cli rdf from-jelly publish/"$base_name".jelly --to publish/"$base_name"."$format"
2332
done

docs/ontology/aggregates.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@
1111
| **JSON-LD** | [`https://w3id.org/rdf-tensor/aggregates.jsonld`](https://w3id.org/rdf-tensor/aggregates.jsonld) |
1212
| **RDF/XML** | [`https://w3id.org/rdf-tensor/aggregates.rdf`](https://w3id.org/rdf-tensor/aggregates.rdf) |
1313

14-
## Ontology source
14+
## Ontology source (LinkML)
15+
16+
[Source file](https://github.com/NeverBlink-OSS/rdf-tensor/blob/main/ontology/aggregates.yaml).
17+
18+
This LinkML source is converted to RDFS using [LinkML-Scala](https://github.com/NeverBlink-OSS/linkml-scala).
19+
20+
```yaml
21+
{% include "./files/linkml/aggregates.yaml" %}
22+
```
23+
24+
## Ontology source (Turtle)
1525

1626
```ttl
17-
{% include "./files/aggregates.ttl" %}
27+
{% include "./files/turtle/aggregates.ttl" %}
1828
```

docs/ontology/datatypes.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@
1111
| **JSON-LD** | [`https://w3id.org/rdf-tensor/datatypes.jsonld`](https://w3id.org/rdf-tensor/datatypes.jsonld) |
1212
| **RDF/XML** | [`https://w3id.org/rdf-tensor/datatypes.rdf`](https://w3id.org/rdf-tensor/datatypes.rdf) |
1313

14-
## Ontology source
14+
## Ontology source (LinkML)
15+
16+
[Source file](https://github.com/NeverBlink-OSS/rdf-tensor/blob/main/ontology/datatypes.yaml).
17+
18+
This LinkML source is converted to RDFS using [LinkML-Scala](https://github.com/NeverBlink-OSS/linkml-scala).
19+
20+
```yaml
21+
{% include "./files/linkml/datatypes.yaml" %}
22+
```
23+
24+
## Ontology source (Turtle)
1525

1626
```ttl
17-
{% include "./files/datatypes.ttl" %}
27+
{% include "./files/turtle/datatypes.ttl" %}
1828
```

docs/ontology/files/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/ontology/files/aggregates.ttl

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)