|
| 1 | +# SHaclEX |
| 2 | + |
| 3 | +Scala implementation of SHEX and SHACL. |
| 4 | + |
| 5 | +This project contains an implementation of |
| 6 | +[SHACL](http://w3c.github.io/data-shapes/shacl/) and |
| 7 | +[ShEx](http://www.shex.io) |
| 8 | + |
| 9 | +[](https://travis-ci.org/labra/shaclex) |
| 10 | +[](https://www.codacy.com/app/jelabra/shaclex) |
| 11 | +[](https://doi.org/10.5281/zenodo.1214239) |
| 12 | + |
| 13 | +## Introduction |
| 14 | + |
| 15 | +This project contains an implementation of [SHACL](https://www.w3.org/TR/shacl/) and [ShEx](http://shex.io/). |
| 16 | + |
| 17 | +Both are implemented in Scala using the same underlying mechanism using a purely functional approach. |
| 18 | + |
| 19 | +The library handles RDF using a |
| 20 | +[simple RDF library](https://github.com/weso/srdf) |
| 21 | +which has 2 implementations, |
| 22 | +one using [Apache Jena](https://jena.apache.org/) |
| 23 | +and another one using [RDF4j](http://rdf4j.org/), |
| 24 | +this means that it is possible to use this library to validate RDF models from any of those RDF libraries, |
| 25 | +as well as from external SPARQL endpoints. |
| 26 | + |
| 27 | +## Installation and compilation |
| 28 | + |
| 29 | +The project uses [sbt](http://www.scala-sbt.org/) for compilation as well as Java 1.8. |
| 30 | + |
| 31 | +* `sbt test` compiles and runs the tests |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +Once compiled, the program can be run as a command line tool. |
| 36 | +It is possible to run the program inside `sbt` as: |
| 37 | + |
| 38 | +### Validating RDF data with SHACL |
| 39 | + |
| 40 | +Example: |
| 41 | + |
| 42 | +```sh |
| 43 | +sbt "run --data examples/shacl/good1.ttl |
| 44 | + --engine ShaClex" |
| 45 | +``` |
| 46 | + |
| 47 | +### Validating RDF with ShEx |
| 48 | + |
| 49 | +Example: |
| 50 | + |
| 51 | +```sh |
| 52 | +sbt "run --engine=ShEx |
| 53 | + --schema examples/shex/good1.shex |
| 54 | + --schemaFormat ShExC |
| 55 | + --data examples/shex/good1.ttl" |
| 56 | +``` |
| 57 | + |
| 58 | +### Validating RDF data through an SPARQL endpoint |
| 59 | + |
| 60 | +The following example validates RDF nodes from wikidata using [Gene-wiki ShEx](https://github.com/SuLab/Genewiki-ShEx): |
| 61 | + |
| 62 | +```sh |
| 63 | +sbt "run --endpoint=https://query.wikidata.org/sparql |
| 64 | + --schemaUrl=https://raw.githubusercontent.com/SuLab/Genewiki-ShEx/master/diseases/wikidata-disease-ontology.shex |
| 65 | + --shapeMap=examples/shex/wikidata/disease1.shapeMap |
| 66 | + --schemaFormat=ShExC |
| 67 | + --engine=ShEx |
| 68 | + --trigger=ShapeMap |
| 69 | + --showResult |
| 70 | + --resultFormat=JSON" |
| 71 | +``` |
| 72 | + |
| 73 | + |
| 74 | +### Interactive mode with `sbt` |
| 75 | + |
| 76 | +It is usually faster to run the `sbt` command, which opens the interactive `sbt` shell and inside that shell, execute |
| 77 | +the different commands. |
| 78 | + |
| 79 | +```sh |
| 80 | +$ sbt |
| 81 | +... several information about loading libraries |
| 82 | +sbt> run -d examples/shacl/good1.ttl --engine ShaClex |
| 83 | +``` |
| 84 | + |
| 85 | +### Binary mode |
| 86 | + |
| 87 | +The fastest way to run Shaclex is to compile the code and generate a binary. |
| 88 | +The following command: |
| 89 | + |
| 90 | +```sh |
| 91 | +$ sbt universal:packageBin |
| 92 | +...generates the file... |
| 93 | +target/universal/shaclex-N.N.N.zip |
| 94 | +``` |
| 95 | + |
| 96 | +which contains the compressed binary code. |
| 97 | + |
| 98 | +## Implementation details |
| 99 | + |
| 100 | +* The engine is based on Monads using the [cats library](http://typelevel.org/cats/) |
| 101 | +* The ShEx compact syntax parser |
| 102 | + is implemented using the following [Antlr grammar](https://github.com/shexSpec/grammar/blob/master/ShExDoc.g4) (previous versions used Scala Parser Combinators) |
| 103 | + which is based on this [grammar](https://github.com/shexSpec/shex.js/blob/master/doc/bnf) |
| 104 | +* JSON encoding and decoding uses the Json structure [defined here](https://shexspec.github.io/spec/) and is implemented using [Circe](https://github.com/travisbrown/circe) |
| 105 | + |
| 106 | +## Compatibility tests |
| 107 | + |
| 108 | +The current implementation passes all [shacl-core tests](https://w3c.github.io/data-shapes/data-shapes-test-suite/). |
| 109 | + In order to generate the EARL report, run: |
| 110 | + |
| 111 | +``` |
| 112 | +$ sbt |
| 113 | +[...] |
| 114 | +sbt:shaclex> project shacl |
| 115 | +sbt:shacl> testOnly es.weso.shacl.report.ReportGeneratorCompatTest |
| 116 | +``` |
| 117 | + |
| 118 | +We also aim to pass the [ShEx test-suite](https://github.com/shexSpec/shexTest). |
| 119 | + |
| 120 | +In order to run the shex test-suite and generate the EARL report, you can do the following: |
| 121 | + |
| 122 | +``` |
| 123 | +sbt |
| 124 | +... |
| 125 | +sbt:shaclex> project shex |
| 126 | +sbt:shex> compat:test |
| 127 | +``` |
| 128 | + |
| 129 | +## Convert between Schema formats |
| 130 | + |
| 131 | +Shaclex can be used to convert between different schemas. |
| 132 | +The following example shows how to convert between ShExC to ShExJ: |
| 133 | + |
| 134 | +``` |
| 135 | +$ sbt "run --schema examples/shex/good1.shex |
| 136 | + --schemaFormat ShExC |
| 137 | + --outSchemaFormat ShExJ |
| 138 | + --showSchema" |
| 139 | +``` |
| 140 | + |
| 141 | +## More information |
| 142 | + |
| 143 | +* The aim of Shaclex is to support both ShEx and SHACL and to provide conversions between both languages. |
| 144 | + More information about both languages can be read in the [Validating RDF data](http://book.validatingrdf.com) written by the authors. |
| 145 | +* An online demo based on this library is available at [http://rdfshape.weso.es](http://rdfshape.weso.es). |
| 146 | +* Another online demo based on this library customized for Wikidata is available at [http://wikidata.weso.es](http://wikidata.weso.es). |
| 147 | +* This project was based on [ShExcala](http://labra.github.io/ShExcala/) which was focused on Shape Expressions only. |
| 148 | + |
| 149 | +## Author & contributors |
| 150 | + |
| 151 | +* Author: [Jose Emilio Labra Gayo](http://labra.weso.es) |
| 152 | + |
| 153 | +Contributors: |
| 154 | + |
| 155 | +* [Eric Prud'hommeaux](https://www.w3.org/People/Eric/) |
| 156 | +* [Bogdan Roman](https://github.com/bogdanromanx) |
| 157 | +* [Toni Cebrían](http://www.tonicebrian.com/) |
| 158 | +* [Andrew Berezovskyi](https://github.com/berezovskyi) |
| 159 | + |
| 160 | +## Adopters |
| 161 | + |
| 162 | +* [RDFShape](http://rdfshape.weso.es): An online demo powered by this library. |
| 163 | +* [Wikishape](http://wikishape.weso.es): An online demo powered by this library for Wikidata. |
| 164 | +* [Eclipse lyo](http://www.eclipse.org/lyo/): An SDK and a modelling environment to design and develop linked data applications based on the [OSLC standards](http://open-services.net/). The validation library is [lyo-validation](https://github.com/eclipse/lyo-validation). |
| 165 | + |
| 166 | +## Contribution |
| 167 | + |
| 168 | +Contributions are greatly appreciated. |
| 169 | +Please fork this repository and open a |
| 170 | +pull request to add more features or [submit issues](https://github.com/labra/shaclex/issues) |
0 commit comments