diff options
| -rw-r--r-- | examples/example2.owl | 2 | ||||
| -rw-r--r-- | src/main/scala/rsacomb/CanonicalModel.scala | 2 | ||||
| -rw-r--r-- | src/test/scala/rsacomb/CanonicalModelSpec.scala | 155 |
3 files changed, 154 insertions, 5 deletions
diff --git a/examples/example2.owl b/examples/example2.owl index f42f6c9..5c83fa6 100644 --- a/examples/example2.owl +++ b/examples/example2.owl | |||
| @@ -109,4 +109,4 @@ | |||
| 109 | <rdfs:subClassOf rdf:resource="#Y" /> | 109 | <rdfs:subClassOf rdf:resource="#Y" /> |
| 110 | </owl:Restriction> | 110 | </owl:Restriction> |
| 111 | 111 | ||
| 112 | </rdf:RDF> \ No newline at end of file | 112 | </rdf:RDF> |
diff --git a/src/main/scala/rsacomb/CanonicalModel.scala b/src/main/scala/rsacomb/CanonicalModel.scala index c07fc06..cc89a85 100644 --- a/src/main/scala/rsacomb/CanonicalModel.scala +++ b/src/main/scala/rsacomb/CanonicalModel.scala | |||
| @@ -24,7 +24,7 @@ object ProgramGenerator { | |||
| 24 | 24 | ||
| 25 | def apply( | 25 | def apply( |
| 26 | ontology: OWLOntology, | 26 | ontology: OWLOntology, |
| 27 | term: Term | 27 | term: Term = Variable.create("X") |
| 28 | ): RDFoxAxiomConverter = | 28 | ): RDFoxAxiomConverter = |
| 29 | new ProgramGenerator(ontology, term) | 29 | new ProgramGenerator(ontology, term) |
| 30 | 30 | ||
diff --git a/src/test/scala/rsacomb/CanonicalModelSpec.scala b/src/test/scala/rsacomb/CanonicalModelSpec.scala index 39801bf..e8db89d 100644 --- a/src/test/scala/rsacomb/CanonicalModelSpec.scala +++ b/src/test/scala/rsacomb/CanonicalModelSpec.scala | |||
| @@ -71,7 +71,7 @@ object Ontology1_CanonicalModelSpec { | |||
| 71 | Seq().asJava | 71 | Seq().asJava |
| 72 | ) | 72 | ) |
| 73 | 73 | ||
| 74 | } // object OWLAxiomSpec | 74 | } |
| 75 | 75 | ||
| 76 | class Ontology1_CanonicalModelSpec | 76 | class Ontology1_CanonicalModelSpec |
| 77 | extends AnyFlatSpec | 77 | extends AnyFlatSpec |
| @@ -181,7 +181,7 @@ class Ontology1_CanonicalModelSpec | |||
| 181 | 181 | ||
| 182 | renderer.render( | 182 | renderer.render( |
| 183 | BsomeValuesFromSD | 183 | BsomeValuesFromSD |
| 184 | ) should "have a sigleton 'cycle' set" in { | 184 | ) should "have a 'cycle' set of 32 elements" in { |
| 185 | // Cycle introduces a new constant for each possible triple (the | 185 | // Cycle introduces a new constant for each possible triple (the |
| 186 | // order among triples is total). In this example there are 4 | 186 | // order among triples is total). In this example there are 4 |
| 187 | // concept names and S has 2 safe roles in its conflict set (R, | 187 | // concept names and S has 2 safe roles in its conflict set (R, |
| @@ -211,4 +211,153 @@ class Ontology1_CanonicalModelSpec | |||
| 211 | rules should have length 2 | 211 | rules should have length 2 |
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | } // class OWLAxiomSpec | 214 | } |
| 215 | |||
| 216 | object Ontology2_CanonicalModelSpec { | ||
| 217 | |||
| 218 | /* Renderer to display OWL Axioms with DL syntax*/ | ||
| 219 | val renderer = new DLSyntaxObjectRenderer() | ||
| 220 | |||
| 221 | val ontology_path: File = new File("examples/example2.owl") | ||
| 222 | val ontology = RSA.loadOntology(ontology_path) | ||
| 223 | val program = ontology.canonicalModel | ||
| 224 | |||
| 225 | val roleR = new OWLObjectPropertyImpl(RSA.base("R")) | ||
| 226 | val roleS = new OWLObjectPropertyImpl(RSA.base("S")) | ||
| 227 | val roleT = new OWLObjectPropertyImpl(RSA.base("T")) | ||
| 228 | val roleP = new OWLObjectPropertyImpl(RSA.base("P")) | ||
| 229 | val roleR_inv = roleR.getInverseProperty() | ||
| 230 | val roleS_inv = roleS.getInverseProperty() | ||
| 231 | val roleT_inv = roleT.getInverseProperty() | ||
| 232 | val roleP_inv = roleP.getInverseProperty() | ||
| 233 | |||
| 234 | val AsomeValuesFromRB = new OWLSubClassOfAxiomImpl( | ||
| 235 | new OWLClassImpl(RSA.base("A")), | ||
| 236 | new OWLObjectSomeValuesFromImpl( | ||
| 237 | roleR, | ||
| 238 | new OWLClassImpl(RSA.base("B")) | ||
| 239 | ), | ||
| 240 | Seq().asJava | ||
| 241 | ) | ||
| 242 | |||
| 243 | val BsomeValuesFromSC = new OWLSubClassOfAxiomImpl( | ||
| 244 | new OWLClassImpl(RSA.base("B")), | ||
| 245 | new OWLObjectSomeValuesFromImpl( | ||
| 246 | roleS, | ||
| 247 | new OWLClassImpl(RSA.base("C")) | ||
| 248 | ), | ||
| 249 | Seq().asJava | ||
| 250 | ) | ||
| 251 | |||
| 252 | val CsomeValuesFromTD = new OWLSubClassOfAxiomImpl( | ||
| 253 | new OWLClassImpl(RSA.base("C")), | ||
| 254 | new OWLObjectSomeValuesFromImpl( | ||
| 255 | roleT, | ||
| 256 | new OWLClassImpl(RSA.base("D")) | ||
| 257 | ), | ||
| 258 | Seq().asJava | ||
| 259 | ) | ||
| 260 | |||
| 261 | val DsomeValuesFromPA = new OWLSubClassOfAxiomImpl( | ||
| 262 | new OWLClassImpl(RSA.base("D")), | ||
| 263 | new OWLObjectSomeValuesFromImpl( | ||
| 264 | roleP, | ||
| 265 | new OWLClassImpl(RSA.base("A")) | ||
| 266 | ), | ||
| 267 | Seq().asJava | ||
| 268 | ) | ||
| 269 | |||
| 270 | } | ||
| 271 | |||
| 272 | class Ontology2_CanonicalModelSpec | ||
| 273 | extends AnyFlatSpec | ||
| 274 | with Matchers | ||
| 275 | with LoneElement { | ||
| 276 | |||
| 277 | import Ontology2_CanonicalModelSpec._ | ||
| 278 | |||
| 279 | "The program generated from Example #1" should "not be empty" in { | ||
| 280 | program should not be empty | ||
| 281 | } | ||
| 282 | |||
| 283 | // Role R // | ||
| 284 | |||
| 285 | renderer.render(roleR) should "be unsafe" in { | ||
| 286 | ontology.unsafeRoles should contain(roleR) | ||
| 287 | } | ||
| 288 | |||
| 289 | it should "have only its inverse in its conflict set" in { | ||
| 290 | ontology.confl(roleR).loneElement shouldBe roleR_inv | ||
| 291 | } | ||
| 292 | |||
| 293 | // Role S // | ||
| 294 | |||
| 295 | renderer.render(roleS) should "be unsafe" in { | ||
| 296 | ontology.unsafeRoles should contain(roleS) | ||
| 297 | } | ||
| 298 | |||
| 299 | it should "have only its inverse in its conflict set" in { | ||
| 300 | ontology.confl(roleS).loneElement shouldBe roleS_inv | ||
| 301 | } | ||
| 302 | |||
| 303 | // Role T // | ||
| 304 | |||
| 305 | renderer.render(roleT) should "be unsafe" in { | ||
| 306 | ontology.unsafeRoles should contain(roleT) | ||
| 307 | } | ||
| 308 | |||
| 309 | it should "have only its inverse in its conflict set" in { | ||
| 310 | ontology.confl(roleT).loneElement shouldBe roleT_inv | ||
| 311 | } | ||
| 312 | |||
| 313 | // Role P // | ||
| 314 | |||
| 315 | renderer.render(roleP) should "be unsafe" in { | ||
| 316 | ontology.unsafeRoles should contain(roleP) | ||
| 317 | } | ||
| 318 | |||
| 319 | it should "have only its inverse in its conflict set" in { | ||
| 320 | ontology.confl(roleP).loneElement shouldBe roleP_inv | ||
| 321 | } | ||
| 322 | |||
| 323 | // A ⊑ ∃ R.B | ||
| 324 | |||
| 325 | renderer.render( | ||
| 326 | AsomeValuesFromRB | ||
| 327 | ) should "produce 1 rule" in { | ||
| 328 | val visitor = ProgramGenerator(ontology) | ||
| 329 | val rules = AsomeValuesFromRB.accept(visitor) | ||
| 330 | rules should have length 1 | ||
| 331 | } | ||
| 332 | |||
| 333 | // B ⊑ ∃ S.C | ||
| 334 | |||
| 335 | renderer.render( | ||
| 336 | BsomeValuesFromSC | ||
| 337 | ) should "produce 1 rule" in { | ||
| 338 | val visitor = ProgramGenerator(ontology) | ||
| 339 | val rules = BsomeValuesFromSC.accept(visitor) | ||
| 340 | rules should have length 1 | ||
| 341 | } | ||
| 342 | |||
| 343 | // C ⊑ ∃ T.D | ||
| 344 | |||
| 345 | renderer.render( | ||
| 346 | CsomeValuesFromTD | ||
| 347 | ) should "produce 1 rule" in { | ||
| 348 | val visitor = ProgramGenerator(ontology) | ||
| 349 | val rules = CsomeValuesFromTD.accept(visitor) | ||
| 350 | rules should have length 1 | ||
| 351 | } | ||
| 352 | |||
| 353 | // D ⊑ ∃ P.A | ||
| 354 | |||
| 355 | renderer.render( | ||
| 356 | DsomeValuesFromPA | ||
| 357 | ) should "produce 1 rule" in { | ||
| 358 | val visitor = ProgramGenerator(ontology) | ||
| 359 | val rules = DsomeValuesFromPA.accept(visitor) | ||
| 360 | rules should have length 1 | ||
| 361 | } | ||
| 362 | |||
| 363 | } | ||
