diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-09-10 11:52:25 +0200 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-09-10 11:52:25 +0200 |
commit | 2d55d441335d28b8a04065caba883785d8952cfb (patch) | |
tree | da63af4cf08b07bcb4c418604174b242715379b6 /src/test/scala/rsacomb/OWLClassSpec.scala | |
parent | c8ba151b172ee0349a79a4cbeda57c6e2255e78a (diff) | |
download | RSAComb-2d55d441335d28b8a04065caba883785d8952cfb.tar.gz RSAComb-2d55d441335d28b8a04065caba883785d8952cfb.zip |
Update and comment some tests
With the introduction of the fresh variable generator it is harder to
test axiom conversion because we would need to define a custom equality
method that doesn't take particular variables into account.
Diffstat (limited to 'src/test/scala/rsacomb/OWLClassSpec.scala')
-rw-r--r-- | src/test/scala/rsacomb/OWLClassSpec.scala | 176 |
1 files changed, 90 insertions, 86 deletions
diff --git a/src/test/scala/rsacomb/OWLClassSpec.scala b/src/test/scala/rsacomb/OWLClassSpec.scala index 98e14cf..23a96fa 100644 --- a/src/test/scala/rsacomb/OWLClassSpec.scala +++ b/src/test/scala/rsacomb/OWLClassSpec.scala | |||
@@ -2,12 +2,28 @@ package rsacomb | |||
2 | 2 | ||
3 | import org.scalatest.{FlatSpec, Matchers, LoneElement} | 3 | import org.scalatest.{FlatSpec, Matchers, LoneElement} |
4 | 4 | ||
5 | import uk.ac.manchester.cs.owl.owlapi.{OWLClassImpl, OWLObjectSomeValuesFromImpl, OWLObjectIntersectionOfImpl, OWLObjectOneOfImpl, OWLObjectAllValuesFromImpl, OWLObjectMaxCardinalityImpl, OWLNamedIndividualImpl} | 5 | import uk.ac.manchester.cs.owl.owlapi.{ |
6 | OWLClassImpl, | ||
7 | OWLObjectSomeValuesFromImpl, | ||
8 | OWLObjectIntersectionOfImpl, | ||
9 | OWLObjectOneOfImpl, | ||
10 | OWLObjectAllValuesFromImpl, | ||
11 | OWLObjectMaxCardinalityImpl, | ||
12 | OWLNamedIndividualImpl | ||
13 | } | ||
6 | import uk.ac.manchester.cs.owl.owlapi.{OWLObjectPropertyImpl} | 14 | import uk.ac.manchester.cs.owl.owlapi.{OWLObjectPropertyImpl} |
7 | import org.semanticweb.owlapi.model.IRI | 15 | import org.semanticweb.owlapi.model.IRI |
8 | 16 | import tech.oxfordsemantic.jrdfox.logic.{IRI => RDFIRI} | |
9 | import tech.oxfordsemantic.jrdfox.logic.{BindAtom,BuiltinFunctionCall} | 17 | |
10 | import tech.oxfordsemantic.jrdfox.logic.{Atom, TupleTableName, Term, Variable, Literal, Datatype} | 18 | import tech.oxfordsemantic.jrdfox.logic.{BindAtom, BuiltinFunctionCall} |
19 | import tech.oxfordsemantic.jrdfox.logic.{ | ||
20 | Atom, | ||
21 | TupleTableName, | ||
22 | Term, | ||
23 | Variable, | ||
24 | Literal, | ||
25 | Datatype | ||
26 | } | ||
11 | 27 | ||
12 | import rsacomb.RDFoxRuleShards | 28 | import rsacomb.RDFoxRuleShards |
13 | 29 | ||
@@ -15,11 +31,11 @@ object OWLClassSpec { | |||
15 | 31 | ||
16 | // IRI | 32 | // IRI |
17 | val iri_Professor = IRI.create("univ:Professor") | 33 | val iri_Professor = IRI.create("univ:Professor") |
18 | val iri_Female = IRI.create("std:Female") | 34 | val iri_Female = IRI.create("std:Female") |
19 | val iri_Student = IRI.create("univ:Student") | 35 | val iri_Student = IRI.create("univ:Student") |
20 | val iri_Worker = IRI.create("univ:Worker") | 36 | val iri_Worker = IRI.create("univ:Worker") |
21 | val iri_alice = IRI.create("univ:alice") | 37 | val iri_alice = IRI.create("univ:alice") |
22 | val iri_supervises = IRI.create("univ:supervises") | 38 | val iri_supervises = IRI.create("univ:supervises") |
23 | val iri_hasSupervisor = IRI.create("univ:hasSupervisor") | 39 | val iri_hasSupervisor = IRI.create("univ:hasSupervisor") |
24 | 40 | ||
25 | // RDFox Terms | 41 | // RDFox Terms |
@@ -40,18 +56,20 @@ object OWLClassSpec { | |||
40 | // Professor | 56 | // Professor |
41 | // | 57 | // |
42 | val class_Professor = new OWLClassImpl(iri_Professor) | 58 | val class_Professor = new OWLClassImpl(iri_Professor) |
43 | val class_Female = new OWLClassImpl(iri_Female) | 59 | val class_Female = new OWLClassImpl(iri_Female) |
44 | val class_Student = new OWLClassImpl(iri_Student) | 60 | val class_Student = new OWLClassImpl(iri_Student) |
45 | val class_Worker = new OWLClassImpl(iri_Worker) | 61 | val class_Worker = new OWLClassImpl(iri_Worker) |
46 | val class_OWLClass = class_Professor | 62 | val class_OWLClass = class_Professor |
47 | 63 | ||
48 | // Class Conjunction corresponding to | 64 | // Class Conjunction corresponding to |
49 | // | 65 | // |
50 | // Female ∧ Student ∧ Worker | 66 | // Female ∧ Student ∧ Worker |
51 | // | 67 | // |
52 | val class_OWLObjectIntersectionOf = | 68 | val class_OWLObjectIntersectionOf = |
53 | new OWLObjectIntersectionOfImpl( | 69 | new OWLObjectIntersectionOfImpl( |
54 | class_Female, class_Student, class_Worker | 70 | class_Female, |
71 | class_Student, | ||
72 | class_Worker | ||
55 | ) | 73 | ) |
56 | // Singleton Class corresponding to | 74 | // Singleton Class corresponding to |
57 | // | 75 | // |
@@ -81,9 +99,7 @@ object OWLClassSpec { | |||
81 | ) | 99 | ) |
82 | } // object OWLClassSpec | 100 | } // object OWLClassSpec |
83 | 101 | ||
84 | class OWLClassSpec | 102 | class OWLClassSpec extends FlatSpec with Matchers with LoneElement { |
85 | extends FlatSpec with Matchers with LoneElement | ||
86 | { | ||
87 | // Import required data | 103 | // Import required data |
88 | import OWLClassSpec._ | 104 | import OWLClassSpec._ |
89 | 105 | ||
@@ -91,13 +107,13 @@ class OWLClassSpec | |||
91 | class_OWLClass.toString should "be converted into a RDFoxRuleShards" in { | 107 | class_OWLClass.toString should "be converted into a RDFoxRuleShards" in { |
92 | val visitor = RDFoxClassExprConverter(term_x) | 108 | val visitor = RDFoxClassExprConverter(term_x) |
93 | val result = class_OWLClass.accept(visitor) | 109 | val result = class_OWLClass.accept(visitor) |
94 | result shouldBe a [RDFoxRuleShards] | 110 | result shouldBe a[RDFoxRuleShards] |
95 | } | 111 | } |
96 | 112 | ||
97 | it should "have a single Atom in its result list" in { | 113 | it should "have a single Atom in its result list" in { |
98 | val visitor = RDFoxClassExprConverter(term_x) | 114 | val visitor = RDFoxClassExprConverter(term_x) |
99 | val result = class_OWLClass.accept(visitor) | 115 | val result = class_OWLClass.accept(visitor) |
100 | result.res.loneElement shouldBe an [Atom] | 116 | result.res.loneElement shouldBe an[Atom] |
101 | } | 117 | } |
102 | 118 | ||
103 | it should "have an empty extension list" in { | 119 | it should "have an empty extension list" in { |
@@ -110,17 +126,19 @@ class OWLClassSpec | |||
110 | class_OWLObjectIntersectionOf.toString should "be converted into a RDFoxRuleShards" in { | 126 | class_OWLObjectIntersectionOf.toString should "be converted into a RDFoxRuleShards" in { |
111 | val visitor = RDFoxClassExprConverter(term_x) | 127 | val visitor = RDFoxClassExprConverter(term_x) |
112 | val result = class_OWLObjectIntersectionOf.accept(visitor) | 128 | val result = class_OWLObjectIntersectionOf.accept(visitor) |
113 | result shouldBe a [RDFoxRuleShards] | 129 | result shouldBe a[RDFoxRuleShards] |
114 | } | 130 | } |
115 | 131 | ||
116 | it should "be converted in the union of its converted conjuncts" in { | 132 | it should "be converted in the union of its converted conjuncts" in { |
117 | val visitor = RDFoxClassExprConverter(term_x) | 133 | val visitor = RDFoxClassExprConverter(term_x) |
118 | val result1= class_OWLObjectIntersectionOf.accept(visitor) | 134 | val result1 = class_OWLObjectIntersectionOf.accept(visitor) |
119 | val result2 = RDFoxClassExprConverter.merge(List( | 135 | val result2 = RDFoxClassExprConverter.merge( |
120 | class_Female.accept(visitor), | 136 | List( |
121 | class_Student.accept(visitor), | 137 | class_Female.accept(visitor), |
122 | class_Worker.accept(visitor) | 138 | class_Student.accept(visitor), |
123 | )) | 139 | class_Worker.accept(visitor) |
140 | ) | ||
141 | ) | ||
124 | result1.res should contain theSameElementsAs result2.res | 142 | result1.res should contain theSameElementsAs result2.res |
125 | result1.ext should contain theSameElementsAs result2.ext | 143 | result1.ext should contain theSameElementsAs result2.ext |
126 | } | 144 | } |
@@ -129,14 +147,14 @@ class OWLClassSpec | |||
129 | class_OWLObjectOneOf.toString should "be converted into a RDFoxRuleShards" in { | 147 | class_OWLObjectOneOf.toString should "be converted into a RDFoxRuleShards" in { |
130 | val visitor = RDFoxClassExprConverter(term_x) | 148 | val visitor = RDFoxClassExprConverter(term_x) |
131 | val result = class_OWLObjectOneOf.accept(visitor) | 149 | val result = class_OWLObjectOneOf.accept(visitor) |
132 | result shouldBe a [RDFoxRuleShards] | 150 | result shouldBe a[RDFoxRuleShards] |
133 | } | 151 | } |
134 | 152 | ||
135 | it should "be converted into a single <owl:sameAs> Atom" in { | 153 | // it should "be converted into a single <owl:sameAs> Atom" in { |
136 | val visitor = RDFoxClassExprConverter(term_x) | 154 | // val visitor = RDFoxClassExprConverter(term_x) |
137 | val result = class_OWLObjectOneOf.accept(visitor) | 155 | // val result = class_OWLObjectOneOf.accept(visitor) |
138 | result.res.loneElement should (be (a [Atom]) and have ('tupleTableName (pred_sameAs))) | 156 | // result.res.loneElement should (be (a [Atom]) and have ('tupleTableName (pred_sameAs))) |
139 | } | 157 | // } |
140 | 158 | ||
141 | it should "have an empty extension list" in { | 159 | it should "have an empty extension list" in { |
142 | val visitor = RDFoxClassExprConverter(term_x) | 160 | val visitor = RDFoxClassExprConverter(term_x) |
@@ -147,85 +165,73 @@ class OWLClassSpec | |||
147 | // OWLObjectSomeValuesFrom | 165 | // OWLObjectSomeValuesFrom |
148 | (class_OWLObjectSomeValuesFrom.toString ++ " w/o skolemization") should | 166 | (class_OWLObjectSomeValuesFrom.toString ++ " w/o skolemization") should |
149 | "be converted into a RDFoxRuleShards" in { | 167 | "be converted into a RDFoxRuleShards" in { |
150 | val visitor = RDFoxClassExprConverter(term_x,SkolemStrategy.None) | 168 | 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) | 169 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
158 | exactly (1, result.res) should (be (an [Atom]) and have ('numberOfArguments (1))) | 170 | result shouldBe a[RDFoxRuleShards] |
159 | } | 171 | } |
160 | 172 | ||
161 | it should "have exactly one binary Atom in its result list" in { | 173 | it should "have two Atoms in its result list" in { |
162 | val visitor = RDFoxClassExprConverter(term_x,SkolemStrategy.None) | 174 | val visitor = RDFoxClassExprConverter(term_x, SkolemStrategy.None) |
163 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 175 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
164 | exactly (1, result.res) should (be (an [Atom]) and have ('numberOfArguments (2))) | 176 | exactly(2, result.res) should (be(an[Atom]) and have( |
177 | 'numberOfArguments (3) | ||
178 | )) | ||
165 | } | 179 | } |
166 | 180 | ||
167 | it should "have an empty extension list" in { | 181 | it should "have an empty extension list" in { |
168 | val visitor = RDFoxClassExprConverter(term_x,SkolemStrategy.None) | 182 | val visitor = RDFoxClassExprConverter(term_x, SkolemStrategy.None) |
169 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 183 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
170 | result.ext shouldBe empty | 184 | result.ext shouldBe empty |
171 | } | 185 | } |
172 | 186 | ||
173 | (class_OWLObjectSomeValuesFrom.toString ++ " w/ skolemization") should | 187 | (class_OWLObjectSomeValuesFrom.toString ++ " w/ skolemization") should |
174 | "be converted into a RDFoxRuleShards" in { | 188 | "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) | 189 | val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString) |
183 | val visitor = RDFoxClassExprConverter(term_x,skolem) | 190 | val visitor = RDFoxClassExprConverter(term_x, skolem) |
184 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 191 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
185 | exactly (1, result.res) should (be (an [Atom]) and have ('numberOfArguments (1))) | 192 | result shouldBe a[RDFoxRuleShards] |
186 | } | 193 | } |
187 | 194 | ||
188 | it should "have exactly one binary Atom in its result list" in { | 195 | it should "have exactly two Atoms in its result list" in { |
189 | val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString) | 196 | val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString) |
190 | val visitor = RDFoxClassExprConverter(term_x,skolem) | 197 | val visitor = RDFoxClassExprConverter(term_x, skolem) |
191 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 198 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
192 | exactly (1, result.res) should (be (an [Atom]) and have ('numberOfArguments (2))) | 199 | exactly(2, result.res) should (be(an[Atom]) and have( |
200 | 'numberOfArguments (3) | ||
201 | )) | ||
193 | } | 202 | } |
194 | 203 | ||
195 | it should "should have a single SKOLEM call in the extension list" in { | 204 | it should "should have a single SKOLEM call in the extension list" in { |
196 | val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString) | 205 | val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString) |
197 | val visitor = RDFoxClassExprConverter(term_x,skolem) | 206 | val visitor = RDFoxClassExprConverter(term_x, skolem) |
198 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 207 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
199 | result.ext.loneElement shouldBe a [BindAtom] | 208 | result.ext.loneElement shouldBe a[BindAtom] |
200 | val builtin = result.ext.head.asInstanceOf[BindAtom].getBuiltinExpression | 209 | val builtin = result.ext.head.asInstanceOf[BindAtom].getBuiltinExpression |
201 | builtin should (be (a [BuiltinFunctionCall]) and have ('functionName ("SKOLEM"))) | 210 | builtin should (be(a[BuiltinFunctionCall]) and have( |
211 | 'functionName ("SKOLEM") | ||
212 | )) | ||
202 | } | 213 | } |
203 | 214 | ||
204 | (class_OWLObjectSomeValuesFrom.toString ++ " w/ constant skolemization") should | 215 | (class_OWLObjectSomeValuesFrom.toString ++ " w/ constant skolemization") should |
205 | "be converted into a RDFoxRuleShards" in { | 216 | "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) | 217 | val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString) |
214 | val visitor = RDFoxClassExprConverter(term_x,skolem) | 218 | val visitor = RDFoxClassExprConverter(term_x, skolem) |
215 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 219 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
216 | exactly (1, result.res) should (be (an [Atom]) and have ('numberOfArguments (1))) | 220 | result shouldBe a[RDFoxRuleShards] |
217 | } | 221 | } |
218 | 222 | ||
219 | it should "have exactly one binary Atom in its result list" in { | 223 | it should "have exactly two Atoms in its result list" in { |
220 | val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString) | 224 | val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString) |
221 | val visitor = RDFoxClassExprConverter(term_x,skolem) | 225 | val visitor = RDFoxClassExprConverter(term_x, skolem) |
222 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 226 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
223 | exactly (1, result.res) should (be (an [Atom]) and have ('numberOfArguments (2))) | 227 | exactly(2, result.res) should (be(an[Atom]) and have( |
228 | 'numberOfArguments (3) | ||
229 | )) | ||
224 | } | 230 | } |
225 | 231 | ||
226 | it should "have an empty extension list" in { | 232 | it should "have an empty extension list" in { |
227 | val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString) | 233 | val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString) |
228 | val visitor = RDFoxClassExprConverter(term_x,skolem) | 234 | val visitor = RDFoxClassExprConverter(term_x, skolem) |
229 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 235 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
230 | result.ext shouldBe empty | 236 | result.ext shouldBe empty |
231 | } | 237 | } |
@@ -233,27 +239,25 @@ class OWLClassSpec | |||
233 | // OWLObjectMaxCardinalityImpl | 239 | // OWLObjectMaxCardinalityImpl |
234 | class_OWLObjectMaxCardinality.toString should | 240 | class_OWLObjectMaxCardinality.toString should |
235 | "be converted into a RDFoxRuleShards" in { | 241 | "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) | 242 | val visitor = RDFoxClassExprConverter(term_x) |
243 | val result = class_OWLObjectMaxCardinality.accept(visitor) | 243 | val result = class_OWLObjectMaxCardinality.accept(visitor) |
244 | result.res.loneElement should (be (an [Atom]) and have ('tupleTableName (pred_sameAs))) | 244 | result shouldBe a[RDFoxRuleShards] |
245 | } | 245 | } |
246 | 246 | ||
247 | it should "have two unary Atoms in its extension list" in { | 247 | // it should "have a single <owl:sameAs> Atom in the result list" in { |
248 | val visitor = RDFoxClassExprConverter(term_x) | 248 | // val visitor = RDFoxClassExprConverter(term_x) |
249 | val result = class_OWLObjectMaxCardinality.accept(visitor) | 249 | // val result = class_OWLObjectMaxCardinality.accept(visitor) |
250 | exactly (2, result.ext) should (be (an [Atom]) and have ('numberOfArguments (1))) | 250 | // result.res.loneElement should (be(an[Atom]) and have( |
251 | } | 251 | // 'tupleTableName (pred_sameAs) |
252 | // )) | ||
253 | // } | ||
252 | 254 | ||
253 | it should "have two binary Atoms in its extension list" in { | 255 | it should "have 4 Atoms in its extension list" in { |
254 | val visitor = RDFoxClassExprConverter(term_x) | 256 | val visitor = RDFoxClassExprConverter(term_x) |
255 | val result = class_OWLObjectMaxCardinality.accept(visitor) | 257 | val result = class_OWLObjectMaxCardinality.accept(visitor) |
256 | exactly (2, result.ext) should (be (an [Atom]) and have ('numberOfArguments (2))) | 258 | exactly(4, result.ext) should (be(an[Atom]) and have( |
259 | 'numberOfArguments (3) | ||
260 | )) | ||
257 | } | 261 | } |
258 | 262 | ||
259 | } // class OWLClassSpec | 263 | } // class OWLClassSpec |