- From: Holger Knublauch <holger@topquadrant.com>
- Date: Tue, 15 Mar 2022 15:46:31 +1000
- To: public-shacl@w3.org
- Message-ID: <d24d03a3-db43-6d83-cf99-458d291edcfe@topquadrant.com>
Hi Rashmi, I struggle to respond because the example that you have provided is quite complex, e.g. with all these numeric identifiers, and everything having three rdf:types so that it's unclear (to me) what you are trying to model. First comment, if you don't find any useful input here, there is also a Discord channel designed to ask such questions, see https://twitter.com/HolgerKnublauch/status/1461590465304662019 but even there I would recommend to simplify this example even further and use human-readable identifiers so that people know what you're talking about. On 2022-03-15 3:22 am, Rashmi Burse wrote: > > Hi, > > I want to implement the following scenario: > > Firstly, I want to create custom targets for a NodeShape in such a way > that these targets should change based on the current focusNode. For > example, if the focusNode is snomed: 24078009 then the custom targets > should be snomed: 24078009_3, snomed: 24078009_5, snomed: 24078009_6; > If the focusNode is snomed:1003505005 then the custom targets for the > same nodeShape should be changed to > snomed:1003505005_1,snomed:1003505005_2. In order to implement this I > want to refer to the current focusNode inside the SPARQLTarget query. > However I am not sure how to use sh:this inside sh:select. > In general, there is no "current" focus node for SPARQL targets. You can start at any node and then bind ?this to any value you like. For example, assuming you have triples such as ex:A rdf:type ex:C1 . ex:B rdf:type ex:C2 . then you could use SELECT ?this WHERE { ?this rdf:type ex:C1 } to target all instances of C1. Based on that you could then narrow it down further, so that certain instances of C1 are not targeted. For example this would only target nodes where ex:prop is true: SELECT ?this WHERE { ?this rdf:type ex:C1 . FILTER EXISTS { ?this ex:prop true } } > Secondly, for each (focusNode specific) list of custom targets > returned by the targetSPARQL query, I want to create a union of all > the properties in those targets, i.e., union of rdf classes (snomed: > 24078009_3, snomed: 24078009_5, snomed: 24078009_6) for the focusNode > snomed: 24078009 and then check if the condition mentioned in the > nodeShape is satisfied for the union of those custom targets and not > just an individual custom target. > The SPARQL targets already produce a union automatically. All bindings of ?this will be unioned together and will be the target of your shape. The SHACL engine will then iterate over all values for ?this and use them as focus nodes of the given shape. Holger > Here is my nodeShape and datagraph: > > *#shacl custom target shape* > > snomed: > > sh:declare [ > > sh:prefix "snomed" ; > > sh:namespace "http://localhost:8890/snomed/"^^xsd:anyURI ; > > ] . > > snomed:dob363698007Shape > > a sh:NodeShape ; > > sh:target [ > > a sh:SPARQLTarget ; > > sh:prefixes snomed: ; > > sh:select "SELECT ?this WHERE { ?node a snomed:24078009. ?node > snomed:609096000 ?this . ?this a snomed:dob363698007 .}"; > > ] ; > > sh:property [ > > sh:path snomed:363698007; > > sh:minCount 1; > > ]. > > *Data Graph:* > > snomed:dob a rdfs:Class,snomed:dob ; > > rdfs:label "Semantic Pattern dob"^^xsd:string ; > > snomed:609096000 snomed:dob363698007 . > > snomed:dob363698007 a rdfs:Class,snomed:dob363698007; > > snomed:363698007 snomed:123037004 . > > snomed:24078009 a rdfs:Class, snomed:24078009, snomed:dob; > > rdfs:label "Gangosa of yaws (disorder)"^^xsd:string ; > > snomed:609096000 > snomed:24078009_3,snomed:24078009_5,snomed:24078009_6; > > rdfs:subClassOf snomed:128349005, > > snomed:140004, > > snomed:177010002, > > snomed:312118003, > > snomed:312129004, > > snomed:312422001, > > snomed:363166002, > > snomed:47841006, > > snomed:88037009 . > > snomed:24078009_3 a rdfs:Class, snomed:24078009_3, > snomed:dob363698007 ; > > snomed:263502005 snomed:90734009 . > > snomed:24078009_5 a rdfs:Class, snomed:24078009_5,snomed:dob363698007; > > snomed:116676008 snomed:110435003 ; > > snomed:246075003 snomed:6246005 ; > > snomed:3636980070 snomed:71836000 ; > > snomed:370135005 snomed:441862004 . > > snomed:24078009_6 a rdfs:Class, > snomed:24078009_6,snomed:dob363698007 ; > > snomed:116676008 snomed:110435003 ; > > snomed:246075003 snomed:6246005 ; > > snomed:3636980070 snomed:72914001 ; > > snomed:370135005 snomed:441862004 . > > snomed:1003505005 a snomed:1003505005, > > rdfs:Class, snomed:dob; > > rdfs:label "Agenesis of rib (disorder)"^^xsd:string ; > > snomed:609096000 snomed:1003505005_1,snomed:1003505005_2 ; > > rdfs:subClassOf snomed:70974002 . > > snomed:1003505005_1 a snomed:1003505005_1, rdfs:Class, > snomed:dob363698007 ; > > snomed:116676008 snomed:782173000 ; > > snomed:246454002 snomed:255399007 ; > > snomed:3636980070 snomed:302523002 ; > > snomed:370135005 snomed:308490002 . > > snomed:1003505005_2 a snomed:1003505005_2, rdfs:Class, > snomed:dob363698007 ; > > snomed:116676008 snomed:782173000 ; > > snomed:246454002 snomed:255399007 ; > > snomed:3636980070 snomed:302523002 ; > > snomed:370135005 snomed:308490002 . > > To reiterate, I want “snomed:24078009” in the SPARQL query (?node a > snomed:24078009) to be replaced by the current focusNode. Then create > a union of all the results nodes present in ?this. and then apply the > constraint sh:property [ sh:path snomed:363698007; sh:minCount > 1; ] to this union, i.e., snomed:363698007 should be present in at > least of the custom targets of a focusNode. > > Any implementation strategy/guidance would be highly appreciated. > > Many thanks, > > Rashmi Burse >
Received on Tuesday, 15 March 2022 05:47:49 UTC