From d5d60c5a2ec20896a824ba71a11c0e8c2d78a5ca Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Mon, 1 Nov 2021 16:58:09 +0000 Subject: Drop filtering tuple table when done with a query This avoids running out of memory on RDFox side when executing a use amount of queries. --- src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | 17 ----- .../scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | 78 +++------------------- 2 files changed, 11 insertions(+), 84 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 1aa748a..7eb39e8 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala @@ -59,7 +59,6 @@ object RSAComb extends App { ) val answers = rsa ask queries - Logger print s"Number of answers: ${answers.length}" /* Write answers to output file */ os.write( @@ -70,21 +69,5 @@ object RSAComb extends App { /* Generate simulation script */ Logger.generateSimulationScripts(data, queries) - - // Logger.print(s"$answers", Logger.VERBOSE) - // Logger print s"Number of answers: ${answers.length} (${answers.lengthWithMultiplicity})" - // Retrieve unfiltered answers - // val unfiltered = rsa.queryDataStore( - // """ - // SELECT (count(?K) as ?COUNT) - // WHERE { - // ?K a rsa:QM . - // } - // """, - // RSA.Prefixes - // ) - // unfiltered.foreach((u) => - // Logger print s"Number of unfiltered answers: ${u.head._2}" - // ) } } 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 a0d567e..f67eca9 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala @@ -635,9 +635,14 @@ class RSAOntology( Logger.write(canonicalModel.rules.mkString("\n"), "canonical_model.dlog") RDFoxUtil.addRules(data, this.canonicalModel.rules) + /* Finalise canonical model */ + data.clearRulesAxiomsExplicateFacts() + RDFoxUtil.closeConnection(server, data) (query => { + Logger print s"Query ID: ${query.id}" + val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) val filter = RSAOntology.filteringProgram(query) @@ -650,85 +655,24 @@ class RSAOntology( ) RDFoxUtil.addRules(data, filter.rules) - // TODO: We remove the rules, should we drop the tuple table as well? - //data.clearRulesAxiomsExplicateFacts() - /* Gather answers to the query */ val answers = RDFoxUtil .submitQuery(data, filter.answerQuery, RSA.Prefixes) .map(new ConjunctiveQueryAnswers(query, query.variables, _)) .get + /* Drop filtering named graph to avoid running out of memory */ + data.clearRulesAxiomsExplicateFacts() + data.deleteTupleTable(filter.target.getIRI) + RDFoxUtil.closeConnection(server, data) + Logger print s"Number of answers: ${answers.length}" + answers }) } - //def ask(query: ConjunctiveQuery): ConjunctiveQueryAnswers = Logger.timed( - // { - // val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) - // val canon = this.canonicalModel - // val filter = RSAOntology.filteringProgram(query) - - // /* Upload data from data file */ - // RDFoxUtil.addData(data, datafiles: _*) - - // RDFoxUtil printStatisticsFor data - - // /* Top / equality axiomatization */ - // RDFoxUtil.addRules(data, topAxioms ++ equalityAxioms) - - // /* Generate `named` predicates */ - // RDFoxUtil.addFacts(data, (individuals ++ literals) map RSA.Named) - // data.evaluateUpdate( - // null, // the base IRI for the query (if null, a default is used) - // RSA.Prefixes, - // "INSERT { ?X a rsa:Named } WHERE { ?X a owl:Thing }", - // new java.util.HashMap[String, String] - // ) - - // /* Add canonical model */ - // Logger print s"Canonical model rules: ${canon.rules.length}" - // RDFoxUtil.addRules(data, canon.rules) - - // Logger print s"Canonical model facts: ${canon.facts.length}" - // RDFoxUtil.addFacts(data, canon.facts) - - // RDFoxUtil printStatisticsFor data - - // //{ - // // import java.io.{PrintStream, FileOutputStream, File} - // // val rules1 = new FileOutputStream(new File("rules1-lubm200.dlog")) - // // val facts1 = new FileOutputStream(new File("facts1-lubm200.ttl")) - // // RDFoxUtil.export(data, rules1, facts1) - // // val rules2 = new PrintStream(new File("rules2-q34.dlog")) - // // rules2.print(filter.rules.mkString("\n")) - // //} - - // /* Add filtering program */ - // Logger print s"Filtering program rules: ${filter.rules.length}" - // RDFoxUtil.addRules(data, filter.rules) - - // RDFoxUtil printStatisticsFor data - - // /* Gather answers to the query */ - // val answers = { - // val ans = filter.answerQuery - // RDFoxUtil - // .submitQuery(data, ans, RSA.Prefixes) - // .map(new ConjunctiveQueryAnswers(query, query.variables, _)) - // .get - // } - - // RDFoxUtil.closeConnection(server, data) - - // answers - // }, - // "Answers computation", - // Logger.DEBUG - //) - /** Query the RDFox data store used for query answering. * * @note This method does not add any facts or rules to the data -- cgit v1.2.3