diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-12-04 14:00:21 +0000 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-12-04 16:51:38 +0000 |
commit | ec76d6cfbf5410fc90060667612461c1e8f3c111 (patch) | |
tree | 6d3268ba7116c2aad3c7238500e87bb990d31a27 /src | |
parent | d7fa665c289923c362c17ce16cda03588911a817 (diff) | |
download | RSAComb-ec76d6cfbf5410fc90060667612461c1e8f3c111.tar.gz RSAComb-ec76d6cfbf5410fc90060667612461c1e8f3c111.zip |
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.
Diffstat (limited to 'src')
11 files changed, 190 insertions, 236 deletions
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/CanonicalModel.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/CanonicalModel.scala index bcc336a..c605e51 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/CanonicalModel.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/CanonicalModel.scala | |||
@@ -24,12 +24,7 @@ import tech.oxfordsemantic.jrdfox.logic.expression.{ | |||
24 | IRI | 24 | IRI |
25 | } | 25 | } |
26 | 26 | ||
27 | import uk.ac.ox.cs.rsacomb.converter.{ | 27 | import uk.ac.ox.cs.rsacomb.converter._ |
28 | SkolemStrategy, | ||
29 | RDFoxConverter | ||
30 | // RDFoxAxiomConverter, | ||
31 | // RDFoxPropertyExprConverter | ||
32 | } | ||
33 | import uk.ac.ox.cs.rsacomb.suffix._ | 28 | import uk.ac.ox.cs.rsacomb.suffix._ |
34 | import uk.ac.ox.cs.rsacomb.util.RSA | 29 | import uk.ac.ox.cs.rsacomb.util.RSA |
35 | 30 | ||
@@ -114,10 +109,8 @@ class CanonicalModel(val ontology: RSAOntology) { | |||
114 | val (facts, rules) = { | 109 | val (facts, rules) = { |
115 | val term = RSAOntology.genFreshVariable() | 110 | val term = RSAOntology.genFreshVariable() |
116 | val unsafe = ontology.unsafeRoles | 111 | val unsafe = ontology.unsafeRoles |
117 | val skolem = SkolemStrategy.None | ||
118 | val suffix = Empty | ||
119 | ontology.axioms | 112 | ontology.axioms |
120 | .map(CanonicalModelConverter.convert(_, term, unsafe, skolem, suffix)) | 113 | .map(CanonicalModelConverter.convert(_, term, unsafe, NoSkolem, Empty)) |
121 | .unzip | 114 | .unzip |
122 | } | 115 | } |
123 | ( | 116 | ( |
@@ -245,10 +238,9 @@ class CanonicalModel(val ontology: RSAOntology) { | |||
245 | 238 | ||
246 | case a: OWLSubClassOfAxiom if a.isT5 => { | 239 | case a: OWLSubClassOfAxiom if a.isT5 => { |
247 | val role = axiom.objectPropertyExpressionsInSignature(0) | 240 | val role = axiom.objectPropertyExpressionsInSignature(0) |
248 | if (unsafe contains role) { | 241 | if (unsafe contains role) |
249 | val skolem = SkolemStrategy.Standard(a.toString) | 242 | super.convert(a, term, unsafe, new Standard(a), Forward) |
250 | super.convert(a, term, unsafe, skolem, Forward) | 243 | else { |
251 | } else { | ||
252 | val (f1, r1) = rules1(a) | 244 | val (f1, r1) = rules1(a) |
253 | (f1, r1 ::: rules2(a) ::: rules3(a)) | 245 | (f1, r1 ::: rules2(a) ::: rules3(a)) |
254 | } | 246 | } |
@@ -256,9 +248,9 @@ class CanonicalModel(val ontology: RSAOntology) { | |||
256 | 248 | ||
257 | case a: OWLSubObjectPropertyOfAxiom => { | 249 | case a: OWLSubObjectPropertyOfAxiom => { |
258 | val (factsF, rulesF) = | 250 | val (factsF, rulesF) = |
259 | super.convert(a, term, unsafe, SkolemStrategy.None, Forward) | 251 | super.convert(a, term, unsafe, NoSkolem, Forward) |
260 | val (factsB, rulesB) = | 252 | val (factsB, rulesB) = |
261 | super.convert(a, term, unsafe, SkolemStrategy.None, Backward) | 253 | super.convert(a, term, unsafe, NoSkolem, Backward) |
262 | (factsF ::: factsB, rulesF ::: rulesB) | 254 | (factsF ::: factsB, rulesF ::: rulesB) |
263 | } | 255 | } |
264 | 256 | ||
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala index a965ef9..8fae4c8 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
@@ -50,7 +50,7 @@ import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer | |||
50 | import tech.oxfordsemantic.jrdfox.logic._ | 50 | import tech.oxfordsemantic.jrdfox.logic._ |
51 | import org.semanticweb.owlapi.model.OWLObjectInverseOf | 51 | import org.semanticweb.owlapi.model.OWLObjectInverseOf |
52 | 52 | ||
53 | import uk.ac.ox.cs.rsacomb.converter.{RDFoxConverter, SkolemStrategy} | 53 | import uk.ac.ox.cs.rsacomb.converter._ |
54 | import uk.ac.ox.cs.rsacomb.suffix._ | 54 | import uk.ac.ox.cs.rsacomb.suffix._ |
55 | import uk.ac.ox.cs.rsacomb.sparql._ | 55 | import uk.ac.ox.cs.rsacomb.sparql._ |
56 | import uk.ac.ox.cs.rsacomb.util.{RDFoxUtil, RSA} | 56 | import uk.ac.ox.cs.rsacomb.util.{RDFoxUtil, RSA} |
@@ -163,16 +163,16 @@ class RSAOntology(val ontology: OWLOntology) { | |||
163 | ): Shards = | 163 | ): Shards = |
164 | (expr, skolem) match { | 164 | (expr, skolem) match { |
165 | 165 | ||
166 | case (e: OWLObjectSomeValuesFrom, SkolemStrategy.Constant(c)) | 166 | case (e: OWLObjectSomeValuesFrom, c: Constant) |
167 | if unsafe contains e.getProperty => { | 167 | if unsafe contains e.getProperty => { |
168 | val (res, ext) = super.convert(e, term, unsafe, skolem, suffix) | 168 | val (res, ext) = super.convert(e, term, unsafe, skolem, suffix) |
169 | (RSA.PE(term, c) :: RSA.U(c) :: res, ext) | 169 | (RSA.PE(term, c.iri) :: RSA.U(c.iri) :: res, ext) |
170 | } | 170 | } |
171 | 171 | ||
172 | case (e: OWLDataSomeValuesFrom, SkolemStrategy.Constant(c)) | 172 | case (e: OWLDataSomeValuesFrom, c: Constant) |
173 | if unsafe contains e.getProperty => { | 173 | if unsafe contains e.getProperty => { |
174 | val (res, ext) = super.convert(e, term, unsafe, skolem, suffix) | 174 | val (res, ext) = super.convert(e, term, unsafe, skolem, suffix) |
175 | (RSA.PE(term, c) :: RSA.U(c) :: res, ext) | 175 | (RSA.PE(term, c.iri) :: RSA.U(c.iri) :: res, ext) |
176 | } | 176 | } |
177 | 177 | ||
178 | case _ => super.convert(expr, term, unsafe, skolem, suffix) | 178 | case _ => super.convert(expr, term, unsafe, skolem, suffix) |
@@ -183,10 +183,7 @@ class RSAOntology(val ontology: OWLOntology) { | |||
183 | /* Ontology convertion into LP rules */ | 183 | /* Ontology convertion into LP rules */ |
184 | val term = RSAOntology.genFreshVariable() | 184 | val term = RSAOntology.genFreshVariable() |
185 | val datalog = axioms | 185 | val datalog = axioms |
186 | .map(a => { | 186 | .map(a => RSAConverter.convert(a, term, unsafe, new Constant(a), Empty)) |
187 | val skolem = SkolemStrategy.Constant(a.toString) | ||
188 | RSAConverter.convert(a, term, unsafe, skolem, Empty) | ||
189 | }) | ||
190 | .unzip | 187 | .unzip |
191 | val facts = datalog._1.flatten | 188 | val facts = datalog._1.flatten |
192 | val rules = datalog._2.flatten | 189 | val rules = datalog._2.flatten |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxAxiomConverter.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxAxiomConverter.scala index 93d8f8c..1fbf28a 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxAxiomConverter.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxAxiomConverter.scala | |||
@@ -44,7 +44,7 @@ object RDFoxAxiomConverter { | |||
44 | def apply( | 44 | def apply( |
45 | term: Term, | 45 | term: Term, |
46 | unsafe: List[OWLObjectPropertyExpression], | 46 | unsafe: List[OWLObjectPropertyExpression], |
47 | skolem: SkolemStrategy = SkolemStrategy.None, | 47 | skolem: SkolemStrategy = NoSkolem, |
48 | suffix: RSASuffix = Empty | 48 | suffix: RSASuffix = Empty |
49 | ): RDFoxAxiomConverter = | 49 | ): RDFoxAxiomConverter = |
50 | new RDFoxAxiomConverter(term, unsafe, skolem, suffix) | 50 | new RDFoxAxiomConverter(term, unsafe, skolem, suffix) |
@@ -63,7 +63,7 @@ class RDFoxAxiomConverter( | |||
63 | override def visit(axiom: OWLSubClassOfAxiom): List[Rule] = { | 63 | override def visit(axiom: OWLSubClassOfAxiom): List[Rule] = { |
64 | // Skolemization is needed only for the head of an axiom | 64 | // Skolemization is needed only for the head of an axiom |
65 | val subVisitor = | 65 | val subVisitor = |
66 | new RDFoxClassExprConverter(term, unsafe, SkolemStrategy.None, suffix) | 66 | new RDFoxClassExprConverter(term, unsafe, NoSkolem, suffix) |
67 | val superVisitor = new RDFoxClassExprConverter(term, unsafe, skolem, suffix) | 67 | val superVisitor = new RDFoxClassExprConverter(term, unsafe, skolem, suffix) |
68 | // Each visitor returns a `RDFoxRuleShards`, a tuple (res,ext): | 68 | // Each visitor returns a `RDFoxRuleShards`, a tuple (res,ext): |
69 | // - the `res` List is a list of atoms resulting from the conversion | 69 | // - the `res` List is a list of atoms resulting from the conversion |
@@ -121,7 +121,7 @@ class RDFoxAxiomConverter( | |||
121 | val term = RDFoxIRI.create(ind.asOWLNamedIndividual().getIRI.getIRIString) | 121 | val term = RDFoxIRI.create(ind.asOWLNamedIndividual().getIRI.getIRIString) |
122 | val cls = axiom.getClassExpression | 122 | val cls = axiom.getClassExpression |
123 | val visitor = | 123 | val visitor = |
124 | new RDFoxClassExprConverter(term, unsafe, SkolemStrategy.None, suffix) | 124 | new RDFoxClassExprConverter(term, unsafe, NoSkolem, suffix) |
125 | val shard = cls.accept(visitor) | 125 | val shard = cls.accept(visitor) |
126 | List(Rule.create(shard.res.asJava, shard.ext.asJava)) | 126 | List(Rule.create(shard.res.asJava, shard.ext.asJava)) |
127 | } else { | 127 | } else { |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxClassExprConverter.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxClassExprConverter.scala index 4ededf9..9551c61 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxClassExprConverter.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxClassExprConverter.scala | |||
@@ -39,7 +39,7 @@ object RDFoxClassExprConverter { | |||
39 | def apply( | 39 | def apply( |
40 | term: Term, | 40 | term: Term, |
41 | unsafe: List[OWLObjectPropertyExpression] = List(), | 41 | unsafe: List[OWLObjectPropertyExpression] = List(), |
42 | skolem: SkolemStrategy = SkolemStrategy.None, | 42 | skolem: SkolemStrategy = NoSkolem, |
43 | suffix: RSASuffix = Empty | 43 | suffix: RSASuffix = Empty |
44 | ): RDFoxClassExprConverter = | 44 | ): RDFoxClassExprConverter = |
45 | new RDFoxClassExprConverter(term, unsafe, skolem, suffix) | 45 | new RDFoxClassExprConverter(term, unsafe, skolem, suffix) |
@@ -58,8 +58,8 @@ object RDFoxClassExprConverter { | |||
58 | class RDFoxClassExprConverter( | 58 | class RDFoxClassExprConverter( |
59 | term: Term, | 59 | term: Term, |
60 | unsafe: List[OWLObjectPropertyExpression], | 60 | unsafe: List[OWLObjectPropertyExpression], |
61 | skolem: SkolemStrategy, | 61 | skolem: SkolemStrategy = NoSkolem, |
62 | suffix: RSASuffix | 62 | suffix: RSASuffix = Empty |
63 | ) extends OWLClassExpressionVisitorEx[RDFoxRuleShards] { | 63 | ) extends OWLClassExpressionVisitorEx[RDFoxRuleShards] { |
64 | 64 | ||
65 | import uk.ac.ox.cs.rsacomb.implicits.RDFox._ | 65 | import uk.ac.ox.cs.rsacomb.implicits.RDFox._ |
@@ -106,18 +106,14 @@ class RDFoxClassExprConverter( | |||
106 | // technique it might involve the introduction of additional atoms, | 106 | // technique it might involve the introduction of additional atoms, |
107 | // and/or fresh constants and variables. | 107 | // and/or fresh constants and variables. |
108 | val (head, body, term1) = skolem match { | 108 | val (head, body, term1) = skolem match { |
109 | case SkolemStrategy.None => (List(), List(), y) | 109 | case NoSkolem => (List(), List(), y) |
110 | case SkolemStrategy.Constant(c) => (List(), List(), c) | 110 | case c: Constant => (List(), List(), c.iri) |
111 | case SkolemStrategy.ConstantRSA(c) => { | 111 | case s: Standard => { |
112 | if (unsafe.contains(prop)) | ||
113 | (List(RSA.PE(term, c), RSA.U(c)), List(), c) | ||
114 | else | ||
115 | (List(), List(), c) | ||
116 | } | ||
117 | case SkolemStrategy.Standard(f) => { | ||
118 | ( | 112 | ( |
119 | List(), | 113 | List(), |
120 | List(BindAtom.create(FunctionCall.create("SKOLEM", f, term), y)), | 114 | List( |
115 | BindAtom.create(FunctionCall.create("SKOLEM", s.literal, term), y) | ||
116 | ), | ||
121 | y | 117 | y |
122 | ) | 118 | ) |
123 | } | 119 | } |
@@ -152,18 +148,14 @@ class RDFoxClassExprConverter( | |||
152 | // technique it might involve the introduction of additional atoms, | 148 | // technique it might involve the introduction of additional atoms, |
153 | // and/or fresh constants and variables. | 149 | // and/or fresh constants and variables. |
154 | val (head, body, term1) = skolem match { | 150 | val (head, body, term1) = skolem match { |
155 | case SkolemStrategy.None => (List(), List(), y) | 151 | case NoSkolem => (List(), List(), y) |
156 | case SkolemStrategy.Constant(c) => (List(), List(), c) | 152 | case c: Constant => (List(), List(), c.iri) |
157 | case SkolemStrategy.ConstantRSA(c) => { | 153 | case s: Standard => { |
158 | if (unsafe.contains(prop)) | ||
159 | (List(RSA.PE(term, c), RSA.U(c)), List(), c) | ||
160 | else | ||
161 | (List(), List(), c) | ||
162 | } | ||
163 | case SkolemStrategy.Standard(f) => { | ||
164 | ( | 154 | ( |
165 | List(), | 155 | List(), |
166 | List(BindAtom.create(FunctionCall.create("SKOLEM", f, term), y)), | 156 | List( |
157 | BindAtom.create(FunctionCall.create("SKOLEM", s.literal, term), y) | ||
158 | ), | ||
167 | y | 159 | y |
168 | ) | 160 | ) |
169 | } | 161 | } |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala index 7fd4dbe..1c8374c 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala | |||
@@ -38,7 +38,7 @@ import tech.oxfordsemantic.jrdfox.logic.datalog.{ | |||
38 | } | 38 | } |
39 | import tech.oxfordsemantic.jrdfox.logic.expression.{Term, IRI, FunctionCall} | 39 | import tech.oxfordsemantic.jrdfox.logic.expression.{Term, IRI, FunctionCall} |
40 | import uk.ac.ox.cs.rsacomb.RSAOntology | 40 | import uk.ac.ox.cs.rsacomb.RSAOntology |
41 | import uk.ac.ox.cs.rsacomb.suffix.{RSASuffix, Inverse} | 41 | import uk.ac.ox.cs.rsacomb.suffix.{Empty, Inverse, RSASuffix} |
42 | import uk.ac.ox.cs.rsacomb.util.RSA | 42 | import uk.ac.ox.cs.rsacomb.util.RSA |
43 | 43 | ||
44 | /** Horn-ALCHOIQ to RDFox axiom converter. | 44 | /** Horn-ALCHOIQ to RDFox axiom converter. |
@@ -144,7 +144,7 @@ trait RDFoxConverter { | |||
144 | 144 | ||
145 | case a: OWLSubClassOfAxiom => { | 145 | case a: OWLSubClassOfAxiom => { |
146 | val (sub, _) = | 146 | val (sub, _) = |
147 | convert(a.getSubClass, term, unsafe, SkolemStrategy.None, suffix) | 147 | convert(a.getSubClass, term, unsafe, NoSkolem, suffix) |
148 | val (sup, ext) = | 148 | val (sup, ext) = |
149 | convert(a.getSuperClass, term, unsafe, skolem, suffix) | 149 | convert(a.getSuperClass, term, unsafe, skolem, suffix) |
150 | val rule = Rule.create(sup, ext ::: sub) | 150 | val rule = Rule.create(sup, ext ::: sub) |
@@ -202,7 +202,7 @@ trait RDFoxConverter { | |||
202 | case i: OWLNamedIndividual => { | 202 | case i: OWLNamedIndividual => { |
203 | val cls = a.getClassExpression | 203 | val cls = a.getClassExpression |
204 | val (res, _) = | 204 | val (res, _) = |
205 | convert(cls, i.getIRI, unsafe, SkolemStrategy.None, suffix) | 205 | convert(cls, i.getIRI, unsafe, NoSkolem, suffix) |
206 | ResultF(res) | 206 | ResultF(res) |
207 | } | 207 | } |
208 | case _ => Result() | 208 | case _ => Result() |
@@ -309,32 +309,18 @@ trait RDFoxConverter { | |||
309 | case e: OWLObjectSomeValuesFrom => { | 309 | case e: OWLObjectSomeValuesFrom => { |
310 | val cls = e.getFiller() | 310 | val cls = e.getFiller() |
311 | val role = e.getProperty() | 311 | val role = e.getProperty() |
312 | // TODO: simplify this: | 312 | val varX = RSAOntology.genFreshVariable |
313 | // Computes the result of rule skolemization. Depending on the used | 313 | val (bind, term1) = skolem match { |
314 | // technique it might involve the introduction of additional atoms, | 314 | case NoSkolem => (None, varX) |
315 | // and/or fresh constants and variables. | 315 | case c: Constant => (None, c.iri) |
316 | val (head, body, term1) = skolem match { | 316 | case s: Standard => { |
317 | case SkolemStrategy.None => | 317 | val func = FunctionCall.create("SKOLEM", s.literal, term) |
318 | (List(), List(), RSAOntology.genFreshVariable) | 318 | (Some(BindAtom.create(func, varX)), varX) |
319 | case SkolemStrategy.Constant(c) => (List(), List(), c) | ||
320 | case SkolemStrategy.ConstantRSA(c) => { | ||
321 | if (unsafe.contains(role)) | ||
322 | (List(RSA.PE(term, c), RSA.U(c)), List(), c) | ||
323 | else | ||
324 | (List(), List(), c) | ||
325 | } | ||
326 | case SkolemStrategy.Standard(f) => { | ||
327 | val x = RSAOntology.genFreshVariable | ||
328 | ( | ||
329 | List(), | ||
330 | List(BindAtom.create(FunctionCall.create("SKOLEM", f, term), x)), | ||
331 | x | ||
332 | ) | ||
333 | } | 319 | } |
334 | } | 320 | } |
335 | val (res, ext) = convert(cls, term1, unsafe, skolem, suffix) | 321 | val (res, ext) = convert(cls, term1, unsafe, skolem, suffix) |
336 | val prop = convert(role, term, term1, suffix) | 322 | val prop = convert(role, term, term1, suffix) |
337 | (prop :: head ::: res, body ::: ext) | 323 | (prop :: res, ext ++ bind) |
338 | } | 324 | } |
339 | 325 | ||
340 | /** Existential class expression (for data properties). | 326 | /** Existential class expression (for data properties). |
@@ -354,27 +340,17 @@ trait RDFoxConverter { | |||
354 | // Computes the result of rule skolemization. Depending on the used | 340 | // Computes the result of rule skolemization. Depending on the used |
355 | // technique it might involve the introduction of additional atoms, | 341 | // technique it might involve the introduction of additional atoms, |
356 | // and/or fresh constants and variables. | 342 | // and/or fresh constants and variables. |
357 | val (head, body, term1) = skolem match { | 343 | val varX = RSAOntology.genFreshVariable |
358 | case SkolemStrategy.None => | 344 | val (bind, term1) = skolem match { |
359 | (List(), List(), RSAOntology.genFreshVariable) | 345 | case NoSkolem => (None, varX) |
360 | case SkolemStrategy.Constant(c) => (List(), List(), c) | 346 | case c: Constant => (None, c.iri) |
361 | case SkolemStrategy.ConstantRSA(c) => { | 347 | case s: Standard => { |
362 | if (unsafe.contains(role)) | 348 | val func = FunctionCall.create("SKOLEM", s.literal, term) |
363 | (List(RSA.PE(term, c), RSA.U(c)), List(), c) | 349 | (Some(BindAtom.create(func, varX)), varX) |
364 | else | ||
365 | (List(), List(), c) | ||
366 | } | ||
367 | case SkolemStrategy.Standard(f) => { | ||
368 | val y = RSAOntology.genFreshVariable() | ||
369 | ( | ||
370 | List(), | ||
371 | List(BindAtom.create(FunctionCall.create("SKOLEM", f, term), y)), | ||
372 | y | ||
373 | ) | ||
374 | } | 350 | } |
375 | } | 351 | } |
376 | val prop = convert(role, term, term1, suffix) | 352 | val prop = convert(role, term, term1, suffix) |
377 | (prop :: head, body) | 353 | (List(prop), bind.toList) |
378 | } | 354 | } |
379 | 355 | ||
380 | /** Maximum cardinality restriction class | 356 | /** Maximum cardinality restriction class |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/SkolemStrategy.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/SkolemStrategy.scala index 0d72226..587db91 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/SkolemStrategy.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/SkolemStrategy.scala | |||
@@ -1,78 +1,76 @@ | |||
1 | package uk.ac.ox.cs.rsacomb.converter | 1 | package uk.ac.ox.cs.rsacomb.converter |
2 | 2 | ||
3 | import org.semanticweb.owlapi.model.OWLAxiom | ||
3 | import tech.oxfordsemantic.jrdfox.logic.Datatype | 4 | import tech.oxfordsemantic.jrdfox.logic.Datatype |
4 | import tech.oxfordsemantic.jrdfox.logic.expression.{Literal, IRI} | 5 | import tech.oxfordsemantic.jrdfox.logic.expression.{Literal, IRI} |
5 | 6 | ||
6 | sealed trait SkolemStrategy | 7 | sealed trait SkolemStrategy |
7 | 8 | ||
8 | object SkolemStrategy { | 9 | /** No skolemization. |
9 | // TODO: might want to use something else other than `hashCode` as a | 10 | * |
10 | // function to generate a fresh function/constant | 11 | * @example role `R` from |
12 | * {{{ | ||
13 | * ∃R.A ⊑ B | ||
14 | * }}} | ||
15 | * to | ||
16 | * {{{ | ||
17 | * R(x,y), B(y) -> B(x) | ||
18 | * }}} | ||
19 | */ | ||
20 | case object NoSkolem extends SkolemStrategy | ||
11 | 21 | ||
12 | /* No skolemization at all. | 22 | /** Functional skolemization |
13 | * | 23 | * |
14 | * From | 24 | * The factory object should be used to create new instances of the |
15 | * ∃R.A ⊑ B | 25 | * class. |
16 | * to | 26 | * |
17 | * R(x,y), B(y) -> B(x) | 27 | * @example role `R` from |
18 | */ | 28 | * {{{ |
19 | case object None extends SkolemStrategy | 29 | * A ⊑ ∃R.B |
20 | 30 | * }}} | |
21 | /* Functional skolemization | 31 | * to |
22 | * | 32 | * {{{ |
23 | * From | 33 | * A(x) -> R(x,f(x)), B(f(x)) |
24 | * A ⊑ ∃R.B | 34 | * }}} |
25 | * to | 35 | * for `f`, fresh function uniquely associated with the input axiom. |
26 | * A(x) -> R(x,f(x)), B(f(x)) | 36 | * |
27 | * for f, fresh function associated with the input axiom | 37 | * RDFox does not support function symbols. We can still implement |
28 | * | 38 | * function symbols combining the `BIND` operator with the `SKOLEM` |
29 | * In RDFox this can represented combining the BIND operator with the | 39 | * operator as such: |
30 | * SKOLEM operator as such: | 40 | * {{{ |
31 | * A(x), BIND(y, SKOLEM("f", x)) -> R(x,y), B(y) | 41 | * A(x), BIND(y, SKOLEM("f", x)) -> R(x,y), B(y) |
32 | * The first argument of a SKOLEM call is a literal string (ideally | 42 | * }}} |
33 | * identifing the simulated function name). | 43 | * The first argument of a `SKOLEM` call '''must''' be a literal string |
34 | * | 44 | * (ideally identifing the simulated function name). |
35 | * NOTE: this requirement for the SKOLEM operator is not enforced by | 45 | * |
36 | * RDFox, that will fail silently if omitted. | 46 | * @note this requirement is not enforced by RDFox, that will fail |
37 | */ | 47 | * silently if a string argument is omitted. |
38 | case class Standard(func: Literal) extends SkolemStrategy | 48 | */ |
39 | object Standard { | 49 | class Standard(var axiom: OWLAxiom)(implicit toString: (OWLAxiom) => String) |
40 | def apply(axiom: String) = | 50 | extends SkolemStrategy { |
41 | new Standard( | 51 | def dup(a: OWLAxiom) = new Standard(a)(toString) |
42 | Literal.create(genFunctionString(axiom), Datatype.XSD_STRING) | 52 | lazy val literal = |
43 | ) | 53 | Literal.create(s"f_${toString(axiom)}", Datatype.XSD_STRING) |
44 | def genFunctionString(str: String) = "f_" ++ str.hashCode.toString | 54 | } |
45 | } | ||
46 | |||
47 | /* Constant skolemization | ||
48 | * | ||
49 | * From | ||
50 | * A ⊑ ∃R.B | ||
51 | * to | ||
52 | * A(y) -> R(x,c), B(c) | ||
53 | * for c, fresh constant associated with the input axiom | ||
54 | */ | ||
55 | case class Constant(const: IRI) extends SkolemStrategy | ||
56 | object Constant { | ||
57 | def apply(axiom: String) = | ||
58 | new Constant(IRI.create(genConstantString(axiom))) | ||
59 | def genConstantString(str: String) = "c_" ++ str.hashCode.toString | ||
60 | } | ||
61 | 55 | ||
62 | /* (RSA) Constant skolemization | 56 | /** Constant skolemization |
63 | * This is a special skolemization option to introduce additional atoms for RSA | 57 | * |
64 | * checking algorithm. | 58 | * The factory object should be used to create new instances of the |
65 | * | 59 | * class. |
66 | * From | 60 | * |
67 | * A ⊑ ∃R.B | 61 | * @example role `R` from |
68 | * to | 62 | * {{{ |
69 | * A(y) -> R(x,c), PE(x,c), B(c) | 63 | * A ⊑ ∃R.B |
70 | * for c, fresh constant associated with the input axiom and PE an internal predicate. | 64 | * }}} |
71 | */ | 65 | * to |
72 | case class ConstantRSA(const: IRI) extends SkolemStrategy | 66 | * {{{ |
73 | object ConstantRSA { | 67 | * A(y) -> R(x,c), B(c) |
74 | def apply(axiom: String) = | 68 | * }}} |
75 | new ConstantRSA(IRI.create(genConstantString(axiom))) | 69 | * for `c`, fresh constant '''uniquely''' associated with the input |
76 | def genConstantString(str: String) = "c_" ++ str.hashCode.toString | 70 | * axiom |
77 | } | 71 | */ |
72 | class Constant(var axiom: OWLAxiom)(implicit toString: (OWLAxiom) => String) | ||
73 | extends SkolemStrategy { | ||
74 | def dup(a: OWLAxiom) = new Constant(a)(toString) | ||
75 | lazy val iri = IRI.create(s"c_${toString(axiom)}") | ||
78 | } | 76 | } |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/package.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/package.scala new file mode 100644 index 0000000..0484153 --- /dev/null +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/package.scala | |||
@@ -0,0 +1,9 @@ | |||
1 | package uk.ac.ox.cs.rsacomb | ||
2 | package object converter { | ||
3 | |||
4 | import org.semanticweb.owlapi.model.OWLAxiom | ||
5 | |||
6 | implicit def axiomToHashedString(axiom: OWLAxiom): String = | ||
7 | s"${axiom.toString.hashCode}" | ||
8 | |||
9 | } | ||
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 | |||
15 | import scala.collection.JavaConverters._ | 15 | import scala.collection.JavaConverters._ |
16 | 16 | ||
17 | import uk.ac.ox.cs.rsacomb.RSAOntology | 17 | import uk.ac.ox.cs.rsacomb.RSAOntology |
18 | import uk.ac.ox.cs.rsacomb.converter.SkolemStrategy | 18 | import uk.ac.ox.cs.rsacomb.converter.{SkolemStrategy, NoSkolem} |
19 | import uk.ac.ox.cs.rsacomb.suffix.Empty | 19 | import uk.ac.ox.cs.rsacomb.suffix.Empty |
20 | import uk.ac.ox.cs.rsacomb.util.{RDFoxUtil, RSA} | 20 | import uk.ac.ox.cs.rsacomb.util.{RDFoxUtil, RSA} |
21 | 21 | ||
@@ -94,10 +94,8 @@ class Ontology1_CanonicalModelSpec | |||
94 | renderer.render(AsubClassOfD) should "be converted into a single Rule" in { | 94 | renderer.render(AsubClassOfD) should "be converted into a single Rule" in { |
95 | val term = Variable.create("X") | 95 | val term = Variable.create("X") |
96 | val unsafe = ontology.unsafeRoles | 96 | val unsafe = ontology.unsafeRoles |
97 | val skolem = SkolemStrategy.None | ||
98 | val suffix = Empty | ||
99 | val (facts, rules) = | 97 | val (facts, rules) = |
100 | converter.convert(AsubClassOfD, term, unsafe, skolem, suffix) | 98 | converter.convert(AsubClassOfD, term, unsafe, NoSkolem, Empty) |
101 | facts shouldBe empty | 99 | facts shouldBe empty |
102 | rules.loneElement shouldBe a[Rule] | 100 | rules.loneElement shouldBe a[Rule] |
103 | } | 101 | } |
@@ -163,10 +161,8 @@ class Ontology1_CanonicalModelSpec | |||
163 | ) should "produce 1 rule" in { | 161 | ) should "produce 1 rule" in { |
164 | val term = Variable.create("X") | 162 | val term = Variable.create("X") |
165 | val unsafe = ontology.unsafeRoles | 163 | val unsafe = ontology.unsafeRoles |
166 | val skolem = SkolemStrategy.None | ||
167 | val suffix = Empty | ||
168 | val (facts, rules) = | 164 | val (facts, rules) = |
169 | converter.convert(AsomeValuesFromSiC, term, unsafe, skolem, suffix) | 165 | converter.convert(AsomeValuesFromSiC, term, unsafe, NoSkolem, Empty) |
170 | facts shouldBe empty | 166 | facts shouldBe empty |
171 | rules.loneElement shouldBe a[Rule] | 167 | rules.loneElement shouldBe a[Rule] |
172 | } | 168 | } |
@@ -189,10 +185,8 @@ class Ontology1_CanonicalModelSpec | |||
189 | // Rule 3 provides 48 rule (split in 2) | 185 | // Rule 3 provides 48 rule (split in 2) |
190 | val term = Variable.create("X") | 186 | val term = Variable.create("X") |
191 | val unsafe = ontology.unsafeRoles | 187 | val unsafe = ontology.unsafeRoles |
192 | val skolem = SkolemStrategy.None | ||
193 | val suffix = Empty | ||
194 | val (facts, rules) = | 188 | val (facts, rules) = |
195 | converter.convert(DsomeValuesFromRB, term, unsafe, skolem, suffix) | 189 | converter.convert(DsomeValuesFromRB, term, unsafe, NoSkolem, Empty) |
196 | facts should have length 48 | 190 | facts should have length 48 |
197 | rules should have length 98 | 191 | rules should have length 98 |
198 | } | 192 | } |
@@ -216,10 +210,8 @@ class Ontology1_CanonicalModelSpec | |||
216 | // Then (1*2 + 32) + (0) + (32*2) = 98 | 210 | // Then (1*2 + 32) + (0) + (32*2) = 98 |
217 | val term = Variable.create("X") | 211 | val term = Variable.create("X") |
218 | val unsafe = ontology.unsafeRoles | 212 | val unsafe = ontology.unsafeRoles |
219 | val skolem = SkolemStrategy.None | ||
220 | val suffix = Empty | ||
221 | val (facts, rules) = | 213 | val (facts, rules) = |
222 | converter.convert(BsomeValuesFromSD, term, unsafe, skolem, suffix) | 214 | converter.convert(BsomeValuesFromSD, term, unsafe, NoSkolem, Empty) |
223 | facts should have length 32 | 215 | facts should have length 32 |
224 | rules should have length 66 | 216 | rules should have length 66 |
225 | } | 217 | } |
@@ -229,10 +221,8 @@ class Ontology1_CanonicalModelSpec | |||
229 | ) should "produce 2 rules" in { | 221 | ) should "produce 2 rules" in { |
230 | val term = Variable.create("X") | 222 | val term = Variable.create("X") |
231 | val unsafe = ontology.unsafeRoles | 223 | val unsafe = ontology.unsafeRoles |
232 | val skolem = SkolemStrategy.None | ||
233 | val suffix = Empty | ||
234 | val (facts, rules) = | 224 | val (facts, rules) = |
235 | converter.convert(SsubPropertyOfT, term, unsafe, skolem, suffix) | 225 | converter.convert(SsubPropertyOfT, term, unsafe, NoSkolem, Empty) |
236 | facts shouldBe empty | 226 | facts shouldBe empty |
237 | rules should have length 2 | 227 | rules should have length 2 |
238 | } | 228 | } |
@@ -357,10 +347,8 @@ class Ontology2_CanonicalModelSpec | |||
357 | ) should "produce 1 rule" in { | 347 | ) should "produce 1 rule" in { |
358 | val term = Variable.create("X") | 348 | val term = Variable.create("X") |
359 | val unsafe = ontology.unsafeRoles | 349 | val unsafe = ontology.unsafeRoles |
360 | val skolem = SkolemStrategy.None | ||
361 | val suffix = Empty | ||
362 | val (facts, rules) = | 350 | val (facts, rules) = |
363 | converter.convert(AsomeValuesFromRB, term, unsafe, skolem, suffix) | 351 | converter.convert(AsomeValuesFromRB, term, unsafe, NoSkolem, Empty) |
364 | facts shouldBe empty | 352 | facts shouldBe empty |
365 | rules should have length 1 | 353 | rules should have length 1 |
366 | } | 354 | } |
@@ -372,10 +360,8 @@ class Ontology2_CanonicalModelSpec | |||
372 | ) should "produce 1 rule" in { | 360 | ) should "produce 1 rule" in { |
373 | val term = Variable.create("X") | 361 | val term = Variable.create("X") |
374 | val unsafe = ontology.unsafeRoles | 362 | val unsafe = ontology.unsafeRoles |
375 | val skolem = SkolemStrategy.None | ||
376 | val suffix = Empty | ||
377 | val (facts, rules) = | 363 | val (facts, rules) = |
378 | converter.convert(BsomeValuesFromSC, term, unsafe, skolem, suffix) | 364 | converter.convert(BsomeValuesFromSC, term, unsafe, NoSkolem, Empty) |
379 | facts shouldBe empty | 365 | facts shouldBe empty |
380 | rules should have length 1 | 366 | rules should have length 1 |
381 | } | 367 | } |
@@ -387,10 +373,8 @@ class Ontology2_CanonicalModelSpec | |||
387 | ) should "produce 1 rule" in { | 373 | ) should "produce 1 rule" in { |
388 | val term = Variable.create("X") | 374 | val term = Variable.create("X") |
389 | val unsafe = ontology.unsafeRoles | 375 | val unsafe = ontology.unsafeRoles |
390 | val skolem = SkolemStrategy.None | ||
391 | val suffix = Empty | ||
392 | val (facts, rules) = | 376 | val (facts, rules) = |
393 | converter.convert(CsomeValuesFromTD, term, unsafe, skolem, suffix) | 377 | converter.convert(CsomeValuesFromTD, term, unsafe, NoSkolem, Empty) |
394 | facts shouldBe empty | 378 | facts shouldBe empty |
395 | rules should have length 1 | 379 | rules should have length 1 |
396 | } | 380 | } |
@@ -402,10 +386,8 @@ class Ontology2_CanonicalModelSpec | |||
402 | ) should "produce 1 rule" in { | 386 | ) should "produce 1 rule" in { |
403 | val term = Variable.create("X") | 387 | val term = Variable.create("X") |
404 | val unsafe = ontology.unsafeRoles | 388 | val unsafe = ontology.unsafeRoles |
405 | val skolem = SkolemStrategy.None | ||
406 | val suffix = Empty | ||
407 | val (facts, rules) = | 389 | val (facts, rules) = |
408 | converter.convert(DsomeValuesFromPA, term, unsafe, skolem, suffix) | 390 | converter.convert(DsomeValuesFromPA, term, unsafe, NoSkolem, Empty) |
409 | facts shouldBe empty | 391 | facts shouldBe empty |
410 | rules should have length 1 | 392 | rules should have length 1 |
411 | } | 393 | } |
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.{ | |||
36 | import org.semanticweb.owlapi.model.{IRI => OWLIRI} | 36 | import org.semanticweb.owlapi.model.{IRI => OWLIRI} |
37 | import tech.oxfordsemantic.jrdfox.logic.expression.{IRI => RDFIRI} | 37 | import tech.oxfordsemantic.jrdfox.logic.expression.{IRI => RDFIRI} |
38 | 38 | ||
39 | import uk.ac.ox.cs.rsacomb.converter.{RDFoxAxiomConverter, SkolemStrategy} | 39 | import uk.ac.ox.cs.rsacomb.converter.{ |
40 | RDFoxAxiomConverter, | ||
41 | SkolemStrategy, | ||
42 | NoSkolem, | ||
43 | Standard, | ||
44 | Constant | ||
45 | } | ||
40 | import uk.ac.ox.cs.rsacomb.util.RSA | 46 | import uk.ac.ox.cs.rsacomb.util.RSA |
41 | 47 | ||
42 | object OWLAxiomSpec { | 48 | object OWLAxiomSpec { |
@@ -172,7 +178,7 @@ object OWLAxiomSpec { | |||
172 | def convertAxiom( | 178 | def convertAxiom( |
173 | axiom: OWLAxiom, | 179 | axiom: OWLAxiom, |
174 | term: Term, | 180 | term: Term, |
175 | skolem: SkolemStrategy = SkolemStrategy.None | 181 | skolem: SkolemStrategy = NoSkolem |
176 | ): List[Rule] = { | 182 | ): List[Rule] = { |
177 | axiom.accept(RDFoxAxiomConverter(term, List())) | 183 | axiom.accept(RDFoxAxiomConverter(term, List())) |
178 | } | 184 | } |
@@ -210,13 +216,13 @@ class OWLAxiomSpec extends AnyFlatSpec with Matchers with LoneElement { | |||
210 | // OWLSubClassOfAxiom #2 (w/ constant skolemization) | 216 | // OWLSubClassOfAxiom #2 (w/ constant skolemization) |
211 | (axiom_OWLSubClassOf2.toString + "\n(w/ constant skolemization)") should | 217 | (axiom_OWLSubClassOf2.toString + "\n(w/ constant skolemization)") should |
212 | "be converted into a singleton List[Rule]" in { | 218 | "be converted into a singleton List[Rule]" in { |
213 | val skolem = SkolemStrategy.Constant(axiom_OWLSubClassOf2.toString) | 219 | val skolem = Constant(axiom_OWLSubClassOf2.toString) |
214 | val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) | 220 | val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) |
215 | result.loneElement shouldBe a[Rule] | 221 | result.loneElement shouldBe a[Rule] |
216 | } | 222 | } |
217 | 223 | ||
218 | it should "contain a single atom (Student[?x]) in the body of the rule" in { | 224 | it should "contain a single atom (Student[?x]) in the body of the rule" in { |
219 | val skolem = SkolemStrategy.Constant(axiom_OWLSubClassOf2.toString) | 225 | val skolem = Constant(axiom_OWLSubClassOf2.toString) |
220 | val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) | 226 | val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) |
221 | val body = | 227 | val body = |
222 | TupleTableAtom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student.getIRIString) | 228 | TupleTableAtom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student.getIRIString) |
@@ -237,13 +243,13 @@ class OWLAxiomSpec extends AnyFlatSpec with Matchers with LoneElement { | |||
237 | // OWLSubClassOfAxiom #2 (w/ skolemization) | 243 | // OWLSubClassOfAxiom #2 (w/ skolemization) |
238 | (axiom_OWLSubClassOf2.toString + "\n(w/ skolemization)") should | 244 | (axiom_OWLSubClassOf2.toString + "\n(w/ skolemization)") should |
239 | "be converted into a singleton List[Rule]" in { | 245 | "be converted into a singleton List[Rule]" in { |
240 | val skolem = SkolemStrategy.Standard(axiom_OWLSubClassOf2.toString) | 246 | val skolem = Standard(axiom_OWLSubClassOf2.toString) |
241 | val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) | 247 | val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) |
242 | result.loneElement shouldBe a[Rule] | 248 | result.loneElement shouldBe a[Rule] |
243 | } | 249 | } |
244 | 250 | ||
245 | it should "contain an atom (Student[?x]) in the body of the rule" in { | 251 | it should "contain an atom (Student[?x]) in the body of the rule" in { |
246 | val skolem = SkolemStrategy.Standard(axiom_OWLSubClassOf2.toString) | 252 | val skolem = Standard(axiom_OWLSubClassOf2.toString) |
247 | val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) | 253 | val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) |
248 | val body = | 254 | val body = |
249 | TupleTableAtom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student) | 255 | 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.{ | |||
36 | import uk.ac.ox.cs.rsacomb.converter.{ | 36 | import uk.ac.ox.cs.rsacomb.converter.{ |
37 | RDFoxRuleShards, | 37 | RDFoxRuleShards, |
38 | RDFoxClassExprConverter, | 38 | RDFoxClassExprConverter, |
39 | SkolemStrategy | 39 | SkolemStrategy, |
40 | Standard, | ||
41 | Constant | ||
40 | } | 42 | } |
41 | import uk.ac.ox.cs.rsacomb.util.RSA | 43 | import uk.ac.ox.cs.rsacomb.util.RSA |
42 | 44 | ||
@@ -179,16 +181,16 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { | |||
179 | // OWLObjectSomeValuesFrom | 181 | // OWLObjectSomeValuesFrom |
180 | (class_OWLObjectSomeValuesFrom.toString ++ " w/o skolemization") should | 182 | (class_OWLObjectSomeValuesFrom.toString ++ " w/o skolemization") should |
181 | "be converted into a RDFoxRuleShards" in { | 183 | "be converted into a RDFoxRuleShards" in { |
182 | val visitor = RDFoxClassExprConverter(term_x) | 184 | val visitor = RDFoxClassExprConverter(term_x) |
183 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 185 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
184 | result shouldBe a[RDFoxRuleShards] | 186 | result shouldBe a[RDFoxRuleShards] |
185 | } | 187 | } |
186 | 188 | ||
187 | it should "have two TupleTableAtoms in its result list" in { | 189 | it should "have two TupleTableAtoms in its result list" in { |
188 | val visitor = RDFoxClassExprConverter(term_x) | 190 | val visitor = RDFoxClassExprConverter(term_x) |
189 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 191 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
190 | exactly(2, result.res) should (be(an[TupleTableAtom]) | 192 | exactly(2, result.res) should (be(an[TupleTableAtom]) |
191 | //and have('numberOfArguments (3)) | 193 | //and have('numberOfArguments (3)) |
192 | ) | 194 | ) |
193 | } | 195 | } |
194 | 196 | ||
@@ -200,23 +202,23 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { | |||
200 | 202 | ||
201 | (class_OWLObjectSomeValuesFrom.toString ++ " w/ skolemization") should | 203 | (class_OWLObjectSomeValuesFrom.toString ++ " w/ skolemization") should |
202 | "be converted into a RDFoxRuleShards" in { | 204 | "be converted into a RDFoxRuleShards" in { |
203 | val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString) | 205 | val skolem = Standard(class_OWLObjectSomeValuesFrom.toString) |
204 | val visitor = RDFoxClassExprConverter(term_x, List(), skolem) | 206 | val visitor = RDFoxClassExprConverter(term_x, List(), skolem) |
205 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 207 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
206 | result shouldBe a[RDFoxRuleShards] | 208 | result shouldBe a[RDFoxRuleShards] |
207 | } | 209 | } |
208 | 210 | ||
209 | it should "have exactly two TupleTableAtoms in its result list" in { | 211 | it should "have exactly two TupleTableAtoms in its result list" in { |
210 | val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString) | 212 | val skolem = Standard(class_OWLObjectSomeValuesFrom.toString) |
211 | val visitor = RDFoxClassExprConverter(term_x, List(), skolem) | 213 | val visitor = RDFoxClassExprConverter(term_x, List(), skolem) |
212 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 214 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
213 | exactly(2, result.res) should (be(an[TupleTableAtom]) | 215 | exactly(2, result.res) should (be(an[TupleTableAtom]) |
214 | //and have('numberOfArguments (3)) | 216 | //and have('numberOfArguments (3)) |
215 | ) | 217 | ) |
216 | } | 218 | } |
217 | 219 | ||
218 | it should "should have a single SKOLEM call in the extension list" in { | 220 | it should "should have a single SKOLEM call in the extension list" in { |
219 | val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString) | 221 | val skolem = Standard(class_OWLObjectSomeValuesFrom.toString) |
220 | val visitor = RDFoxClassExprConverter(term_x, List(), skolem) | 222 | val visitor = RDFoxClassExprConverter(term_x, List(), skolem) |
221 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 223 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
222 | result.ext.loneElement shouldBe a[BindAtom] | 224 | result.ext.loneElement shouldBe a[BindAtom] |
@@ -228,23 +230,23 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { | |||
228 | 230 | ||
229 | (class_OWLObjectSomeValuesFrom.toString ++ " w/ constant skolemization") should | 231 | (class_OWLObjectSomeValuesFrom.toString ++ " w/ constant skolemization") should |
230 | "be converted into a RDFoxRuleShards" in { | 232 | "be converted into a RDFoxRuleShards" in { |
231 | val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString) | 233 | val skolem = Constant(class_OWLObjectSomeValuesFrom.toString) |
232 | val visitor = RDFoxClassExprConverter(term_x, List(), skolem) | 234 | val visitor = RDFoxClassExprConverter(term_x, List(), skolem) |
233 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 235 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
234 | result shouldBe a[RDFoxRuleShards] | 236 | result shouldBe a[RDFoxRuleShards] |
235 | } | 237 | } |
236 | 238 | ||
237 | it should "have exactly two TupleTableAtoms in its result list" in { | 239 | it should "have exactly two TupleTableAtoms in its result list" in { |
238 | val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString) | 240 | val skolem = Constant(class_OWLObjectSomeValuesFrom.toString) |
239 | val visitor = RDFoxClassExprConverter(term_x, List(), skolem) | 241 | val visitor = RDFoxClassExprConverter(term_x, List(), skolem) |
240 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 242 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
241 | exactly(2, result.res) should (be(an[TupleTableAtom]) | 243 | exactly(2, result.res) should (be(an[TupleTableAtom]) |
242 | //and have('numberOfArguments (3)) | 244 | //and have('numberOfArguments (3)) |
243 | ) | 245 | ) |
244 | } | 246 | } |
245 | 247 | ||
246 | it should "have an empty extension list" in { | 248 | it should "have an empty extension list" in { |
247 | val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString) | 249 | val skolem = Constant(class_OWLObjectSomeValuesFrom.toString) |
248 | val visitor = RDFoxClassExprConverter(term_x, List(), skolem) | 250 | val visitor = RDFoxClassExprConverter(term_x, List(), skolem) |
249 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) | 251 | val result = class_OWLObjectSomeValuesFrom.accept(visitor) |
250 | result.ext shouldBe empty | 252 | result.ext shouldBe empty |
@@ -253,10 +255,10 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { | |||
253 | // OWLObjectMaxCardinalityImpl | 255 | // OWLObjectMaxCardinalityImpl |
254 | class_OWLObjectMaxCardinality.toString should | 256 | class_OWLObjectMaxCardinality.toString should |
255 | "be converted into a RDFoxRuleShards" in { | 257 | "be converted into a RDFoxRuleShards" in { |
256 | val visitor = RDFoxClassExprConverter(term_x) | 258 | val visitor = RDFoxClassExprConverter(term_x) |
257 | val result = class_OWLObjectMaxCardinality.accept(visitor) | 259 | val result = class_OWLObjectMaxCardinality.accept(visitor) |
258 | result shouldBe a[RDFoxRuleShards] | 260 | result shouldBe a[RDFoxRuleShards] |
259 | } | 261 | } |
260 | 262 | ||
261 | // it should "have a single <owl:sameAs> TupleTableAtom in the result list" in { | 263 | // it should "have a single <owl:sameAs> TupleTableAtom in the result list" in { |
262 | // val visitor = RDFoxClassExprConverter(term_x) | 264 | // val visitor = RDFoxClassExprConverter(term_x) |
@@ -270,7 +272,7 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { | |||
270 | val visitor = RDFoxClassExprConverter(term_x) | 272 | val visitor = RDFoxClassExprConverter(term_x) |
271 | val result = class_OWLObjectMaxCardinality.accept(visitor) | 273 | val result = class_OWLObjectMaxCardinality.accept(visitor) |
272 | exactly(4, result.ext) should (be(an[TupleTableAtom]) | 274 | exactly(4, result.ext) should (be(an[TupleTableAtom]) |
273 | //and have('numberOfArguments (3)) | 275 | //and have('numberOfArguments (3)) |
274 | ) | 276 | ) |
275 | } | 277 | } |
276 | 278 | ||
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 | |||
10 | import tech.oxfordsemantic.jrdfox.logic.expression.{Variable, IRI} | 10 | import tech.oxfordsemantic.jrdfox.logic.expression.{Variable, IRI} |
11 | import uk.ac.ox.cs.rsacomb.converter.RDFoxConverter | 11 | import uk.ac.ox.cs.rsacomb.converter.RDFoxConverter |
12 | import uk.ac.ox.cs.rsacomb.suffix.{Empty, Forward, Backward, Inverse} | 12 | import uk.ac.ox.cs.rsacomb.suffix.{Empty, Forward, Backward, Inverse} |
13 | import uk.ac.ox.cs.rsacomb.converter.SkolemStrategy | 13 | import uk.ac.ox.cs.rsacomb.converter.{SkolemStrategy, NoSkolem} |
14 | 14 | ||
15 | object RDFoxConverterSpec { | 15 | object RDFoxConverterSpec { |
16 | 16 | ||
@@ -44,7 +44,7 @@ class RDFoxConverterSpec | |||
44 | val cls = factory.getOWLClass(iriString0) | 44 | val cls = factory.getOWLClass(iriString0) |
45 | val atom = TupleTableAtom.rdf(term0, IRI.RDF_TYPE, IRI.create(iriString0)) | 45 | val atom = TupleTableAtom.rdf(term0, IRI.RDF_TYPE, IRI.create(iriString0)) |
46 | val (res, ext) = | 46 | val (res, ext) = |
47 | convert(cls, term0, List(), SkolemStrategy.None, Empty) | 47 | convert(cls, term0, List(), NoSkolem, Empty) |
48 | res.loneElement shouldEqual atom | 48 | res.loneElement shouldEqual atom |
49 | ext shouldBe empty | 49 | ext shouldBe empty |
50 | } | 50 | } |
@@ -55,13 +55,13 @@ class RDFoxConverterSpec | |||
55 | val cls2 = factory.getOWLClass(iriString2) | 55 | val cls2 = factory.getOWLClass(iriString2) |
56 | val conj = factory.getOWLObjectIntersectionOf(cls0, cls1, cls2) | 56 | val conj = factory.getOWLObjectIntersectionOf(cls0, cls1, cls2) |
57 | val (res0, ext0) = | 57 | val (res0, ext0) = |
58 | convert(cls0, term0, List(), SkolemStrategy.None, Empty) | 58 | convert(cls0, term0, List(), NoSkolem, Empty) |
59 | val (res1, ext1) = | 59 | val (res1, ext1) = |
60 | convert(cls1, term0, List(), SkolemStrategy.None, Empty) | 60 | convert(cls1, term0, List(), NoSkolem, Empty) |
61 | val (res2, ext2) = | 61 | val (res2, ext2) = |
62 | convert(cls2, term0, List(), SkolemStrategy.None, Empty) | 62 | convert(cls2, term0, List(), NoSkolem, Empty) |
63 | val (res, ext) = | 63 | val (res, ext) = |
64 | convert(conj, term0, List(), SkolemStrategy.None, Empty) | 64 | convert(conj, term0, List(), NoSkolem, Empty) |
65 | res should contain theSameElementsAs (res0 ::: res1 ::: res2) | 65 | res should contain theSameElementsAs (res0 ::: res1 ::: res2) |
66 | ext should contain theSameElementsAs (ext0 ::: ext1 ::: ext2) | 66 | ext should contain theSameElementsAs (ext0 ::: ext1 ::: ext2) |
67 | } | 67 | } |
@@ -70,9 +70,9 @@ class RDFoxConverterSpec | |||
70 | val cls0 = factory.getOWLClass(iriString0) | 70 | val cls0 = factory.getOWLClass(iriString0) |
71 | val conj = factory.getOWLObjectIntersectionOf(cls0) | 71 | val conj = factory.getOWLObjectIntersectionOf(cls0) |
72 | val (res0, ext0) = | 72 | val (res0, ext0) = |
73 | convert(cls0, term0, List(), SkolemStrategy.None, Empty) | 73 | convert(cls0, term0, List(), NoSkolem, Empty) |
74 | val (res, ext) = | 74 | val (res, ext) = |
75 | convert(conj, term0, List(), SkolemStrategy.None, Empty) | 75 | convert(conj, term0, List(), NoSkolem, Empty) |
76 | res should contain theSameElementsAs res0 | 76 | res should contain theSameElementsAs res0 |
77 | ext should contain theSameElementsAs ext0 | 77 | ext should contain theSameElementsAs ext0 |
78 | } | 78 | } |