top of page
IMG_20210701_190720.jpg
  • Magnus Bakken

Beginning Shacl Support

The Shapes Constraint Language (SHACL) allows knowledge graphs to be validated according to a rich set of rules. Shapes are used to find the parts of the graph that are subject to constraints. To allow interactive validation of the graph under construction, we have implemented a significant part of the SHACL recommendation in maplib. 



Whereas OTTR allows reusable templates for instantiating knowledge graphs in industry according to a standard, SHACL allows us to ensure to a greater degree that the standard is being followed, improving ease of reuse and resulting interoperability. Maplib crucially allows knowledge engineers to be immediately notified when a standard is incorrectly instantiated, allowing fast feedback and error correction. 


The Information Modeling Framework (IMF) introduced by the READI-project uses SHACL to ensure that both types and instances are correctly formed. We have adapted the example for mapping data about a pump located here (by OTTR creator Martin Skjæveland) to show how this works in maplib. In particular, we will be instantiating the nominal volumetric flow rate of a pump. The next part of the post is for technical readers, and we will be able to forgive you if you stop reading here.


Good, you kept going. The shape in the screenshotted file ("pump_shape.ttl") below states that relative to any instance A of <http://example.com/example/VolumetricFlowrate> , there should be exactly one B, such that:

A imf:value B


where B has the xsd:integer datatype with a value from 10 to 1000, and exactly one C such that:


A imf:uom C


which is an instance of <http://www.ontology-of-units-of-measure.org/resource/om-2/VolumetricFlowRate>.



We use one of the OTTR templates (simplified) that ship with IMF, to instantiate two such nominal volumetric flowrates. This template associates among other things a value and a unit of measure.



Now, we create a Mapping object with the templates, and load the SHACL file.



We load example attributes from a Parquet file.



Now we can instantiate the attributes - the nominal volumetric flow rates in the graph.



At any point after expanding templates, we may run SHACL validation. This produces a result that contains a report as specified by the SHACL recommendation. We only include the information here about:


  • the focus node - an instance of the targetClass <http://example.com/example/VolumetricFlowrate>)

  • the source constraint component, i.e. the constraint that failed validation

  • and the value (having some relation to the focus node) that failed to validate according to this constraint


It is possible to include other information in this report such as informative messages.



After shacl validation is done, we see that the MinInclusive constraint has been violated for the first nominal rate. This should come as no surprise, because this value 0 is lower than the minimum value of 10. Second, we see that the object of the imf:uom path for both nominal rates violates the Class constraint.


We can use the query functionality of maplib to see that indeed, the objects of imf:uom do not have a specified class at all, yet alone the class required. So we still have some work to do to be compliant!






Comments


Data Treehouse AS

Org. nr: 931 863 568

Contact

info@data-treehouse.com

Kobben Incubator,
Forskningsparken i Vestfold,

Raveien 205,
3184 Borre,

Norway

Follow

  • LinkedIn
bottom of page