diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-06-01 11:20:39 +0100 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-06-01 11:20:39 +0100 |
commit | 6b4226c41ec2a2439fb44a312ccaff01769e8212 (patch) | |
tree | 3028a3b248056baac5b50d6c41a35524eacb67fb /src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |
parent | 5f9815c3f67114645593840a8648bffb1207b8d0 (diff) | |
download | RSAComb-6b4226c41ec2a2439fb44a312ccaff01769e8212.tar.gz RSAComb-6b4226c41ec2a2439fb44a312ccaff01769e8212.zip |
Fix minor compilation errors
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.scala | 130 |
1 files changed, 69 insertions, 61 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 4d0f13d..247b5d5 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
@@ -80,7 +80,7 @@ object RSAUtil { | |||
80 | * construction of the dependency graph is computed regardless. The | 80 | * construction of the dependency graph is computed regardless. The |
81 | * input axioms are assumed to be normalized. | 81 | * input axioms are assumed to be normalized. |
82 | */ | 82 | */ |
83 | private def dependencyGraph( | 83 | def dependencyGraph( |
84 | axioms: List[OWLLogicalAxiom], | 84 | axioms: List[OWLLogicalAxiom], |
85 | datafiles: List[File] | 85 | datafiles: List[File] |
86 | ): (Graph[Resource, DiEdge], Map[String, OWLAxiom]) = { | 86 | ): (Graph[Resource, DiEdge], Map[String, OWLAxiom]) = { |
@@ -166,18 +166,23 @@ object RSAOntology { | |||
166 | 166 | ||
167 | import uk.ac.ox.cs.rsacomb.implicits.JavaCollections._ | 167 | import uk.ac.ox.cs.rsacomb.implicits.JavaCollections._ |
168 | 168 | ||
169 | /** Manager instance to interface with OWLAPI */ | ||
170 | val manager = OWLManager.createOWLOntologyManager() | ||
171 | val factory = manager.getOWLDataFactory() | ||
172 | |||
169 | /** Name of the RDFox data store used for CQ answering */ | 173 | /** Name of the RDFox data store used for CQ answering */ |
170 | private val DataStore = "answer_computation" | 174 | private val DataStore = "answer_computation" |
171 | 175 | ||
172 | /** Simple fresh variable generator */ | 176 | /** Simple fresh variable/class generator */ |
173 | private var counter = -1; | 177 | private var counter = -1; |
174 | def genFreshVariable(): Variable = { | 178 | def genFreshVariable(): Variable = { |
175 | counter += 1 | 179 | counter += 1 |
176 | Variable.create(f"I$counter%05d") | 180 | Variable.create(f"I$counter%05d") |
177 | } | 181 | } |
178 | 182 | def getFreshOWLClass(): OWLClass = { | |
179 | /** Manager instance to interface with OWLAPI */ | 183 | counter += 1 |
180 | val manager = OWLManager.createOWLOntologyManager() | 184 | factory.getOWLClass(s"X$counter") |
185 | } | ||
181 | 186 | ||
182 | def apply( | 187 | def apply( |
183 | axioms: List[OWLLogicalAxiom], | 188 | axioms: List[OWLLogicalAxiom], |
@@ -254,13 +259,16 @@ class RSAOntology(val axioms: List[OWLLogicalAxiom], val datafiles: File*) { | |||
254 | /** Simplify conversion between OWLAPI and RDFox concepts */ | 259 | /** Simplify conversion between OWLAPI and RDFox concepts */ |
255 | import implicits.RDFox._ | 260 | import implicits.RDFox._ |
256 | import uk.ac.ox.cs.rsacomb.implicits.RSAAxiom._ | 261 | import uk.ac.ox.cs.rsacomb.implicits.RSAAxiom._ |
262 | |||
263 | /** Simplify conversion between Java and Scala collections */ | ||
257 | import uk.ac.ox.cs.rsacomb.implicits.JavaCollections._ | 264 | import uk.ac.ox.cs.rsacomb.implicits.JavaCollections._ |
258 | 265 | ||
259 | /** Set of axioms removed during the approximation to RSA */ | 266 | /** Set of axioms removed during the approximation to RSA */ |
260 | private var removed: Seq[OWLAxiom] = Seq.empty | 267 | private var removed: Seq[OWLAxiom] = Seq.empty |
261 | 268 | ||
262 | /** Normalized Horn-ALCHOIQ ontology */ | 269 | /** Normalized Horn-ALCHOIQ ontology */ |
263 | val ontology = RSAOntology.manager.createOntology(axioms.asJava) | 270 | val ontology = |
271 | RSAOntology.manager.createOntology((axioms: List[OWLAxiom]).asJava) | ||
264 | 272 | ||
265 | /** OWLAPI internal reasoner instantiated over the approximated ontology */ | 273 | /** OWLAPI internal reasoner instantiated over the approximated ontology */ |
266 | private val reasoner = | 274 | private val reasoner = |
@@ -340,61 +348,61 @@ class RSAOntology(val axioms: List[OWLLogicalAxiom], val datafiles: File*) { | |||
340 | * @param graph the graph used to compute the axioms to remove. | 348 | * @param graph the graph used to compute the axioms to remove. |
341 | * @param nodemap map from graph nodes to ontology axioms. | 349 | * @param nodemap map from graph nodes to ontology axioms. |
342 | */ | 350 | */ |
343 | def toRSA(): RSAOntology = Logger.timed( | 351 | // def toRSA(): RSAOntology = Logger.timed( |
344 | { | 352 | // { |
345 | 353 | ||
346 | /* Compute the dependency graph for the ontology */ | 354 | // /* Compute the dependency graph for the ontology */ |
347 | val (graph, nodemap) = this.dependencyGraph() | 355 | // val (graph, nodemap) = this.dependencyGraph() |
348 | 356 | ||
349 | /* Define node colors for the graph visit */ | 357 | // /* Define node colors for the graph visit */ |
350 | sealed trait NodeColor | 358 | // sealed trait NodeColor |
351 | case object Unvisited extends NodeColor | 359 | // case object Unvisited extends NodeColor |
352 | case object Visited extends NodeColor | 360 | // case object Visited extends NodeColor |
353 | case object ToDelete extends NodeColor | 361 | // case object ToDelete extends NodeColor |
354 | 362 | ||
355 | /* Keep track of node colors during graph visit */ | 363 | // /* Keep track of node colors during graph visit */ |
356 | var color = Map.from[Resource, NodeColor]( | 364 | // var color = Map.from[Resource, NodeColor]( |
357 | graph.nodes.toOuter.map(k => (k, Unvisited)) | 365 | // graph.nodes.toOuter.map(k => (k, Unvisited)) |
358 | ) | 366 | // ) |
359 | 367 | ||
360 | for { | 368 | // for { |
361 | component <- graph.componentTraverser().map(_ to Graph) | 369 | // component <- graph.componentTraverser().map(_ to Graph) |
362 | edge <- component | 370 | // edge <- component |
363 | .outerEdgeTraverser(component.nodes.head) | 371 | // .outerEdgeTraverser(component.nodes.head) |
364 | .withKind(BreadthFirst) | 372 | // .withKind(BreadthFirst) |
365 | } yield { | 373 | // } yield { |
366 | val source = edge._1 | 374 | // val source = edge._1 |
367 | val target = edge._2 | 375 | // val target = edge._2 |
368 | color(source) match { | 376 | // color(source) match { |
369 | case Unvisited | Visited => { | 377 | // case Unvisited | Visited => { |
370 | color(target) match { | 378 | // color(target) match { |
371 | case Unvisited => | 379 | // case Unvisited => |
372 | color(source) = Visited; | 380 | // color(source) = Visited; |
373 | color(target) = Visited | 381 | // color(target) = Visited |
374 | case Visited => | 382 | // case Visited => |
375 | color(source) = ToDelete | 383 | // color(source) = ToDelete |
376 | case ToDelete => | 384 | // case ToDelete => |
377 | color(source) = Visited | 385 | // color(source) = Visited |
378 | } | 386 | // } |
379 | } | 387 | // } |
380 | case ToDelete => | 388 | // case ToDelete => |
381 | } | 389 | // } |
382 | } | 390 | // } |
383 | 391 | ||
384 | val toDelete = color.iterator.collect { case (resource: IRI, ToDelete) => | 392 | // val toDelete = color.iterator.collect { case (resource: IRI, ToDelete) => |
385 | nodemap(resource.getIRI) | 393 | // nodemap(resource.getIRI) |
386 | }.toSeq | 394 | // }.toSeq |
387 | 395 | ||
388 | /* Remove axioms from approximated ontology */ | 396 | // /* Remove axioms from approximated ontology */ |
389 | ontology.removeAxioms(toDelete: _*) | 397 | // ontology.removeAxioms(toDelete: _*) |
390 | this.removed = toDelete | 398 | // this.removed = toDelete |
391 | 399 | ||
392 | /* Return RSA ontology */ | 400 | // /* Return RSA ontology */ |
393 | RSAOntology(ontology, datafiles: _*) | 401 | // RSAOntology(ontology, datafiles: _*) |
394 | }, | 402 | // }, |
395 | "Horn-ALCHOIQ to RSA approximation:", | 403 | // "Horn-ALCHOIQ to RSA approximation:", |
396 | Logger.DEBUG | 404 | // Logger.DEBUG |
397 | ) | 405 | // ) |
398 | // val edges1 = Seq('A ~> 'B, 'B ~> 'C, 'C ~> 'D, 'D ~> 'H, 'H ~> | 406 | // val edges1 = Seq('A ~> 'B, 'B ~> 'C, 'C ~> 'D, 'D ~> 'H, 'H ~> |
399 | // 'G, 'G ~> 'F, 'E ~> 'A, 'E ~> 'F, 'B ~> 'E, 'F ~> 'G, 'B ~> 'F, | 407 | // 'G, 'G ~> 'F, 'E ~> 'A, 'E ~> 'F, 'B ~> 'E, 'F ~> 'G, 'B ~> 'F, |
400 | // 'C ~> 'G, 'D ~> 'C, 'H ~> 'D) | 408 | // 'C ~> 'G, 'D ~> 'C, 'H ~> 'D) |