Hi Matt,
I found this interesting so I made a quick attempt to create such a
constraint component. The source code is below. It's basically a new
flag dash:closedByTypes which, if set to true, will close off the given
instances based on the property declarations in their associated types.
All that a user would need to do is to set this to true for the root
class, and it will apply to all subclasses, too (assuming that shapes
are also classes). I plan to put this into the next release of TopBraid
and the DASH namespace. If you find it useful, you may add it to your
local shape definitions. Example use:
ex:SuperClass
a rdfs:Class, sh:Shape ;
dash:closedByTypes true .
Please let me know if this has the semantics that you would expect.
(It's a bit geeky so please ask for clarifications if you need them).
Regards,
Holger
dash:ClosedByTypesConstraintComponent
rdf:type sh:ConstraintComponent ;
rdfs:comment "A constraint component that can be used to declare that
focus nodes are \"closed\" based on their rdf:types, meaning that focus
nodes may only have values for the properties that are explicitly
enumerated via sh:property/sh:predicate in property constraints at their
rdf:types and the superclasses of those. This assumes that the type
classes are also shapes." ;
rdfs:label "Closed by types constraint component" ;
sh:parameter [
sh:predicate dash:closedByTypes ;
sh:datatype xsd:boolean ;
sh:description "True to indicate that the focus nodes are closed
by their types. A constraint violation is reported for each property
value of the focus node where the property is not among those that are
explicitly declared via sh:property/sh:predicate in any of the rdf:types
of the focus node (and their superclasses). The property rdf:type is
always permitted." ;
] ;
sh:shapeValidator [
rdf:type sh:SPARQLSelectValidator ;
sh:message "Property {?path} is not among those permitted for any
of the types" ;
sh:prefixes <http://datashapes.org/dash> ;
sh:select """SELECT $this (?predicate AS ?path) ?value
WHERE {
$this ?predicate ?value .
FILTER (?predicate != rdf:type) .
FILTER NOT EXISTS {
$this rdf:type ?type .
?type rdfs:subClassOf* ?class .
GRAPH $shapesGraph {
?class sh:property/sh:predicate ?predicate .
}
}
}""" ;
] ;
sh:targetClass sh:Shape ;
.
On 30/11/2016 23:06, Matt Johnson wrote:
Thank you for the reply Holger. Assuming I truly want to completely
close the world, it sounds like there are 2 current options. 1) Make
my own constraint component along with a validator or 2) manually
maintain super-class constraints for each sub-class shape. Thanks again.
Matt
On Tuesday, November 29, 2016 at 6:00:54 PM UTC-5, Holger Knublauch
wrote:
The implementation follows what the SHACL WG decided. And the
official design uses sh:closed only on the current shape. Many WG
members were against using class inheritance for anything (which
came to a surprise to me because I think rdfs:subClassOf is the
most important relation in the RDF world after rdf:type).
In the future we could add a variation of sh:closed that also
walks up the superclasses (e.g. into the dash namespace). This is
not too difficult to do, and anyone could add such a constraint
component in their own namespace. Its validator would be a
variation of the SPARQL query of sh:closed, probably only replace
the one line with
$currentShape rdfs:subClassOf*/sh:property/sh:predicate
?predicate .
Holger
On 30/11/2016 8:20, Matt Johnson wrote:
Hello,
I am trying to understand just how possible it is to close the
world using SHACL. With the current implementation of the SHACL
API, is it possible to inherit the constraints of one's super
class (via rdfs:subClassOf) **and** to close the sub-class? The
following example defines a shape (and class) and two property
constraints for Events. Dinner is then defined as a subClassOf
Event but the Dinner shape is also defined as being closed. The
intent here is to not allow any other predicates for Dinner. The
result produces a failure for inst:dinner_1 stating that
ex:startDate is not allowed because Dinner is closed. If I change
the Dinner shape such that sh:closed == false, the instance does
indeed become conformant but also allows other predicates. Am I
attempting something that SHACL is not meant to do? From what I
can tell, subClassOf is the way of achieving "inheritance" but
perhaps I have misunderstood. Thanks for your help.
Matt
PS: I created this example using TBC 5.2.1 and have gotten
similar results when using the SHACL API directly.
ex:Event
rdf:type rdfs:Class ;
rdf:type sh:Shape ;
rdfs:label "Event" ;
sh:ignoredProperties (
rdf:type
rdfs:label
) ;
sh:property [
sh:predicate ex:endDate ;
sh:datatype xsd:date ;
sh:maxCount 1 ;
sh:name "end date" ;
] ;
sh:property [
sh:predicate ex:startDate ;
sh:datatype xsd:date ;
sh:maxCount 1 ;
sh:name "start date" ;
] ;
.
ex:Dinner
rdf:type rdfs:Class ;
rdf:type sh:Shape ;
rdfs:label "Dinner" ;
rdfs:subClassOf ex:Event ;
sh:closed "true"^^xsd:boolean ;
sh:ignoredProperties (
rdf:type
rdfs:label
) ;
sh:property [
sh:predicate ex:onMenu ;
sh:datatype xsd:string ;
sh:name "on menu" ;
] ;
.
inst:dinner_1
rdf:type ex:Dinner ;
ex:onMenu "Hamburger" ;
ex:startDate "2001-01-01"^^xsd:date ;
rdfs:label "dinner 1" ;
.
--
You received this message because you are subscribed to the
Google Group "TopBraid Suite Users", the topics of which include
the TopBraid Suite family of products and its base technologies
such as SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to [email protected]
<javascript:>
---
You received this message because you are subscribed to the
Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to [email protected] <javascript:>.
For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.
--
You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include the TopBraid
Suite family of products and its base technologies such as
SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to [email protected]
---
You received this message because you are subscribed to the Google
Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Group "TopBraid
Suite Users", the topics of which include the TopBraid Suite family of products and
its base technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to [email protected]
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.