labra / shaclex

SHACL/ShEx implementation

Version Matrix


SHACL and SHEX Implementation.

This project contains an implementation of SHACL and ShEx

CircleCI Build Status Codacy Badge DOI


This project contains an implementation of SHACL and ShEx.

Both are implemented in Scala using the same underlying mechanism using a purely functional approach.

The library handles RDF using a simple RDF interface which has 2 implementations, one using Apache Jena and another one using RDF4j, this means that it is possible to use this library to validate RDF models from any of those RDF libraries, as well as from external SPARQL endpoints.

Installation and compilation

The projects uses sbt for compilation as well as Java 1.8.

  • sbt test compiles and runs the tests


Once compiled, the program can be run as a command line tool. It is possible to run the program inside sbt as:

Validating RDF data with SHACL

Example with conformant RDF data:

sbt "run -d examples/shacl/good1.ttl --engine ShaClex"

Example with non-conformant RDF generating SHACL validation report:

sbt "run -d examples/shacl/bad1.ttl --engine ShaClex --showValidationReport --validationReportFormat TURTLE"

Validating RDF with ShEx


sbt "run -e ShEx -s examples/shex/good1.shex --schemaFormat ShExC -d examples/shex/good1.ttl"

Interactive mode with sbt

It is usually faster to run the sbt command, which opens the interactive sbt shell and inside that shell, execute the different commands.

$ sbt
... several information about loading libraries
sbt> run -d examples/shacl/good1.ttl --engine ShaClex  

Binary mode

The fastest way to run Shaclex is to compile the code and generate a binary. The following command:

$ sbt universal:packageBin  

generates the file:


which contains the compressed binary code.

Server mode

The --server option activates server mode.

sbt "run --server"

Implementation details

  • The engine is based on Monads using the cats library
  • The ShEx compact syntax parser
    is implemented using the following Antlr grammar (previous versions used Scala Parser Combinators) which is based on this grammar
  • JSON encoding and decoding uses the Json structure defined here and is implemented using Circe

Compatibility tests

We aim to pass the standard test-suites of ShEx and SHACL.

In order to run the test suite and generate the EARL report, you can do the following:

  • For ShEx, run sbt, select project shex and run compat:test for compatibility tests.

More information

This project is a based on ShExcala which was focused on Shape Expressions only. The aim of Shaclex is to support both ShEx and SHACL and to provide conversions between both languages.

Author & contributors




Contributions are greatly appreciated. Please fork this repository and open a pull request to add more features or submit issues