rudof shacl

rudof shacl reads SHACL shapes and shows them, converts them to other formats, and shows how rudof classifies recursive shapes. SHACL is the W3C Recommendation for the validation of RDF data.

The SHACL command can be used to obtain information about a SHACL shapes graph.

Assuming that a file simple_shacl.ttl contains the following data:

@prefix :       <http://example.org/> .
@prefix sh:     <http://www.w3.org/ns/shacl#> .
@prefix xsd:    <http://www.w3.org/2001/XMLSchema#> .

:Person a sh:NodeShape;
   sh:closed true ;
   sh:property [
    sh:path     :name ;
    sh:minCount 1;
    sh:maxCount 1;
    sh:datatype xsd:string ;
  ] ;
  sh:property [
   sh:path     :birthDate ;
   sh:maxCount 1;
   sh:datatype xsd:date ;
  ] ;
  sh:property [
   sh:path     :enrolledIn ;
   sh:node    :Course ;
  ] .
:Course a sh:NodeShape;
   sh:closed true ;
   sh:property [
    sh:path     :name ;
    sh:minCount 1;
    sh:maxCount 1;
    sh:datatype xsd:string ;
  ] .

The file can also obtained from the examples/simple_shacl.ttl.

curl -o simple_shacl.ttl https://raw.githubusercontent.com/rudof-project/rudof/refs/heads/master/examples/simple_shacl.ttl

The following command can be used to get information about a SHACL shapes graph:

rudof shacl -s simple_shacl.ttl

Convert from one format to another

It is also possible to read a SHACL shapes graph and convert it to some format

In the example below, rudof will read a SHACL file in Turle and convert it to RDF/XML.

rudof shacl -s simple_shacl.ttl -r rdfxml -o output.rdf

Checking whether shapes are recursive

-r internal shows the internal representation of the shapes graph. It includes a “Recursive shapes” section, which classifies each shape in a cyclic shape reference:

rudof shacl -s recursive_shapes.ttl -r internal

Each recursive shape is reported as one of:

  • Positive recursive: the cycle uses only monotonic constraints (sh:and, sh:or, sh:node, sh:property and others). It works with lfp and gfp.
  • Stratified recursive: the cycle also has a negating constraint (sh:not, sh:xone and others), but it points to a shape outside any recursion. rudof can resolve that shape on its own. It works with lfp and gfp.
  • Non-stratified recursive: a negating constraint in the cycle points back into a recursive shape, its own or another. There is no safe order to resolve it. rudof always rejects such a schema when it loads -s/--shapes.

The section does not list shapes outside cycles. If the schema has no recursion, the section shows “none”. See Recursive shapes for the full explanation, and for the choice between lfp and gfp with --recursion-semantics.

Options

$ rudof shacl --help
Show information about SHACL shapes

Usage: rudof shacl [OPTIONS] [DATA]...

Arguments:
  [DATA]...


Options:
  -t, --data-format <FORMAT>
          RDF Data format

          [default: turtle]
          [possible values: turtle, ntriples, rdfxml, trig, n3, nquads, jsonld, pg, html]

      --reader-mode <MODE>
          RDF Reader mode

          [default: strict]
          [possible values: lax, strict]

  -s, --shapes <INPUT>
          Shapes graph: File, URI or - for stdin, if not set, it assumes the shapes come from the data

  -f, --shapes-format <FORMAT>
          Shapes file format

          [default: turtle]
          [possible values: internal, turtle, ntriples, rdfxml, trig, n3, nquads, jsonld, json]

      --base-data <IRI>
          Base RDF Data (used to resolve relative IRIs in RDF data)

      --base-shapes <IRI>
          Base RDF Data (used to resolve relative IRIs in Shapes)

  -r, --result-shapes-format <FORMAT>
          Result shapes format

          [default: turtle]
          [possible values: internal, turtle, ntriples, rdfxml, trig, n3, nquads, jsonld, json]

  -c, --config-file <FILE>
          Config file name

  -o, --output-file <FILE>
          Output file name, default = terminal

      --force-overwrite
          Force overwrite to output file if it already exists

      --backend <BACKEND>
          Choose which backend to load the input into.

          - `memory` (default): parse into an in-process oxrdf::Graph. - `qlever`: launch a local QLever Docker container and index the input on disk. Requires the binary to be built with the `qlever` feature. - `lbug`: the connected LadybugDB property graph database (see `rudof connect`). Accepted here but not yet functional: rudof can derive a property graph from RDF (`load`/`ddl`) but cannot yet read one back out as RDF triples. - `endpoint=<URL_OR_NAME>`: query an external SPARQL endpoint by URL or by the name of an endpoint registered in the TOML config. See also the `--endpoint` / `-e` shortcut.

  -e, --endpoint <URL_OR_NAME>
          Shortcut for `--backend endpoint=<URL_OR_NAME>`.

          Accepts either a full SPARQL endpoint URL or the name of an endpoint registered in the TOML config. Mutually exclusive with `--backend`.

      --min-request-interval <MS>
          Minimum milliseconds between two requests to the SPARQL endpoint (-e/--endpoint only); default: the endpoint's configured value, else 1100 for remote hosts and 0 for localhost

      --max-concurrent-requests <N>
          Maximum requests in flight at once to the SPARQL endpoint (-e/--endpoint only); default 1

      --max-nodes-per-query <N>
          Maximum nodes fetched per SPARQL query when prefetching a shapemap's nodes (-e/--endpoint only); 1 disables batching; default 20

      --qlever-index-dir <DIR>
          Directory for the QLever on-disk index, overriding `[rdf.qlever] index_dir` from the TOML config.

          Only meaningful with `--backend qlever`. Naming a directory explicitly is how you find out (and share) where an index lives: pass the same directory again — from this machine or another rudof session pointed at the same path (e.g. a shared/mounted volume) — and the idempotent build step is skipped, going straight to serving. When unset, rudof resolves a per-input fingerprinted path under the platform cache dir and logs it at startup.

      --html-extract <MODE>
          RDF to read from HTML data: microdata, rdfa, jsonld or any (default: the config, else any)

          [possible values: microdata, rdfa, jsonld, any]

  -h, --help
          Print help (see a summary with '-h')

See also

  • RDF backends: where the data is (memory, QLever or a SPARQL endpoint).