Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-27-2021 11:47 AM
Hello,
consider I have the following graph:
CREATE (n:A)-[:develops]->(m:B)
I'd like to enforce that A has at least one edge "develops" and that B has at least one edge "develops".
For A, this is easy enough:
@prefix neo4j: <neo4j://graph.schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
neo4j:AShape a sh:NodeShape ;
sh:targetClass neo4j:A ;
sh:property [
sh:minCount 1 ;
sh:path neo4j:develops;
sh:class neo4j:B;
sh:nodekind sh:IRI;
]
.
The graph is validated without error.
Now, for validating the constraint on B, I tried (in the same manner):
.
neo4j:BShape a sh:NodeShape ;
sh:targetClass neo4j:B ;
sh:property [
sh:minCount 1 ;
sh:path neo4j:develops;
sh:class neo4j:A;
sh:nodekind sh:IRI;
]
.
But that fails when validating:
╒═══════════╤══════════╤════════════════════════════╤════════════════════════════════════════════════════════╤════════════════╤════════════╤══════════════════════════════════════╤══════════════════════════════╕
│"focusNode"│"nodeType"│"shapeId" │"propertyShape" │"offendingValue"│"resultPath"│"severity" │"resultMessage" │
╞═══════════╪══════════╪════════════════════════════╪════════════════════════════════════════════════════════╪════════════════╪════════════╪══════════════════════════════════════╪══════════════════════════════╡
│109 │"B" │"bnode://id/node1fj1fn0bkx1"│"http://www.w3.org/ns/shacl#MinCountConstraintComponent"│null │"develops" │"http://www.w3.org/ns/shacl#Violation"│"unnacceptable cardinality: 0"│
└───────────┴──────────┴────────────────────────────┴────────────────────────────────────────────────────────┴────────────────┴────────────┴──────────────────────────────────────┴──────────────────────────────┘
It looks to me as if the first node in a relationship owns the edge. That would be bad for my use case, where I cannot really reverse the direction of the edge. I also tried
call n10s.validation.shacl.import.inline('
@prefix neo4j: <neo4j://graph.schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
neo4j:BShape a sh:NodeShape ;
sh:targetClass neo4j:B ;
sh:property [
sh:minCount 1 ;
sh:path [sh:inversePath neo4j:develops];
sh:class neo4j:A;
sh:nodekind sh:IRI;
]
.
', "Turtle")
but that would give me the following error:
Failed to invoke procedure `n10s.validation.shacl.validate`: Caused by: java.lang.ClassCastException: class org.neo4j.cypher.internal.expressions.HasDegreeLessThan cannot be cast to class org.neo4j.cypher.internal.expressions.InequalityExpression (org.neo4j.cypher.internal.expressions.HasDegreeLessThan and org.neo4j.cypher.internal.expressions.InequalityExpression are in unnamed module of loader 'app')
So, I guess my question is: How can I ensure that a node has at least one incoming edge of a certain type?
11-05-2021 03:26 AM
I politely want to push this issue, as I am totally clueless here.
11-06-2021 11:43 PM
May be the cast is not fixed and its dynamic so difficult for program to gauge.So the program is assuming a wrong caste when in reality it is of other caste.That is what is causing chaos in
the local program.
Thanking you
Sameer SG
11-07-2021 11:40 AM
Hi @max.beikirch at the moment the SHACL validator does not support sh:inversePath
, which means that you can unfortunately only define constraints on outgoing relationships.
I agree that the error message is not particularly useful
We are planning to extend the coverage of the SHACL primitives so hopefully the wait will not be very long. Watch out for the new releases of neosemantics for updates on this.
Thanks!
JB.
11-08-2021 12:05 AM
Those are great news 🙂 I guess I'll hack something together in python for now and replace that with a proper sh:inversePath
-solution when it's there. Thanks for your work!! Do you already have an estimate on when an implementation might be there?
All the sessions of the conference are now available online