简体   繁体   中英

SHACL union shapes

I have framed a SPARQL query for the following use-case: If IfcWallStandardCase have a property 'FireRating', then the doors associated with it should have a property 'FireRating' as well.

The Data Graph

@prefix inst1: <https://someHost.com/PROJ1001#> .
@prefix :      <http://test.com/#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix ifcowl: <https://www.buildingsmart-tech.org/ifcOWL/IFC4_ADD1#> .
@prefix s4bldg: <https://saref.etsi.org/saref4bldg/> .
@prefix bot:   <https://w3id.org/bot#> .

inst1:Wall1  a  ifcowl:IfcWallStandardCase ;
    s4bldg:FireRating "2" ;
    bot:containsSubElement  inst1:Door1, inst1:Door2.
inst1:Door1 a ifcowl:IfcDoor ;
    s4bldg:FireRating  "2" .
inst1:Door2 a ifcowl:IfcDoor .

SPARQL Query

SELECT ?door
WHERE {{
   ?wall rdf:type ifcowl:IfcWallStandardCase.
   ?wall bot:containsElement ?val.
   ?wall s4bldg:FireRating ?val.
   }UNION{
   ?door rdf:type ifcowl:IfcDoor.
   ?door s4bldg:FireRating ?val.
   }}

I want to frame a SHACL shape for the same. From the SHACL advanced features, the closest option is to use the sh:union. Below, is my shape.

bot:BuildingShape
    a sh:NodeShape ;
    sh:targetClass ifcowl:IfcWallStandardCase;
    sh:rule [
        sh:subject sh:this;
        sh:predicate s4bldg:FireRating;
        sh:object ifcowl:IfcWallStandardCase;
        sh:union(
            [sh:path ifcowl:IfcDoor]
            [sh:path s4bldg:FireRating]
        )
    ].

But, it does not give me the result given by the SPARQL query. Where am I going wrong? Any help would be appreciated.

It's not clear to me that you need a sh:rule for this. Try the following:

bot:BuildingShape
    a sh:NodeShape ;
    sh:targetClass ifcowl:IfcWallStandardCase;
    sh:property [
       sh:path bot:containsSubElement;
       sh:class ifcowl:IfcDoor ;
    ] ;
    sh:property [
        sh:path s4bldg:FireRating;
        sh:hasValue "2" ;
    ]
.

It may not be a full value, and you may want to use sh:in to specify the range of values for FireRating, but it may be worth thinking of it this way and maybe you can tweak to meet your specification.

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