rdf4j
rdf4j copied to clipboard
SHACL: More descriptive message when a shape is both a sh:NodeShape and a sh:PropertyShape
Discussed in https://github.com/eclipse/rdf4j/discussions/4287
Originally posted by volkerjaenisch November 19, 2022 Dear RDF4J Users!
Currently we am implementing SHACL for an OpenData portal (http://datenadler.de). We are Python programmers so we planed to go with pySHACL. But our Plan B is RDF4J which we are currently using as our backend.
Testing our Plan B we stumbled over the following exception of RDF4J reading a SHAPE file.
javax.servlet.ServletException: org.eclipse.rdf4j.repository.RepositoryException: Shape with multiple types: <http://www.w3.org/ns/shacl#PropertyShape>, <http://www.w3.org/ns/shacl#NodeShape>
org.eclipse.rdf4j.workbench.proxy.WorkbenchServlet.handleRequest(WorkbenchServlet.java:160)
org.eclipse.rdf4j.workbench.proxy.WorkbenchServlet.service(WorkbenchServlet.java:112)
org.eclipse.rdf4j.workbench.proxy.WorkbenchGateway.service(WorkbenchGateway.java:117)
org.eclipse.rdf4j.workbench.base.AbstractServlet.service(AbstractServlet.java:129)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
org.eclipse.rdf4j.workbench.proxy.CacheFilter.doFilter(CacheFilter.java:64)
org.eclipse.rdf4j.workbench.proxy.CookieCacheControlFilter.doFilter(CookieCacheControlFilter.java:56)
Root Cause
org.eclipse.rdf4j.repository.RepositoryException: Shape with multiple types: <http://www.w3.org/ns/shacl#PropertyShape>, <http://www.w3.org/ns/shacl#NodeShape>
org.eclipse.rdf4j.http.client.SPARQLProtocolSession.execute(SPARQLProtocolSession.java:1095)
org.eclipse.rdf4j.http.client.SPARQLProtocolSession.executeNoContent(SPARQLProtocolSession.java:1049)
org.eclipse.rdf4j.http.client.RDF4JProtocolSession.upload(RDF4JProtocolSession.java:1103)
org.eclipse.rdf4j.http.client.RDF4JProtocolSession.upload(RDF4JProtocolSession.java:928)
org.eclipse.rdf4j.http.client.RDF4JProtocolSession.upload(RDF4JProtocolSession.java:919)
org.eclipse.rdf4j.repository.http.HTTPRepositoryConnection.add(HTTPRepositoryConnection.java:447)
org.eclipse.rdf4j.workbench.commands.AddServlet.add(AddServlet.java:94)
org.eclipse.rdf4j.workbench.commands.AddServlet.doPost(AddServlet.java:53)
org.eclipse.rdf4j.workbench.base.TransformationServlet.service(TransformationServlet.java:98)
org.eclipse.rdf4j.workbench.base.AbstractServlet.service(AbstractServlet.java:129)
org.eclipse.rdf4j.workbench.proxy.ProxyRepositoryServlet.service(ProxyRepositoryServlet.java:100)
org.eclipse.rdf4j.workbench.proxy.WorkbenchServlet.service(WorkbenchServlet.java:215)
org.eclipse.rdf4j.workbench.proxy.WorkbenchServlet.handleRequest(WorkbenchServlet.java:137)
org.eclipse.rdf4j.workbench.proxy.WorkbenchServlet.service(WorkbenchServlet.java:112)
org.eclipse.rdf4j.workbench.proxy.WorkbenchGateway.service(WorkbenchGateway.java:117)
org.eclipse.rdf4j.workbench.base.AbstractServlet.service(AbstractServlet.java:129)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
org.eclipse.rdf4j.workbench.proxy.CacheFilter.doFilter(CacheFilter.java:64)
org.eclipse.rdf4j.workbench.proxy.CookieCacheControlFilter.doFilter(CookieCacheControlFilter.java:56)
Can someone please explain what is going wrong.
The shape file comes from the EU
https://github.com/SEMICeu/DCAT-AP/blob/master/releases/2.1.1/dcat-ap_2.1.1_shacl_shapes.ttl
pySHACL reads and uses this file with no complains. I also checked graphDB (to make sure my RDF4J is installed correctly) with the exact same outcome.
Any help appreciated
Cheers, Volker
Looks like the exception is thrown when a SHACL shape has a sh:name
Eg.
:Agent_Shape
a sh:NodeShape ;
sh:name "Agent"@en ;
sh:property [
sh:minCount 1 ;
sh:nodeKind sh:Literal ;
sh:path foaf:name ;
sh:severity sh:Violation
], [
sh:maxCount 1 ;
sh:path dct:type ;
sh:severity sh:Violation
] ;
sh:targetClass foaf:Agent .
Doesn't work, but simply removing the sh:name "Agent"@en fixes it.
Arguably this is not a bug, since, according to the SHACL ontology (https://github.com/w3c/data-shapes/blob/gh-pages/shacl/shacl.ttl), sh:name is only a property of a sh:PropertyShape
While the DCAT-AP shacl file uses it on sh:NodeShape ...
It would be nice to have a bit more logging on which subject/shape the SHACL sail is failing (in this particular case: all nodeshapes), and/or to simply ignore sh:name and sh:description on NodeShapes
Improved logging would be nice.
Might also be nice to have a "skip invalid shapes" option.
I’m going to handle this by improving the error message. If I can I will try to add some kind of backwards tracing to log the reason for a shape being both a node shape and a property shape.
I won’t introduce a way to skip invalid shapes at the moment.