aboutsummaryrefslogtreecommitdiff
path: root/src/uk/ac/ox/cs/pagoda/reasoner
diff options
context:
space:
mode:
authorRncLsn <rnc.lsn@gmail.com>2015-06-03 15:21:30 +0100
committerRncLsn <rnc.lsn@gmail.com>2015-06-03 15:21:30 +0100
commitb3b822d187a6402a39d30e471fe90a5dfad64312 (patch)
tree912e1914610c8cf6103b7b7aef07087ddd7eb62f /src/uk/ac/ox/cs/pagoda/reasoner
parent691964863246bbf6ef9f72cc5e82c83df34f135a (diff)
downloadACQuA-b3b822d187a6402a39d30e471fe90a5dfad64312.tar.gz
ACQuA-b3b822d187a6402a39d30e471fe90a5dfad64312.zip
Before reintroducing extended queries.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/reasoner')
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java13
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java2
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java2
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java4
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java93
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java14
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java2
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java2
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/full/Checker.java12
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java330
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java38
11 files changed, 301 insertions, 211 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java
index 453b5ca..3fd2fbd 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java
@@ -23,6 +23,7 @@ import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoder;
23import uk.ac.ox.cs.pagoda.util.Timer; 23import uk.ac.ox.cs.pagoda.util.Timer;
24import uk.ac.ox.cs.pagoda.util.Utility; 24import uk.ac.ox.cs.pagoda.util.Utility;
25import uk.ac.ox.cs.pagoda.util.disposable.Disposable; 25import uk.ac.ox.cs.pagoda.util.disposable.Disposable;
26import uk.ac.ox.cs.pagoda.util.disposable.DisposedException;
26 27
27import java.util.LinkedList; 28import java.util.LinkedList;
28 29
@@ -49,6 +50,8 @@ public class ConsistencyManager extends Disposable {
49 } 50 }
50 51
51 public void extractBottomFragment() { 52 public void extractBottomFragment() {
53 if(isDisposed()) throw new DisposedException();
54
52 if(fragmentExtracted) return; 55 if(fragmentExtracted) return;
53 fragmentExtracted = true; 56 fragmentExtracted = true;
54 57
@@ -141,10 +144,14 @@ public class ConsistencyManager extends Disposable {
141 } 144 }
142 145
143 public QueryRecord[] getQueryRecords() { 146 public QueryRecord[] getQueryRecords() {
147 if(isDisposed()) throw new DisposedException();
148
144 return botQueryRecords; 149 return botQueryRecords;
145 } 150 }
146 151
147 boolean checkRLLowerBound() { 152 boolean checkRLLowerBound() {
153 if(isDisposed()) throw new DisposedException();
154
148 fullQueryRecord = m_queryManager.create(QueryRecord.botQueryText, 0); 155 fullQueryRecord = m_queryManager.create(QueryRecord.botQueryText, 0);
149 AnswerTuples iter = null; 156 AnswerTuples iter = null;
150 157
@@ -175,6 +182,8 @@ public class ConsistencyManager extends Disposable {
175// } 182// }
176 183
177 boolean checkELLowerBound() { 184 boolean checkELLowerBound() {
185 if(isDisposed()) throw new DisposedException();
186
178 fullQueryRecord.updateLowerBoundAnswers(m_reasoner.elLowerStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord 187 fullQueryRecord.updateLowerBoundAnswers(m_reasoner.elLowerStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord
179 .getAnswerVariables())); 188 .getAnswerVariables()));
180 if(fullQueryRecord.getNoOfSoundAnswers() > 0) { 189 if(fullQueryRecord.getNoOfSoundAnswers() > 0) {
@@ -185,6 +194,8 @@ public class ConsistencyManager extends Disposable {
185 } 194 }
186 195
187 boolean checkUpper(BasicQueryEngine upperStore) { 196 boolean checkUpper(BasicQueryEngine upperStore) {
197 if(isDisposed()) throw new DisposedException();
198
188 if(upperStore != null) { 199 if(upperStore != null) {
189 AnswerTuples tuples = null; 200 AnswerTuples tuples = null;
190 try { 201 try {
@@ -202,6 +213,8 @@ public class ConsistencyManager extends Disposable {
202 } 213 }
203 214
204 boolean check() { 215 boolean check() {
216 if(isDisposed()) throw new DisposedException();
217
205// if (!checkRLLowerBound()) return false; 218// if (!checkRLLowerBound()) return false;
206// if (!checkELLowerBound()) return false; 219// if (!checkELLowerBound()) return false;
207// if (checkLazyUpper()) return true; 220// if (checkLazyUpper()) return true;
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java
index 0a151bc..cc2c4c0 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java
@@ -70,7 +70,7 @@ class ELHOQueryReasoner extends QueryReasoner {
70 @Override 70 @Override
71 public boolean preprocess() { 71 public boolean preprocess() {
72 if(isDisposed()) throw new DisposedException(); 72 if(isDisposed()) throw new DisposedException();
73 elLowerStore.importRDFData("data", importedData.toString()); 73 elLowerStore.importRDFData("data", getImportedData());
74 String rlLowerProgramText = program.toString(); 74 String rlLowerProgramText = program.toString();
75// program.save(); 75// program.save();
76 elLowerStore.materialise("lower program", rlLowerProgramText); 76 elLowerStore.materialise("lower program", rlLowerProgramText);
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java
index 771190e..a56a793 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java
@@ -129,7 +129,7 @@ class ELHOUQueryReasoner extends QueryReasoner {
129 @Override 129 @Override
130 public boolean preprocess() { 130 public boolean preprocess() {
131 if(isDisposed()) throw new DisposedException(); 131 if(isDisposed()) throw new DisposedException();
132 String name = "data", datafile = importedData.toString(); 132 String name = "data", datafile = getImportedData();
133 133
134 String lowername = "lower program"; 134 String lowername = "lower program";
135 String rlLowerProgramText = program.getLower().toString(); 135 String rlLowerProgramText = program.getLower().toString();
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java
index 78b9a0b..15eb9e8 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java
@@ -46,7 +46,7 @@ class HermiTReasoner extends QueryReasoner {
46 if(isDisposed()) throw new DisposedException(); 46 if(isDisposed()) throw new DisposedException();
47 OWLOntology tbox = onto; 47 OWLOntology tbox = onto;
48 try { 48 try {
49 onto = OWLHelper.getImportedOntology(tbox, importedData.toString().split(ImportDataFileSeparator)); 49 onto = OWLHelper.getImportedOntology(tbox, getImportedData().split(ImportDataFileSeparator));
50 importedOntologyPath = OWLHelper.getOntologyPath(onto); 50 importedOntologyPath = OWLHelper.getOntologyPath(onto);
51 } catch(OWLOntologyCreationException | OWLOntologyStorageException | IOException e) { 51 } catch(OWLOntologyCreationException | OWLOntologyStorageException | IOException e) {
52 e.printStackTrace(); 52 e.printStackTrace();
@@ -55,7 +55,7 @@ class HermiTReasoner extends QueryReasoner {
55 DatalogProgram datalogProgram = new DatalogProgram(tbox, false); 55 DatalogProgram datalogProgram = new DatalogProgram(tbox, false);
56 importData(datalogProgram.getAdditionalDataFile()); 56 importData(datalogProgram.getAdditionalDataFile());
57 upperStore = new MultiStageQueryEngine("rl-upper", false); 57 upperStore = new MultiStageQueryEngine("rl-upper", false);
58 upperStore.importRDFData("data", importedData.toString()); 58 upperStore.importRDFData("data", getImportedData());
59 GapByStore4ID gap = new GapByStore4ID(upperStore); 59 GapByStore4ID gap = new GapByStore4ID(upperStore);
60 upperStore.materialiseFoldedly(datalogProgram, gap); 60 upperStore.materialiseFoldedly(datalogProgram, gap);
61 gap.clear(); 61 gap.clear();
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
index acdb8a3..b4e2f5a 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
@@ -29,20 +29,22 @@ import java.util.Collection;
29class MyQueryReasoner extends QueryReasoner { 29class MyQueryReasoner extends QueryReasoner {
30 30
31 OWLOntology ontology; 31 OWLOntology ontology;
32 OWLOntology elho_ontology;
32 DatalogProgram program; 33 DatalogProgram program;
33 34
34 BasicQueryEngine rlLowerStore = null; 35 BasicQueryEngine rlLowerStore = null;
35 BasicQueryEngine lazyUpperStore = null;
36 // MultiStageQueryEngine limitedSkolemUpperStore;
37 OWLOntology elho_ontology;
38 KarmaQueryEngine elLowerStore = null; 36 KarmaQueryEngine elLowerStore = null;
39 BasicQueryEngine trackingStore = null; 37 MultiStageQueryEngine lazyUpperStore = null;
38 MultiStageQueryEngine trackingStore = null;
40 TrackingRuleEncoder encoder; 39 TrackingRuleEncoder encoder;
40
41 private boolean equalityTag; 41 private boolean equalityTag;
42 private Timer t = new Timer(); 42 private Timer t = new Timer();
43
43 private Collection<String> predicatesWithGap = null; 44 private Collection<String> predicatesWithGap = null;
44 private SatisfiabilityStatus satisfiable; 45 private ConsistencyStatus isConsistent;
45 private ConsistencyManager consistency = new ConsistencyManager(this); 46 private ConsistencyManager consistency = new ConsistencyManager(this);
47 private boolean useSkolemisation = false; // now only debugging
46 48
47 public MyQueryReasoner() { 49 public MyQueryReasoner() {
48 setup(true); 50 setup(true);
@@ -92,11 +94,15 @@ class MyQueryReasoner extends QueryReasoner {
92 t.reset(); 94 t.reset();
93 Utility.logInfo("Preprocessing (and checking satisfiability)..."); 95 Utility.logInfo("Preprocessing (and checking satisfiability)...");
94 96
95 String name = "data", datafile = importedData.toString(); 97 String name = "data", datafile = getImportedData();
96 rlLowerStore.importRDFData(name, datafile); 98 rlLowerStore.importRDFData(name, datafile);
97 rlLowerStore.materialise("lower program", program.getLower().toString()); 99 rlLowerStore.materialise("lower program", program.getLower().toString());
98// program.getLower().save(); 100// program.getLower().save();
99 if(!consistency.checkRLLowerBound()) return false; 101 if(!consistency.checkRLLowerBound()) {
102 Utility.logDebug("time for satisfiability checking: " + t.duration());
103 isConsistent = ConsistencyStatus.INCONSISTENT;
104 return false;
105 }
100 Utility.logDebug("The number of sameAs assertions in RL lower store: " + rlLowerStore.getSameAsNumber()); 106 Utility.logDebug("The number of sameAs assertions in RL lower store: " + rlLowerStore.getSameAsNumber());
101 107
102 String originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology); 108 String originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology);
@@ -105,20 +111,28 @@ class MyQueryReasoner extends QueryReasoner {
105 elLowerStore.materialise("saturate named individuals", originalMarkProgram); 111 elLowerStore.materialise("saturate named individuals", originalMarkProgram);
106 elLowerStore.materialise("lower program", program.getLower().toString()); 112 elLowerStore.materialise("lower program", program.getLower().toString());
107 elLowerStore.initialiseKarma(); 113 elLowerStore.initialiseKarma();
108 if(!consistency.checkELLowerBound()) return false; 114 if(!consistency.checkELLowerBound()) {
115 Utility.logDebug("time for satisfiability checking: " + t.duration());
116 isConsistent = ConsistencyStatus.INCONSISTENT;
117 return false;
118 }
109 119
110 if(lazyUpperStore != null) { 120 if(lazyUpperStore != null) {
111 lazyUpperStore.importRDFData(name, datafile); 121 lazyUpperStore.importRDFData(name, datafile);
112 lazyUpperStore.materialise("saturate named individuals", originalMarkProgram); 122 lazyUpperStore.materialise("saturate named individuals", originalMarkProgram);
113 int tag = lazyUpperStore.materialiseRestrictedly(program, null); 123 int tag = lazyUpperStore.materialiseRestrictedly(program, null);
114 if(tag != 1) { 124 if(tag == -1) {
125 Utility.logDebug("time for satisfiability checking: " + t.duration());
126 isConsistent = ConsistencyStatus.INCONSISTENT;
127 return false;
128 }
129 else if(tag != 1) {
115 lazyUpperStore.dispose(); 130 lazyUpperStore.dispose();
116 lazyUpperStore = null; 131 lazyUpperStore = null;
117 } 132 }
118 if(tag == -1) return false;
119 } 133 }
120 if(consistency.checkUpper(lazyUpperStore)) { 134 if(consistency.checkUpper(lazyUpperStore)) {
121 satisfiable = SatisfiabilityStatus.SATISFIABLE; 135 isConsistent = ConsistencyStatus.CONSISTENT;
122 Utility.logDebug("time for satisfiability checking: " + t.duration()); 136 Utility.logDebug("time for satisfiability checking: " + t.duration());
123 } 137 }
124 138
@@ -140,13 +154,12 @@ class MyQueryReasoner extends QueryReasoner {
140// encoder = new TrackingRuleEncoderDisjVar2(program.getUpper(), trackingStore); 154// encoder = new TrackingRuleEncoderDisjVar2(program.getUpper(), trackingStore);
141// encoder = new TrackingRuleEncoderDisj2(program.getUpper(), trackingStore); 155// encoder = new TrackingRuleEncoderDisj2(program.getUpper(), trackingStore);
142 156
157 // TODO add consistency check by Skolem-upper-bound
158
143 if(!isConsistent()) 159 if(!isConsistent())
144 return false; 160 return false;
145 161
146 consistency.extractBottomFragment(); 162 consistency.extractBottomFragment();
147 consistency.dispose();
148
149 program.dispose();
150 163
151 return true; 164 return true;
152 } 165 }
@@ -154,11 +167,19 @@ class MyQueryReasoner extends QueryReasoner {
154 @Override 167 @Override
155 public boolean isConsistent() { 168 public boolean isConsistent() {
156 if(isDisposed()) throw new DisposedException(); 169 if(isDisposed()) throw new DisposedException();
157 if(satisfiable == SatisfiabilityStatus.UNCHECKED) { 170
158 satisfiable = consistency.check() ? SatisfiabilityStatus.SATISFIABLE : SatisfiabilityStatus.UNSATISFIABLE; 171 if(isConsistent == ConsistencyStatus.UNCHECKED) {
159 Utility.logInfo("time for satisfiability checking: " + t.duration()); 172 isConsistent = consistency.check() ? ConsistencyStatus.CONSISTENT : ConsistencyStatus.INCONSISTENT;
173 Utility.logDebug("time for satisfiability checking: " + t.duration());
174 }
175 if(isConsistent == ConsistencyStatus.CONSISTENT) {
176 Utility.logInfo("The ontology is consistent!");
177 return true;
178 }
179 else {
180 Utility.logInfo("The ontology is inconsistent!");
181 return false;
160 } 182 }
161 return satisfiable == SatisfiabilityStatus.SATISFIABLE;
162 } 183 }
163 184
164 @Override 185 @Override
@@ -169,9 +190,9 @@ class MyQueryReasoner extends QueryReasoner {
169 return; 190 return;
170 191
171 OWLOntology relevantOntologySubset = extractRelevantOntologySubset(queryRecord); 192 OWLOntology relevantOntologySubset = extractRelevantOntologySubset(queryRecord);
172// queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl"); 193 queryRecord.saveRelevantOntology("/home/alessandro/Desktop/fragment_query" + queryRecord.getQueryID() + ".owl");
173 194
174 if(querySkolemisedRelevantSubset(relevantOntologySubset, queryRecord)) 195 if(useSkolemisation && querySkolemisedRelevantSubset(relevantOntologySubset, queryRecord))
175 return; 196 return;
176 197
177 Timer t = new Timer(); 198 Timer t = new Timer();
@@ -207,12 +228,14 @@ class MyQueryReasoner extends QueryReasoner {
207 if(lazyUpperStore != null) lazyUpperStore.dispose(); 228 if(lazyUpperStore != null) lazyUpperStore.dispose();
208 if(elLowerStore != null) elLowerStore.dispose(); 229 if(elLowerStore != null) elLowerStore.dispose();
209 if(trackingStore != null) trackingStore.dispose(); 230 if(trackingStore != null) trackingStore.dispose();
210// if(limitedSkolemUpperStore != null) limitedSkolemUpperStore.dispose(); 231 if(consistency != null) consistency.dispose();
232 if(program != null) program.dispose();
211 } 233 }
212 234
213 private void setup(boolean considerEqualities) { 235 private void setup(boolean considerEqualities) {
214 if(isDisposed()) throw new DisposedException(); 236 if(isDisposed()) throw new DisposedException();
215 satisfiable = SatisfiabilityStatus.UNCHECKED; 237
238 isConsistent = ConsistencyStatus.UNCHECKED;
216 this.equalityTag = considerEqualities; 239 this.equalityTag = considerEqualities;
217 240
218 rlLowerStore = new BasicQueryEngine("rl-lower-bound"); 241 rlLowerStore = new BasicQueryEngine("rl-lower-bound");
@@ -239,7 +262,7 @@ class MyQueryReasoner extends QueryReasoner {
239 */ 262 */
240 private boolean queryUpperStore(BasicQueryEngine upperStore, QueryRecord queryRecord, 263 private boolean queryUpperStore(BasicQueryEngine upperStore, QueryRecord queryRecord,
241 Tuple<String> extendedQuery, Step step) { 264 Tuple<String> extendedQuery, Step step) {
242 265 t.reset();
243 if(queryRecord.hasNonAnsDistinguishedVariables()) 266 if(queryRecord.hasNonAnsDistinguishedVariables())
244 queryUpperBound(upperStore, queryRecord, extendedQuery.get(0), queryRecord.getAnswerVariables()); 267 queryUpperBound(upperStore, queryRecord, extendedQuery.get(0), queryRecord.getAnswerVariables());
245 else 268 else
@@ -254,6 +277,7 @@ class MyQueryReasoner extends QueryReasoner {
254 } 277 }
255 278
256 private boolean checkGapAnswers(BasicQueryEngine relevantStore, QueryRecord queryRecord) { 279 private boolean checkGapAnswers(BasicQueryEngine relevantStore, QueryRecord queryRecord) {
280 t.reset();
257 Tuple<String> extendedQueries = queryRecord.getExtendedQueryText(); 281 Tuple<String> extendedQueries = queryRecord.getExtendedQueryText();
258 if(queryRecord.hasNonAnsDistinguishedVariables()) 282 if(queryRecord.hasNonAnsDistinguishedVariables())
259 checkGapAnswers(relevantStore, queryRecord, extendedQueries.get(0), queryRecord.getAnswerVariables()); 283 checkGapAnswers(relevantStore, queryRecord, extendedQueries.get(0), queryRecord.getAnswerVariables());
@@ -296,8 +320,6 @@ class MyQueryReasoner extends QueryReasoner {
296 } 320 }
297 queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration()); 321 queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration());
298 322
299 t.reset();
300
301 Tuple<String> extendedQueryTexts = queryRecord.getExtendedQueryText(); 323 Tuple<String> extendedQueryTexts = queryRecord.getExtendedQueryText();
302 324
303 Utility.logDebug("Tracking store"); 325 Utility.logDebug("Tracking store");
@@ -343,8 +365,6 @@ class MyQueryReasoner extends QueryReasoner {
343 // just statistics 365 // just statistics
344 int numOfABoxAxioms = relevantOntologySubset.getABoxAxioms(true).size(); 366 int numOfABoxAxioms = relevantOntologySubset.getABoxAxioms(true).size();
345 int numOfTBoxAxioms = relevantOntologySubset.getAxiomCount() - numOfABoxAxioms; 367 int numOfTBoxAxioms = relevantOntologySubset.getAxiomCount() - numOfABoxAxioms;
346 int originalNumOfABoxAxioms = ontology.getABoxAxioms(true).size();
347 int originalNumOfTBoxAxioms = ontology.getAxiomCount() - originalNumOfABoxAxioms;
348 Utility.logInfo("Relevant ontology-subset has been extracted: |ABox|=" 368 Utility.logInfo("Relevant ontology-subset has been extracted: |ABox|="
349 + numOfABoxAxioms + ", |TBox|=" + numOfTBoxAxioms); 369 + numOfABoxAxioms + ", |TBox|=" + numOfTBoxAxioms);
350 370
@@ -365,6 +385,7 @@ class MyQueryReasoner extends QueryReasoner {
365 385
366 private boolean querySkolemisedRelevantSubset(OWLOntology relevantSubset, QueryRecord queryRecord) { 386 private boolean querySkolemisedRelevantSubset(OWLOntology relevantSubset, QueryRecord queryRecord) {
367 Utility.logInfo("Evaluating semi-Skolemised relevant upper store..."); 387 Utility.logInfo("Evaluating semi-Skolemised relevant upper store...");
388 t.reset();
368 389
369 DatalogProgram relevantProgram = new DatalogProgram(relevantSubset, false); // toClassify is false 390 DatalogProgram relevantProgram = new DatalogProgram(relevantSubset, false); // toClassify is false
370 391
@@ -373,16 +394,24 @@ class MyQueryReasoner extends QueryReasoner {
373 394
374 relevantStore.importDataFromABoxOf(relevantSubset); 395 relevantStore.importDataFromABoxOf(relevantSubset);
375 396
376 int materialisationResult = relevantStore.materialiseSkolemly(relevantProgram, null); 397 int queryDependentMaxTermDepth = 1; // TODO make it dynamic
377 if(materialisationResult != 1) 398 int materialisationTag = relevantStore.materialiseSkolemly(relevantProgram, null,
378 throw new RuntimeException("Skolemised materialisation error"); // TODO check consistency 399 queryDependentMaxTermDepth);
400 queryRecord.addProcessingTime(Step.L_SKOLEM_UPPER_BOUND, t.duration());
401 if(materialisationTag == -1) {
402 throw new Error("A consistent ontology has turned out to be " +
403 "inconsistent in the Skolemises-relevant-upper-store");
404 }
405 else if(materialisationTag != 1) {
406 Utility.logInfo("Semi-Skolemised relevant upper store cannot be employed");
407 return false;
408 }
379 409
380 boolean isFullyProcessed = checkGapAnswers(relevantStore, queryRecord); 410 boolean isFullyProcessed = checkGapAnswers(relevantStore, queryRecord);
381
382 Utility.logInfo("Semi-Skolemised relevant upper store has been evaluated"); 411 Utility.logInfo("Semi-Skolemised relevant upper store has been evaluated");
383 return isFullyProcessed; 412 return isFullyProcessed;
384 } 413 }
385 414
386 enum SatisfiabilityStatus {SATISFIABLE, UNSATISFIABLE, UNCHECKED} 415 private enum ConsistencyStatus {CONSISTENT, INCONSISTENT, UNCHECKED}
387 416
388} 417}
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
index 962a78f..eab6a1b 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
@@ -26,10 +26,10 @@ public abstract class QueryReasoner extends Disposable {
26 private static final boolean DEFAULT_MULTI_STAGES = true; 26 private static final boolean DEFAULT_MULTI_STAGES = true;
27 private static final boolean DEFAULT_EQUALITIES = true; 27 private static final boolean DEFAULT_EQUALITIES = true;
28 public boolean fullReasoner = this instanceof MyQueryReasoner; 28 public boolean fullReasoner = this instanceof MyQueryReasoner;
29 protected StringBuilder importedData = new StringBuilder();
30 // protected boolean forSemFacet = false; 29 // protected boolean forSemFacet = false;
31 PagodaProperties properties; 30 PagodaProperties properties;
32 BufferedWriter answerWriter = null; 31 BufferedWriter answerWriter = null;
32 private StringBuilder importedData = new StringBuilder();
33 private QueryManager m_queryManager = new QueryManager(); 33 private QueryManager m_queryManager = new QueryManager();
34 34
35 public static QueryReasoner getInstance(PagodaProperties p) { 35 public static QueryReasoner getInstance(PagodaProperties p) {
@@ -208,10 +208,6 @@ public abstract class QueryReasoner extends Disposable {
208 queryRecords.stream().forEach(record -> record.dispose()); 208 queryRecords.stream().forEach(record -> record.dispose());
209 } 209 }
210 210
211// public void evaluate(Collection<QueryRecord> queryRecords) {
212// evaluate(queryRecords);
213// }
214
215 @Override 211 @Override
216 public void dispose() { 212 public void dispose() {
217 super.dispose(); 213 super.dispose();
@@ -225,11 +221,19 @@ public abstract class QueryReasoner extends Disposable {
225// Utility.cleanup(); 221// Utility.cleanup();
226 } 222 }
227 223
224// public void evaluate(Collection<QueryRecord> queryRecords) {
225// evaluate(queryRecords);
226// }
227
228 public QueryManager getQueryManager() { 228 public QueryManager getQueryManager() {
229 if(isDisposed()) throw new DisposedException(); 229 if(isDisposed()) throw new DisposedException();
230 return m_queryManager; 230 return m_queryManager;
231 } 231 }
232 232
233 protected String getImportedData() {
234 return importedData.toString();
235 }
236
233 private void importDataDirectory(File file) { 237 private void importDataDirectory(File file) {
234 for(File child : file.listFiles()) 238 for(File child : file.listFiles())
235 if(child.isFile()) importDataFile(child); 239 if(child.isFile()) importDataFile(child);
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java
index 16e2627..3934498 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java
@@ -57,7 +57,7 @@ class RLQueryReasoner extends QueryReasoner {
57 @Override 57 @Override
58 public boolean preprocess() { 58 public boolean preprocess() {
59 if(isDisposed()) throw new DisposedException(); 59 if(isDisposed()) throw new DisposedException();
60 rlLowerStore.importRDFData("data", importedData.toString()); 60 rlLowerStore.importRDFData("data", getImportedData());
61 rlLowerStore.materialise("lower program", program.toString()); 61 rlLowerStore.materialise("lower program", program.toString());
62 62
63 return isConsistent(); 63 return isConsistent();
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java
index d0712e1..368fbb2 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java
@@ -97,7 +97,7 @@ class RLUQueryReasoner extends QueryReasoner {
97 @Override 97 @Override
98 public boolean preprocess() { 98 public boolean preprocess() {
99 if(isDisposed()) throw new DisposedException(); 99 if(isDisposed()) throw new DisposedException();
100 String datafile = importedData.toString(); 100 String datafile = getImportedData();
101 rlLowerStore.importRDFData("data", datafile); 101 rlLowerStore.importRDFData("data", datafile);
102 rlLowerStore.materialise("lower program", program.getLower().toString()); 102 rlLowerStore.materialise("lower program", program.getLower().toString());
103 103
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/full/Checker.java b/src/uk/ac/ox/cs/pagoda/reasoner/full/Checker.java
index 849b971..fd620a5 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/full/Checker.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/full/Checker.java
@@ -2,14 +2,14 @@ package uk.ac.ox.cs.pagoda.reasoner.full;
2 2
3import uk.ac.ox.cs.pagoda.query.AnswerTuple; 3import uk.ac.ox.cs.pagoda.query.AnswerTuple;
4import uk.ac.ox.cs.pagoda.query.AnswerTuples; 4import uk.ac.ox.cs.pagoda.query.AnswerTuples;
5import uk.ac.ox.cs.pagoda.util.disposable.Disposable;
5 6
6public interface Checker { 7public abstract class Checker extends Disposable {
7 8
8 public int check(AnswerTuples answers); 9 public abstract int check(AnswerTuples answers);
9
10 public boolean check(AnswerTuple answer);
11 10
12 public boolean isConsistent(); 11 public abstract boolean check(AnswerTuple answer);
12
13 public abstract boolean isConsistent();
13 14
14 public void dispose();
15} 15}
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java b/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java
index 5dcf0f8..35db0f2 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java
@@ -1,24 +1,10 @@
1package uk.ac.ox.cs.pagoda.reasoner.full; 1package uk.ac.ox.cs.pagoda.reasoner.full;
2 2
3import java.util.HashMap;
4import java.util.HashSet;
5import java.util.Map;
6import java.util.Set;
7
8import org.semanticweb.HermiT.Reasoner; 3import org.semanticweb.HermiT.Reasoner;
9import org.semanticweb.HermiT.model.DLClause; 4import org.semanticweb.HermiT.model.DLClause;
10import org.semanticweb.HermiT.model.Term; 5import org.semanticweb.HermiT.model.Term;
11import org.semanticweb.HermiT.model.Variable; 6import org.semanticweb.HermiT.model.Variable;
12import org.semanticweb.owlapi.model.IRI; 7import org.semanticweb.owlapi.model.*;
13import org.semanticweb.owlapi.model.OWLAxiom;
14import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
15import org.semanticweb.owlapi.model.OWLDataFactory;
16import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom;
17import org.semanticweb.owlapi.model.OWLIndividual;
18import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
19import org.semanticweb.owlapi.model.OWLOntology;
20import org.semanticweb.owlapi.model.OWLOntologyManager;
21
22import uk.ac.ox.cs.pagoda.endomorph.Clique; 8import uk.ac.ox.cs.pagoda.endomorph.Clique;
23import uk.ac.ox.cs.pagoda.endomorph.DependencyGraph; 9import uk.ac.ox.cs.pagoda.endomorph.DependencyGraph;
24import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; 10import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper;
@@ -30,216 +16,236 @@ import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper;
30import uk.ac.ox.cs.pagoda.util.Namespace; 16import uk.ac.ox.cs.pagoda.util.Namespace;
31import uk.ac.ox.cs.pagoda.util.Timer; 17import uk.ac.ox.cs.pagoda.util.Timer;
32import uk.ac.ox.cs.pagoda.util.Utility; 18import uk.ac.ox.cs.pagoda.util.Utility;
19import uk.ac.ox.cs.pagoda.util.disposable.DisposedException;
33 20
34public class HermitChecker implements Checker { 21import java.util.HashMap;
35 22import java.util.HashSet;
36 protected OWLDataFactory factory; 23import java.util.Map;
24import java.util.Set;
37 25
38 private String queryText; 26public class HermitChecker extends Checker {
39 private DLClause queryClause;
40 27
41 private Reasoner hermit; 28 protected OWLDataFactory factory;
42 protected String[][] answerVariable; 29 protected String[][] answerVariable;
43 protected OWLOntology ontology; 30 protected OWLOntology ontology;
44 protected QueryRecord record; 31 protected QueryRecord record;
45 protected QueryGraph qGraph = null; 32 protected QueryGraph qGraph = null;
46 boolean toCheck = true; 33 boolean toCheck = true;
47 34 AnswerTuple topAnswerTuple = null, botAnswerTuple = null;
35 private String queryText;
36 private DLClause queryClause;
37 private Reasoner hermit;
38 private int tag = 0;
39 private int counter = 0;
40 private DependencyGraph dGraph = null;
48 public HermitChecker(Checker checker) { 41 public HermitChecker(Checker checker) {
49 if (checker instanceof HermitChecker) { 42 if (checker instanceof HermitChecker) {
50 HermitChecker other = (HermitChecker) checker; 43 HermitChecker other = (HermitChecker) checker;
51 factory = other.factory; 44 factory = other.factory;
52 queryText = other.queryText; 45 queryText = other.queryText;
53 queryClause = other.queryClause; 46 queryClause = other.queryClause;
54 answerVariable = other.answerVariable; 47 answerVariable = other.answerVariable;
55 ontology = other.ontology; 48 ontology = other.ontology;
56// record = other.record; 49// record = other.record;
57 } 50 }
58 51
59 hermit = new Reasoner(ontology); 52 hermit = new Reasoner(ontology);
60 } 53 }
61 54
62 public HermitChecker(OWLOntology ontology, QueryRecord record, boolean toCheck) { 55 public HermitChecker(OWLOntology ontology, QueryRecord record, boolean toCheck) {
63 this.ontology = ontology; 56 this.ontology = ontology;
64 queryText = record.getQueryText(); 57 queryText = record.getQueryText();
65 answerVariable = record.getVariables(); 58 answerVariable = record.getVariables();
66 queryClause = record.getClause(); 59 queryClause = record.getClause();
67// this.record = record; 60// this.record = record;
68 this.toCheck = toCheck; 61 this.toCheck = toCheck;
69 } 62 }
70 63
71 public HermitChecker(OWLOntology ontology, String queryText) { 64 public HermitChecker(OWLOntology ontology, String queryText) {
72 this.ontology = ontology; 65 this.ontology = ontology;
73 this.queryText = queryText; 66 this.queryText = queryText;
74 answerVariable = queryText == null ? null : ConjunctiveQueryHelper.getAnswerVariables(queryText); 67 answerVariable = queryText == null ? null : ConjunctiveQueryHelper.getAnswerVariables(queryText);
75 queryClause = DLClauseHelper.getQuery(queryText, null); 68 queryClause = DLClauseHelper.getQuery(queryText, null);
76// this.record = null; 69// this.record = null;
70 }
71
72 @Override
73 public int check(AnswerTuples answers) {
74 if(isDisposed()) throw new DisposedException();
75
76 if(hermit == null) initialiseReasoner();
77 int answerCounter = 0, counter = 0;
78 for(; answers.isValid(); answers.moveNext()) {
79 ++counter;
80 if(check(answers.getTuple())) ++answerCounter;
81 }
82 answers.dispose();
83
84 Utility.logDebug("The number of individuals to be checked by HermiT: " + counter,
85 "The number of correct answers: " + answerCounter);
86 return answerCounter;
87 }
88
89 @Override
90 public boolean check(AnswerTuple answerTuple) {
91 if(isDisposed()) throw new DisposedException();
92
93 if(!toCheck) return false;
94
95 if(hermit == null) initialiseReasoner();
96 if(tag != 0) return tag == 1;
97 ++counter;
98 Timer t = new Timer();
99 Map<Variable, Term> sub = answerTuple.getAssignment(answerVariable[1]);
100 Set<OWLAxiom> toCheckAxioms = qGraph.getAssertions(sub);
101
102// for (OWLAxiom axiom: toCheckAxioms) System.out.println(axiom.toString());
103
104 if(hermit.isEntailed(toCheckAxioms)) {
105 Utility.logDebug("@TIME to check one tuple: " + t.duration());
106 return true;
107 }
108 Utility.logDebug("@TIME to check one tuple: " + t.duration());
109 return false;
77 } 110 }
78 111
79 private int tag = 0; 112 @Override
80 AnswerTuple topAnswerTuple = null, botAnswerTuple = null; 113 public boolean isConsistent() {
81 114 if(isDisposed()) throw new DisposedException();
115
116 if(hermit == null) initialiseReasoner();
117 return hermit.isConsistent();
118 }
119
120 public void dispose() {
121 super.dispose();
122
123 Utility.logInfo("Hermit was called " + counter + " times.");
124 if(hermit != null) hermit.dispose();
125 hermit = null;
126 }
127
128 public void setDependencyGraph(DependencyGraph dGraph) {
129 if(isDisposed()) throw new DisposedException();
130
131 this.dGraph = dGraph;
132 }
133
82 private void initialiseReasoner() { 134 private void initialiseReasoner() {
83 qGraph = new QueryGraph(queryClause.getBodyAtoms(), answerVariable[1], ontology); 135 qGraph = new QueryGraph(queryClause.getBodyAtoms(), answerVariable[1], ontology);
84 OWLOntologyManager manager = ontology.getOWLOntologyManager(); 136 OWLOntologyManager manager = ontology.getOWLOntologyManager();
85 factory = manager.getOWLDataFactory(); 137 factory = manager.getOWLDataFactory();
86 138
87 if (hermit != null) hermit.dispose(); 139 if(hermit != null) hermit.dispose();
88 140
89 if (dGraph != null && answerVariable[1].length == 1 && (dGraph.getExits().size() > 1 || dGraph.getEntrances().size() > 1)) { 141 if(dGraph != null && answerVariable[1].length == 1 && (dGraph.getExits().size() > 1 || dGraph.getEntrances()
90 Set<OWLAxiom> topAxioms = new HashSet<OWLAxiom>(); 142 .size() > 1)) {
91 Set<OWLAxiom> botAxioms = new HashSet<OWLAxiom>(); 143 Set<OWLAxiom> topAxioms = new HashSet<OWLAxiom>();
144 Set<OWLAxiom> botAxioms = new HashSet<OWLAxiom>();
92 addTopAndBotTuple(topAxioms, botAxioms); 145 addTopAndBotTuple(topAxioms, botAxioms);
93 manager.addAxioms(ontology, topAxioms); 146 manager.addAxioms(ontology, topAxioms);
94 manager.addAxioms(ontology, botAxioms); 147 manager.addAxioms(ontology, botAxioms);
95 hermit = new Reasoner(ontology); 148 hermit = new Reasoner(ontology);
96 boolean topValid = true; 149 boolean topValid = true;
97 if (!hermit.isConsistent() || topAnswerTuple != null && (topValid = check(topAnswerTuple))) { 150 if(!hermit.isConsistent() || topAnswerTuple != null && (topValid = check(topAnswerTuple))) {
98 hermit.dispose(); 151 hermit.dispose();
99 manager.removeAxioms(ontology, topAxioms); 152 manager.removeAxioms(ontology, topAxioms);
100 hermit = new Reasoner(ontology); 153 hermit = new Reasoner(ontology);
101 } else { 154 }
102 if (!topValid) tag = -1; 155 else {
103 else 156 if(!topValid) tag = -1;
104 if (botAnswerTuple != null && check(botAnswerTuple)) tag = 1; 157 else if(botAnswerTuple != null && check(botAnswerTuple)) tag = 1;
105 } 158 }
106 } 159 }
107 else 160 else
108 hermit = new Reasoner(ontology); 161 hermit = new Reasoner(ontology);
109 } 162 }
110 163
111 private void addTopAndBotTuple(Set<OWLAxiom> topAxioms, Set<OWLAxiom> botAxioms) { 164 private void addTopAndBotTuple(Set<OWLAxiom> topAxioms, Set<OWLAxiom> botAxioms) {
112 String top_str = Namespace.PAGODA_ANONY + "top", bot_str = Namespace.PAGODA_ANONY + "bot"; 165 String top_str = Namespace.PAGODA_ANONY + "top", bot_str = Namespace.PAGODA_ANONY + "bot";
113 topAnswerTuple = new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[] { uk.ac.ox.cs.JRDFox.model.Individual.create(top_str) } ); 166 topAnswerTuple =
114 botAnswerTuple = new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[] { uk.ac.ox.cs.JRDFox.model.Individual.create(bot_str) } ); 167 new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[]{uk.ac.ox.cs.JRDFox.model.Individual.create(top_str)});
115 OWLIndividual top_ind = factory.getOWLNamedIndividual(IRI.create(top_str)), bot_ind = factory.getOWLNamedIndividual(IRI.create(bot_str)); 168 botAnswerTuple =
116 Map<OWLAxiom, Integer> counter = new HashMap<OWLAxiom, Integer>(); 169 new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[]{uk.ac.ox.cs.JRDFox.model.Individual.create(bot_str)});
117 170 OWLIndividual top_ind = factory.getOWLNamedIndividual(IRI.create(top_str)), bot_ind =
171 factory.getOWLNamedIndividual(IRI.create(bot_str));
172 Map<OWLAxiom, Integer> counter = new HashMap<OWLAxiom, Integer>();
173
118 Set<String> topAnswers = new HashSet<String>(), botAnswers = new HashSet<String>(); 174 Set<String> topAnswers = new HashSet<String>(), botAnswers = new HashSet<String>();
119 OWLIndividual sub, obj; 175 OWLIndividual sub, obj;
120 if (dGraph.getExits().size() > 1) { 176 if(dGraph.getExits().size() > 1) {
121 for (Clique answerClique: dGraph.getExits()) 177 for(Clique answerClique : dGraph.getExits())
122 topAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative().getAnswerTuple().getGroundTerm(0)).getIRI()); 178 topAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative()
179 .getAnswerTuple()
180 .getGroundTerm(0)).getIRI());
123 } 181 }
124 else topAnswerTuple = null; 182 else topAnswerTuple = null;
125 183
126 if (dGraph.getEntrances().size() > 1) { 184 if(dGraph.getEntrances().size() > 1) {
127 for (Clique answerClique: dGraph.getEntrances()) 185 for(Clique answerClique : dGraph.getEntrances())
128 botAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative().getAnswerTuple().getGroundTerm(0)).getIRI()); 186 botAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative()
187 .getAnswerTuple()
188 .getGroundTerm(0)).getIRI());
129 } 189 }
130 else botAnswerTuple = null; 190 else botAnswerTuple = null;
131 191
132 for (OWLAxiom axiom: ontology.getABoxAxioms(true)) 192 for(OWLAxiom axiom : ontology.getABoxAxioms(true))
133 if (axiom instanceof OWLClassAssertionAxiom) { 193 if(axiom instanceof OWLClassAssertionAxiom) {
134 OWLClassAssertionAxiom ca = (OWLClassAssertionAxiom) axiom; 194 OWLClassAssertionAxiom ca = (OWLClassAssertionAxiom) axiom;
135 sub = ca.getIndividual(); 195 sub = ca.getIndividual();
136 if (topAnswers.contains(sub.toStringID())) 196 if(topAnswers.contains(sub.toStringID()))
137 topAxioms.add(factory.getOWLClassAssertionAxiom(ca.getClassExpression(), top_ind)); 197 topAxioms.add(factory.getOWLClassAssertionAxiom(ca.getClassExpression(), top_ind));
138 if (botAnswers.contains(sub.toStringID())) 198 if(botAnswers.contains(sub.toStringID()))
139 inc(counter, factory.getOWLClassAssertionAxiom(ca.getClassExpression(), bot_ind)); 199 inc(counter, factory.getOWLClassAssertionAxiom(ca.getClassExpression(), bot_ind));
140 } 200 }
141 else if (axiom instanceof OWLObjectPropertyAssertionAxiom) { 201 else if(axiom instanceof OWLObjectPropertyAssertionAxiom) {
142 OWLObjectPropertyAssertionAxiom oa = (OWLObjectPropertyAssertionAxiom) axiom; 202 OWLObjectPropertyAssertionAxiom oa = (OWLObjectPropertyAssertionAxiom) axiom;
143 sub = oa.getSubject(); obj = oa.getObject(); 203 sub = oa.getSubject();
144 if (topAnswers.contains(sub.toStringID())) 204 obj = oa.getObject();
145 if (topAnswers.contains(obj.toStringID())) 205 if(topAnswers.contains(sub.toStringID()))
206 if(topAnswers.contains(obj.toStringID()))
146 topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, top_ind)); 207 topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, top_ind));
147 else 208 else
148 topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, obj)); 209 topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, obj));
149 else { 210 else {
150 if (topAnswers.contains(obj.toStringID())) 211 if(topAnswers.contains(obj.toStringID()))
151 topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, top_ind)); 212 topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, top_ind));
152 } 213 }
153 214
154 if (botAnswers.contains(sub.toStringID())) 215 if(botAnswers.contains(sub.toStringID()))
155 if (botAnswers.contains(obj.toStringID())) 216 if(botAnswers.contains(obj.toStringID()))
156 inc(counter, factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), bot_ind, bot_ind)); 217 inc(counter, factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), bot_ind, bot_ind));
157 else 218 else
158 inc(counter, factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), bot_ind, obj)); 219 inc(counter, factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), bot_ind, obj));
159 else { 220 else {
160 if (botAnswers.contains(obj.toStringID())) 221 if(botAnswers.contains(obj.toStringID()))
161 inc(counter, factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, bot_ind)); 222 inc(counter, factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, bot_ind));
162 } 223 }
163 224
164 } 225 }
165 else if (axiom instanceof OWLDataPropertyAssertionAxiom) { 226 else if(axiom instanceof OWLDataPropertyAssertionAxiom) {
166 OWLDataPropertyAssertionAxiom da = (OWLDataPropertyAssertionAxiom) axiom; 227 OWLDataPropertyAssertionAxiom da = (OWLDataPropertyAssertionAxiom) axiom;
167 sub = da.getSubject(); 228 sub = da.getSubject();
168 if (topAnswers.contains(sub.toStringID())) 229 if(topAnswers.contains(sub.toStringID()))
169 topAxioms.add(factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), top_ind, da.getObject())); 230 topAxioms.add(factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), top_ind, da.getObject()));
170 231
171 if (botAnswers.contains(sub.toStringID())) 232 if(botAnswers.contains(sub.toStringID()))
172 inc(counter, factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), bot_ind, da.getObject())); 233 inc(counter, factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), bot_ind, da.getObject()));
173 } 234 }
174 235
175 int number = botAnswers.size(); 236 int number = botAnswers.size();
176 for (Map.Entry<OWLAxiom, Integer> entry: counter.entrySet()) { 237 for(Map.Entry<OWLAxiom, Integer> entry : counter.entrySet()) {
177 if (entry.getValue() == number) 238 if(entry.getValue() == number)
178 botAxioms.add(entry.getKey()); 239 botAxioms.add(entry.getKey());
179 } 240 }
180 } 241 }
181 242
182 private void inc(Map<OWLAxiom, Integer> counter, OWLAxiom newAxiom) { 243 private void inc(Map<OWLAxiom, Integer> counter, OWLAxiom newAxiom) {
183 Integer number = counter.get(newAxiom); 244 if(isDisposed()) throw new DisposedException();
184 if (number == null) counter.put(newAxiom, 1);
185 else counter.put(newAxiom, number + 1);
186 }
187 245
188 @Override 246 Integer number = counter.get(newAxiom);
189 public int check(AnswerTuples answers) { 247 if(number == null) counter.put(newAxiom, 1);
190 if (hermit == null) initialiseReasoner(); 248 else counter.put(newAxiom, number + 1);
191 int answerCounter = 0, counter = 0;
192 for (; answers.isValid(); answers.moveNext()) {
193 ++counter;
194 if (check(answers.getTuple())) ++answerCounter;
195 }
196 answers.dispose();
197
198 Utility.logDebug("The number of individuals to be checked by HermiT: " + counter,
199 "The number of correct answers: " + answerCounter);
200 return answerCounter;
201 }
202
203 private int counter = 0;
204
205 @Override
206 public boolean check(AnswerTuple answerTuple) {
207 if (!toCheck) return false;
208
209 if (hermit == null) initialiseReasoner();
210 if (tag != 0) return tag == 1;
211 ++counter;
212 Timer t = new Timer();
213 Map<Variable, Term> sub = answerTuple.getAssignment(answerVariable[1]);
214 Set<OWLAxiom> toCheckAxioms = qGraph.getAssertions(sub);
215
216// for (OWLAxiom axiom: toCheckAxioms) System.out.println(axiom.toString());
217
218 if (hermit.isEntailed(toCheckAxioms)) {
219 Utility.logDebug("@TIME to check one tuple: " + t.duration());
220 return true;
221 }
222 Utility.logDebug("@TIME to check one tuple: " + t.duration());
223 return false;
224 }
225
226 @Override
227 public boolean isConsistent() {
228 if (hermit == null) initialiseReasoner();
229 return hermit.isConsistent();
230 }
231
232
233 public void dispose() {
234 Utility.logInfo("Hermit was called " + counter + " times.");
235 if (hermit != null) hermit.dispose();
236 hermit = null;
237 }
238
239 private DependencyGraph dGraph = null;
240
241 public void setDependencyGraph(DependencyGraph dGraph) {
242 this.dGraph = dGraph;
243 } 249 }
244 250
245} 251}
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java b/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java
index fe43e09..107d3ca 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java
@@ -104,16 +104,22 @@ public class BasicQueryEngine extends RDFoxQueryEngine {
104 } 104 }
105 105
106 public void outputInstance4BinaryPredicate(String iri, String filename) { 106 public void outputInstance4BinaryPredicate(String iri, String filename) {
107 if(isDisposed()) throw new DisposedException();
108
107 Utility.redirectCurrentOut(filename); 109 Utility.redirectCurrentOut(filename);
108 outputInstance4BinaryPredicate(iri); 110 outputInstance4BinaryPredicate(iri);
109 Utility.closeCurrentOut(); 111 Utility.closeCurrentOut();
110 } 112 }
111 113
112 public void outputInstance4BinaryPredicate(String iri) { 114 public void outputInstance4BinaryPredicate(String iri) {
115 if(isDisposed()) throw new DisposedException();
116
113 outputAnswers("select ?x ?y where { ?x <" + iri + "> ?y . }"); 117 outputAnswers("select ?x ?y where { ?x <" + iri + "> ?y . }");
114 } 118 }
115 119
116 public void outputInstanceNumbers(String filename) { 120 public void outputInstanceNumbers(String filename) {
121 if(isDisposed()) throw new DisposedException();
122
117 TupleIterator predicateTuples = null; 123 TupleIterator predicateTuples = null;
118 TupleIterator instanceTuples; 124 TupleIterator instanceTuples;
119 Set<String> number = new HashSet<String>(); 125 Set<String> number = new HashSet<String>();
@@ -177,6 +183,8 @@ public class BasicQueryEngine extends RDFoxQueryEngine {
177 } 183 }
178 184
179 public TupleIterator internal_evaluateAgainstIDBs(String queryText) throws JRDFStoreException { 185 public TupleIterator internal_evaluateAgainstIDBs(String queryText) throws JRDFStoreException {
186 if(isDisposed()) throw new DisposedException();
187
180 TupleIterator iter = 188 TupleIterator iter =
181 store.compileQuery(queryText, prefixes, parameters, TripleStatus.TUPLE_STATUS_IDB.union(TripleStatus.TUPLE_STATUS_EDB), TripleStatus.TUPLE_STATUS_IDB); 189 store.compileQuery(queryText, prefixes, parameters, TripleStatus.TUPLE_STATUS_IDB.union(TripleStatus.TUPLE_STATUS_EDB), TripleStatus.TUPLE_STATUS_IDB);
182// iter.open(); 190// iter.open();
@@ -184,16 +192,22 @@ public class BasicQueryEngine extends RDFoxQueryEngine {
184 } 192 }
185 193
186 public TupleIterator internal_evaluate(String queryText) throws JRDFStoreException { 194 public TupleIterator internal_evaluate(String queryText) throws JRDFStoreException {
195 if(isDisposed()) throw new DisposedException();
196
187 TupleIterator iter = store.compileQuery(queryText, prefixes, parameters); 197 TupleIterator iter = store.compileQuery(queryText, prefixes, parameters);
188// iter.open(); 198// iter.open();
189 return iter; 199 return iter;
190 } 200 }
191 201
192 public void setExpandEquality(boolean flag) { 202 public void setExpandEquality(boolean flag) {
203 if(isDisposed()) throw new DisposedException();
204
193 parameters.m_expandEquality = flag; 205 parameters.m_expandEquality = flag;
194 } 206 }
195 207
196 public TupleIterator internal_evaluateNotExpanded(String queryText) throws JRDFStoreException { 208 public TupleIterator internal_evaluateNotExpanded(String queryText) throws JRDFStoreException {
209 if(isDisposed()) throw new DisposedException();
210
197 parameters.m_expandEquality = false; 211 parameters.m_expandEquality = false;
198 TupleIterator iter = store.compileQuery(queryText, prefixes, parameters); 212 TupleIterator iter = store.compileQuery(queryText, prefixes, parameters);
199// iter.open(); 213// iter.open();
@@ -202,10 +216,14 @@ public class BasicQueryEngine extends RDFoxQueryEngine {
202 } 216 }
203 217
204 public TupleIterator internal_evaluate(String queryText, boolean incrementally) throws JRDFStoreException { 218 public TupleIterator internal_evaluate(String queryText, boolean incrementally) throws JRDFStoreException {
219 if(isDisposed()) throw new DisposedException();
220
205 return incrementally ? internal_evaluateAgainstIDBs(queryText) : internal_evaluate(queryText); 221 return incrementally ? internal_evaluateAgainstIDBs(queryText) : internal_evaluate(queryText);
206 } 222 }
207 223
208 public String getUnusedRules(Collection<DLClause> clauses, boolean toUpdate) { 224 public String getUnusedRules(Collection<DLClause> clauses, boolean toUpdate) {
225 if(isDisposed()) throw new DisposedException();
226
209 DLClause clause; 227 DLClause clause;
210 for(Iterator<DLClause> iter = clauses.iterator(); iter.hasNext(); ) { 228 for(Iterator<DLClause> iter = clauses.iterator(); iter.hasNext(); ) {
211 if(materialisedRules.contains(clause = iter.next())) 229 if(materialisedRules.contains(clause = iter.next()))
@@ -219,10 +237,14 @@ public class BasicQueryEngine extends RDFoxQueryEngine {
219 } 237 }
220 238
221 public void outputMaterialisedRules() { 239 public void outputMaterialisedRules() {
240 if(isDisposed()) throw new DisposedException();
241
222 System.out.println(DLClauseHelper.toString(materialisedRules)); 242 System.out.println(DLClauseHelper.toString(materialisedRules));
223 } 243 }
224 244
225 public void outputAnswers(String query) { 245 public void outputAnswers(String query) {
246 if(isDisposed()) throw new DisposedException();
247
226 TupleIterator iter = null; 248 TupleIterator iter = null;
227 try { 249 try {
228 iter = internal_evaluate(query); 250 iter = internal_evaluate(query);
@@ -241,6 +263,8 @@ public class BasicQueryEngine extends RDFoxQueryEngine {
241 } 263 }
242 264
243 public void outputInstance4UnaryPredicate(String iri) { 265 public void outputInstance4UnaryPredicate(String iri) {
266 if(isDisposed()) throw new DisposedException();
267
244 outputAnswers("select ?x where { ?x " 268 outputAnswers("select ?x where { ?x "
245 + "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" 269 + "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <"
246 + iri 270 + iri
@@ -248,14 +272,20 @@ public class BasicQueryEngine extends RDFoxQueryEngine {
248 } 272 }
249 273
250 public void outputSubjects(String p, String o) { 274 public void outputSubjects(String p, String o) {
275 if(isDisposed()) throw new DisposedException();
276
251 outputAnswers("select x where { ?x <" + p + "> <" + o + "> . }"); 277 outputAnswers("select x where { ?x <" + p + "> <" + o + "> . }");
252 } 278 }
253 279
254 public void outputObjects(String s, String p) { 280 public void outputObjects(String s, String p) {
281 if(isDisposed()) throw new DisposedException();
282
255 outputAnswers("select ?x where { <" + s + "> <" + p + "> ?x . }"); 283 outputAnswers("select ?x where { <" + s + "> <" + p + "> ?x . }");
256 } 284 }
257 285
258 public void outputIDBFacts() { 286 public void outputIDBFacts() {
287 if(isDisposed()) throw new DisposedException();
288
259 TupleIterator iter = null; 289 TupleIterator iter = null;
260 try { 290 try {
261 iter = internal_evaluateAgainstIDBs("select distict ?x ?y ?z where { ?x ?y ?z }"); 291 iter = internal_evaluateAgainstIDBs("select distict ?x ?y ?z where { ?x ?y ?z }");
@@ -274,10 +304,14 @@ public class BasicQueryEngine extends RDFoxQueryEngine {
274 } 304 }
275 305
276 public void outputType4Individual(String iri) { 306 public void outputType4Individual(String iri) {
307 if(isDisposed()) throw new DisposedException();
308
277 outputAnswers("select ?z where { <" + iri + "> " + Namespace.RDF_TYPE_QUOTED + " ?z }"); 309 outputAnswers("select ?z where { <" + iri + "> " + Namespace.RDF_TYPE_QUOTED + " ?z }");
278 } 310 }
279 311
280 public int getSameAsNumber() { 312 public int getSameAsNumber() {
313 if(isDisposed()) throw new DisposedException();
314
281 TupleIterator iter = null; 315 TupleIterator iter = null;
282 int counter = 0; 316 int counter = 0;
283 try { 317 try {
@@ -294,6 +328,8 @@ public class BasicQueryEngine extends RDFoxQueryEngine {
294 } 328 }
295 329
296 public UFS<String> getEqualityGroups(boolean reuse) { 330 public UFS<String> getEqualityGroups(boolean reuse) {
331 if(isDisposed()) throw new DisposedException();
332
297 if(reuse && equalityGroups != null) return equalityGroups; 333 if(reuse && equalityGroups != null) return equalityGroups;
298 334
299 equalityGroups = new UFS<String>(); 335 equalityGroups = new UFS<String>();
@@ -317,6 +353,8 @@ public class BasicQueryEngine extends RDFoxQueryEngine {
317 } 353 }
318 354
319 public void clearRulesAndIDBFacts(Collection<int[]> collection) { 355 public void clearRulesAndIDBFacts(Collection<int[]> collection) {
356 if(isDisposed()) throw new DisposedException();
357
320// performDeletion(collection); 358// performDeletion(collection);
321 collection.clear(); 359 collection.clear();
322 try { 360 try {