On 10/29/2020 11:51 AM, Steve Ray wrote:
Hi,
I am trying to recreate a recursive magic property, using a SHACL property shape. However, I suspect that the reason the recursion is not working is because the property identified in the sh:path statement isn't really a function in the same sense as a magic property is a function.

My shape code is as follows:

qudt:QuantityKind-appropriateUnit

rdf:type sh:NodeShape ;

sh:property [

rdf:type sh:PropertyShape ;

sh:path qudt:dappropriateUnit ;

sh:values [

sh:prefixes <http://qudt.org/2.1/schema/shacl/overlay/qudt> ;

sh:select """SELECT DISTINCT ?unit

WHERE {

{

?unit qudt:hasQuantityKind $this .

}

UNION

{

NOT EXISTS {

?unit qudt:hasQuantityKind $this .

} .

$this skos:broader ?parent1 .

?parent1 qudt:dappropriateUnit ?unit .

} .

}""" ;

] ;

] ;

sh:targetClass qudt:QuantityKind ;

.


The non-recursive part works (the first clause of the union). But the second union clause does not work. Is there a way to make the qudt:dappropriateUnit property know that there's this associated sh:values clause?

As you have found out, SPARQL itself doesn't "see" the additional inferred triples. SHACL node expressions do, if you can reformulate this query, using sh:path.

In TopBraid there is a "native" way of querying inferred values within SPARQL too:

Try

    ( ?parent1 qudt:dappropriateUnit ) tosh:values ?unit .

which is a magic property that will look at both inferred and asserted values at query time. Make sure to avoid infinite loops though, i.e. no cycles in the graph.

As this would only work within TopBraid, a more "standard" approach would be to use node expressions. Something like

sh:values [
    sh:distinct [
        sh:if [
            sh:exists [
                sh:path [ sh:inversePath qudt:hasQuantityKind ]
            ]
        ] ;
        sh:then [
                sh:path [ sh:inversePath qudt:hasQuantityKind ]
            ]
        ] ;
        sh:else [
            sh:path qudt:dappropriateUnit ;
            sh:nodes [
                sh:path skos:broader ;
            ]
        ]
    ]
]

which due to the geekiness and my lack of example data I haven't tested. It's another syntax for "If this has a subject for hasQuantityKind then use that, otherwise recurse into the broader parent". The sh:path near the sh:else would do the recursion automatically, I believe.

    https://w3c.github.io/shacl/shacl-af/#node-expressions-path

(I just noticed the example there was wrong but this will hopefully be fixed soon).

Holger



Steve


--
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/CAGUep86_5U4TAKX-Jjb5erVdzZZZ9Xrfvv5%3DOzNJi-69gCjdzg%40mail.gmail.com <https://groups.google.com/d/msgid/topbraid-users/CAGUep86_5U4TAKX-Jjb5erVdzZZZ9Xrfvv5%3DOzNJi-69gCjdzg%40mail.gmail.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "TopBraid 
Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/topbraid-users/f0606b84-d191-ad63-014b-a1ca870980ce%40topquadrant.com.

Reply via email to