Skip to content

(SHACL) Validating RDF data using SHACL

Jose Emilio Labra Gayo edited this page Aug 14, 2024 · 10 revisions

(SHACL) Validating RDF data using SHACL

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.

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" .

For SHACL validation, we can use the generic validate command and the specific shacl-validate command.

Using the generic validate command:

rudof validate -M shacl -f turtle --schema examples/book.ttl examples/book_conformant.ttl

Using the specific shacl-validate command:

There is one shacl-validate command which can also be used. The difference is that instead of schema, it uses shapes and it doesn't require to specify a Mode:

rudof shacl-validate --shapes examples/book.ttl 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 run as:

rudof shacl-validate --shapes examples/book.ttl examples/book_non-conformant.ttl
Clone this wiki locally