Skip to main content

RDF data shapes implementation in Rust

Project description

SHAPES-rs

Shapes-rs dependency status

This repo contains an RDF data shapes library implemented in Rust. The implementation supports ShEx, SHACL, DCTap and conversions between different RDF data modeling formalisms.

The code can be used as a Rust library but it also contains a binary called rudof which can be used as an RDF playground.

We provide binaries for Linux, Windows, Mac and Docker (see releases), as well as Python bindings.

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/rudof_vX.X.X_amd64.deb
sudo dpkg -i rudof_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

The library is also published as a Docker image.

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

rudof 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

RDF Data shapes implementation in Rust

Usage: rudof [OPTIONS] [COMMAND]

Commands:
  shapemap        Information about ShEx shapemaps
  shex            Information about ShEx schemas
  validate        RDF Validation using ShEx or SHACL
  shex-validate   RDF Validation using ShEx schemas
  shacl-validate  RDF Validation using SHACL shapes
  data            Information about RDF data
  node            Information about RDF nodes which are part of RDF Graphs
  shacl           Information about SHACL shapes
  dctap           Information and processing of DCTAP files
  convert         Conversion between different Data modeling technologies
  help            Print this message or the help of the given subcommand(s)

Options:
  -d, --debug...  
  -h, --help      Print help (see more with '--help')
  -V, --version   Print version

Obtaining information about a ShEx schema

$ rudof shex --help
Information about ShEx schemas

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

Options:
  -s, --schema <Schema file name>
          
  -f, --format <Schema format>
          [default: shexc] [possible values: internal, shexc, shexj, turtle, ntriples, rdfxml, trig, n3, nquads]
  -r, --result-format <Result schema format>
          [default: shexj] [possible values: internal, shexc, shexj, turtle, ntriples, rdfxml, trig, n3, nquads]
  -t, --show elapsed time
          
      --statistics
          
  -o, --output-file <Output file name, default = terminal>
          
  -h, --help
          Print help

Obtaining information about RDF data

$ rudof data --help
Information about RDF data

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

Options:
  -d, --data <RDF data path>
          
  -t, --data-format <RDF Data format>
          [default: turtle] [possible values: turtle, ntriples, rdfxml, trig, n3, nquads]
  -o, --output-file <Output file name, default = terminal>
          
  -h, --help
          Print help

Obtaining information about a node in RDF data

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

$ rudof node --help
Information about RDF nodes which are part of RDF Graphs

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

Options:
  -n, --node <NODE>
          
  -d, --data <RDF data path>
          
  -t, --data-format <RDF Data format>
          [default: turtle] [possible values: turtle, ntriples, rdfxml, trig, n3, nquads]
  -e, --endpoint <Endpoint with RDF data>
          
  -m, --show-node-mode <Show Node Mode>
          [default: outgoing] [possible values: outgoing, incoming, both]
      --show hyperlinks
          
  -p, --predicates <PREDICATES>
          
  -o, --output-file <Output file name, default = terminal>
          
  -h, --help
          Print help

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

rudof node -e wikidata -n wd:Q80

Validating an RDF node against some data

$ rudof validate --help
RDF Validation using ShEx or SHACL

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

Options:
  -M, --mode <Validation mode>
          [default: shex] [possible values: shex, shacl]
  -s, --schema <Schema file name>
          
  -f, --schema-format <Schema format>
          [default: shexc] [possible values: internal, shexc, shexj, turtle, ntriples, rdfxml, trig, n3, nquads]
  -m, --shapemap <ShapeMap file name>
          
      --shapemap-format <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, ntriples, rdfxml, trig, n3, nquads]
  -e, --endpoint <Endpoint with RDF data>
          
      --max-steps <max steps to run>
          [default: 100]
  -o, --output-file <Output file name, default = terminal>
          
  -h, --help
          Print help

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:

rudof 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:

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

Validating an RDF node against some SHACL Shape

rudof shacl-validate --shapes examples/simple_shacl.ttl --data examples/simple.ttl

Conversion between shapes formalisms

$ rudof convert --help
Conversion between different Data modeling technologies

Usage: rudof convert [OPTIONS] --input-mode <Input mode> --source-file <Source file name> --export-mode <Result mode>

Options:
  -m, --input-mode <Input mode>
          [possible values: shex, dctap]
  -s, --source-file <Source file name>
          
  -f, --format <Input file format>
          [default: shexc] [possible values: csv, shexc, shexj, turtle]
  -r, --result-format <Result format>
          [default: default] [possible values: default, internal, json, shexc, shexj, turtle, plantuml, html, svg, png]
  -o, --output-file <Output file name, default = terminal>
          
  -t, --target-folder <Target folder>
          
  -l, --shape-label <shape label (default = START)>
          
  -x, --export-mode <Result mode>
          [possible values: sparql, shex, uml, html]
  -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.
  • shacl_validation contains the code required to validate RDF using SHACL.
  • dctap contains the code required to do handle DCTAP files.
  • shapes_converter contains the code required to do conversion between different shapes formalisms.

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 conformance tests for ShEx

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rudof-0.1.12-cp37-abi3-win_amd64.whl (555.6 kB view details)

Uploaded CPython 3.7+Windows x86-64

rudof-0.1.12-cp37-abi3-win32.whl (509.0 kB view details)

Uploaded CPython 3.7+Windows x86

rudof-0.1.12-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (781.9 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ x86-64

rudof-0.1.12-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (746.6 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARMv7l

rudof-0.1.12-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (763.6 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

rudof-0.1.12-cp37-abi3-macosx_10_12_x86_64.whl (707.5 kB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file rudof-0.1.12-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: rudof-0.1.12-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 555.6 kB
  • Tags: CPython 3.7+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.0

File hashes

Hashes for rudof-0.1.12-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f445bc1639d90027c118f2b5ffe9b0a68e2df4904e9bb21d444e4aa7446bd4f4
MD5 d39865923f340e2464ac4d1fce9493f1
BLAKE2b-256 c2d08d1ac29654626b113c8c29d680f2ca4c3db9ca1c72ef1fd53928bf731659

See more details on using hashes here.

File details

Details for the file rudof-0.1.12-cp37-abi3-win32.whl.

File metadata

  • Download URL: rudof-0.1.12-cp37-abi3-win32.whl
  • Upload date:
  • Size: 509.0 kB
  • Tags: CPython 3.7+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.0

File hashes

Hashes for rudof-0.1.12-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 9db3cf17203266bfa1091bbcefb11f094c4a0a76618c838ff5afc3c5c1f604b9
MD5 b4657feca0e31f0c02d152e13fa5d631
BLAKE2b-256 8b42f81595314e06f71fc935794bb539e8e8ef4a96f9670f3fa2d7e0d9c79d60

See more details on using hashes here.

File details

Details for the file rudof-0.1.12-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rudof-0.1.12-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 42e953fe7e4ec4dab0e7fca2c35110632517c67779b259fa83ddf404ac781972
MD5 3e7f9d5ce705e82bf07982ecbe0057e1
BLAKE2b-256 06e00239984c2dcf59c41647a24966a12a7864650fd4eeb7de0009be293b978c

See more details on using hashes here.

File details

Details for the file rudof-0.1.12-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for rudof-0.1.12-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 8dc5de4fab57f9d8ffaebb354e14a7d18135b4eafa1f9091c20cffb03d40711a
MD5 23c7a5ecc6567c92112fe0e310639e2d
BLAKE2b-256 e8db228b301e4c7a25077eded30c8c873cd835b102a382119c147dff34ae9512

See more details on using hashes here.

File details

Details for the file rudof-0.1.12-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rudof-0.1.12-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1e4d221a49cb5f7f0805ee71fcc6c82b7496d60d5ab77095ab56c2c406257ed1
MD5 898ab3766a80eacd28d73eacb1adbc57
BLAKE2b-256 e62abe7b537405be0a8b7c6ec123f1b06462dc9dd87bf6da4cf773c3b6e95103

See more details on using hashes here.

File details

Details for the file rudof-0.1.12-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for rudof-0.1.12-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c878cdb0895187f2a5fd6fef962cdb6d747abe8ffd037f6893b288ab6cef3d95
MD5 5d32e95afc6fb7d5ad100f399a69326b
BLAKE2b-256 3d785210f7b0f2188409c827dd4822146358453d24ea4299e34947476ab5fb93

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page