Validating RDF data tutorial
ShEx/SHACL by example
Presenters: Jose Emilio Labra Gayo Iovka Boneva
WESO Research group,Spain LINKS, INRIA & CNRS, France
Collaborators: Eric Prud'hommeaux Dimitris Kontokostas
World Wide Web Consortium GeoPhy
MIT, Cambridge, MA, USA [Link]
More info
HTML version: [Link]
Examples: [Link]
Contents
RDF data model (short overview)
Motivation for RDF data Validation
ShEx by example
SHACL by example
Comparing ShEx and SHACL
Applications
RDF Data Model
Overview of RDF Data Model and simple exercise
Link to slides about
[Link]
RDF Data Model
RDF, the good parts...
RDF as an integration language
RDF as a lingua franca for semantic web and linked data
RDF data stores & SPARQL
RDF flexibility
Data can be adapted to multiple environments
Open and reusable data by default
RDF, the other parts
Inference & knowledge representation
RDF should combine well with KR vocabularies (RDF Schema, OWL...)
Performance of RDF based systems with inference = challenging
Consuming & producing RDF
Multiple serializations: Turtle, RDF/XML, JSON-LD, ...
Embedding RDF in HTML
Describing and validating RDF content
Why describe & validate RDF?
For producers
Developers can understand the contents they are going to produce
They can ensure they produce the expected structure
Advertise and document the structure
Generate interfaces
For consumers
Understand the contents
Verify the structure before processing it
Query generation & optimization
Similar technologies
Technology Schema
Relational Databases DDL
XML DTD, XML Schema, RelaxNG, Schematron
Json Json Schema
RDF ?
Fill that gap
Understanding the problem
RDF is composed by nodes and arcs between nodes
We can describe/check
The form of the node itself (node constraint)
The number of possible arcs incoming/outgoing from a node
The possible values associated with those arcs
RDF Node ShEx <UserShape> IRI {
:alice schema:name "Alice"; schema:name xsd:string ;
schema:knows :bob . schema:knows IRI *
}
IRI schema:name string 1 Shape
schema:knows IRI 0, 1,... RDF Node that
represents a User
Understanding the problem
RDF flexibility
Mixed use of objects & literals
Example: :angie schema:creator "Keith Richards" ;
schema:creator [
Values of schema:creator can be:
schema:firstName "Mick" ;
string or schema:lastName "Jagger"
schema:Person ] .
in the same data
Lots of examples at [Link]
Understanding the problem
Repeated properties
The same property can be used for different purposes in the same data
Example: A product must have 2 codes with different structure
:product schema:productID "isbn:123-456-789";
schema:productID "code456" .
A practical example from FHIR
See: [Link]
Understanding the problem
Shapes ≠ types
Nodes in RDF graphs can have zero, one or many rdf:type
declarations
One type can be used for multiple purposes (foaf:Person)
Data doesn't need to be annotated with fully discriminating types
foaf:Person can represent friend, invitee, patient,...
Different meanings and different structure depending on the context
Specific validation constraints for different contexts
Understanding the problem
RDF validation ≠ ontology definition ≠ instance data
Ontologies are usually focused on real world entities
RDF validation is focused on RDF graph features (lower level)
schema:knows a owl:ObjectProperty ;
Ontology rdfs:domain schema:Person ;
rdfs:range schema:Person .
A user must have only two properties: <User> IRI {
Constraints
Different levels schema:name of value xsd:string schema:name xsd:string ;
RDF Validation
schema:knows with an IRI value schema:knows IRI
}
:alice schema:name "Alice";
Instance data
schema:knows :bob .
Previous RDF validation approaches
SPARQL based
Plain SPARQL
SPIN: [Link]
OWL based
Stardog ICV
[Link]
Grammar based
OSLC Resource Shapes
[Link]
Define SPARQL queries that detect errors
ASK {{ SELECT ?Person {
Pros: ?Person schema:name ?o .
} GROUP BY ?Person HAVING (COUNT(*)=1)
Expressive }
Ubiquitous { SELECT ?Person {
?Person schema:name ?o .
Cons FILTER ( isLiteral(?o) &&
datatype(?o) = xsd:string )
Expressive } GROUP BY ?Person HAVING (COUNT(*)=1)
Idiomatic - many ways to encode }
{ SELECT ?Person (COUNT(*) AS ?c1) {
the same constraint ?Person schema:gender ?o .
} GROUP BY ?Person HAVING (COUNT(*)=1)}
{ SELECT ?Person (COUNT(*) AS ?c2) {
Example: SPARQL query to check that… ?S schema:gender ?o .
There is one schema:name which must be a xsd:string and
one schema:gender must be schema:Male or schema:Female FILTER ((?o = schema:Female ||
?o = schema:Male))
} GROUP BY ?Person HAVING (COUNT(*)=1)}
FILTER (?c1 = ?c2)
}
SPIN
SPARQL inferencing notation [Link]
Developed by TopQuadrant
Commercial product
Vocabulary associated with user-defined functions in SPARQL
SPIN has influenced SHACL (see later)
Stardog ICV
ICV - Integrity Constraint Validation
Commercial product
OWL with unique name assumption and closed world
Compiled to SPARQL
More info: [Link]
OSLC Resource Shapes
OSLC Resource Shapes :user a rs:ResourceShape ;
rs:property [
[Link]
rs:name "name" ;
Grammar based approach rs:propertyDefinition schema:name ;
rs:valueType xsd:string ;
Language for RDF validation rs:occurs rs:Exactly-one ;
] ;
Input for ShEx and SHACL rs:property [
rs:name "gender" ;
rs:propertyDefinition schema:gender ;
rs:allowedValue schema:Male, schema:Female ;
rs:occurs rs:Zero-or-one ;
].
Other approaches
Dublin Core Application profiles (K. Coyle, T. Baker)
[Link]
RDF Data Descriptions (Fischer et al)
[Link]
RDFUnit (D. Kontokostas)
[Link]
...
ShEx and SHACL
2013 RDF Validation Workshop
Conclusions of the workshop:
There is a need of a higher level, concise language for RDF Validation
ShEx initially proposed (v 1.0)
2014 W3c Data Shapes WG chartered
2017 SHACL accepted as W3C recommendation
2017 ShEx 2.0 released as Community group draft
Continue this tutorial with...
[Link]
ShEx by example
SHACL by example [Link]
ShEx and SHACL [Link]
compared
Applications and
[Link]
future work