diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-12-02 18:30:16 +0000 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-12-02 18:30:16 +0000 |
commit | bb2fe6440ea4f7e7aeca037c4a4351a28aac3a9f (patch) | |
tree | 2de02b445ccbba942e3de2a25cba969d1244b871 /src | |
parent | 42ba69cc2ad2ccc6ba0208a58e874eba5c911baf (diff) | |
download | RSAComb-bb2fe6440ea4f7e7aeca037c4a4351a28aac3a9f.tar.gz RSAComb-bb2fe6440ea4f7e7aeca037c4a4351a28aac3a9f.zip |
Move datalog rules generation for RSA check to new RDFox generator
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | 75 |
1 files changed, 47 insertions, 28 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 fef4cfa..f90e3c1 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
@@ -10,10 +10,12 @@ import org.semanticweb.owlapi.util.OWLOntologyMerger | |||
10 | import org.semanticweb.owlapi.model.{OWLOntology, OWLAxiom, OWLLogicalAxiom} | 10 | import org.semanticweb.owlapi.model.{OWLOntology, OWLAxiom, OWLLogicalAxiom} |
11 | import org.semanticweb.owlapi.model.{ | 11 | import org.semanticweb.owlapi.model.{ |
12 | OWLClass, | 12 | OWLClass, |
13 | OWLClassExpression, | ||
13 | OWLObjectProperty, | 14 | OWLObjectProperty, |
14 | OWLSubObjectPropertyOfAxiom, | 15 | OWLSubObjectPropertyOfAxiom, |
15 | OWLObjectPropertyExpression, | 16 | OWLObjectPropertyExpression, |
16 | OWLObjectSomeValuesFrom, | 17 | OWLObjectSomeValuesFrom, |
18 | OWLDataSomeValuesFrom, | ||
17 | OWLSubClassOfAxiom | 19 | OWLSubClassOfAxiom |
18 | } | 20 | } |
19 | import org.semanticweb.owlapi.model.parameters.Imports | 21 | import org.semanticweb.owlapi.model.parameters.Imports |
@@ -48,7 +50,7 @@ import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer | |||
48 | import tech.oxfordsemantic.jrdfox.logic._ | 50 | import tech.oxfordsemantic.jrdfox.logic._ |
49 | import org.semanticweb.owlapi.model.OWLObjectInverseOf | 51 | import org.semanticweb.owlapi.model.OWLObjectInverseOf |
50 | 52 | ||
51 | import uk.ac.ox.cs.rsacomb.converter.{RDFoxAxiomConverter, SkolemStrategy} | 53 | import uk.ac.ox.cs.rsacomb.converter.{RDFoxConverter, SkolemStrategy} |
52 | import uk.ac.ox.cs.rsacomb.suffix._ | 54 | import uk.ac.ox.cs.rsacomb.suffix._ |
53 | import uk.ac.ox.cs.rsacomb.sparql._ | 55 | import uk.ac.ox.cs.rsacomb.sparql._ |
54 | import uk.ac.ox.cs.rsacomb.util.{RDFoxUtil, RSA} | 56 | import uk.ac.ox.cs.rsacomb.util.{RDFoxUtil, RSA} |
@@ -150,28 +152,54 @@ class RSAOntology(val ontology: OWLOntology) { | |||
150 | //println("\nUnsafe roles:") | 152 | //println("\nUnsafe roles:") |
151 | //println(unsafe) | 153 | //println(unsafe) |
152 | 154 | ||
155 | object RSAConverter extends RDFoxConverter { | ||
156 | |||
157 | override def convert( | ||
158 | expr: OWLClassExpression, | ||
159 | term: Term, | ||
160 | unsafe: List[OWLObjectPropertyExpression], | ||
161 | skolem: SkolemStrategy, | ||
162 | suffix: RSASuffix | ||
163 | ): Shards = | ||
164 | (expr, skolem) match { | ||
165 | |||
166 | case (e: OWLObjectSomeValuesFrom, SkolemStrategy.Constant(c)) | ||
167 | if unsafe contains e.getProperty => { | ||
168 | val (res, ext) = super.convert(e, term, unsafe, skolem, suffix) | ||
169 | (RSA.PE(term, c) :: RSA.U(c) :: res, ext) | ||
170 | } | ||
171 | |||
172 | case (e: OWLDataSomeValuesFrom, SkolemStrategy.Constant(c)) | ||
173 | if unsafe contains e.getProperty => { | ||
174 | val (res, ext) = super.convert(e, term, unsafe, skolem, suffix) | ||
175 | (RSA.PE(term, c) :: RSA.U(c) :: res, ext) | ||
176 | } | ||
177 | |||
178 | case _ => super.convert(expr, term, unsafe, skolem, suffix) | ||
179 | } | ||
180 | |||
181 | } | ||
182 | |||
153 | /* Ontology convertion into LP rules */ | 183 | /* Ontology convertion into LP rules */ |
154 | val datalog = for { | 184 | val term = RSAOntology.genFreshVariable() |
155 | axiom <- axioms | 185 | val datalog = axioms |
156 | visitor = new RDFoxAxiomConverter( | 186 | .map(a => { |
157 | RSAOntology.genFreshVariable(), | 187 | val skolem = SkolemStrategy.Constant(a.toString) |
158 | unsafe, | 188 | RSAConverter.convert(a, term, unsafe, skolem, Empty) |
159 | SkolemStrategy.ConstantRSA(axiom.toString), | 189 | }) |
160 | Empty | 190 | .unzip |
161 | ) | 191 | val facts = datalog._1.flatten |
162 | rule <- axiom.accept(visitor) | 192 | val rules = datalog._2.flatten |
163 | } yield rule | ||
164 | 193 | ||
165 | /* DEBUG: print datalog rules */ | 194 | /* DEBUG: print datalog rules */ |
166 | println("\nDatalog roles:") | 195 | //println("\nDatalog rules:") |
167 | datalog.foreach(println) | 196 | //rules.foreach(println) |
168 | 197 | ||
169 | // Open connection with RDFox | 198 | // Open connection with RDFox |
170 | val (server, data) = RDFoxUtil.openConnection("RSACheck") | 199 | val (server, data) = RDFoxUtil.openConnection("RSACheck") |
171 | // Add Data (hardcoded for now) | ||
172 | //data.importData(UpdateType.ADDITION, RSA.Prefixes, ":a a :A .") | ||
173 | 200 | ||
174 | /* Add built-in rules | 201 | /* Add built-in rules |
202 | * TODO: substitute with RDFoxUtil.addRules | ||
175 | */ | 203 | */ |
176 | data.importData( | 204 | data.importData( |
177 | UpdateType.ADDITION, | 205 | UpdateType.ADDITION, |
@@ -179,20 +207,11 @@ class RSAOntology(val ontology: OWLOntology) { | |||
179 | "rsa:E[?X,?Y] :- rsa:PE[?X,?Y], rsa:U[?X], rsa:U[?Y] ." | 207 | "rsa:E[?X,?Y] :- rsa:PE[?X,?Y], rsa:U[?X], rsa:U[?Y] ." |
180 | ) | 208 | ) |
181 | 209 | ||
182 | /* Add built-in rules | 210 | /* Add ontology facts and rules */ |
183 | */ | 211 | RDFoxUtil.addFacts(data, facts) |
184 | // data.importData( | 212 | RDFoxUtil.addRules(data, rules) |
185 | // UpdateType.ADDITION, | ||
186 | // RSA.Prefixes, | ||
187 | // "[?entity, a, ?superClass] :- [?entity, a, ?class], [?class, rdfs:subClassOf, ?superClass] ." | ||
188 | // ) | ||
189 | 213 | ||
190 | /* Add ontology rules | 214 | /* Build graph */ |
191 | */ | ||
192 | data.addRules(datalog.asJava) | ||
193 | |||
194 | /* Build graph | ||
195 | */ | ||
196 | val graph = this.rsaGraph(data); | 215 | val graph = this.rsaGraph(data); |
197 | //println(graph) | 216 | //println(graph) |
198 | 217 | ||