diff options
4 files changed, 31 insertions, 14 deletions
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 f2d1a5d..b749401 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | |||
@@ -118,9 +118,23 @@ object RSAComb extends App { | |||
118 | 118 | ||
119 | ConjunctiveQuery.parse(query) match { | 119 | ConjunctiveQuery.parse(query) match { |
120 | case Some(query) => { | 120 | case Some(query) => { |
121 | // Retrieve answers | ||
121 | val answers = rsa ask query | 122 | val answers = rsa ask query |
122 | Logger.print(s"$answers", Logger.VERBOSE) | 123 | Logger.print(s"$answers", Logger.VERBOSE) |
123 | Logger print s"Number of answers: ${answers.length} (${answers.lengthWithMultiplicity})" | 124 | Logger print s"Number of answers: ${answers.length} (${answers.lengthWithMultiplicity})" |
125 | // Retrieve unfiltered answers | ||
126 | val unfiltered = rsa.queryDataStore( | ||
127 | """ | ||
128 | SELECT (count(?K) as ?COUNT) | ||
129 | WHERE { | ||
130 | ?K a rsa:QM . | ||
131 | } | ||
132 | """, | ||
133 | RSA.Prefixes | ||
134 | ) | ||
135 | unfiltered.foreach((u) => | ||
136 | Logger print s"Number of unfiltered answers: ${u.head._2}" | ||
137 | ) | ||
124 | } | 138 | } |
125 | case None => | 139 | case None => |
126 | throw new RuntimeException("Submitted query is not conjunctive") | 140 | throw new RuntimeException("Submitted query is not conjunctive") |
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 247b5d5..bbbbcf3 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
@@ -591,7 +591,6 @@ class RSAOntology(val axioms: List[OWLLogicalAxiom], val datafiles: File*) { | |||
591 | * [[uk.ac.ox.cs.rsacomb.RSAOntology.ask RSAOntology.ask]]. | 591 | * [[uk.ac.ox.cs.rsacomb.RSAOntology.ask RSAOntology.ask]]. |
592 | * @note This method has been introduced mostly for debugging purposes. | 592 | * @note This method has been introduced mostly for debugging purposes. |
593 | * | 593 | * |
594 | * @param cq a CQ used to compute the environment. | ||
595 | * @param query query to be executed against the environment | 594 | * @param query query to be executed against the environment |
596 | * @param prefixes additional prefixes for the query. It defaults to | 595 | * @param prefixes additional prefixes for the query. It defaults to |
597 | * an empty set. | 596 | * an empty set. |
@@ -599,7 +598,6 @@ class RSAOntology(val axioms: List[OWLLogicalAxiom], val datafiles: File*) { | |||
599 | * @return a collection of answers to the input query. | 598 | * @return a collection of answers to the input query. |
600 | */ | 599 | */ |
601 | def queryDataStore( | 600 | def queryDataStore( |
602 | cq: ConjunctiveQuery, | ||
603 | query: String, | 601 | query: String, |
604 | prefixes: Prefixes = new Prefixes(), | 602 | prefixes: Prefixes = new Prefixes(), |
605 | opts: ju.Map[String, String] = new ju.HashMap[String, String]() | 603 | opts: ju.Map[String, String] = new ju.HashMap[String, String]() |
@@ -623,7 +621,7 @@ class RSAOntology(val axioms: List[OWLLogicalAxiom], val datafiles: File*) { | |||
623 | cq: ConjunctiveQuery | 621 | cq: ConjunctiveQuery |
624 | ): Option[Seq[(Long, Seq[Resource])]] = { | 622 | ): Option[Seq[(Long, Seq[Resource])]] = { |
625 | val query = RDFoxUtil.buildDescriptionQuery("QM", cq.variables.length) | 623 | val query = RDFoxUtil.buildDescriptionQuery("QM", cq.variables.length) |
626 | queryDataStore(cq, query, RSA.Prefixes) | 624 | queryDataStore(query, RSA.Prefixes) |
627 | } | 625 | } |
628 | 626 | ||
629 | def self(axiom: OWLSubClassOfAxiom): Set[Term] = { | 627 | def self(axiom: OWLSubClassOfAxiom): Set[Term] = { |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/filtering/RevisedFilteringProgram.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/filtering/RevisedFilteringProgram.scala index 3773423..8787b43 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/filtering/RevisedFilteringProgram.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/filtering/RevisedFilteringProgram.scala | |||
@@ -401,13 +401,14 @@ class RevisedFilteringProgram(val query: ConjunctiveQuery) | |||
401 | val answerQuery: String = { | 401 | val answerQuery: String = { |
402 | val arity = query.answer.size | 402 | val arity = query.answer.size |
403 | if (arity > 0) { | 403 | if (arity > 0) { |
404 | val variables = (0 until arity).mkString("?X", " ?X", "") | 404 | val answer = query.answer mkString " " |
405 | val bounded = query.bounded mkString " " | ||
405 | s""" | 406 | s""" |
406 | SELECT ${query.answer mkString ""} | 407 | SELECT $answer |
407 | WHERE { | 408 | WHERE { |
408 | ?K a rsa:Ans . | 409 | ?K a rsa:Ans . |
409 | TT <http://oxfordsemantic.tech/RDFox#SKOLEM> { ${query.answer mkString ""} ${query.bounded mkString ""} ?K } . | 410 | TT <http://oxfordsemantic.tech/RDFox#SKOLEM> { $answer $bounded ?K } . |
410 | } | 411 | } |
411 | """ | 412 | """ |
412 | } else { | 413 | } else { |
413 | "ASK { ?X a rsa:Ans }" | 414 | "ASK { ?X a rsa:Ans }" |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala index 6833640..82aa971 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala | |||
@@ -275,12 +275,16 @@ object RDFoxUtil { | |||
275 | arity: Int | 275 | arity: Int |
276 | ): String = { | 276 | ): String = { |
277 | if (arity > 0) { | 277 | if (arity > 0) { |
278 | (0 until arity).mkString("SELECT ?X", " ?X", "\n") + | 278 | val variables = (0 until arity).mkString("?X", " ?X", "") |
279 | (0 until arity) | 279 | s""" |
280 | .map(i => s"?S rsa:${pred :: Nth(i)} ?X$i .") | 280 | SELECT $variables |
281 | .mkString("WHERE {\n", "\n", "\n}") | 281 | WHERE { |
282 | ?K a rsa:$pred. | ||
283 | TT <http://oxfordsemantic.tech/RDFox#SKOLEM> { $variables ?K } . | ||
284 | } | ||
285 | """ | ||
282 | } else { | 286 | } else { |
283 | s"ASK { ?X a rsa:$pred }" | 287 | "ASK { ?X a rsa:Ans }" |
284 | } | 288 | } |
285 | } | 289 | } |
286 | 290 | ||