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