76 
 
 
Chapter 11 SHACL 
 
Next, we will look at a plugin for SHACL. SHACL stands for Shapes Constraint Language. Note that 
shape in this context has nothing to do with geometric shapes. SHACL is somewhat newer than the other 
technologies described here. However, it fills an essential gap in the Semantic Web architecture stack, and 
it is gaining a lot of traction in the world of large-scale corporate development. The reason for SHACL 
may at first seem a bit hard to grasp. After all many of the constraints that SHACL can define for data can 
also be defined using Description Logic or SWRL which are more high level and a bit easier to use. So 
why even bother with SHACL? There are two reasons that SHACL is essential for real world use of 
Semantic Web and Knowledge Graph technology: 
1. The need to define constraints that aren’t limited by the Open World Assumption (OWA) and 
Monotonic reasoning.  
2. The fact that real world data is messy!  
11.1 OWA and Monotonic Reasoning 
As described in section 4.13 OWL uses the Open World Assumption (OWA) because it was designed for 
the Internet. However, the OWA makes certain kinds of constraint validation difficult or impossible. For 
example, it is common to have a data integrity constraint that all employees must have a social security 
number. While such an axiom can be defined in OWL it will seldom work when we want it to because of 
the OWA. The OWA means that there may be a social security number out there somewhere in the 
Internet but that the system just hasn’t found it yet. While this is true, to validate the integrity of corporate 
data just saying “well it is out there somewhere” won’t do. To validate data integrity we need to be able to 
fire off warnings when required data isn’t there so we need to use the Closed World Assumption (CWA).  
Monotonic reasoning is a byproduct of the fact that OWL and SWRL are based on logic. The OWL 
reasoners are essentially theorem provers. If you have ever studied mathematical proofs, you know that 
one of the classic ways to prove that something is invalid is to show that some variable has two different 
values. E.g., if our theorem implies that p = True and p = False then we have a contradiction. Each 
variable can only have one value. This is why SWRL rules can only add values to variables rather than 
change them. For more on this see the excellent presentation on SWRL by Martin O’Connor: 
https://protege.stanford.edu/conference/2009/slides/SWRL2009ProtegeConference.pdf  
This is why SPARQL often needs to be used rather than SWRL even though SWRL is more abstract and 
powerful. SWRL does not support non-monotonic reasoning whereas SPARQL does. Similarly, when 
validating data, we may want to take actions to change it, e.g., to coerce it into a proper standard format. 
To do that we need to change rather than add a value, i.e., we need non-monotonic reasoning.   
11.2 The Real World is Messy 
The other reason for SHACL is that real world data is messy.  Over the span of this tutorial, you may 
have experienced a point where you made an error, and the reasoner marked your ontology as invalid. If 
you haven’t, congratulations, but as you work with Protégé more you will experience it. This is another 
by product of using a logic-based language. Simply having one inconsistency makes the entire model 
invalid. For small examples this is not a problem. When one has tens, hundreds, or even thousands of 
individuals it isn’t that difficult to find the problem and fix it. However, when dealing with Big Data 
where one has tens of thousands, millions, or more individuals the prevalence of bad data may be huge.