aboutsummaryrefslogtreecommitdiff
path: root/src/uk/ac/ox/cs/pagoda/reasoner
diff options
context:
space:
mode:
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/reasoner')
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java68
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager2.java6
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java44
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java13
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java26
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java22
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxTripleManager.java54
7 files changed, 122 insertions, 111 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java
index b7a3667..409a2c9 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java
@@ -15,6 +15,7 @@ import uk.ac.ox.cs.pagoda.query.AnswerTuples;
15import uk.ac.ox.cs.pagoda.query.QueryManager; 15import uk.ac.ox.cs.pagoda.query.QueryManager;
16import uk.ac.ox.cs.pagoda.query.QueryRecord; 16import uk.ac.ox.cs.pagoda.query.QueryRecord;
17import uk.ac.ox.cs.pagoda.reasoner.full.Checker; 17import uk.ac.ox.cs.pagoda.reasoner.full.Checker;
18import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine;
18import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram; 19import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram;
19import uk.ac.ox.cs.pagoda.summary.HermitSummaryFilter; 20import uk.ac.ox.cs.pagoda.summary.HermitSummaryFilter;
20import uk.ac.ox.cs.pagoda.tracking.QueryTracker; 21import uk.ac.ox.cs.pagoda.tracking.QueryTracker;
@@ -54,7 +55,7 @@ public class ConsistencyManager {
54 55
55 if (fullQueryRecord.getNoOfSoundAnswers() > 0) { 56 if (fullQueryRecord.getNoOfSoundAnswers() > 0) {
56 Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple()); 57 Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple());
57 return unsatisfiability(t.duration()); 58 return false;
58 } 59 }
59 return true; 60 return true;
60 } 61 }
@@ -63,39 +64,20 @@ public class ConsistencyManager {
63 fullQueryRecord.updateLowerBoundAnswers(m_reasoner.elLowerStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables())); 64 fullQueryRecord.updateLowerBoundAnswers(m_reasoner.elLowerStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()));
64 if (fullQueryRecord.getNoOfSoundAnswers() > 0) { 65 if (fullQueryRecord.getNoOfSoundAnswers() > 0) {
65 Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple()); 66 Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple());
66 return unsatisfiability(t.duration()); 67 return true;
67 } 68 }
68 return true; 69 return true;
69 } 70 }
70
71 boolean checkLazyUpper() {
72 if (m_reasoner.lazyUpperStore != null) {
73 AnswerTuples tuples = null;
74 try {
75 tuples = m_reasoner.lazyUpperStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables());
76
77 Utility.logDebug("CheckLazyUpperBound: answerVars=" + fullQueryRecord.getAnswerVariables());
78
79 if (!tuples.isValid()) {
80 Utility.logInfo("There are no contradictions derived in the lazy upper bound materialisation.");
81 return satisfiability(t.duration());
82 }
83 }
84 finally {
85 if (tuples != null) tuples.dispose();
86 }
87 }
88 return false;
89 }
90 71
91 boolean checkSkolemUpper() { 72 boolean checkUpper(BasicQueryEngine upperStore) {
92 if (m_reasoner.limitedSkolemUpperStore != null) { 73 if (upperStore != null) {
93 AnswerTuples tuples = null; 74 AnswerTuples tuples = null;
94 try { 75 try {
95 tuples = m_reasoner.limitedSkolemUpperStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); 76 tuples = upperStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables());
96 if (!tuples.isValid()) { 77 if (!tuples.isValid()) {
97 Utility.logInfo("There are no contradictions derived in the limited-skolem upper bound materialisation."); 78 Utility.logInfo("There are no contradictions derived in "+ upperStore.getName() +" materialisation.");
98 return satisfiability(t.duration()); 79 Utility.logDebug("The ontology and dataset is satisfiable.");
80 return true;
99 } 81 }
100 } 82 }
101 finally { 83 finally {
@@ -104,7 +86,11 @@ public class ConsistencyManager {
104 } 86 }
105 return false; 87 return false;
106 } 88 }
107 89
90 void dispose() {
91 fullQueryRecord.dispose();
92 }
93
108 boolean check() { 94 boolean check() {
109// if (!checkRLLowerBound()) return false; 95// if (!checkRLLowerBound()) return false;
110// if (!checkELLowerBound()) return false; 96// if (!checkELLowerBound()) return false;
@@ -119,7 +105,7 @@ public class ConsistencyManager {
119 } 105 }
120 106
121 if (fullQueryRecord.getNoOfCompleteAnswers() == 0) 107 if (fullQueryRecord.getNoOfCompleteAnswers() == 0)
122 return satisfiability(t.duration()); 108 return true;
123 109
124 extractBottomFragment(); 110 extractBottomFragment();
125 111
@@ -139,7 +125,7 @@ public class ConsistencyManager {
139 checker = new HermitSummaryFilter(r, true); // m_reasoner.factory.getSummarisedReasoner(r); 125 checker = new HermitSummaryFilter(r, true); // m_reasoner.factory.getSummarisedReasoner(r);
140 satisfiability = checker.isConsistent(); 126 satisfiability = checker.isConsistent();
141 checker.dispose(); 127 checker.dispose();
142 if (!satisfiability) return unsatisfiability(t.duration()); 128 if (!satisfiability) return false;
143 } 129 }
144 130
145// Checker checker = m_reasoner.factory.getSummarisedReasoner(fullQueryRecord); 131// Checker checker = m_reasoner.factory.getSummarisedReasoner(fullQueryRecord);
@@ -147,20 +133,20 @@ public class ConsistencyManager {
147// checker.dispose(); 133// checker.dispose();
148// if (!satisfiable) return unsatisfiability(t.duration()); 134// if (!satisfiable) return unsatisfiability(t.duration());
149 135
150 return satisfiability(t.duration()); 136 return true;
151 } 137 }
152 138
153 protected boolean unsatisfiability(double duration) { 139// protected boolean unsatisfiability(double duration) {
154 fullQueryRecord.dispose(); 140// fullQueryRecord.dispose();
155 Utility.logDebug("The ontology and dataset is unsatisfiable."); 141// Utility.logDebug("The ontology and dataset is unsatisfiable.");
156 return false; 142// return false;
157 } 143// }
158 144
159 protected boolean satisfiability(double duration) { 145// protected boolean satisfiability(double duration) {
160 fullQueryRecord.dispose(); 146// fullQueryRecord.dispose();
161 Utility.logDebug("The ontology and dataset is satisfiable."); 147// Utility.logDebug("The ontology and dataset is satisfiable.");
162 return true; 148// return true;
163 } 149// }
164 150
165 boolean fragmentExtracted = false; 151 boolean fragmentExtracted = false;
166 152
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager2.java b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager2.java
index 9c335f3..9191067 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager2.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager2.java
@@ -2,7 +2,6 @@ package uk.ac.ox.cs.pagoda.reasoner;
2 2
3import org.semanticweb.owlapi.model.OWLOntologyCreationException; 3import org.semanticweb.owlapi.model.OWLOntologyCreationException;
4import org.semanticweb.owlapi.model.OWLOntologyManager; 4import org.semanticweb.owlapi.model.OWLOntologyManager;
5
6import uk.ac.ox.cs.pagoda.query.AnswerTuples; 5import uk.ac.ox.cs.pagoda.query.AnswerTuples;
7import uk.ac.ox.cs.pagoda.query.QueryRecord; 6import uk.ac.ox.cs.pagoda.query.QueryRecord;
8import uk.ac.ox.cs.pagoda.reasoner.full.Checker; 7import uk.ac.ox.cs.pagoda.reasoner.full.Checker;
@@ -31,8 +30,9 @@ public class ConsistencyManager2 extends ConsistencyManager {
31 @Override 30 @Override
32 boolean check() { 31 boolean check() {
33// if (!checkRLLowerBound()) return false; 32// if (!checkRLLowerBound()) return false;
34// if (!checkELLowerBound()) return false; 33// if (!checkELLowerBound()) return false;
35 if (checkLazyUpper()) return true; 34 // TODO test
35 if (checkUpper(m_reasoner.lazyUpperStore) && checkUpper(m_reasoner.limitedSkolemUpperStore)) return true;
36 AnswerTuples iter = null; 36 AnswerTuples iter = null;
37 37
38 try { 38 try {
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
index 36ea7de..1f435b7 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
@@ -50,6 +50,7 @@ public class MyQueryReasoner extends QueryReasoner {
50 private Collection<String> predicatesWithGap = null; 50 private Collection<String> predicatesWithGap = null;
51 private Boolean satisfiable; 51 private Boolean satisfiable;
52 private ConsistencyManager consistency = new ConsistencyManager(this); 52 private ConsistencyManager consistency = new ConsistencyManager(this);
53 private boolean useUpperStores = false;
53 54
54 public MyQueryReasoner() { 55 public MyQueryReasoner() {
55 setup(true, true); 56 setup(true, true);
@@ -101,9 +102,9 @@ public class MyQueryReasoner extends QueryReasoner {
101// program.getUpper().save(); 102// program.getUpper().save();
102// program.getGeneral().save(); 103// program.getGeneral().save();
103 104
104 if (multiStageTag && !program.getGeneral().isHorn()) { 105 useUpperStores = multiStageTag && !program.getGeneral().isHorn();
106 if (useUpperStores) {
105 lazyUpperStore = getUpperStore("lazy-upper-bound", true); // new MultiStageQueryEngine("lazy-upper-bound", true); // 107 lazyUpperStore = getUpperStore("lazy-upper-bound", true); // new MultiStageQueryEngine("lazy-upper-bound", true); //
106 // TODO CHECK
107 limitedSkolemUpperStore = getUpperStore("limited-skolem-upper-bound", true); 108 limitedSkolemUpperStore = getUpperStore("limited-skolem-upper-bound", true);
108 } 109 }
109 110
@@ -120,7 +121,7 @@ public class MyQueryReasoner extends QueryReasoner {
120 @Override 121 @Override
121 public boolean preprocess() { 122 public boolean preprocess() {
122 t.reset(); 123 t.reset();
123 Utility.logInfo("Preprocessing ... checking satisfiability ... "); 124 Utility.logInfo("Preprocessing... checking satisfiability... ");
124 125
125 String name = "data", datafile = importedData.toString(); 126 String name = "data", datafile = importedData.toString();
126 rlLowerStore.importRDFData(name, datafile); 127 rlLowerStore.importRDFData(name, datafile);
@@ -147,12 +148,11 @@ public class MyQueryReasoner extends QueryReasoner {
147 } 148 }
148 if (tag == -1) return false; 149 if (tag == -1) return false;
149 } 150 }
150 if (consistency.checkLazyUpper()) { 151 if (consistency.checkUpper(lazyUpperStore)) {
151 satisfiable = true; 152 satisfiable = true;
152 Utility.logInfo("time for satisfiability checking: " + t.duration()); 153 Utility.logInfo("time for satisfiability checking: " + t.duration());
153 } 154 }
154 155
155 // TODO check
156 if (limitedSkolemUpperStore != null) { 156 if (limitedSkolemUpperStore != null) {
157 limitedSkolemUpperStore.importRDFData(name, datafile); 157 limitedSkolemUpperStore.importRDFData(name, datafile);
158 limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram); 158 limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram);
@@ -163,16 +163,14 @@ public class MyQueryReasoner extends QueryReasoner {
163 } 163 }
164 if (tag == -1) return false; 164 if (tag == -1) return false;
165 } 165 }
166 // FIXME nullPointerException 166 if (consistency.checkUpper(limitedSkolemUpperStore)) {
167// if (consistency.checkSkolemUpper()) { 167 satisfiable = true;
168// satisfiable = true; 168 Utility.logInfo("time for satisfiability checking: " + t.duration());
169// Utility.logInfo("time for satisfiability checking: " + t.duration()); 169 }
170// }
171 170
172 trackingStore.importRDFData(name, datafile); 171 trackingStore.importRDFData(name, datafile);
173 trackingStore.materialise("saturate named individuals", originalMarkProgram); 172 trackingStore.materialise("saturate named individuals", originalMarkProgram);
174 173
175// materialiseFullUpper();
176 GapByStore4ID gap = new GapByStore4ID(trackingStore); 174 GapByStore4ID gap = new GapByStore4ID(trackingStore);
177 trackingStore.materialiseFoldedly(program, gap); 175 trackingStore.materialiseFoldedly(program, gap);
178 predicatesWithGap = gap.getPredicatesWithGap(); 176 predicatesWithGap = gap.getPredicatesWithGap();
@@ -192,6 +190,7 @@ public class MyQueryReasoner extends QueryReasoner {
192 return false; 190 return false;
193 191
194 consistency.extractBottomFragment(); 192 consistency.extractBottomFragment();
193 consistency.dispose();
195 return true; 194 return true;
196 } 195 }
197 196
@@ -204,6 +203,9 @@ public class MyQueryReasoner extends QueryReasoner {
204 return satisfiable; 203 return satisfiable;
205 } 204 }
206 205
206 /**
207 * Returns the relevant part of the ontology, while computing the bound answers.
208 * */
207 private OWLOntology relevantPart(QueryRecord queryRecord) { 209 private OWLOntology relevantPart(QueryRecord queryRecord) {
208 AnswerTuples rlAnswer = null, elAnswer = null; 210 AnswerTuples rlAnswer = null, elAnswer = null;
209 211
@@ -216,13 +218,13 @@ public class MyQueryReasoner extends QueryReasoner {
216 if (rlAnswer != null) rlAnswer.dispose(); 218 if (rlAnswer != null) rlAnswer.dispose();
217 } 219 }
218 queryRecord.addProcessingTime(Step.LowerBound, t.duration()); 220 queryRecord.addProcessingTime(Step.LowerBound, t.duration());
219 rlAnswer = null;
220 221
221 t.reset(); 222 t.reset();
222 BasicQueryEngine upperStore = queryRecord.isBottom() || lazyUpperStore == null ? trackingStore : lazyUpperStore; 223 BasicQueryEngine upperStore = queryRecord.isBottom() || lazyUpperStore == null ? trackingStore : lazyUpperStore;
223 224
224 String[] extendedQuery = queryRecord.getExtendedQueryText(); 225 String[] extendedQuery = queryRecord.getExtendedQueryText();
225 226
227 // TODO why the following???
226 queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); 228 queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables());
227 229
228 if (!queryRecord.processed() && !queryRecord.getQueryText().equals(extendedQuery[0])) { 230 if (!queryRecord.processed() && !queryRecord.getQueryText().equals(extendedQuery[0])) {
@@ -232,25 +234,21 @@ public class MyQueryReasoner extends QueryReasoner {
232 queryUpperBound(upperStore, queryRecord, extendedQuery[1], queryRecord.getDistinguishedVariables()); 234 queryUpperBound(upperStore, queryRecord, extendedQuery[1], queryRecord.getDistinguishedVariables());
233 } 235 }
234 236
235 Utility.logDebug(toJsonKeyValuePair("upperBound1", queryRecord)); 237// Utility.logDebug(toJsonKeyValuePair("upperBound", queryRecord));
236 238
237 // TODO check whether it is harmful. In case is not, implement it properly 239 // TODO test intersection and new upper bound
238 // BEGIN: trying to intersect
239 if (!queryRecord.isBottom() && lazyUpperStore != null) { 240 if (!queryRecord.isBottom() && lazyUpperStore != null) {
240 queryUpperBound(trackingStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); 241 queryUpperBound(trackingStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables());
241 } 242 }
242 if (!queryRecord.isBottom() && limitedSkolemUpperStore != null) { 243 if (!queryRecord.isBottom() && limitedSkolemUpperStore != null) {
243 queryUpperBound(limitedSkolemUpperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); 244 queryUpperBound(limitedSkolemUpperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables());
244 } 245 }
245 // END: trying to intersect
246 246
247 queryRecord.addProcessingTime(Step.UpperBound, t.duration()); 247 queryRecord.addProcessingTime(Step.UpperBound, t.duration());
248 if (queryRecord.processed()) { 248 if (queryRecord.processed()) {
249 queryRecord.setDifficulty(Step.UpperBound); 249 queryRecord.setDifficulty(Step.UpperBound);
250 return null; 250 return null;
251 } 251 }
252
253 // TODO add evaluation on new upper store
254 252
255 t.reset(); 253 t.reset();
256 try { 254 try {
@@ -327,15 +325,15 @@ public class MyQueryReasoner extends QueryReasoner {
327 325
328 @Override 326 @Override
329 public void evaluate(QueryRecord queryRecord) { 327 public void evaluate(QueryRecord queryRecord) {
330 OWLOntology knowledgebase = relevantPart(queryRecord); 328 OWLOntology knowledgeBase = relevantPart(queryRecord);
331 329
332 if (knowledgebase == null) { 330 if (knowledgeBase == null) {
333 Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); 331 Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty());
334 return ; 332 return ;
335 } 333 }
336 334
337 int aboxcount = knowledgebase.getABoxAxioms(true).size(); 335 int aBoxCount = knowledgeBase.getABoxAxioms(true).size();
338 Utility.logDebug("ABox axioms: " + aboxcount + " TBox axioms: " + (knowledgebase.getAxiomCount() - aboxcount)); 336 Utility.logDebug("ABox axioms: " + aBoxCount + " TBox axioms: " + (knowledgeBase.getAxiomCount() - aBoxCount));
339// queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl"); 337// queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl");
340 338
341 Timer t = new Timer(); 339 Timer t = new Timer();
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
index 326bf7e..97bab50 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
@@ -25,8 +25,8 @@ public abstract class QueryReasoner {
25 private static boolean defaultMultiStages = true; 25 private static boolean defaultMultiStages = true;
26 private static boolean defaultEqualities = true; 26 private static boolean defaultEqualities = true;
27 27
28 public static enum Type { Full, RLU, ELHOU }; 28 public enum Type { Full, RLU, ELHOU }
29 29
30 public static QueryReasoner getInstance(Properties p) { 30 public static QueryReasoner getInstance(Properties p) {
31 OWLOntology ontology = OWLHelper.loadOntology(p.getOntologyPath()); 31 OWLOntology ontology = OWLHelper.loadOntology(p.getOntologyPath());
32 QueryReasoner pagoda = getInstance(ontology, p); 32 QueryReasoner pagoda = getInstance(ontology, p);
@@ -63,7 +63,7 @@ public abstract class QueryReasoner {
63 } 63 }
64 64
65 public static QueryReasoner getInstance(Type type, OWLOntology o, boolean performMultiStages, boolean considerEqualities) { 65 public static QueryReasoner getInstance(Type type, OWLOntology o, boolean performMultiStages, boolean considerEqualities) {
66 Utility.initialise(); 66// Utility.initialise();
67 QueryReasoner reasoner; 67 QueryReasoner reasoner;
68 if (OWLHelper.isInOWL2RL(o)) reasoner = new RLQueryReasoner(); 68 if (OWLHelper.isInOWL2RL(o)) reasoner = new RLQueryReasoner();
69 else if (OWLHelper.isInELHO(o)) reasoner = new ELHOQueryReasoner(); 69 else if (OWLHelper.isInELHO(o)) reasoner = new ELHOQueryReasoner();
@@ -218,9 +218,10 @@ public abstract class QueryReasoner {
218 record.outputAnswerStatistics(); 218 record.outputAnswerStatistics();
219 record.outputTimes(); 219 record.outputTimes();
220 } 220 }
221 // TODO it can handle one call only 221 /* TODO it can handle one call only
222 // if you call twice, you will end up with a json file with multiple roots 222 if you call twice, you will end up with a json file with multiple roots */
223 if(answerWriter != null) gson.toJson(queryRecords, answerWriter); 223 if(answerWriter != null) gson.toJson(queryRecords, answerWriter);
224// queryRecords.stream().forEach(record -> Utility.logDebug(gson.toJson(record)));
224 queryRecords.stream().forEach(record -> record.dispose()); 225 queryRecords.stream().forEach(record -> record.dispose());
225 } 226 }
226 227
@@ -232,7 +233,7 @@ public abstract class QueryReasoner {
232 e.printStackTrace(); 233 e.printStackTrace();
233 } 234 }
234 } 235 }
235 Utility.cleanup(); 236// Utility.cleanup();
236 } 237 }
237 238
238 private QueryManager m_queryManager = new QueryManager(); 239 private QueryManager m_queryManager = new QueryManager();
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 @@
1package uk.ac.ox.cs.pagoda.reasoner.light; 1package uk.ac.ox.cs.pagoda.reasoner.light;
2 2
3import java.io.File; 3import org.semanticweb.karma2.MyKarma;
4import java.io.FileNotFoundException;
5import java.util.*;
6
7import org.semanticweb.karma2.*;
8import org.semanticweb.karma2.clausifier.OntologyProcesser; 4import org.semanticweb.karma2.clausifier.OntologyProcesser;
9import org.semanticweb.karma2.exception.IllegalInputOntologyException; 5import org.semanticweb.karma2.exception.IllegalInputOntologyException;
10import org.semanticweb.karma2.model.ConjunctiveQuery; 6import org.semanticweb.karma2.model.ConjunctiveQuery;
11import org.semanticweb.owlapi.model.OWLOntology; 7import org.semanticweb.owlapi.model.OWLOntology;
12
13import uk.ac.ox.cs.pagoda.query.*;
14import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper;
15import uk.ac.ox.cs.pagoda.util.Utility;
16import uk.ac.ox.cs.JRDFox.JRDFStoreException; 8import uk.ac.ox.cs.JRDFox.JRDFStoreException;
17import uk.ac.ox.cs.JRDFox.store.DataStore; 9import uk.ac.ox.cs.JRDFox.store.DataStore;
10import uk.ac.ox.cs.pagoda.query.AnswerTuple;
11import uk.ac.ox.cs.pagoda.query.AnswerTuples;
12import uk.ac.ox.cs.pagoda.query.AnswerTuplesImp;
13import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper;
14import uk.ac.ox.cs.pagoda.util.Utility;
15
16import java.io.File;
17import java.io.FileNotFoundException;
18import java.nio.file.Paths;
19import java.util.Set;
18 20
19public class KarmaQueryEngine extends RDFoxQueryEngine { 21public 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..63773d9 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,9 @@
1package uk.ac.ox.cs.pagoda.reasoner.light; 1package uk.ac.ox.cs.pagoda.reasoner.light;
2 2
3import java.io.File; 3import uk.ac.ox.cs.JRDFox.JRDFStoreException;
4import java.util.Collection; 4import uk.ac.ox.cs.JRDFox.Prefixes;
5 5import uk.ac.ox.cs.JRDFox.store.DataStore;
6import uk.ac.ox.cs.JRDFox.store.DataStore.StoreType;
6import uk.ac.ox.cs.pagoda.MyPrefixes; 7import uk.ac.ox.cs.pagoda.MyPrefixes;
7import uk.ac.ox.cs.pagoda.query.AnswerTuples; 8import uk.ac.ox.cs.pagoda.query.AnswerTuples;
8import uk.ac.ox.cs.pagoda.reasoner.QueryEngine; 9import uk.ac.ox.cs.pagoda.reasoner.QueryEngine;
@@ -10,16 +11,19 @@ import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner;
10import uk.ac.ox.cs.pagoda.tracking.AnswerTuplesWriter; 11import uk.ac.ox.cs.pagoda.tracking.AnswerTuplesWriter;
11import uk.ac.ox.cs.pagoda.util.Timer; 12import uk.ac.ox.cs.pagoda.util.Timer;
12import uk.ac.ox.cs.pagoda.util.Utility; 13import uk.ac.ox.cs.pagoda.util.Utility;
13import uk.ac.ox.cs.JRDFox.JRDFStoreException; 14
14import uk.ac.ox.cs.JRDFox.Prefixes; 15import java.io.File;
15import uk.ac.ox.cs.JRDFox.store.DataStore; 16import java.util.Collection;
16import uk.ac.ox.cs.JRDFox.store.DataStore.StoreType;
17 17
18public abstract class RDFoxQueryEngine implements QueryEngine { 18public abstract class RDFoxQueryEngine implements QueryEngine {
19 19
20 public static final int matNoOfThreads = Runtime.getRuntime().availableProcessors() * 2; 20 public static final int matNoOfThreads = Runtime.getRuntime().availableProcessors() * 2;
21 21
22 protected String name; 22 public String getName() {
23 return name;
24 }
25
26 protected String name;
23 protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes(); 27 protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes();
24 28
25 public RDFoxQueryEngine(String name) { 29 public RDFoxQueryEngine(String name) {
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 232bc31..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,5 +1,8 @@
1package uk.ac.ox.cs.pagoda.reasoner.light; 1package uk.ac.ox.cs.pagoda.reasoner.light;
2 2
3import net.sf.ehcache.Cache;
4import net.sf.ehcache.CacheManager;
5import net.sf.ehcache.Element;
3import org.semanticweb.HermiT.model.*; 6import org.semanticweb.HermiT.model.*;
4import uk.ac.ox.cs.JRDFox.JRDFStoreException; 7import uk.ac.ox.cs.JRDFox.JRDFStoreException;
5import uk.ac.ox.cs.JRDFox.model.Datatype; 8import uk.ac.ox.cs.JRDFox.model.Datatype;
@@ -11,11 +14,20 @@ import uk.ac.ox.cs.JRDFox.store.Resource;
11import uk.ac.ox.cs.pagoda.owl.OWLHelper; 14import uk.ac.ox.cs.pagoda.owl.OWLHelper;
12import uk.ac.ox.cs.pagoda.util.Namespace; 15import uk.ac.ox.cs.pagoda.util.Namespace;
13 16
14import java.util.*; 17import java.util.Collection;
18import java.util.HashMap;
19import java.util.Map;
15 20
16public class RDFoxTripleManager { 21public class RDFoxTripleManager {
17 22
18 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;
19// boolean m_incrementally; 31// boolean m_incrementally;
20 32
21 DataStore m_store; 33 DataStore m_store;
@@ -24,7 +36,19 @@ public class RDFoxTripleManager {
24 36
25 public RDFoxTripleManager(DataStore store, boolean incrementally) { 37 public RDFoxTripleManager(DataStore store, boolean incrementally) {
26 m_store = store; 38 m_store = store;
27// 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
28 if (incrementally) 52 if (incrementally)
29 m_incrementally = UpdateType.ScheduleForAddition; 53 m_incrementally = UpdateType.ScheduleForAddition;
30 else 54 else
@@ -164,29 +188,25 @@ public class RDFoxTripleManager {
164 return m_dict.resolveResources(lexicalForms, types)[0]; 188 return m_dict.resolveResources(lexicalForms, types)[0];
165 } 189 }
166 190
167 Map<Term, Integer> termCache = new HashMap<Term, Integer>(); 191// Map<Term, Integer> termCache = new HashMap<Term, Integer>();
168 Queue<Term> termList = new LinkedList<Term>(); 192// Queue<Term> termQueue = new LinkedList<Term>();
169 int sizeLimit = 10000;
170 193
171 private int getResourceID(Term arg, Map<Variable, Integer> assignment) { 194 private int getResourceID(Term arg, Map<Variable, Integer> assignment) {
172 // FIXME infinite loop
173// while (termCache.size() > sizeLimit)
174// termCache.remove(termList.poll());
175
176 if (arg instanceof Variable) return assignment.get(arg); 195 if (arg instanceof Variable) return assignment.get(arg);
177 Integer id = null; 196 int id = -1;
178 if ((id = termCache.get(arg)) != null) 197 if(termsCache.isKeyInCache(arg))
179 return id; 198 return ((int) termsCache.get(arg).getObjectValue());
180 199
181// if (arg instanceof Individual) { 200// if (arg instanceof Individual) {
182 try { 201 try {
183 if (arg instanceof Individual) 202 if (arg instanceof Individual)
184 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())));
185 else if (arg instanceof Constant) 204 else if (arg instanceof Constant)
186 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()))));
187 206
188 } catch (JRDFStoreException e) { 207 } catch (JRDFStoreException e) {
189 e.printStackTrace(); 208 e.printStackTrace();
209 System.exit(1);
190 } 210 }
191// } 211// }
192 212