diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-11-01 16:58:09 +0000 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-11-01 18:30:36 +0000 |
| commit | d5d60c5a2ec20896a824ba71a11c0e8c2d78a5ca (patch) | |
| tree | 204c2a5b57d7772a92f03974b6aed77269d2e137 | |
| parent | 356fd137648b703824b906e44ca5fce98b94169c (diff) | |
| download | RSAComb-d5d60c5a2ec20896a824ba71a11c0e8c2d78a5ca.tar.gz RSAComb-d5d60c5a2ec20896a824ba71a11c0e8c2d78a5ca.zip | |
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.
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | 17 | ||||
| -rw-r--r-- | src/main/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 { | |||
| 59 | ) | 59 | ) |
| 60 | 60 | ||
| 61 | val answers = rsa ask queries | 61 | val answers = rsa ask queries |
| 62 | Logger print s"Number of answers: ${answers.length}" | ||
| 63 | 62 | ||
| 64 | /* Write answers to output file */ | 63 | /* Write answers to output file */ |
| 65 | os.write( | 64 | os.write( |
| @@ -70,21 +69,5 @@ object RSAComb extends App { | |||
| 70 | 69 | ||
| 71 | /* Generate simulation script */ | 70 | /* Generate simulation script */ |
| 72 | Logger.generateSimulationScripts(data, queries) | 71 | Logger.generateSimulationScripts(data, queries) |
| 73 | |||
| 74 | // Logger.print(s"$answers", Logger.VERBOSE) | ||
| 75 | // Logger print s"Number of answers: ${answers.length} (${answers.lengthWithMultiplicity})" | ||
| 76 | // Retrieve unfiltered answers | ||
| 77 | // val unfiltered = rsa.queryDataStore( | ||
| 78 | // """ | ||
| 79 | // SELECT (count(?K) as ?COUNT) | ||
| 80 | // WHERE { | ||
| 81 | // ?K a rsa:QM . | ||
| 82 | // } | ||
| 83 | // """, | ||
| 84 | // RSA.Prefixes | ||
| 85 | // ) | ||
| 86 | // unfiltered.foreach((u) => | ||
| 87 | // Logger print s"Number of unfiltered answers: ${u.head._2}" | ||
| 88 | // ) | ||
| 89 | } | 72 | } |
| 90 | } | 73 | } |
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( | |||
| 635 | Logger.write(canonicalModel.rules.mkString("\n"), "canonical_model.dlog") | 635 | Logger.write(canonicalModel.rules.mkString("\n"), "canonical_model.dlog") |
| 636 | RDFoxUtil.addRules(data, this.canonicalModel.rules) | 636 | RDFoxUtil.addRules(data, this.canonicalModel.rules) |
| 637 | 637 | ||
| 638 | /* Finalise canonical model */ | ||
| 639 | data.clearRulesAxiomsExplicateFacts() | ||
| 640 | |||
| 638 | RDFoxUtil.closeConnection(server, data) | 641 | RDFoxUtil.closeConnection(server, data) |
| 639 | 642 | ||
| 640 | (query => { | 643 | (query => { |
| 644 | Logger print s"Query ID: ${query.id}" | ||
| 645 | |||
| 641 | val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) | 646 | val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) |
| 642 | 647 | ||
| 643 | val filter = RSAOntology.filteringProgram(query) | 648 | val filter = RSAOntology.filteringProgram(query) |
| @@ -650,85 +655,24 @@ class RSAOntology( | |||
| 650 | ) | 655 | ) |
| 651 | RDFoxUtil.addRules(data, filter.rules) | 656 | RDFoxUtil.addRules(data, filter.rules) |
| 652 | 657 | ||
| 653 | // TODO: We remove the rules, should we drop the tuple table as well? | ||
| 654 | //data.clearRulesAxiomsExplicateFacts() | ||
| 655 | |||
| 656 | /* Gather answers to the query */ | 658 | /* Gather answers to the query */ |
| 657 | val answers = RDFoxUtil | 659 | val answers = RDFoxUtil |
| 658 | .submitQuery(data, filter.answerQuery, RSA.Prefixes) | 660 | .submitQuery(data, filter.answerQuery, RSA.Prefixes) |
| 659 | .map(new ConjunctiveQueryAnswers(query, query.variables, _)) | 661 | .map(new ConjunctiveQueryAnswers(query, query.variables, _)) |
| 660 | .get | 662 | .get |
| 661 | 663 | ||
| 664 | /* Drop filtering named graph to avoid running out of memory */ | ||
| 665 | data.clearRulesAxiomsExplicateFacts() | ||
| 666 | data.deleteTupleTable(filter.target.getIRI) | ||
| 667 | |||
| 662 | RDFoxUtil.closeConnection(server, data) | 668 | RDFoxUtil.closeConnection(server, data) |
| 663 | 669 | ||
| 670 | Logger print s"Number of answers: ${answers.length}" | ||
| 671 | |||
| 664 | answers | 672 | answers |
| 665 | }) | 673 | }) |
| 666 | } | 674 | } |
| 667 | 675 | ||
| 668 | //def ask(query: ConjunctiveQuery): ConjunctiveQueryAnswers = Logger.timed( | ||
| 669 | // { | ||
| 670 | // val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) | ||
| 671 | // val canon = this.canonicalModel | ||
| 672 | // val filter = RSAOntology.filteringProgram(query) | ||
| 673 | |||
| 674 | // /* Upload data from data file */ | ||
| 675 | // RDFoxUtil.addData(data, datafiles: _*) | ||
| 676 | |||
| 677 | // RDFoxUtil printStatisticsFor data | ||
| 678 | |||
| 679 | // /* Top / equality axiomatization */ | ||
| 680 | // RDFoxUtil.addRules(data, topAxioms ++ equalityAxioms) | ||
| 681 | |||
| 682 | // /* Generate `named` predicates */ | ||
| 683 | // RDFoxUtil.addFacts(data, (individuals ++ literals) map RSA.Named) | ||
| 684 | // data.evaluateUpdate( | ||
| 685 | // null, // the base IRI for the query (if null, a default is used) | ||
| 686 | // RSA.Prefixes, | ||
| 687 | // "INSERT { ?X a rsa:Named } WHERE { ?X a owl:Thing }", | ||
| 688 | // new java.util.HashMap[String, String] | ||
| 689 | // ) | ||
| 690 | |||
| 691 | // /* Add canonical model */ | ||
| 692 | // Logger print s"Canonical model rules: ${canon.rules.length}" | ||
| 693 | // RDFoxUtil.addRules(data, canon.rules) | ||
| 694 | |||
| 695 | // Logger print s"Canonical model facts: ${canon.facts.length}" | ||
| 696 | // RDFoxUtil.addFacts(data, canon.facts) | ||
| 697 | |||
| 698 | // RDFoxUtil printStatisticsFor data | ||
| 699 | |||
| 700 | // //{ | ||
| 701 | // // import java.io.{PrintStream, FileOutputStream, File} | ||
| 702 | // // val rules1 = new FileOutputStream(new File("rules1-lubm200.dlog")) | ||
| 703 | // // val facts1 = new FileOutputStream(new File("facts1-lubm200.ttl")) | ||
| 704 | // // RDFoxUtil.export(data, rules1, facts1) | ||
| 705 | // // val rules2 = new PrintStream(new File("rules2-q34.dlog")) | ||
| 706 | // // rules2.print(filter.rules.mkString("\n")) | ||
| 707 | // //} | ||
| 708 | |||
| 709 | // /* Add filtering program */ | ||
| 710 | // Logger print s"Filtering program rules: ${filter.rules.length}" | ||
| 711 | // RDFoxUtil.addRules(data, filter.rules) | ||
| 712 | |||
| 713 | // RDFoxUtil printStatisticsFor data | ||
| 714 | |||
| 715 | // /* Gather answers to the query */ | ||
| 716 | // val answers = { | ||
| 717 | // val ans = filter.answerQuery | ||
| 718 | // RDFoxUtil | ||
| 719 | // .submitQuery(data, ans, RSA.Prefixes) | ||
| 720 | // .map(new ConjunctiveQueryAnswers(query, query.variables, _)) | ||
| 721 | // .get | ||
| 722 | // } | ||
| 723 | |||
| 724 | // RDFoxUtil.closeConnection(server, data) | ||
| 725 | |||
| 726 | // answers | ||
| 727 | // }, | ||
| 728 | // "Answers computation", | ||
| 729 | // Logger.DEBUG | ||
| 730 | //) | ||
| 731 | |||
| 732 | /** Query the RDFox data store used for query answering. | 676 | /** Query the RDFox data store used for query answering. |
| 733 | * | 677 | * |
| 734 | * @note This method does not add any facts or rules to the data | 678 | * @note This method does not add any facts or rules to the data |
