1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
package rsacomb
import org.scalatest.LoneElement
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.semanticweb.owlapi.apibinding.OWLManager
import org.semanticweb.owlapi.model.OWLOntologyManager
import tech.oxfordsemantic.jrdfox.logic.datalog.TupleTableAtom
import tech.oxfordsemantic.jrdfox.logic.expression.{Variable, IRI}
import uk.ac.ox.cs.rsacomb.converter.RDFoxConverter
import uk.ac.ox.cs.rsacomb.suffix.{Empty, Forward, Backward, Inverse}
import uk.ac.ox.cs.rsacomb.converter.SkolemStrategy
object RDFoxConverterSpec {
val manager = OWLManager.createOWLOntologyManager()
val factory = manager.getOWLDataFactory
val term0 = Variable.create("X")
val term1 = Variable.create("Y")
val iriString0 = "http://example.com/rsacomb/iri0"
val iriString1 = "http://example.com/rsacomb/iri1"
val iriString2 = "http://example.com/rsacomb/iri2"
val suffixes = Seq(
Empty,
Forward,
Backward,
Inverse,
Forward + Inverse,
Backward + Inverse
)
}
class RDFoxConverterSpec extends AnyFlatSpec with Matchers with LoneElement {
import RDFoxConverterSpec._
"A class name" should "be converted into a single atom" in {
val cls = factory.getOWLClass(iriString0)
val atom = TupleTableAtom.rdf(term0, IRI.RDF_TYPE, IRI.create(iriString0))
val (res, ext) =
RDFoxConverter.convert(cls, term0, List(), SkolemStrategy.None, Empty)
res.loneElement shouldEqual atom
ext shouldBe empty
}
"A intersection of classes" should "be converted into the union of the conversion of the classes" in {
val cls0 = factory.getOWLClass(iriString0)
val cls1 = factory.getOWLClass(iriString1)
val cls2 = factory.getOWLClass(iriString2)
val conj = factory.getOWLObjectIntersectionOf(cls0, cls1, cls2)
val (res0, ext0) =
RDFoxConverter.convert(cls0, term0, List(), SkolemStrategy.None, Empty)
val (res1, ext1) =
RDFoxConverter.convert(cls1, term0, List(), SkolemStrategy.None, Empty)
val (res2, ext2) =
RDFoxConverter.convert(cls2, term0, List(), SkolemStrategy.None, Empty)
val (res, ext) =
RDFoxConverter.convert(conj, term0, List(), SkolemStrategy.None, Empty)
res should contain theSameElementsAs (res0 ::: res1 ::: res2)
ext should contain theSameElementsAs (ext0 ::: ext1 ::: ext2)
}
"A singleton intersection" should "correspond to the conversion of the internal class" in {
val cls0 = factory.getOWLClass(iriString0)
val conj = factory.getOWLObjectIntersectionOf(cls0)
val (res0, ext0) =
RDFoxConverter.convert(cls0, term0, List(), SkolemStrategy.None, Empty)
val (res, ext) =
RDFoxConverter.convert(conj, term0, List(), SkolemStrategy.None, Empty)
res should contain theSameElementsAs res0
ext should contain theSameElementsAs ext0
}
"An object property" should "be converted into an atom with matching predicate" in {
val prop = factory.getOWLObjectProperty(iriString0)
for (sx <- suffixes) {
val atom =
TupleTableAtom.rdf(term0, IRI.create(iriString0 :: sx), term1)
RDFoxConverter.convert(prop, term0, term1, sx) shouldEqual atom
}
}
"The inverse of an object property" should "be converted into an atom with matching negated predicate" in {
val prop = factory.getOWLObjectProperty(iriString0)
val inv = factory.getOWLObjectInverseOf(prop)
for (sx <- Seq(Empty, Forward, Backward)) {
val atom =
TupleTableAtom.rdf(term0, IRI.create(iriString0 :: sx + Inverse), term1)
RDFoxConverter.convert(inv, term0, term1, sx) shouldEqual atom
}
}
"A data property" should "be converted into an atom with matching predicate" in {
val prop = factory.getOWLDataProperty(iriString0)
for (suffix <- suffixes) {
val atom =
TupleTableAtom.rdf(term0, IRI.create(iriString0 :: suffix), term1)
RDFoxConverter.convert(prop, term0, term1, suffix) shouldEqual atom
}
}
}
|