Hide menu

Hands-On Sessions: SHACL


SHACL is a language for validating RDF graphs against a set of conditions, referred to as shapes. The language can support a variety of use-cases beside validation, including user-interface generation, data integration, data transformation, and inferencing. The language became a W3C recommendation in July 2017, filling an important gap in the Semantic Web technology stack. The most important feature of SHACL is that it adds the ability to validate RDF data, which until now has required non-standardized solutions. In this tutorial, the focus is on the features of SHACL core for the use in validation.

Hands-on Exercises

The hands-on exercises will be done on an online platform prepared for the tutorial, which can be found here. The platform is based on SHACL.js, which is an an open-source implementation of SHACL. In the exercises, you will create and modify existing shapes to validate data from a subset of the Nobel Prize dataset. Some of the exercises will require you to modify the data graph to verify that your shapes have been designed correctly. Refer to Section 2.1 of the ontology specification for an overview of the ontology of this data. The SHACL properties required for the exercises are described in the tutorial slides and SHACL by example slides. The tasks are defined in increasing level of complexity, and at the end you will have a grasp of the core features of SHACL and how it can be used for validating RDF data. Tasks marked as "advanced" add additional complexity to a previous task.

  1. Start by selecting Data 1 and Shapes 1 in the dropdowns. Run the validator and try to understand the why the validation fails. Modify the shape so that the data is evaluated as valid.
  2. Add additional property node constraints to validate the datatypes for foaf:givenName, foaf:familyName and foaf:name as xsd:string. Modify the data graph to verify that your new constraints are working.
  3. (Advanced) Try to model the name constraints in the previous task using sh:alternativePath.
  4. Select Data 2 and Shape 2. Add a property constraint to ensure that all laureates have at least one dbo:affiliation to some dbo:University.
  5. Add another property constraint that requires dbp:dateOfBirth and foaf:birthday to have equal values. Will the shape pass validation if one of the properties are missing?
  6. (Advanced) Try to model a missing property in the task above using sh:or and cardinality restrictions.
  7. Select Data 3 and Shape 3 and confirm that the data validates correctly against the shapes graph. Now, create property shapes that validate foaf:name, foaf:givenName and foaf:familyName with regular expressions, using sh:pattern. Names should not be allowed to be shorter than two letters and must not contain underscores or numbers.
  8. Add a property constraint that limits the values of foaf:gender to either "male" or "female".
  9. (Extra) Take the validation to the next level by polishing your regex expressions further and add you own constraints regarding legal names.
  10. Add a constraint that requires all laureate awards to have a nobel:motivation that is a string of 10 characters or more. Allow only one motivation per language tag.

Page responsible: Olaf Hartig
Last updated: 2018-03-16