aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/uk/ac/ox/cs/rsacomb/RDFoxConverterSpec.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala/uk/ac/ox/cs/rsacomb/RDFoxConverterSpec.scala')
-rw-r--r--src/test/scala/uk/ac/ox/cs/rsacomb/RDFoxConverterSpec.scala108
1 files changed, 108 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..e2da6e4
--- /dev/null
+++ b/src/test/scala/uk/ac/ox/cs/rsacomb/RDFoxConverterSpec.scala
@@ -0,0 +1,108 @@
1package rsacomb
2
3import org.scalatest.LoneElement
4import org.scalatest.flatspec.AnyFlatSpec
5import org.scalatest.matchers.should.Matchers
6import org.semanticweb.owlapi.apibinding.OWLManager
7import org.semanticweb.owlapi.model.OWLOntologyManager
8
9import tech.oxfordsemantic.jrdfox.logic.datalog.TupleTableAtom
10import tech.oxfordsemantic.jrdfox.logic.expression.{Variable, IRI}
11import uk.ac.ox.cs.rsacomb.converter.RDFoxConverter
12import uk.ac.ox.cs.rsacomb.suffix.{Empty, Forward, Backward, Inverse}
13import uk.ac.ox.cs.rsacomb.converter.SkolemStrategy
14
15object 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
35class RDFoxConverterSpec
36 extends AnyFlatSpec
37 with Matchers
38 with LoneElement
39 with RDFoxConverter {
40
41 import RDFoxConverterSpec._
42
43 "A class name" should "be converted into a single atom" in {
44 val cls = factory.getOWLClass(iriString0)
45 val atom = TupleTableAtom.rdf(term0, IRI.RDF_TYPE, IRI.create(iriString0))
46 val (res, ext) =
47 convert(cls, term0, List(), SkolemStrategy.None, Empty)
48 res.loneElement shouldEqual atom
49 ext shouldBe empty
50 }
51
52 "A intersection of classes" should "be converted into the union of the conversion of the classes" in {
53 val cls0 = factory.getOWLClass(iriString0)
54 val cls1 = factory.getOWLClass(iriString1)
55 val cls2 = factory.getOWLClass(iriString2)
56 val conj = factory.getOWLObjectIntersectionOf(cls0, cls1, cls2)
57 val (res0, ext0) =
58 convert(cls0, term0, List(), SkolemStrategy.None, Empty)
59 val (res1, ext1) =
60 convert(cls1, term0, List(), SkolemStrategy.None, Empty)
61 val (res2, ext2) =
62 convert(cls2, term0, List(), SkolemStrategy.None, Empty)
63 val (res, ext) =
64 convert(conj, term0, List(), SkolemStrategy.None, Empty)
65 res should contain theSameElementsAs (res0 ::: res1 ::: res2)
66 ext should contain theSameElementsAs (ext0 ::: ext1 ::: ext2)
67 }
68
69 "A singleton intersection" should "correspond to the conversion of the internal class" in {
70 val cls0 = factory.getOWLClass(iriString0)
71 val conj = factory.getOWLObjectIntersectionOf(cls0)
72 val (res0, ext0) =
73 convert(cls0, term0, List(), SkolemStrategy.None, Empty)
74 val (res, ext) =
75 convert(conj, term0, List(), SkolemStrategy.None, Empty)
76 res should contain theSameElementsAs res0
77 ext should contain theSameElementsAs ext0
78 }
79
80 "An object property" should "be converted into an atom with matching predicate" in {
81 val prop = factory.getOWLObjectProperty(iriString0)
82 for (sx <- suffixes) {
83 val atom =
84 TupleTableAtom.rdf(term0, IRI.create(iriString0 :: sx), term1)
85 convert(prop, term0, term1, sx) shouldEqual atom
86 }
87 }
88
89 "The inverse of an object property" should "be converted into an atom with matching negated predicate" in {
90 val prop = factory.getOWLObjectProperty(iriString0)
91 val inv = factory.getOWLObjectInverseOf(prop)
92 for (sx <- Seq(Empty, Forward, Backward)) {
93 val atom =
94 TupleTableAtom.rdf(term0, IRI.create(iriString0 :: sx + Inverse), term1)
95 convert(inv, term0, term1, sx) shouldEqual atom
96 }
97 }
98
99 "A data property" should "be converted into an atom with matching predicate" in {
100 val prop = factory.getOWLDataProperty(iriString0)
101 for (suffix <- suffixes) {
102 val atom =
103 TupleTableAtom.rdf(term0, IRI.create(iriString0 :: suffix), term1)
104 convert(prop, term0, term1, suffix) shouldEqual atom
105 }
106 }
107
108}