-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathowl2sh-open.ttl
917 lines (870 loc) · 33.2 KB
/
owl2sh-open.ttl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix swa: <http://topbraid.org/swa#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix dct: <http://purl.org/dc/terms/>.
@prefix owl2sh-open: <http://data.sparna.fr/ontologies/owl2sh-open#> .
<http://data.sparna.fr/ontologies/owl2sh-open>
rdf:type owl:Ontology ;
rdfs:label "OWL 2 SHACL open ruleset"@en;
rdfs:comment """Turns an OWL Ontology into a set of SHACL Shapes.
The generated Shapes remain open and will not detect a property asserted on an instance of a wrong class.
Properties from other ontologies can still be asserted anywhere as the NodeShapes are not closed."""@en;
dct:source <https://www.topquadrant.com/from-owl-to-shacl-in-an-automated-way/> ;
dct:provenance "This is derived from original work by TopQuadrant at https://www.topquadrant.com/from-owl-to-shacl-in-an-automated-way/, with their authorization.";
sh:declare [
rdf:type sh:PrefixDeclaration ;
sh:namespace "http://data.sparna.fr/ontologies/owl2sh-open#"^^xsd:anyURI ;
sh:prefix "owl2sh-open" ;
] ;
sh:declare [
rdf:type sh:PrefixDeclaration ;
sh:namespace "http://www.w3.org/2000/01/rdf-schema#"^^xsd:anyURI ;
sh:prefix "rdfs" ;
] ;
sh:declare [
rdf:type sh:PrefixDeclaration ;
sh:namespace "http://www.w3.org/2002/07/owl#"^^xsd:anyURI ;
sh:prefix "owl" ;
] ;
sh:declare [
rdf:type sh:PrefixDeclaration ;
sh:namespace "http://www.w3.org/ns/shacl#"^^xsd:anyURI ;
sh:prefix "sh" ;
] ;
sh:declare [
rdf:type sh:PrefixDeclaration ;
sh:namespace "http://www.w3.org/2001/XMLSchema#"^^xsd:anyURI ;
sh:prefix "xsd" ;
] ;
sh:declare [
rdf:type sh:PrefixDeclaration ;
sh:namespace "http://www.w3.org/1999/02/22-rdf-syntax-ns#"^^xsd:anyURI ;
sh:prefix "rdf" ;
] ;
sh:declare [
rdf:type sh:PrefixDeclaration ;
sh:namespace "http://datashapes.org/dash#"^^xsd:anyURI ;
sh:prefix "dash" ;
] ;
.
owl2sh-open:ClassShape
rdf:type sh:NodeShape ;
# Preprocessing
sh:rule owl2sh-open:Preprocessing-CopyEquivalentIntersection;
sh:rule owl2sh-open:Preprocessing-FlattenIntersectionOf ;
# Create base PropertyShapes
sh:rule owl2sh-open:CreateNodeShapesAndPropertyShapesFromRestrictions ;
sh:rule owl2sh-open:CreateNodeShapesAndPropertyShapesFromMatchingDomains ;
sh:rule owl2sh-open:CreateNodeShapesAndPropertyShapesFromEquivalentClassHasValue ;
# properties characteristics stuff
sh:rule owl2sh-open:owlFunctionalProperty2shMaxCount1 ;
# cardinality stuff
sh:rule owl2sh-open:owlMaxCardinality2shMaxCount ;
sh:rule owl2sh-open:owlMaxQualifiedCardinalityOnClass2shMaxCount ;
sh:rule owl2sh-open:owlMaxQualifiedCardinalityOnClass2shQualifiedMaxCount ;
sh:rule owl2sh-open:owlMaxQualifiedCardinalityOnDataRange2shQualifiedMaxCount ;
sh:rule owl2sh-open:owlMinCardinality2shMinCount ;
sh:rule owl2sh-open:owlMinQualifiedCardinalityOnClass2shMinCount ;
sh:rule owl2sh-open:owlMinQualifiedCardinalityOnClass2shQualifiedMinCount ;
sh:rule owl2sh-open:owlMinQualifiedCardinalityOnDataRange2shQualifiedMinCount ;
sh:rule owl2sh-open:owlQualifiedCardinalityOnClass2shMinMaxCount ;
sh:rule owl2sh-open:owlQualifiedCardinalityOnClass2shQualifiedMinMaxCount ;
sh:rule owl2sh-open:owlQualifiedCardinalityOnDataRange2shQualifiedMinMaxCount ;
# quantifiers stuff
sh:rule owl2sh-open:owlHasValue2shHasValue ;
sh:rule owl2sh-open:owlSomeValuesFrom2shMinCount1 ;
sh:rule owl2sh-open:owlSomeValuesFromAllValuesFrom2dashHasValueWithClass ;
sh:rule owl2sh-open:owlSomeValuesFromIRI2dashHasValueWithClass ;
sh:rule owl2sh-open:owlAllValuesFrom2shClassOrDatatype ;
# Turn UNIONS of IRIs into rdfs:subClassOf (so that it can be interpreted by SHACL validator I guess)
sh:rule owl2sh-open:owlUnionOfIRIs2rdfsSubClassOf ;
# range stuff
sh:rule owl2sh-open:rdfsRange2shNode ;
sh:rule owl2sh-open:rdfsRange2shClassOrDatatype ;
sh:rule owl2sh-open:rdfsRangeLiteral2shNodeKind ;
sh:rule owl2sh-open:shPropertyShapeCleanUp ;
sh:target [
rdf:type sh:SPARQLTarget ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
sh:select """
SELECT ?this
WHERE {
{
{
{
?type rdfs:subClassOf* rdfs:Class .
?this a ?type .
}
UNION
{
?this a owl:Class .
}
}
FILTER isIRI(?this) .
}
}""" ;
] ;
.
owl2sh-open:Preprocessing-CopyEquivalentIntersection
rdf:type sh:SPARQLRule ;
rdfs:comment "Copies any intersections within owl:equivalentClass into the host class itself so that subsequent rules convert them further." ;
rdfs:label "Copy owl:intersectionOfs from owl:equivalentClass" ;
sh:construct """CONSTRUCT {
$this owl:intersectionOf ?inter .
}
WHERE {
$this owl:equivalentClass ?equi .
FILTER isBlank(?equi) .
?equi owl:intersectionOf ?inter .
}""" ;
sh:order -1 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:Preprocessing-FlattenIntersectionOf
rdf:type sh:SPARQLRule ;
rdfs:comment "Copies the members of an owl:intersectionOf list as superclasses into the host class itself. Subsequent rules then apply." ;
rdfs:label "Flatten owl:intersectionOf" ;
sh:construct """CONSTRUCT {
$this rdfs:subClassOf ?superClass .
}
WHERE {
$this owl:intersectionOf ?list .
?list rdf:rest*/rdf:first ?superClass .
FILTER isBlank(?superClass) .
}""" ;
sh:order 0 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:CreateNodeShapesAndPropertyShapesFromRestrictions
rdf:type sh:SPARQLRule ;
rdfs:comment "Creates a sh:property shape for each property that is mentioned in an owl:Restriction." ;
rdfs:label "owl:onProperty to sh:property" ;
sh:construct """
CONSTRUCT {
$this a sh:NodeShape .
$this a rdfs:Class .
$this sh:property ?propertyShape .
?propertyShape sh:path ?property .
}
WHERE {
$this rdfs:subClassOf/owl:onProperty ?property .
BIND (owl2sh-open:getPropertyShape(?property, $this) AS ?propertyShape) .
}
""" ;
sh:order 1 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:CreateNodeShapesAndPropertyShapesFromEquivalentClassHasValue
rdf:type sh:SPARQLRule ;
rdfs:comment "Creates a sh:property shape for each property that is mentioned in an owl:Restriction." ;
rdfs:label "owl:equivalentClass/owl:hasValue to sh:NodeShape with sh:hasValue" ;
sh:construct """
CONSTRUCT {
$this a sh:NodeShape .
$this a rdfs:Class .
$this sh:property ?propertyShape .
?propertyShape sh:path ?propertyProbablySkosInScheme .
?propertyShape sh:hasValue ?somethingProbablyAConceptScheme .
}
WHERE {
$this owl:equivalentClass ?restriction .
FILTER(isBlank(?restriction)) .
?restriction owl:hasValue ?somethingProbablyAConceptScheme .
?restriction owl:onProperty ?propertyProbablySkosInScheme .
BIND (owl2sh-open:getPropertyShape(?propertyProbablySkosInScheme, $this) AS ?propertyShape) .
}
""" ;
sh:order 1 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:CreateNodeShapesAndPropertyShapesFromMatchingDomains
rdf:type sh:SPARQLRule ;
rdfs:comment "Creates a sh:property shape for each property with matching rdfs:domain." ;
rdfs:label "rdfs:domain to sh:property" ;
sh:construct """
CONSTRUCT {
$this a sh:NodeShape .
$this a rdfs:Class .
$this sh:property ?propertyShape .
?propertyShape sh:path ?property .
}
WHERE {
{
?property rdfs:domain $this .
}
UNION {
?property rdfs:domain/owl:unionOf ?unionOf .
?unionOf rdf:rest*/rdf:first $this .
}
BIND (owl2sh-open:getPropertyShape(?property, $this) AS ?propertyShape) .
}
""" ;
sh:order 2 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlFunctionalProperty2shMaxCount1
rdf:type sh:SPARQLRule ;
rdfs:comment "For each relevant property that is owl:FunctionalProperty, create sh:maxCount of 1 (unless there is an OWL cardinality restriction)." ;
rdfs:label "owl:FunctionalProperty to sh:maxCount 1" ;
sh:construct """
CONSTRUCT {
?propertyShape sh:maxCount 1 .
}
WHERE {
$this sh:property ?propertyShape .
?propertyShape sh:path ?property .
?property a owl:FunctionalProperty .
FILTER NOT EXISTS {
$this rdfs:subClassOf* ?class .
?class rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
?restriction owl:maxCardinality|owl:cardinality ?any .
}
}
""" ;
sh:order 3 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:rdfsRange2shNode
rdf:type sh:SPARQLRule ;
rdfs:comment "For each relevant property that has an rdfs:range, creates an sh:node if the range yielded a NodeShape that has an sh:hasValue constraint, instead of an sh:class" ;
rdfs:label "rdfs:range with IRI to sh:class or sh:datatype" ;
sh:construct """
CONSTRUCT {
?propertyShape sh:node ?range .
}
WHERE {
{
$this sh:property ?propertyShape .
}
?propertyShape sh:path ?property .
?property rdfs:range ?range .
?range sh:property ?propertyWithHasValue .
?propertyWithHasValue sh:hasValue ?anything .
}
""" ;
sh:order 4 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:rdfsRange2shClassOrDatatype
rdf:type sh:SPARQLRule ;
rdfs:comment "For each relevant property that has an rdfs:range, create sh:class or sh:datatype constraint unless it already exists (from a restriction)." ;
rdfs:label "rdfs:range with IRI to sh:class or sh:datatype" ;
sh:construct """
CONSTRUCT {
?propertyShape ?parameter ?range .
}
WHERE {
{
$this sh:property ?propertyShape .
# exclude cases where the range of the property was already interpreted as sh:class or sh:node
FILTER NOT EXISTS { ?propertyShape sh:class|sh:datatype|sh:node ?any } .
}
?propertyShape sh:path ?property .
?property rdfs:range ?range .
FILTER isIRI(?range) .
# exclude the case where range is rdfs:Literal, this will be handled with an sh:kind
FILTER(?range != rdfs:Literal) .
BIND (
IF(
(?range IN (xsd:boolean, xsd:string, xsd:date, xsd:dateTime, xsd:integer, xsd:float, xsd:double, xsd:duration, xsd:anyURI, rdf:langString)),
sh:datatype,
sh:class
) AS ?parameter) .
}
""" ;
sh:order 5 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:rdfsRangeLiteral2shNodeKind
rdf:type sh:SPARQLRule ;
rdfs:comment "For each relevant property that has an rdfs:range with value rdfs:Literal, create sh:nodeKind constraint." ;
rdfs:label "rdfs:range rdfs:Literal to sh:nodeKind sh:Literal" ;
sh:construct """
CONSTRUCT {
?propertyShape sh:nodeKind sh:Literal .
}
WHERE {
?propertyShape sh:path ?property .
?property a owl:DatatypeProperty .
?property rdfs:range rdfs:Literal .
}
""" ;
sh:order 5 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlMaxCardinality2shMaxCount
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:maxCardinality restriction, create a corresponding sh:maxCount constraint." ;
rdfs:label "owl:maxCardinality to sh:maxCount" ;
sh:construct """
CONSTRUCT {
?propertyShape sh:maxCount ?maxCount .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
?restriction owl:onProperty ?property .
?restriction owl:maxCardinality|owl:cardinality ?raw .
BIND (xsd:integer(?raw) AS ?maxCount) .
BIND (owl2sh-open:getPropertyShape(?property, $this) AS ?propertyShape) .
}
""" ;
sh:order 6 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlMaxQualifiedCardinalityOnClass2shMaxCount
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:maxQualifiedCardinality restriction on an IRI class, create a corresponding sh:maxCount constraint, if the owl:onClass is identical to the rdfs:range of the property." ;
rdfs:label "owl:maxQualifiedCardinality with owl:onClass to sh:maxCount" ;
sh:construct """
PREFIX sh: <http://www.w3.org/ns/shacl#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX owl2sh-open: <http://sparna.fr/ontologies/owl2sh-open#>
CONSTRUCT {
?propertyShape sh:maxCount ?maxCount .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:maxQualifiedCardinality ?raw .
?restriction owl:onProperty ?property .
?restriction owl:onClass ?onClass .
FILTER isIRI(?onClass) .
FILTER EXISTS { ?property rdfs:range ?onClass } .
BIND (xsd:integer(?raw) AS ?maxCount) .
BIND (owl2sh-open:getPropertyShape(?property, $this) AS ?propertyShape) .
}
""" ;
sh:order 6 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlMaxQualifiedCardinalityOnClass2shQualifiedMaxCount
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:maxQualifiedCardinality restriction on an IRI class, create a corresponding (new) sh:qualifiedMaxCount constraint, unless the owl:onClass is identical to the rdfs:range of the property." ;
rdfs:label "owl:maxQualifiedCardinality with owl:onClass to sh:qualifiedMaxCount" ;
sh:construct """
CONSTRUCT {
$this sh:property ?propertyShape .
?propertyShape sh:path ?property .
?propertyShape sh:qualifiedMaxCount ?maxCount .
?propertyShape sh:qualifiedValueShape ?valueShape .
?valueShape sh:class ?onClass .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:maxQualifiedCardinality ?raw .
?restriction owl:onProperty ?property .
?restriction owl:onClass ?onClass .
FILTER isIRI(?onClass) .
FILTER NOT EXISTS { ?property rdfs:range ?onClass } .
BIND (xsd:integer(?raw) AS ?maxCount) .
BIND (BNODE() AS ?propertyShape) .
BIND (BNODE() AS ?valueShape) .
}
""" ;
sh:order 6 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlMaxQualifiedCardinalityOnDataRange2shQualifiedMaxCount
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:maxQualifiedCardinality restriction on an IRI datatype, create a corresponding (new) sh:qualifiedMaxCount constraint." ;
rdfs:label "owl:maxQualifiedCardinality with owl:onDataRange to sh:qualifiedMaxCount" ;
sh:construct """
CONSTRUCT {
$this sh:property ?propertyShape .
?propertyShape sh:path ?property .
?propertyShape sh:qualifiedMaxCount ?maxCount .
?propertyShape sh:qualifiedValueShape ?valueShape .
?valueShape sh:datatype ?onDataRange .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:maxQualifiedCardinality ?raw .
?restriction owl:onProperty ?property .
?restriction owl:onDataRange ?onDataRange .
FILTER isIRI(?onDataRange) .
BIND (xsd:integer(?raw) AS ?maxCount) .
BIND (BNODE() AS ?propertyShape) .
BIND (BNODE() AS ?valueShape) .
}
""" ;
sh:order 6 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlMinCardinality2shMinCount
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:minCardinality restriction, create a corresponding sh:minCount constraint." ;
rdfs:label "owl:minCardinality to sh:minCount" ;
sh:construct """
CONSTRUCT {
?propertyShape sh:minCount ?maxCount .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:minCardinality|owl:cardinality ?raw .
?restriction owl:onProperty ?property .
BIND (xsd:integer(?raw) AS ?maxCount) .
BIND (owl2sh-open:getPropertyShape(?property, $this) AS ?propertyShape) .
}
""" ;
sh:order 6 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlMinQualifiedCardinalityOnClass2shMinCount
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:minQualifiedCardinality restriction on an IRI class, create a corresponding sh:minCount constraint, if the owl:onClass is identical to the rdfs:range of the property." ;
rdfs:label "owl:minQualifiedCardinality with owl:onClass to sh:minCount" ;
sh:construct """
CONSTRUCT {
?propertyShape sh:minCount ?minCount .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:minQualifiedCardinality ?raw .
?restriction owl:onClass ?onClass .
?restriction owl:onProperty ?property .
FILTER isIRI(?onClass) .
FILTER EXISTS { ?property rdfs:range ?onClass } .
BIND (xsd:integer(?raw) AS ?minCount) .
BIND (owl2sh-open:getPropertyShape(?property, $this) AS ?propertyShape) .
}
""" ;
sh:order 6 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlMinQualifiedCardinalityOnClass2shQualifiedMinCount
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:minQualifiedCardinality restriction on an IRI class, create a corresponding (new) sh:qualifiedMinCount constraint, unless the owl:onClass is identical to the rdfs:range of the property." ;
rdfs:label "owl:minQualifiedCardinality with owl:onClass to sh:qualifiedMinCount" ;
sh:construct """
CONSTRUCT {
$this sh:property ?propertyShape .
?propertyShape sh:path ?property .
?propertyShape sh:qualifiedMinCount ?minCount .
?propertyShape sh:qualifiedValueShape ?valueShape .
?valueShape sh:class ?onClass .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:minQualifiedCardinality ?raw .
?restriction owl:onClass ?onClass .
?restriction owl:onProperty ?property .
FILTER isIRI(?onClass) .
FILTER NOT EXISTS { ?property rdfs:range ?onClass } .
BIND (xsd:integer(?raw) AS ?minCount) .
BIND (BNODE() AS ?propertyShape) .
BIND (BNODE() AS ?valueShape) .
}
""" ;
sh:order 6 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlMinQualifiedCardinalityOnDataRange2shQualifiedMinCount
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:minQualifiedCardinality restriction on an IRI datatype, create a corresponding (new) sh:qualifiedMinCount constraint." ;
rdfs:label "owl:minQualifiedCardinality with owl:onDataRange to sh:qualifiedMinCount" ;
sh:construct """
CONSTRUCT {
$this sh:property ?propertyShape .
?propertyShape sh:path ?property .
?propertyShape sh:qualifiedMinCount ?minCount .
?propertyShape sh:qualifiedValueShape ?valueShape .
?valueShape sh:datatype ?onDataRange .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:minQualifiedCardinality ?raw .
?restriction owl:onDataRange ?onDataRange .
?restriction owl:onProperty ?property .
FILTER isIRI(?onDataRange) .
BIND (xsd:integer(?raw) AS ?minCount) .
BIND (BNODE() AS ?propertyShape) .
BIND (BNODE() AS ?valueShape) .
}
""" ;
sh:order 6 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlQualifiedCardinalityOnClass2shMinMaxCount
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:qualifiedCardinality restriction on an IRI class, create corresponding sh:max/minCount constraints, if the owl:onClass is identical to the rdfs:range of the property." ;
rdfs:label "owl:qualifiedCardinality with owl:onClass to sh:max/minCount" ;
sh:construct """
CONSTRUCT {
?propertyShape sh:maxCount ?count .
?propertyShape sh:minCount ?count .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:qualifiedCardinality ?raw .
?restriction owl:onClass ?onClass .
?restriction owl:onProperty ?property .
FILTER isIRI(?onClass) .
FILTER EXISTS { ?property rdfs:range ?onClass } .
BIND (xsd:integer(?raw) AS ?count) .
BIND (owl2sh-open:getPropertyShape(?property, $this) AS ?propertyShape) .
}
""" ;
sh:order 6 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlQualifiedCardinalityOnClass2shQualifiedMinMaxCount
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:qualifiedCardinality restriction on an IRI class, create a corresponding (new) sh:qualifiedMax/MinCount constraint, unless the owl:onClass is identical to the rdfs:range of the property." ;
rdfs:label "owl:qualifiedCardinality with owl:onClass to sh:qualifiedMax/MinCount" ;
sh:construct """
CONSTRUCT {
$this sh:property ?propertyShape .
?propertyShape sh:path ?property .
?propertyShape sh:qualifiedMaxCount ?count .
?propertyShape sh:qualifiedMinCount ?count .
?propertyShape sh:qualifiedValueShape ?valueShape .
?valueShape sh:class ?onClass .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:qualifiedCardinality ?raw .
?restriction owl:onClass ?onClass .
?restriction owl:onProperty ?property .
FILTER isIRI(?onClass) .
FILTER NOT EXISTS { ?property rdfs:range ?onClass } .
BIND (xsd:integer(?raw) AS ?count) .
BIND (BNODE() AS ?propertyShape) .
BIND (BNODE() AS ?valueShape) .
}
""" ;
sh:order 6 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlQualifiedCardinalityOnDataRange2shQualifiedMinMaxCount
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:qualifiedCardinality restriction on an IRI datatype, create a corresponding (new) sh:qualifiedMax/MinCount constraint." ;
rdfs:label "owl:qualifiedCardinality with owl:onDataRange to sh:qualifiedMax/MinCount" ;
sh:construct """
CONSTRUCT {
$this sh:property ?propertyShape .
?propertyShape sh:path ?property .
?propertyShape sh:qualifiedMaxCount ?count .
?propertyShape sh:qualifiedMinCount ?count .
?propertyShape sh:qualifiedValueShape ?valueShape .
?valueShape sh:datatype ?onDataRange .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:qualifiedCardinality ?raw .
?restriction owl:onDataRange ?onDataRange .
?restriction owl:onProperty ?property .
FILTER isIRI(?onDataRange) .
BIND (xsd:integer(?raw) AS ?count) .
BIND (BNODE() AS ?propertyShape) .
BIND (BNODE() AS ?valueShape) .
}
""" ;
sh:order 6 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlHasValue2shHasValue
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:hasValue restriction, create a corresponding sh:hasValue constraint." ;
rdfs:label "owl:hasValue to sh:hasValue" ;
sh:construct """
CONSTRUCT {
?propertyShape sh:hasValue ?hasValue .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:onProperty ?property .
?restriction owl:hasValue ?hasValue .
BIND (owl2sh-open:getPropertyShape(?property, $this) AS ?propertyShape) .
}
""" ;
sh:order 8 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlSomeValuesFrom2shMinCount1
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:someValuesFrom restriction, create a corresponding sh:minCount 1 constraint." ;
rdfs:label "owl:someValuesFrom to sh:minCount 1" ;
sh:construct """
CONSTRUCT {
?propertyShape sh:minCount 1 .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
?restriction owl:someValuesFrom ?someValuesFrom .
?restriction owl:onProperty ?property .
BIND (owl2sh-open:getPropertyShape(?property, $this) AS ?propertyShape) .
}
""" ;
sh:order 4 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlSomeValuesFromAllValuesFrom2dashHasValueWithClass
rdf:type sh:SPARQLRule ;
rdfs:comment """For each owl:someValuesFrom restriction combined with an owl:allValuesFrom on an IRI, create a corresponding dash:hasValueWithClass constraint using a path expression.
For example:
ex:ConstitutionalOwner
a owl:Class ;
rdfs:subClassOf [
a owl:Restriction ;
owl:onProperty ex:isPlayedBy ;
owl:someValuesFrom [
a owl:Restriction ;
owl:allValuesFrom ex:StockholdersEquity ;
owl:onProperty ex:holdsEquityIn ;
] ;
] .
becomes
ex:ConstitutionalOwner
a sh:NodeShape ;
sh:property [
sh:path ( ex:isPlayedBy ex:holdsEquityIn ) ;
dash:hasValueWithClass ex:StockholdersEquity ;
] .""" ;
rdfs:label "owl:someValuesFrom with IRI to dash:hasValueWithClass" ;
sh:construct """
CONSTRUCT {
$this sh:property ?propertyShape .
?propertyShape dash:hasValueWithClass ?allValuesFrom .
?propertyShape sh:path ?firstNode .
?firstNode rdf:first ?property .
?firstNode rdf:rest ?secondNode .
?secondNode rdf:first ?allValuesFromProperty .
?secondNode rdf:rest rdf:nil .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:someValuesFrom ?someValuesFrom .
?someValuesFrom owl:allValuesFrom ?allValuesFrom .
FILTER isIRI(?allValuesFrom) .
FILTER (!(?allValuesFrom IN (xsd:boolean, xsd:string, xsd:date, xsd:dateTime, xsd:integer, xsd:float, xsd:double, xsd:duration, xsd:anyURI))) .
FILTER isBlank(?someValuesFrom) .
}
?restriction owl:onProperty ?property .
?someValuesFrom owl:onProperty ?allValuesFromProperty .
BIND (BNODE() AS ?propertyShape) .
BIND (BNODE() AS ?firstNode) .
BIND (BNODE() AS ?secondNode) .
}
""" ;
sh:order 7 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlUnionOfIRIs2rdfsSubClassOf
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:unionOf that only consists of named classes, move these classes into \"normal\" rdfs:subClassOf triples." ;
rdfs:label "owl:unionOf IRIs to rdfs:subClassOf" ;
sh:construct """
CONSTRUCT {
$this rdfs:subClassOf ?class .
# ?union owl2sh-open:mappedTo $this .
}
WHERE {
{
$this rdfs:subClassOf ?union .
?union owl:unionOf ?unionOf .
FILTER isBlank(?union) .
}
FILTER NOT EXISTS {
?unionOf rdf:rest*/rdf:first ?member .
FILTER (!isIRI(?member)) .
} .
?unionOf rdf:rest*/rdf:first ?class .
}
""" ;
sh:order 4 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlSomeValuesFromIRI2dashHasValueWithClass
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:someValuesFrom restriction with an IRI, create a corresponding dash:hasValueWithClass constraint." ;
rdfs:label "owl:someValuesFrom with IRI to dash:hasValueWithClass" ;
sh:construct """
CONSTRUCT {
?propertyShape dash:hasValueWithClass ?someValuesFrom .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:someValuesFrom ?someValuesFrom .
?restriction owl:onProperty ?property .
FILTER (isIRI(?someValuesFrom))
FILTER (!(?someValuesFrom IN (xsd:boolean, xsd:string, xsd:date, xsd:dateTime, xsd:integer, xsd:float, xsd:double, xsd:duration, xsd:anyURI))) .
FILTER NOT EXISTS { ?property rdfs:range ?someValuesFrom } .
BIND (owl2sh-open:getPropertyShape(?property, $this) AS ?propertyShape) .
}
""" ;
sh:order 4 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:owlAllValuesFrom2shClassOrDatatype
rdf:type sh:SPARQLRule ;
rdfs:comment "For each owl:allValuesFrom restriction, create a corresponding sh:class or sh:datatype constraint." ;
rdfs:label "owl:allValuesFrom with IRI to sh:class or sh:datatype" ;
sh:construct """
CONSTRUCT {
?propertyShape ?parameter ?allValuesFrom .
# ?restriction owl2sh-open:mappedTo ?propertyShape .
}
WHERE {
{
$this rdfs:subClassOf ?restriction .
?restriction a owl:Restriction .
FILTER isBlank(?restriction) .
}
?restriction owl:onProperty ?property .
?restriction owl:allValuesFrom ?allValuesFrom .
FILTER isIRI(?allValuesFrom) .
BIND (owl2sh-open:getPropertyShape(?property, $this) AS ?propertyShape) .
BIND (
IF(
(?allValuesFrom IN (xsd:boolean, xsd:string, xsd:date, xsd:dateTime, xsd:integer, xsd:float, xsd:double, xsd:duration, xsd:anyURI)),
sh:datatype,
sh:class
)
AS ?parameter
) .
}
""" ;
sh:order 4 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
owl2sh-open:shPropertyShapeCleanUp
rdf:type sh:SPARQLRule ;
rdfs:comment "For each value of sh:property, add a rdf:type sh:PropertyShape triple." ;
rdfs:label "sh:property shape clean up" ;
sh:construct """CONSTRUCT {
?propertyShape a sh:PropertyShape .
}
WHERE {
?shape sh:property ?propertyShape .
}""" ;
sh:order 100 ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
.
# owl2sh-open:mappedTo
# rdf:type rdf:Property ;
# rdfs:comment "Associates an OWL/RDFS subject with one or more SHACL subjects that have been produced by the mapping rules. Statements that have been mapped to others can in principle be deleted. This is currently only used to flag blank nodes that appear in rdfs:subClassOf triples." ;
# rdfs:label "mapped to" ;
# .
owl2sh-open:getPropertyShape
rdf:type sh:SPARQLFunction ;
rdfs:comment "Gets an existing sh:PropertyShape for a given property at a given shape. If none is found, return a new blank node that will be reused by future calls." ;
rdfs:label "get property shape" ;
sh:parameter [
sh:path owl2sh-open:predicate ;
sh:class rdf:Property ;
sh:description "The predicate to match." ;
] ;
sh:parameter [
sh:path owl2sh-open:shape ;
sh:class sh:Shape ;
sh:description "The shape hosting the constraint." ;
] ;
sh:prefixes <http://data.sparna.fr/ontologies/owl2sh-open> ;
sh:returnType sh:PropertyShape ;
sh:select """
SELECT ?result
WHERE {
{
?shape sh:property ?result .
?result sh:path ?predicate .
}
UNION
{
BIND(
IF(
CONTAINS(STR(?predicate), '#'),
STRAFTER(STR(?predicate), '#'),
REPLACE(REPLACE(STR(?predicate), '/', '_'), ':', '_')
)
AS ?propertyLocalName
)
BIND (
IF(isIRI($shape),
IRI(CONCAT(
STR($shape),
\"-\",
?propertyLocalName
)),
BNODE()
)
AS ?result) .
}
}
""" ;
.