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