-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUUIDTransformations
More file actions
74 lines (60 loc) · 2.42 KB
/
Copy pathUUIDTransformations
File metadata and controls
74 lines (60 loc) · 2.42 KB
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
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 dmn: <http://www.semanticweb.org/pizzatutorial/ontologies/2020/PizzaTutorial#>
#Transformations to change an ontology from user defined names to UUIDs
#The dmn PREFIX above should be bound to the prefix for the domain ontology
# Create the entityCopy annotation property
# This will store a new UUID IRI for each entity
INSERT DATA
{dmn:entityCopy a owl:AnnotationProperty.}
#For debugging
SELECT ?i
WHERE {?i a owl:NamedIndividual.}
SELECT ?s ?o
WHERE {?s dmn:entityCopy ?o .}
#Make UUID copy for each individual
INSERT {?i dmn:entityCopy ?niri.}
WHERE {?i a owl:NamedIndividual.
BIND (IRI(CONCAT(str(dmn:),"NamedIndividual", STRUUID())) AS ?niri).}
#Make UUID copy for each class
#Check for anonymous classes, don't need UUID for them.
INSERT {?c dmn:entityCopy ?niri.}
WHERE {?c a owl:Class.
BIND(STRAFTER(STR(?c), '#') as ?name).
BIND (IRI(CONCAT(str(dmn:),"OwlClass", STRUUID())) AS ?niri).
FILTER(?c != owl:Thing && ?c != owl:Nothing && !isBlank(?c)).}
#Make UUID copy for each object property
INSERT {?pr dmn:entityCopy ?niri.}
WHERE {?pr a owl:ObjectProperty.
BIND (IRI(CONCAT(str(dmn:),"ObjectProperty",STRUUID())) AS ?niri).}
#Make UUID copy for each data property
INSERT {?pr dmn:entityCopy ?niri.}
WHERE {?pr a owl:DatatypeProperty.
BIND (IRI(CONCAT(str(dmn:),"DataProperty", STRUUID())) AS ?niri).}
#Change the triples to use the new UUIDs
#Could use COALESE instead of IF (BOUND but that results in many SPARQL
#Error messages so I'm using the IF (BOUND
DELETE {?e ?p ?o.}
INSERT {?newe ?newp ?newo.}
WHERE {?e ?p ?o.
OPTIONAL{?e dmn:entityCopy ?ne.}
OPTIONAL{?p dmn:entityCopy ?np.}
OPTIONAL{?o dmn:entityCopy ?no.}
BIND(IF (BOUND(?ne),?ne, ?e) AS ?newe)
BIND(IF (BOUND(?np),?np, ?p) AS ?newp)
BIND(IF (BOUND(?no),?no, ?o) AS ?newo)
FILTER(?p != dmn:entityCopy)}
#Delete the value for all entityCopy properties. This makes all the
#old IRIs orphans which will not be saved.
DELETE {?e dmn:entityCopy ?niri.}
WHERE {?e dmn:entityCopy ?niri.}
#Delete all the links from the entityCopy property to make it an orphan.
DELETE {dmn:entityCopy ?p ?o.}
WHERE {dmn:entityCopy ?p ?o.}
#Queries below used for debugging
SELECT *
WHERE {?i a owl:NamedIndividual;
dmn:entityCopy ?niri.}
SELECT *
WHERE {?e dmn:entityCopy ?niri.}