shacl#

The shacl command allows validation of RDF files against SHACL shapes.

Usage:

corese-command shacl [-hRvw]
                            [-a=<shapesFormat>]
                            [-i=<rdfData>...] [-f=<inputFormat>]
                            [-o=<output>]  [-r=<outputFormat>]
                            [-c=<configFilePath>]
                            -s=<shaclShapes>  [-s=<shaclShapes>...]

Options and arguments:

  • -s, --shapes <file|URL> : Required path or URL of the file containing the SHACL shapes.

  • -a, -sf, --shape-format <format> : Serialization format of the SHACL shapes. Supported shape formats are listed below.

  • -i, --input-data <file|dir|pattern|URL> : Optional path to a file, directory, filename pattern, or URL containing the RDF data. Default: standard input.

  • -f, -if, --input-format <format> : Input format is automatically detected for files. Use this option with the standard input or if you want to force the input file format. Supported input formats are listed below.

  • -R, --recursive : Recursively input all the files in the input directory and sub-directories.

  • -o, --output-data <file> : Optional file path to save the validation report. Default: standard output.

  • -r, -of, --result-format <format> : Optional validation report format. Default: turtle. Supported report formats are listed below.

  • -c, --config, --init <path> : Optional path to the configuration file.

  • -w, --no-owl-import : Disables the automatic import of referenced ontologies specified in ‘owl:imports’ statements in the profile.ttl file. Default: enabled.

  • -v, --verbose : Display verbose output.

  • -h, --help: Display sparql comamnd options.

Example:

To run this example you can download the sample data file beatles.rdf and the sample shapes file album_shapes.ttl.

The shapes file validates that each album has at least one track. The data file contains three albums, one with a track and two without. It also validates that all the songs have an integer length. The data file has one song that has a length.

corese-command shacl -i beatles.rdf -s album_shapes.ttl
@prefix xsh: <http://www.w3.org/ns/shacl#> .
@prefix ns1: <http://example.com/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<urn:uuid:09fa0411-395d-4a5e-8013-4b2c2d7c4586> a sh:ValidationResult ;
sh:focusNode ns1:McCartney ;
sh:resultMessage "Fail at: [sh:class <http://example.com/Song> ;
                            sh:minCount 1 ;
                            sh:path <http://example.com/track>]" ;
sh:resultPath ns1:track ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
sh:sourceShape _:b2 ;
sh:value 0 .

<urn:uuid:804cd082-d664-45af-8e7c-30562ec3da1c> a sh:ValidationResult ;
sh:focusNode ns1:Imagine ;
sh:resultMessage "Fail at: [sh:class <http://example.com/Song> ;
                            sh:minCount 1 ;
                            sh:path <http://example.com/track>]" ;
sh:resultPath ns1:track ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
sh:sourceShape _:b2 ;
sh:value 0 .

_:bb2 a sh:ValidationReport ;
sh:conforms false ;
sh:result <urn:uuid:09fa0411-395d-4a5e-8013-4b2c2d7c4586> ;
sh:result <urn:uuid:804cd082-d664-45af-8e7c-30562ec3da1c> .

For more examples, see the Getting Started Guide.

Input formats#

  • RDF/XML: rdfxml, rdf or application/rdf+xml

  • Turtle: turtle, ttl or text/turtle

  • TriG: trig or application/trig

  • JSON-LD: jsonld or application/ld+json

  • NTRIPLES: ntriples, nt or application/n-triples

  • NQUADS: nquads, nq, or application/n-quads

  • RDFa/HTML: rdfa, html, application/xhtml+xml

Output (report) formats#

  • RDF/XML: rdfxml, rdf or application/rdf+xml

  • Turtle: turtle, ttl or text/turtle

  • TriG: trig or application/trig

  • JSON-LD: jsonld or application/ld+json

  • NTRIPLES: ntriples, nt or application/n-triples

  • NQUADS: nquads, nq, or application/n-quads

  • RDFC: rdfc-1.0, rdfc-1.0-sha256, rdfc-1.0-sha384