Skip to content

(SHACL) Validating RDF data using SHACL

Ángel Iglesias Préstamo edited this page Aug 11, 2024 · 10 revisions

We will make use of the UserShape example in SHACL from the Validating RDF Data book to demonstrate tha capabilities of the SHACL validator we propose.

In case we want to perform the SHACL validation, it's as easy as executing the shacl-validate command provided a shapes and data graph. According to this, an RDF graph conforming to the example above is:

:alice a :User;                             #Passes as a :UserShape     
       schema:name           "Alice" ;
       schema:gender         schema:Female ;
       schema:knows          :bob .

:bob   a :User;                             #Passes as a :UserShape     
       schema:gender         schema:Male ;
       schema:name           "Robert";
       schema:birthDate      "1980-03-10"^^xsd:date .

:carol a :User;                             #Passes as a :UserShape     
       schema:name           "Carol" ;
       schema:gender         schema:Female ;
       foaf:name             "Carol" .

And can be executed by means of the following command:

cargo run -- shacl-validate --shapes examples/book.ttl --data examples/book_conformant.ttl

An example of a non-conforming data graph is the following:

:dave  a :User ;                        #Fails as a :UserShape     
       schema:name       "Dave";
       schema:gender     :Unknown ;
       schema:birthDate  1980 ;
       schema:knows      :grace .

:emily a :User ;                        #Fails as a :UserShape          
       schema:name       "Emily", "Emilee";
       schema:gender     schema:Female .

:frank a :User ;                        #Fails as a :UserShape     
       foaf:name         "Frank" ;
       schema:gender     schema:Male .

_:x    a :User;                         #Fails as a :UserShape          
       schema:name       "Unknown" ;
       schema:gender     schema:Male ;
       schema:knows      _:x .

And can be executed by means of the following command:

cargo run -- shacl-validate --shapes examples/book.ttl --data examples/book_non-conformant.ttl
Clone this wiki locally