There is an obvious need in some situations to exercise constraints on the data that one manages in RDF. This is particularly true within local systems where data is created and updated, and when exchanging data with known partners. To fill this gap, the semantic web branch of the World Wide Web Consortium has been working on a new standard, called the SHApes Constraint Language (SHACL), that will perform for RDF the function that XML schema performs for XML: it will allow software developers to define validity rules for a particular set of RDF.
SHACL has been in development for nearly a year, and is just now available in a First Public Working Draft. A FPWD is not by any means a finished product, but is far enough along to give readers an idea of the direction that the standard is taking. It is made available because comment from a larger community is extremely important. The introduction to the draft tells you where to send your comments. (Note: I serve on the working group representing the Dublin Core community, so I will do my best to make sure your comments get full consideration.)
Like many standards, SHACL is not easy to understand. However, I think it will be important for members of the library and other cultural heritage communities to make an effort to weigh in on this standard. Support for SHACL is strong from the "enterprise" sector, people who primarily work on highly controlled closed systems like banks and other information intense businesses. How SHACL benefits those whose data is designed for the open web may depend on us.
SHACL Basics
The key to understanding SHACL is that SHACL is based in large part on SPARQL because SPARQL already has formally defined mechanisms that function on RDF graphs. There will be little if any SHACL functionality that could not be done with SPARQL. SPARQL queries that perform some of these functions are devilishly difficult to write so SHACL should provide a cleaner, more constraint-based language.SHACL consists of a core of constraints that belong to the SHACL language and have SHACL-defined properties. These should be sufficient for most validation needs. SHACL also has a template mechanism that makes it possible for anyone to create a templated constraint to meet additional needs.
What does SHACL look like? It's RDF, so it looks like RDF. Here's a SHACL statement that covers the case "either one foaf:name OR (one foaf:forename AND one foaf:lastname):
ex:myPersonShape
a sh:Shape ;
sh:scopeClass foaf:Person ;
sh:constraint [
a sh:OrConstraint ;
sh:shapes(
[
sh:property [
sh:predicate foaf:name ;
sh:minCount 1 ;
sh:maxCount 1 ;
]
]
[
sh:property [
sh:predicate foaf:forename ;
sh:minCount 1 ;
sh:maxCount 1 ;
] ;
sh:property [
sh:predicate foaf:lastname ;
sh:minCount 1 ;
sh:maxCount 1 ;
]
]
)
] .
SHACL constraints can either be open or closed. Open, the default, constrains the named properties but ignores other properties in the same RDF graph. Closed, it essentially means "these properties and only these properties; everything else is a violation."
There are comparisons, such as "equal/not equal" that act on pairs of properties. There are also constraints on values such as defined value types (IRI, data type), lists of valid values, and pattern matching.
The question that needs to be answered around this draft is whether SHACL, as currently defined, meets our needs -- or at least, most of them. One way to address this would be to gather some typical and some atypical validation tests that are needed for library and archive data, and try to express those in SHACL. I have a few examples (mainly from Europeana data), but definitely need more. You can add them to the comments here, send them to me (or send a link to documentation that outlines your data rules), or post them directly to the working group list if you have specific questions.
Thanks in advance.
Karen,
ReplyDeleteThanks for pointing to this work. SHACL looks promising for library domain use cases. Currently I'm part of a discussion about viable person entities and so far we've only discussed minimally viable, like your example. It looks like SHACL could allow us to define different levels, e.g. ex:MyMinimallyViablePerson, ex:MyViableForAParticularAppPerson, ex:MyLibraryStandardBreakingPrivacyNormsViablePerson. I also like the sh:hasValue property. With so many properties minimally defined ranges to avoid high degrees of ontological commitments, sh:hasValue can allow to specify for a particular app or domain. I wish I had more experience in production RDF systems to give more/better feedback; maybe over the next year...
Thanks again for your work on this,
Steven