SHACL: Shapes Constraint Language (SHACL) for Ruby

This is a pure-Ruby library for working with the Shape Constraint Language to validate the shape of RDF graphs.

Gem Version Build Status Coverage Status Gitter chat


Implementation Report

Install with gem install shacl


The SHACL gem implements a SHACL Shape Expression engine.


require 'linkeddata'
require 'shacl'

graph = RDF::Graph.load("etc/doap.ttl")
shacl ="etc/doap.shacl")
report = shacl.execute(graph)
#=> ValidationReport(conform?, results*)

Command Line

TODO: When the linkeddata gem is installed, RDF.rb includes a rdf executable which acts as a wrapper to perform a number of different operations on RDF files, including SHACL. The commands specific to SHACL is

*shacl: Validate repository given shape

Using this command requires shacl, which references a URI or file path to the SHACL shapes graph. Other options are shape and focus.

Example usage:

rdf shacl \

The result will add the SHACL validation report to the output graph, optionally replacing the graph with the results, expressing the results as an s-expression, or adding the results as output messages.


Implementation Notes

Similar to the ShEx gem and to the general strategy for querying graphs in the SPARQL gem, the strategy is to parse SHACL shapes into executable operators, which are called recursively to create result sets corresponding to matched nodes and properties.

The shape graph is parsed into JSON-LD, and then converted into S-Expressions, which match the execution path. These S-Expressions can be parsed to recreate the executable shape constraints.

Evaluating the shapes against a graph results in a {SHACL::ValidationReport} indicating conformance, along with a set of individual {SHACL::ValidationResult} instances.

The resulting validation report can be compared with other validation reports, used as native Ruby objects, serialized to s-expressions, or used as an RDF::Enumerable to retrieve the RDF representation of the report, as defined in SHACL Spec.

Matching Entailed Triples

Many tests check for entailed triples, such as entailed super-classes of explicit rdf:type values. If this is required for a given application, the RDF::Reasoner gem can be used to create such entailed triples.

require 'shacl'
require 'rdf/reasoner'
graph = RDF::Graph.load("etc/doap.ttl")
shacl ="etc/doap.shacl")
results = shacl.execute(graph)
#=> [ValidationResult, ...]

Future work

This implementation is certainly not performant. Some things that can be be considered in future versions:



The recommended installation method is via RubyGems. To install the latest official release of RDF.rb, do:

% [sudo] gem install shacl


To get a local working copy of the development repository, do:

% git clone git://

Alternatively, download the latest development version as a tarball as follows:

% wget


Mailing List



This repository uses Git Flow to mange development and release activity. All submissions must be on a feature branch based on the develop branch to ease staging and integration.


This is free and unencumbered public domain software. For more information, see or the accompanying {file:LICENSE} file.