Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-25-2021 12:44 AM
Hello,
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 (Validating Neo4j graphs against SHACL - Neosemantics), 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 (Neosemantics(n10s) User Guide - Neosemantics) and only adapted slightly.
I should add that I can import the original schema just fine with handleVocabUris: KEEP.
But still something isn't linked correctly. I added a shape that definitely violates the specification (name is missing):
CREATE (n:Person {violation: 5})
Then I ran the validation with
call n10s.validation.shacl.validate() yield focusNode, nodeType,propertyShape,offendingValue,resultPath,severity
but the result remained empty.
What am I missing?
11-05-2021 02:44 AM
All the sessions of the conference are now available online