Skip to content

Commit 8b72673

Browse files
committed
ci: update docs tooling
1 parent 153b1ee commit 8b72673

File tree

2 files changed

+130
-17
lines changed

2 files changed

+130
-17
lines changed

.github/workflows/docs.yml

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,78 @@
1-
# name: Build ontology docs
1+
name: SHACL Documentation Generation
22

3-
# on:
4-
# workflow_call:
3+
on:
4+
push:
5+
paths:
6+
- 'build/ontology/**'
7+
pull_request:
8+
paths:
9+
- 'build/ontology/**'
510

6-
# jobs:
11+
jobs:
12+
generate-docs:
13+
runs-on: ubuntu-latest
714

8-
# build:
9-
# runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
1018

11-
# steps:
19+
- name: Set up Python and install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install rdflib
1223
13-
# - uses: actions/checkout@v4
24+
- name: Enrich ontology with rdflib
25+
id: enrich
26+
run: |
27+
python tools/python/docs/sparql.py
28+
echo "enriched_file=/tmp/enriched.ttl" >> $GITHUB_ENV
29+
1430
15-
# - name: Set up Python
16-
# uses: actions/setup-python@v5
17-
# with:
18-
# python-version: '3.12'
31+
- name: Set up Java 11
32+
uses: actions/setup-java@v4
33+
with:
34+
distribution: 'temurin'
35+
java-version: '11'
1936

20-
# - name: Install dependencies
21-
# run: |
22-
# python -m pip install --upgrade pip
23-
# pip install
37+
- name: Install Graphviz
38+
run: |
39+
sudo apt-get update
40+
sudo apt-get install -y graphviz
2441
25-
# TODO: BUILD DOCUMENTATION USING RESPECTER
42+
- name: Set DOT_PATH environment variable
43+
run: echo "GRAPHVIZ_DOT=/usr/bin/dot" >> $GITHUB_ENV
44+
45+
- name: Download SHACL Play CLI
46+
run: |
47+
wget https://github.com/sparna-git/shacl-play/releases/download/0.10.2/shacl-play-app-0.10.2-onejar.jar -O shacl-play-cli.jar
48+
49+
- name: Generate Documentation
50+
run: |
51+
java -jar shacl-play-cli.jar \
52+
doc \
53+
-d \
54+
-i ${{ env.enriched_file }} \
55+
-l en \
56+
-o docs/index.html
57+
58+
- name: Generate Ontology Diagram
59+
run: |
60+
java -jar shacl-play-cli.jar \
61+
draw \
62+
-i ${{ env.enriched_file }} \
63+
-o docs/ontology.svg
64+
65+
- name: Commit generated docs
66+
run: |
67+
git config user.name "github-actions[bot]"
68+
git config user.email "github-actions[bot]@users.noreply.github.com"
69+
git add docs/index.html
70+
git add docs/ontology.svg
71+
git commit -m "Update generated docs" || echo "Nothing to commit"
72+
git push
73+
74+
- name: Upload generated documentation as an artifact
75+
uses: actions/upload-artifact@v4
76+
with:
77+
name: shacl-documentation
78+
path: docs/index.html

tools/python/docs/sparql.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from rdflib import Graph, Namespace, URIRef
2+
import tempfile
3+
import os
4+
5+
# Define SHACL namespace
6+
SH = Namespace("http://www.w3.org/ns/shacl#")
7+
8+
# Load the input ontology
9+
g = Graph()
10+
g.parse("build/ontology_combined.ttl", format="turtle")
11+
12+
to_replace = []
13+
for s, p, o in g.triples((None, SH.node, None)):
14+
to_replace.append((s, p, o))
15+
16+
for s, p, o in to_replace:
17+
g.remove((s, p, o))
18+
g.add((s, SH.term("notanode"), o))
19+
20+
insert_query = """
21+
PREFIX sh: <http://www.w3.org/ns/shacl#>
22+
INSERT {
23+
?parentShape sh:node ?newNodeShape .
24+
?newNodeShape a sh:NodeShape .
25+
?newNodeShape sh:property ?innerPropertyShape .
26+
?innerPropertyShape ?p ?o .
27+
}
28+
WHERE {
29+
?parentShape sh:notanode ?anonShape .
30+
?anonShape sh:property ?innerPropertyShape .
31+
?innerPropertyShape sh:hasValue ?val ;
32+
?p ?o .
33+
FILTER(isIRI(?val))
34+
FILTER(isBlank(?anonShape))
35+
FILTER(isBlank(?innerPropertyShape))
36+
BIND(IRI(CONCAT(STR(?val), "Shape")) AS ?newNodeShape)
37+
}
38+
"""
39+
g.update(insert_query)
40+
41+
delete_query = """
42+
PREFIX sh: <http://www.w3.org/ns/shacl#>
43+
DELETE {
44+
?s sh:notanode ?something .
45+
}
46+
WHERE {
47+
?s sh:notanode ?something .
48+
}
49+
"""
50+
g.update(delete_query)
51+
52+
53+
# Use a predictable path for the enriched ontology
54+
enriched_file = "/tmp/enriched.ttl"
55+
ttl_data = g.serialize(format="turtle")
56+
with open(enriched_file, "w") as f:
57+
f.write(ttl_data)
58+
print("Ontology enriched with new node shapes.")
59+
print(ttl_data)
60+
print(f"Enriched ontology saved to: {enriched_file}")

0 commit comments

Comments
 (0)