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
|
package rsacomb
import java.util.{ArrayList => JList}
import org.scalatest.LoneElement
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.semanticweb.owlapi.model.OWLClassExpression
import uk.ac.manchester.cs.owl.owlapi.{
OWLClassImpl,
OWLObjectSomeValuesFromImpl,
OWLObjectIntersectionOfImpl,
OWLObjectOneOfImpl,
OWLObjectAllValuesFromImpl,
OWLObjectMaxCardinalityImpl,
OWLNamedIndividualImpl
}
import uk.ac.manchester.cs.owl.owlapi.{OWLObjectPropertyImpl}
import org.semanticweb.owlapi.model.IRI
import tech.oxfordsemantic.jrdfox.logic.expression.{IRI => RDFIRI}
import tech.oxfordsemantic.jrdfox.logic.Datatype
import tech.oxfordsemantic.jrdfox.logic.datalog.{
TupleTableAtom,
TupleTableName,
BindAtom
}
import tech.oxfordsemantic.jrdfox.logic.expression.{
FunctionCall,
Term,
Variable,
Literal
}
import uk.ac.ox.cs.rsacomb.converter.{
RDFoxRuleShards,
RDFoxClassExprConverter,
SkolemStrategy,
Standard,
Constant
}
import uk.ac.ox.cs.rsacomb.util.RSA
object OWLClassSpec {
// IRI
val iri_Professor = IRI.create("univ:Professor")
val iri_Female = IRI.create("std:Female")
val iri_Student = IRI.create("univ:Student")
val iri_Worker = IRI.create("univ:Worker")
val iri_alice = IRI.create("univ:alice")
val iri_supervises = IRI.create("univ:supervises")
val iri_hasSupervisor = IRI.create("univ:hasSupervisor")
// RDFox Terms
val term_x = Variable.create("x")
val term_y = Variable.create("y")
val term_c1 = RSA("c_1")
val term_c2 = RSA("c_2")
val term_alice = RDFIRI.create("univ:alice")
// RDFox Predicates
val pred_sameAs = TupleTableName.create("owl:sameAs")
val pred_Professor = TupleTableName.create(iri_Professor.getIRIString)
val pred_hasSupervisor = TupleTableName.create(iri_hasSupervisor.getIRIString)
// OWL Classes
// Name Class corresponding to
//
// Professor
//
val class_Professor = new OWLClassImpl(iri_Professor)
val class_Female = new OWLClassImpl(iri_Female)
val class_Student = new OWLClassImpl(iri_Student)
val class_Worker = new OWLClassImpl(iri_Worker)
val class_OWLClass = class_Professor
// Class Conjunction corresponding to
//
// Female ∧ Student ∧ Worker
//
val class_OWLObjectIntersectionOf = {
val conjuncts = new JList[OWLClassExpression]()
conjuncts.add(class_Female)
conjuncts.add(class_Student)
conjuncts.add(class_Worker)
new OWLObjectIntersectionOfImpl(conjuncts)
}
// Singleton Class corresponding to
//
// { alice }
//
val class_OWLObjectOneOf =
new OWLObjectOneOfImpl(
new OWLNamedIndividualImpl(iri_alice)
)
// Object Existential Restiction corresponding to
//
// ∃ hasSupervisor.Professor
//
val class_OWLObjectSomeValuesFrom =
new OWLObjectSomeValuesFromImpl(
new OWLObjectPropertyImpl(iri_hasSupervisor),
class_Professor
)
// Object Max Cardinality Restriction corresponding to
//
// ≤1 hasSupervisor.Professor
val class_OWLObjectMaxCardinality =
new OWLObjectMaxCardinalityImpl(
new OWLObjectPropertyImpl(iri_hasSupervisor),
1,
class_Professor
)
} // object OWLClassSpec
class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement {
// Import required data
import OWLClassSpec._
// OWLClass
class_OWLClass.toString should "be converted into a RDFoxRuleShards" in {
val visitor = RDFoxClassExprConverter(term_x)
val result = class_OWLClass.accept(visitor)
result shouldBe a[RDFoxRuleShards]
}
it should "have a single TupleTableAtom in its result list" in {
val visitor = RDFoxClassExprConverter(term_x)
val result = class_OWLClass.accept(visitor)
result.res.loneElement shouldBe an[TupleTableAtom]
}
it should "have an empty extension list" in {
val visitor = RDFoxClassExprConverter(term_x)
val result = class_OWLClass.accept(visitor)
result.ext shouldBe empty
}
// OWLObjectIntersectionOf
class_OWLObjectIntersectionOf.toString should "be converted into a RDFoxRuleShards" in {
val visitor = RDFoxClassExprConverter(term_x)
val result = class_OWLObjectIntersectionOf.accept(visitor)
result shouldBe a[RDFoxRuleShards]
}
it should "be converted in the union of its converted conjuncts" in {
val visitor = RDFoxClassExprConverter(term_x)
val result1 = class_OWLObjectIntersectionOf.accept(visitor)
val result2 = RDFoxClassExprConverter.merge(
List(
class_Female.accept(visitor),
class_Student.accept(visitor),
class_Worker.accept(visitor)
)
)
result1.res should contain theSameElementsAs result2.res
result1.ext should contain theSameElementsAs result2.ext
}
// OWLObjectOneOf
class_OWLObjectOneOf.toString should "be converted into a RDFoxRuleShards" in {
val visitor = RDFoxClassExprConverter(term_x)
val result = class_OWLObjectOneOf.accept(visitor)
result shouldBe a[RDFoxRuleShards]
}
// it should "be converted into a single <owl:sameAs> TupleTableAtom" in {
// val visitor = RDFoxClassExprConverter(term_x)
// val result = class_OWLObjectOneOf.accept(visitor)
// result.res.loneElement should (be (a [TupleTableAtom]) and have ('tupleTableName (pred_sameAs)))
// }
it should "have an empty extension list" in {
val visitor = RDFoxClassExprConverter(term_x)
val result = class_OWLObjectOneOf.accept(visitor)
result.ext shouldBe empty
}
// OWLObjectSomeValuesFrom
(class_OWLObjectSomeValuesFrom.toString ++ " w/o skolemization") should
"be converted into a RDFoxRuleShards" in {
val visitor = RDFoxClassExprConverter(term_x)
val result = class_OWLObjectSomeValuesFrom.accept(visitor)
result shouldBe a[RDFoxRuleShards]
}
it should "have two TupleTableAtoms in its result list" in {
val visitor = RDFoxClassExprConverter(term_x)
val result = class_OWLObjectSomeValuesFrom.accept(visitor)
exactly(2, result.res) should (be(an[TupleTableAtom])
//and have('numberOfArguments (3))
)
}
it should "have an empty extension list" in {
val visitor = RDFoxClassExprConverter(term_x)
val result = class_OWLObjectSomeValuesFrom.accept(visitor)
result.ext shouldBe empty
}
(class_OWLObjectSomeValuesFrom.toString ++ " w/ skolemization") should
"be converted into a RDFoxRuleShards" in {
val skolem = Standard(class_OWLObjectSomeValuesFrom.toString)
val visitor = RDFoxClassExprConverter(term_x, List(), skolem)
val result = class_OWLObjectSomeValuesFrom.accept(visitor)
result shouldBe a[RDFoxRuleShards]
}
it should "have exactly two TupleTableAtoms in its result list" in {
val skolem = Standard(class_OWLObjectSomeValuesFrom.toString)
val visitor = RDFoxClassExprConverter(term_x, List(), skolem)
val result = class_OWLObjectSomeValuesFrom.accept(visitor)
exactly(2, result.res) should (be(an[TupleTableAtom])
//and have('numberOfArguments (3))
)
}
it should "should have a single SKOLEM call in the extension list" in {
val skolem = Standard(class_OWLObjectSomeValuesFrom.toString)
val visitor = RDFoxClassExprConverter(term_x, List(), skolem)
val result = class_OWLObjectSomeValuesFrom.accept(visitor)
result.ext.loneElement shouldBe a[BindAtom]
val builtin = result.ext.head.asInstanceOf[BindAtom].getExpression
builtin should (be(a[FunctionCall]) and have(
'functionName ("SKOLEM")
))
}
(class_OWLObjectSomeValuesFrom.toString ++ " w/ constant skolemization") should
"be converted into a RDFoxRuleShards" in {
val skolem = Constant(class_OWLObjectSomeValuesFrom.toString)
val visitor = RDFoxClassExprConverter(term_x, List(), skolem)
val result = class_OWLObjectSomeValuesFrom.accept(visitor)
result shouldBe a[RDFoxRuleShards]
}
it should "have exactly two TupleTableAtoms in its result list" in {
val skolem = Constant(class_OWLObjectSomeValuesFrom.toString)
val visitor = RDFoxClassExprConverter(term_x, List(), skolem)
val result = class_OWLObjectSomeValuesFrom.accept(visitor)
exactly(2, result.res) should (be(an[TupleTableAtom])
//and have('numberOfArguments (3))
)
}
it should "have an empty extension list" in {
val skolem = Constant(class_OWLObjectSomeValuesFrom.toString)
val visitor = RDFoxClassExprConverter(term_x, List(), skolem)
val result = class_OWLObjectSomeValuesFrom.accept(visitor)
result.ext shouldBe empty
}
// OWLObjectMaxCardinalityImpl
class_OWLObjectMaxCardinality.toString should
"be converted into a RDFoxRuleShards" in {
val visitor = RDFoxClassExprConverter(term_x)
val result = class_OWLObjectMaxCardinality.accept(visitor)
result shouldBe a[RDFoxRuleShards]
}
// it should "have a single <owl:sameAs> TupleTableAtom in the result list" in {
// val visitor = RDFoxClassExprConverter(term_x)
// val result = class_OWLObjectMaxCardinality.accept(visitor)
// result.res.loneElement should (be(an[TupleTableAtom]) and have(
// 'tupleTableName (pred_sameAs)
// ))
// }
it should "have 4 TupleTableAtoms in its extension list" in {
val visitor = RDFoxClassExprConverter(term_x)
val result = class_OWLObjectMaxCardinality.accept(visitor)
exactly(4, result.ext) should (be(an[TupleTableAtom])
//and have('numberOfArguments (3))
)
}
} // class OWLClassSpec
|