13 releases

0.0.13 Jun 22, 2024
0.0.12 Jun 17, 2024
0.0.10 Jan 29, 2024
0.0.6 Dec 30, 2023
0.0.1 Mar 20, 2023

#3 in #shapes

Download history 17/week @ 2024-03-13 14/week @ 2024-03-20 24/week @ 2024-03-27 38/week @ 2024-04-03 13/week @ 2024-04-10 14/week @ 2024-04-17 16/week @ 2024-04-24 13/week @ 2024-05-01 6/week @ 2024-05-08 9/week @ 2024-05-15 18/week @ 2024-05-22 23/week @ 2024-05-29 201/week @ 2024-06-05 160/week @ 2024-06-12 258/week @ 2024-06-19 27/week @ 2024-06-26

647 downloads per month
Used in 14 crates

MIT/Apache

9KB
186 lines

Shapes-rs dependency status

SHAPES-rs

This repo contains an RDF data shapes library implemented in Rust. The implementation supports both ShEx and SHACL.

We provide binaries for Linux, Windows, Mac and Docker (see releases).

Installation

Official releases

You can download a binary from the latest release page. There you will also find the compiled packages for the installation on your system using a package manager.

Ubuntu

Download the binary from https://github.com/weso/shapes-rs/releases and install the .deb package running the following commands after replacing X.X.X by the latest version:

wget https://github.com/weso/shapes-rs/releases/download/X.X.X/rdfsx_vX.X.X_amd64.deb
sudo dpkg -i rdfsx_vX.X.X_amd64.deb
Windows

The binary can be downloaded from https://github.com/weso/shapes-rs/releases

Mac

The binary is available at: https://github.com/weso/shapes-rs/releases

Compiling from source

Compiling from source

shapes-rs has been implemented in Rust and is compiled using cargo. The command cargo run can be used to compile and run locally the code.

For example:

cargo run -- validate --data examples/user.ttl --schema examples/user.shex --shapemap examples/user.sm 

Compiling from source and installing the binary (Debian)

Install cargo deb (only the first time)

cargo install cargo-deb

Create the .deb package by:

cargo deb

And run:

sudo dpkg -i target/debian/shapes-rs_0.0.11-1_amd64.deb

Docker

TBD

Usage

Some examples

The folder examples contains several example files with ShEx schemas and RDF data.

Validate a simple RDF file with a ShEx schema using a ShapeMap
rdfsx validate --data examples/user.ttl --schema examples/user.shex --shapemap examples/user.sm

We maintain a Wiki page with some common Usage scenarios and How-to guides.

Debugging information

It is possible to change the debug level information with:

export RUST_LOG=value

where value can be debug to show more verbose information or info to show basic information.

Command line usage

$ rdfsx --help
Usage: sx [OPTIONS] [COMMAND]
Commands:
  schema
  validate
  data
  node
  help
          Print this message or the help of the given subcommand(s)

Obtaining information about a schema

Usage: rdfsx schema [OPTIONS] --schema <Schema file name>

Options:
  -s, --schema <Schema file name>
          
  -f, --schema-format <Schema format>
          [default: shexj] [possible values: internal, shexc, shexj]
  -r, --result-schema-format <Result schema format>
          [default: shexj] [possible values: internal, shexc, shexj]
  -h, --help
          Print help

Obtaining information about RDF data

Usage: rdfsx data [OPTIONS] --data <RDF data path>

Options:
  -d, --data <RDF data path>           
  -t, --data-format <RDF Data format>  [default: turtle] [possible values: turtle]
  -h, --help                           Print help

Obtaining information about a node in RDF data

This command can be useful to obtain the neighbourhood of a node.

Usage: rdfsx node [OPTIONS] --node <NODE>

Options:
  -n, --node <NODE>
          
  -d, --data <RDF data path>
          
  -t, --data-format <RDF Data format>
          [default: turtle] [possible values: turtle]
  -e, --endpoint <Endpoint with RDF data>
          
  -m, --show-node-mode <Show Node Mode>
          [default: outgoing] [possible values: outgoing, incoming, both]
  -h, --help
          Print help  

For example, the following command shows the neighbourhood of node wd:Q80 in the Wikidata endpoint.

rdfsx node -e wikidata -n wd:Q80

Validating an RDF node against some data

Example: Assuming there a ShEx file in examples/user.shex and an RDF turtle file in examples/user.ttl we can ask to validate node :a with shape label :User using:

rdfsx validate -s examples/user.shex -d examples/user.ttl -n :a -l :User

If there is a shapemap in examples/user.sm, we can validate using:

rdfsx validate -s examples/user.shex -d examples/user.ttl -m examples/user.sm

The full help for the validate subcommand is:

Usage: rdfsx validate [OPTIONS] --schema <Schema file name> --data <RDF data path>

Options:
  -s, --schema <Schema file name>
          
  -f, --schema-format <Schema format>
          [default: shexc] [possible values: internal, shexc, shexj]
  -m, --shapemap <ShapeMap file name>
          
      --shapemap-format <ShapeMap format>
          [default: compact] [possible values: compact, internal]
      --result-shapemap-format <Result shapemap format>
          [default: compact] [possible values: compact, internal]
  -n, --node <NODE>
          
  -l, --shape-label <shape label (default = START)>
          
  -d, --data <RDF data path>
          
  -t, --data-format <RDF Data format>
          [default: turtle] [possible values: turtle]
      --max-steps <max steps to run>
          [default: 100]
  -h, --help
          Print help

Main modules

The repo is divided in the following modules:

  • iri_s defines simple IRIs.
  • srdf simple RDF model which will be used for validation.
  • prefixmap Prefix maps implementation.
  • shapemap ShapeMap implementation.
  • shex_ast defines the ShEx Abstract syntax
  • shex_compact contains the code required to handle ShEx compact syntax.
  • shex_validation contains the code required to validate RDF using ShEx.
  • shex_testsuite contains the code required to run the ShEx testsuite.
  • shacl_ast defines the SHACL core Abstract syntax.

Publishing the crates

cargo workspaces publish 

Worskpaces

The project is using cargo workspaces wihch can be installed with:

cargo install cargo-workspaces

Unit-testing

In order to test all the sub-projects

cargo test --all

Testing one specific subproject:

cargo test -p shex_validation

Using the ShEx test-suite

The ShEx testsuite is included in a git submodule. In order to obtain it, it is necessary to do:

git submodule update --init --recursive
cargo run -p shex_testsuite
Usage: shex_testsuite [OPTIONS]

Options:
  -m, --manifest <Manifest FILE (.jsonld)>
          Name of Manifest file [default: shex_testsuite/shexTest/validation/manifest.jsonld]
  -c, --config <Config file>
          [default: shex_testsuite/config.yml]
  -x, --run_mode <MANIFEST_RUN_MODE>
          [default: collect-errors] [possible values: collect-errors, fail-first-error]
  -f, --manifest_mode <MANIFEST_MODE>
          [possible values: schemas, validation, negative-syntax, negative-structure]
  -p, --print_result_mode <PRINT_RESULT_MODE>
          [default: basic] [possible values: basic, failed, passed, not-implemented, all]
  -e, --entry <Entry names>
          
  -t, --trait <Trait names>
          
  -h, --help
          Print help
  -V, --version
          Print version

Validation tests

cargo run -p shex_testsuite -- -m shex_testsuite/shexTest/validation/manifest.jsonld validation 

Schemas tests

cargo run -p shex_testsuite -- -m shex_testsuite/shexTest/schemas/manifest.jsonld -f schemas -p failed

License

Licensed under either of

at your option.

Contributors

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

IRI simple wrapper

This module contains a simple wrapper to work with IRIs The main goal is that we can use a simple interface to work with IRIs which could be adapted to different implementations in the future if needed.

The library provides the macro [iri] to create IRIs from strings.

Dependencies

~1–1.6MB
~35K SLoC