From ec76d6cfbf5410fc90060667612461c1e8f3c111 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Fri, 4 Dec 2020 14:00:21 +0000 Subject: Rework skolemization strategies In particular `ConstantRSA` has been removed, since it was *not* a skolemization strategy. The case for extra atoms generation previously handled by `ConstantRSA` is not dealt with inside the RSA check. --- .../uk/ac/ox/cs/rsacomb/CanonicalModelSpec.scala | 38 ++++----------- .../scala/uk/ac/ox/cs/rsacomb/OWLAxiomSpec.scala | 30 +++++++----- .../scala/uk/ac/ox/cs/rsacomb/OWLClassSpec.scala | 56 +++++++++++----------- .../uk/ac/ox/cs/rsacomb/RDFoxConverterSpec.scala | 16 +++---- 4 files changed, 65 insertions(+), 75 deletions(-) (limited to 'src/test/scala') diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/CanonicalModelSpec.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/CanonicalModelSpec.scala index 0d07923..42ca6bd 100644 --- a/src/test/scala/uk/ac/ox/cs/rsacomb/CanonicalModelSpec.scala +++ b/src/test/scala/uk/ac/ox/cs/rsacomb/CanonicalModelSpec.scala @@ -15,7 +15,7 @@ import tech.oxfordsemantic.jrdfox.logic.expression.Variable import scala.collection.JavaConverters._ import uk.ac.ox.cs.rsacomb.RSAOntology -import uk.ac.ox.cs.rsacomb.converter.SkolemStrategy +import uk.ac.ox.cs.rsacomb.converter.{SkolemStrategy, NoSkolem} import uk.ac.ox.cs.rsacomb.suffix.Empty import uk.ac.ox.cs.rsacomb.util.{RDFoxUtil, RSA} @@ -94,10 +94,8 @@ class Ontology1_CanonicalModelSpec renderer.render(AsubClassOfD) should "be converted into a single Rule" in { val term = Variable.create("X") val unsafe = ontology.unsafeRoles - val skolem = SkolemStrategy.None - val suffix = Empty val (facts, rules) = - converter.convert(AsubClassOfD, term, unsafe, skolem, suffix) + converter.convert(AsubClassOfD, term, unsafe, NoSkolem, Empty) facts shouldBe empty rules.loneElement shouldBe a[Rule] } @@ -163,10 +161,8 @@ class Ontology1_CanonicalModelSpec ) should "produce 1 rule" in { val term = Variable.create("X") val unsafe = ontology.unsafeRoles - val skolem = SkolemStrategy.None - val suffix = Empty val (facts, rules) = - converter.convert(AsomeValuesFromSiC, term, unsafe, skolem, suffix) + converter.convert(AsomeValuesFromSiC, term, unsafe, NoSkolem, Empty) facts shouldBe empty rules.loneElement shouldBe a[Rule] } @@ -189,10 +185,8 @@ class Ontology1_CanonicalModelSpec // Rule 3 provides 48 rule (split in 2) val term = Variable.create("X") val unsafe = ontology.unsafeRoles - val skolem = SkolemStrategy.None - val suffix = Empty val (facts, rules) = - converter.convert(DsomeValuesFromRB, term, unsafe, skolem, suffix) + converter.convert(DsomeValuesFromRB, term, unsafe, NoSkolem, Empty) facts should have length 48 rules should have length 98 } @@ -216,10 +210,8 @@ class Ontology1_CanonicalModelSpec // Then (1*2 + 32) + (0) + (32*2) = 98 val term = Variable.create("X") val unsafe = ontology.unsafeRoles - val skolem = SkolemStrategy.None - val suffix = Empty val (facts, rules) = - converter.convert(BsomeValuesFromSD, term, unsafe, skolem, suffix) + converter.convert(BsomeValuesFromSD, term, unsafe, NoSkolem, Empty) facts should have length 32 rules should have length 66 } @@ -229,10 +221,8 @@ class Ontology1_CanonicalModelSpec ) should "produce 2 rules" in { val term = Variable.create("X") val unsafe = ontology.unsafeRoles - val skolem = SkolemStrategy.None - val suffix = Empty val (facts, rules) = - converter.convert(SsubPropertyOfT, term, unsafe, skolem, suffix) + converter.convert(SsubPropertyOfT, term, unsafe, NoSkolem, Empty) facts shouldBe empty rules should have length 2 } @@ -357,10 +347,8 @@ class Ontology2_CanonicalModelSpec ) should "produce 1 rule" in { val term = Variable.create("X") val unsafe = ontology.unsafeRoles - val skolem = SkolemStrategy.None - val suffix = Empty val (facts, rules) = - converter.convert(AsomeValuesFromRB, term, unsafe, skolem, suffix) + converter.convert(AsomeValuesFromRB, term, unsafe, NoSkolem, Empty) facts shouldBe empty rules should have length 1 } @@ -372,10 +360,8 @@ class Ontology2_CanonicalModelSpec ) should "produce 1 rule" in { val term = Variable.create("X") val unsafe = ontology.unsafeRoles - val skolem = SkolemStrategy.None - val suffix = Empty val (facts, rules) = - converter.convert(BsomeValuesFromSC, term, unsafe, skolem, suffix) + converter.convert(BsomeValuesFromSC, term, unsafe, NoSkolem, Empty) facts shouldBe empty rules should have length 1 } @@ -387,10 +373,8 @@ class Ontology2_CanonicalModelSpec ) should "produce 1 rule" in { val term = Variable.create("X") val unsafe = ontology.unsafeRoles - val skolem = SkolemStrategy.None - val suffix = Empty val (facts, rules) = - converter.convert(CsomeValuesFromTD, term, unsafe, skolem, suffix) + converter.convert(CsomeValuesFromTD, term, unsafe, NoSkolem, Empty) facts shouldBe empty rules should have length 1 } @@ -402,10 +386,8 @@ class Ontology2_CanonicalModelSpec ) should "produce 1 rule" in { val term = Variable.create("X") val unsafe = ontology.unsafeRoles - val skolem = SkolemStrategy.None - val suffix = Empty val (facts, rules) = - converter.convert(DsomeValuesFromPA, term, unsafe, skolem, suffix) + converter.convert(DsomeValuesFromPA, term, unsafe, NoSkolem, Empty) facts shouldBe empty rules should have length 1 } diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/OWLAxiomSpec.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/OWLAxiomSpec.scala index 8aee03d..d39dec7 100644 --- a/src/test/scala/uk/ac/ox/cs/rsacomb/OWLAxiomSpec.scala +++ b/src/test/scala/uk/ac/ox/cs/rsacomb/OWLAxiomSpec.scala @@ -36,7 +36,13 @@ import tech.oxfordsemantic.jrdfox.logic.expression.{ import org.semanticweb.owlapi.model.{IRI => OWLIRI} import tech.oxfordsemantic.jrdfox.logic.expression.{IRI => RDFIRI} -import uk.ac.ox.cs.rsacomb.converter.{RDFoxAxiomConverter, SkolemStrategy} +import uk.ac.ox.cs.rsacomb.converter.{ + RDFoxAxiomConverter, + SkolemStrategy, + NoSkolem, + Standard, + Constant +} import uk.ac.ox.cs.rsacomb.util.RSA object OWLAxiomSpec { @@ -172,7 +178,7 @@ object OWLAxiomSpec { def convertAxiom( axiom: OWLAxiom, term: Term, - skolem: SkolemStrategy = SkolemStrategy.None + skolem: SkolemStrategy = NoSkolem ): List[Rule] = { axiom.accept(RDFoxAxiomConverter(term, List())) } @@ -210,13 +216,13 @@ class OWLAxiomSpec extends AnyFlatSpec with Matchers with LoneElement { // OWLSubClassOfAxiom #2 (w/ constant skolemization) (axiom_OWLSubClassOf2.toString + "\n(w/ constant skolemization)") should "be converted into a singleton List[Rule]" in { - val skolem = SkolemStrategy.Constant(axiom_OWLSubClassOf2.toString) - val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) - result.loneElement shouldBe a[Rule] - } + val skolem = Constant(axiom_OWLSubClassOf2.toString) + val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) + result.loneElement shouldBe a[Rule] + } it should "contain a single atom (Student[?x]) in the body of the rule" in { - val skolem = SkolemStrategy.Constant(axiom_OWLSubClassOf2.toString) + val skolem = Constant(axiom_OWLSubClassOf2.toString) val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) val body = TupleTableAtom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student.getIRIString) @@ -237,13 +243,13 @@ class OWLAxiomSpec extends AnyFlatSpec with Matchers with LoneElement { // OWLSubClassOfAxiom #2 (w/ skolemization) (axiom_OWLSubClassOf2.toString + "\n(w/ skolemization)") should "be converted into a singleton List[Rule]" in { - val skolem = SkolemStrategy.Standard(axiom_OWLSubClassOf2.toString) - val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) - result.loneElement shouldBe a[Rule] - } + val skolem = Standard(axiom_OWLSubClassOf2.toString) + val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) + result.loneElement shouldBe a[Rule] + } it should "contain an atom (Student[?x]) in the body of the rule" in { - val skolem = SkolemStrategy.Standard(axiom_OWLSubClassOf2.toString) + val skolem = Standard(axiom_OWLSubClassOf2.toString) val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) val body = TupleTableAtom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student) diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/OWLClassSpec.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/OWLClassSpec.scala index 459fe21..bc3ac2b 100644 --- a/src/test/scala/uk/ac/ox/cs/rsacomb/OWLClassSpec.scala +++ b/src/test/scala/uk/ac/ox/cs/rsacomb/OWLClassSpec.scala @@ -36,7 +36,9 @@ import tech.oxfordsemantic.jrdfox.logic.expression.{ import uk.ac.ox.cs.rsacomb.converter.{ RDFoxRuleShards, RDFoxClassExprConverter, - SkolemStrategy + SkolemStrategy, + Standard, + Constant } import uk.ac.ox.cs.rsacomb.util.RSA @@ -179,16 +181,16 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { // OWLObjectSomeValuesFrom (class_OWLObjectSomeValuesFrom.toString ++ " w/o skolemization") should "be converted into a RDFoxRuleShards" in { - val visitor = RDFoxClassExprConverter(term_x) - val result = class_OWLObjectSomeValuesFrom.accept(visitor) - result shouldBe a[RDFoxRuleShards] - } + val visitor = RDFoxClassExprConverter(term_x) + val result = class_OWLObjectSomeValuesFrom.accept(visitor) + result shouldBe a[RDFoxRuleShards] + } it should "have two TupleTableAtoms in its result list" in { val visitor = RDFoxClassExprConverter(term_x) val result = class_OWLObjectSomeValuesFrom.accept(visitor) exactly(2, result.res) should (be(an[TupleTableAtom]) - //and have('numberOfArguments (3)) + //and have('numberOfArguments (3)) ) } @@ -200,23 +202,23 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { (class_OWLObjectSomeValuesFrom.toString ++ " w/ skolemization") should "be converted into a RDFoxRuleShards" in { - val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString) - val visitor = RDFoxClassExprConverter(term_x, List(), skolem) - val result = class_OWLObjectSomeValuesFrom.accept(visitor) - result shouldBe a[RDFoxRuleShards] - } + val skolem = Standard(class_OWLObjectSomeValuesFrom.toString) + val visitor = RDFoxClassExprConverter(term_x, List(), skolem) + val result = class_OWLObjectSomeValuesFrom.accept(visitor) + result shouldBe a[RDFoxRuleShards] + } it should "have exactly two TupleTableAtoms in its result list" in { - val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString) + val skolem = Standard(class_OWLObjectSomeValuesFrom.toString) val visitor = RDFoxClassExprConverter(term_x, List(), skolem) val result = class_OWLObjectSomeValuesFrom.accept(visitor) exactly(2, result.res) should (be(an[TupleTableAtom]) - //and have('numberOfArguments (3)) + //and have('numberOfArguments (3)) ) } it should "should have a single SKOLEM call in the extension list" in { - val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString) + val skolem = Standard(class_OWLObjectSomeValuesFrom.toString) val visitor = RDFoxClassExprConverter(term_x, List(), skolem) val result = class_OWLObjectSomeValuesFrom.accept(visitor) result.ext.loneElement shouldBe a[BindAtom] @@ -228,23 +230,23 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { (class_OWLObjectSomeValuesFrom.toString ++ " w/ constant skolemization") should "be converted into a RDFoxRuleShards" in { - val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString) - val visitor = RDFoxClassExprConverter(term_x, List(), skolem) - val result = class_OWLObjectSomeValuesFrom.accept(visitor) - result shouldBe a[RDFoxRuleShards] - } + val skolem = Constant(class_OWLObjectSomeValuesFrom.toString) + val visitor = RDFoxClassExprConverter(term_x, List(), skolem) + val result = class_OWLObjectSomeValuesFrom.accept(visitor) + result shouldBe a[RDFoxRuleShards] + } it should "have exactly two TupleTableAtoms in its result list" in { - val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString) + val skolem = Constant(class_OWLObjectSomeValuesFrom.toString) val visitor = RDFoxClassExprConverter(term_x, List(), skolem) val result = class_OWLObjectSomeValuesFrom.accept(visitor) exactly(2, result.res) should (be(an[TupleTableAtom]) - //and have('numberOfArguments (3)) + //and have('numberOfArguments (3)) ) } it should "have an empty extension list" in { - val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString) + val skolem = Constant(class_OWLObjectSomeValuesFrom.toString) val visitor = RDFoxClassExprConverter(term_x, List(), skolem) val result = class_OWLObjectSomeValuesFrom.accept(visitor) result.ext shouldBe empty @@ -253,10 +255,10 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { // OWLObjectMaxCardinalityImpl class_OWLObjectMaxCardinality.toString should "be converted into a RDFoxRuleShards" in { - val visitor = RDFoxClassExprConverter(term_x) - val result = class_OWLObjectMaxCardinality.accept(visitor) - result shouldBe a[RDFoxRuleShards] - } + val visitor = RDFoxClassExprConverter(term_x) + val result = class_OWLObjectMaxCardinality.accept(visitor) + result shouldBe a[RDFoxRuleShards] + } // it should "have a single TupleTableAtom in the result list" in { // val visitor = RDFoxClassExprConverter(term_x) @@ -270,7 +272,7 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { val visitor = RDFoxClassExprConverter(term_x) val result = class_OWLObjectMaxCardinality.accept(visitor) exactly(4, result.ext) should (be(an[TupleTableAtom]) - //and have('numberOfArguments (3)) + //and have('numberOfArguments (3)) ) } diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/RDFoxConverterSpec.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/RDFoxConverterSpec.scala index e2da6e4..5c9fa96 100644 --- a/src/test/scala/uk/ac/ox/cs/rsacomb/RDFoxConverterSpec.scala +++ b/src/test/scala/uk/ac/ox/cs/rsacomb/RDFoxConverterSpec.scala @@ -10,7 +10,7 @@ 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 +import uk.ac.ox.cs.rsacomb.converter.{SkolemStrategy, NoSkolem} object RDFoxConverterSpec { @@ -44,7 +44,7 @@ class RDFoxConverterSpec val cls = factory.getOWLClass(iriString0) val atom = TupleTableAtom.rdf(term0, IRI.RDF_TYPE, IRI.create(iriString0)) val (res, ext) = - convert(cls, term0, List(), SkolemStrategy.None, Empty) + convert(cls, term0, List(), NoSkolem, Empty) res.loneElement shouldEqual atom ext shouldBe empty } @@ -55,13 +55,13 @@ class RDFoxConverterSpec val cls2 = factory.getOWLClass(iriString2) val conj = factory.getOWLObjectIntersectionOf(cls0, cls1, cls2) val (res0, ext0) = - convert(cls0, term0, List(), SkolemStrategy.None, Empty) + convert(cls0, term0, List(), NoSkolem, Empty) val (res1, ext1) = - convert(cls1, term0, List(), SkolemStrategy.None, Empty) + convert(cls1, term0, List(), NoSkolem, Empty) val (res2, ext2) = - convert(cls2, term0, List(), SkolemStrategy.None, Empty) + convert(cls2, term0, List(), NoSkolem, Empty) val (res, ext) = - convert(conj, term0, List(), SkolemStrategy.None, Empty) + convert(conj, term0, List(), NoSkolem, Empty) res should contain theSameElementsAs (res0 ::: res1 ::: res2) ext should contain theSameElementsAs (ext0 ::: ext1 ::: ext2) } @@ -70,9 +70,9 @@ class RDFoxConverterSpec val cls0 = factory.getOWLClass(iriString0) val conj = factory.getOWLObjectIntersectionOf(cls0) val (res0, ext0) = - convert(cls0, term0, List(), SkolemStrategy.None, Empty) + convert(cls0, term0, List(), NoSkolem, Empty) val (res, ext) = - convert(conj, term0, List(), SkolemStrategy.None, Empty) + convert(conj, term0, List(), NoSkolem, Empty) res should contain theSameElementsAs res0 ext should contain theSameElementsAs ext0 } -- cgit v1.2.3