简体   繁体   中英

Does SHACL provide the capability to define “target shapes”?

I think the answer is probably no, but does there exist in SHACL the capability to define “target shapes” as an alternative to targetClass, targetNode, targetObjectsOf, targetSubjectsOf?

Being able to create target selectors seems like something that would simplify SHACL rules in general.

I'm finding myself having to use Boolean logic to accomplish the same thing which requires those same checks to appear in all shapes requiring that type of filtering.

For example:

Creating what I'd like to be a selector / filter for validations if that's possible:

# human made objects that are the object of an equivalent statement - these external references could be in the graph along with our data
# but the crm:E22_Human-Made_Object class is still the same
la:isSparseObject
    a sh:PropertyShape;
    sh:path [ sh:inversePath la:equivalent ];
    sh:class crm:E22_Human-Made_Object ; # the value node must be a HumanMadeObject
    sh:minCount 1;
.

But since I haven't found a “selector” feature, I'm using sh:or to ignore certain individuals.

la:hasAtLeastOnePrimaryName
    a sh:PropertyShape;

    sh:or (
        la:isSparseObject
        [
            sh:property [
                sh:path crm:P1_is_identified_by;
                sh:qualifiedValueShape [
…

la:object
    a sh:NodeShape;
    sh:targetsClass crm:E22_Human-Made_Object; # 

    la:hasAtLeastOnePrimaryName;
.

What I'd prefer to do is use hypothetical sh:targetsShape and sh:targetsSeverity properties like this:

la:sparseObject
    a sh:NodeShape;
    sh:targetsClass crm:E22_Human-Made_Object; # 
    sh:targetsShape la:isSparseObject;
    sh:targetsSeverity sh:Warning;

    # the focusnodes for this shape include all E22_Human-Made_Objects that la:isSparseObject validates with sh:Warning level and below
    # so I can accumulate all sparseObject properties here
    # this approach allows me to easily segment my instances into data shape based groupings
…

So, the questions are: is this possible? Is not, is there a better way of approaching the problem than the solution I've arrived at?

Thanks!

Ah, it looks like SPARQLTarget does that!

https://w3c.github.io/shacl/shacl-af/#SPARQLTarget

ex:PeopleBornInCountryTarget
    a sh:SPARQLTargetType ;
    rdfs:subClassOf sh:Target ;
    sh:labelTemplate "All persons born in {$country}" ;
    sh:parameter [
        sh:path ex:country ;
        sh:description "The country that the focus nodes are 'born' in." ;
        sh:class ex:Country ;
        sh:nodeKind sh:IRI ;
    ] ;
    sh:select """
        PREFIX ex: <http://example.com/ns#>
        SELECT ?this
        WHERE {
            ?this a ex:Person .
            ?this ex:bornIn $country .
        }
        """ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM