aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/rsacomb/OWLClassSpec.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/OWLClassSpec.scala
parent58b8d3c11a9deebb40e21c70d0b085d01cada745 (diff)
downloadRSAComb-0ccecbe8718c90201700897ee33e9082b7bfce50.tar.gz
RSAComb-0ccecbe8718c90201700897ee33e9082b7bfce50.zip
Rename source code directory structure
Diffstat (limited to 'src/test/scala/rsacomb/OWLClassSpec.scala')
-rw-r--r--src/test/scala/rsacomb/OWLClassSpec.scala259
1 files changed, 259 insertions, 0 deletions
diff --git a/src/test/scala/rsacomb/OWLClassSpec.scala b/src/test/scala/rsacomb/OWLClassSpec.scala
new file mode 100644
index 0000000..df10e19
--- /dev/null
+++ b/src/test/scala/rsacomb/OWLClassSpec.scala
@@ -0,0 +1,259 @@
1package rsacomb
2
3import org.scalatest.{FlatSpec, Matchers, LoneElement}
4
5import uk.ac.manchester.cs.owl.owlapi.{OWLClassImpl, OWLObjectSomeValuesFromImpl, OWLObjectIntersectionOfImpl, OWLObjectOneOfImpl, OWLObjectAllValuesFromImpl, OWLObjectMaxCardinalityImpl, OWLNamedIndividualImpl}
6import uk.ac.manchester.cs.owl.owlapi.{OWLObjectPropertyImpl}
7import org.semanticweb.owlapi.model.IRI
8
9import tech.oxfordsemantic.jrdfox.logic.{Bind,BuiltinFunctionCall}
10import tech.oxfordsemantic.jrdfox.logic.{Atom, Predicate, Term, Variable, Individual}
11
12import rsacomb.RDFoxRuleShards
13
14object OWLClassSpec {
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_Worker = IRI.create("univ:Worker")
21 val iri_alice = IRI.create("univ:alice")
22 val iri_supervises = IRI.create("univ:supervises")
23 val iri_hasSupervisor = IRI.create("univ:hasSupervisor")
24
25 // RDFox Terms
26 val term_x = Variable.create("x")
27 val term_y = Variable.create("y")
28 val term_c1 = Individual.create("internal:c_1")
29 val term_c2 = Individual.create("internal:c_2")
30 val term_alice = Individual.create("univ:alice")
31
32 // RDFox Predicates
33 val pred_sameAs = Predicate.create("owl:sameAs")
34 val pred_Professor = Predicate.create(iri_Professor.getIRIString)
35 val pred_hasSupervisor = Predicate.create(iri_hasSupervisor.getIRIString)
36
37 // OWL Classes
38 // Name Class corresponding to
39 //
40 // Professor
41 //
42 val class_Professor = new OWLClassImpl(iri_Professor)
43 val class_Female = new OWLClassImpl(iri_Female)
44 val class_Student = new OWLClassImpl(iri_Student)
45 val class_Worker = new OWLClassImpl(iri_Worker)
46 val class_OWLClass = class_Professor
47
48 // Class Conjunction corresponding to
49 //
50 // Female ∧ Student ∧ Worker
51 //
52 val class_OWLObjectIntersectionOf =
53 new OWLObjectIntersectionOfImpl(
54 class_Female, class_Student, class_Worker
55 )
56 // Singleton Class corresponding to
57 //
58 // { alice }
59 //
60 val class_OWLObjectOneOf =
61 new OWLObjectOneOfImpl(
62 new OWLNamedIndividualImpl(iri_alice)
63 )
64 // Object Existential Restiction corresponding to
65 //
66 // ∃ hasSupervisor.Professor
67 //
68 val class_OWLObjectSomeValuesFrom =
69 new OWLObjectSomeValuesFromImpl(
70 new OWLObjectPropertyImpl(iri_hasSupervisor),
71 class_Professor
72 )
73 // Object Max Cardinality Restriction corresponding to
74 //
75 // ≤1 hasSupervisor.Professor
76 val class_OWLObjectMaxCardinality =
77 new OWLObjectMaxCardinalityImpl(
78 new OWLObjectPropertyImpl(iri_hasSupervisor),
79 1,
80 class_Professor
81 )
82} // object OWLClassSpec
83
84class OWLClassSpec
85 extends FlatSpec with Matchers with LoneElement
86{
87 // Import required data
88 import OWLClassSpec._
89
90 // OWLClass
91 class_OWLClass.toString should "be converted into a RDFoxRuleShards" in {
92 val visitor = RDFoxClassExprConverter(term_x)
93 val result = class_OWLClass.accept(visitor)
94 result shouldBe a [RDFoxRuleShards]
95 }
96
97 it should "have a single Atom in its result list" in {
98 val visitor = RDFoxClassExprConverter(term_x)
99 val result = class_OWLClass.accept(visitor)
100 result.res.loneElement shouldBe an [Atom]
101 }
102
103 it should "have an empty extension list" in {
104 val visitor = RDFoxClassExprConverter(term_x)
105 val result = class_OWLClass.accept(visitor)
106 result.ext shouldBe empty
107 }
108
109 // OWLObjectIntersectionOf
110 class_OWLObjectIntersectionOf.toString should "be converted into a RDFoxRuleShards" in {
111 val visitor = RDFoxClassExprConverter(term_x)
112 val result = class_OWLObjectIntersectionOf.accept(visitor)
113 result shouldBe a [RDFoxRuleShards]
114 }
115
116 it should "be converted in the union of its converted conjuncts" in {
117 val visitor = RDFoxClassExprConverter(term_x)
118 val result1= class_OWLObjectIntersectionOf.accept(visitor)
119 val result2 = RDFoxClassExprConverter.merge(List(
120 class_Female.accept(visitor),
121 class_Student.accept(visitor),
122 class_Worker.accept(visitor)
123 ))
124 result1.res should contain theSameElementsAs result2.res
125 result1.ext should contain theSameElementsAs result2.ext
126 }
127
128 // OWLObjectOneOf
129 class_OWLObjectOneOf.toString should "be converted into a RDFoxRuleShards" in {
130 val visitor = RDFoxClassExprConverter(term_x)
131 val result = class_OWLObjectOneOf.accept(visitor)
132 result shouldBe a [RDFoxRuleShards]
133 }
134
135 it should "be converted into a single <owl:sameAs> Atom" in {
136 val visitor = RDFoxClassExprConverter(term_x)
137 val result = class_OWLObjectOneOf.accept(visitor)
138 result.res.loneElement should (be (a [Atom]) and have ('predicate (pred_sameAs)))
139 }
140
141 it should "have an empty extension list" in {
142 val visitor = RDFoxClassExprConverter(term_x)
143 val result = class_OWLObjectOneOf.accept(visitor)
144 result.ext shouldBe empty
145 }
146
147 // OWLObjectSomeValuesFrom
148 (class_OWLObjectSomeValuesFrom.toString ++ " w/o skolemization") should
149 "be converted into a RDFoxRuleShards" in {
150 val visitor = RDFoxClassExprConverter(term_x,SkolemStrategy.None)
151 val result = class_OWLObjectSomeValuesFrom.accept(visitor)
152 result shouldBe a [RDFoxRuleShards]
153 }
154
155 it should "have exactly one unary Atom in its result list" in {
156 val visitor = RDFoxClassExprConverter(term_x,SkolemStrategy.None)
157 val result = class_OWLObjectSomeValuesFrom.accept(visitor)
158 exactly (1, result.res) should (be (an [Atom]) and have ('numberOfArguments (1)))
159 }
160
161 it should "have exactly one binary Atom in its result list" in {
162 val visitor = RDFoxClassExprConverter(term_x,SkolemStrategy.None)
163 val result = class_OWLObjectSomeValuesFrom.accept(visitor)
164 exactly (1, result.res) should (be (an [Atom]) and have ('numberOfArguments (2)))
165 }
166
167 it should "have an empty extension list" in {
168 val visitor = RDFoxClassExprConverter(term_x,SkolemStrategy.None)
169 val result = class_OWLObjectSomeValuesFrom.accept(visitor)
170 result.ext shouldBe empty
171 }
172
173 (class_OWLObjectSomeValuesFrom.toString ++ " w/ skolemization") should
174 "be converted into a RDFoxRuleShards" in {
175 val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString)
176 val visitor = RDFoxClassExprConverter(term_x,skolem)
177 val result = class_OWLObjectSomeValuesFrom.accept(visitor)
178 result shouldBe a [RDFoxRuleShards]
179 }
180
181 it should "have exactly one unary Atom in its result list" in {
182 val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString)
183 val visitor = RDFoxClassExprConverter(term_x,skolem)
184 val result = class_OWLObjectSomeValuesFrom.accept(visitor)
185 exactly (1, result.res) should (be (an [Atom]) and have ('numberOfArguments (1)))
186 }
187
188 it should "have exactly one binary Atom in its result list" in {
189 val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString)
190 val visitor = RDFoxClassExprConverter(term_x,skolem)
191 val result = class_OWLObjectSomeValuesFrom.accept(visitor)
192 exactly (1, result.res) should (be (an [Atom]) and have ('numberOfArguments (2)))
193 }
194
195 it should "should have a single SKOLEM call in the extension list" in {
196 val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString)
197 val visitor = RDFoxClassExprConverter(term_x,skolem)
198 val result = class_OWLObjectSomeValuesFrom.accept(visitor)
199 result.ext.loneElement shouldBe a [Bind]
200 val builtin = result.ext.head.asInstanceOf[Bind].getBuiltinExpression
201 builtin should (be (a [BuiltinFunctionCall]) and have ('functionName ("SKOLEM")))
202 }
203
204 (class_OWLObjectSomeValuesFrom.toString ++ " w/ constant skolemization") should
205 "be converted into a RDFoxRuleShards" in {
206 val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString)
207 val visitor = RDFoxClassExprConverter(term_x,skolem)
208 val result = class_OWLObjectSomeValuesFrom.accept(visitor)
209 result shouldBe a [RDFoxRuleShards]
210 }
211
212 it should "have exactly one unary Atom in its result list" in {
213 val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString)
214 val visitor = RDFoxClassExprConverter(term_x,skolem)
215 val result = class_OWLObjectSomeValuesFrom.accept(visitor)
216 exactly (1, result.res) should (be (an [Atom]) and have ('numberOfArguments (1)))
217 }
218
219 it should "have exactly one binary Atom in its result list" in {
220 val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString)
221 val visitor = RDFoxClassExprConverter(term_x,skolem)
222 val result = class_OWLObjectSomeValuesFrom.accept(visitor)
223 exactly (1, result.res) should (be (an [Atom]) and have ('numberOfArguments (2)))
224 }
225
226 it should "have an empty extension list" in {
227 val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString)
228 val visitor = RDFoxClassExprConverter(term_x,skolem)
229 val result = class_OWLObjectSomeValuesFrom.accept(visitor)
230 result.ext shouldBe empty
231 }
232
233 // OWLObjectMaxCardinalityImpl
234 class_OWLObjectMaxCardinality.toString should
235 "be converted into a RDFoxRuleShards" in {
236 val visitor = RDFoxClassExprConverter(term_x)
237 val result = class_OWLObjectMaxCardinality.accept(visitor)
238 result shouldBe a [RDFoxRuleShards]
239 }
240
241 it should "have a single <owl:sameAs> Atom in the result list" in {
242 val visitor = RDFoxClassExprConverter(term_x)
243 val result = class_OWLObjectMaxCardinality.accept(visitor)
244 result.res.loneElement should (be (an [Atom]) and have ('predicate (pred_sameAs)))
245 }
246
247 it should "have two unary Atoms in its extension list" in {
248 val visitor = RDFoxClassExprConverter(term_x)
249 val result = class_OWLObjectMaxCardinality.accept(visitor)
250 exactly (2, result.ext) should (be (an [Atom]) and have ('numberOfArguments (1)))
251 }
252
253 it should "have two binary Atoms in its extension list" in {
254 val visitor = RDFoxClassExprConverter(term_x)
255 val result = class_OWLObjectMaxCardinality.accept(visitor)
256 exactly (2, result.ext) should (be (an [Atom]) and have ('numberOfArguments (2)))
257 }
258
259} // class OWLClassSpec