diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-11-18 18:07:53 +0000 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-11-18 18:07:53 +0000 |
commit | 4df351d3b1d11fc045005323c38ba3528de631ea (patch) | |
tree | 35f809e3def7d55602ed124f7b194db29407ba33 /src/main/scala/rsacomb/RSAOntology.scala | |
parent | e1a04294ed8737444e40323474f4084cb64c1d55 (diff) | |
download | RSAComb-4df351d3b1d11fc045005323c38ba3528de631ea.tar.gz RSAComb-4df351d3b1d11fc045005323c38ba3528de631ea.zip |
Rework RSA as a utility object
Diffstat (limited to 'src/main/scala/rsacomb/RSAOntology.scala')
-rw-r--r-- | src/main/scala/rsacomb/RSAOntology.scala | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/main/scala/rsacomb/RSAOntology.scala b/src/main/scala/rsacomb/RSAOntology.scala index 52bff37..1a5e4ca 100644 --- a/src/main/scala/rsacomb/RSAOntology.scala +++ b/src/main/scala/rsacomb/RSAOntology.scala | |||
@@ -47,14 +47,23 @@ import tech.oxfordsemantic.jrdfox.logic._ | |||
47 | import org.semanticweb.owlapi.model.OWLObjectInverseOf | 47 | import org.semanticweb.owlapi.model.OWLObjectInverseOf |
48 | 48 | ||
49 | import suffix.{Empty, Forward, Backward, Inverse} | 49 | import suffix.{Empty, Forward, Backward, Inverse} |
50 | import util.{RDFoxHelpers, RSA} | ||
50 | 51 | ||
51 | object RSAOntology { | 52 | object RSAOntology { |
52 | 53 | ||
54 | // Counter used to implement a simple fresh variable generator | ||
55 | private var counter = -1; | ||
56 | |||
53 | def apply(ontology: OWLOntology): RSAOntology = new RSAOntology(ontology) | 57 | def apply(ontology: OWLOntology): RSAOntology = new RSAOntology(ontology) |
54 | 58 | ||
55 | def apply(ontology: File): RSAOntology = | 59 | def apply(ontology: File): RSAOntology = |
56 | new RSAOntology(loadOntology(ontology)) | 60 | new RSAOntology(loadOntology(ontology)) |
57 | 61 | ||
62 | def genFreshVariable(): Variable = { | ||
63 | counter += 1 | ||
64 | Variable.create(f"I$counter%03d") | ||
65 | } | ||
66 | |||
58 | private def loadOntology(onto: File): OWLOntology = { | 67 | private def loadOntology(onto: File): OWLOntology = { |
59 | val manager = OWLManager.createOWLOntologyManager() | 68 | val manager = OWLManager.createOWLOntologyManager() |
60 | manager.loadOntologyFromOntologyDocument(onto) | 69 | manager.loadOntologyFromOntologyDocument(onto) |
@@ -94,7 +103,7 @@ class RSAOntology(val ontology: OWLOntology) extends RSAAxiom { | |||
94 | .getIndividualsInSignature() | 103 | .getIndividualsInSignature() |
95 | .asScala | 104 | .asScala |
96 | .map(_.getIRI) | 105 | .map(_.getIRI) |
97 | .map(RDFoxUtil.owlapi2rdfox) | 106 | .map(implicits.RDFox.owlapiToRdfoxIri) |
98 | .toList | 107 | .toList |
99 | 108 | ||
100 | val concepts: List[OWLClass] = | 109 | val concepts: List[OWLClass] = |
@@ -133,7 +142,7 @@ class RSAOntology(val ontology: OWLOntology) extends RSAAxiom { | |||
133 | val datalog = for { | 142 | val datalog = for { |
134 | axiom <- axioms | 143 | axiom <- axioms |
135 | visitor = new RDFoxAxiomConverter( | 144 | visitor = new RDFoxAxiomConverter( |
136 | RSA.getFreshVariable(), | 145 | RSAOntology.genFreshVariable(), |
137 | unsafe, | 146 | unsafe, |
138 | SkolemStrategy.ConstantRSA(axiom.toString), | 147 | SkolemStrategy.ConstantRSA(axiom.toString), |
139 | Empty | 148 | Empty |
@@ -146,9 +155,9 @@ class RSAOntology(val ontology: OWLOntology) extends RSAAxiom { | |||
146 | //datalog.foreach(println) | 155 | //datalog.foreach(println) |
147 | 156 | ||
148 | // Open connection with RDFox | 157 | // Open connection with RDFox |
149 | val (server, data) = RDFoxUtil.openConnection("RSACheck") | 158 | val (server, data) = RDFoxHelpers.openConnection("RSACheck") |
150 | // Add Data (hardcoded for now) | 159 | // Add Data (hardcoded for now) |
151 | data.importData(UpdateType.ADDITION, RSA.Prefixes, ":a a :A .") | 160 | //data.importData(UpdateType.ADDITION, RSA.Prefixes, ":a a :A .") |
152 | 161 | ||
153 | /* Add built-in rules | 162 | /* Add built-in rules |
154 | */ | 163 | */ |
@@ -176,7 +185,7 @@ class RSAOntology(val ontology: OWLOntology) extends RSAAxiom { | |||
176 | //println(graph) | 185 | //println(graph) |
177 | 186 | ||
178 | // Close connection to RDFox | 187 | // Close connection to RDFox |
179 | RDFoxUtil.closeConnection(server, data) | 188 | RDFoxHelpers.closeConnection(server, data) |
180 | 189 | ||
181 | /* To check if the graph is tree-like we check for acyclicity in a | 190 | /* To check if the graph is tree-like we check for acyclicity in a |
182 | * undirected graph. | 191 | * undirected graph. |
@@ -291,8 +300,8 @@ class RSAOntology(val ontology: OWLOntology) extends RSAAxiom { | |||
291 | val role = axiom.objectPropertyExpressionsInSignature(0) | 300 | val role = axiom.objectPropertyExpressionsInSignature(0) |
292 | if (this.confl(role).contains(role)) { | 301 | if (this.confl(role).contains(role)) { |
293 | Set( | 302 | Set( |
294 | RSA.rsa("v0_" ++ RSA.hashed(axiom)), | 303 | RSA("v0_" ++ axiom.hashed), |
295 | RSA.rsa("v1_" ++ RSA.hashed(axiom)) | 304 | RSA("v1_" ++ axiom.hashed) |
296 | ) | 305 | ) |
297 | } else { | 306 | } else { |
298 | Set() | 307 | Set() |
@@ -354,15 +363,15 @@ class RSAOntology(val ontology: OWLOntology) extends RSAAxiom { | |||
354 | classC <- classes | 363 | classC <- classes |
355 | // Keeping this check for now | 364 | // Keeping this check for now |
356 | if !unsafeRoles.contains(roleS) | 365 | if !unsafeRoles.contains(roleS) |
357 | tripleARB = RSA.hashed(classA, roleR, classB) | 366 | tripleARB = RSAAxiom.hashed(classA, roleR, classB) |
358 | tripleDSC = RSA.hashed(classD, roleS, classC) | 367 | tripleDSC = RSAAxiom.hashed(classD, roleS, classC) |
359 | individual = | 368 | individual = |
360 | if (tripleARB > tripleDSC) { | 369 | if (tripleARB > tripleDSC) { |
361 | RSA.rsa("v1_" ++ tripleDSC) | 370 | RSA("v1_" ++ tripleDSC) |
362 | } else { | 371 | } else { |
363 | // Note that this is also the case for | 372 | // Note that this is also the case for |
364 | // `tripleARB == tripleDSC` | 373 | // `tripleARB == tripleDSC` |
365 | RSA.rsa("v0_" ++ tripleDSC) | 374 | RSA("v0_" ++ tripleDSC) |
366 | } | 375 | } |
367 | } yield individual | 376 | } yield individual |
368 | } | 377 | } |