Quick start

This page shows the main rudof tasks on a small example: inspect RDF data, validate it with ShEx and SHACL, query it with SPARQL, and convert a schema. Before you start, install rudof and make sure that rudof --version works.

Example files

Save these files in an empty folder.

person.ttl, the RDF data. The name of :carol is a number, so it is not valid:

prefix :       <http://example.org/>
prefix schema: <http://schema.org/>

:alice a schema:Person ;
    schema:name  "Alice" ;
    schema:knows :bob .

:bob a schema:Person ;
    schema:name  "Bob" .

:carol a schema:Person ;
    schema:name  23 .

person.shex, a ShEx schema:

prefix :       <http://example.org/>
prefix schema: <http://schema.org/>
prefix xsd:    <http://www.w3.org/2001/XMLSchema#>

:Person {
  schema:name  xsd:string ;
  schema:knows @:Person *
}

person.sm, a ShapeMap. It tells the validator which node to validate against which shape:

:alice@:Person, :bob@:Person, :carol@:Person

person-shapes.ttl, SHACL shapes with the same rules:

prefix :       <http://example.org/>
prefix schema: <http://schema.org/>
prefix sh:     <http://www.w3.org/ns/shacl#>
prefix xsd:    <http://www.w3.org/2001/XMLSchema#>

:PersonShape a sh:NodeShape ;
    sh:targetClass schema:Person ;
    sh:property [
        sh:path     schema:name ;
        sh:datatype xsd:string ;
        sh:minCount 1 ;
        sh:maxCount 1
    ] .

names.sparql, a SPARQL query:

prefix schema: <http://schema.org/>

select ?person ?name where {
  ?person schema:name ?name .
}

Inspect the data

rudof data reads RDF data and writes it back, by default as Turtle. The order of the triples can change between runs:

$ rudof data person.ttl
@prefix : <http://example.org/> .
@prefix schema: <http://schema.org/> .
:carol a schema:Person ;
	schema:name 23 .
:alice schema:knows :bob ;
	a schema:Person ;
	schema:name "Alice" .
:bob a schema:Person ;
	schema:name "Bob" .

rudof node shows the neighborhood of one node:

$ rudof node -n :alice person.ttl
Outgoing arcs
:alice
├─── schema:knows ─► :bob
├─── schema:name ─► "Alice"
└─── <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ─► schema:Person

Validate with ShEx

$ rudof shex-validate person.ttl --schema person.shex --shapemap person.sm
╭────────┬─────────┬────────┬──────────────────────────────────────────────────────────────────────╮
│ Node   │ Shape   │ Status │ Summary                                                              │
├────────┼─────────┼────────┼──────────────────────────────────────────────────────────────────────┤
│ :alice │ :Person │ OK     │ Shape passed :alice@:Person                                          │
├────────┼─────────┼────────┼──────────────────────────────────────────────────────────────────────┤
│ :bob   │ :Person │ OK     │ Shape passed :bob@:Person                                            │
├────────┼─────────┼────────┼──────────────────────────────────────────────────────────────────────┤
│ :carol │ :Person │ FAIL   │ property schema:name: Datatype error: found xsd:integer, expected x… │
╰────────┴─────────┴────────┴──────────────────────────────────────────────────────────────────────╯

:carol@:Person FAIL
  :carol does not conform to :Person: property schema:name: Datatype error: found xsd:integer, expected xsd:string, lexical form "23"^^xsd:integer (at @:Person~schema:name)

Validate with SHACL

$ rudof shacl-validate person.ttl --shapes person-shapes.ttl -r compact
╭──────────────┬────────┬────────────────────────────────┬─────────────┬───────────────────┬──────────────╮
│ Severity     │ Node   │ Component                      │ Path        │ Value             │ Source shape │
├──────────────┼────────┼────────────────────────────────┼─────────────┼───────────────────┼──────────────┤
│ sh:Violation │ :carol │ sh:DatatypeConstraintComponent │ schema:name │ "23"^^xsd:integer │ _:…          │
╰──────────────┴────────┴────────────────────────────────┴─────────────┴───────────────────┴──────────────╯

The source shape is the blank node of the property shape, so its label changes on each run.

rudof validate is a generic command for both languages. The validate page describes it.

Query with SPARQL

The order of the rows can change between runs.

$ rudof query person.ttl --query names.sparql
╭───┬─────────┬───────────────────╮
│   │ ?person │ ?name             │
├───┼─────────┼───────────────────┤
│ 1 │ :carol  │ "23"^^xsd:integer │
├───┼─────────┼───────────────────┤
│ 2 │ :alice  │ "Alice"           │
├───┼─────────┼───────────────────┤
│ 3 │ :bob    │ "Bob"             │
╰───┴─────────┴───────────────────╯

To query a remote SPARQL endpoint instead of a file, use --endpoint. See the query page.

Convert a schema

Convert the SHACL shapes to ShEx:

$ rudof convert -m shacl -f turtle -s person-shapes.ttl -x shex -r shexc
prefix sh: <http://www.w3.org/ns/shacl#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix : <http://example.org/>
prefix schema: <http://schema.org/>
:PersonShape { schema:name xsd:string }

The convert page lists all the supported conversions, for example ShEx to UML diagrams or HTML pages.

Next steps

Most commands are of one of two types:

  • Technology commands, named after a technology, give information about an input: data, node, shex, shacl, shapemap, dctap, service, sparql.
  • Action commands, named with a verb, do a task: validate, query, convert, compare, generate.