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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
package rsacomb
import java.io.File
import org.scalatest.LoneElement
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.semanticweb.owlapi.model._
import uk.ac.manchester.cs.owl.owlapi._
import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer
import tech.oxfordsemantic.jrdfox.logic.{Rule, Variable}
import scala.collection.JavaConverters._
import rsacomb.RSA._
import rsacomb.RDFoxUtil._
object Ontology1_CanonicalModelSpec {
/* Renderer to display OWL Axioms with DL syntax*/
val renderer = new DLSyntaxObjectRenderer()
val ontology_path: File = new File("examples/example1.owl")
val ontology = RSA.loadOntology(ontology_path)
val program = ontology.canonicalModel
val roleR = new OWLObjectPropertyImpl(RSA.base("R"))
val roleS = new OWLObjectPropertyImpl(RSA.base("S"))
val roleT = new OWLObjectPropertyImpl(RSA.base("T"))
val roleR_inv = roleR.getInverseProperty()
val roleS_inv = roleS.getInverseProperty()
val roleT_inv = roleT.getInverseProperty()
val AsubClassOfD = new OWLSubClassOfAxiomImpl(
new OWLClassImpl(RSA.base("A")),
new OWLClassImpl(RSA.base("D")),
Seq().asJava
)
val DsomeValuesFromRB = new OWLSubClassOfAxiomImpl(
new OWLClassImpl(RSA.base("D")),
new OWLObjectSomeValuesFromImpl(
roleR,
new OWLClassImpl(RSA.base("B"))
),
Seq().asJava
)
val BsomeValuesFromSD = new OWLSubClassOfAxiomImpl(
new OWLClassImpl(RSA.base("B")),
new OWLObjectSomeValuesFromImpl(
roleS,
new OWLClassImpl(RSA.base("D"))
),
Seq().asJava
)
val AsomeValuesFromSiC = new OWLSubClassOfAxiomImpl(
new OWLClassImpl(RSA.base("A")),
new OWLObjectSomeValuesFromImpl(
roleS_inv,
new OWLClassImpl(RSA.base("C"))
),
Seq().asJava
)
val SsubPropertyOfT = new OWLSubObjectPropertyOfAxiomImpl(
new OWLObjectPropertyImpl(RSA.base("S")),
new OWLObjectPropertyImpl(RSA.base("T")),
Seq().asJava
)
} // object OWLAxiomSpec
class Ontology1_CanonicalModelSpec
extends AnyFlatSpec
with Matchers
with LoneElement {
import Ontology1_CanonicalModelSpec._
"The program generated from Example #1" should "not be empty" in {
program should not be empty
}
renderer.render(AsubClassOfD) should "be converted into a single Rule" in {
val varX = Variable.create("X")
val visitor = ProgramGenerator(ontology, varX)
val rules = AsubClassOfD.accept(visitor)
rules.loneElement shouldBe a[Rule]
}
// Role R //
renderer.render(roleR) should "be safe" in {
ontology.unsafeRoles should not contain roleR
}
it should "have 3 elements in its conflict set" in {
ontology.confl(roleR) should have size 3
}
it should "contain S in its conflict set" in {
ontology.confl(roleR) should contain(roleS)
}
it should "contain T in its conflict set" in {
ontology.confl(roleR) should contain(roleT)
}
it should ("contain " + renderer.render(
roleR_inv
) + " in its conflict set") in {
ontology.confl(roleR) should contain(roleR_inv)
}
// Role S //
renderer.render(roleS) should "be safe" in {
ontology.unsafeRoles should not contain roleS
}
it should "have 3 elements in its conflict set" in {
ontology.confl(roleS) should have size 3
}
it should "contain R in its conflict set" in {
ontology.confl(roleS) should contain(roleR)
}
it should ("contain " + renderer.render(
roleS_inv
) + " in its conflict set") in {
ontology.confl(roleS) should contain(roleS_inv)
}
it should ("contain " + renderer.render(
roleT_inv
) + " in its conflict set") in {
ontology.confl(roleS) should contain(roleT_inv)
}
// S⁻
renderer.render(roleS_inv) should "be unsafe" in {
ontology.unsafeRoles should contain(roleS_inv)
}
renderer.render(
AsomeValuesFromSiC
) should "produce 1 rule" in {
val varX = Variable.create("X")
val visitor = ProgramGenerator(ontology, varX)
val rules = AsomeValuesFromSiC.accept(visitor)
rules should have length 1
}
renderer.render(
DsomeValuesFromRB
) should "have a sigleton 'cycle' set" in {
// Using `hashCode` we are assuming (B,S,D) < (D,R,B)
val ind = RSA.internal("v1_" ++ BsomeValuesFromSD.hashCode.toString())
ontology.cycle(DsomeValuesFromRB).loneElement shouldBe ind
}
it should "produce 5 rules" in {
// Rule 1 provides 1 rule (split in 2) + 1 fact
// Rule 2 provides 0 rules
// Rule 3 provides 1 rule (split in 2)
val varX = Variable.create("X")
val visitor = ProgramGenerator(ontology, varX)
val rules = DsomeValuesFromRB.accept(visitor)
rules should have length 5
}
renderer.render(
BsomeValuesFromSD
) should "have a sigleton 'cycle' set" in {
// Using `hashCode` we are assuming (B,S,D) < (D,R,B)
val ind = RSA.internal("v0_" ++ DsomeValuesFromRB.hashCode.toString())
ontology.cycle(BsomeValuesFromSD).loneElement shouldBe ind
}
it should "produce 5 rules" in {
// Rule 1 provides 1 rule (split in 2) + 1 fact
// Rule 2 provides 0 rules
// Rule 3 provides 1 rule (split in 2)
val varX = Variable.create("X")
val visitor = ProgramGenerator(ontology, varX)
val rules = BsomeValuesFromSD.accept(visitor)
rules should have length 5
}
renderer.render(
SsubPropertyOfT
) should "produce 2 rules" in {
val varX = Variable.create("X")
val visitor = ProgramGenerator(ontology, varX)
val rules = SsubPropertyOfT.accept(visitor)
rules should have length 2
}
} // class OWLAxiomSpec
|