Git Product home page Git Product logo

shapes's Introduction

Shape Repository For SkoHub

This is a repository for SHACL shapes used in SkoHub modules.

Shapes

skos.shacl.ttl

this is just a first draft, comments are very welcome

This shape is inspired by and borrows heavily from the SKOS-XL shape definition from EU Vocabularies.

Most adjustments were made regarding correcting syntax and pulling out the SPARQL-based constraints into dedicated shapes. At least with Apache Jena SHACL and pySHACL I got lots of different error messages when trying to use the shape as it is.

If you take our template repo as a starting point the validation against this shape is already built in.

Check with Apache Jena SHACL

To use this shape with Apache Jena SHACL validate your file with shacl validate --shapes skos.shacl.ttl --data YOUR-DATA.ttl

Check with Docker

To validate with the help of a docker container, you can run the script scripts/validate-skos:

./scripts/validate-skos YOUR_SKOS_FILE_TTL

Call with -h or without arguments to list options.

Add Validation in a vocabulary repository

Adding the following GitHub Action to a repository (add a .github/workflows/main.yaml file), will validate your vocabulary against the SkoHub Shape. Notice that, when the action is triggered, you will get an error shown in GitHub not only for violations but also for warnings. That is because GitHub Actions either pass or fail.

name: Validate TTL Files

on: [push]

jobs:
  check-for-warnings:
    name: Check for Warnings
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v3

    - name: Check for Warnings
      run: |
        curl -s https://raw.githubusercontent.com/skohub-io/shapes/main/scripts/checkForWarning.rq >> checkForWarning.rq
        find . -type f -name '*.ttl' | while read file; do
          # Adjust the file path to remove the './' part
          adjusted_file_path=$(echo "$file" | sed 's|^./||')
          echo "Processing $adjusted_file_path with Docker..."
          docker run --rm -v "$(pwd)/$adjusted_file_path:/rdf/test.ttl" skohub/jena:4.6.1 shacl validate --shapes https://raw.githubusercontent.com/skohub-io/shapes/main/skohub.shacl.ttl --data /rdf/test.ttl >> result.ttl
          validation_result="$(docker run --rm --mount type=bind,source=./checkForWarning.rq,target=/rdf/checkForViolation.rq --mount type=bind,source=./result.ttl,target=/rdf/result.ttl skohub/jena:4.6.1 arq --data /rdf/result.ttl --query /rdf/checkForViolation.rq)"
          echo $validation_result
          lines=$(echo "$validation_result" | wc -l )
          # Correct validation has 4 lines of output
          [[ ${lines} -eq 4 ]] || exit 1
        done

  check-for-errors:
    name: Check for Errors
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v3

    - name: Check for Errors
      run: |
        curl -s https://raw.githubusercontent.com/skohub-io/shapes/main/scripts/checkForViolation.rq >> checkForViolation.rq
        find . -type f -name '*.ttl' | while read file; do
          # Adjust the file path to remove the './' part
          adjusted_file_path=$(echo "$file" | sed 's|^./||')
          echo "Processing $adjusted_file_path with Docker..."
          docker run --rm -v "$(pwd)/$adjusted_file_path:/rdf/test.ttl" skohub/jena:4.6.1 shacl validate --shapes https://raw.githubusercontent.com/skohub-io/shapes/main/skohub.shacl.ttl --data /rdf/test.ttl >> result.ttl
          validation_result="$(docker run --rm --mount type=bind,source=./checkForViolation.rq,target=/rdf/checkForViolation.rq --mount type=bind,source=./result.ttl,target=/rdf/result.ttl skohub/jena:4.6.1 arq --data /rdf/result.ttl --query /rdf/checkForViolation.rq)"
          echo $validation_result
          lines=$(echo "$validation_result" | wc -l )
          # Correct validation has 4 lines of output
          [[ ${lines} -eq 4 ]] || exit 1
        done

Checked Constraints

All class and property definitions from the SKOS reference are added in the test files. All valid and invalid consistency examples are added to the test files.

Integrity conditions are checked by the skos.shacl.ttl shape.

Tests

There is some basis test functionality provided to test the shape. Currently there are not many tests provided, but the general idea is as follows:

  • build a small valid Concept Scheme for a node shape
  • build a small invalid Concept Scheme for a node shape
  • put these in the appropriate folders under test/
  • check if it works with scripts/test.sh

These tests are also run on every push via GitHub Actions.

It is very basic, but works like this:

  • all files in the valid folder are run against the shape. If the validation script exits with exit 1 it returns an error
  • all files in the invalid folder are run against the shape. If the validation script exits with exit 0 it returns an error

Feel free to suggest improvements or add more tests!

shapes's People

Contributors

acka47 avatar nichtich avatar sroertgen avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

nichtich

shapes's Issues

NoLinkToConceptScheme is to restrictive

With skohub-io/skohub-vocabs#230 we made it possible to only add one of the inverse relations 'hasTopConcept or topConceptOf in SkoHub Vocabs. The Shape does not reflect this change yet and thus a build won't start in skohub-docker-vocabs:

shapes/skos.shacl.ttl

Lines 156 to 175 in 61d50c3

:NoLinkToConceptScheme
a sh:NodeShape ;
sh:targetClass skos:Concept ;
sh:message "Orphaned concepts that are not linked to the ConceptScheme are not allowed." ;
sh:sparql [
a sh:SPARQLConstraint ;
sh:prefixes skos: ;
sh:select """
SELECT $this
WHERE {
$this a skos:Concept ;
FILTER (NOT EXISTS {
{$this skos:topConceptOf ?a }
UNION
{$this skos:inScheme ?a }
})
.
}""" ;
] ;
.

Split skos.shacl.ttl

The shapes file should better be split into e.g.

  • core SKOS integrity rules (see #3)
  • SKOS-XL rules
  • best practice (warning severity)
  • analysis rules (information severity)
  • additional rules from Skohub
  • additional rules from coli-conc/JSKOS
  • XKOS rules

SkoHub Shape

Build a shape that specifies SkoHub specific rules

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.