Skip to content

Commit

Permalink
Merge pull request #8 from SEMICeu/shape-script
Browse files Browse the repository at this point in the history
Generate shape on GH Pages with owl:imports replaced by actual contents
  • Loading branch information
pietercolpaert authored Mar 26, 2024
2 parents 49e746d + ee56835 commit 1986e01
Show file tree
Hide file tree
Showing 6 changed files with 741 additions and 8 deletions.
36 changes: 30 additions & 6 deletions .github/workflows/build-shape-ttl.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
name: CI
name: Shape
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
# Run workflow every day at 5:30
schedule:
- cron: '30 5 * * *'
# Run workflow when new commits are pushed to the repository (shape.ttl might have changed)
push:
branches: [ "main" ]
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
# This workflow contains two jobs: first it checks if new commits were made to the upstream repo, and if so, it runs the second job
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- run: curl -s https://api.github.com/repos/SEMICeu/DCAT-AP/commits/master | jq -r "((now - (.commit.author.date | fromdateiso8601) ) / (60*60*24) | trunc)"

build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# In case the workflow was triggered because of the schedule, the DCAT-AP repo must contain new commits to proceed
if: ${{ github.event_name != 'schedule' || github.steps.check.conclusion == 'success' }}

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- run: cd shacl-shapes-generator/
- name: Install dependencies
run: npm ci
- name: Build the script
run: npm run build

# Runs a single command using the runners shell
- name: Fetch the owl:imports, remove the owl:imports triples into shape.ttl
run: echo Hello, world!
run: node .
- run: cd ..

- name: Deploy everything to GH pages
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gh-pages-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Spec
on:
workflow_dispatch: {}
pull_request: {}
Expand All @@ -11,7 +11,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: w3c/spec-prod@v2
with:
TOOLCHAIN: bikeshed
Expand Down
50 changes: 50 additions & 0 deletions shacl-shapes-generator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as fs from 'fs';
import arrayifyStream from "arrayify-stream";
import N3 from "n3";
import got from "got-cjs";

async function main() {
const parser = new N3.StreamParser();
const store = new N3.Store();
const shape = fs.createReadStream("../shape.ttl");
shape.pipe(parser);
store.addQuads(await arrayifyStream(parser));

// Check for owl:imports and add the imported quads to the store
let imports = store.getQuads(null, "http://www.w3.org/2002/07/owl#imports", null, null);
while (imports.length > 0) {
for (const quad of imports) {
// Import the file
const importUrl = quad.object.value;
const importParser = new N3.StreamParser();
got.stream(importUrl).pipe(importParser);
store.addQuads(await arrayifyStream(importParser));

// Remove that owl:imports quad
store.removeQuad(quad);
}
imports = store.getQuads(null, "http://www.w3.org/2002/07/owl#imports", null, null);
}


// Add all quads to the writer
const writer = new N3.Writer(fs.createWriteStream('../shape.ttl'), {
prefixes: {
dcatapfeeds: "https://semiceu.github.io/LDES-DCAT-AP-feeds/shape.ttl#",
sh: "http://www.w3.org/ns/shacl#",
owl: "http://www.w3.org/2002/07/owl#",
as: "https://www.w3.org/ns/activitystreams#",
dcatap: "http://data.europa.eu/r5r/shacl_shapes#",
xsd: "http://www.w3.org/2001/XMLSchema#",
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
rdfs: "http://www.w3.org/2000/01/rdf-schema#",
vcard: "http://www.w3.org/2006/vcard/ns#",
}
});
for (const quad of store) {
writer.addQuad(quad);
}
writer.end();
}

main().catch(console.error);
Loading

0 comments on commit 1986e01

Please sign in to comment.