Skip to content

Commit

Permalink
Added basic shape expression testing
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed Oct 24, 2023
1 parent 3ab1ad6 commit 53b9dec
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/GroovyScriptTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Update the Open SbD4Nano Cache

on:
workflow_dispatch:
push:

jobs:
fetch-data:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0

- name: Install groovy
run: sudo apt install groovy

- name: Generate the Shex validation reports
run: |
groovy validate.groovy
14 changes: 14 additions & 0 deletions shapes/InteractionData.shex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BASE <http://bigcat-um.github.io/KinRDF/shapes#>
PREFIX : <http://bigcat-um.github.io/KinRDF/shapes#>

PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sbd: <https://www.sbd4nano.eu/rdf/#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wp: <http://vocabularies.wikipathways.org/wp#>

:InteractionData {
a [ wp:InteractionData ]
}
53 changes: 53 additions & 0 deletions validate.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// MIT, Copyright (c) Egon Willighagen
@Grab(group='io.github.egonw.bacting', module='managers-rdf', version='0.3.6')

import org.apache.jena.shex.ShexStatus

workspaceRoot = "."
rdf = new net.bioclipse.managers.RDFManager(workspaceRoot);

file = "/Output/RDF_Kin_Data_2022-Dec.ttl"
clazz = "InteractionData"

store = rdf.createInMemoryStore(true);
store = rdf.importFile(store, "${file}", "TURTLE")
report = rdf.validateAllOfType(
store,
"/shapes/${clazz}.shex",
"http://bigcat-um.github.io/KinRDF/shapes#${clazz}",
"http://vocabularies.wikipathways.org/wp#${clazz}"
)

println "{"
println " \"target\": \"${clazz}\","
println " \"conformant\": ["
report.forEachReport { reportEntry ->
status = reportEntry.status
reason = reportEntry.reason
focusNode = reportEntry.focus

switch (status) {
case ShexStatus.conformant :
println " {\n \"class\": \"${focusNode}\",\n \"status\": \"${status}\"\n },"
}
}
println " {}"
println " ],"
nonconformantCounter = 0
println " \"nonconformant\": ["
report.forEachReport { reportEntry ->
status = reportEntry.status
reason = reportEntry.reason
focusNode = reportEntry.focus

switch (status) {
case ShexStatus.nonconformant :
nonconformantCounter = nonconformantCounter + 1
println " {\n \"class\": \"${focusNode}\",\n \"status\": \"${status}\",\n \"reason\": \"${reason}\"\n },"
}
}
println " {}"
println " ]"
println "}"

if (nonconformantCounter > 0) System.exit(1)

0 comments on commit 53b9dec

Please sign in to comment.