Scala implementation of SHEX and SHACL.
Both are implemented in Scala using the same underlying mechanism using a purely functional approach.
The library handles RDF using a simple RDF library 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 project uses sbt for compilation as well as Java 1.8.
sbt testcompiles and runs the tests
Command line usage
Once compiled, the program can be run as a command line tool.
It is possible to run the program inside
Validating RDF data with SHACL
sbt "run --data examples/shacl/good1.ttl --engine ShaClex"
Validating RDF with ShEx
sbt "run --engine=ShEx --schema examples/shex/good1.shex --schemaFormat ShExC --data examples/shex/good1.ttl"
Validating RDF data through an SPARQL endpoint
The following example validates RDF nodes from wikidata using Gene-wiki ShEx:
sbt "run --endpoint=https://query.wikidata.org/sparql --schemaUrl=https://raw.githubusercontent.com/SuLab/Genewiki-ShEx/master/diseases/wikidata-disease-ontology.shex --shapeMap=examples/shex/wikidata/disease1.shapeMap --schemaFormat=ShExC --engine=ShEx --trigger=ShapeMap --showResult --resultFormat=JSON"
Interactive mode with
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
The fastest way to run Shaclex is to compile the code and generate a binary. The following command:
$ sbt universal:packageBin ...generates the file... target/universal/shaclex-N.N.N.zip
which contains the compressed binary code.
The Shaclex library can be invoked programmatically.
- Simple project validating ShEx
- Simple example validating SHACL
- 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
The current implementation passes all shacl-core tests. In order to generate the EARL report, run:
$ sbt [...] sbt:shaclex> project shacl sbt:shacl> testOnly es.weso.shacl.report.ReportGeneratorCompatTest
We also aim to pass the ShEx test-suite.
In order to run the shex test-suite and generate the EARL report, you can do the following:
sbt ... sbt:shaclex> project shex sbt:shex> compat:test
Convert between Schema formats
Shaclex can be used to convert between different schemas. The following example shows how to convert between ShExC to ShExJ:
$ sbt "run --schema examples/shex/good1.shex --schemaFormat ShExC --outSchemaFormat ShExJ --showSchema"
- The aim of Shaclex is to support both ShEx and SHACL and to provide conversions between both languages. More information about both languages can be read in the Validating RDF data written by the authors.
- An online demo based on this library is available at http://rdfshape.weso.es.
- Another online demo based on this library customized for Wikidata is available at http://wikidata.weso.es.
- This project was based on ShExcala which was focused on Shape Expressions only.
Author & contributors
- Author: Jose Emilio Labra Gayo
- RDFShape: An online demo powered by this library.
- Wikishape: An online demo powered by this library for Wikidata.
- Eclipse lyo: An SDK and a modelling environment to design and develop linked data applications based on the OSLC standards. The validation library is lyo-validation.
Contributions are greatly appreciated. Please fork this repository and open a pull request to add more features or submit issues