Search code examples
shacl

How to check for a number of class instances with SHACL


I have an RDF file - a single graph - that I'd like to validate using SHACL. I want to make sure it contains one, and only one, instance of Class X. Is this possible?

There are no nodes linking to this instance of Class X in the file so I can't count it via some other instance's property paths.


Solution

  • See https://www.w3.org/wiki/SHACL/Examples for the general pattern that should work here too: use sh:targetNode together with the inverse path ^rdf:type.