Max Beikirch
Max Beikirch

Reputation: 2153

neo4j neosemantics: loading model constraints

I want to use neosemantics to validate a graph in neo4j, but I'm having trouble to get the model constraints loaded on a minimal example:

Suppose I have the following graph:

CREATE (n:Person {name: 'Andy'})

Then, I initialize neosemantics as follows:

CALL n10s.graphconfig.init();

Now I should be good to go and validate the graph. Based on what I found here (https://neo4j.com/labs/neosemantics/4.0/validation/), I thought that the following schema should work as a first approach:

call n10s.validation.shacl.import.inline('

@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:datatype xsd:string ;
  ];
.','Turtle')

However, that gives me:

Failed to invoke procedure `n10s.validation.shacl.import.inline`: Caused by: n10s.utils.UriUtils$UriNamespaceHasNoAssociatedPrefix: Prefix Undefined: No prefix defined for namespace <http://neo4j.com/myvoc#Person>. Use n10s.nsprefixes.add(...) procedure.

It felt weird, but to match that error message, I tried adding the line

@prefix neo4jPerson: <http://neo4j.com/myvoc#Person> .

but that didn't help.

I then tried the following:

CALL n10s.graphconfig.init({handleVocabUris:"IGNORE"});

Then, the validation rule is accepted, but it doesn't really look connected to anything:

target  propertyOrRelationshipPath  param   value
"__NONE__"  "__NONE__"  "datatype"  "string"

I thought that it would be helpful to remove that namespace stuff all along. So I also tried

call n10s.validation.shacl.import.inline('

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

PersonShape a sh:NodeShape ;
  sh:targetClass Person ;
  sh:property [
    sh:path name ;
    sh:datatype xsd:string ;
  ];
.','Turtle')

But that didn't work either as the parser insists on getting that namespace stuff to work:

Failed to invoke procedure `n10s.validation.shacl.import.inline`: Caused by: org.eclipse.rdf4j.rio.RDFParseException: Expected ':', found ' ' [line 6]

I'm a bit at a loss here. The code I've given is more or less taken from the neosemantics user guide (https://neo4j.com/labs/neosemantics/4.0/). and only adapted slightly. Their unit tests also seem to have no magic added https://github.com/neo4j-labs/neosemantics/blob/4.0/src/test/java/n10s/validation/SHACLValidationProceduresTest.java#L59. Still I'm getting the error messages outlined above. What am I missing? Is there a MWE of anyone that got neo4j graph validation to work?

Upvotes: 0

Views: 733

Answers (1)

Max Beikirch
Max Beikirch

Reputation: 2153

Answering my own question, the neo4j namespace has changed to <neo4j://graph.schema#> (https://github.com/neo4j-labs/neosemantics/issues/229)

Upvotes: 0

Related Questions