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.

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 run using the generic validate command:

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

There is one shacl-validate command which can also be used:

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