diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-12-01 22:53:43 +0000 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-12-01 22:53:43 +0000 |
| commit | 30f1449365f51d3e138a3fcfd46aca2a4a4c55b9 (patch) | |
| tree | 3aa0b1abb667356602cfeac3086b2818810aa419 /src/test/scala/uk | |
| parent | 6462d8566cc10b47473803e3e9e9547cec6524be (diff) | |
| download | RSAComb-30f1449365f51d3e138a3fcfd46aca2a4a4c55b9.tar.gz RSAComb-30f1449365f51d3e138a3fcfd46aca2a4a4c55b9.zip | |
Add alternative conversion of axioms using switch-cases
This is part of an effort to move away from the Java-style visitor
pattern pushed by the OWLAPI and RDFox. Using a Scala approach will
allow us to be more flexible in the long run.
Diffstat (limited to 'src/test/scala/uk')
| -rw-r--r-- | src/test/scala/uk/ac/ox/cs/rsacomb/RDFoxConverterSpec.scala | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/RDFoxConverterSpec.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/RDFoxConverterSpec.scala new file mode 100644 index 0000000..35af464 --- /dev/null +++ b/src/test/scala/uk/ac/ox/cs/rsacomb/RDFoxConverterSpec.scala | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | package rsacomb | ||
| 2 | |||
| 3 | import org.scalatest.LoneElement | ||
| 4 | import org.scalatest.flatspec.AnyFlatSpec | ||
| 5 | import org.scalatest.matchers.should.Matchers | ||
| 6 | import org.semanticweb.owlapi.apibinding.OWLManager | ||
| 7 | import org.semanticweb.owlapi.model.OWLOntologyManager | ||
| 8 | |||
| 9 | import tech.oxfordsemantic.jrdfox.logic.datalog.TupleTableAtom | ||
| 10 | import tech.oxfordsemantic.jrdfox.logic.expression.{Variable, IRI} | ||
| 11 | import uk.ac.ox.cs.rsacomb.converter.RDFoxConverter | ||
| 12 | import uk.ac.ox.cs.rsacomb.suffix.{Empty, Forward, Backward, Inverse} | ||
| 13 | import uk.ac.ox.cs.rsacomb.converter.SkolemStrategy | ||
| 14 | |||
| 15 | object RDFoxConverterSpec { | ||
| 16 | |||
| 17 | val manager = OWLManager.createOWLOntologyManager() | ||
| 18 | val factory = manager.getOWLDataFactory | ||
| 19 | |||
| 20 | val term0 = Variable.create("X") | ||
| 21 | val term1 = Variable.create("Y") | ||
| 22 | val iriString0 = "http://example.com/rsacomb/iri0" | ||
| 23 | val iriString1 = "http://example.com/rsacomb/iri1" | ||
| 24 | val iriString2 = "http://example.com/rsacomb/iri2" | ||
| 25 | val suffixes = Seq( | ||
| 26 | Empty, | ||
| 27 | Forward, | ||
| 28 | Backward, | ||
| 29 | Inverse, | ||
| 30 | Forward + Inverse, | ||
| 31 | Backward + Inverse | ||
| 32 | ) | ||
| 33 | } | ||
| 34 | |||
| 35 | class RDFoxConverterSpec extends AnyFlatSpec with Matchers with LoneElement { | ||
| 36 | |||
| 37 | import RDFoxConverterSpec._ | ||
| 38 | |||
| 39 | "A class name" should "be converted into a single atom" in { | ||
| 40 | val cls = factory.getOWLClass(iriString0) | ||
| 41 | val atom = TupleTableAtom.rdf(term0, IRI.RDF_TYPE, IRI.create(iriString0)) | ||
| 42 | val (res, ext) = | ||
| 43 | RDFoxConverter.convert(cls, term0, List(), SkolemStrategy.None, Empty) | ||
| 44 | res.loneElement shouldEqual atom | ||
| 45 | ext shouldBe empty | ||
| 46 | } | ||
| 47 | |||
| 48 | "A intersection of classes" should "be converted into the union of the conversion of the classes" in { | ||
| 49 | val cls0 = factory.getOWLClass(iriString0) | ||
| 50 | val cls1 = factory.getOWLClass(iriString1) | ||
| 51 | val cls2 = factory.getOWLClass(iriString2) | ||
| 52 | val conj = factory.getOWLObjectIntersectionOf(cls0, cls1, cls2) | ||
| 53 | val (res0, ext0) = | ||
| 54 | RDFoxConverter.convert(cls0, term0, List(), SkolemStrategy.None, Empty) | ||
| 55 | val (res1, ext1) = | ||
| 56 | RDFoxConverter.convert(cls1, term0, List(), SkolemStrategy.None, Empty) | ||
| 57 | val (res2, ext2) = | ||
| 58 | RDFoxConverter.convert(cls2, term0, List(), SkolemStrategy.None, Empty) | ||
| 59 | val (res, ext) = | ||
| 60 | RDFoxConverter.convert(conj, term0, List(), SkolemStrategy.None, Empty) | ||
| 61 | res should contain theSameElementsAs (res0 ::: res1 ::: res2) | ||
| 62 | ext should contain theSameElementsAs (ext0 ::: ext1 ::: ext2) | ||
| 63 | } | ||
| 64 | |||
| 65 | "A singleton intersection" should "correspond to the conversion of the internal class" in { | ||
| 66 | val cls0 = factory.getOWLClass(iriString0) | ||
| 67 | val conj = factory.getOWLObjectIntersectionOf(cls0) | ||
| 68 | val (res0, ext0) = | ||
| 69 | RDFoxConverter.convert(cls0, term0, List(), SkolemStrategy.None, Empty) | ||
| 70 | val (res, ext) = | ||
| 71 | RDFoxConverter.convert(conj, term0, List(), SkolemStrategy.None, Empty) | ||
| 72 | res should contain theSameElementsAs res0 | ||
| 73 | ext should contain theSameElementsAs ext0 | ||
| 74 | } | ||
| 75 | |||
| 76 | "An object property" should "be converted into an atom with matching predicate" in { | ||
| 77 | val prop = factory.getOWLObjectProperty(iriString0) | ||
| 78 | for (sx <- suffixes) { | ||
| 79 | val atom = | ||
| 80 | TupleTableAtom.rdf(term0, IRI.create(iriString0 :: sx), term1) | ||
| 81 | RDFoxConverter.convert(prop, term0, term1, sx) shouldEqual atom | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | "The inverse of an object property" should "be converted into an atom with matching negated predicate" in { | ||
| 86 | val prop = factory.getOWLObjectProperty(iriString0) | ||
| 87 | val inv = factory.getOWLObjectInverseOf(prop) | ||
| 88 | for (sx <- Seq(Empty, Forward, Backward)) { | ||
| 89 | val atom = | ||
| 90 | TupleTableAtom.rdf(term0, IRI.create(iriString0 :: sx + Inverse), term1) | ||
| 91 | RDFoxConverter.convert(inv, term0, term1, sx) shouldEqual atom | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | "A data property" should "be converted into an atom with matching predicate" in { | ||
| 96 | val prop = factory.getOWLDataProperty(iriString0) | ||
| 97 | for (suffix <- suffixes) { | ||
| 98 | val atom = | ||
| 99 | TupleTableAtom.rdf(term0, IRI.create(iriString0 :: suffix), term1) | ||
| 100 | RDFoxConverter.convert(prop, term0, term1, suffix) shouldEqual atom | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | } | ||
