diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-10-10 13:14:33 +0200 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-10-10 13:14:33 +0200 |
| commit | 014fda84a13620b64597f4bbd6d27afcb929e0f4 (patch) | |
| tree | 459f091e3fc0d8942a653655e4ad9741e9c88ff1 /src | |
| parent | dbc4499bbf1ee21441158f4028fba330f18e0b3d (diff) | |
| download | RSAComb-014fda84a13620b64597f4bbd6d27afcb929e0f4.tar.gz RSAComb-014fda84a13620b64597f4bbd6d27afcb929e0f4.zip | |
Add some tests for canonical model computation
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/rsacomb/RSAOntology.scala | 2 | ||||
| -rw-r--r-- | src/test/scala/rsacomb/CanonicalModelSpec.scala | 82 |
2 files changed, 70 insertions, 14 deletions
diff --git a/src/main/scala/rsacomb/RSAOntology.scala b/src/main/scala/rsacomb/RSAOntology.scala index aa84308..c1d3ba9 100644 --- a/src/main/scala/rsacomb/RSAOntology.scala +++ b/src/main/scala/rsacomb/RSAOntology.scala | |||
| @@ -270,7 +270,7 @@ trait RSAOntology { | |||
| 270 | .filterNot(_.isOWLBottomObjectProperty()) | 270 | .filterNot(_.isOWLBottomObjectProperty()) |
| 271 | } | 271 | } |
| 272 | 272 | ||
| 273 | private def self(axiom: OWLSubClassOfAxiom): Set[Term] = { | 273 | def self(axiom: OWLSubClassOfAxiom): Set[Term] = { |
| 274 | // Assuming just one role in the signature of a T5 axiom | 274 | // Assuming just one role in the signature of a T5 axiom |
| 275 | val role = axiom.objectPropertyExpressionsInSignature(0) | 275 | val role = axiom.objectPropertyExpressionsInSignature(0) |
| 276 | if (this.confl(role).contains(role)) { | 276 | if (this.confl(role).contains(role)) { |
diff --git a/src/test/scala/rsacomb/CanonicalModelSpec.scala b/src/test/scala/rsacomb/CanonicalModelSpec.scala index 44c4441..d783b12 100644 --- a/src/test/scala/rsacomb/CanonicalModelSpec.scala +++ b/src/test/scala/rsacomb/CanonicalModelSpec.scala | |||
| @@ -5,6 +5,7 @@ import org.scalatest.{FlatSpec, Matchers, LoneElement} | |||
| 5 | 5 | ||
| 6 | import org.semanticweb.owlapi.model._ | 6 | import org.semanticweb.owlapi.model._ |
| 7 | import uk.ac.manchester.cs.owl.owlapi._ | 7 | import uk.ac.manchester.cs.owl.owlapi._ |
| 8 | import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer | ||
| 8 | 9 | ||
| 9 | import tech.oxfordsemantic.jrdfox.logic.{Rule, Variable} | 10 | import tech.oxfordsemantic.jrdfox.logic.{Rule, Variable} |
| 10 | 11 | ||
| @@ -13,34 +14,89 @@ import scala.collection.JavaConverters._ | |||
| 13 | import rsacomb.RSA._ | 14 | import rsacomb.RSA._ |
| 14 | import rsacomb.RDFoxUtil._ | 15 | import rsacomb.RDFoxUtil._ |
| 15 | 16 | ||
| 16 | object CanonicalModelSpec { | 17 | object Ontology1_CanonicalModelSpec { |
| 17 | 18 | ||
| 18 | val ontology1_path: File = new File("examples/example1.owl") | 19 | /* Renderer to display OWL Axioms with DL syntax*/ |
| 19 | val ontology1 = RSA.loadOntology(ontology1_path) | 20 | val renderer = new DLSyntaxObjectRenderer() |
| 20 | val program1 = ontology1.canonicalModel | ||
| 21 | 21 | ||
| 22 | val axiom1 = new OWLSubClassOfAxiomImpl( | 22 | val ontology_path: File = new File("examples/example1.owl") |
| 23 | val ontology = RSA.loadOntology(ontology_path) | ||
| 24 | val program = ontology.canonicalModel | ||
| 25 | |||
| 26 | val roleR = new OWLObjectPropertyImpl(RSA.base("R")) | ||
| 27 | val roleS = new OWLObjectPropertyImpl(RSA.base("S")) | ||
| 28 | val roleT = new OWLObjectPropertyImpl(RSA.base("T")) | ||
| 29 | val roleR_inv = roleR.getInverseProperty() | ||
| 30 | val roleS_inv = roleS.getInverseProperty() | ||
| 31 | val roleT_inv = roleT.getInverseProperty() | ||
| 32 | |||
| 33 | val AsubClassOfD = new OWLSubClassOfAxiomImpl( | ||
| 23 | new OWLClassImpl(RSA.base("A")), | 34 | new OWLClassImpl(RSA.base("A")), |
| 24 | new OWLClassImpl(RSA.base("D")), | 35 | new OWLClassImpl(RSA.base("D")), |
| 25 | Seq().asJava | 36 | Seq().asJava |
| 26 | ) | 37 | ) |
| 27 | 38 | ||
| 39 | val DsomeValuesFromRB = new OWLSubClassOfAxiomImpl( | ||
| 40 | new OWLClassImpl(RSA.base("D")), | ||
| 41 | new OWLObjectSomeValuesFromImpl( | ||
| 42 | roleR, | ||
| 43 | new OWLClassImpl(RSA.base("B")) | ||
| 44 | ), | ||
| 45 | Seq().asJava | ||
| 46 | ) | ||
| 47 | |||
| 28 | } // object OWLAxiomSpec | 48 | } // object OWLAxiomSpec |
| 29 | 49 | ||
| 30 | class CanonicalModelSpec extends FlatSpec with Matchers with LoneElement { | 50 | class Ontology1_CanonicalModelSpec |
| 51 | extends FlatSpec | ||
| 52 | with Matchers | ||
| 53 | with LoneElement { | ||
| 31 | 54 | ||
| 32 | import CanonicalModelSpec._ | 55 | import Ontology1_CanonicalModelSpec._ |
| 33 | 56 | ||
| 34 | // Example 1 | 57 | "The program generated from Example #1" should "not be empty" in { |
| 35 | "The program generated from Example1" should "not be empty" in { | 58 | program should not be empty |
| 36 | program1 should not be empty | ||
| 37 | } | 59 | } |
| 38 | 60 | ||
| 39 | axiom1.toString should "be converted into a single Rule" in { | 61 | renderer.render(AsubClassOfD) should "be converted into a single Rule" in { |
| 40 | val varX = Variable.create("X") | 62 | val varX = Variable.create("X") |
| 41 | val visitor = ProgramGenerator(ontology1, varX) | 63 | val visitor = ProgramGenerator(ontology, varX) |
| 42 | val rules = axiom1.accept(visitor) | 64 | val rules = AsubClassOfD.accept(visitor) |
| 43 | rules.loneElement shouldBe a[Rule] | 65 | rules.loneElement shouldBe a[Rule] |
| 44 | } | 66 | } |
| 45 | 67 | ||
| 68 | renderer.render(roleR) should "be safe" in { | ||
| 69 | ontology.unsafeRoles should not contain roleR | ||
| 70 | } | ||
| 71 | |||
| 72 | it should "contain S in its conflict set" in { | ||
| 73 | ontology.confl(roleR) should contain(roleS) | ||
| 74 | } | ||
| 75 | |||
| 76 | renderer.render(roleS) should "be safe" in { | ||
| 77 | ontology.unsafeRoles should not contain roleS | ||
| 78 | } | ||
| 79 | |||
| 80 | it should "contain R in its conflict set" in { | ||
| 81 | ontology.confl(roleS) should contain(roleR) | ||
| 82 | } | ||
| 83 | |||
| 84 | renderer.render(roleS_inv) should "be unsafe" in { | ||
| 85 | ontology.unsafeRoles should contain(roleS_inv) | ||
| 86 | } | ||
| 87 | |||
| 88 | it should ("contain " + renderer.render( | ||
| 89 | roleR_inv | ||
| 90 | ) + " in its conflict set") in { | ||
| 91 | ontology.confl(roleS_inv) should contain(roleR_inv) | ||
| 92 | } | ||
| 93 | |||
| 94 | renderer.render( | ||
| 95 | DsomeValuesFromRB | ||
| 96 | ) should "produce 5 rules" ignore { | ||
| 97 | val varX = Variable.create("X") | ||
| 98 | val visitor = ProgramGenerator(ontology, varX) | ||
| 99 | val rules = DsomeValuesFromRB.accept(visitor) | ||
| 100 | rules should have length 5 | ||
| 101 | } | ||
| 46 | } // class OWLAxiomSpec | 102 | } // class OWLAxiomSpec |
