rudof shex-path

The command shex-path evaluates a ShExPath against a ShEx schema and prints the elements of the schema it selects. A ShExPath addresses shape expressions, triple constraints, value sets, annotations and the other elements of a schema: @:Person~:knows is the :knows triple constraint of the shape :Person.

The path is written with the prefixes and base the schema declares, and it is evaluated over the ShExJ form of the schema. Each selected element is printed as a JSON object with its location, a JSON Pointer into that ShExJ document, and its value, the element as ShExJ. The elements come in the order the path selects them, with their duplicates.

See ShExPath for the language.

Examples

Select a triple constraint

$ rudof shex-path -s "PREFIX : <http://example.org/> :Person { :name . ; :knows @:Person * }" \
    -p "@:Person~:knows"
[
  {
    "location": "/shapes/0/shapeExpr/expression/expressions/1",
    "value": {
      "max": -1,
      "min": 0,
      "predicate": "http://example.org/knows",
      "type": "TripleConstraint",
      "valueExpr": "http://example.org/Person"
    }
  }
]

Select an atomic value

A reference to a shape is an IRI, not the shape it names:

$ rudof shex-path -s "PREFIX : <http://example.org/> :Person { :name . ; :knows @:Person * }" \
    -p "@:Person~:knows/valueExpr"
[
  {
    "location": "/shapes/0/shapeExpr/expression/expressions/1/valueExpr",
    "value": "http://example.org/Person"
  }
]

A path that selects nothing

$ rudof shex-path -s "PREFIX : <http://example.org/> :Person { :name . }" -p "@:Nope"
[]

A failed assertion

[assert ...] makes the path an error when the assertion does not hold. The error is written to the standard error, and the command exits with a non-zero code:

$ rudof shex-path -s "PREFIX : <http://example.org/> :Person { :name . ; :knows @:Person * }" \
    -p "@:Person/expression/expressions/*[assert count() = 1]"
Error: ShEx error: Failed to evaluate the ShExPath '@:Person/expression/expressions/*[assert count() = 1]': ShExPath assertion failed on the item at "/shapes/0/shapeExpr/expression/expressions/0"

A path that is not a ShExPath is reported the same way.

Options

OptionDescription
-s, --schema INPUTSchema, file, URI, or - for stdin (required)
-p, --path SHEXPATHShExPath to evaluate, written with the prefixes and base of the schema (required)
-f, --format FORMATSchema format (ShExC, ShExJ, Turtle, …), default ShExC
-b, --base IRIBase IRI for resolving relative IRIs in the schema
-c, --config-file FILEConfig file name
-o, --output-file FILEOutput file name, default terminal
--force-overwriteOverwrite the output file if it already exists