diff options
author | Federico Igne <git@federicoigne.com> | 2021-10-02 12:10:22 +0100 |
---|---|---|
committer | Federico Igne <git@federicoigne.com> | 2021-10-02 12:10:22 +0100 |
commit | d0868f102ac29a04461d9aa68230c0d4bb663426 (patch) | |
tree | 273ea59ffce755d9e4ceec9b47d2482f4bf0abca | |
parent | 19fcf57f84a04599062b0751cf781dd073ae360d (diff) | |
download | RSAComb-d0868f102ac29a04461d9aa68230c0d4bb663426.tar.gz RSAComb-d0868f102ac29a04461d9aa68230c0d4bb663426.zip |
Allow querying of a single query
-rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | 54 |
1 files changed, 36 insertions, 18 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 993e9df..21e0506 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
@@ -527,12 +527,22 @@ class RSAOntology(axioms: List[OWLLogicalAxiom], datafiles: List[File]) | |||
527 | def unfold(axiom: OWLSubClassOfAxiom): Set[Term] = | 527 | def unfold(axiom: OWLSubClassOfAxiom): Set[Term] = |
528 | this.self(axiom) | this.cycle(axiom) | 528 | this.self(axiom) | this.cycle(axiom) |
529 | 529 | ||
530 | /** Returns the answers to a single query | ||
531 | * | ||
532 | * @param queries a sequence of conjunctive queries to answer. | ||
533 | * @return a collection of answers for each query. | ||
534 | */ | ||
535 | def ask(query: ConjunctiveQuery): ConjunctiveQueryAnswers = this._ask(query) | ||
536 | |||
530 | /** Returns the answers to a collection of queries | 537 | /** Returns the answers to a collection of queries |
531 | * | 538 | * |
532 | * @param queries a sequence of conjunctive queries to answer. | 539 | * @param queries a sequence of conjunctive queries to answer. |
533 | * @return a collection of answers for each query. | 540 | * @return a collection of answers for each query. |
534 | */ | 541 | */ |
535 | def ask(queries: Seq[ConjunctiveQuery]): Seq[ConjunctiveQueryAnswers] = { | 542 | def ask(queries: Seq[ConjunctiveQuery]): Seq[ConjunctiveQueryAnswers] = |
543 | queries map _ask | ||
544 | |||
545 | private lazy val _ask: ConjunctiveQuery => ConjunctiveQueryAnswers = { | ||
536 | /* Open connection with RDFox server */ | 546 | /* Open connection with RDFox server */ |
537 | val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) | 547 | val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) |
538 | 548 | ||
@@ -567,23 +577,31 @@ class RSAOntology(axioms: List[OWLLogicalAxiom], datafiles: List[File]) | |||
567 | Logger print s"Canonical model facts: ${this.canonicalModel.facts.length}" | 577 | Logger print s"Canonical model facts: ${this.canonicalModel.facts.length}" |
568 | RDFoxUtil.addFacts(data, RSAOntology.CanonGraph, this.canonicalModel.facts) | 578 | RDFoxUtil.addFacts(data, RSAOntology.CanonGraph, this.canonicalModel.facts) |
569 | 579 | ||
570 | queries map { query => | 580 | /* Close connection with RDFox server */ |
571 | { | 581 | RDFoxUtil.closeConnection(server, data) |
572 | val filter = RSAOntology.filteringProgram(query) | 582 | |
573 | 583 | (query => { | |
574 | /* Add filtering program */ | 584 | /* Open connection with RDFox server */ |
575 | Logger print s"Filtering program rules: ${filter.rules.length}" | 585 | val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) |
576 | RDFoxUtil.addRules(data, filter.rules) | 586 | val filter = RSAOntology.filteringProgram(query) |
577 | // TODO: We remove the rules, should we drop the tuple table as well? | 587 | |
578 | data.clearRulesAxiomsExplicateFacts() | 588 | /* Add filtering program */ |
579 | 589 | Logger print s"Filtering program rules: ${filter.rules.length}" | |
580 | /* Gather answers to the query */ | 590 | RDFoxUtil.addRules(data, filter.rules) |
581 | RDFoxUtil | 591 | // TODO: We remove the rules, should we drop the tuple table as well? |
582 | .submitQuery(data, filter.answerQuery, RSA.Prefixes) | 592 | data.clearRulesAxiomsExplicateFacts() |
583 | .map(new ConjunctiveQueryAnswers(query, query.variables, _)) | 593 | |
584 | .get | 594 | /* Gather answers to the query */ |
585 | } | 595 | val answers = RDFoxUtil |
586 | } | 596 | .submitQuery(data, filter.answerQuery, RSA.Prefixes) |
597 | .map(new ConjunctiveQueryAnswers(query, query.variables, _)) | ||
598 | .get | ||
599 | |||
600 | /* Close connection with RDFox server */ | ||
601 | RDFoxUtil.closeConnection(server, data) | ||
602 | |||
603 | answers | ||
604 | }) | ||
587 | } | 605 | } |
588 | 606 | ||
589 | //def ask(query: ConjunctiveQuery): ConjunctiveQueryAnswers = Logger.timed( | 607 | //def ask(query: ConjunctiveQuery): ConjunctiveQueryAnswers = Logger.timed( |