diff options
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/reasoner')
14 files changed, 644 insertions, 671 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java index 9b862ce..ef9338a 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java | |||
| @@ -1,7 +1,5 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner; | 1 | package uk.ac.ox.cs.pagoda.reasoner; |
| 2 | 2 | ||
| 3 | import java.util.LinkedList; | ||
| 4 | |||
| 5 | import org.semanticweb.HermiT.model.Atom; | 3 | import org.semanticweb.HermiT.model.Atom; |
| 6 | import org.semanticweb.HermiT.model.AtomicConcept; | 4 | import org.semanticweb.HermiT.model.AtomicConcept; |
| 7 | import org.semanticweb.HermiT.model.DLClause; | 5 | import org.semanticweb.HermiT.model.DLClause; |
| @@ -9,141 +7,146 @@ import org.semanticweb.HermiT.model.Variable; | |||
| 9 | import org.semanticweb.owlapi.model.OWLOntology; | 7 | import org.semanticweb.owlapi.model.OWLOntology; |
| 10 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; | 8 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; |
| 11 | import org.semanticweb.owlapi.model.OWLOntologyManager; | 9 | import org.semanticweb.owlapi.model.OWLOntologyManager; |
| 12 | 10 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | |
| 11 | import uk.ac.ox.cs.JRDFox.store.DataStore; | ||
| 12 | import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType; | ||
| 13 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; | 13 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; |
| 14 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | 14 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; |
| 15 | import uk.ac.ox.cs.pagoda.query.QueryManager; | 15 | import uk.ac.ox.cs.pagoda.query.QueryManager; |
| 16 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | 16 | import uk.ac.ox.cs.pagoda.query.QueryRecord; |
| 17 | import uk.ac.ox.cs.pagoda.reasoner.full.Checker; | 17 | import uk.ac.ox.cs.pagoda.reasoner.full.Checker; |
| 18 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | ||
| 18 | import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram; | 19 | import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram; |
| 19 | import uk.ac.ox.cs.pagoda.summary.HermitSummaryFilter; | 20 | import uk.ac.ox.cs.pagoda.summary.HermitSummaryFilter; |
| 20 | import uk.ac.ox.cs.pagoda.tracking.QueryTracker; | 21 | import uk.ac.ox.cs.pagoda.tracking.QueryTracker; |
| 21 | import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoder; | 22 | import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoder; |
| 22 | import uk.ac.ox.cs.pagoda.util.Timer; | 23 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 23 | import uk.ac.ox.cs.pagoda.util.Utility; | 24 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 24 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 25 | |
| 25 | import uk.ac.ox.cs.JRDFox.store.DataStore; | 26 | import java.util.LinkedList; |
| 26 | import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType; | ||
| 27 | 27 | ||
| 28 | public class ConsistencyManager { | 28 | public class ConsistencyManager { |
| 29 | 29 | ||
| 30 | protected MyQueryReasoner m_reasoner; | 30 | protected MyQueryReasoner m_reasoner; |
| 31 | protected QueryManager m_queryManager; | 31 | protected QueryManager m_queryManager; |
| 32 | 32 | ||
| 33 | Timer t = new Timer(); | 33 | Timer t = new Timer(); |
| 34 | QueryRecord fullQueryRecord; | ||
| 35 | QueryRecord[] botQueryRecords; | ||
| 36 | LinkedList<DLClause> toAddClauses; | ||
| 37 | boolean fragmentExtracted = false; | ||
| 34 | 38 | ||
| 35 | public ConsistencyManager(MyQueryReasoner reasoner) { | 39 | public ConsistencyManager(MyQueryReasoner reasoner) { |
| 36 | m_reasoner = reasoner; | 40 | m_reasoner = reasoner; |
| 37 | m_queryManager = reasoner.getQueryManager(); | 41 | m_queryManager = reasoner.getQueryManager(); |
| 38 | } | 42 | } |
| 39 | 43 | ||
| 40 | QueryRecord fullQueryRecord; | ||
| 41 | QueryRecord[] botQueryRecords; | ||
| 42 | |||
| 43 | LinkedList<DLClause> toAddClauses; | ||
| 44 | |||
| 45 | boolean checkRLLowerBound() { | 44 | boolean checkRLLowerBound() { |
| 46 | fullQueryRecord = m_queryManager.create(QueryRecord.botQueryText, 0); | 45 | fullQueryRecord = m_queryManager.create(QueryRecord.botQueryText, 0); |
| 47 | AnswerTuples iter = null; | 46 | AnswerTuples iter = null; |
| 48 | 47 | ||
| 49 | try { | 48 | try { |
| 50 | iter = m_reasoner.rlLowerStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); | 49 | iter = m_reasoner.rlLowerStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); |
| 51 | fullQueryRecord.updateLowerBoundAnswers(iter); | 50 | fullQueryRecord.updateLowerBoundAnswers(iter); |
| 52 | } finally { | 51 | } finally { |
| 53 | iter.dispose(); | 52 | iter.dispose(); |
| 54 | } | 53 | } |
| 55 | 54 | ||
| 56 | if (fullQueryRecord.getNoOfSoundAnswers() > 0) { | 55 | if (fullQueryRecord.getNoOfSoundAnswers() > 0) { |
| 57 | Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple()); | 56 | Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple()); |
| 58 | return unsatisfiability(t.duration()); | 57 | return false; |
| 59 | } | 58 | } |
| 60 | return true; | 59 | return true; |
| 61 | } | 60 | } |
| 62 | 61 | ||
| 63 | boolean checkELLowerBound() { | 62 | boolean checkELLowerBound() { |
| 64 | fullQueryRecord.updateLowerBoundAnswers(m_reasoner.elLowerStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables())); | 63 | fullQueryRecord.updateLowerBoundAnswers(m_reasoner.elLowerStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables())); |
| 65 | if (fullQueryRecord.getNoOfSoundAnswers() > 0) { | 64 | if (fullQueryRecord.getNoOfSoundAnswers() > 0) { |
| 66 | Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple()); | 65 | Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple()); |
| 67 | return unsatisfiability(t.duration()); | 66 | return true; |
| 68 | } | 67 | } |
| 69 | return true; | 68 | return true; |
| 70 | } | 69 | } |
| 71 | 70 | ||
| 72 | boolean checkLazyUpper() { | 71 | boolean checkUpper(BasicQueryEngine upperStore) { |
| 73 | if (m_reasoner.lazyUpperStore != null) { | 72 | if (upperStore != null) { |
| 74 | AnswerTuples tuples = null; | 73 | AnswerTuples tuples = null; |
| 75 | try { | 74 | try { |
| 76 | tuples = m_reasoner.lazyUpperStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); | 75 | tuples = upperStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); |
| 77 | if (!tuples.isValid()) { | 76 | if (!tuples.isValid()) { |
| 78 | Utility.logInfo("There are no contradictions derived in the lazy upper bound materialisation."); | 77 | Utility.logInfo("There are no contradictions derived in "+ upperStore.getName() +" materialisation."); |
| 79 | return satisfiability(t.duration()); | 78 | Utility.logDebug("The ontology and dataset is satisfiable."); |
| 79 | return true; | ||
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | finally { | 82 | finally { |
| 83 | if (tuples != null) tuples.dispose(); | 83 | if (tuples != null) tuples.dispose(); |
| 84 | } | 84 | } |
| 85 | } | 85 | } |
| 86 | return false; | 86 | return false; |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | void dispose() { | ||
| 90 | fullQueryRecord.dispose(); | ||
| 91 | } | ||
| 92 | |||
| 93 | // protected boolean unsatisfiability(double duration) { | ||
| 94 | // fullQueryRecord.dispose(); | ||
| 95 | // Utility.logDebug("The ontology and dataset is unsatisfiable."); | ||
| 96 | // return false; | ||
| 97 | // } | ||
| 98 | |||
| 99 | // protected boolean satisfiability(double duration) { | ||
| 100 | // fullQueryRecord.dispose(); | ||
| 101 | // Utility.logDebug("The ontology and dataset is satisfiable."); | ||
| 102 | // return true; | ||
| 103 | // } | ||
| 104 | |||
| 89 | boolean check() { | 105 | boolean check() { |
| 90 | // if (!checkRLLowerBound()) return false; | 106 | // if (!checkRLLowerBound()) return false; |
| 91 | // if (!checkELLowerBound()) return false; | 107 | // if (!checkELLowerBound()) return false; |
| 92 | // if (checkLazyUpper()) return true; | 108 | // if (checkLazyUpper()) return true; |
| 93 | AnswerTuples iter = null; | 109 | AnswerTuples iter = null; |
| 94 | 110 | ||
| 95 | try { | 111 | try { |
| 96 | iter = m_reasoner.trackingStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); | 112 | iter = |
| 113 | m_reasoner.trackingStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); | ||
| 97 | fullQueryRecord.updateUpperBoundAnswers(iter); | 114 | fullQueryRecord.updateUpperBoundAnswers(iter); |
| 98 | } finally { | 115 | } finally { |
| 99 | if (iter != null) iter.dispose(); | 116 | if(iter != null) iter.dispose(); |
| 100 | } | 117 | } |
| 101 | 118 | ||
| 102 | if (fullQueryRecord.getNoOfCompleteAnswers() == 0) | 119 | if(fullQueryRecord.getNoOfCompleteAnswers() == 0) |
| 103 | return satisfiability(t.duration()); | 120 | return true; |
| 104 | 121 | ||
| 105 | extractBottomFragment(); | 122 | extractBottomFragment(); |
| 106 | 123 | ||
| 107 | try { | 124 | try { |
| 108 | extractAxioms4Full(); | 125 | extractAxioms4Full(); |
| 109 | } catch (OWLOntologyCreationException e) { | 126 | } catch(OWLOntologyCreationException e) { |
| 110 | e.printStackTrace(); | 127 | e.printStackTrace(); |
| 111 | } | 128 | } |
| 112 | // fullQueryRecord.saveRelevantClause(); | 129 | // fullQueryRecord.saveRelevantClause(); |
| 113 | 130 | ||
| 114 | boolean satisfiability; | 131 | boolean satisfiability; |
| 115 | 132 | ||
| 116 | Checker checker; | 133 | Checker checker; |
| 117 | for (QueryRecord r: getQueryRecords()) { | 134 | for(QueryRecord r : getQueryRecords()) { |
| 118 | // TODO to be removed ... | 135 | // TODO to be removed ... |
| 119 | // r.saveRelevantOntology("bottom" + r.getQueryID() + ".owl"); | 136 | // r.saveRelevantOntology("bottom" + r.getQueryID() + ".owl"); |
| 120 | checker = new HermitSummaryFilter(r, true); // m_reasoner.factory.getSummarisedReasoner(r); | 137 | checker = new HermitSummaryFilter(r, true); // m_reasoner.factory.getSummarisedReasoner(r); |
| 121 | satisfiability = checker.isConsistent(); | 138 | satisfiability = checker.isConsistent(); |
| 122 | checker.dispose(); | 139 | checker.dispose(); |
| 123 | if (!satisfiability) return unsatisfiability(t.duration()); | 140 | if(!satisfiability) return false; |
| 124 | } | 141 | } |
| 125 | |||
| 126 | // Checker checker = m_reasoner.factory.getSummarisedReasoner(fullQueryRecord); | ||
| 127 | // boolean satisfiable = checker.isConsistent(); | ||
| 128 | // checker.dispose(); | ||
| 129 | // if (!satisfiable) return unsatisfiability(t.duration()); | ||
| 130 | |||
| 131 | return satisfiability(t.duration()); | ||
| 132 | } | ||
| 133 | 142 | ||
| 134 | protected boolean unsatisfiability(double duration) { | 143 | // Checker checker = m_reasoner.factory.getSummarisedReasoner(fullQueryRecord); |
| 135 | fullQueryRecord.dispose(); | 144 | // boolean satisfiable = checker.isConsistent(); |
| 136 | Utility.logDebug("The ontology and dataset is unsatisfiable."); | 145 | // checker.dispose(); |
| 137 | return false; | 146 | // if (!satisfiable) return unsatisfiability(t.duration()); |
| 138 | } | ||
| 139 | 147 | ||
| 140 | protected boolean satisfiability(double duration) { | ||
| 141 | fullQueryRecord.dispose(); | ||
| 142 | Utility.logDebug("The ontology and dataset is satisfiable."); | ||
| 143 | return true; | 148 | return true; |
| 144 | } | 149 | } |
| 145 | |||
| 146 | boolean fragmentExtracted = false; | ||
| 147 | 150 | ||
| 148 | public void extractBottomFragment() { | 151 | public void extractBottomFragment() { |
| 149 | if (fragmentExtracted) return ; | 152 | if (fragmentExtracted) return ; |
| @@ -174,7 +177,7 @@ public class ConsistencyManager { | |||
| 174 | int[] group = new int[number - 1]; | 177 | int[] group = new int[number - 1]; |
| 175 | for (int i = 0; i < number - 1; ++i) group[i] = i; | 178 | for (int i = 0; i < number - 1; ++i) group[i] = i; |
| 176 | for (int i = 0; i < number - 1; ++i) | 179 | for (int i = 0; i < number - 1; ++i) |
| 177 | if (tempQueryRecords[i].processed()) tempQueryRecords[i].dispose(); | 180 | if(tempQueryRecords[i].isProcessed()) tempQueryRecords[i].dispose(); |
| 178 | else if (group[i] == i) { | 181 | else if (group[i] == i) { |
| 179 | ++bottomNumber; | 182 | ++bottomNumber; |
| 180 | record = tempQueryRecords[i]; | 183 | record = tempQueryRecords[i]; |
| @@ -188,8 +191,8 @@ public class ConsistencyManager { | |||
| 188 | int bottomCounter = 0; | 191 | int bottomCounter = 0; |
| 189 | botQueryRecords = new QueryRecord[bottomNumber]; | 192 | botQueryRecords = new QueryRecord[bottomNumber]; |
| 190 | Variable X = Variable.create("X"); | 193 | Variable X = Variable.create("X"); |
| 191 | for (int i = 0; i < number - 1; ++i) | 194 | for (int i = 0; i < number - 1; ++i) |
| 192 | if (!tempQueryRecords[i].processed()) | 195 | if(!tempQueryRecords[i].isProcessed()) |
| 193 | if (group[i] == i) { | 196 | if (group[i] == i) { |
| 194 | botQueryRecords[bottomCounter] = record = tempQueryRecords[i]; | 197 | botQueryRecords[bottomCounter] = record = tempQueryRecords[i]; |
| 195 | record.resetInfo(QueryRecord.botQueryText.replace("Nothing", "Nothing_final" + (++bottomCounter)), 0, group[i] = bottomCounter); | 198 | record.resetInfo(QueryRecord.botQueryText.replace("Nothing", "Nothing_final" + (++bottomCounter)), 0, group[i] = bottomCounter); |
| @@ -288,5 +291,6 @@ public class ConsistencyManager { | |||
| 288 | public QueryRecord[] getQueryRecords() { | 291 | public QueryRecord[] getQueryRecords() { |
| 289 | return botQueryRecords; | 292 | return botQueryRecords; |
| 290 | } | 293 | } |
| 291 | 294 | ||
| 295 | |||
| 292 | } | 296 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager2.java b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager2.java deleted file mode 100644 index 9c335f3..0000000 --- a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager2.java +++ /dev/null | |||
| @@ -1,78 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner; | ||
| 2 | |||
| 3 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; | ||
| 4 | import org.semanticweb.owlapi.model.OWLOntologyManager; | ||
| 5 | |||
| 6 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 7 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 8 | import uk.ac.ox.cs.pagoda.reasoner.full.Checker; | ||
| 9 | import uk.ac.ox.cs.pagoda.summary.HermitSummaryFilter; | ||
| 10 | import uk.ac.ox.cs.pagoda.tracking.QueryTracker; | ||
| 11 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 12 | |||
| 13 | @Deprecated | ||
| 14 | public class ConsistencyManager2 extends ConsistencyManager { | ||
| 15 | |||
| 16 | public ConsistencyManager2(MyQueryReasoner reasoner) { | ||
| 17 | super(reasoner); | ||
| 18 | fragmentExtracted = true; | ||
| 19 | } | ||
| 20 | |||
| 21 | protected boolean unsatisfiability(double duration) { | ||
| 22 | Utility.logDebug("The ontology and dataset is unsatisfiable."); | ||
| 23 | return false; | ||
| 24 | } | ||
| 25 | |||
| 26 | protected boolean satisfiability(double duration) { | ||
| 27 | Utility.logDebug("The ontology and dataset is satisfiable."); | ||
| 28 | return true; | ||
| 29 | } | ||
| 30 | |||
| 31 | @Override | ||
| 32 | boolean check() { | ||
| 33 | // if (!checkRLLowerBound()) return false; | ||
| 34 | // if (!checkELLowerBound()) return false; | ||
| 35 | if (checkLazyUpper()) return true; | ||
| 36 | AnswerTuples iter = null; | ||
| 37 | |||
| 38 | try { | ||
| 39 | iter = m_reasoner.trackingStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); | ||
| 40 | fullQueryRecord.updateUpperBoundAnswers(iter); | ||
| 41 | } finally { | ||
| 42 | if (iter != null) iter.dispose(); | ||
| 43 | } | ||
| 44 | |||
| 45 | if (fullQueryRecord.getNoOfCompleteAnswers() == 0) | ||
| 46 | return satisfiability(t.duration()); | ||
| 47 | |||
| 48 | try { | ||
| 49 | extractAxioms(); | ||
| 50 | } catch (OWLOntologyCreationException e) { | ||
| 51 | e.printStackTrace(); | ||
| 52 | } | ||
| 53 | |||
| 54 | Checker checker = new HermitSummaryFilter(fullQueryRecord, true); // m_reasoner.factory.getSummarisedReasoner(fullQueryRecord); | ||
| 55 | // fullQueryRecord.saveRelevantOntology("fragment_bottom.owl"); | ||
| 56 | boolean satisfiable = checker.isConsistent(); | ||
| 57 | checker.dispose(); | ||
| 58 | if (!satisfiable) return unsatisfiability(t.duration()); | ||
| 59 | |||
| 60 | return satisfiability(t.duration()); | ||
| 61 | } | ||
| 62 | |||
| 63 | private void extractAxioms() throws OWLOntologyCreationException { | ||
| 64 | OWLOntologyManager manager = m_reasoner.encoder.getProgram().getOntology().getOWLOntologyManager(); | ||
| 65 | fullQueryRecord.setRelevantOntology(manager.createOntology()); | ||
| 66 | QueryTracker tracker = new QueryTracker(m_reasoner.encoder, m_reasoner.rlLowerStore, fullQueryRecord); | ||
| 67 | m_reasoner.encoder.setCurrentQuery(fullQueryRecord); | ||
| 68 | tracker.extract(m_reasoner.trackingStore, null, true); | ||
| 69 | } | ||
| 70 | |||
| 71 | @Override | ||
| 72 | public QueryRecord[] getQueryRecords() { | ||
| 73 | if (botQueryRecords == null) | ||
| 74 | botQueryRecords = new QueryRecord[] {fullQueryRecord}; | ||
| 75 | return botQueryRecords; | ||
| 76 | } | ||
| 77 | |||
| 78 | } | ||
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java index ab57ccf..f5a8093 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java | |||
| @@ -2,7 +2,6 @@ package uk.ac.ox.cs.pagoda.reasoner; | |||
| 2 | 2 | ||
| 3 | import org.semanticweb.karma2.profile.ELHOProfile; | 3 | import org.semanticweb.karma2.profile.ELHOProfile; |
| 4 | import org.semanticweb.owlapi.model.OWLOntology; | 4 | import org.semanticweb.owlapi.model.OWLOntology; |
| 5 | |||
| 6 | import uk.ac.ox.cs.pagoda.constraints.UnaryBottom; | 5 | import uk.ac.ox.cs.pagoda.constraints.UnaryBottom; |
| 7 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | 6 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; |
| 8 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | 7 | import uk.ac.ox.cs.pagoda.query.QueryRecord; |
| @@ -12,7 +11,7 @@ import uk.ac.ox.cs.pagoda.rules.LowerDatalogProgram; | |||
| 12 | import uk.ac.ox.cs.pagoda.util.Timer; | 11 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 13 | import uk.ac.ox.cs.pagoda.util.Utility; | 12 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 14 | 13 | ||
| 15 | public class ELHOQueryReasoner extends QueryReasoner { | 14 | class ELHOQueryReasoner extends QueryReasoner { |
| 16 | 15 | ||
| 17 | LowerDatalogProgram program; | 16 | LowerDatalogProgram program; |
| 18 | 17 | ||
| @@ -35,9 +34,9 @@ public class ELHOQueryReasoner extends QueryReasoner { | |||
| 35 | } finally { | 34 | } finally { |
| 36 | if (elAnswer != null) elAnswer.dispose(); | 35 | if (elAnswer != null) elAnswer.dispose(); |
| 37 | } | 36 | } |
| 38 | queryRecord.addProcessingTime(Step.ELLowerBound, t.duration()); | 37 | queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration()); |
| 39 | 38 | ||
| 40 | queryRecord.setDifficulty(Step.ELLowerBound); | 39 | queryRecord.setDifficulty(Step.EL_LOWER_BOUND); |
| 41 | queryRecord.markAsProcessed(); | 40 | queryRecord.markAsProcessed(); |
| 42 | } | 41 | } |
| 43 | 42 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java index 0d24a02..c74ea58 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java | |||
| @@ -2,7 +2,6 @@ package uk.ac.ox.cs.pagoda.reasoner; | |||
| 2 | 2 | ||
| 3 | import org.semanticweb.karma2.profile.ELHOProfile; | 3 | import org.semanticweb.karma2.profile.ELHOProfile; |
| 4 | import org.semanticweb.owlapi.model.OWLOntology; | 4 | import org.semanticweb.owlapi.model.OWLOntology; |
| 5 | |||
| 6 | import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; | 5 | import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; |
| 7 | import uk.ac.ox.cs.pagoda.owl.EqualitiesEliminator; | 6 | import uk.ac.ox.cs.pagoda.owl.EqualitiesEliminator; |
| 8 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | 7 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; |
| @@ -15,7 +14,7 @@ import uk.ac.ox.cs.pagoda.rules.DatalogProgram; | |||
| 15 | import uk.ac.ox.cs.pagoda.util.Timer; | 14 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 16 | import uk.ac.ox.cs.pagoda.util.Utility; | 15 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 17 | 16 | ||
| 18 | public class ELHOUQueryReasoner extends QueryReasoner { | 17 | class ELHOUQueryReasoner extends QueryReasoner { |
| 19 | 18 | ||
| 20 | DatalogProgram program; | 19 | DatalogProgram program; |
| 21 | 20 | ||
| @@ -26,81 +25,82 @@ public class ELHOUQueryReasoner extends QueryReasoner { | |||
| 26 | KarmaQueryEngine elLowerStore = null; | 25 | KarmaQueryEngine elLowerStore = null; |
| 27 | 26 | ||
| 28 | boolean multiStageTag, equalityTag; | 27 | boolean multiStageTag, equalityTag; |
| 29 | 28 | String originalMarkProgram; | |
| 29 | private Timer t = new Timer(); | ||
| 30 | |||
| 30 | public ELHOUQueryReasoner(boolean multiStageTag, boolean considerEqualities) { | 31 | public ELHOUQueryReasoner(boolean multiStageTag, boolean considerEqualities) { |
| 31 | this.multiStageTag = multiStageTag; | 32 | this.multiStageTag = multiStageTag; |
| 32 | this.equalityTag = considerEqualities; | 33 | this.equalityTag = considerEqualities; |
| 33 | rlLowerStore = new BasicQueryEngine("rl-lower-bound"); | 34 | rlLowerStore = new BasicQueryEngine("rl-lower-bound"); |
| 34 | elLowerStore = new KarmaQueryEngine("el-lower-bound"); | 35 | elLowerStore = new KarmaQueryEngine("el-lower-bound"); |
| 35 | 36 | ||
| 36 | if (!multiStageTag) | 37 | if(!multiStageTag) |
| 37 | rlUpperStore = new BasicQueryEngine("rl-upper-bound"); | 38 | rlUpperStore = new BasicQueryEngine("rl-upper-bound"); |
| 38 | else | 39 | else |
| 39 | rlUpperStore = new MultiStageQueryEngine("rl-upper-bound", false); | 40 | rlUpperStore = new MultiStageQueryEngine("rl-upper-bound", false); |
| 40 | } | 41 | } |
| 41 | |||
| 42 | private Timer t = new Timer(); | ||
| 43 | 42 | ||
| 44 | @Override | 43 | @Override |
| 45 | public void evaluate(QueryRecord queryRecord) { | 44 | public void evaluate(QueryRecord queryRecord) { |
| 46 | AnswerTuples rlAnswer = null; | 45 | AnswerTuples rlAnswer = null; |
| 47 | t.reset(); | 46 | t.reset(); |
| 48 | try { | 47 | try { |
| 49 | rlAnswer = rlLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | 48 | rlAnswer = rlLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); |
| 50 | queryRecord.updateLowerBoundAnswers(rlAnswer); | 49 | queryRecord.updateLowerBoundAnswers(rlAnswer); |
| 51 | } finally { | 50 | } finally { |
| 52 | if (rlAnswer != null) rlAnswer.dispose(); | 51 | if(rlAnswer != null) rlAnswer.dispose(); |
| 53 | } | 52 | } |
| 54 | queryRecord.addProcessingTime(Step.LowerBound, t.duration()); | 53 | queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration()); |
| 55 | 54 | ||
| 56 | String extendedQueryText = queryRecord.getExtendedQueryText()[0]; | 55 | String extendedQueryText = queryRecord.getExtendedQueryText().get(0); |
| 57 | String[] toQuery = queryRecord.getQueryText().equals(extendedQueryText) ? | 56 | String[] toQuery = queryRecord.getQueryText().equals(extendedQueryText) ? |
| 58 | new String[] {queryRecord.getQueryText()} : | 57 | new String[]{queryRecord.getQueryText()} : |
| 59 | new String[] {queryRecord.getQueryText(), extendedQueryText}; | 58 | new String[] {queryRecord.getQueryText(), extendedQueryText}; |
| 60 | 59 | ||
| 61 | for (String queryText: toQuery) { | 60 | for (String queryText: toQuery) { |
| 62 | rlAnswer = null; | 61 | rlAnswer = null; |
| 63 | t.reset(); | 62 | t.reset(); |
| 64 | try { | 63 | try { |
| 65 | rlAnswer = rlUpperStore.evaluate(queryText, queryRecord.getAnswerVariables()); | 64 | rlAnswer = rlUpperStore.evaluate(queryText, queryRecord.getAnswerVariables()); |
| 66 | queryRecord.updateUpperBoundAnswers(rlAnswer); | 65 | queryRecord.updateUpperBoundAnswers(rlAnswer); |
| 67 | } finally { | 66 | } finally { |
| 68 | if (rlAnswer != null) rlAnswer.dispose(); | 67 | if(rlAnswer != null) rlAnswer.dispose(); |
| 69 | } | 68 | } |
| 70 | queryRecord.addProcessingTime(Step.UpperBound, t.duration()); | 69 | queryRecord.addProcessingTime(Step.UPPER_BOUND, t.duration()); |
| 71 | 70 | ||
| 72 | if (queryRecord.processed()) { | 71 | if(queryRecord.isProcessed()) { |
| 73 | queryRecord.setDifficulty(Step.UpperBound); | 72 | queryRecord.setDifficulty(Step.UPPER_BOUND); |
| 74 | return ; | 73 | return; |
| 75 | } | 74 | } |
| 76 | } | 75 | } |
| 77 | 76 | ||
| 78 | AnswerTuples elAnswer = null; | 77 | AnswerTuples elAnswer = null; |
| 79 | t.reset(); | 78 | t.reset(); |
| 80 | try { | 79 | try { |
| 81 | elAnswer = elLowerStore.evaluate(extendedQueryText, queryRecord.getAnswerVariables(), queryRecord.getLowerBoundAnswers()); | 80 | elAnswer = |
| 81 | elLowerStore.evaluate(extendedQueryText, queryRecord.getAnswerVariables(), queryRecord.getLowerBoundAnswers()); | ||
| 82 | queryRecord.updateLowerBoundAnswers(elAnswer); | 82 | queryRecord.updateLowerBoundAnswers(elAnswer); |
| 83 | } finally { | 83 | } finally { |
| 84 | if (elAnswer != null) elAnswer.dispose(); | 84 | if (elAnswer != null) elAnswer.dispose(); |
| 85 | } | 85 | } |
| 86 | queryRecord.addProcessingTime(Step.ELLowerBound, t.duration()); | 86 | queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration()); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | @Override | 89 | @Override |
| 90 | public void evaluateUpper(QueryRecord queryRecord) { | 90 | public void evaluateUpper(QueryRecord queryRecord) { |
| 91 | AnswerTuples rlAnswer = null; | 91 | AnswerTuples rlAnswer = null; |
| 92 | try { | 92 | try { |
| 93 | rlAnswer = rlUpperStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | 93 | rlAnswer = rlUpperStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); |
| 94 | queryRecord.updateUpperBoundAnswers(rlAnswer, true); | 94 | queryRecord.updateUpperBoundAnswers(rlAnswer, true); |
| 95 | } finally { | 95 | } finally { |
| 96 | if (rlAnswer != null) rlAnswer.dispose(); | 96 | if(rlAnswer != null) rlAnswer.dispose(); |
| 97 | } | 97 | } |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | @Override | 100 | @Override |
| 101 | public void dispose() { | 101 | public void dispose() { |
| 102 | if (elLowerStore != null) elLowerStore.dispose(); | 102 | if (elLowerStore != null) elLowerStore.dispose(); |
| 103 | if (rlUpperStore != null) rlUpperStore.dispose(); | 103 | if(rlUpperStore != null) rlUpperStore.dispose(); |
| 104 | super.dispose(); | 104 | super.dispose(); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| @@ -110,19 +110,17 @@ public class ELHOUQueryReasoner extends QueryReasoner { | |||
| 110 | EqualitiesEliminator eliminator = new EqualitiesEliminator(o); | 110 | EqualitiesEliminator eliminator = new EqualitiesEliminator(o); |
| 111 | o = eliminator.getOutputOntology(); | 111 | o = eliminator.getOutputOntology(); |
| 112 | eliminator.save(); | 112 | eliminator.save(); |
| 113 | } | 113 | } |
| 114 | |||
| 115 | OWLOntology ontology = o; | ||
| 116 | program = new DatalogProgram(ontology, properties.getToClassify()); | ||
| 114 | 117 | ||
| 115 | OWLOntology ontology = o; | ||
| 116 | program = new DatalogProgram(ontology, properties.getToClassify()); | ||
| 117 | |||
| 118 | importData(program.getAdditionalDataFile()); | 118 | importData(program.getAdditionalDataFile()); |
| 119 | 119 | ||
| 120 | elho_ontology = new ELHOProfile().getFragment(ontology); | 120 | elho_ontology = new ELHOProfile().getFragment(ontology); |
| 121 | elLowerStore.processOntology(elho_ontology); | 121 | elLowerStore.processOntology(elho_ontology); |
| 122 | originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology); | 122 | originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology); |
| 123 | } | 123 | } |
| 124 | |||
| 125 | String originalMarkProgram; | ||
| 126 | 124 | ||
| 127 | @Override | 125 | @Override |
| 128 | public boolean preprocess() { | 126 | public boolean preprocess() { |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java index 5511691..d1856c9 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java | |||
| @@ -1,32 +1,22 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner; | 1 | package uk.ac.ox.cs.pagoda.reasoner; |
| 2 | 2 | ||
| 3 | import java.io.File; | ||
| 4 | import java.io.IOException; | ||
| 5 | import java.util.HashSet; | ||
| 6 | import java.util.Set; | ||
| 7 | |||
| 8 | import org.semanticweb.HermiT.Reasoner; | 3 | import org.semanticweb.HermiT.Reasoner; |
| 9 | import org.semanticweb.owlapi.model.OWLClassExpression; | 4 | import org.semanticweb.owlapi.model.*; |
| 10 | import org.semanticweb.owlapi.model.OWLDataFactory; | ||
| 11 | import org.semanticweb.owlapi.model.OWLNamedIndividual; | ||
| 12 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 13 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; | ||
| 14 | import org.semanticweb.owlapi.model.OWLOntologyStorageException; | ||
| 15 | |||
| 16 | import uk.ac.ox.cs.JRDFox.model.Individual; | 5 | import uk.ac.ox.cs.JRDFox.model.Individual; |
| 17 | import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; | 6 | import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; |
| 18 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | 7 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; |
| 19 | import uk.ac.ox.cs.pagoda.owl.QueryRoller; | 8 | import uk.ac.ox.cs.pagoda.owl.QueryRoller; |
| 20 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | 9 | import uk.ac.ox.cs.pagoda.query.*; |
| 21 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 22 | import uk.ac.ox.cs.pagoda.query.AnswerTuplesImp; | ||
| 23 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID; | ||
| 24 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 25 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | 10 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; |
| 26 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; | 11 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; |
| 27 | import uk.ac.ox.cs.pagoda.util.Utility; | 12 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 28 | 13 | ||
| 29 | public class HermiTReasoner extends QueryReasoner { | 14 | import java.io.File; |
| 15 | import java.io.IOException; | ||
| 16 | import java.util.HashSet; | ||
| 17 | import java.util.Set; | ||
| 18 | |||
| 19 | class HermiTReasoner extends QueryReasoner { | ||
| 30 | 20 | ||
| 31 | Reasoner hermit; | 21 | Reasoner hermit; |
| 32 | 22 | ||
| @@ -54,15 +44,8 @@ public class HermiTReasoner extends QueryReasoner { | |||
| 54 | OWLOntology tbox = onto; | 44 | OWLOntology tbox = onto; |
| 55 | try { | 45 | try { |
| 56 | onto = OWLHelper.getImportedOntology(tbox, importedData.toString().split(ImportDataFileSeparator)); | 46 | onto = OWLHelper.getImportedOntology(tbox, importedData.toString().split(ImportDataFileSeparator)); |
| 57 | importedOntologyPath = OWLHelper.getOntologyPath(onto); | 47 | importedOntologyPath = OWLHelper.getOntologyPath(onto); |
| 58 | } catch (OWLOntologyCreationException e) { | 48 | } catch(OWLOntologyCreationException | OWLOntologyStorageException | IOException e) { |
| 59 | // TODO Auto-generated catch block | ||
| 60 | e.printStackTrace(); | ||
| 61 | } catch (OWLOntologyStorageException e) { | ||
| 62 | // TODO Auto-generated catch block | ||
| 63 | e.printStackTrace(); | ||
| 64 | } catch (IOException e) { | ||
| 65 | // TODO Auto-generated catch block | ||
| 66 | e.printStackTrace(); | 49 | e.printStackTrace(); |
| 67 | } | 50 | } |
| 68 | 51 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java b/src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java index 447a92d..7847e7c 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java | |||
| @@ -1,9 +1,6 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner; | 1 | package uk.ac.ox.cs.pagoda.reasoner; |
| 2 | 2 | ||
| 3 | import java.io.File; | ||
| 4 | |||
| 5 | import org.semanticweb.owlapi.model.OWLOntology; | 3 | import org.semanticweb.owlapi.model.OWLOntology; |
| 6 | |||
| 7 | import uk.ac.ox.cs.pagoda.constraints.BottomStrategy; | 4 | import uk.ac.ox.cs.pagoda.constraints.BottomStrategy; |
| 8 | import uk.ac.ox.cs.pagoda.constraints.UpperUnaryBottom; | 5 | import uk.ac.ox.cs.pagoda.constraints.UpperUnaryBottom; |
| 9 | import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; | 6 | import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; |
| @@ -14,6 +11,8 @@ import uk.ac.ox.cs.pagoda.rules.GeneralProgram; | |||
| 14 | import uk.ac.ox.cs.pagoda.tracking.QueryTracker; | 11 | import uk.ac.ox.cs.pagoda.tracking.QueryTracker; |
| 15 | import uk.ac.ox.cs.pagoda.util.Utility; | 12 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 16 | 13 | ||
| 14 | import java.io.File; | ||
| 15 | |||
| 17 | public class IterativeRefinement { | 16 | public class IterativeRefinement { |
| 18 | 17 | ||
| 19 | private static final int depthLimit = 1; | 18 | private static final int depthLimit = 1; |
| @@ -23,16 +22,15 @@ public class IterativeRefinement { | |||
| 23 | BasicQueryEngine m_trackingStore; | 22 | BasicQueryEngine m_trackingStore; |
| 24 | QueryRecord[] botQueryRecords; | 23 | QueryRecord[] botQueryRecords; |
| 25 | 24 | ||
| 26 | int m_depth = 0; | 25 | int m_depth = 0; |
| 27 | 26 | String tempDataFile = "temp.ttl"; | |
| 27 | |||
| 28 | public IterativeRefinement(QueryRecord queryRecord, QueryTracker tracker, BasicQueryEngine trackingStore, QueryRecord[] botQueryRecords) { | 28 | public IterativeRefinement(QueryRecord queryRecord, QueryTracker tracker, BasicQueryEngine trackingStore, QueryRecord[] botQueryRecords) { |
| 29 | m_record = queryRecord; | 29 | m_record = queryRecord; |
| 30 | m_tracker = tracker; | 30 | m_tracker = tracker; |
| 31 | m_trackingStore = trackingStore; | 31 | m_trackingStore = trackingStore; |
| 32 | this.botQueryRecords = botQueryRecords; | 32 | this.botQueryRecords = botQueryRecords; |
| 33 | } | 33 | } |
| 34 | |||
| 35 | String tempDataFile = "temp.ttl"; | ||
| 36 | 34 | ||
| 37 | public OWLOntology extractWithFullABox(String dataset, BottomStrategy upperBottom) { | 35 | public OWLOntology extractWithFullABox(String dataset, BottomStrategy upperBottom) { |
| 38 | GeneralProgram program; | 36 | GeneralProgram program; |
| @@ -58,8 +56,8 @@ public class IterativeRefinement { | |||
| 58 | } finally { | 56 | } finally { |
| 59 | tEngine.dispose(); | 57 | tEngine.dispose(); |
| 60 | } | 58 | } |
| 61 | 59 | ||
| 62 | if (m_record.processed()) | 60 | if(m_record.isProcessed()) |
| 63 | return null; | 61 | return null; |
| 64 | 62 | ||
| 65 | if (!update) break; | 63 | if (!update) break; |
| @@ -95,8 +93,8 @@ public class IterativeRefinement { | |||
| 95 | } finally { | 93 | } finally { |
| 96 | tEngine.dispose(); | 94 | tEngine.dispose(); |
| 97 | } | 95 | } |
| 98 | 96 | ||
| 99 | if (m_record.processed()) | 97 | if(m_record.isProcessed()) |
| 100 | return null; | 98 | return null; |
| 101 | 99 | ||
| 102 | if (!update) break; | 100 | if (!update) break; |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java index 55ecb81..618fb70 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java | |||
| @@ -1,69 +1,75 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner; | 1 | package uk.ac.ox.cs.pagoda.reasoner; |
| 2 | 2 | ||
| 3 | import java.util.Collection; | ||
| 4 | |||
| 5 | import org.semanticweb.karma2.profile.ELHOProfile; | 3 | import org.semanticweb.karma2.profile.ELHOProfile; |
| 6 | import org.semanticweb.owlapi.model.OWLOntology; | 4 | import org.semanticweb.owlapi.model.OWLOntology; |
| 7 | 5 | import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; | |
| 8 | import uk.ac.ox.cs.pagoda.multistage.*; | ||
| 9 | import uk.ac.ox.cs.pagoda.owl.EqualitiesEliminator; | 6 | import uk.ac.ox.cs.pagoda.owl.EqualitiesEliminator; |
| 10 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | 7 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; |
| 11 | import uk.ac.ox.cs.pagoda.query.*; | 8 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; |
| 9 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID; | ||
| 10 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID2; | ||
| 11 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 12 | import uk.ac.ox.cs.pagoda.query.QueryRecord.Step; | 12 | import uk.ac.ox.cs.pagoda.query.QueryRecord.Step; |
| 13 | import uk.ac.ox.cs.pagoda.reasoner.full.Checker; | 13 | import uk.ac.ox.cs.pagoda.reasoner.full.Checker; |
| 14 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | 14 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; |
| 15 | import uk.ac.ox.cs.pagoda.reasoner.light.KarmaQueryEngine; | 15 | import uk.ac.ox.cs.pagoda.reasoner.light.KarmaQueryEngine; |
| 16 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; | 16 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; |
| 17 | import uk.ac.ox.cs.pagoda.summary.HermitSummaryFilter; | 17 | import uk.ac.ox.cs.pagoda.summary.HermitSummaryFilter; |
| 18 | import uk.ac.ox.cs.pagoda.tracking.*; | 18 | import uk.ac.ox.cs.pagoda.tracking.QueryTracker; |
| 19 | import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoder; | ||
| 20 | import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoderDisjVar1; | ||
| 21 | import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoderWithGap; | ||
| 19 | import uk.ac.ox.cs.pagoda.util.Timer; | 22 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 20 | import uk.ac.ox.cs.pagoda.util.Utility; | 23 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 24 | import uk.ac.ox.cs.pagoda.util.tuples.Tuple; | ||
| 21 | 25 | ||
| 22 | public class MyQueryReasoner extends QueryReasoner { | 26 | import java.util.Collection; |
| 23 | 27 | ||
| 24 | OWLOntology ontology; | 28 | class MyQueryReasoner extends QueryReasoner { |
| 25 | 29 | ||
| 26 | // String additonalDataFile; | 30 | OWLOntology ontology; |
| 27 | 31 | DatalogProgram program; | |
| 28 | DatalogProgram program; | ||
| 29 | 32 | ||
| 33 | // String additonalDataFile; | ||
| 30 | BasicQueryEngine rlLowerStore = null; | 34 | BasicQueryEngine rlLowerStore = null; |
| 31 | BasicQueryEngine lazyUpperStore = null; | 35 | BasicQueryEngine lazyUpperStore = null; |
| 36 | // BasicQueryEngine limitedSkolemUpperStore; | ||
| 37 | OWLOntology elho_ontology; | ||
| 32 | // boolean[] namedIndividuals_lazyUpper; | 38 | // boolean[] namedIndividuals_lazyUpper; |
| 33 | 39 | KarmaQueryEngine elLowerStore = null; | |
| 34 | OWLOntology elho_ontology; | ||
| 35 | KarmaQueryEngine elLowerStore = null; | ||
| 36 | |||
| 37 | BasicQueryEngine trackingStore = null; | 40 | BasicQueryEngine trackingStore = null; |
| 38 | // boolean[] namedIndividuals_tracking; | 41 | // boolean[] namedIndividuals_tracking; |
| 39 | 42 | TrackingRuleEncoder encoder; | |
| 40 | boolean equalityTag; | 43 | private boolean equalityTag; |
| 41 | boolean multiStageTag; | 44 | private boolean multiStageTag; |
| 42 | 45 | private Timer t = new Timer(); | |
| 46 | private Collection<String> predicatesWithGap = null; | ||
| 47 | private SatisfiabilityStatus satisfiable; | ||
| 48 | private ConsistencyManager consistency = new ConsistencyManager(this); | ||
| 49 | private boolean useUpperStores = false; | ||
| 43 | public MyQueryReasoner() { | 50 | public MyQueryReasoner() { |
| 44 | setup(true, true); | 51 | setup(true, true); |
| 45 | } | 52 | } |
| 46 | |||
| 47 | public MyQueryReasoner(boolean multiStageTag, boolean considerEqualities) { | 53 | public MyQueryReasoner(boolean multiStageTag, boolean considerEqualities) { |
| 48 | setup(multiStageTag, considerEqualities); | 54 | setup(multiStageTag, considerEqualities); |
| 49 | } | 55 | } |
| 50 | 56 | ||
| 51 | private BasicQueryEngine getUpperStore(String name, boolean checkValidity) { | 57 | private BasicQueryEngine getUpperStore(String name, boolean checkValidity) { |
| 52 | if (multiStageTag) | 58 | if (multiStageTag) |
| 53 | return new MultiStageQueryEngine(name, checkValidity); | 59 | return new MultiStageQueryEngine(name, checkValidity); |
| 54 | // return new TwoStageQueryEngine(name, checkValidity); | 60 | // return new TwoStageQueryEngine(name, checkValidity); |
| 55 | else | 61 | else |
| 56 | return new BasicQueryEngine(name); | 62 | return new BasicQueryEngine(name); |
| 57 | } | 63 | } |
| 58 | 64 | ||
| 59 | public void setup(boolean multiStageTag, boolean considerEqualities) { | 65 | public void setup(boolean multiStageTag, boolean considerEqualities) { |
| 60 | satisfiable = null; | 66 | satisfiable = SatisfiabilityStatus.UNCHECKED; |
| 61 | this.multiStageTag = multiStageTag; | 67 | this.multiStageTag = multiStageTag; |
| 62 | this.equalityTag = considerEqualities; | 68 | this.equalityTag = considerEqualities; |
| 63 | 69 | ||
| 64 | rlLowerStore = new BasicQueryEngine("rl-lower-bound"); | 70 | rlLowerStore = new BasicQueryEngine("rl-lower-bound"); |
| 65 | elLowerStore = new KarmaQueryEngine("elho-lower-bound"); | 71 | elLowerStore = new KarmaQueryEngine("elho-lower-bound"); |
| 66 | 72 | ||
| 67 | trackingStore = getUpperStore("tracking", false); | 73 | trackingStore = getUpperStore("tracking", false); |
| 68 | } | 74 | } |
| 69 | 75 | ||
| @@ -75,119 +81,155 @@ public class MyQueryReasoner extends QueryReasoner { | |||
| 75 | elLowerStore.importRDFData(name, datafile); | 81 | elLowerStore.importRDFData(name, datafile); |
| 76 | trackingStore.importRDFData(name, datafile); | 82 | trackingStore.importRDFData(name, datafile); |
| 77 | } | 83 | } |
| 78 | 84 | ||
| 79 | @Override | 85 | @Override |
| 80 | public void loadOntology(OWLOntology o) { | 86 | public void loadOntology(OWLOntology o) { |
| 81 | if (!equalityTag) { | 87 | if(!equalityTag) { |
| 82 | EqualitiesEliminator eliminator = new EqualitiesEliminator(o); | 88 | EqualitiesEliminator eliminator = new EqualitiesEliminator(o); |
| 83 | o = eliminator.getOutputOntology(); | 89 | o = eliminator.getOutputOntology(); |
| 84 | eliminator.save(); | 90 | eliminator.save(); |
| 85 | } | 91 | } |
| 86 | 92 | ||
| 87 | ontology = o; | 93 | ontology = o; |
| 88 | program = new DatalogProgram(ontology, properties.getToClassify()); | 94 | program = new DatalogProgram(ontology, properties.getToClassify()); |
| 89 | // program.getLower().save(); | 95 | // program.getLower().save(); |
| 90 | // program.getUpper().save(); | 96 | // program.getUpper().save(); |
| 91 | // program.getGeneral().save(); | 97 | // program.getGeneral().save(); |
| 92 | 98 | ||
| 93 | if (multiStageTag && !program.getGeneral().isHorn()) { | 99 | useUpperStores = multiStageTag && !program.getGeneral().isHorn(); |
| 94 | lazyUpperStore = getUpperStore("lazy-upper-bound", true); // new MultiStageQueryEngine("lazy-upper-bound", true); // | 100 | if(useUpperStores) { |
| 101 | lazyUpperStore = getUpperStore("lazy-upper-bound", true); | ||
| 102 | // limitedSkolemUpperStore = getUpperStore("limited-skolem-upper-bound", true); | ||
| 95 | } | 103 | } |
| 96 | 104 | ||
| 97 | importData(program.getAdditionalDataFile()); | 105 | importData(program.getAdditionalDataFile()); |
| 98 | 106 | ||
| 99 | elho_ontology = new ELHOProfile().getFragment(ontology); | 107 | elho_ontology = new ELHOProfile().getFragment(ontology); |
| 100 | elLowerStore.processOntology(elho_ontology); | 108 | elLowerStore.processOntology(elho_ontology); |
| 101 | } | 109 | } |
| 102 | 110 | ||
| 103 | private Collection<String> predicatesWithGap = null; | ||
| 104 | |||
| 105 | public Collection<String> getPredicatesWithGap() { | 111 | public Collection<String> getPredicatesWithGap() { |
| 106 | return predicatesWithGap; | 112 | return predicatesWithGap; |
| 107 | } | 113 | } |
| 108 | 114 | ||
| 109 | @Override | 115 | @Override |
| 110 | public boolean preprocess() { | 116 | public boolean preprocess() { |
| 111 | t.reset(); | 117 | t.reset(); |
| 112 | Utility.logInfo("Preprocessing ... checking satisfiability ... "); | 118 | Utility.logInfo("Preprocessing... checking satisfiability... "); |
| 113 | 119 | ||
| 114 | String name = "data", datafile = importedData.toString(); | 120 | String name = "data", datafile = importedData.toString(); |
| 115 | rlLowerStore.importRDFData(name, datafile); | 121 | rlLowerStore.importRDFData(name, datafile); |
| 116 | rlLowerStore.materialise("lower program", program.getLower().toString()); | 122 | rlLowerStore.materialise("lower program", program.getLower().toString()); |
| 117 | // program.getLower().save(); | 123 | // program.getLower().save(); |
| 118 | if (!consistency.checkRLLowerBound()) return false; | 124 | if(!consistency.checkRLLowerBound()) return false; |
| 119 | Utility.logInfo("The number of sameAs assertions in RL lower store: " + rlLowerStore.getSameAsNumber()); | 125 | Utility.logInfo("The number of sameAs assertions in RL lower store: " + rlLowerStore.getSameAsNumber()); |
| 120 | 126 | ||
| 121 | String originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology); | 127 | String originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology); |
| 122 | 128 | ||
| 123 | elLowerStore.importRDFData(name, datafile); | 129 | elLowerStore.importRDFData(name, datafile); |
| 124 | elLowerStore.materialise("saturate named individuals", originalMarkProgram); | 130 | elLowerStore.materialise("saturate named individuals", originalMarkProgram); |
| 125 | elLowerStore.materialise("lower program", program.getLower().toString()); | 131 | elLowerStore.materialise("lower program", program.getLower().toString()); |
| 126 | elLowerStore.initialiseKarma(); | 132 | elLowerStore.initialiseKarma(); |
| 127 | if (!consistency.checkELLowerBound()) return false; | 133 | if(!consistency.checkELLowerBound()) return false; |
| 128 | 134 | ||
| 129 | if (lazyUpperStore != null) { | 135 | if(lazyUpperStore != null) { |
| 130 | lazyUpperStore.importRDFData(name, datafile); | 136 | lazyUpperStore.importRDFData(name, datafile); |
| 131 | lazyUpperStore.materialise("saturate named individuals", originalMarkProgram); | 137 | lazyUpperStore.materialise("saturate named individuals", originalMarkProgram); |
| 132 | int tag = lazyUpperStore.materialiseRestrictedly(program, null); | 138 | int tag = lazyUpperStore.materialiseRestrictedly(program, null); |
| 133 | if (tag != 1) { | 139 | if(tag != 1) { |
| 134 | lazyUpperStore.dispose(); | 140 | lazyUpperStore.dispose(); |
| 135 | lazyUpperStore = null; | 141 | lazyUpperStore = null; |
| 136 | } | 142 | } |
| 137 | if (tag == -1) return false; | 143 | if(tag == -1) return false; |
| 138 | } | 144 | } |
| 139 | if (consistency.checkLazyUpper()) { | 145 | if(consistency.checkUpper(lazyUpperStore)) { |
| 140 | satisfiable = true; | 146 | satisfiable = SatisfiabilityStatus.SATISFIABLE; |
| 141 | Utility.logInfo("time for satisfiability checking: " + t.duration()); | 147 | Utility.logInfo("time for satisfiability checking: " + t.duration()); |
| 142 | } | 148 | } |
| 143 | 149 | ||
| 150 | // if(limitedSkolemUpperStore != null) { | ||
| 151 | // limitedSkolemUpperStore.importRDFData(name, datafile); | ||
| 152 | // limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram); | ||
| 153 | // int tag = limitedSkolemUpperStore.materialiseSkolemly(program, null); | ||
| 154 | // if(tag != 1) { | ||
| 155 | // limitedSkolemUpperStore.dispose(); | ||
| 156 | // limitedSkolemUpperStore = null; | ||
| 157 | // } | ||
| 158 | // if(tag == -1) return false; | ||
| 159 | // } | ||
| 160 | // if(satisfiable == SatisfiabilityStatus.UNCHECKED && consistency.checkUpper(limitedSkolemUpperStore)) { | ||
| 161 | // satisfiable = SatisfiabilityStatus.SATISFIABLE; | ||
| 162 | // Utility.logInfo("time for satisfiability checking: " + t.duration()); | ||
| 163 | // } | ||
| 164 | |||
| 144 | trackingStore.importRDFData(name, datafile); | 165 | trackingStore.importRDFData(name, datafile); |
| 145 | trackingStore.materialise("saturate named individuals", originalMarkProgram); | 166 | trackingStore.materialise("saturate named individuals", originalMarkProgram); |
| 146 | 167 | ||
| 147 | // materialiseFullUpper(); | 168 | // materialiseFullUpper(); |
| 148 | // GapByStore4ID gap = new GapByStore4ID(trackingStore); | 169 | // GapByStore4ID gap = new GapByStore4ID(trackingStore); |
| 149 | GapByStore4ID gap = new GapByStore4ID2(trackingStore, rlLowerStore); | 170 | GapByStore4ID gap = new GapByStore4ID2(trackingStore, rlLowerStore); |
| 150 | trackingStore.materialiseFoldedly(program, gap); | 171 | trackingStore.materialiseFoldedly(program, gap); |
| 151 | predicatesWithGap = gap.getPredicatesWithGap(); | 172 | predicatesWithGap = gap.getPredicatesWithGap(); |
| 152 | gap.clear(); | 173 | gap.clear(); |
| 153 | 174 | ||
| 154 | if (program.getGeneral().isHorn()) | 175 | if(program.getGeneral().isHorn()) |
| 155 | encoder = new TrackingRuleEncoderWithGap(program.getUpper(), trackingStore); | 176 | encoder = new TrackingRuleEncoderWithGap(program.getUpper(), trackingStore); |
| 156 | else | 177 | else |
| 157 | encoder = new TrackingRuleEncoderDisjVar1(program.getUpper(), trackingStore); | 178 | encoder = new TrackingRuleEncoderDisjVar1(program.getUpper(), trackingStore); |
| 158 | // encoder = new TrackingRuleEncoderDisj1(program.getUpper(), trackingStore); | 179 | // encoder = new TrackingRuleEncoderDisj1(program.getUpper(), trackingStore); |
| 159 | // encoder = new TrackingRuleEncoderDisjVar2(program.getUpper(), trackingStore); | 180 | // encoder = new TrackingRuleEncoderDisjVar2(program.getUpper(), trackingStore); |
| 160 | // encoder = new TrackingRuleEncoderDisj2(program.getUpper(), trackingStore); | 181 | // encoder = new TrackingRuleEncoderDisj2(program.getUpper(), trackingStore); |
| 161 | 182 | ||
| 162 | program.deleteABoxTurtleFile(); | 183 | program.deleteABoxTurtleFile(); |
| 163 | 184 | ||
| 164 | if (!isConsistent()) | 185 | if(!isConsistent()) |
| 165 | return false; | 186 | return false; |
| 166 | 187 | ||
| 167 | consistency.extractBottomFragment(); | 188 | consistency.extractBottomFragment(); |
| 168 | return true; | 189 | consistency.dispose(); |
| 190 | |||
| 191 | return true; | ||
| 169 | } | 192 | } |
| 170 | 193 | ||
| 171 | private Boolean satisfiable; | ||
| 172 | private ConsistencyManager consistency = new ConsistencyManager(this); | ||
| 173 | |||
| 174 | TrackingRuleEncoder encoder; | ||
| 175 | |||
| 176 | @Override | 194 | @Override |
| 177 | public boolean isConsistent() { | 195 | public boolean isConsistent() { |
| 178 | if (satisfiable == null) { | 196 | if(satisfiable == SatisfiabilityStatus.UNCHECKED) { |
| 179 | satisfiable = consistency.check(); | 197 | satisfiable = consistency.check() ? SatisfiabilityStatus.SATISFIABLE : SatisfiabilityStatus.UNSATISFIABLE; |
| 180 | Utility.logInfo("time for satisfiability checking: " + t.duration()); | 198 | Utility.logInfo("time for satisfiability checking: " + t.duration()); |
| 181 | } | 199 | } |
| 182 | return satisfiable; | 200 | return satisfiable == SatisfiabilityStatus.SATISFIABLE; |
| 201 | } | ||
| 202 | |||
| 203 | /** | ||
| 204 | * It deals with blanks nodes differently from variables | ||
| 205 | * according to SPARQL semantics for OWL2 Entailment Regime. | ||
| 206 | * <p> | ||
| 207 | * In particular variables are matched only against named individuals, | ||
| 208 | * and blank nodes against named and anonymous individuals. | ||
| 209 | */ | ||
| 210 | private boolean queryUpperStore(BasicQueryEngine upperStore, QueryRecord queryRecord, | ||
| 211 | Tuple<String> extendedQuery, Step step) { | ||
| 212 | |||
| 213 | if(queryRecord.hasNonAnsDistinguishedVariables()) | ||
| 214 | queryUpperBound(upperStore, queryRecord, extendedQuery.get(0), queryRecord.getAnswerVariables()); | ||
| 215 | else | ||
| 216 | queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | ||
| 217 | |||
| 218 | queryRecord.addProcessingTime(step, t.duration()); | ||
| 219 | if(queryRecord.isProcessed()) { | ||
| 220 | queryRecord.setDifficulty(step); | ||
| 221 | return true; | ||
| 222 | } | ||
| 223 | return false; | ||
| 183 | } | 224 | } |
| 184 | |||
| 185 | Timer t = new Timer(); | ||
| 186 | 225 | ||
| 187 | private OWLOntology relevantPart(QueryRecord queryRecord) { | 226 | /** |
| 227 | * Returns the part of the ontology relevant for Hermit, while computing the bound answers. | ||
| 228 | * */ | ||
| 229 | private boolean queryBounds(QueryRecord queryRecord) { | ||
| 188 | AnswerTuples rlAnswer = null, elAnswer = null; | 230 | AnswerTuples rlAnswer = null, elAnswer = null; |
| 189 | 231 | ||
| 190 | t.reset(); | 232 | t.reset(); |
| 191 | try { | 233 | try { |
| 192 | rlAnswer = rlLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | 234 | rlAnswer = rlLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); |
| 193 | Utility.logDebug(t.duration()); | 235 | Utility.logDebug(t.duration()); |
| @@ -195,130 +237,134 @@ public class MyQueryReasoner extends QueryReasoner { | |||
| 195 | } finally { | 237 | } finally { |
| 196 | if (rlAnswer != null) rlAnswer.dispose(); | 238 | if (rlAnswer != null) rlAnswer.dispose(); |
| 197 | } | 239 | } |
| 198 | queryRecord.addProcessingTime(Step.LowerBound, t.duration()); | 240 | queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration()); |
| 199 | rlAnswer = null; | 241 | |
| 200 | |||
| 201 | t.reset(); | 242 | t.reset(); |
| 202 | BasicQueryEngine upperStore = queryRecord.isBottom() || lazyUpperStore == null ? trackingStore : lazyUpperStore; | 243 | |
| 203 | 244 | Tuple<String> extendedQueryTexts = queryRecord.getExtendedQueryText(); | |
| 204 | String[] extendedQuery = queryRecord.getExtendedQueryText(); | 245 | |
| 205 | 246 | Utility.logDebug("Tracking store"); | |
| 206 | queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | 247 | if(queryUpperStore(trackingStore, queryRecord, extendedQueryTexts, Step.SIMPLE_UPPER_BOUND)) |
| 207 | if (!queryRecord.processed() && !queryRecord.getQueryText().equals(extendedQuery[0])) | 248 | return true; |
| 208 | queryUpperBound(upperStore, queryRecord, extendedQuery[0], queryRecord.getAnswerVariables()); | 249 | |
| 209 | if (!queryRecord.processed() && queryRecord.hasNonAnsDistinguishedVariables()) | 250 | if(!queryRecord.isBottom()) { |
| 210 | queryUpperBound(upperStore, queryRecord, extendedQuery[1], queryRecord.getDistinguishedVariables()); | 251 | Utility.logDebug("Lazy store"); |
| 211 | 252 | if(lazyUpperStore != null && queryUpperStore(lazyUpperStore, queryRecord, extendedQueryTexts, Step.LAZY_UPPER_BOUND)) | |
| 212 | queryRecord.addProcessingTime(Step.UpperBound, t.duration()); | 253 | return true; |
| 213 | if (queryRecord.processed()) { | 254 | // Utility.logDebug("Skolem store"); |
| 214 | queryRecord.setDifficulty(Step.UpperBound); | 255 | // if(limitedSkolemUpperStore != null && queryUpperStore(limitedSkolemUpperStore, queryRecord, extendedQueryTexts, Step.L_SKOLEM_UPPER_BOUND)) |
| 215 | return null; | 256 | // return null; |
| 216 | } | 257 | } |
| 217 | 258 | ||
| 218 | t.reset(); | 259 | t.reset(); |
| 219 | try { | 260 | try { |
| 220 | elAnswer = elLowerStore.evaluate(extendedQuery[0], queryRecord.getAnswerVariables(), queryRecord.getLowerBoundAnswers()); | 261 | elAnswer = elLowerStore.evaluate(extendedQueryTexts.get(0), |
| 262 | queryRecord.getAnswerVariables(), | ||
| 263 | queryRecord.getLowerBoundAnswers()); | ||
| 221 | Utility.logDebug(t.duration()); | 264 | Utility.logDebug(t.duration()); |
| 222 | queryRecord.updateLowerBoundAnswers(elAnswer); | 265 | queryRecord.updateLowerBoundAnswers(elAnswer); |
| 223 | } finally { | 266 | } finally { |
| 224 | if (elAnswer != null) elAnswer.dispose(); | 267 | if (elAnswer != null) elAnswer.dispose(); |
| 225 | } | 268 | } |
| 226 | queryRecord.addProcessingTime(Step.ELLowerBound, t.duration()); | 269 | queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration()); |
| 227 | 270 | ||
| 228 | if (queryRecord.processed()) { | 271 | if(queryRecord.isProcessed()) { |
| 229 | queryRecord.setDifficulty(Step.ELLowerBound); | 272 | queryRecord.setDifficulty(Step.EL_LOWER_BOUND); |
| 230 | return null; | 273 | return true; |
| 231 | } | 274 | } |
| 232 | 275 | ||
| 233 | t.reset(); | 276 | return false; |
| 234 | |||
| 235 | QueryTracker tracker = new QueryTracker(encoder, rlLowerStore, queryRecord); | ||
| 236 | |||
| 237 | OWLOntology knowledgebase; | ||
| 238 | t.reset(); | ||
| 239 | // if (program.getGeneral().isHorn()) { | ||
| 240 | // knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true); | ||
| 241 | // queryRecord.addProcessingTime(Step.Fragment, t.duration()); | ||
| 242 | // return knowledgebase; | ||
| 243 | // } | ||
| 244 | // else { | ||
| 245 | knowledgebase = tracker.extract(trackingStore, consistency.getQueryRecords(), true); | ||
| 246 | queryRecord.addProcessingTime(Step.Fragment, t.duration()); | ||
| 247 | // } | ||
| 248 | |||
| 249 | if (knowledgebase.isEmpty() || queryRecord.isBottom()) | ||
| 250 | return knowledgebase; | ||
| 251 | |||
| 252 | if (program.getGeneral().isHorn()) return knowledgebase; | ||
| 253 | |||
| 254 | // t.reset(); | ||
| 255 | // if (queryRecord.isHorn() && lazyUpperStore != null) { | ||
| 256 | //// knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true); | ||
| 257 | // } else if (queryRecord.getArity() < 3) { | ||
| 258 | // IterativeRefinement iterativeRefinement = new IterativeRefinement(queryRecord, tracker, trackingStore, consistency.getQueryRecords()); | ||
| 259 | // knowledgebase = iterativeRefinement.extractWithFullABox(importedData.toString(), program.getUpperBottomStrategy()); | ||
| 260 | // } | ||
| 261 | // | ||
| 262 | // queryRecord.addProcessingTime(Step.FragmentRefinement, t.duration()); | ||
| 263 | // | ||
| 264 | // if (knowledgebase == null) | ||
| 265 | // queryRecord.setDifficulty(Step.FragmentRefinement); | ||
| 266 | |||
| 267 | return knowledgebase; | ||
| 268 | } | 277 | } |
| 269 | 278 | ||
| 270 | // int counter = 0; | 279 | private OWLOntology extractRelevantOntologySubset(QueryRecord queryRecord) { |
| 280 | t.reset(); | ||
| 281 | |||
| 282 | QueryTracker tracker = new QueryTracker(encoder, rlLowerStore, queryRecord); | ||
| 283 | OWLOntology relevantOntologySubset = tracker.extract(trackingStore, consistency.getQueryRecords(), true); | ||
| 284 | |||
| 285 | queryRecord.addProcessingTime(Step.FRAGMENT, t.duration()); | ||
| 286 | |||
| 287 | return relevantOntologySubset; | ||
| 288 | } | ||
| 271 | 289 | ||
| 272 | private void queryUpperBound(BasicQueryEngine upperStore, QueryRecord queryRecord, String queryText, String[] answerVariables) { | 290 | private void queryUpperBound(BasicQueryEngine upperStore, QueryRecord queryRecord, String queryText, String[] answerVariables) { |
| 273 | AnswerTuples rlAnswer = null; | 291 | AnswerTuples rlAnswer = null; |
| 274 | try { | 292 | try { |
| 275 | Utility.logDebug(queryText); | 293 | Utility.logDebug(queryText); |
| 276 | rlAnswer = upperStore.evaluate(queryText, answerVariables); | 294 | rlAnswer = upperStore.evaluate(queryText, answerVariables); |
| 277 | Utility.logDebug(t.duration()); | 295 | Utility.logDebug(t.duration()); |
| 278 | queryRecord.updateUpperBoundAnswers(rlAnswer); | 296 | queryRecord.updateUpperBoundAnswers(rlAnswer); |
| 279 | } finally { | 297 | } finally { |
| 280 | if (rlAnswer != null) rlAnswer.dispose(); | 298 | if(rlAnswer != null) rlAnswer.dispose(); |
| 281 | rlAnswer = null; | ||
| 282 | } | 299 | } |
| 283 | } | 300 | } |
| 284 | 301 | ||
| 285 | @Override | 302 | @Override |
| 286 | public void evaluate(QueryRecord queryRecord) { | 303 | public void evaluate(QueryRecord queryRecord) { |
| 287 | OWLOntology knowledgebase = relevantPart(queryRecord); | 304 | if(queryBounds(queryRecord)) |
| 288 | 305 | return; | |
| 289 | if (knowledgebase == null) { | 306 | |
| 290 | Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); | 307 | OWLOntology relevantOntologySubset = extractRelevantOntologySubset(queryRecord); |
| 291 | return ; | 308 | |
| 292 | } | 309 | int aBoxCount = relevantOntologySubset.getABoxAxioms(true).size(); |
| 293 | 310 | Utility.logInfo("Relevant ontology subset: ABox_axioms=" + aBoxCount + " TBox_axioms=" + (relevantOntologySubset | |
| 294 | int aboxcount = knowledgebase.getABoxAxioms(true).size(); | 311 | .getAxiomCount() - aBoxCount)); |
| 295 | Utility.logDebug("ABox axioms: " + aboxcount + " TBox axioms: " + (knowledgebase.getAxiomCount() - aboxcount)); | 312 | // queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl"); |
| 296 | // queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl"); | 313 | |
| 297 | 314 | if(querySkolemisedRelevantSubset(relevantOntologySubset, queryRecord)) | |
| 298 | Timer t = new Timer(); | 315 | return; |
| 299 | Checker summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT()); | 316 | |
| 300 | // int validNumber = | 317 | Timer t = new Timer(); |
| 301 | summarisedChecker.check(queryRecord.getGapAnswers()); | 318 | Checker summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT()); |
| 319 | summarisedChecker.check(queryRecord.getGapAnswers()); | ||
| 302 | summarisedChecker.dispose(); | 320 | summarisedChecker.dispose(); |
| 303 | Utility.logDebug("Total time for full reasoner: " + t.duration()); | 321 | Utility.logDebug("Total time for full reasoner: " + t.duration()); |
| 304 | // if (validNumber == 0) { | 322 | queryRecord.markAsProcessed(); |
| 305 | queryRecord.markAsProcessed(); | 323 | Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); |
| 306 | Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); | ||
| 307 | // } | ||
| 308 | } | 324 | } |
| 309 | 325 | ||
| 326 | private boolean querySkolemisedRelevantSubset(OWLOntology relevantSubset, QueryRecord queryRecord) { | ||
| 327 | MultiStageQueryEngine relevantStore = | ||
| 328 | new MultiStageQueryEngine("Relevant-store", true); // checkValidity is true | ||
| 329 | DatalogProgram relevantProgram = new DatalogProgram(relevantSubset, false); // toClassify is false | ||
| 330 | |||
| 331 | // relevantStore.importRDFData("data", importedData.toString()); // 2 answers more | ||
| 332 | relevantStore.importDataFromABoxOf(relevantSubset); | ||
| 333 | |||
| 334 | int materialisationResult = relevantStore.materialiseSkolemly(relevantProgram, null); | ||
| 335 | if(materialisationResult != 1) | ||
| 336 | throw new RuntimeException("Skolemised materialisation error"); // TODO check consistency | ||
| 337 | // relevantStore.materialiseRestrictedly(relevantProgram, null); // it has been tried | ||
| 338 | |||
| 339 | return queryUpperStore(relevantStore, queryRecord, queryRecord.getExtendedQueryText(), Step.L_SKOLEM_UPPER_BOUND); | ||
| 340 | |||
| 341 | // the following has been tried | ||
| 342 | // Tuple<String> extendedQueryText = queryRecord.getExtendedQueryText(); | ||
| 343 | // if(queryRecord.hasNonAnsDistinguishedVariables()) { | ||
| 344 | // queryUpperBound(relevantStore, queryRecord, extendedQueryText.get(0), queryRecord.getAnswerVariables()); | ||
| 345 | // queryUpperBound(relevantStore, queryRecord, extendedQueryText.get(1), queryRecord.getDistinguishedVariables()); | ||
| 346 | // } | ||
| 347 | // else | ||
| 348 | // queryUpperBound(relevantStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | ||
| 349 | // | ||
| 350 | // return queryRecord.isProcessed(); | ||
| 351 | |||
| 352 | } | ||
| 353 | |||
| 310 | @Override | 354 | @Override |
| 311 | public void evaluateUpper(QueryRecord queryRecord) { | 355 | public void evaluateUpper(QueryRecord queryRecord) { |
| 312 | AnswerTuples rlAnswer = null; | 356 | // TODO add new upper store |
| 313 | boolean useFull = queryRecord.isBottom() || lazyUpperStore == null; | 357 | AnswerTuples rlAnswer = null; |
| 358 | boolean useFull = queryRecord.isBottom() || lazyUpperStore == null; | ||
| 314 | try { | 359 | try { |
| 315 | rlAnswer = (useFull ? trackingStore: lazyUpperStore).evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | 360 | rlAnswer = |
| 316 | queryRecord.updateUpperBoundAnswers(rlAnswer, true); | 361 | (useFull ? trackingStore : lazyUpperStore).evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); |
| 362 | queryRecord.updateUpperBoundAnswers(rlAnswer, true); | ||
| 317 | } finally { | 363 | } finally { |
| 318 | if (rlAnswer != null) rlAnswer.dispose(); | 364 | if(rlAnswer != null) rlAnswer.dispose(); |
| 319 | } | 365 | } |
| 320 | } | 366 | } |
| 321 | 367 | ||
| 322 | @Override | 368 | @Override |
| 323 | public void dispose() { | 369 | public void dispose() { |
| 324 | if (encoder != null) encoder.dispose(); | 370 | if (encoder != null) encoder.dispose(); |
| @@ -326,7 +372,11 @@ public class MyQueryReasoner extends QueryReasoner { | |||
| 326 | if (lazyUpperStore != null) lazyUpperStore.dispose(); | 372 | if (lazyUpperStore != null) lazyUpperStore.dispose(); |
| 327 | if (elLowerStore != null) elLowerStore.dispose(); | 373 | if (elLowerStore != null) elLowerStore.dispose(); |
| 328 | if (trackingStore != null) trackingStore.dispose(); | 374 | if (trackingStore != null) trackingStore.dispose(); |
| 375 | |||
| 376 | // if(limitedSkolemUpperStore != null) limitedSkolemUpperStore.dispose(); | ||
| 329 | super.dispose(); | 377 | super.dispose(); |
| 330 | } | 378 | } |
| 331 | 379 | ||
| 380 | enum SatisfiabilityStatus {SATISFIABLE, UNSATISFIABLE, UNCHECKED} | ||
| 381 | |||
| 332 | } | 382 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java index f2b7251..118c1b2 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java | |||
| @@ -1,42 +1,44 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner; | 1 | package uk.ac.ox.cs.pagoda.reasoner; |
| 2 | 2 | ||
| 3 | import java.io.BufferedWriter; | 3 | import com.google.gson.Gson; |
| 4 | import java.io.File; | ||
| 5 | import java.io.FileNotFoundException; | ||
| 6 | import java.io.FileOutputStream; | ||
| 7 | import java.io.IOException; | ||
| 8 | import java.io.OutputStreamWriter; | ||
| 9 | import java.util.Collection; | ||
| 10 | |||
| 11 | import org.semanticweb.owlapi.model.OWLOntology; | 4 | import org.semanticweb.owlapi.model.OWLOntology; |
| 12 | |||
| 13 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | 5 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; |
| 14 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | 6 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; |
| 15 | import uk.ac.ox.cs.pagoda.query.QueryManager; | 7 | import uk.ac.ox.cs.pagoda.query.QueryManager; |
| 16 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | 8 | import uk.ac.ox.cs.pagoda.query.QueryRecord; |
| 17 | import uk.ac.ox.cs.pagoda.util.Properties; | 9 | import uk.ac.ox.cs.pagoda.util.PagodaProperties; |
| 18 | import uk.ac.ox.cs.pagoda.util.Timer; | 10 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 19 | import uk.ac.ox.cs.pagoda.util.Utility; | 11 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 20 | 12 | ||
| 13 | import java.io.BufferedWriter; | ||
| 14 | import java.io.File; | ||
| 15 | import java.io.IOException; | ||
| 16 | import java.nio.file.Files; | ||
| 17 | import java.nio.file.Paths; | ||
| 18 | import java.util.Collection; | ||
| 19 | |||
| 20 | // TODO clean APIs | ||
| 21 | public abstract class QueryReasoner { | 21 | public abstract class QueryReasoner { |
| 22 | 22 | ||
| 23 | public static final String ImportDataFileSeparator = ";"; | ||
| 24 | private static final boolean DEFAULT_MULTI_STAGES = true; | ||
| 25 | private static final boolean DEFAULT_EQUALITIES = true; | ||
| 26 | public boolean fullReasoner = this instanceof MyQueryReasoner; | ||
| 27 | protected StringBuilder importedData = new StringBuilder(); | ||
| 23 | // protected boolean forSemFacet = false; | 28 | // protected boolean forSemFacet = false; |
| 24 | Properties properties; | 29 | PagodaProperties properties; |
| 25 | 30 | BufferedWriter answerWriter = null; | |
| 26 | private static boolean defaultMultiStages = true; | 31 | private QueryManager m_queryManager = new QueryManager(); |
| 27 | private static boolean defaultEqualities = true; | ||
| 28 | 32 | ||
| 29 | public static enum Type { Full, RLU, ELHOU }; | 33 | public static QueryReasoner getInstance(PagodaProperties p) { |
| 30 | |||
| 31 | public static QueryReasoner getInstance(Properties p) { | ||
| 32 | OWLOntology ontology = OWLHelper.loadOntology(p.getOntologyPath()); | 34 | OWLOntology ontology = OWLHelper.loadOntology(p.getOntologyPath()); |
| 33 | QueryReasoner pagoda = getInstance(ontology, p); | 35 | QueryReasoner pagoda = getInstance(ontology, p); |
| 34 | pagoda.properties = p; | 36 | pagoda.properties = p; |
| 35 | pagoda.loadOntology(ontology); | 37 | pagoda.loadOntology(ontology); |
| 36 | pagoda.importData(p.getDataPath()); | 38 | pagoda.importData(p.getDataPath()); |
| 37 | if (pagoda.preprocess()) { | 39 | if (pagoda.preprocess()) { |
| 38 | Utility.logInfo("The ontology is consistent!"); | 40 | Utility.logInfo("The ontology is consistent!"); |
| 39 | return pagoda; | 41 | return pagoda; |
| 40 | } | 42 | } |
| 41 | else { | 43 | else { |
| 42 | System.out.println("The ontology is inconsistent!"); | 44 | System.out.println("The ontology is inconsistent!"); |
| @@ -44,60 +46,63 @@ public abstract class QueryReasoner { | |||
| 44 | return null; | 46 | return null; |
| 45 | } | 47 | } |
| 46 | } | 48 | } |
| 47 | 49 | ||
| 48 | public static QueryReasoner getInstance(OWLOntology o) { | 50 | public static QueryReasoner getInstance(OWLOntology o) { |
| 49 | QueryReasoner pagoda = getInstance(Type.Full, o, defaultMultiStages, defaultEqualities); | 51 | QueryReasoner pagoda = getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES); |
| 50 | pagoda.properties = new Properties(); | 52 | pagoda.properties = new PagodaProperties(); |
| 51 | return pagoda; | 53 | return pagoda; |
| 52 | } | ||
| 53 | |||
| 54 | public void setToClassify(boolean flag) { | ||
| 55 | properties.setToClassify(flag); | ||
| 56 | } | ||
| 57 | |||
| 58 | public void setToCallHermiT(boolean flag) { | ||
| 59 | properties.setToCallHermiT(flag); | ||
| 60 | } | 54 | } |
| 61 | 55 | ||
| 62 | private static QueryReasoner getInstance(OWLOntology o, Properties p) { | 56 | private static QueryReasoner getInstance(OWLOntology o, PagodaProperties p) { |
| 63 | return getInstance(Type.Full, o, defaultMultiStages, defaultEqualities); | 57 | return getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES); |
| 64 | } | 58 | } |
| 65 | 59 | ||
| 66 | public static QueryReasoner getInstance(Type type, OWLOntology o, boolean performMultiStages, boolean considerEqualities) { | 60 | public static QueryReasoner getInstance(Type type, OWLOntology o, boolean performMultiStages, boolean considerEqualities) { |
| 67 | Utility.initialise(); | 61 | // Utility.initialise(); |
| 68 | QueryReasoner reasoner; | 62 | QueryReasoner reasoner; |
| 69 | if (OWLHelper.isInOWL2RL(o)) reasoner = new RLQueryReasoner(); | 63 | if (OWLHelper.isInOWL2RL(o)) reasoner = new RLQueryReasoner(); |
| 70 | else if (OWLHelper.isInELHO(o)) reasoner = new ELHOQueryReasoner(); | 64 | else if (OWLHelper.isInELHO(o)) reasoner = new ELHOQueryReasoner(); |
| 71 | else | 65 | else |
| 72 | switch (type) { | 66 | switch (type) { |
| 73 | case RLU: | 67 | case RLU: |
| 74 | reasoner = new RLUQueryReasoner(performMultiStages, considerEqualities); break; | 68 | reasoner = new RLUQueryReasoner(performMultiStages, considerEqualities); |
| 75 | case ELHOU: | 69 | break; |
| 76 | reasoner = new ELHOUQueryReasoner(performMultiStages, considerEqualities); break; | 70 | case ELHOU: |
| 77 | default: | 71 | reasoner = new ELHOUQueryReasoner(performMultiStages, considerEqualities); |
| 78 | reasoner = new MyQueryReasoner(performMultiStages, considerEqualities); | 72 | break; |
| 73 | default: | ||
| 74 | reasoner = new MyQueryReasoner(performMultiStages, considerEqualities); | ||
| 79 | } | 75 | } |
| 80 | return reasoner; | 76 | return reasoner; |
| 77 | } | ||
| 78 | |||
| 79 | public static QueryReasoner getHermiTReasoner(boolean toCheckSatisfiability) { | ||
| 80 | return new HermiTReasoner(toCheckSatisfiability); | ||
| 81 | } | ||
| 82 | |||
| 83 | public void setToClassify(boolean flag) { | ||
| 84 | properties.setToClassify(flag); | ||
| 85 | } | ||
| 86 | |||
| 87 | public void setToCallHermiT(boolean flag) { | ||
| 88 | properties.setToCallHermiT(flag); | ||
| 81 | } | 89 | } |
| 82 | |||
| 83 | public static final String ImportDataFileSeparator = ";"; | ||
| 84 | protected StringBuilder importedData = new StringBuilder(); | ||
| 85 | 90 | ||
| 86 | public void importData(String datafile) { | 91 | public void importData(String datafile) { |
| 87 | if (datafile != null && !datafile.equalsIgnoreCase("null")) | 92 | if (datafile != null && !datafile.equalsIgnoreCase("null")) |
| 88 | importData(datafile.split(ImportDataFileSeparator)); | 93 | importData(datafile.split(ImportDataFileSeparator)); |
| 89 | } | 94 | } |
| 90 | 95 | ||
| 91 | public void importData(String[] datafiles) { | 96 | public void importData(String[] datafiles) { |
| 92 | if (datafiles != null) { | 97 | if (datafiles != null) { |
| 93 | for (String datafile: datafiles) { | 98 | for (String datafile: datafiles) { |
| 94 | File file = new File(datafile); | 99 | File file = new File(datafile); |
| 95 | if (file.exists()) { | 100 | if (file.exists()) { |
| 96 | if (file.isFile()) importDataFile(file); | 101 | if (file.isFile()) importDataFile(file); |
| 97 | else importDataDirectory(file); | 102 | else importDataDirectory(file); |
| 98 | } | 103 | } |
| 99 | else { | 104 | else { |
| 100 | Utility.logError("warning: file " + datafile + " doesn't exists."); | 105 | Utility.logError("warning: file " + datafile + " doesn't exists."); |
| 101 | } | 106 | } |
| 102 | } | 107 | } |
| 103 | } | 108 | } |
| @@ -115,136 +120,128 @@ public abstract class QueryReasoner { | |||
| 115 | datafile = file.getCanonicalPath(); | 120 | datafile = file.getCanonicalPath(); |
| 116 | } catch (IOException e) { | 121 | } catch (IOException e) { |
| 117 | e.printStackTrace(); | 122 | e.printStackTrace(); |
| 118 | return ; | 123 | return; |
| 119 | } | 124 | } |
| 120 | importDataFile(datafile); | 125 | importDataFile(datafile); |
| 121 | } | 126 | } |
| 122 | 127 | ||
| 123 | protected final void importDataFile(String datafile) { | 128 | protected final void importDataFile(String datafile) { |
| 124 | if (importedData.length() == 0) | 129 | if (importedData.length() == 0) |
| 125 | importedData.append(datafile); | 130 | importedData.append(datafile); |
| 126 | else | 131 | else |
| 127 | importedData.append(ImportDataFileSeparator).append(datafile); | 132 | importedData.append(ImportDataFileSeparator).append(datafile); |
| 128 | 133 | ||
| 129 | } | 134 | } |
| 130 | |||
| 131 | public abstract void loadOntology(OWLOntology ontology); | ||
| 132 | |||
| 133 | public abstract boolean preprocess(); | ||
| 134 | 135 | ||
| 135 | public abstract boolean isConsistent(); | 136 | public abstract void loadOntology(OWLOntology ontology); |
| 136 | 137 | ||
| 137 | public boolean fullReasoner = this instanceof MyQueryReasoner; | 138 | public abstract boolean preprocess(); |
| 138 | 139 | ||
| 139 | public abstract void evaluate(QueryRecord record); | 140 | public abstract boolean isConsistent(); |
| 140 | 141 | ||
| 141 | public abstract void evaluateUpper(QueryRecord record); | 142 | public abstract void evaluate(QueryRecord record); |
| 143 | |||
| 144 | public abstract void evaluateUpper(QueryRecord record); | ||
| 142 | 145 | ||
| 143 | public AnswerTuples evaluate(String queryText, boolean forFacetGeneration) { | 146 | public AnswerTuples evaluate(String queryText, boolean forFacetGeneration) { |
| 144 | if (forFacetGeneration) { | 147 | if (forFacetGeneration) { |
| 145 | QueryRecord record = m_queryManager.create(queryText); | 148 | QueryRecord record = m_queryManager.create(queryText); |
| 146 | Utility.logInfo("---------- start evaluating upper bound for Query " + record.getQueryID() + " ----------", queryText); | 149 | Utility.logInfo("---------- start evaluating upper bound for Query " + record.getQueryID() + " ----------", queryText); |
| 147 | if (!record.processed()) | 150 | if(!record.isProcessed()) |
| 148 | evaluateUpper(record); | 151 | evaluateUpper(record); |
| 149 | // AnswerTuples tuples = record.getUpperBoundAnswers(); | 152 | // AnswerTuples tuples = record.getUpperBoundAnswers(); |
| 150 | // for (AnswerTuple tuple; tuples.isValid(); tuples.moveNext()) { | 153 | // for (AnswerTuple tuple; tuples.isValid(); tuples.moveNext()) { |
| 151 | // tuple = tuples.getTuple(); | 154 | // tuple = tuples.getTuple(); |
| 152 | // if (tuple.toString().contains("NC")) | 155 | // if (tuple.toString().contains("NC")) |
| 153 | // System.out.println(tuple.toString()); | 156 | // System.out.println(tuple.toString()); |
| 154 | // } | 157 | // } |
| 155 | return record.getUpperBoundAnswers(); | 158 | return record.getUpperBoundAnswers(); |
| 156 | } | 159 | } else |
| 157 | else | 160 | return evaluate(queryText); |
| 158 | return evaluate(queryText); | ||
| 159 | } | 161 | } |
| 160 | 162 | ||
| 163 | // public void evaluate(Collection<QueryRecord> queryRecords) { | ||
| 164 | // evaluate(queryRecords); | ||
| 165 | // } | ||
| 166 | |||
| 161 | public AnswerTuples evaluate(String queryText) { | 167 | public AnswerTuples evaluate(String queryText) { |
| 162 | QueryRecord record = m_queryManager.create(queryText); | 168 | QueryRecord record = m_queryManager.create(queryText); |
| 163 | Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); | 169 | Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); |
| 164 | if (!record.processed()) | 170 | if(!record.isProcessed()) |
| 165 | evaluate(record); | 171 | evaluate(record); |
| 166 | AnswerTuples answer = record.getAnswers(); | 172 | AnswerTuples answer = record.getAnswers(); |
| 167 | record.dispose(); | 173 | record.dispose(); |
| 168 | return answer; | 174 | return answer; |
| 169 | 175 | ||
| 170 | } | 176 | } |
| 171 | 177 | ||
| 172 | public void evaluate_shell(String queryText) { | 178 | public void evaluate_shell(String queryText) { |
| 173 | QueryRecord record = m_queryManager.create(queryText); | 179 | QueryRecord record = m_queryManager.create(queryText); |
| 174 | Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); | 180 | Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); |
| 175 | if (!record.processed()) | 181 | if(!record.isProcessed()) |
| 176 | evaluate(record); | 182 | evaluate(record); |
| 177 | Utility.logInfo("Answers to this query: ", record.outputSoundAnswerTuple()); | 183 | Utility.logInfo("Answers to this query: ", record.outputSoundAnswerTuple()); |
| 178 | record.dispose(); | 184 | record.dispose(); |
| 179 | 185 | ||
| 180 | } | 186 | } |
| 181 | 187 | ||
| 182 | public void evaluate(Collection<QueryRecord> queryRecords) { | 188 | public void evaluate(Collection<QueryRecord> queryRecords) { |
| 183 | evaluate(queryRecords, null); | ||
| 184 | } | ||
| 185 | |||
| 186 | BufferedWriter answerWriter = null; | ||
| 187 | |||
| 188 | public void evaluate(Collection<QueryRecord> queryRecords, String answerFile) { | ||
| 189 | if (!isConsistent()) { | 189 | if (!isConsistent()) { |
| 190 | Utility.logDebug("The ontology and dataset is inconsistent."); | 190 | Utility.logDebug("The ontology and dataset is inconsistent."); |
| 191 | return ; | 191 | return; |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | if (answerWriter == null && answerFile != null) { | 194 | if(properties.getAnswerPath() != null && answerWriter == null) { |
| 195 | try { | 195 | try { |
| 196 | answerWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(answerFile))); | 196 | answerWriter = Files.newBufferedWriter(Paths.get(properties.getAnswerPath())); |
| 197 | } catch (FileNotFoundException e) { | 197 | } catch (IOException e) { |
| 198 | Utility.logInfo("The answer file not found! " + answerFile); | 198 | Utility.logError("The answer path is not valid!"); |
| 199 | return ; | 199 | e.printStackTrace(); |
| 200 | } | 200 | } |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | Timer t = new Timer(); | 203 | Timer t = new Timer(); |
| 204 | Gson gson = QueryRecord.GsonCreator.getInstance(); | ||
| 204 | for (QueryRecord record: queryRecords) { | 205 | for (QueryRecord record: queryRecords) { |
| 205 | // if (Integer.parseInt(record.getQueryID()) != 218) continue; | 206 | // if (Integer.parseInt(record.getQueryID()) != 218) continue; |
| 206 | Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", | 207 | Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", |
| 207 | record.getQueryText()); | 208 | record.getQueryText()); |
| 208 | if (!record.processed()) { | 209 | if(!record.isProcessed()) { |
| 209 | t.reset(); | 210 | t.reset(); |
| 210 | if (!record.processed()) | 211 | if(!record.isProcessed()) |
| 211 | evaluate(record); | 212 | evaluate(record); |
| 212 | Utility.logInfo("Total time to answer this query: " + t.duration()); | 213 | Utility.logInfo("Total time to answer this query: " + t.duration()); |
| 213 | if (!fullReasoner && !record.processed()) { | 214 | if(!fullReasoner && !record.isProcessed()) { |
| 214 | Utility.logInfo("The query has not been fully answered in " + t.duration() + " seconds."); | 215 | Utility.logInfo("The query has not been fully answered in " + t.duration() + " seconds."); |
| 215 | continue; | 216 | continue; |
| 216 | } | 217 | } |
| 217 | } | 218 | } |
| 218 | // FIXME: change the argument below | 219 | record.outputAnswerStatistics(); |
| 219 | try { | ||
| 220 | record.outputAnswers(answerWriter); | ||
| 221 | } catch (IOException e) { | ||
| 222 | Utility.logInfo("Error in outputing answers " + answerFile); | ||
| 223 | } | ||
| 224 | record.outputTimes(); | 220 | record.outputTimes(); |
| 225 | record.dispose(); | ||
| 226 | } | 221 | } |
| 222 | /* TODO it can handle one call only | ||
| 223 | if you call twice, you will end up with a json file with multiple roots */ | ||
| 224 | if(answerWriter != null) gson.toJson(queryRecords, answerWriter); | ||
| 225 | // queryRecords.stream().forEach(record -> Utility.logDebug(gson.toJson(record))); | ||
| 226 | queryRecords.stream().forEach(record -> record.dispose()); | ||
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | public void dispose() { | 229 | public void dispose() { |
| 230 | if (answerWriter != null) | 230 | if (answerWriter != null) { |
| 231 | try { | 231 | try { |
| 232 | answerWriter.close(); | 232 | answerWriter.close(); |
| 233 | } catch (IOException e) { | 233 | } catch (IOException e) { |
| 234 | e.printStackTrace(); | 234 | e.printStackTrace(); |
| 235 | } | 235 | } |
| 236 | Utility.cleanup(); | 236 | } |
| 237 | } | 237 | // Utility.cleanup(); |
| 238 | 238 | } | |
| 239 | private QueryManager m_queryManager = new QueryManager(); | ||
| 240 | 239 | ||
| 241 | public QueryManager getQueryManager() { | 240 | public QueryManager getQueryManager() { |
| 242 | return m_queryManager; | 241 | return m_queryManager; |
| 243 | } | 242 | } |
| 244 | 243 | ||
| 245 | 244 | ||
| 246 | public static QueryReasoner getHermiTReasoner(boolean toCheckSatisfiability) { | 245 | public enum Type {Full, RLU, ELHOU} |
| 247 | return new HermiTReasoner(toCheckSatisfiability); | 246 | |
| 248 | } | ||
| 249 | |||
| 250 | } | 247 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java index 3894874..bea5bbf 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java | |||
| @@ -10,18 +10,17 @@ import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxQueryEngine; | |||
| 10 | import uk.ac.ox.cs.pagoda.rules.LowerDatalogProgram; | 10 | import uk.ac.ox.cs.pagoda.rules.LowerDatalogProgram; |
| 11 | import uk.ac.ox.cs.pagoda.util.Timer; | 11 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 12 | 12 | ||
| 13 | public class RLQueryReasoner extends QueryReasoner { | 13 | class RLQueryReasoner extends QueryReasoner { |
| 14 | 14 | ||
| 15 | RDFoxQueryEngine rlLowerStore = null; | 15 | RDFoxQueryEngine rlLowerStore = null; |
| 16 | 16 | ||
| 17 | LowerDatalogProgram program; | 17 | LowerDatalogProgram program; |
| 18 | Timer t = new Timer(); | ||
| 18 | 19 | ||
| 19 | public RLQueryReasoner() { | 20 | public RLQueryReasoner() { |
| 20 | rlLowerStore = new BasicQueryEngine("rl"); | 21 | rlLowerStore = new BasicQueryEngine("rl"); |
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | Timer t = new Timer(); | ||
| 24 | |||
| 25 | @Override | 24 | @Override |
| 26 | public void evaluate(QueryRecord queryRecord) { | 25 | public void evaluate(QueryRecord queryRecord) { |
| 27 | AnswerTuples rlAnswer = null; | 26 | AnswerTuples rlAnswer = null; |
| @@ -32,8 +31,8 @@ public class RLQueryReasoner extends QueryReasoner { | |||
| 32 | } finally { | 31 | } finally { |
| 33 | if (rlAnswer != null) rlAnswer.dispose(); | 32 | if (rlAnswer != null) rlAnswer.dispose(); |
| 34 | } | 33 | } |
| 35 | queryRecord.addProcessingTime(Step.LowerBound, t.duration()); | 34 | queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration()); |
| 36 | queryRecord.setDifficulty(Step.LowerBound); | 35 | queryRecord.setDifficulty(Step.LOWER_BOUND); |
| 37 | queryRecord.markAsProcessed(); | 36 | queryRecord.markAsProcessed(); |
| 38 | } | 37 | } |
| 39 | 38 | ||
| @@ -56,10 +55,8 @@ public class RLQueryReasoner extends QueryReasoner { | |||
| 56 | public boolean preprocess() { | 55 | public boolean preprocess() { |
| 57 | rlLowerStore.importRDFData("data", importedData.toString()); | 56 | rlLowerStore.importRDFData("data", importedData.toString()); |
| 58 | rlLowerStore.materialise("lower program", program.toString()); | 57 | rlLowerStore.materialise("lower program", program.toString()); |
| 59 | 58 | ||
| 60 | if (!isConsistent()) | 59 | return isConsistent(); |
| 61 | return false; | ||
| 62 | return true; | ||
| 63 | } | 60 | } |
| 64 | 61 | ||
| 65 | @Override | 62 | @Override |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java index fe4022d..547140a 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner; | 1 | package uk.ac.ox.cs.pagoda.reasoner; |
| 2 | 2 | ||
| 3 | import org.semanticweb.owlapi.model.OWLOntology; | 3 | import org.semanticweb.owlapi.model.OWLOntology; |
| 4 | |||
| 5 | import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; | 4 | import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; |
| 6 | import uk.ac.ox.cs.pagoda.owl.EqualitiesEliminator; | 5 | import uk.ac.ox.cs.pagoda.owl.EqualitiesEliminator; |
| 7 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | 6 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; |
| @@ -12,26 +11,25 @@ import uk.ac.ox.cs.pagoda.rules.DatalogProgram; | |||
| 12 | import uk.ac.ox.cs.pagoda.util.Timer; | 11 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 13 | import uk.ac.ox.cs.pagoda.util.Utility; | 12 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 14 | 13 | ||
| 15 | public class RLUQueryReasoner extends QueryReasoner { | 14 | class RLUQueryReasoner extends QueryReasoner { |
| 16 | 15 | ||
| 17 | DatalogProgram program; | 16 | DatalogProgram program; |
| 18 | 17 | ||
| 19 | BasicQueryEngine rlLowerStore, rlUpperStore; | 18 | BasicQueryEngine rlLowerStore, rlUpperStore; |
| 20 | 19 | ||
| 21 | boolean multiStageTag, equalityTag; | 20 | boolean multiStageTag, equalityTag; |
| 21 | Timer t = new Timer(); | ||
| 22 | 22 | ||
| 23 | public RLUQueryReasoner(boolean multiStageTag, boolean considerEqualities) { | 23 | public RLUQueryReasoner(boolean multiStageTag, boolean considerEqualities) { |
| 24 | this.multiStageTag = multiStageTag; | 24 | this.multiStageTag = multiStageTag; |
| 25 | this.equalityTag = considerEqualities; | 25 | this.equalityTag = considerEqualities; |
| 26 | rlLowerStore = new BasicQueryEngine("rl-lower-bound"); | 26 | rlLowerStore = new BasicQueryEngine("rl-lower-bound"); |
| 27 | if (!multiStageTag) | 27 | if(!multiStageTag) |
| 28 | rlUpperStore = new BasicQueryEngine("rl-upper-bound"); | 28 | rlUpperStore = new BasicQueryEngine("rl-upper-bound"); |
| 29 | else | 29 | else |
| 30 | rlUpperStore = new MultiStageQueryEngine("rl-upper-bound", false); | 30 | rlUpperStore = new MultiStageQueryEngine("rl-upper-bound", false); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | Timer t = new Timer(); | ||
| 34 | |||
| 35 | @Override | 33 | @Override |
| 36 | public void evaluate(QueryRecord queryRecord) { | 34 | public void evaluate(QueryRecord queryRecord) { |
| 37 | AnswerTuples ans = null; | 35 | AnswerTuples ans = null; |
| @@ -43,7 +41,7 @@ public class RLUQueryReasoner extends QueryReasoner { | |||
| 43 | } finally { | 41 | } finally { |
| 44 | if (ans != null) ans.dispose(); | 42 | if (ans != null) ans.dispose(); |
| 45 | } | 43 | } |
| 46 | queryRecord.addProcessingTime(Step.LowerBound, t.duration()); | 44 | queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration()); |
| 47 | 45 | ||
| 48 | ans = null; | 46 | ans = null; |
| 49 | t.reset(); | 47 | t.reset(); |
| @@ -54,10 +52,10 @@ public class RLUQueryReasoner extends QueryReasoner { | |||
| 54 | } finally { | 52 | } finally { |
| 55 | if (ans != null) ans.dispose(); | 53 | if (ans != null) ans.dispose(); |
| 56 | } | 54 | } |
| 57 | queryRecord.addProcessingTime(Step.UpperBound, t.duration()); | 55 | queryRecord.addProcessingTime(Step.UPPER_BOUND, t.duration()); |
| 58 | 56 | ||
| 59 | if (queryRecord.processed()) | 57 | if(queryRecord.isProcessed()) |
| 60 | queryRecord.setDifficulty(Step.UpperBound); | 58 | queryRecord.setDifficulty(Step.UPPER_BOUND); |
| 61 | } | 59 | } |
| 62 | 60 | ||
| 63 | @Override | 61 | @Override |
| @@ -100,11 +98,9 @@ public class RLUQueryReasoner extends QueryReasoner { | |||
| 100 | 98 | ||
| 101 | rlUpperStore.importRDFData("data", datafile); | 99 | rlUpperStore.importRDFData("data", datafile); |
| 102 | rlUpperStore.materialiseRestrictedly(program, null); | 100 | rlUpperStore.materialiseRestrictedly(program, null); |
| 103 | |||
| 104 | if (!isConsistent()) | ||
| 105 | return false; | ||
| 106 | 101 | ||
| 107 | return true; | 102 | return isConsistent(); |
| 103 | |||
| 108 | } | 104 | } |
| 109 | 105 | ||
| 110 | @Override | 106 | @Override |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/light/DLPredicateComparator.java b/src/uk/ac/ox/cs/pagoda/reasoner/light/DLPredicateComparator.java index c22902c..05e399e 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/DLPredicateComparator.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/DLPredicateComparator.java | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner.light; | 1 | package uk.ac.ox.cs.pagoda.reasoner.light; |
| 2 | 2 | ||
| 3 | import java.util.Comparator; | ||
| 4 | |||
| 5 | import uk.ac.ox.cs.pagoda.multistage.Normalisation; | 3 | import uk.ac.ox.cs.pagoda.multistage.Normalisation; |
| 6 | import uk.ac.ox.cs.pagoda.rules.OverApproxExist; | 4 | import uk.ac.ox.cs.pagoda.rules.approximators.OverApproxExist; |
| 5 | |||
| 6 | import java.util.Comparator; | ||
| 7 | 7 | ||
| 8 | public class DLPredicateComparator implements Comparator<String> { | 8 | public class DLPredicateComparator implements Comparator<String> { |
| 9 | 9 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java b/src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java index f70dde9..f068164 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java | |||
| @@ -1,20 +1,22 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner.light; | 1 | package uk.ac.ox.cs.pagoda.reasoner.light; |
| 2 | 2 | ||
| 3 | import java.io.File; | 3 | import org.semanticweb.karma2.MyKarma; |
| 4 | import java.io.FileNotFoundException; | ||
| 5 | import java.util.*; | ||
| 6 | |||
| 7 | import org.semanticweb.karma2.*; | ||
| 8 | import org.semanticweb.karma2.clausifier.OntologyProcesser; | 4 | import org.semanticweb.karma2.clausifier.OntologyProcesser; |
| 9 | import org.semanticweb.karma2.exception.IllegalInputOntologyException; | 5 | import org.semanticweb.karma2.exception.IllegalInputOntologyException; |
| 10 | import org.semanticweb.karma2.model.ConjunctiveQuery; | 6 | import org.semanticweb.karma2.model.ConjunctiveQuery; |
| 11 | import org.semanticweb.owlapi.model.OWLOntology; | 7 | import org.semanticweb.owlapi.model.OWLOntology; |
| 12 | |||
| 13 | import uk.ac.ox.cs.pagoda.query.*; | ||
| 14 | import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper; | ||
| 15 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 16 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 8 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| 17 | import uk.ac.ox.cs.JRDFox.store.DataStore; | 9 | import uk.ac.ox.cs.JRDFox.store.DataStore; |
| 10 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | ||
| 11 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 12 | import uk.ac.ox.cs.pagoda.query.AnswerTuplesImp; | ||
| 13 | import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper; | ||
| 14 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 15 | |||
| 16 | import java.io.File; | ||
| 17 | import java.io.FileNotFoundException; | ||
| 18 | import java.nio.file.Paths; | ||
| 19 | import java.util.Set; | ||
| 18 | 20 | ||
| 19 | public class KarmaQueryEngine extends RDFoxQueryEngine { | 21 | public class KarmaQueryEngine extends RDFoxQueryEngine { |
| 20 | 22 | ||
| @@ -29,8 +31,8 @@ public class KarmaQueryEngine extends RDFoxQueryEngine { | |||
| 29 | // int index = (new Random().nextInt() % Base + Base) % Base; | 31 | // int index = (new Random().nextInt() % Base + Base) % Base; |
| 30 | // karmaDataFile = "karma_data" + index + ".ttl"; | 32 | // karmaDataFile = "karma_data" + index + ".ttl"; |
| 31 | // karmaRuleFile = "karma_rule" + index + ".dlog"; | 33 | // karmaRuleFile = "karma_rule" + index + ".dlog"; |
| 32 | karmaDataFile = Utility.TempDirectory + "karma_data.ttl"; | 34 | karmaDataFile = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "karma_data.ttl").toString(); |
| 33 | karmaRuleFile = Utility.TempDirectory + "karma_rule.dlog"; | 35 | karmaRuleFile = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "karma_rule.dlog").toString(); |
| 34 | 36 | ||
| 35 | reasoner = new MyKarma(); | 37 | reasoner = new MyKarma(); |
| 36 | } | 38 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java index 70d0cc9..61500f5 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java | |||
| @@ -1,8 +1,11 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner.light; | 1 | package uk.ac.ox.cs.pagoda.reasoner.light; |
| 2 | 2 | ||
| 3 | import java.io.File; | 3 | import org.semanticweb.owlapi.model.OWLOntology; |
| 4 | import java.util.Collection; | 4 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; |
| 5 | 5 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | |
| 6 | import uk.ac.ox.cs.JRDFox.Prefixes; | ||
| 7 | import uk.ac.ox.cs.JRDFox.store.DataStore; | ||
| 8 | import uk.ac.ox.cs.JRDFox.store.DataStore.StoreType; | ||
| 6 | import uk.ac.ox.cs.pagoda.MyPrefixes; | 9 | import uk.ac.ox.cs.pagoda.MyPrefixes; |
| 7 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | 10 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; |
| 8 | import uk.ac.ox.cs.pagoda.reasoner.QueryEngine; | 11 | import uk.ac.ox.cs.pagoda.reasoner.QueryEngine; |
| @@ -10,36 +13,51 @@ import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | |||
| 10 | import uk.ac.ox.cs.pagoda.tracking.AnswerTuplesWriter; | 13 | import uk.ac.ox.cs.pagoda.tracking.AnswerTuplesWriter; |
| 11 | import uk.ac.ox.cs.pagoda.util.Timer; | 14 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 12 | import uk.ac.ox.cs.pagoda.util.Utility; | 15 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 13 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 16 | |
| 14 | import uk.ac.ox.cs.JRDFox.Prefixes; | 17 | import java.io.File; |
| 15 | import uk.ac.ox.cs.JRDFox.store.DataStore; | 18 | import java.util.Collection; |
| 16 | import uk.ac.ox.cs.JRDFox.store.DataStore.StoreType; | ||
| 17 | 19 | ||
| 18 | public abstract class RDFoxQueryEngine implements QueryEngine { | 20 | public abstract class RDFoxQueryEngine implements QueryEngine { |
| 19 | 21 | ||
| 20 | public static final int matNoOfThreads = Runtime.getRuntime().availableProcessors() * 2; | 22 | public static final int matNoOfThreads = Runtime.getRuntime().availableProcessors() * 2; |
| 21 | 23 | protected String name; | |
| 22 | protected String name; | ||
| 23 | protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes(); | 24 | protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes(); |
| 24 | 25 | ||
| 25 | public RDFoxQueryEngine(String name) { | 26 | public RDFoxQueryEngine(String name) { |
| 26 | this.name = name; | 27 | this.name = name; |
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | public abstract DataStore getDataStore(); | 30 | public static DataStore createDataStore() { |
| 31 | DataStore instance = null; | ||
| 32 | try { | ||
| 33 | // instance = new DataStore("par-head-n"); | ||
| 34 | instance = new DataStore(StoreType.NarrowParallelHead); | ||
| 35 | instance.setNumberOfThreads(matNoOfThreads); | ||
| 36 | instance.initialize(); | ||
| 37 | } catch(JRDFStoreException e) { | ||
| 38 | e.printStackTrace(); | ||
| 39 | } | ||
| 40 | return instance; | ||
| 41 | } | ||
| 30 | 42 | ||
| 31 | public abstract void dispose(); | 43 | public String getName() { |
| 44 | return name; | ||
| 45 | } | ||
| 32 | 46 | ||
| 47 | public abstract DataStore getDataStore(); | ||
| 48 | |||
| 49 | public abstract void dispose(); | ||
| 50 | |||
| 33 | public void importRDFData(String fileName, String importedFile) { | 51 | public void importRDFData(String fileName, String importedFile) { |
| 34 | if (importedFile == null || importedFile.isEmpty()) return ; | 52 | if(importedFile == null || importedFile.isEmpty()) return; |
| 35 | Timer t = new Timer(); | 53 | Timer t = new Timer(); |
| 36 | DataStore store = getDataStore(); | 54 | DataStore store = getDataStore(); |
| 37 | try { | 55 | try { |
| 38 | long oldTripleCount = store.getTriplesCount(), tripleCount; | 56 | long oldTripleCount = store.getTriplesCount(), tripleCount; |
| 39 | for (String file: importedFile.split(QueryReasoner.ImportDataFileSeparator)) { | 57 | for (String file: importedFile.split(QueryReasoner.ImportDataFileSeparator)) { |
| 40 | store.importTurtleFile(new File(file), prefixes); | 58 | store.importTurtleFile(new File(file), prefixes); |
| 41 | } | 59 | } |
| 42 | tripleCount = store.getTriplesCount(); | 60 | tripleCount = store.getTriplesCount(); |
| 43 | Utility.logDebug(name + " store after importing " + fileName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); | 61 | Utility.logDebug(name + " store after importing " + fileName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); |
| 44 | store.clearRulesAndMakeFactsExplicit(); | 62 | store.clearRulesAndMakeFactsExplicit(); |
| 45 | } catch (JRDFStoreException e) { | 63 | } catch (JRDFStoreException e) { |
| @@ -47,17 +65,32 @@ public abstract class RDFoxQueryEngine implements QueryEngine { | |||
| 47 | } | 65 | } |
| 48 | Utility.logDebug(name + " store finished importing " + fileName + " in " + t.duration() + " seconds."); | 66 | Utility.logDebug(name + " store finished importing " + fileName + " in " + t.duration() + " seconds."); |
| 49 | } | 67 | } |
| 50 | 68 | ||
| 69 | public void importDataFromABoxOf(OWLOntology ontology) { | ||
| 70 | DataStore store = getDataStore(); | ||
| 71 | try { | ||
| 72 | long prevTriplesCount = store.getTriplesCount(); | ||
| 73 | store.importOntology(ontology.getOWLOntologyManager().createOntology(ontology.getABoxAxioms(true))); | ||
| 74 | long loadedTriples = store.getTriplesCount() - prevTriplesCount; | ||
| 75 | Utility.logInfo(name + ": loaded " + loadedTriples + " triples from " + ontology.getABoxAxioms(true) | ||
| 76 | .size() + " ABox axioms"); | ||
| 77 | } catch(JRDFStoreException | OWLOntologyCreationException e) { | ||
| 78 | e.printStackTrace(); | ||
| 79 | System.exit(1); | ||
| 80 | } | ||
| 81 | |||
| 82 | } | ||
| 83 | |||
| 51 | public void materialise(String programName, String programText) { | 84 | public void materialise(String programName, String programText) { |
| 52 | if (programText == null) return ; | 85 | if(programText == null) return; |
| 53 | Timer t = new Timer(); | 86 | Timer t = new Timer(); |
| 54 | DataStore store = getDataStore(); | 87 | DataStore store = getDataStore(); |
| 55 | try { | 88 | try { |
| 56 | long oldTripleCount = store.getTriplesCount(), tripleCount; | 89 | long oldTripleCount = store.getTriplesCount(), tripleCount; |
| 57 | // store.addRules(new String[] {programText}); | 90 | // store.addRules(new String[] {programText}); |
| 58 | store.importRules(programText); | 91 | store.importRules(programText); |
| 59 | store.applyReasoning(); | 92 | store.applyReasoning(); |
| 60 | tripleCount = store.getTriplesCount(); | 93 | tripleCount = store.getTriplesCount(); |
| 61 | Utility.logDebug(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); | 94 | Utility.logDebug(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); |
| 62 | store.clearRulesAndMakeFactsExplicit(); | 95 | store.clearRulesAndMakeFactsExplicit(); |
| 63 | } catch (JRDFStoreException e) { | 96 | } catch (JRDFStoreException e) { |
| @@ -70,17 +103,17 @@ public abstract class RDFoxQueryEngine implements QueryEngine { | |||
| 70 | public void evaluate(Collection<String> queryTexts, String answerFile) { | 103 | public void evaluate(Collection<String> queryTexts, String answerFile) { |
| 71 | if (queryTexts == null) | 104 | if (queryTexts == null) |
| 72 | return ; | 105 | return ; |
| 73 | 106 | ||
| 74 | int queryID = 0; | 107 | int queryID = 0; |
| 75 | AnswerTuplesWriter answerWriter = new AnswerTuplesWriter(answerFile); | 108 | AnswerTuplesWriter answerWriter = new AnswerTuplesWriter(answerFile); |
| 76 | AnswerTuples answerTuples; | 109 | AnswerTuples answerTuples; |
| 77 | Timer t = new Timer(); | 110 | Timer t = new Timer(); |
| 78 | try { | 111 | try { |
| 79 | for (String query: queryTexts) { | 112 | for (String query: queryTexts) { |
| 80 | t.reset(); | 113 | t.reset(); |
| 81 | answerTuples = null; | 114 | answerTuples = null; |
| 82 | try { | 115 | try { |
| 83 | answerTuples = evaluate(query); | 116 | answerTuples = evaluate(query); |
| 84 | Utility.logDebug("time to answer Query " + ++queryID + ": " + t.duration()); | 117 | Utility.logDebug("time to answer Query " + ++queryID + ": " + t.duration()); |
| 85 | answerWriter.write(answerTuples.getAnswerVariables(), answerTuples); | 118 | answerWriter.write(answerTuples.getAnswerVariables(), answerTuples); |
| 86 | } finally { | 119 | } finally { |
| @@ -90,22 +123,9 @@ public abstract class RDFoxQueryEngine implements QueryEngine { | |||
| 90 | } finally { | 123 | } finally { |
| 91 | answerWriter.close(); | 124 | answerWriter.close(); |
| 92 | } | 125 | } |
| 93 | 126 | ||
| 94 | Utility.logDebug("done computing query answers by RDFox."); | 127 | Utility.logDebug("done computing query answers by RDFox."); |
| 95 | 128 | ||
| 96 | } | ||
| 97 | |||
| 98 | public static DataStore createDataStore() { | ||
| 99 | DataStore instance = null; | ||
| 100 | try { | ||
| 101 | // instance = new DataStore("par-head-n"); | ||
| 102 | instance = new DataStore(StoreType.NarrowParallelHead); | ||
| 103 | instance.setNumberOfThreads(matNoOfThreads); | ||
| 104 | instance.initialize(); | ||
| 105 | } catch (JRDFStoreException e) { | ||
| 106 | e.printStackTrace(); | ||
| 107 | } | ||
| 108 | return instance; | ||
| 109 | } | 129 | } |
| 110 | 130 | ||
| 111 | } | 131 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxTripleManager.java b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxTripleManager.java index c2065dc..85f8ef9 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxTripleManager.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxTripleManager.java | |||
| @@ -1,35 +1,33 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner.light; | 1 | package uk.ac.ox.cs.pagoda.reasoner.light; |
| 2 | 2 | ||
| 3 | import java.util.Collection; | 3 | import net.sf.ehcache.Cache; |
| 4 | import java.util.HashMap; | 4 | import net.sf.ehcache.CacheManager; |
| 5 | import java.util.LinkedList; | 5 | import net.sf.ehcache.Element; |
| 6 | import java.util.Map; | 6 | import org.semanticweb.HermiT.model.*; |
| 7 | import java.util.Queue; | ||
| 8 | import org.semanticweb.HermiT.model.AnnotatedEquality; | ||
| 9 | import org.semanticweb.HermiT.model.Atom; | ||
| 10 | import org.semanticweb.HermiT.model.AtomicConcept; | ||
| 11 | import org.semanticweb.HermiT.model.AtomicRole; | ||
| 12 | import org.semanticweb.HermiT.model.Constant; | ||
| 13 | import org.semanticweb.HermiT.model.DLPredicate; | ||
| 14 | import org.semanticweb.HermiT.model.Equality; | ||
| 15 | import org.semanticweb.HermiT.model.Individual; | ||
| 16 | import org.semanticweb.HermiT.model.Inequality; | ||
| 17 | import org.semanticweb.HermiT.model.Term; | ||
| 18 | import org.semanticweb.HermiT.model.Variable; | ||
| 19 | |||
| 20 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 21 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 22 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 7 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| 8 | import uk.ac.ox.cs.JRDFox.model.Datatype; | ||
| 23 | import uk.ac.ox.cs.JRDFox.model.GroundTerm; | 9 | import uk.ac.ox.cs.JRDFox.model.GroundTerm; |
| 24 | import uk.ac.ox.cs.JRDFox.store.DataStore; | 10 | import uk.ac.ox.cs.JRDFox.store.DataStore; |
| 25 | import uk.ac.ox.cs.JRDFox.model.Datatype; | ||
| 26 | import uk.ac.ox.cs.JRDFox.store.Dictionary; | ||
| 27 | import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType; | 11 | import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType; |
| 12 | import uk.ac.ox.cs.JRDFox.store.Dictionary; | ||
| 28 | import uk.ac.ox.cs.JRDFox.store.Resource; | 13 | import uk.ac.ox.cs.JRDFox.store.Resource; |
| 14 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 15 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 16 | |||
| 17 | import java.util.Collection; | ||
| 18 | import java.util.HashMap; | ||
| 19 | import java.util.Map; | ||
| 29 | 20 | ||
| 30 | public class RDFoxTripleManager { | 21 | public class RDFoxTripleManager { |
| 31 | 22 | ||
| 32 | UpdateType m_incrementally; | 23 | private final Cache termsCache; |
| 24 | private static final int TERMS_CACHE_SIZE = 10000; | ||
| 25 | private static final int CACHE_TTL_DEFAULT = 0; | ||
| 26 | private static final int CACHE_TTI_DEFAULT = 0; | ||
| 27 | private static final boolean CACHE_ETERNAL = true; | ||
| 28 | private static final boolean CACHE_USE_DISK = false; | ||
| 29 | |||
| 30 | UpdateType m_incrementally; | ||
| 33 | // boolean m_incrementally; | 31 | // boolean m_incrementally; |
| 34 | 32 | ||
| 35 | DataStore m_store; | 33 | DataStore m_store; |
| @@ -38,7 +36,19 @@ public class RDFoxTripleManager { | |||
| 38 | 36 | ||
| 39 | public RDFoxTripleManager(DataStore store, boolean incrementally) { | 37 | public RDFoxTripleManager(DataStore store, boolean incrementally) { |
| 40 | m_store = store; | 38 | m_store = store; |
| 41 | // m_incrementally = incrementally; | 39 | // m_incrementally = incrementally; |
| 40 | |||
| 41 | CacheManager cacheManager = CacheManager.getInstance(); | ||
| 42 | String cacheName = "RDFoxTripleManager_" + store.hashCode(); | ||
| 43 | if(! cacheManager.cacheExists(cacheName)) { | ||
| 44 | termsCache = new Cache(cacheName, | ||
| 45 | TERMS_CACHE_SIZE, CACHE_USE_DISK, CACHE_ETERNAL, | ||
| 46 | CACHE_TTL_DEFAULT, CACHE_TTI_DEFAULT); | ||
| 47 | cacheManager.addCache(termsCache); | ||
| 48 | } | ||
| 49 | else | ||
| 50 | termsCache = cacheManager.getCache(cacheName); | ||
| 51 | |||
| 42 | if (incrementally) | 52 | if (incrementally) |
| 43 | m_incrementally = UpdateType.ScheduleForAddition; | 53 | m_incrementally = UpdateType.ScheduleForAddition; |
| 44 | else | 54 | else |
| @@ -178,28 +188,25 @@ public class RDFoxTripleManager { | |||
| 178 | return m_dict.resolveResources(lexicalForms, types)[0]; | 188 | return m_dict.resolveResources(lexicalForms, types)[0]; |
| 179 | } | 189 | } |
| 180 | 190 | ||
| 181 | Map<Term, Integer> termCache = new HashMap<Term, Integer>(); | 191 | // Map<Term, Integer> termCache = new HashMap<Term, Integer>(); |
| 182 | Queue<Term> termList = new LinkedList<Term>(); | 192 | // Queue<Term> termQueue = new LinkedList<Term>(); |
| 183 | int sizeLimit = 10000; | ||
| 184 | 193 | ||
| 185 | private int getResourceID(Term arg, Map<Variable, Integer> assignment) { | 194 | private int getResourceID(Term arg, Map<Variable, Integer> assignment) { |
| 186 | while (termCache.size() > sizeLimit) | 195 | if (arg instanceof Variable) return assignment.get(arg); |
| 187 | termCache.remove(termList.poll()); | 196 | int id = -1; |
| 188 | 197 | if(termsCache.isKeyInCache(arg)) | |
| 189 | if (arg instanceof Variable) return assignment.get((Variable) arg); | 198 | return ((int) termsCache.get(arg).getObjectValue()); |
| 190 | Integer id = null; | 199 | |
| 191 | if ((id = termCache.get(arg)) != null) | ||
| 192 | return id; | ||
| 193 | |||
| 194 | // if (arg instanceof Individual) { | 200 | // if (arg instanceof Individual) { |
| 195 | try { | 201 | try { |
| 196 | if (arg instanceof Individual) | 202 | if (arg instanceof Individual) |
| 197 | termCache.put(arg, id = resolveResource(((Individual) arg).getIRI(), Datatype.IRI_REFERENCE.value())); | 203 | termsCache.put(new Element(arg, id = resolveResource(((Individual) arg).getIRI(), Datatype.IRI_REFERENCE.value()))); |
| 198 | else if (arg instanceof Constant) | 204 | else if (arg instanceof Constant) |
| 199 | termCache.put(arg, id = resolveResource(((Constant) arg).getLexicalForm(), getDatatypeID(((Constant) arg).getDatatypeURI()))); | 205 | termsCache.put(new Element(arg, id = resolveResource(((Constant) arg).getLexicalForm(), getDatatypeID(((Constant) arg).getDatatypeURI())))); |
| 200 | 206 | ||
| 201 | } catch (JRDFStoreException e) { | 207 | } catch (JRDFStoreException e) { |
| 202 | e.printStackTrace(); | 208 | e.printStackTrace(); |
| 209 | System.exit(1); | ||
| 203 | } | 210 | } |
| 204 | // } | 211 | // } |
| 205 | 212 | ||
