aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/rsacomb/RSAOntology.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/rsacomb/RSAOntology.scala')
-rw-r--r--src/main/scala/rsacomb/RSAOntology.scala105
1 files changed, 5 insertions, 100 deletions
diff --git a/src/main/scala/rsacomb/RSAOntology.scala b/src/main/scala/rsacomb/RSAOntology.scala
index e49d4ac..efd6e7f 100644
--- a/src/main/scala/rsacomb/RSAOntology.scala
+++ b/src/main/scala/rsacomb/RSAOntology.scala
@@ -28,7 +28,9 @@ trait RSAOntology {
28 /* Implements additional features to reason about RSA ontologies 28 /* Implements additional features to reason about RSA ontologies
29 * on top of `OWLOntology` from the OWLAPI. 29 * on top of `OWLOntology` from the OWLAPI.
30 */ 30 */
31 implicit class RSAOntology(ontology: OWLOntology) extends RSAAxiom { 31 implicit class RSAOntology(ontology: OWLOntology)
32 extends RSAAxiom
33 with RDFTriple {
32 34
33 /* Steps for RSA check 35 /* Steps for RSA check
34 * 1) convert ontology axioms into LP rules 36 * 1) convert ontology axioms into LP rules
@@ -224,28 +226,6 @@ trait RSAOntology {
224 .toList 226 .toList
225 } 227 }
226 228
227 // Is this the best way to determine if an atom is an RDF triple?
228 // Note that we can't use `getNumberOfArguments()` because is not
229 // "consistent":
230 // - for an atom created with `rdf(<term1>, <term2>, <term3>)`,
231 // `getNumberOfArguments` returns 3
232 // - for an atom created with `Atom.create(<tupletablename>, <term1>,
233 // <term2>, <term3>)`, `getNumberOfArguments()` returns 3
234 //
235 // This is probably because `Atom.rdf(...) is implemented as:
236 // ```scala
237 // def rdf(term1: Term, term2: Term, term3: Term): Atom =
238 // Atom.create(TupleTableName.create("internal:triple"), term1, term2, term3)
239 // ```
240 def isRdfTriple(atom: Atom): Boolean =
241 atom.getTupleTableName.getIRI.equals("internal:triple")
242
243 def isClassAssertion(atom: Atom): Boolean =
244 isRdfTriple(atom) && atom.getArgument(1).equals(IRI.RDF_TYPE)
245
246 def isRoleAssertion(atom: Atom): Boolean =
247 isRdfTriple(atom) && !atom.getArgument(1).equals(IRI.RDF_TYPE)
248
249 def reify( 229 def reify(
250 formula: BodyFormula, 230 formula: BodyFormula,
251 head: Boolean 231 head: Boolean
@@ -253,7 +233,7 @@ trait RSAOntology {
253 def default[A <: BodyFormula](x: A) = Unaltered(x) 233 def default[A <: BodyFormula](x: A) = Unaltered(x)
254 formula match { 234 formula match {
255 case a: Atom => { 235 case a: Atom => {
256 if (!isRdfTriple(a)) { 236 if (!a.isRdfTriple) {
257 if (head) { 237 if (head) {
258 val b = getBindAtom(a) 238 val b = getBindAtom(a)
259 ReifiedHead(b, reifyAtom(a, b.getBoundVariable)) 239 ReifiedHead(b, reifyAtom(a, b.getBoundVariable))
@@ -293,83 +273,8 @@ trait RSAOntology {
293 Rule.create(head.asJava, (skols ++ body).asJava) 273 Rule.create(head.asJava, (skols ++ body).asJava)
294 } 274 }
295 275
296 def formulaToRuleBody(body: Formula): List[BodyFormula] = {
297 body match {
298 case a: BodyFormula => List(a);
299 case a: Conjunction =>
300 a.getConjuncts().asScala.toList.flatMap(formulaToRuleBody(_));
301 case _ => List() /* We don't handle this for now */
302 }
303 }
304
305 val body = formulaToRuleBody(query.getQueryFormula)
306 val bounded: List[Term] = List()
307 val answer: List[Term] = query.getAnswerVariables.asScala.toList
308 def id(t1: Term, t2: Term) =
309 Atom.create(
310 TupleTableName.create("http://127.0.0.1/ID"),
311 (bounded ++ answer).appendedAll(List(t1, t2)).asJava
312 )
313 def tq(suffix: String, t1: Term, t2: Term) =
314 Atom.create(
315 TupleTableName.create(s"http://127.0.0.1/TQ$suffix"),
316 (bounded ++ answer).appendedAll(List(t1, t2)).asJava
317 )
318 def aq(suffix: String, t1: Term, t2: Term) =
319 Atom.create(
320 TupleTableName.create(s"http://127.0.0.1/AQ$suffix"),
321 (bounded ++ answer).appendedAll(List(t1, t2)).asJava
322 )
323 val qm =
324 Atom.create(TupleTableName.create("QM"), (bounded ++ answer).asJava)
325
326 /* Filtering program */
327 val rule1 = Rule.create(qm, body.asJava)
328 val rule3a =
329 for ((v, i) <- answer.zipWithIndex)
330 yield Rule.create(
331 id(
332 IRI.create(s"http://127.0.0.1/$i"),
333 IRI.create(s"http://127.0.0.1/$i")
334 ),
335 qm,
336 Negation.create(
337 Atom.rdf(v, IRI.RDF_TYPE, IRI.create("http://127.0.0.1/NI"))
338 )
339 )
340 val rule3b = Rule.create(
341 id(Variable.create("V"), Variable.create("U")),
342 id(Variable.create("U"), Variable.create("V"))
343 )
344 val rule3c = Rule.create(
345 id(Variable.create("U"), Variable.create("W")),
346 id(Variable.create("U"), Variable.create("V")),
347 id(Variable.create("V"), Variable.create("W"))
348 )
349 val rule7a =
350 for (r <- Seq("f", "b"))
351 yield Rule.create(
352 tq(r, Variable.create("U"), Variable.create("V")),
353 aq(r, Variable.create("U"), Variable.create("V"))
354 )
355 val rule7b =
356 for (r <- Seq("f", "b"))
357 yield Rule.create(
358 tq(r, Variable.create("U"), Variable.create("W")),
359 aq(r, Variable.create("U"), Variable.create("V")),
360 tq(r, Variable.create("V"), Variable.create("W"))
361 )
362
363 var rules: List[Rule] =
364 List.empty
365 .prependedAll(rule7b)
366 .prependedAll(rule7a)
367 .prepended(rule3c)
368 .prepended(rule3b)
369 .prependedAll(rule3a)
370 .prepended(rule1)
371
372 // DEBUG 276 // DEBUG
277 val rules = FilteringProgram(query, List()).rules
373 println("FILTERING PROGRAM:") 278 println("FILTERING PROGRAM:")
374 rules.map(skolemizeRule(_)).foreach(println(_)) 279 rules.map(skolemizeRule(_)).foreach(println(_))
375 280