aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2021-05-31 16:58:15 +0100
committerFederico Igne <federico.igne@cs.ox.ac.uk>2021-05-31 16:58:15 +0100
commit5f9815c3f67114645593840a8648bffb1207b8d0 (patch)
tree2a2e14d7fd9c686a8167447b91500bb86de696e4 /src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala
parente932527e33b6f4c1634995224188b26d870d92b2 (diff)
downloadRSAComb-5f9815c3f67114645593840a8648bffb1207b8d0.tar.gz
RSAComb-5f9815c3f67114645593840a8648bffb1207b8d0.zip
Multiple fixes
Diffstat (limited to 'src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala')
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala88
1 files changed, 48 insertions, 40 deletions
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 e048c28..4d0f13d 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala
@@ -50,13 +50,13 @@ import scala.collection.JavaConverters._
50import scala.collection.mutable.{Set, Map} 50import scala.collection.mutable.{Set, Map}
51import scalax.collection.Graph 51import scalax.collection.Graph
52import scalax.collection.GraphPredef._, scalax.collection.GraphEdge._ 52import scalax.collection.GraphPredef._, scalax.collection.GraphEdge._
53import scalax.collection.GraphTraversal._
54 53
55/* Debug only */ 54/* Debug only */
56import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer 55import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer
57import tech.oxfordsemantic.jrdfox.logic._ 56import tech.oxfordsemantic.jrdfox.logic._
58import org.semanticweb.owlapi.model.OWLObjectInverseOf 57import org.semanticweb.owlapi.model.OWLObjectInverseOf
59 58
59import uk.ac.ox.cs.rsacomb.approximation.Approximation
60import uk.ac.ox.cs.rsacomb.converter._ 60import uk.ac.ox.cs.rsacomb.converter._
61import uk.ac.ox.cs.rsacomb.filtering.{FilteringProgram, FilterType} 61import uk.ac.ox.cs.rsacomb.filtering.{FilteringProgram, FilterType}
62import uk.ac.ox.cs.rsacomb.suffix._ 62import uk.ac.ox.cs.rsacomb.suffix._
@@ -66,10 +66,10 @@ import uk.ac.ox.cs.rsacomb.util.Logger
66 66
67object RSAUtil { 67object RSAUtil {
68 68
69 implicit def axiomsToOntology(axioms: Seq[OWLAxiom]) = { 69 // implicit def axiomsToOntology(axioms: Seq[OWLAxiom]) = {
70 val manager = OWLManager.createOWLOntologyManager() 70 // val manager = OWLManager.createOWLOntologyManager()
71 manager.createOntology(axioms.asJava) 71 // manager.createOntology(axioms.asJava)
72 } 72 // }
73 73
74 /** Compute the RSA dependency graph for a set of axioms 74 /** Compute the RSA dependency graph for a set of axioms
75 * 75 *
@@ -81,10 +81,10 @@ object RSAUtil {
81 * input axioms are assumed to be normalized. 81 * input axioms are assumed to be normalized.
82 */ 82 */
83 private def dependencyGraph( 83 private def dependencyGraph(
84 axioms: Seq[OWLAxiom], 84 axioms: List[OWLLogicalAxiom],
85 datafiles: Seq[File] 85 datafiles: List[File]
86 ): (Graph[Resource, DiEdge], Map[String, OWLAxiom]) = { 86 ): (Graph[Resource, DiEdge], Map[String, OWLAxiom]) = {
87 val unsafe = this.unsafeRoles 87 val unsafe = RSAOntology(axioms, datafiles).unsafeRoles
88 var nodemap = Map.empty[String, OWLAxiom] 88 var nodemap = Map.empty[String, OWLAxiom]
89 89
90 object RSAConverter extends RDFoxConverter { 90 object RSAConverter extends RDFoxConverter {
@@ -164,6 +164,8 @@ object RSAUtil {
164 164
165object RSAOntology { 165object RSAOntology {
166 166
167 import uk.ac.ox.cs.rsacomb.implicits.JavaCollections._
168
167 /** Name of the RDFox data store used for CQ answering */ 169 /** Name of the RDFox data store used for CQ answering */
168 private val DataStore = "answer_computation" 170 private val DataStore = "answer_computation"
169 171
@@ -178,9 +180,14 @@ object RSAOntology {
178 val manager = OWLManager.createOWLOntologyManager() 180 val manager = OWLManager.createOWLOntologyManager()
179 181
180 def apply( 182 def apply(
183 axioms: List[OWLLogicalAxiom],
184 datafiles: List[File]
185 ): RSAOntology = new RSAOntology(axioms, datafiles: _*)
186
187 def apply(
181 ontofile: File, 188 ontofile: File,
182 datafiles: Seq[File], 189 datafiles: List[File],
183 approx: Option[Approximation] = None 190 approx: Option[Approximation]
184 ): RSAOntology = { 191 ): RSAOntology = {
185 val ontology = manager.loadOntologyFromOntologyDocument(ontofile) 192 val ontology = manager.loadOntologyFromOntologyDocument(ontofile)
186 RSAOntology(ontology, datafiles, approx) 193 RSAOntology(ontology, datafiles, approx)
@@ -188,14 +195,14 @@ object RSAOntology {
188 195
189 def apply( 196 def apply(
190 ontology: OWLOntology, 197 ontology: OWLOntology,
191 datafiles: Seq[File], 198 datafiles: List[File],
192 approx: Option[Approximation] = None 199 approx: Option[Approximation]
193 ): RSAOntology = { 200 ): RSAOntology = {
194 val normalizer = new Normalizer() 201 val normalizer = new Normalizer()
195 202
196 /** TBox axioms */ 203 /** TBox axioms */
197 var tbox: List[OWLLogicalAxiom] = 204 var tbox: List[OWLLogicalAxiom] =
198 original 205 ontology
199 .tboxAxioms(Imports.INCLUDED) 206 .tboxAxioms(Imports.INCLUDED)
200 .collect(Collectors.toList()) 207 .collect(Collectors.toList())
201 .collect { case a: OWLLogicalAxiom => a } 208 .collect { case a: OWLLogicalAxiom => a }
@@ -203,7 +210,7 @@ object RSAOntology {
203 210
204 /** RBox axioms */ 211 /** RBox axioms */
205 var rbox: List[OWLLogicalAxiom] = 212 var rbox: List[OWLLogicalAxiom] =
206 original 213 ontology
207 .rboxAxioms(Imports.INCLUDED) 214 .rboxAxioms(Imports.INCLUDED)
208 .collect(Collectors.toList()) 215 .collect(Collectors.toList())
209 .collect { case a: OWLLogicalAxiom => a } 216 .collect { case a: OWLLogicalAxiom => a }
@@ -217,7 +224,7 @@ object RSAOntology {
217 * large data files via OWLAPI. 224 * large data files via OWLAPI.
218 */ 225 */
219 var abox: List[OWLLogicalAxiom] = 226 var abox: List[OWLLogicalAxiom] =
220 original 227 ontology
221 .aboxAxioms(Imports.INCLUDED) 228 .aboxAxioms(Imports.INCLUDED)
222 .collect(Collectors.toList()) 229 .collect(Collectors.toList())
223 .collect { case a: OWLLogicalAxiom => a } 230 .collect { case a: OWLLogicalAxiom => a }
@@ -231,9 +238,10 @@ object RSAOntology {
231 case Some(a) => a.approximate(axioms, datafiles) 238 case Some(a) => a.approximate(axioms, datafiles)
232 case None => axioms 239 case None => axioms
233 }, 240 },
234 datafiles 241 datafiles: _*
235 ) 242 )
236 } 243 }
244
237} 245}
238 246
239/** Wrapper class for an ontology in RSA 247/** Wrapper class for an ontology in RSA
@@ -241,7 +249,7 @@ object RSAOntology {
241 * @param ontology the input OWL2 ontology. 249 * @param ontology the input OWL2 ontology.
242 * @param datafiles additinal data (treated as part of the ABox) 250 * @param datafiles additinal data (treated as part of the ABox)
243 */ 251 */
244class RSAOntology(val axioms: Seq[OWLAxiom], val datafiles: File*) { 252class RSAOntology(val axioms: List[OWLLogicalAxiom], val datafiles: File*) {
245 253
246 /** Simplify conversion between OWLAPI and RDFox concepts */ 254 /** Simplify conversion between OWLAPI and RDFox concepts */
247 import implicits.RDFox._ 255 import implicits.RDFox._
@@ -697,28 +705,28 @@ class RSAOntology(val axioms: Seq[OWLAxiom], val datafiles: File*) {
697 this.self(axiom) | this.cycle(axiom) 705 this.self(axiom) | this.cycle(axiom)
698 706
699 /** Log normalization/approximation statistics */ 707 /** Log normalization/approximation statistics */
700 def statistics(level: Logger.Level = Logger.DEBUG): Unit = { 708 // def statistics(level: Logger.Level = Logger.DEBUG): Unit = {
701 Logger.print( 709 // Logger.print(
702 s"Logical axioms in original input ontology: ${original.getLogicalAxiomCount(true)}", 710 // s"Logical axioms in original input ontology: ${original.getLogicalAxiomCount(true)}",
703 level 711 // level
704 ) 712 // )
705 Logger.print( 713 // Logger.print(
706 s"Logical axioms discarded in Horn-ALCHOIQ approximation: ${normalizer.discarded}", 714 // s"Logical axioms discarded in Horn-ALCHOIQ approximation: ${normalizer.discarded}",
707 level 715 // level
708 ) 716 // )
709 Logger.print( 717 // Logger.print(
710 s"Logical axioms shifted in Horn-ALCHOIQ approximation: ${normalizer.shifted}", 718 // s"Logical axioms shifted in Horn-ALCHOIQ approximation: ${normalizer.shifted}",
711 level 719 // level
712 ) 720 // )
713 Logger.print( 721 // Logger.print(
714 s"Logical axioms in Horn-ALCHOIQ ontology: ${ontology 722 // s"Logical axioms in Horn-ALCHOIQ ontology: ${ontology
715 .getLogicalAxiomCount(true)} (${axioms.length}/${axioms.length}/${axioms.length})", 723 // .getLogicalAxiomCount(true)} (${axioms.length}/${axioms.length}/${axioms.length})",
716 level 724 // level
717 ) 725 // )
718 Logger.print( 726 // Logger.print(
719 s"Logical axioms discarded in RSA approximation: ${removed.length}", 727 // s"Logical axioms discarded in RSA approximation: ${removed.length}",
720 level 728 // level
721 ) 729 // )
722 } 730 // }
723 731
724} // class RSAOntology 732} // class RSAOntology