diff options
3 files changed, 105 insertions, 118 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 0f3b16a..bcc336a 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/CanonicalModel.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/CanonicalModel.scala | |||
@@ -3,9 +3,10 @@ package uk.ac.ox.cs.rsacomb | |||
3 | import org.semanticweb.owlapi.model.{OWLObjectInverseOf, OWLObjectProperty} | 3 | import org.semanticweb.owlapi.model.{OWLObjectInverseOf, OWLObjectProperty} |
4 | import org.semanticweb.owlapi.model.{ | 4 | import org.semanticweb.owlapi.model.{ |
5 | OWLClass, | 5 | OWLClass, |
6 | OWLLogicalAxiom, | ||
6 | // OWLObjectProperty, | 7 | // OWLObjectProperty, |
7 | OWLSubObjectPropertyOfAxiom, | 8 | OWLSubObjectPropertyOfAxiom, |
8 | // OWLObjectPropertyExpression, | 9 | OWLObjectPropertyExpression, |
9 | OWLObjectSomeValuesFrom, | 10 | OWLObjectSomeValuesFrom, |
10 | OWLSubClassOfAxiom | 11 | OWLSubClassOfAxiom |
11 | } | 12 | } |
@@ -25,10 +26,11 @@ import tech.oxfordsemantic.jrdfox.logic.expression.{ | |||
25 | 26 | ||
26 | import uk.ac.ox.cs.rsacomb.converter.{ | 27 | import uk.ac.ox.cs.rsacomb.converter.{ |
27 | SkolemStrategy, | 28 | SkolemStrategy, |
28 | RDFoxAxiomConverter, | 29 | RDFoxConverter |
29 | RDFoxPropertyExprConverter | 30 | // RDFoxAxiomConverter, |
31 | // RDFoxPropertyExprConverter | ||
30 | } | 32 | } |
31 | import uk.ac.ox.cs.rsacomb.suffix.{Empty, Forward, Backward, Inverse} | 33 | import uk.ac.ox.cs.rsacomb.suffix._ |
32 | import uk.ac.ox.cs.rsacomb.util.RSA | 34 | import uk.ac.ox.cs.rsacomb.util.RSA |
33 | 35 | ||
34 | class CanonicalModel(val ontology: RSAOntology) { | 36 | class CanonicalModel(val ontology: RSAOntology) { |
@@ -107,22 +109,28 @@ class CanonicalModel(val ontology: RSAOntology) { | |||
107 | ) | 109 | ) |
108 | } | 110 | } |
109 | 111 | ||
110 | val rules: List[Rule] = { | 112 | val (facts, rules): (List[TupleTableAtom], List[Rule]) = { |
111 | // Compute rules from ontology axioms | 113 | // Compute rules from ontology axioms |
112 | val rules = ontology.axioms.flatMap(_.accept(RuleGenerator)) | 114 | val (facts, rules) = { |
113 | // Return full set of rules | 115 | val term = RSAOntology.genFreshVariable() |
114 | rules ::: rolesAdditionalRules ::: topAxioms ::: equalityAxioms | 116 | val unsafe = ontology.unsafeRoles |
117 | val skolem = SkolemStrategy.None | ||
118 | val suffix = Empty | ||
119 | ontology.axioms | ||
120 | .map(CanonicalModelConverter.convert(_, term, unsafe, skolem, suffix)) | ||
121 | .unzip | ||
122 | } | ||
123 | ( | ||
124 | facts.flatten, | ||
125 | rolesAdditionalRules ::: topAxioms ::: equalityAxioms ::: rules.flatten | ||
126 | ) | ||
115 | } | 127 | } |
116 | 128 | ||
117 | object RuleGenerator | 129 | object CanonicalModelConverter extends RDFoxConverter { |
118 | extends RDFoxAxiomConverter( | ||
119 | Variable.create("X"), | ||
120 | ontology.unsafeRoles, | ||
121 | SkolemStrategy.None, | ||
122 | Empty | ||
123 | ) { | ||
124 | 130 | ||
125 | private def rules1(axiom: OWLSubClassOfAxiom): List[Rule] = { | 131 | private def rules1( |
132 | axiom: OWLSubClassOfAxiom | ||
133 | ): Result = { | ||
126 | val unfold = ontology.unfold(axiom).toList | 134 | val unfold = ontology.unfold(axiom).toList |
127 | // Fresh Variables | 135 | // Fresh Variables |
128 | val v0 = RSA("v0_" ++ axiom.hashed) | 136 | val v0 = RSA("v0_" ++ axiom.hashed) |
@@ -134,13 +142,9 @@ class CanonicalModel(val ontology: RSAOntology) { | |||
134 | TupleTableAtom.rdf(varX, IRI.RDF_TYPE, cls) | 142 | TupleTableAtom.rdf(varX, IRI.RDF_TYPE, cls) |
135 | } | 143 | } |
136 | val roleRf: TupleTableAtom = { | 144 | val roleRf: TupleTableAtom = { |
137 | val visitor = | 145 | val prop = |
138 | new RDFoxPropertyExprConverter(varX, v0, Forward) | 146 | axiom.getSuperClass.asInstanceOf[OWLObjectSomeValuesFrom].getProperty |
139 | axiom.getSuperClass | 147 | super.convert(prop, varX, v0, Forward) |
140 | .asInstanceOf[OWLObjectSomeValuesFrom] | ||
141 | .getProperty | ||
142 | .accept(visitor) | ||
143 | .head | ||
144 | } | 148 | } |
145 | val atomB: TupleTableAtom = { | 149 | val atomB: TupleTableAtom = { |
146 | val cls = axiom.getSuperClass | 150 | val cls = axiom.getSuperClass |
@@ -154,12 +158,12 @@ class CanonicalModel(val ontology: RSAOntology) { | |||
154 | // returning facts as `Rule`s with true body. While this is correct | 158 | // returning facts as `Rule`s with true body. While this is correct |
155 | // there is an easier way to import facts into RDFox. Are we able to | 159 | // there is an easier way to import facts into RDFox. Are we able to |
156 | // do that? | 160 | // do that? |
157 | val facts = unfold.map(x => Rule.create(RSA.In(x))) | 161 | val facts = unfold map RSA.In |
158 | val rules = List( | 162 | val rules = List( |
159 | Rule.create(roleRf, atomA, RSA.NotIn(varX)), | 163 | Rule.create(roleRf, atomA, RSA.NotIn(varX)), |
160 | Rule.create(atomB, atomA, RSA.NotIn(varX)) | 164 | Rule.create(atomB, atomA, RSA.NotIn(varX)) |
161 | ) | 165 | ) |
162 | facts ++ rules | 166 | (facts, rules) |
163 | } | 167 | } |
164 | 168 | ||
165 | private def rules2(axiom: OWLSubClassOfAxiom): List[Rule] = { | 169 | private def rules2(axiom: OWLSubClassOfAxiom): List[Rule] = { |
@@ -177,11 +181,8 @@ class CanonicalModel(val ontology: RSAOntology) { | |||
177 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI | 181 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI |
178 | TupleTableAtom.rdf(t, IRI.RDF_TYPE, cls) | 182 | TupleTableAtom.rdf(t, IRI.RDF_TYPE, cls) |
179 | } | 183 | } |
180 | def roleRf(t1: Term, t2: Term): TupleTableAtom = { | 184 | def roleRf(t1: Term, t2: Term): TupleTableAtom = |
181 | val visitor = | 185 | super.convert(roleR, t1, t2, Forward) |
182 | new RDFoxPropertyExprConverter(t1, t2, Forward) | ||
183 | roleR.accept(visitor).head | ||
184 | } | ||
185 | def atomB(t: Term): TupleTableAtom = { | 186 | def atomB(t: Term): TupleTableAtom = { |
186 | val cls = axiom.getSuperClass | 187 | val cls = axiom.getSuperClass |
187 | .asInstanceOf[OWLObjectSomeValuesFrom] | 188 | .asInstanceOf[OWLObjectSomeValuesFrom] |
@@ -215,11 +216,8 @@ class CanonicalModel(val ontology: RSAOntology) { | |||
215 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI | 216 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI |
216 | TupleTableAtom.rdf(t, IRI.RDF_TYPE, cls) | 217 | TupleTableAtom.rdf(t, IRI.RDF_TYPE, cls) |
217 | } | 218 | } |
218 | def roleRf(t: Term): TupleTableAtom = { | 219 | def roleRf(t: Term): TupleTableAtom = |
219 | val visitor = | 220 | super.convert(roleR, t, v1, Forward) |
220 | new RDFoxPropertyExprConverter(t, v1, Forward) | ||
221 | roleR.accept(visitor).head | ||
222 | } | ||
223 | val atomB: TupleTableAtom = { | 221 | val atomB: TupleTableAtom = { |
224 | val cls = axiom.getSuperClass | 222 | val cls = axiom.getSuperClass |
225 | .asInstanceOf[OWLObjectSomeValuesFrom] | 223 | .asInstanceOf[OWLObjectSomeValuesFrom] |
@@ -236,46 +234,37 @@ class CanonicalModel(val ontology: RSAOntology) { | |||
236 | } | 234 | } |
237 | } | 235 | } |
238 | 236 | ||
239 | override def visit(axiom: OWLSubClassOfAxiom): List[Rule] = { | 237 | override def convert( |
240 | if (axiom.isT5) { | 238 | axiom: OWLLogicalAxiom, |
241 | // TODO: get role in T5 axiom | 239 | term: Term, |
242 | // Assuming one role here | 240 | unsafe: List[OWLObjectPropertyExpression], |
243 | val role = axiom.objectPropertyExpressionsInSignature(0) | 241 | skolem: SkolemStrategy, |
244 | if (ontology.unsafeRoles contains role) { | 242 | suffix: RSASuffix |
245 | val visitor = | 243 | ): Result = |
246 | new RDFoxAxiomConverter( | 244 | axiom match { |
247 | Variable.create("X"), | 245 | |
248 | ontology.unsafeRoles, | 246 | case a: OWLSubClassOfAxiom if a.isT5 => { |
249 | SkolemStrategy.Standard(axiom.toString), | 247 | val role = axiom.objectPropertyExpressionsInSignature(0) |
250 | Forward | 248 | if (unsafe contains role) { |
251 | ) | 249 | val skolem = SkolemStrategy.Standard(a.toString) |
252 | axiom.accept(visitor) | 250 | super.convert(a, term, unsafe, skolem, Forward) |
253 | } else { | 251 | } else { |
254 | rules1(axiom) ::: rules2(axiom) ::: rules3(axiom) | 252 | val (f1, r1) = rules1(a) |
253 | (f1, r1 ::: rules2(a) ::: rules3(a)) | ||
254 | } | ||
255 | } | 255 | } |
256 | } else { | ||
257 | // Fallback to standard OWL to LP translation | ||
258 | super.visit(axiom) | ||
259 | } | ||
260 | } | ||
261 | 256 | ||
262 | override def visit(axiom: OWLSubObjectPropertyOfAxiom): List[Rule] = { | 257 | case a: OWLSubObjectPropertyOfAxiom => { |
263 | val varX = Variable.create("X") | 258 | val (factsF, rulesF) = |
264 | val visitorF = new RDFoxAxiomConverter( | 259 | super.convert(a, term, unsafe, SkolemStrategy.None, Forward) |
265 | varX, | 260 | val (factsB, rulesB) = |
266 | ontology.unsafeRoles, | 261 | super.convert(a, term, unsafe, SkolemStrategy.None, Backward) |
267 | SkolemStrategy.None, | 262 | (factsF ::: factsB, rulesF ::: rulesB) |
268 | Forward | 263 | } |
269 | ) | ||
270 | val visitorB = new RDFoxAxiomConverter( | ||
271 | varX, | ||
272 | ontology.unsafeRoles, | ||
273 | SkolemStrategy.None, | ||
274 | Backward | ||
275 | ) | ||
276 | axiom.accept(visitorB) ::: axiom.accept(visitorF) | ||
277 | } | ||
278 | 264 | ||
265 | case a => super.convert(a, term, unsafe, skolem, suffix) | ||
266 | |||
267 | } | ||
279 | } | 268 | } |
280 | 269 | ||
281 | } | 270 | } |
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 4dd554a..fef4cfa 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
@@ -7,7 +7,7 @@ import java.util.stream.{Collectors, Stream} | |||
7 | import java.io.File | 7 | import java.io.File |
8 | import org.semanticweb.owlapi.apibinding.OWLManager | 8 | import org.semanticweb.owlapi.apibinding.OWLManager |
9 | import org.semanticweb.owlapi.util.OWLOntologyMerger | 9 | import org.semanticweb.owlapi.util.OWLOntologyMerger |
10 | import org.semanticweb.owlapi.model.{OWLOntology, OWLAxiom} | 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 | OWLObjectProperty, | 13 | OWLObjectProperty, |
@@ -82,30 +82,28 @@ object RSAOntology { | |||
82 | class RSAOntology(val ontology: OWLOntology) { | 82 | class RSAOntology(val ontology: OWLOntology) { |
83 | 83 | ||
84 | import uk.ac.ox.cs.rsacomb.implicits.RSAAxiom._ | 84 | import uk.ac.ox.cs.rsacomb.implicits.RSAAxiom._ |
85 | import uk.ac.ox.cs.rsacomb.implicits.JavaCollections._ | ||
85 | 86 | ||
86 | // Gather TBox/RBox/ABox from original ontology | 87 | // Gather TBox/RBox/ABox from original ontology |
87 | val tbox: List[OWLAxiom] = | 88 | val tbox: List[OWLLogicalAxiom] = |
88 | ontology | 89 | ontology |
89 | .tboxAxioms(Imports.INCLUDED) | 90 | .tboxAxioms(Imports.INCLUDED) |
90 | .collect(Collectors.toList()) | 91 | .collect(Collectors.toList()) |
91 | .asScala | 92 | .collect { case a: OWLLogicalAxiom => a } |
92 | .toList | ||
93 | 93 | ||
94 | val rbox: List[OWLAxiom] = | 94 | val rbox: List[OWLLogicalAxiom] = |
95 | ontology | 95 | ontology |
96 | .rboxAxioms(Imports.INCLUDED) | 96 | .rboxAxioms(Imports.INCLUDED) |
97 | .collect(Collectors.toList()) | 97 | .collect(Collectors.toList()) |
98 | .asScala | 98 | .collect { case a: OWLLogicalAxiom => a } |
99 | .toList | ||
100 | 99 | ||
101 | val abox: List[OWLAxiom] = | 100 | val abox: List[OWLLogicalAxiom] = |
102 | ontology | 101 | ontology |
103 | .aboxAxioms(Imports.INCLUDED) | 102 | .aboxAxioms(Imports.INCLUDED) |
104 | .collect(Collectors.toList()) | 103 | .collect(Collectors.toList()) |
105 | .asScala | 104 | .collect { case a: OWLLogicalAxiom => a } |
106 | .toList | ||
107 | 105 | ||
108 | val axioms: List[OWLAxiom] = abox ::: tbox ::: rbox | 106 | val axioms: List[OWLLogicalAxiom] = abox ::: tbox ::: rbox |
109 | 107 | ||
110 | /* Retrieve individuals in the original ontology | 108 | /* Retrieve individuals in the original ontology |
111 | */ | 109 | */ |
@@ -267,8 +265,8 @@ class RSAOntology(val ontology: OWLOntology) { | |||
267 | ): Graph[Resource, UnDiEdge] = { | 265 | ): Graph[Resource, UnDiEdge] = { |
268 | val query = "SELECT ?X ?Y WHERE { ?X rsa:E ?Y }" | 266 | val query = "SELECT ?X ?Y WHERE { ?X rsa:E ?Y }" |
269 | val answers = RDFoxUtil.submitQuery(data, query, RSA.Prefixes).get | 267 | val answers = RDFoxUtil.submitQuery(data, query, RSA.Prefixes).get |
270 | var edges: Seq[UnDiEdge[Resource]] = answers.map { | 268 | var edges: Seq[UnDiEdge[Resource]] = answers.map { case Seq(n1, n2) => |
271 | case Seq(n1, n2) => UnDiEdge(n1, n2) | 269 | UnDiEdge(n1, n2) |
272 | } | 270 | } |
273 | Graph(edges: _*) | 271 | Graph(edges: _*) |
274 | } | 272 | } |
@@ -310,7 +308,8 @@ class RSAOntology(val ontology: OWLOntology) { | |||
310 | def ask(query: ConjunctiveQuery): ConjunctiveQueryAnswers = { | 308 | def ask(query: ConjunctiveQuery): ConjunctiveQueryAnswers = { |
311 | import implicits.JavaCollections._ | 309 | import implicits.JavaCollections._ |
312 | val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) | 310 | val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) |
313 | data.addRules(this.canonicalModel.rules) | 311 | RDFoxUtil.addRules(data, this.canonicalModel.rules) |
312 | RDFoxUtil.addFacts(data, this.canonicalModel.facts) | ||
314 | data.addRules(this.filteringProgram(query).rules) | 313 | data.addRules(this.filteringProgram(query).rules) |
315 | val answers = RDFoxUtil | 314 | val answers = RDFoxUtil |
316 | .submitQuery( | 315 | .submitQuery( |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala index 9b2071e..7fd4dbe 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala | |||
@@ -57,7 +57,7 @@ import uk.ac.ox.cs.rsacomb.util.RSA | |||
57 | * normalization procedure that will prevent errors or unexpected | 57 | * normalization procedure that will prevent errors or unexpected |
58 | * results. | 58 | * results. |
59 | */ | 59 | */ |
60 | object RDFoxConverter { | 60 | trait RDFoxConverter { |
61 | 61 | ||
62 | /** Simplify conversion between Java and Scala collections */ | 62 | /** Simplify conversion between Java and Scala collections */ |
63 | import uk.ac.ox.cs.rsacomb.implicits.JavaCollections._ | 63 | import uk.ac.ox.cs.rsacomb.implicits.JavaCollections._ |
@@ -85,7 +85,7 @@ object RDFoxConverter { | |||
85 | * along with a set of atoms for the body of the rule (namely | 85 | * along with a set of atoms for the body of the rule (namely |
86 | * `R(x,y), B(y), R(x,z), B(z)`). | 86 | * `R(x,y), B(y), R(x,z), B(z)`). |
87 | */ | 87 | */ |
88 | private type Shards = (List[TupleTableAtom], List[BodyFormula]) | 88 | protected type Shards = (List[TupleTableAtom], List[BodyFormula]) |
89 | 89 | ||
90 | /** Represent the result of the conversion of | 90 | /** Represent the result of the conversion of |
91 | * [[org.semanticweb.owlapi.model.OWLLogicalAxiom OWLLogicalAxiom]]. | 91 | * [[org.semanticweb.owlapi.model.OWLLogicalAxiom OWLLogicalAxiom]]. |
@@ -93,7 +93,10 @@ object RDFoxConverter { | |||
93 | * In general we have assertion returning (a collection of) atoms, | 93 | * In general we have assertion returning (a collection of) atoms, |
94 | * while other axioms that generate rules. | 94 | * while other axioms that generate rules. |
95 | */ | 95 | */ |
96 | private type Result = Either[List[TupleTableAtom], List[Rule]] | 96 | protected type Result = (List[TupleTableAtom], List[Rule]) |
97 | protected def Result(): Result = (List(), List()) | ||
98 | protected def ResultF(atoms: List[TupleTableAtom]): Result = (atoms, List()) | ||
99 | protected def ResultR(rules: List[Rule]): Result = (List(), rules) | ||
97 | 100 | ||
98 | /** Converts a | 101 | /** Converts a |
99 | * [[org.semanticweb.owlapi.model.OWLLogicalAxiom OWLLogicalAxiom]] | 102 | * [[org.semanticweb.owlapi.model.OWLLogicalAxiom OWLLogicalAxiom]] |
@@ -145,35 +148,32 @@ object RDFoxConverter { | |||
145 | val (sup, ext) = | 148 | val (sup, ext) = |
146 | convert(a.getSuperClass, term, unsafe, skolem, suffix) | 149 | convert(a.getSuperClass, term, unsafe, skolem, suffix) |
147 | val rule = Rule.create(sup, ext ::: sub) | 150 | val rule = Rule.create(sup, ext ::: sub) |
148 | Right(List(rule)) | 151 | ResultR(List(rule)) |
149 | } | 152 | } |
150 | 153 | ||
151 | // cannot be left | 154 | // cannot be left |
152 | // http://www.w3.org/TR/owl2-syntax/#Equivalent_Classes | 155 | // http://www.w3.org/TR/owl2-syntax/#Equivalent_Classes |
153 | case a: OWLEquivalentClassesAxiom => | 156 | case a: OWLEquivalentClassesAxiom => { |
154 | Right( | 157 | val (atoms, rules) = a.asPairwiseAxioms |
155 | a.asPairwiseAxioms | 158 | .flatMap(_.asOWLSubClassOfAxioms) |
156 | .flatMap(_.asOWLSubClassOfAxioms) | 159 | .map(convert(_, term, unsafe, skolem, suffix)) |
157 | .map(convert(_, term, unsafe, skolem, suffix)) | 160 | .unzip |
158 | .collect { case Right(rs) => rs } | 161 | (atoms.flatten, rules.flatten) |
159 | .flatten | 162 | } |
160 | ) | ||
161 | 163 | ||
162 | case a: OWLEquivalentObjectPropertiesAxiom => { | 164 | case a: OWLEquivalentObjectPropertiesAxiom => { |
163 | Right( | 165 | val (atoms, rules) = a.asPairwiseAxioms |
164 | a.asPairwiseAxioms | 166 | .flatMap(_.asSubObjectPropertyOfAxioms) |
165 | .flatMap(_.asSubObjectPropertyOfAxioms) | 167 | .map(convert(_, term, unsafe, skolem, suffix)) |
166 | .map(convert(_, term, unsafe, skolem, suffix)) | 168 | .unzip |
167 | .collect { case Right(rs) => rs } | 169 | (atoms.flatten, rules.flatten) |
168 | .flatten | ||
169 | ) | ||
170 | } | 170 | } |
171 | 171 | ||
172 | case a: OWLSubObjectPropertyOfAxiom => { | 172 | case a: OWLSubObjectPropertyOfAxiom => { |
173 | val term1 = RSAOntology.genFreshVariable() | 173 | val term1 = RSAOntology.genFreshVariable() |
174 | val body = convert(a.getSubProperty, term, term1, suffix) | 174 | val body = convert(a.getSubProperty, term, term1, suffix) |
175 | val head = convert(a.getSuperProperty, term, term1, suffix) | 175 | val head = convert(a.getSuperProperty, term, term1, suffix) |
176 | Right(List(Rule.create(head, body))) | 176 | ResultR(List(Rule.create(head, body))) |
177 | } | 177 | } |
178 | 178 | ||
179 | case a: OWLObjectPropertyDomainAxiom => | 179 | case a: OWLObjectPropertyDomainAxiom => |
@@ -183,19 +183,18 @@ object RDFoxConverter { | |||
183 | val term1 = RSAOntology.genFreshVariable() | 183 | val term1 = RSAOntology.genFreshVariable() |
184 | val (res, ext) = convert(a.getRange, term, unsafe, skolem, suffix) | 184 | val (res, ext) = convert(a.getRange, term, unsafe, skolem, suffix) |
185 | val prop = convert(a.getProperty, term1, term, suffix) | 185 | val prop = convert(a.getProperty, term1, term, suffix) |
186 | Right(List(Rule.create(res, prop :: ext))) | 186 | ResultR(List(Rule.create(res, prop :: ext))) |
187 | } | 187 | } |
188 | 188 | ||
189 | case a: OWLDataPropertyDomainAxiom => | 189 | case a: OWLDataPropertyDomainAxiom => |
190 | convert(a.asOWLSubClassOfAxiom, term, unsafe, skolem, suffix) | 190 | convert(a.asOWLSubClassOfAxiom, term, unsafe, skolem, suffix) |
191 | 191 | ||
192 | case a: OWLInverseObjectPropertiesAxiom => | 192 | case a: OWLInverseObjectPropertiesAxiom => { |
193 | Right( | 193 | val (atoms, rules) = a.asSubObjectPropertyOfAxioms |
194 | a.asSubObjectPropertyOfAxioms | 194 | .map(convert(_, term, unsafe, skolem, suffix)) |
195 | .map(convert(_, term, unsafe, skolem, suffix)) | 195 | .unzip |
196 | .collect { case Right(rs) => rs } | 196 | (atoms.flatten, rules.flatten) |
197 | .flatten | 197 | } |
198 | ) | ||
199 | 198 | ||
200 | case a: OWLClassAssertionAxiom => { | 199 | case a: OWLClassAssertionAxiom => { |
201 | val ind = a.getIndividual | 200 | val ind = a.getIndividual |
@@ -204,20 +203,20 @@ object RDFoxConverter { | |||
204 | val cls = a.getClassExpression | 203 | val cls = a.getClassExpression |
205 | val (res, _) = | 204 | val (res, _) = |
206 | convert(cls, i.getIRI, unsafe, SkolemStrategy.None, suffix) | 205 | convert(cls, i.getIRI, unsafe, SkolemStrategy.None, suffix) |
207 | Left(res) | 206 | ResultF(res) |
208 | } | 207 | } |
209 | case _ => Left(List()) | 208 | case _ => Result() |
210 | } | 209 | } |
211 | } | 210 | } |
212 | 211 | ||
213 | case a: OWLObjectPropertyAssertionAxiom => | 212 | case a: OWLObjectPropertyAssertionAxiom => |
214 | if (!a.getSubject.isNamed || !a.getObject.isNamed) | 213 | if (!a.getSubject.isNamed || !a.getObject.isNamed) |
215 | Left(List()) | 214 | Result() |
216 | else { | 215 | else { |
217 | val subj = a.getSubject.asOWLNamedIndividual.getIRI | 216 | val subj = a.getSubject.asOWLNamedIndividual.getIRI |
218 | val obj = a.getObject.asOWLNamedIndividual.getIRI | 217 | val obj = a.getObject.asOWLNamedIndividual.getIRI |
219 | val prop = convert(a.getProperty, subj, obj, suffix) | 218 | val prop = convert(a.getProperty, subj, obj, suffix) |
220 | Left(List(prop)) | 219 | ResultF(List(prop)) |
221 | } | 220 | } |
222 | 221 | ||
223 | /** Catch-all case for all unhandled axiom types. */ | 222 | /** Catch-all case for all unhandled axiom types. */ |