aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2022-05-19 15:03:05 +0100
committerFederico Igne <federico.igne@cs.ox.ac.uk>2022-05-19 15:21:29 +0100
commit41e3b3b42e4dc891aaf5fca9f87e9c9cb9325011 (patch)
tree285398907f2bfc2b9cf6b319248047eed4b13bab
parent24fd3ba575e4857eead4fc33d728a2938746d7ef (diff)
downloadRSAComb-41e3b3b42e4dc891aaf5fca9f87e9c9cb9325011.tar.gz
RSAComb-41e3b3b42e4dc891aaf5fca9f87e9c9cb9325011.zip
refactor: move RSAOntology class under ontology package
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/CanonicalModel.scala1
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala2
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/approximation/Upperbound.scala2
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/converter/Normalizer.scala2
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala2
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/implicits/RSAAtom.scala2
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/ontology/RSAOntology.scala (renamed from src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala)158
-rw-r--r--src/test/scala/uk/ac/ox/cs/rsacomb/CanonicalModelSpec.scala2
8 files changed, 23 insertions, 148 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 bd3d3c3..37b80ef 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/CanonicalModel.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/CanonicalModel.scala
@@ -39,6 +39,7 @@ import tech.oxfordsemantic.jrdfox.logic.expression.{IRI, Term, Variable}
39import implicits.JavaCollections._ 39import implicits.JavaCollections._
40 40
41import uk.ac.ox.cs.rsacomb.converter._ 41import uk.ac.ox.cs.rsacomb.converter._
42import uk.ac.ox.cs.rsacomb.ontology.RSAOntology
42import uk.ac.ox.cs.rsacomb.suffix._ 43import uk.ac.ox.cs.rsacomb.suffix._
43import uk.ac.ox.cs.rsacomb.util.{DataFactory, RSA} 44import uk.ac.ox.cs.rsacomb.util.{DataFactory, RSA}
44 45
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
index 21b4cd2..8784651 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
@@ -18,7 +18,7 @@ package uk.ac.ox.cs.rsacomb
18 18
19import approximation.{Lowerbound,Upperbound} 19import approximation.{Lowerbound,Upperbound}
20import converter.Normalizer 20import converter.Normalizer
21import ontology.Ontology 21import ontology.{Ontology,RSAOntology}
22import util.{Logger, RDFoxUtil, RSA} 22import util.{Logger, RDFoxUtil, RSA}
23 23
24object RSAComb extends App { 24object RSAComb extends App {
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/approximation/Upperbound.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/approximation/Upperbound.scala
index 469d774..2c3bdc4 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/approximation/Upperbound.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/approximation/Upperbound.scala
@@ -12,7 +12,7 @@ import scalax.collection.Graph
12import scalax.collection.GraphPredef._, scalax.collection.GraphEdge._ 12import scalax.collection.GraphPredef._, scalax.collection.GraphEdge._
13import scalax.collection.GraphTraversal._ 13import scalax.collection.GraphTraversal._
14 14
15import uk.ac.ox.cs.rsacomb.RSAOntology 15import uk.ac.ox.cs.rsacomb.ontology.RSAOntology
16import uk.ac.ox.cs.rsacomb.ontology.Ontology 16import uk.ac.ox.cs.rsacomb.ontology.Ontology
17import uk.ac.ox.cs.rsacomb.util.DataFactory 17import uk.ac.ox.cs.rsacomb.util.DataFactory
18 18
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/Normalizer.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/Normalizer.scala
index 98e4dd0..c8d0628 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/Normalizer.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/Normalizer.scala
@@ -20,7 +20,7 @@ import org.semanticweb.owlapi.apibinding.OWLManager
20import org.semanticweb.owlapi.model._ 20import org.semanticweb.owlapi.model._
21 21
22import uk.ac.ox.cs.rsacomb.util.{Logger, DataFactory} 22import uk.ac.ox.cs.rsacomb.util.{Logger, DataFactory}
23import uk.ac.ox.cs.rsacomb.RSAOntology 23import uk.ac.ox.cs.rsacomb.ontology.RSAOntology
24 24
25object Normalizer { 25object Normalizer {
26 26
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 d9f000d..2d0fa3f 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
@@ -28,7 +28,7 @@ import tech.oxfordsemantic.jrdfox.logic.datalog.{
28 TupleTableName 28 TupleTableName
29} 29}
30import tech.oxfordsemantic.jrdfox.logic.expression.{Term, IRI, FunctionCall} 30import tech.oxfordsemantic.jrdfox.logic.expression.{Term, IRI, FunctionCall}
31import uk.ac.ox.cs.rsacomb.RSAOntology 31import uk.ac.ox.cs.rsacomb.ontology.RSAOntology
32import uk.ac.ox.cs.rsacomb.suffix.{Empty, Inverse, RSASuffix} 32import uk.ac.ox.cs.rsacomb.suffix.{Empty, Inverse, RSASuffix}
33import uk.ac.ox.cs.rsacomb.util.{DataFactory, RSA, RDFoxUtil} 33import uk.ac.ox.cs.rsacomb.util.{DataFactory, RSA, RDFoxUtil}
34 34
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/implicits/RSAAtom.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/implicits/RSAAtom.scala
index 89777c4..5c2684e 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/implicits/RSAAtom.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/implicits/RSAAtom.scala
@@ -25,7 +25,7 @@ import tech.oxfordsemantic.jrdfox.logic.datalog.{
25} 25}
26import tech.oxfordsemantic.jrdfox.logic.expression.{IRI} 26import tech.oxfordsemantic.jrdfox.logic.expression.{IRI}
27 27
28import uk.ac.ox.cs.rsacomb.RSAOntology 28import uk.ac.ox.cs.rsacomb.ontology.RSAOntology
29import uk.ac.ox.cs.rsacomb.suffix.{RSASuffix, Nth} 29import uk.ac.ox.cs.rsacomb.suffix.{RSASuffix, Nth}
30import uk.ac.ox.cs.rsacomb.util.{DataFactory, RDFoxUtil} 30import uk.ac.ox.cs.rsacomb.util.{DataFactory, RDFoxUtil}
31 31
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/ontology/RSAOntology.scala
index 3fec7bc..f544b4b 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/ontology/RSAOntology.scala
@@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17package uk.ac.ox.cs.rsacomb 17package uk.ac.ox.cs.rsacomb.ontology
18 18
19/* Java imports */ 19/* Java imports */
20import java.{util => ju} 20import java.{util => ju}
@@ -76,6 +76,7 @@ import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer
76import tech.oxfordsemantic.jrdfox.logic._ 76import tech.oxfordsemantic.jrdfox.logic._
77import org.semanticweb.owlapi.model.OWLObjectInverseOf 77import org.semanticweb.owlapi.model.OWLObjectInverseOf
78 78
79import uk.ac.ox.cs.rsacomb.CanonicalModel
79import uk.ac.ox.cs.rsacomb.approximation.Approximation 80import uk.ac.ox.cs.rsacomb.approximation.Approximation
80import uk.ac.ox.cs.rsacomb.converter._ 81import uk.ac.ox.cs.rsacomb.converter._
81import uk.ac.ox.cs.rsacomb.filtering.{FilteringProgram, FilterType} 82import uk.ac.ox.cs.rsacomb.filtering.{FilteringProgram, FilterType}
@@ -144,7 +145,7 @@ class RSAOntology(
144) extends Ontology(origin, axioms, datafiles) { 145) extends Ontology(origin, axioms, datafiles) {
145 146
146 /** Simplify conversion between OWLAPI and RDFox concepts */ 147 /** Simplify conversion between OWLAPI and RDFox concepts */
147 import implicits.RDFox._ 148 import uk.ac.ox.cs.rsacomb.implicits.RDFox._
148 import uk.ac.ox.cs.rsacomb.implicits.RSAAxiom._ 149 import uk.ac.ox.cs.rsacomb.implicits.RSAAxiom._
149 150
150 /** Simplify conversion between Java and Scala collections */ 151 /** Simplify conversion between Java and Scala collections */
@@ -153,27 +154,6 @@ class RSAOntology(
153 /** Set of axioms removed during the approximation to RSA */ 154 /** Set of axioms removed during the approximation to RSA */
154 //private var removed: Seq[OWLAxiom] = Seq.empty 155 //private var removed: Seq[OWLAxiom] = Seq.empty
155 156
156 /** Retrieve individuals/literals in the ontology */
157 private val individuals: List[IRI] =
158 ontology
159 .getIndividualsInSignature(Imports.INCLUDED)
160 .asScala
161 .map(_.getIRI)
162 .map(implicits.RDFox.owlapiToRdfoxIri)
163 .toList
164 private val literals: List[Literal] =
165 axioms
166 .collect { case a: OWLDataPropertyAssertionAxiom => a }
167 .map(_.getObject)
168 .map(implicits.RDFox.owlapiToRdfoxLiteral)
169
170 /** Retrieve concepts/roles in the ontology */
171 val concepts: List[OWLClass] =
172 ontology.getClassesInSignature().asScala.toList
173 val objroles: List[OWLObjectPropertyExpression] =
174 axioms.flatMap(_.objectPropertyExpressionsInSignature).distinct
175 val dataroles: List[OWLDataProperty] = origin.getDataPropertiesInSignature
176
177 /** Unsafe roles of a given ontology. 157 /** Unsafe roles of a given ontology.
178 * 158 *
179 * Unsafety conditions are the following: 159 * Unsafety conditions are the following:
@@ -288,123 +268,6 @@ class RSAOntology(
288 // val edges3 = Seq('P ~> 'O) 268 // val edges3 = Seq('P ~> 'O)
289 // val graph = Graph.from(edges = edges1 ++ edges2 ++ edges3) 269 // val graph = Graph.from(edges = edges1 ++ edges2 ++ edges3)
290 270
291 /** Top axiomatization rules
292 *
293 * For each concept/role *in the ontology file* introduce a rule to
294 * derive `owl:Thing`.
295 *
296 * @note this might not be enough in cases where data files contain
297 * concept/roles that are not in the ontology file. While this is
298 * non-standard, it is not forbidden either and may cause problems
299 * since not all individuals are considered part of `owl:Thing`.
300 *
301 * @note this is a naïve implementation of top axiomatization and
302 * might change in the future. The ideal solution would be for RDFox
303 * to take care of this, but at the time of writing this is not
304 * compatible with the way we are using the tool.
305 */
306 private val topAxioms: List[Rule] = {
307 val varX = Variable.create("X")
308 val varY = Variable.create("Y")
309 val varZ = Variable.create("Z")
310 val graph = TupleTableName.create(RSAOntology.CanonGraph.getIRI)
311 Rule.create(
312 TupleTableAtom.create(graph, varX, IRI.RDF_TYPE, IRI.THING),
313 TupleTableAtom.create(graph, varX, IRI.RDF_TYPE, varY)
314 ) :: objroles.map(r => {
315 val name = r match {
316 case x: OWLObjectProperty => x.getIRI.getIRIString
317 case x: OWLObjectInverseOf =>
318 x.getInverse.getNamedProperty.getIRI.getIRIString :: Inverse
319 }
320 Rule.create(
321 List(
322 TupleTableAtom.create(graph, varX, IRI.RDF_TYPE, IRI.THING),
323 TupleTableAtom.create(graph, varY, IRI.RDF_TYPE, IRI.THING)
324 ),
325 List(TupleTableAtom.create(graph, varX, name, varY))
326 )
327 }) ::: dataroles.map(r => {
328 val name = r.getIRI.getIRIString
329 Rule.create(
330 List(
331 TupleTableAtom.create(graph, varX, IRI.RDF_TYPE, IRI.THING),
332 TupleTableAtom.create(graph, varY, IRI.RDF_TYPE, IRI.THING)
333 ),
334 List(TupleTableAtom.create(graph, varX, name, varY))
335 )
336 })
337 }
338
339 /** Equality axiomatization rules
340 *
341 * Introduce reflexivity, simmetry and transitivity rules for a naïve
342 * equality axiomatization.
343 *
344 * @note that we are using a custom `congruent` predicate to indicate
345 * equality. This is to avoid interfering with the standard
346 * `owl:sameAs`.
347 *
348 * @note RDFox is able to handle equality in a "smart" way, but this
349 * behaviour is incompatible with other needed features like
350 * negation-as-failure and aggregates.
351 *
352 * @todo naïve substitution rules might not be very efficient. We
353 * should look into other ways of implementing this.
354 */
355 private val equalityAxioms: List[Rule] = {
356 val varX = Variable.create("X")
357 val varY = Variable.create("Y")
358 val varZ = Variable.create("Z")
359 val varW = Variable.create("W")
360 val graph = TupleTableName.create(RSAOntology.CanonGraph.getIRI)
361 // Equality properties
362 val properties = List(
363 // Reflexivity
364 Rule.create(
365 TupleTableAtom.create(graph, varX, RSA.CONGRUENT, varX),
366 TupleTableAtom.create(graph, varX, IRI.RDF_TYPE, IRI.THING)
367 ),
368 // Simmetry
369 Rule.create(
370 TupleTableAtom.create(graph, varY, RSA.CONGRUENT, varX),
371 TupleTableAtom.create(graph, varX, RSA.CONGRUENT, varY)
372 ),
373 // Transitivity
374 Rule.create(
375 TupleTableAtom.create(graph, varX, RSA.CONGRUENT, varZ),
376 TupleTableAtom.create(graph, varX, RSA.CONGRUENT, varY),
377 TupleTableAtom.create(graph, varY, RSA.CONGRUENT, varZ)
378 )
379 )
380 /* Equality substitution rules */
381 val substitutions =
382 Rule.create(
383 TupleTableAtom.create(graph, varY, IRI.RDF_TYPE, varZ),
384 TupleTableAtom.create(graph, varX, RSA.CONGRUENT, varY),
385 TupleTableAtom.create(graph, varX, IRI.RDF_TYPE, varZ)
386 ) :: objroles.flatMap(r => {
387 val name = r match {
388 case x: OWLObjectProperty => x.getIRI.getIRIString
389 case x: OWLObjectInverseOf =>
390 x.getInverse.getNamedProperty.getIRI.getIRIString :: Inverse
391 }
392 List(
393 Rule.create(
394 TupleTableAtom.create(graph, varZ, name, varY),
395 TupleTableAtom.create(graph, varX, RSA.CONGRUENT, varZ),
396 TupleTableAtom.create(graph, varX, name, varY)
397 ),
398 Rule.create(
399 TupleTableAtom.create(graph, varY, name, varZ),
400 TupleTableAtom.create(graph, varX, RSA.CONGRUENT, varZ),
401 TupleTableAtom.create(graph, varY, name, varX)
402 )
403 )
404 })
405 properties ++ substitutions
406 }
407
408 /** Canonical model of the ontology */ 271 /** Canonical model of the ontology */
409 lazy val canonicalModel = Logger.timed( 272 lazy val canonicalModel = Logger.timed(
410 new CanonicalModel(this, RSAOntology.CanonGraph), 273 new CanonicalModel(this, RSAOntology.CanonGraph),
@@ -509,6 +372,15 @@ class RSAOntology(
509 def unfold(axiom: OWLSubClassOfAxiom): Set[Term] = 372 def unfold(axiom: OWLSubClassOfAxiom): Set[Term] =
510 this.self(axiom) | this.cycle(axiom) 373 this.self(axiom) | this.cycle(axiom)
511 374
375 /** Compute canonical model for the ontology.
376 *
377 * This is a *query independent* process and as such can be performed
378 * separately as a one-time operation.
379 *
380 * Calling this method multiple time will have no effect.
381 */
382 def computeCanonicalModel(): Unit = _ask
383
512 /** Returns the answers to a single query 384 /** Returns the answers to a single query
513 * 385 *
514 * @param queries a sequence of conjunctive queries to answer. 386 * @param queries a sequence of conjunctive queries to answer.
@@ -531,6 +403,8 @@ class RSAOntology(
531 RDFoxUtil.addData(data, RSAOntology.CanonGraph, datafiles: _*) 403 RDFoxUtil.addData(data, RSAOntology.CanonGraph, datafiles: _*)
532 404
533 /* Top/equality axiomatization */ 405 /* Top/equality axiomatization */
406 val topAxioms = this.topAxioms(RSAOntology.CanonGraph)
407 val equalityAxioms = this.equalityAxioms(RSAOntology.CanonGraph)
534 Logger.write(topAxioms.mkString("\n"), "axiomatisation.dlog") 408 Logger.write(topAxioms.mkString("\n"), "axiomatisation.dlog")
535 Logger.write(equalityAxioms.mkString("\n"), "axiomatisation.dlog") 409 Logger.write(equalityAxioms.mkString("\n"), "axiomatisation.dlog")
536 RDFoxUtil.updateData(data, 410 RDFoxUtil.updateData(data,
@@ -607,8 +481,8 @@ class RSAOntology(
607 .get 481 .get
608 482
609 /* Drop filtering named graph to avoid running out of memory */ 483 /* Drop filtering named graph to avoid running out of memory */
610 data.clearRulesAxiomsExplicateFacts() 484 //data.clearRulesAxiomsExplicateFacts()
611 data.deleteTupleTable(filter.target.getIRI) 485 //data.deleteTupleTable(filter.target.getIRI)
612 486
613 RDFoxUtil.closeConnection(server, data) 487 RDFoxUtil.closeConnection(server, data)
614 488
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 69363ff..32f7d9b 100644
--- a/src/test/scala/uk/ac/ox/cs/rsacomb/CanonicalModelSpec.scala
+++ b/src/test/scala/uk/ac/ox/cs/rsacomb/CanonicalModelSpec.scala
@@ -30,7 +30,7 @@ import tech.oxfordsemantic.jrdfox.logic.expression.Variable
30 30
31import scala.collection.JavaConverters._ 31import scala.collection.JavaConverters._
32 32
33import uk.ac.ox.cs.rsacomb.RSAOntology 33import uk.ac.ox.cs.rsacomb.ontology.RSAOntology
34import uk.ac.ox.cs.rsacomb.approximation.Lowerbound 34import uk.ac.ox.cs.rsacomb.approximation.Lowerbound
35import uk.ac.ox.cs.rsacomb.ontology.Ontology 35import uk.ac.ox.cs.rsacomb.ontology.Ontology
36import uk.ac.ox.cs.rsacomb.converter.{SkolemStrategy, NoSkolem} 36import uk.ac.ox.cs.rsacomb.converter.{SkolemStrategy, NoSkolem}