Skip to content

Latest commit

 

History

History
43 lines (34 loc) · 1.62 KB

shacl.adoc

File metadata and controls

43 lines (34 loc) · 1.62 KB

SHACL (Shapes constraint language)

SHACL is a language for defining constraints on RDF data, such that supporting tools can actually enforce them! It allows you to define constraints such as the type, the multiplicity (0 or 1 values, 1 to 3 values, etc.), the expected regex pattern to match, and so on. The neosemantics plugin for Neo4j supports loading SHACL now. Here is an example SHACL snippet from the neosemantics docs in turtle format:

@prefix neo4j: <http://neo4j.com/myvoc#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

neo4j:PersonShape a sh:NodeShape ;
  sh:targetClass neo4j:Person ;
  sh:property [
    sh:path neo4j:name ;
    sh:pattern "^\w[\s\w\.]*$" ;
    sh:maxCount 1 ;
    sh:datatype xsd:string ;
  ];
  sh:property [
    sh:path neo4j:ACTED_IN ;
    sh:class neo4j:Movie ;
    sh:nodeKind sh:IRI ;
  ] ;
.

Which can be loaded into the graph using:

call n10s.validation.shacl.import.inline( <SHACL snippet>, <SHACL format e.g. 'Turtle'> )

This can be very handy for enforcing rules on a taxonomy or ontology. These types of constraints are similar to the ones available in the Legend modeling language, however these are enforceable on the data store, leverage the RDF and SHACL standards, and provide error reporting of violations. To run a validation of loaded SHACL constraints on graph data, you can do so using the validate function provided by the plugin on an adhoc/manual basis, or enforce it on each transaction by adding it as a trigger!

See docs linked below for latest syntax and capabilities.