Lab: SHACL

From info216
Revision as of 10:44, 17 February 2023 by Sinoa (talk | contribs)

Topics

  • Validating RDF graphs with SHACL
  • Running pySHACL

Useful materials

SHACL:

pySHACL:

Tasks

Task: Go to the interactive, online SHACL Playground. The file [File:xxx.txt] contains a small Turtle example you can paste into the Data Graph text field. The example is based on the kg4news.ttl graph introduced in the SPARQL lecture (S03). It contains several errors. Take some time to look at it in Turtle and also in JSON-LD, using the drop-down menu next to the Data Graph heading.

Task: Write Shapes Graphs in Turtle (recommended) or JSON-LD for each of the checks below. Keep copies of your of your Shape Graphs in a separate text editor and file. You will need them later. Each time you have entered a Shape Graph into the text field, click Update to validate the contents of the Data Graph.

  • Every kg:MainPaper has (is the subject of) exactly on kg:year property.
  • Every kg:year value (literal object) is an integer.

You can use the following prefixes:

xxx

Task: Install pySHACL into your virtual environment:

pip install pyshacl


If you have more time

Task: Fix kg4news.txt (renamed to .ttl) so that:

  • Every kg:year value has rdf:type xsd:year .