diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-06-23 16:30:45 +0100 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-06-23 16:31:07 +0100 |
commit | b4ddcd3f489aa217cda56140274c5b6d91a75c10 (patch) | |
tree | 2f9b77ca5e9a15b3a8456798ab1bef4888be9c93 /src/main/scala/uk/ac/ox/cs | |
parent | 7ab2d819947c03a6618e273d5996a171f0217119 (diff) | |
download | RSAComb-b4ddcd3f489aa217cda56140274c5b6d91a75c10.tar.gz RSAComb-b4ddcd3f489aa217cda56140274c5b6d91a75c10.zip |
Fix automatic query building
The API for the SKOLEM operator is changed in RDFox but the helper
functions using it were not ported to the new syntax.
Diffstat (limited to 'src/main/scala/uk/ac/ox/cs')
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 74084af..f9de801 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | |||
@@ -119,9 +119,23 @@ object RSAComb extends App { | |||
119 | 119 | ||
120 | ConjunctiveQuery.parse(query) match { | 120 | ConjunctiveQuery.parse(query) match { |
121 | case Some(query) => { | 121 | case Some(query) => { |
122 | // Retrieve answers | ||
122 | val answers = rsa ask query | 123 | val answers = rsa ask query |
123 | Logger.print(s"$answers", Logger.VERBOSE) | 124 | Logger.print(s"$answers", Logger.VERBOSE) |
124 | Logger print s"Number of answers: ${answers.length} (${answers.lengthWithMultiplicity})" | 125 | Logger print s"Number of answers: ${answers.length} (${answers.lengthWithMultiplicity})" |
126 | // Retrieve unfiltered answers | ||
127 | val unfiltered = rsa.queryDataStore( | ||
128 | """ | ||
129 | SELECT (count(?K) as ?COUNT) | ||
130 | WHERE { | ||
131 | ?K a rsa:QM . | ||
132 | } | ||
133 | """, | ||
134 | RSA.Prefixes | ||
135 | ) | ||
136 | unfiltered.foreach((u) => | ||
137 | Logger print s"Number of unfiltered answers: ${u.head._2}" | ||
138 | ) | ||
125 | } | 139 | } |
126 | case None => | 140 | case None => |
127 | throw new RuntimeException("Submitted query is not conjunctive") | 141 | 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 c7b3bf0..0e10f89 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
@@ -556,7 +556,6 @@ class RSAOntology(val original: OWLOntology, val datafiles: File*) { | |||
556 | * [[uk.ac.ox.cs.rsacomb.RSAOntology.ask RSAOntology.ask]]. | 556 | * [[uk.ac.ox.cs.rsacomb.RSAOntology.ask RSAOntology.ask]]. |
557 | * @note This method has been introduced mostly for debugging purposes. | 557 | * @note This method has been introduced mostly for debugging purposes. |
558 | * | 558 | * |
559 | * @param cq a CQ used to compute the environment. | ||
560 | * @param query query to be executed against the environment | 559 | * @param query query to be executed against the environment |
561 | * @param prefixes additional prefixes for the query. It defaults to | 560 | * @param prefixes additional prefixes for the query. It defaults to |
562 | * an empty set. | 561 | * an empty set. |
@@ -564,7 +563,6 @@ class RSAOntology(val original: OWLOntology, val datafiles: File*) { | |||
564 | * @return a collection of answers to the input query. | 563 | * @return a collection of answers to the input query. |
565 | */ | 564 | */ |
566 | def queryDataStore( | 565 | def queryDataStore( |
567 | cq: ConjunctiveQuery, | ||
568 | query: String, | 566 | query: String, |
569 | prefixes: Prefixes = new Prefixes(), | 567 | prefixes: Prefixes = new Prefixes(), |
570 | opts: ju.Map[String, String] = new ju.HashMap[String, String]() | 568 | opts: ju.Map[String, String] = new ju.HashMap[String, String]() |
@@ -588,7 +586,7 @@ class RSAOntology(val original: OWLOntology, val datafiles: File*) { | |||
588 | cq: ConjunctiveQuery | 586 | cq: ConjunctiveQuery |
589 | ): Option[Seq[(Long, Seq[Resource])]] = { | 587 | ): Option[Seq[(Long, Seq[Resource])]] = { |
590 | val query = RDFoxUtil.buildDescriptionQuery("QM", cq.variables.length) | 588 | val query = RDFoxUtil.buildDescriptionQuery("QM", cq.variables.length) |
591 | queryDataStore(cq, query, RSA.Prefixes) | 589 | queryDataStore(query, RSA.Prefixes) |
592 | } | 590 | } |
593 | 591 | ||
594 | def self(axiom: OWLSubClassOfAxiom): Set[Term] = { | 592 | 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 | ||