-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinverse-functional-property-inference.sql
222 lines (159 loc) · 7.12 KB
/
inverse-functional-property-inference.sql
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
-- Cleanup
SPARQL CLEAR GRAPH <urn:spin:rule:foaf:ifp:lib1> ;
SPARQL DROP SPIN LIBRARY <urn:spin:rule:foaf:ifp:lib1> ;
-- Load Rules from data source
-- SPARQL
-- DEFINE get:soft "no-sponge"
-- LOAD <http://kingsley.idehen.net/DAV/home/kidehen/Public/SPIN%20Rules/spin-foaf-ifp.ttl> INTO <urn:spin:rule:foaf:ifp:lib1> ;
-- Remove rdf:type relations that have ldp:Resource, rdf:Resource as objects
-- SPARQL DELETE WHERE { GRAPH <urn:spin:rule:foaf:ifp:lib1> { <http://kingsley.idehen.net/DAV/home/kidehen/Public/SPIN%20Rules/geospatial-rules.ttl> ?p ?o }};
-- SPARQL DELETE WHERE { GRAPH <urn:spin:rule:foaf:ifp:lib1> { <http://kingsley.idehen.net/DAV/home/kidehen/Public/SPIN%20Rules/geospatial-rules.ttl#this> ?p ?o } };
TTLP ('
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix sp: <http://spinrdf.org/sp#> .
@prefix spl: <http://spinrdf.org/spl#> .
@prefix spin: <http://spinrdf.org/spin#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rel: <http://purl.org/vocab/relationship/> .
@prefix wdrs: <http://www.w3.org/2007/05/powder-s#> .
@prefix schema: <http://schema.org/> .
@prefix ecrm: <http://www.openlinksw.com/ontology/ecrm#> .
foaf:Person a rdfs:Class ;
rdfs:label "People"^^xsd:string ;
spin:rule
[
a sp:Construct, spin:Rule ;
rdfs:label "Identity Reconciliation using owl:InverseFunctionalProperty Semantics" ;
rdfs:comment """Generates explicit coreferences from IFP designaton of foaf:mbox relationship type (relation)""" ;
sp:text """
CONSTRUCT {?this owl:sameAs ?that}
WHERE {
?this foaf:mbox ?mbox1 .
?that foaf:mbox ?mbox2 .
FILTER (?mbox1 = ?mbox2)
FILTER (?this != ?that)
FILTER (! isblank(?that))
FILTER (! isblank(?this))
# FILTER (?this = <https://twitter.com/kidehen#this> )
}
"""
] .
',
'', 'urn:spin:rule:foaf:ifp:lib1', 4096 )
;
-- Rules Load Verification
SPARQL
SELECT COUNT (*)
FROM <urn:spin:rule:foaf:ifp:lib1> WHERE {?s ?p ?o} ;
-- Generate Macros
EXEC ('SPARQL ' || SPARQL_SPIN_GRAPH_TO_DEFSPIN('urn:spin:rule:foaf:ifp:lib1'));
-- Control Tests ---
-- Cleanup Named Graph to be used for Control Test
SPARQL
CLEAR GRAPH <urn:kidehen:ifp:test:2> ;
-- Copy Data to Control Test Named Graph
SPARQL
COPY <https://medium.com/virtuoso-blog/using-a-semantic-web-of-linked-data-to-reconcile-disparate-identities-83ab7a315568> TO <urn:kidehen:ifp:test:2> ;
-- Control Check 1 (totals need to match across source and target named graphs)
SPARQL
SELECT count (*)
FROM <https://medium.com/virtuoso-blog/using-a-semantic-web-of-linked-data-to-reconcile-disparate-identities-83ab7a315568>
WHERE {?s ?p ?o} ;
SPARQL
SELECT count (*)
FROM <urn:kidehen:ifp:test:2>
WHERE {?s ?p ?o} ;
-- Remove owl:sameAs relations
SPARQL
DELETE { GRAPH <urn:kidehen:ifp:test:2> {?s owl:sameAs ?o} }
WHERE { GRAPH <urn:kidehen:ifp:test:2> {?s owl:sameAs ?o} } ;
-- Control Check 2 (total must differ due to effect of owl:sameAs relation deletions )
SPARQL
SELECT count (*)
FROM <https://medium.com/virtuoso-blog/using-a-semantic-web-of-linked-data-to-reconcile-disparate-identities-83ab7a315568>
WHERE {?s ?p ?o} ;
SPARQL
SELECT count (*)
FROM <urn:kidehen:ifp:test:2>
WHERE {?s ?p ?o} ;
-- Test Query 1
-- Successful if materialization of missing owl:sameAs relations occurs, courtesy of Custom IFP Inference Rule Pragma
SPARQL
DEFINE input:macro-lib <urn:spin:rule:foaf:ifp:lib1>
# DEFINE input:inference ‘urn:ifp:inference:rule’
# DEFINE input:same-as "yes"
SELECT DISTINCT ?s owl:sameAs as ?sameAs ?o
# FROM <https://medium.com/virtuoso-blog/using-a-semantic-web-of-linked-data-to-reconcile-disparate-identities-83ab7a315568>
FROM <urn:kidehen:ifp:test:2>
WHERE {
?s a foaf:Person ;
owl:sameAs ?o .
FILTER (?s = <https://twitter.com/kidehen#this>)
} ;
-- Test Query 2
-- Successful if materialization of missing owl:sameAs relations occurs, courtesy of Custom IFP Inference Rule Pragma
-- Current Status: Fail
SPARQL
DEFINE input:macro-lib <urn:spin:rule:foaf:ifp:lib1>
# DEFINE input:same-as "yes"
DESCRIBE ?s
# FROM <https://medium.com/virtuoso-blog/using-a-semantic-web-of-linked-data-to-reconcile-disparate-identities-83ab7a315568>
FROM <urn:kidehen:ifp:test:2>
WHERE {
?s a foaf:Person ;
owl:sameAs ?o .
FILTER (?s = <https://twitter.com/kidehen#this>)
} ;
-- Test Query 3
-- Successful if materialization of missing owl:sameAs relations occurs, courtesy of Custom IFP Inference Rule Pragma
-- plus materialization of other relations based on "samesAs"
-- Current Status: Fail
-- Proof: Uncomment FROM <https://medium.com/virtuoso-blog/using-a-semantic-web-of-linked-data-to-reconcile-disparate-identities-83ab7a315568>
-- and then comment out FROM <urn:kidehen:ifp:test:2>, and then comment out "DEFINE input:macro-lib <urn:spin:rule:foaf:ifp:lib1>"
-- the solutions are different. The second solution correctly includes materialized relations from "owl:sameAs" inference pragma
SPARQL
DEFINE input:macro-lib <urn:spin:rule:foaf:ifp:lib1>
DEFINE input:same-as "yes"
DESCRIBE ?s
# FROM <https://medium.com/virtuoso-blog/using-a-semantic-web-of-linked-data-to-reconcile-disparate-identities-83ab7a315568>
FROM <urn:kidehen:ifp:test:2>
WHERE {
?s a foaf:Person ;
owl:sameAs ?o .
FILTER (?s = <https://twitter.com/kidehen#this>)
} ;
-- Test Query 4
SPARQL
DEFINE input:macro-lib <urn:spin:rule:foaf:ifp:lib1>
# DEFINE input:same-as "yes"
SELECT DISTINCT ?s ?sameAs ?mainEntityOfPage
# FROM <https://medium.com/virtuoso-blog/using-a-semantic-web-of-linked-data-to-reconcile-disparate-identities-83ab7a315568>
FROM <urn:kidehen:ifp:test:2>
WHERE {
?s a foaf:Person ;
owl:sameAs ?sameAs ;
schema:mainEntityOfPage ?mainEntityOfPage .
FILTER (?s = <https://twitter.com/kidehen#this> )
} ;
-- Test Query 5
-- Successful if materialization of missing owl:sameAs relations occurs, courtesy of Custom IFP Inference Rule Pragma
-- plus materialization of other relations based on "samesAs"
-- Current Status: Fail
-- Proof: Uncomment FROM <https://medium.com/virtuoso-blog/using-a-semantic-web-of-linked-data-to-reconcile-disparate-identities-83ab7a315568>
-- and then comment out FROM <urn:kidehen:ifp:test:2>, and then comment out "DEFINE input:macro-lib <urn:spin:rule:foaf:ifp:lib1>"
-- the solutions are different. The second solution correctly includes materialized relations from "owl:sameAs" inference pragma
SPARQL
DEFINE input:macro-lib <urn:spin:rule:foaf:ifp:lib1>
DEFINE input:same-as "yes"
SELECT DISTINCT ?s ?sameAs ?mainEntityOfPage
# FROM <https://medium.com/virtuoso-blog/using-a-semantic-web-of-linked-data-to-reconcile-disparate-identities-83ab7a315568>
FROM <urn:kidehen:ifp:test:2>
WHERE {
?s a foaf:Person ;
owl:sameAs ?sameAs ;
schema:mainEntityOfPage ?mainEntityOfPage .
FILTER (?s = <https://twitter.com/kidehen#this> )
} ;