neosemantics icon indicating copy to clipboard operation
neosemantics copied to clipboard

Support for sh:inversePath for one-to-one condition

Open palandlom opened this issue 3 years ago • 3 comments

How one-to-one condition can be implemented?

As I understand in SHACL we can define 2 shapes for direct and reverse conditions with sh:maxCount 1; sh:minCount 1 for singe edge (e.g. HAS_PART)

But for reverse one sh:inversePath is needed but it seems that it is not supported by cur version of neosemantics

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

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

neo4j:PartShape    a sh:NodeShape;
    sh:targetClass neo4j:Part;    
    sh:property [            
        sh:inversePath  neo4j:HAS_PART;
        sh:maxCount 1;
        sh:minCount 1;
        sh:class neo4j:System;
    ] ;
.
','Turtle')


palandlom avatar Sep 29 '21 14:09 palandlom

how about using a blank node with sh:path for the sh:inversePath?

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

neo4j:PartShape    a sh:NodeShape;
    sh:targetClass neo4j:Part;    
    sh:property [            
        sh:path  [sh:inversePath neo4j:HAS_PART];
        sh:maxCount 1;
        sh:minCount 1;
        sh:class neo4j:System;
    ] .

joedavid-tuni avatar Jan 23 '22 19:01 joedavid-tuni

Hello, Currently working with neosemantics, I'm facing the exact same problem.

The first solution by @palandlom fail at constraint creation with a NullPointerException. For the second solution by @joedavid91 , the creation is ok but at validation, we get a ClassCastException. (into cypher.internal.expressions package : HasDegreeLessThan cannot be cast to InequalityExpression).

Have you find any solution?

PaulBazin avatar Jun 01 '22 08:06 PaulBazin

In my case - it wasn't solved. My suggestion - consider to use https://neo4j.com/docs/cypher-manual/current/constraints/ in addition to neosemantic OR/AND implement restrictions on a "higher" level of application.

palandlom avatar Jun 01 '22 09:06 palandlom