aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFederico Igne <git@federicoigne.com>2021-07-22 09:59:07 +0100
committerFederico Igne <git@federicoigne.com>2021-07-22 09:59:07 +0100
commitcb8572606f8951213bcfe9e6667caa208ad3d189 (patch)
tree7ffc99c0d252f7eb828b9147215650dd06149367 /src
parentfb0bbb76a53d08dffea74d0ae13c03a122c379bd (diff)
downloadRSAComb-cb8572606f8951213bcfe9e6667caa208ad3d189.tar.gz
RSAComb-cb8572606f8951213bcfe9e6667caa208ad3d189.zip
Review main workflow
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/CanonicalModel.scala2
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala26
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala4
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/ontologies/Ontology.scala46
4 files changed, 61 insertions, 17 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 af6c463..ee808c3 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/CanonicalModel.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/CanonicalModel.scala
@@ -77,7 +77,7 @@ class CanonicalModel(val ontology: RSAOntology) {
77 // Compute rules from ontology axioms 77 // Compute rules from ontology axioms
78 val (facts, rules) = { 78 val (facts, rules) = {
79 val term = RSAUtil.genFreshVariable() 79 val term = RSAUtil.genFreshVariable()
80 val unsafe = ontology.unsafeRoles 80 val unsafe = ontology.unsafe
81 ontology.axioms 81 ontology.axioms
82 .map(a => 82 .map(a =>
83 CanonicalModelConverter.convert(a, term, unsafe, Constant(a), Empty) 83 CanonicalModelConverter.convert(a, term, unsafe, Constant(a), Empty)
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 82da9df..8e5169d 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
@@ -10,6 +10,10 @@ import tech.oxfordsemantic.jrdfox.logic.sparql.statement.SelectQuery
10import util.{Logger, RDFoxUtil, RSA} 10import util.{Logger, RDFoxUtil, RSA}
11import sparql.ConjunctiveQuery 11import sparql.ConjunctiveQuery
12 12
13import uk.ac.ox.cs.rsacomb.ontology.Ontology
14import uk.ac.ox.cs.rsacomb.converter.Normalizer
15import uk.ac.ox.cs.rsacomb.approximation.LowerBound
16
13case class RSAOption[+T](opt: T) { 17case class RSAOption[+T](opt: T) {
14 def get[T]: T = opt.asInstanceOf[T] 18 def get[T]: T = opt.asInstanceOf[T]
15} 19}
@@ -103,24 +107,18 @@ object RSAConfig {
103/** Main entry point to the program */ 107/** Main entry point to the program */
104object RSAComb extends App { 108object RSAComb extends App {
105 109
106 /*
107 * TODO: Aiming for this workflow:
108 *
109 * implicit val manager = new Manager(...)
110 * val original = manager.importFromFile("ontology.owl")
111 * val axioms = original.getAxioms.filter(isLogicalAxiom).normalize(normalizer)
112 * val ontology = new Ontology(axioms, data)
113 * val rsa = ontology.toRSA(approximator)
114 */
115
116 /* Command-line options */ 110 /* Command-line options */
117 val config = RSAConfig.parse(args.toList) 111 val config = RSAConfig.parse(args.toList)
118 112
119 val rsa = RSAOntology( 113 /* Load original ontology and normalize it */
114 val ontology = Ontology(
120 config('ontology).get[File], 115 config('ontology).get[File],
121 config('data).get[List[File]], 116 config('data).get[List[File]]
122 None 117 ).normalize(new Normalizer)
123 ) 118
119 /* Approximate the ontology to RSA */
120 val toRSA = new LowerBound
121 val rsa = ontology approximate toRSA
124 122
125 if (config contains 'query) { 123 if (config contains 'query) {
126 val query = 124 val query =
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 630d2a0..73c4411 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala
@@ -209,9 +209,9 @@ class RSAOntology(axioms: List[OWLLogicalAxiom], datafiles: List[File])
209 .map(implicits.RDFox.owlapiToRdfoxLiteral) 209 .map(implicits.RDFox.owlapiToRdfoxLiteral)
210 210
211 /** Retrieve concepts/roles in the ontology */ 211 /** Retrieve concepts/roles in the ontology */
212 private val concepts: List[OWLClass] = 212 val concepts: List[OWLClass] =
213 ontology.getClassesInSignature().asScala.toList 213 ontology.getClassesInSignature().asScala.toList
214 private val roles: List[OWLObjectPropertyExpression] = 214 val roles: List[OWLObjectPropertyExpression] =
215 axioms 215 axioms
216 .flatMap(_.objectPropertyExpressionsInSignature) 216 .flatMap(_.objectPropertyExpressionsInSignature)
217 .distinct 217 .distinct
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/ontologies/Ontology.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/ontologies/Ontology.scala
index 9d947bc..723bcaa 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/ontologies/Ontology.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/ontologies/Ontology.scala
@@ -17,12 +17,14 @@
17package uk.ac.ox.cs.rsacomb.ontology 17package uk.ac.ox.cs.rsacomb.ontology
18 18
19import java.io.File 19import java.io.File
20import java.util.stream.Collectors
20 21
21import scala.collection.mutable.Map 22import scala.collection.mutable.Map
22import scala.collection.JavaConverters._ 23import scala.collection.JavaConverters._
23import scalax.collection.Graph 24import scalax.collection.Graph
24import scalax.collection.GraphPredef._, scalax.collection.GraphEdge._ 25import scalax.collection.GraphPredef._, scalax.collection.GraphEdge._
25 26
27import org.semanticweb.owlapi.model.parameters.Imports
26import org.semanticweb.owlapi.apibinding.OWLManager 28import org.semanticweb.owlapi.apibinding.OWLManager
27import org.semanticweb.owlapi.model.{OWLOntology, OWLAxiom, OWLLogicalAxiom} 29import org.semanticweb.owlapi.model.{OWLOntology, OWLAxiom, OWLLogicalAxiom}
28import org.semanticweb.owlapi.model.{OWLObjectPropertyExpression} 30import org.semanticweb.owlapi.model.{OWLObjectPropertyExpression}
@@ -39,6 +41,9 @@ import uk.ac.ox.cs.rsacomb.RSAUtil
39 41
40object Ontology { 42object Ontology {
41 43
44 /** Simplify conversion between Java and Scala collections */
45 import uk.ac.ox.cs.rsacomb.implicits.JavaCollections._
46
42 /** Type wrapper representing a dependency graph for the ontology. 47 /** Type wrapper representing a dependency graph for the ontology.
43 * 48 *
44 * The graph is returned along with a map associating each node (IRI 49 * The graph is returned along with a map associating each node (IRI
@@ -155,6 +160,47 @@ object Ontology {
155 160
156 (graph, nodemap) 161 (graph, nodemap)
157 } 162 }
163
164 def apply(axioms: List[OWLLogicalAxiom], datafiles: List[File]): Ontology =
165 new Ontology(axioms, datafiles)
166
167 def apply(ontology: OWLOntology, datafiles: List[File]): Ontology = {
168
169 /** TBox axioms */
170 var tbox: List[OWLLogicalAxiom] =
171 ontology
172 .tboxAxioms(Imports.INCLUDED)
173 .collect(Collectors.toList())
174 .collect { case a: OWLLogicalAxiom => a }
175
176 /** RBox axioms */
177 var rbox: List[OWLLogicalAxiom] =
178 ontology
179 .rboxAxioms(Imports.INCLUDED)
180 .collect(Collectors.toList())
181 .collect { case a: OWLLogicalAxiom => a }
182
183 /** ABox axioms
184 *
185 * @note this represents only the set of assertions contained in the
186 * ontology file. Data files specified in `datafiles` are directly
187 * imported in RDFox due to performance issues when trying to import
188 * large data files via OWLAPI.
189 */
190 var abox: List[OWLLogicalAxiom] =
191 ontology
192 .aboxAxioms(Imports.INCLUDED)
193 .collect(Collectors.toList())
194 .collect { case a: OWLLogicalAxiom => a }
195
196 Ontology(abox ::: tbox ::: rbox, datafiles)
197 }
198
199 def apply(ontofile: File, datafiles: List[File]): Ontology = {
200 val ontology = manager.loadOntologyFromOntologyDocument(ontofile)
201 Ontology(ontology, datafiles)
202 }
203
158} 204}
159 205
160/** A wrapper for a generic OWL2 ontology 206/** A wrapper for a generic OWL2 ontology