aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/rsacomb/OWLAxiomSpec.scala
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2020-07-15 17:48:11 +0100
committerFederico Igne <federico.igne@cs.ox.ac.uk>2020-07-15 17:48:11 +0100
commit0ccecbe8718c90201700897ee33e9082b7bfce50 (patch)
tree04a696141e8a6f5dd5e1e6c681b32dd03995cd41 /src/test/scala/rsacomb/OWLAxiomSpec.scala
parent58b8d3c11a9deebb40e21c70d0b085d01cada745 (diff)
downloadRSAComb-0ccecbe8718c90201700897ee33e9082b7bfce50.tar.gz
RSAComb-0ccecbe8718c90201700897ee33e9082b7bfce50.zip
Rename source code directory structure
Diffstat (limited to 'src/test/scala/rsacomb/OWLAxiomSpec.scala')
-rw-r--r--src/test/scala/rsacomb/OWLAxiomSpec.scala302
1 files changed, 302 insertions, 0 deletions
diff --git a/src/test/scala/rsacomb/OWLAxiomSpec.scala b/src/test/scala/rsacomb/OWLAxiomSpec.scala
new file mode 100644
index 0000000..b6a44f4
--- /dev/null
+++ b/src/test/scala/rsacomb/OWLAxiomSpec.scala
@@ -0,0 +1,302 @@
1package rsacomb
2
3import java.util.ArrayList
4import org.scalatest.{FlatSpec, Matchers, LoneElement}
5
6import uk.ac.manchester.cs.owl.owlapi.{OWLSubClassOfAxiomImpl}
7import uk.ac.manchester.cs.owl.owlapi.{OWLClassImpl, OWLObjectSomeValuesFromImpl, OWLObjectIntersectionOfImpl, OWLObjectOneOfImpl, OWLObjectAllValuesFromImpl, OWLObjectMaxCardinalityImpl, OWLNamedIndividualImpl}
8import uk.ac.manchester.cs.owl.owlapi.{OWLObjectPropertyImpl}
9import org.semanticweb.owlapi.model.{OWLAxiom,IRI}
10
11import tech.oxfordsemantic.jrdfox.logic.{Rule,Bind,BuiltinFunctionCall}
12import tech.oxfordsemantic.jrdfox.logic.{Atom, Predicate, Term, Variable, Individual}
13
14object OWLAxiomSpec {
15
16 // IRI
17 val iri_Professor = IRI.create("univ:Professor")
18 val iri_Female = IRI.create("std:Female")
19 val iri_Student = IRI.create("univ:Student")
20 val iri_PartTimeStudent = IRI.create("univ:PartTimeStudent")
21 val iri_Worker = IRI.create("univ:Worker")
22 val iri_alice = IRI.create("univ:alice")
23 val iri_supervises = IRI.create("univ:supervises")
24 val iri_hasSupervisor = IRI.create("univ:hasSupervisor")
25 val iri_sameAs = IRI.create("owl:sameAs")
26
27 // RDFox Terms
28 val term_x = Variable.create("x")
29 val term_y = Variable.create("y")
30 val term_z = Variable.create("z")
31 val term_c1 = Individual.create("internal:c_1")
32 val term_c2 = Individual.create("internal:c_2")
33 val term_alice = Individual.create("univ:alice")
34
35 // RDFox Predicates
36 val pred_sameAs = Predicate.create("owl:sameAs")
37 val pred_Professor = Predicate.create(iri_Professor.getIRIString)
38 val pred_hasSupervisor = Predicate.create(iri_hasSupervisor.getIRIString)
39
40 // OWL Classes
41 // Name Class corresponding to
42 //
43 // Professor
44 //
45 val class_Professor = new OWLClassImpl(iri_Professor)
46 val class_Female = new OWLClassImpl(iri_Female)
47 val class_Student = new OWLClassImpl(iri_Student)
48 val class_PartTimeStudent = new OWLClassImpl(iri_PartTimeStudent)
49 val class_Worker = new OWLClassImpl(iri_Worker)
50 val class_OWLClass = class_Professor
51 // Class Conjunction corresponding to
52 //
53 // Student ∧ Worker
54 //
55 val class_OWLObjectIntersectionOf =
56 new OWLObjectIntersectionOfImpl(
57 class_Student, class_Worker
58 )
59 // Singleton Class corresponding to
60 //
61 // { alice }
62 //
63 val class_OWLObjectOneOf =
64 new OWLObjectOneOfImpl(
65 new OWLNamedIndividualImpl(iri_alice)
66 )
67 // Object Existential Restiction corresponding to
68 //
69 // ∃ hasSupervisor.Professor
70 //
71 val class_OWLObjectSomeValuesFrom =
72 new OWLObjectSomeValuesFromImpl(
73 new OWLObjectPropertyImpl(iri_hasSupervisor),
74 class_Professor
75 )
76 // Object Max Cardinality Restriction corresponding to
77 //
78 // ≤ 1 hasSupervisor . Professor
79 val class_OWLObjectMaxCardinality =
80 new OWLObjectMaxCardinalityImpl(
81 new OWLObjectPropertyImpl(iri_hasSupervisor),
82 1,
83 class_Professor
84 )
85
86 // OWL Axioms
87 // Axiom SubClassOf corresponding to
88 //
89 // Student ∧ Worker -> PartTimeStudent
90 //
91 val axiom_OWLSubClassOf1 =
92 new OWLSubClassOfAxiomImpl(
93 class_OWLObjectIntersectionOf,
94 class_PartTimeStudent,
95 new ArrayList()
96 )
97
98 // Axiom SubClassOf corresponding to
99 //
100 // Student -> ∃ hasSupervisor.Professor
101 //
102 val axiom_OWLSubClassOf2 =
103 new OWLSubClassOfAxiomImpl(
104 class_Student,
105 class_OWLObjectSomeValuesFrom,
106 new ArrayList()
107 )
108
109 // Axiom SubClassOf corresponding to
110 //
111 // ∃ hasSupervisor.Professor -> Student
112 //
113 val axiom_OWLSubClassOf3 =
114 new OWLSubClassOfAxiomImpl(
115 class_OWLObjectSomeValuesFrom,
116 class_Student,
117 new ArrayList()
118 )
119
120 // Axiom SubClassOf corresponding to
121 //
122 // Student -> { alice }
123 //
124 val axiom_OWLSubClassOf4 =
125 new OWLSubClassOfAxiomImpl(
126 class_Student,
127 class_OWLObjectOneOf,
128 new ArrayList()
129 )
130
131 // Axiom SubClassOf corresponding to
132 //
133 // Student -> ≤1 hasSupervisor.Professor
134 //
135 val axiom_OWLSubClassOf5 =
136 new OWLSubClassOfAxiomImpl(
137 class_Student,
138 class_OWLObjectMaxCardinality,
139 new ArrayList()
140 )
141
142 def convertAxiom(
143 axiom: OWLAxiom,
144 term: Term,
145 skolem: SkolemStrategy = SkolemStrategy.None
146 ) : List[Rule] = {
147 axiom.accept(RDFoxAxiomConverter(term,skolem))
148 }
149
150} // object OWLAxiomSpec
151
152class OWLAxiomSpec
153 extends FlatSpec with Matchers with LoneElement
154{
155 // Import required data
156 import OWLAxiomSpec._
157
158 // OWLSubClassOfAxiom #1
159 axiom_OWLSubClassOf1.toString should "be converted into a singleton List[Rule]" in {
160 val result = convertAxiom(axiom_OWLSubClassOf1,term_x)
161 result.loneElement shouldBe a [Rule]
162 }
163
164 it should "contain a conjuction of atoms (Student[?x],Worker[?x]) in the body of the rule" in {
165 val result = convertAxiom(axiom_OWLSubClassOf1,term_x)
166 val body = List(
167 Atom.create(Predicate.create(iri_Student.getIRIString),term_x),
168 Atom.create(Predicate.create(iri_Worker.getIRIString),term_x)
169 )
170 result.loneElement.getBody should contain theSameElementsAs body
171 }
172
173 it should "contain a single atom (PartTimeStudent[?x]) in the head of the rule" in {
174 val result = convertAxiom(axiom_OWLSubClassOf1,term_x)
175 val head = Atom.create(Predicate.create(iri_PartTimeStudent.getIRIString),term_x)
176 result.loneElement.getHead.loneElement should be (head)
177 }
178
179 // OWLSubClassOfAxiom #2 (w/ constant skolemization)
180 (axiom_OWLSubClassOf2.toString + "\n(w/ constant skolemization)") should
181 "be converted into a singleton List[Rule]" in
182 {
183 val skolem = SkolemStrategy.Constant(axiom_OWLSubClassOf2.toString)
184 val result = convertAxiom(axiom_OWLSubClassOf2,term_x,skolem)
185 result.loneElement shouldBe a [Rule]
186 }
187
188 it should "contain a single atom (Student[?x]) in the body of the rule" in {
189 val skolem = SkolemStrategy.Constant(axiom_OWLSubClassOf2.toString)
190 val result = convertAxiom(axiom_OWLSubClassOf2,term_x,skolem)
191 val body = Atom.create(Predicate.create(iri_Student.getIRIString),term_x)
192 result.loneElement.getBody.loneElement should equal (body)
193 }
194
195 it should "contain a conjuction of atoms (hasSupervisor[?x,?c],Professor[?c]) in the head of the rule" in {
196 val skolem = SkolemStrategy.Constant(axiom_OWLSubClassOf2.toString)
197 val result = convertAxiom(axiom_OWLSubClassOf2,term_x,skolem)
198 val term_c = Individual.create(skolem.const)
199 val head = List(
200 Atom.create(Predicate.create(iri_hasSupervisor.getIRIString),term_x,term_c),
201 Atom.create(Predicate.create(iri_Professor.getIRIString),term_c)
202 )
203 result.loneElement.getHead should contain theSameElementsAs (head)
204 }
205
206 // OWLSubClassOfAxiom #2 (w/ skolemization)
207 (axiom_OWLSubClassOf2.toString + "\n(w/ skolemization)") should
208 "be converted into a singleton List[Rule]" in
209 {
210 val skolem = SkolemStrategy.Standard(axiom_OWLSubClassOf2.toString)
211 val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem)
212 result.loneElement shouldBe a [Rule]
213 }
214
215 it should "contain an atom (Student[?x]) in the body of the rule" in {
216 val skolem = SkolemStrategy.Standard(axiom_OWLSubClassOf2.toString)
217 val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem)
218 val body = Atom.create(Predicate.create(iri_Student.getIRIString),term_x)
219 result.loneElement.getBody should contain (body)
220 }
221
222 it should "contain a built-in function call (BIND(?y,SKOLEM(?f,?x))) in the body of the rule" in {
223 val skolem = SkolemStrategy.Standard(axiom_OWLSubClassOf2.toString)
224 val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem)
225 val call = Bind.create(BuiltinFunctionCall.create("SKOLEM",term_x),term_y)
226 result.loneElement.getBody should contain (call)
227 }
228
229 it should "contain a conjuction of atom (hasSupervisor[?x,?y],Professor[?y]) in the head of the rule" in {
230 val skolem = SkolemStrategy.Standard(axiom_OWLSubClassOf2.toString)
231 val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem)
232 val head = List(
233 Atom.create(Predicate.create(iri_hasSupervisor.getIRIString),term_x,term_y),
234 Atom.create(Predicate.create(iri_Professor.getIRIString),term_y)
235 )
236 result.loneElement.getHead should contain theSameElementsAs head
237 }
238
239 // OWLSubClassOfAxiom #3
240 axiom_OWLSubClassOf3.toString should "be converted into a singleton List[Rule]" in {
241 val result = convertAxiom(axiom_OWLSubClassOf3,term_x)
242 result.loneElement shouldBe a [Rule]
243 }
244
245 it should "contain a conjunction of atoms (hasSupervisor[?x,?y],Professor[?y]) in the body of the rule" in {
246 val result = convertAxiom(axiom_OWLSubClassOf3,term_x)
247 val body = List(
248 Atom.create(Predicate.create(iri_hasSupervisor.getIRIString),term_x,term_y),
249 Atom.create(Predicate.create(iri_Professor.getIRIString),term_y)
250 )
251 result.loneElement.getBody should contain theSameElementsAs body
252 }
253
254 it should "contain a single atom (Student[?x]) in the head of the rule" in {
255 val result = convertAxiom(axiom_OWLSubClassOf3, term_x)
256 val head = Atom.create(Predicate.create(iri_Student.getIRIString),term_x)
257 result.loneElement.getHead.loneElement should be (head)
258 }
259
260 // OWLSubClassOfAxiom #4
261 axiom_OWLSubClassOf4.toString should "be converted into a singleton List[Rule]" in {
262 val result = convertAxiom(axiom_OWLSubClassOf4,term_x)
263 result.loneElement shouldBe a [Rule]
264 }
265
266 it should "contain a single atoms (Student[?x]) in the body of the rule" in {
267 val result = convertAxiom(axiom_OWLSubClassOf4,term_x)
268 val body = Atom.create(Predicate.create(iri_Student.getIRIString),term_x)
269 result.loneElement.getBody.loneElement should be (body)
270 }
271
272 it should "contain a single atom (sameAs[?x,alice])) in the head of the rule" in {
273 val result = convertAxiom(axiom_OWLSubClassOf4, term_x)
274 val head = Atom.create(Predicate.create(iri_sameAs.getIRIString),term_x,term_alice)
275 result.loneElement.getHead.loneElement should be (head)
276 }
277
278 // OWLSubClassOfAxiom #5
279 axiom_OWLSubClassOf5.toString should "be converted into a singleton List[Rule]" in {
280 val result = convertAxiom(axiom_OWLSubClassOf5,term_x)
281 result.loneElement shouldBe a [Rule]
282 }
283
284 it should "contain a conjunction of atoms (...) in the body of the rule" in {
285 val result = convertAxiom(axiom_OWLSubClassOf5,term_x)
286 val body = List(
287 Atom.create(Predicate.create(iri_Student.getIRIString),term_x),
288 Atom.create(Predicate.create(iri_hasSupervisor.getIRIString),term_x,term_y),
289 Atom.create(Predicate.create(iri_Professor.getIRIString),term_y),
290 Atom.create(Predicate.create(iri_hasSupervisor.getIRIString),term_x,term_z),
291 Atom.create(Predicate.create(iri_Professor.getIRIString),term_z)
292 )
293 result.loneElement.getBody should contain theSameElementsAs body
294 }
295
296 it should "contain a single atom (sameAs[?x,?z])) in the head of the rule" in {
297 val result = convertAxiom(axiom_OWLSubClassOf5, term_x)
298 val head = Atom.create(Predicate.create(iri_sameAs.getIRIString),term_y,term_z)
299 result.loneElement.getHead.loneElement should be (head)
300 }
301
302} // class OWLAxiomSpec