diff options
Diffstat (limited to 'src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala')
-rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | 64 |
1 files changed, 36 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 56fbac3..9ef8986 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
@@ -22,6 +22,7 @@ import org.semanticweb.owlapi.model.{IRI => OWLIRI} | |||
22 | import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl | 22 | import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl |
23 | 23 | ||
24 | import tech.oxfordsemantic.jrdfox.client.{UpdateType, DataStoreConnection} | 24 | import tech.oxfordsemantic.jrdfox.client.{UpdateType, DataStoreConnection} |
25 | import tech.oxfordsemantic.jrdfox.Prefixes | ||
25 | import tech.oxfordsemantic.jrdfox.logic.datalog.{ | 26 | import tech.oxfordsemantic.jrdfox.logic.datalog.{ |
26 | Rule, | 27 | Rule, |
27 | TupleTableAtom, | 28 | TupleTableAtom, |
@@ -302,40 +303,47 @@ class RSAOntology(val ontology: OWLOntology) extends RSAAxiom { | |||
302 | val (server, data) = RDFoxHelpers.openConnection("AnswerComputation") | 303 | val (server, data) = RDFoxHelpers.openConnection("AnswerComputation") |
303 | data.addRules(this.canonicalModel.rules) | 304 | data.addRules(this.canonicalModel.rules) |
304 | data.addRules(this.filteringProgram(query).rules) | 305 | data.addRules(this.filteringProgram(query).rules) |
305 | new ConjunctiveQueryAnswers( | 306 | val answers = RDFoxHelpers |
306 | query.boolean, | 307 | .submitQuery( |
307 | queryInternalPredicate(data, "Ans", query.answer.size) | 308 | data, |
308 | ) | 309 | RDFoxHelpers.buildDescriptionQuery("Ans", query.answer.size), |
310 | RSA.Prefixes | ||
311 | ) | ||
312 | .map( | ||
313 | new ConjunctiveQueryAnswers(query.boolean, _) | ||
314 | ) | ||
315 | .get | ||
316 | RDFoxHelpers.closeConnection(server, data) | ||
317 | answers | ||
309 | } | 318 | } |
310 | 319 | ||
311 | /** Returns instances of a reified predicate | 320 | /** Query the logic program used to compute answers to a given CQ. |
321 | * | ||
322 | * This method has been introduced mostly for debugging purposes. | ||
312 | * | 323 | * |
313 | * Predicated with arity higher than 2 are internally reified to be | 324 | * @param cq a CQ used to compute the environment. |
314 | * compatible with RDFox engine. This helper queries for predicate | 325 | * @param query query to be executed against the environment |
315 | * instances and returns a set of un-reified answers. | 326 | * @param prefixes additional prefixes for the query. It defaults to |
327 | * an empty set. | ||
328 | * @param opts additional options to RDFox. | ||
329 | * @return a collection of answers to the input query. | ||
316 | * | 330 | * |
317 | * @param data open datastore connection to RDFox | 331 | * @todo this function currently fails because RDFox reports a |
318 | * @param pred name of the predicate | 332 | * datastore duplication. |
319 | * @param arity arity of the predicate | ||
320 | * @param opts additional options to RDFox | ||
321 | * @return a collection of instances of the given predicate | ||
322 | */ | 333 | */ |
323 | private def queryInternalPredicate( | 334 | def queryEnvironment( |
324 | data: DataStoreConnection, | 335 | cq: ConjunctiveQuery, |
325 | pred: String, | 336 | query: String, |
326 | arity: Int, | 337 | prefixes: Prefixes = new Prefixes(), |
327 | opts: ju.Map[String, String] = new ju.HashMap[String, String]() | 338 | opts: ju.Map[String, String] = new ju.HashMap[String, String]() |
328 | ): Seq[Seq[Resource]] = { | 339 | ): Option[Seq[Seq[Resource]]] = { |
329 | val query = | 340 | import implicits.JavaCollections._ |
330 | if (arity > 0) { | 341 | val (server, data) = RDFoxHelpers.openConnection("AnswerComputation") |
331 | (0 until arity).mkString("SELECT ?X", " ?X", "\n") + | 342 | data.addRules(this.canonicalModel.rules) |
332 | (0 until arity) | 343 | data.addRules(this.filteringProgram(cq).rules) |
333 | .map(i => s"?S rsa:${pred :: Nth(i)} ?X$i .") | 344 | val answers = RDFoxHelpers.submitQuery(data, query, prefixes, opts) |
334 | .mkString("WHERE {\n", "\n", "\n}") | 345 | RDFoxHelpers.closeConnection(server, data) |
335 | } else { | 346 | answers |
336 | s"ASK { ?X a rsa:$pred }" | ||
337 | } | ||
338 | RDFoxHelpers.submitQuery(data, query, RSA.Prefixes).get | ||
339 | } | 347 | } |
340 | 348 | ||
341 | def self(axiom: OWLSubClassOfAxiom): Set[Term] = { | 349 | def self(axiom: OWLSubClassOfAxiom): Set[Term] = { |