aboutsummaryrefslogtreecommitdiff
path: root/src/uk/ac/ox/cs
diff options
context:
space:
mode:
authorRncLsn <rnc.lsn@gmail.com>2015-05-28 10:29:11 +0100
committerRncLsn <rnc.lsn@gmail.com>2015-05-28 10:29:11 +0100
commit2e069a4966e6305194c4168d6fc5c406123d7f64 (patch)
treedc70e541b78494ac13f899db2831422b28fc5f72 /src/uk/ac/ox/cs
parentc9c8d03e957fa56df5dc1304f7a81dfa61b7b70e (diff)
downloadACQuA-2e069a4966e6305194c4168d6fc5c406123d7f64.tar.gz
ACQuA-2e069a4966e6305194c4168d6fc5c406123d7f64.zip
NOT-WORKING: trying to add query-dependent Skolemisation.
Diffstat (limited to 'src/uk/ac/ox/cs')
-rw-r--r--src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java178
-rw-r--r--src/uk/ac/ox/cs/pagoda/query/QueryRecord.java13
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java114
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java2
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java26
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java145
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java12
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java4
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java94
-rw-r--r--src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java2
-rw-r--r--src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java38
11 files changed, 310 insertions, 318 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java
index 1e17dac..767d379 100644
--- a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java
+++ b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java
@@ -38,46 +38,51 @@ public class RLPlusOntology implements KnowledgeBase {
38 LinkedList<Clause> clauses; 38 LinkedList<Clause> clauses;
39 Map<OWLAxiom, OWLAxiom> correspondence; 39 Map<OWLAxiom, OWLAxiom> correspondence;
40 40
41 BottomStrategy botStrategy; 41 BottomStrategy botStrategy;
42 42 Random random = new Random(19900114);
43 private Map<OWLClassExpression, Integer> subCounter = null;
44 private Map<OWLClass, OWLClass> atomic2negation = new HashMap<OWLClass, OWLClass>();
45
46 // FIXME multiple anonymous ontologies
43 @Override 47 @Override
44 public void load(OWLOntology o, uk.ac.ox.cs.pagoda.constraints.BottomStrategy bottomStrategy) { 48 public void load(OWLOntology o, uk.ac.ox.cs.pagoda.constraints.BottomStrategy bottomStrategy) {
45 if (bottomStrategy instanceof UnaryBottom) 49 if (bottomStrategy instanceof UnaryBottom)
46 botStrategy = BottomStrategy.UNARY; 50 botStrategy = BottomStrategy.UNARY;
47 else if (bottomStrategy instanceof NullaryBottom) 51 else if (bottomStrategy instanceof NullaryBottom)
48 botStrategy = BottomStrategy.NULLARY; 52 botStrategy = BottomStrategy.NULLARY;
49 else 53 else
50 botStrategy = BottomStrategy.TOREMOVE; 54 botStrategy = BottomStrategy.TOREMOVE;
51 55
52 if (corrFileName == null) 56 if(corrFileName == null)
53 corrFileName = "rlplus.crr"; 57 corrFileName = "rlplus.crr";
54 manager = o.getOWLOntologyManager(); 58 manager = o.getOWLOntologyManager();
55// manager = OWLManager.createOWLOntologyManager(); 59// manager = OWLManager.createOWLOntologyManager();
56 factory = manager.getOWLDataFactory(); 60 factory = manager.getOWLDataFactory();
57 inputOntology = o; 61 inputOntology = o;
58 62
59 try { 63 try {
60 String path = OWLHelper.getOntologyPath(inputOntology); 64 String path = OWLHelper.getOntologyPath(inputOntology);
61 String name = path.substring(path.lastIndexOf(Utility.JAVA_FILE_SEPARATOR)); 65 String name = path.substring(path.lastIndexOf(Utility.JAVA_FILE_SEPARATOR));
62 String originalExtension = name.lastIndexOf(".") >= 0 ? name.substring(name.lastIndexOf(".")) : ""; 66 String originalExtension = name.lastIndexOf(".") >= 0 ? name.substring(name.lastIndexOf(".")) : "";
63 67
64 if (inputOntology.getOntologyID().getOntologyIRI() == null) 68 if (inputOntology.getOntologyID().getOntologyIRI() == null)
65 ontologyIRI = "http://www.example.org/anonymous-ontology" + originalExtension; 69 ontologyIRI = "http://www.example.org/anonymous-ontology" + originalExtension;
66 else 70 else
67 ontologyIRI = inputOntology.getOntologyID().getOntologyIRI().toString(); 71 ontologyIRI = inputOntology.getOntologyID().getOntologyIRI().toString();
68 72
69 String tOntoIRI = ontologyIRI; 73 String tOntoIRI = ontologyIRI;
70 if (!tOntoIRI.endsWith(originalExtension)) tOntoIRI += originalExtension; 74 if (!tOntoIRI.endsWith(originalExtension)) tOntoIRI += originalExtension;
71 75
72 String rlOntologyIRI = originalExtension.isEmpty() ? tOntoIRI + "-RL.owl" : tOntoIRI.replaceFirst(originalExtension, "-RL.owl"); 76 String rlOntologyIRI = originalExtension.isEmpty() ? tOntoIRI + "-RL.owl" : tOntoIRI.replaceFirst(originalExtension, "-RL.owl");
73 String rlDocumentIRI = (outputPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "RL.owl").toString()); 77 String rlDocumentIRI = (outputPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "RL.owl").toString());
74 outputOntology = manager.createOntology(IRI.create(rlOntologyIRI)); 78 outputOntology = manager.createOntology(IRI.create(rlOntologyIRI));
75 manager.setOntologyDocumentIRI(outputOntology, IRI.create(Utility.toFileIRI(rlDocumentIRI))); 79 manager.setOntologyDocumentIRI(outputOntology, IRI.create(Utility.toFileIRI(rlDocumentIRI)));
76 80
77 String tBoxOntologyIRI, aBoxOntologyIRI; 81 String tBoxOntologyIRI, aBoxOntologyIRI;
78 tBoxOntologyIRI = originalExtension.isEmpty() ? tOntoIRI + "-TBox.owl" : tOntoIRI.replaceFirst(originalExtension, "-TBox.owl"); 82 tBoxOntologyIRI =
83 originalExtension.isEmpty() ? tOntoIRI + "-TBox.owl" : tOntoIRI.replaceFirst(originalExtension, "-TBox.owl");
79 aBoxOntologyIRI = originalExtension.isEmpty() ? tOntoIRI + "-ABox.owl" : tOntoIRI.replaceFirst(originalExtension, "-ABox.owl"); 84 aBoxOntologyIRI = originalExtension.isEmpty() ? tOntoIRI + "-ABox.owl" : tOntoIRI.replaceFirst(originalExtension, "-ABox.owl");
80 85
81 String tBoxDocumentIRI = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "TBox.owl").toString(); 86 String tBoxDocumentIRI = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "TBox.owl").toString();
82 String aBoxDocumentIRI = (aBoxPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "ABox.owl").toString()); 87 String aBoxDocumentIRI = (aBoxPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "ABox.owl").toString());
83 tBox = manager.createOntology(IRI.create(tBoxOntologyIRI)); 88 tBox = manager.createOntology(IRI.create(tBoxOntologyIRI));
@@ -85,10 +90,10 @@ public class RLPlusOntology implements KnowledgeBase {
85 manager.setOntologyDocumentIRI(tBox, IRI.create(Utility.toFileIRI(tBoxDocumentIRI))); 90 manager.setOntologyDocumentIRI(tBox, IRI.create(Utility.toFileIRI(tBoxDocumentIRI)));
86 manager.setOntologyDocumentIRI(aBox, IRI.create(Utility.toFileIRI(aBoxDocumentIRI))); 91 manager.setOntologyDocumentIRI(aBox, IRI.create(Utility.toFileIRI(aBoxDocumentIRI)));
87 92
88 FileOutputStream aBoxOut = new FileOutputStream(aBoxPath); 93 FileOutputStream aBoxOut = new FileOutputStream(aBoxPath);
89 manager.saveOntology(aBox, aBoxOut); 94 manager.saveOntology(aBox, aBoxOut);
90 aBoxOut.close(); 95 aBoxOut.close();
91 96
92 restOntology = manager.createOntology(); 97 restOntology = manager.createOntology();
93 } 98 }
94 catch (OWLOntologyCreationException e) { 99 catch (OWLOntologyCreationException e) {
@@ -103,11 +108,11 @@ public class RLPlusOntology implements KnowledgeBase {
103 } 108 }
104 109
105 public OWLOntology getTBox() { 110 public OWLOntology getTBox() {
106 return tBox; 111 return tBox;
107 } 112 }
108 113
109 public String getABoxPath() { 114 public String getABoxPath() {
110 return aBoxPath; 115 return aBoxPath;
111 } 116 }
112 117
113 private void add2SubCounter(OWLClassExpression exp) { 118 private void add2SubCounter(OWLClassExpression exp) {
@@ -118,24 +123,23 @@ public class RLPlusOntology implements KnowledgeBase {
118 } 123 }
119 124
120 public void simplify() { 125 public void simplify() {
121 if (simplifyABox()) { 126 if(simplifyABox()) {
122 save(aBox); 127 save(aBox);
123// save(tBox); 128// save(tBox);
124 } 129 } else
125 else 130 tBox = inputOntology;
126 tBox = inputOntology;
127 } 131 }
128 132
129 @Override 133 @Override
130 public void transform() { 134 public void transform() {
131 simplify(); 135 simplify();
132 filter(); 136 filter();
133 clausify(); 137 clausify();
134 138
135 subCounter = new HashMap<OWLClassExpression, Integer>(); 139 subCounter = new HashMap<OWLClassExpression, Integer>();
136 clauses = new LinkedList<Clause>(); 140 clauses = new LinkedList<Clause>();
137 Clausifier clausifier = Clausifier.getInstance(restOntology); 141 Clausifier clausifier = Clausifier.getInstance(restOntology);
138 142
139 for (DLClause c: dlOntology.getDLClauses()) { 143 for (DLClause c: dlOntology.getDLClauses()) {
140 Clause clause = new Clause(clausifier, c); 144 Clause clause = new Clause(clausifier, c);
141 clauses.add(clause); 145 clauses.add(clause);
@@ -144,7 +148,7 @@ public class RLPlusOntology implements KnowledgeBase {
144 * count the expressions in the left 148 * count the expressions in the left
145 */ 149 */
146 for (OWLClassExpression exp: clause.getSubClasses()) { 150 for (OWLClassExpression exp: clause.getSubClasses()) {
147 if (exp instanceof OWLClass) 151 if(exp instanceof OWLClass)
148 add2SubCounter(exp); 152 add2SubCounter(exp);
149 else if (exp instanceof OWLObjectSomeValuesFrom) { 153 else if (exp instanceof OWLObjectSomeValuesFrom) {
150 OWLObjectSomeValuesFrom someValue = (OWLObjectSomeValuesFrom)exp; 154 OWLObjectSomeValuesFrom someValue = (OWLObjectSomeValuesFrom)exp;
@@ -155,8 +159,7 @@ public class RLPlusOntology implements KnowledgeBase {
155 OWLObjectMinCardinality minCard = (OWLObjectMinCardinality)exp; 159 OWLObjectMinCardinality minCard = (OWLObjectMinCardinality)exp;
156 add2SubCounter(factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), factory.getOWLThing())); 160 add2SubCounter(factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), factory.getOWLThing()));
157 add2SubCounter(minCard.getFiller()); 161 add2SubCounter(minCard.getFiller());
158 } 162 } else
159 else
160 Utility.logError("strange class expression: " + exp); 163 Utility.logError("strange class expression: " + exp);
161 164
162 } 165 }
@@ -170,12 +173,12 @@ public class RLPlusOntology implements KnowledgeBase {
170 addedAxioms.clear(); 173 addedAxioms.clear();
171 for (OWLClassExpression exp: getDisjunctionApprox0(clause.getSuperClasses())) { 174 for (OWLClassExpression exp: getDisjunctionApprox0(clause.getSuperClasses())) {
172 addedAxioms.add(factory.getOWLSubClassOfAxiom(subExp, transform(exp, addedAxioms))); 175 addedAxioms.add(factory.getOWLSubClassOfAxiom(subExp, transform(exp, addedAxioms)));
173 for (OWLAxiom a: addedAxioms) 176 for(OWLAxiom a : addedAxioms)
174 addAxiom2output(a, factory.getOWLSubClassOfAxiom(subExp, 177 addAxiom2output(a, factory.getOWLSubClassOfAxiom(subExp,
175 OWLHelper.getSimplifiedDisjunction(factory, clause.getSuperClasses()))); 178 OWLHelper.getSimplifiedDisjunction(factory, clause.getSuperClasses())));
176 } 179 }
177 } 180 }
178 181
179 subCounter.clear(); 182 subCounter.clear();
180 } 183 }
181 184
@@ -185,7 +188,7 @@ public class RLPlusOntology implements KnowledgeBase {
185 save(correspondence, corrFileName); 188 save(correspondence, corrFileName);
186 save(outputOntology); 189 save(outputOntology);
187 } 190 }
188 191
189 private void save(Map<OWLAxiom, OWLAxiom> map, String corrFileName) { 192 private void save(Map<OWLAxiom, OWLAxiom> map, String corrFileName) {
190 if (corrFileName == null) return ; 193 if (corrFileName == null) return ;
191 ObjectOutput output; 194 ObjectOutput output;
@@ -205,63 +208,61 @@ public class RLPlusOntology implements KnowledgeBase {
205 e.printStackTrace(); 208 e.printStackTrace();
206 } 209 }
207 } 210 }
208 211
209 /* 212 /*
210 * treat disjunction as conjunction 213 * treat disjunction as conjunction
211 */ 214 */
212 private Set<OWLClassExpression> getDisjunctionApprox0(Set<OWLClassExpression> superClasses) { 215 private Set<OWLClassExpression> getDisjunctionApprox0(Set<OWLClassExpression> superClasses) {
213 return superClasses; 216 return superClasses;
214 } 217 }
215 218
216 /* 219 /*
217 * choose one simple class disjunct 220 * choose one simple class disjunct
218 */ 221 */
219 @SuppressWarnings("unused") 222 @SuppressWarnings("unused")
220 private Set<OWLClassExpression> getDisjunctionApprox1(Set<OWLClassExpression> superClasses) { 223 private Set<OWLClassExpression> getDisjunctionApprox1(Set<OWLClassExpression> superClasses) {
221 if (superClasses.isEmpty() || superClasses.size() == 1) 224 if(superClasses.isEmpty() || superClasses.size() == 1)
222 return superClasses; 225 return superClasses;
223 226
224 OWLClassExpression rep = null; 227 OWLClassExpression rep = null;
225 int min = Integer.MAX_VALUE, o; 228 int min = Integer.MAX_VALUE, o;
226 for (OWLClassExpression exp: superClasses) 229 for(OWLClassExpression exp : superClasses)
227 if (exp instanceof OWLClass && (o = getOccurrence(exp)) < min) { 230 if(exp instanceof OWLClass && (o = getOccurrence(exp)) < min) {
228 min = o; 231 min = o;
229 rep = exp; 232 rep = exp;
230 } 233 }
231 234
232 if (rep == null) rep = superClasses.iterator().next(); 235 if(rep == null) rep = superClasses.iterator().next();
233 236
234 return Collections.singleton(rep); 237 return Collections.singleton(rep);
235 } 238 }
236 239
237 Random random = new Random(19900114);
238 /* 240 /*
239 * randomly choose a class expression to represent this disjunction 241 * randomly choose a class expression to represent this disjunction
240 */ 242 */
241 @SuppressWarnings("unused") 243 @SuppressWarnings("unused")
242 private Set<OWLClassExpression> getDisjunctionApprox2(Set<OWLClassExpression> superClasses) { 244 private Set<OWLClassExpression> getDisjunctionApprox2(Set<OWLClassExpression> superClasses) {
243 if (superClasses.isEmpty() || superClasses.size() == 1) 245 if(superClasses.isEmpty() || superClasses.size() == 1)
244 return superClasses; 246 return superClasses;
245 247
246 int index = random.nextInt() % superClasses.size(); 248 int index = random.nextInt() % superClasses.size();
247 if (index < 0) index += superClasses.size(); 249 if (index < 0) index += superClasses.size();
248 250
249 int i = 0; 251 int i = 0;
250 for (OWLClassExpression exp: superClasses) 252 for(OWLClassExpression exp : superClasses)
251 if (i++ == index) 253 if (i++ == index)
252 return Collections.singleton(exp); 254 return Collections.singleton(exp);
253 return null; 255 return null;
254 } 256 }
255 257
256 private Map<OWLClassExpression, Integer> subCounter = null;
257 /* 258 /*
258 * choose the one that appears least in the l.h.s. 259 * choose the one that appears least in the l.h.s.
259 */ 260 */
260 @SuppressWarnings("unused") 261 @SuppressWarnings("unused")
261 private Set<OWLClassExpression> getDisjunctionApprox3(Set<OWLClassExpression> superClasses) { 262 private Set<OWLClassExpression> getDisjunctionApprox3(Set<OWLClassExpression> superClasses) {
262 if (superClasses.isEmpty() || superClasses.size() == 1) 263 if(superClasses.isEmpty() || superClasses.size() == 1)
263 return superClasses; 264 return superClasses;
264 265
265 OWLClassExpression rep = null, exp1; 266 OWLClassExpression rep = null, exp1;
266 int occurrence = Integer.MAX_VALUE, o; 267 int occurrence = Integer.MAX_VALUE, o;
267 for (OWLClassExpression exp: superClasses) { 268 for (OWLClassExpression exp: superClasses) {
@@ -272,16 +273,16 @@ public class RLPlusOntology implements KnowledgeBase {
272 if (minCard.getCardinality() == 1) 273 if (minCard.getCardinality() == 1)
273 exp1 = factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), minCard.getFiller()); 274 exp1 = factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), minCard.getFiller());
274 } 275 }
275 276
276 if (!subCounter.containsKey(exp1) || (o = subCounter.get(exp1)) < occurrence) { 277 if (!subCounter.containsKey(exp1) || (o = subCounter.get(exp1)) < occurrence) {
277 rep = exp; 278 rep = exp;
278 occurrence = o; 279 occurrence = o;
279 } 280 }
280 } 281 }
281 282
282 return Collections.singleton(rep); 283 return Collections.singleton(rep);
283 } 284 }
284 285
285 private int getOccurrence(OWLClassExpression exp) { 286 private int getOccurrence(OWLClassExpression exp) {
286 if (!subCounter.containsKey(exp)) 287 if (!subCounter.containsKey(exp))
287 return 0; 288 return 0;
@@ -290,9 +291,9 @@ public class RLPlusOntology implements KnowledgeBase {
290 291
291 @SuppressWarnings("unused") 292 @SuppressWarnings("unused")
292 private Set<OWLClassExpression> getDisjunctionApprox4(Set<OWLClassExpression> superClasses) { 293 private Set<OWLClassExpression> getDisjunctionApprox4(Set<OWLClassExpression> superClasses) {
293 if (superClasses.isEmpty() || superClasses.size() == 1) 294 if(superClasses.isEmpty() || superClasses.size() == 1)
294 return superClasses; 295 return superClasses;
295 296
296 OWLClassExpression rep = null; 297 OWLClassExpression rep = null;
297 int occurrence = Integer.MAX_VALUE, o; 298 int occurrence = Integer.MAX_VALUE, o;
298 for (OWLClassExpression exp: superClasses) { 299 for (OWLClassExpression exp: superClasses) {
@@ -304,10 +305,9 @@ public class RLPlusOntology implements KnowledgeBase {
304 o += getOccurrence(minCard.getFiller()); 305 o += getOccurrence(minCard.getFiller());
305// if (o < o1) o = o1; 306// if (o < o1) o = o1;
306 } 307 }
307 } 308 } else
308 else
309 o = getOccurrence(exp); 309 o = getOccurrence(exp);
310 310
311 if (o < occurrence || o == occurrence && !(rep instanceof OWLClass)) { 311 if (o < occurrence || o == occurrence && !(rep instanceof OWLClass)) {
312 rep = exp; 312 rep = exp;
313 occurrence = o; 313 occurrence = o;
@@ -320,11 +320,11 @@ public class RLPlusOntology implements KnowledgeBase {
320 private boolean simplifyABox() { 320 private boolean simplifyABox() {
321 boolean flag = false; 321 boolean flag = false;
322 Map<OWLClassExpression, OWLClass> complex2atomic= new HashMap<OWLClassExpression, OWLClass>(); 322 Map<OWLClassExpression, OWLClass> complex2atomic= new HashMap<OWLClassExpression, OWLClass>();
323 323
324 OWLDatatype anyURI = factory.getOWLDatatype(IRI.create(Namespace.XSD_NS + "anyURI")); 324 OWLDatatype anyURI = factory.getOWLDatatype(IRI.create(Namespace.XSD_NS + "anyURI"));
325 OWLObjectProperty sameAs = factory.getOWLObjectProperty(IRI.create(Namespace.EQUALITY)); 325 OWLObjectProperty sameAs = factory.getOWLObjectProperty(IRI.create(Namespace.EQUALITY));
326 OWLObjectProperty differentFrom = factory.getOWLObjectProperty(IRI.create(Namespace.INEQUALITY)); 326 OWLObjectProperty differentFrom = factory.getOWLObjectProperty(IRI.create(Namespace.INEQUALITY));
327 327
328 for (OWLOntology imported: inputOntology.getImportsClosure()) 328 for (OWLOntology imported: inputOntology.getImportsClosure())
329 for (OWLAxiom axiom: imported.getAxioms()) { 329 for (OWLAxiom axiom: imported.getAxioms()) {
330 if (axiom instanceof OWLClassAssertionAxiom) { 330 if (axiom instanceof OWLClassAssertionAxiom) {
@@ -334,7 +334,7 @@ public class RLPlusOntology implements KnowledgeBase {
334 OWLClass cls; 334 OWLClass cls;
335 if (clsExp instanceof OWLClass) { 335 if (clsExp instanceof OWLClass) {
336 if (((OWLClass) clsExp).toStringID().startsWith("owl:")) 336 if (((OWLClass) clsExp).toStringID().startsWith("owl:"))
337 manager.addAxiom(tBox, axiom); 337 manager.addAxiom(tBox, axiom);
338 else manager.addAxiom(aBox, axiom); 338 else manager.addAxiom(aBox, axiom);
339 } 339 }
340 else { 340 else {
@@ -343,40 +343,38 @@ public class RLPlusOntology implements KnowledgeBase {
343 manager.addAxiom(tBox, factory.getOWLSubClassOfAxiom(cls, clsExp)); 343 manager.addAxiom(tBox, factory.getOWLSubClassOfAxiom(cls, clsExp));
344 } 344 }
345 manager.addAxiom(aBox, factory.getOWLClassAssertionAxiom(cls, assertion.getIndividual())); 345 manager.addAxiom(aBox, factory.getOWLClassAssertionAxiom(cls, assertion.getIndividual()));
346 } 346 }
347 } 347 }
348 else if (axiom instanceof OWLObjectPropertyAssertionAxiom || axiom instanceof OWLDataPropertyAssertionAxiom || axiom instanceof OWLAnnotationAssertionAxiom) { 348 else if (axiom instanceof OWLObjectPropertyAssertionAxiom || axiom instanceof OWLDataPropertyAssertionAxiom || axiom instanceof OWLAnnotationAssertionAxiom) {
349 if (axiom.getDataPropertiesInSignature().contains(anyURI)) continue; 349 if(axiom.getDataPropertiesInSignature().contains(anyURI)) continue;
350 flag = true; 350 flag = true;
351 manager.addAxiom(aBox, axiom); 351 manager.addAxiom(aBox, axiom);
352 } 352 }
353 else if (axiom instanceof OWLSameIndividualAxiom) { 353 else if (axiom instanceof OWLSameIndividualAxiom) {
354 OWLIndividual firstIndividual = null, previousIndividual = null, lastIndividual = null; 354 OWLIndividual firstIndividual = null, previousIndividual = null, lastIndividual = null;
355 for (OWLIndividual next: ((OWLSameIndividualAxiom) axiom).getIndividuals()) { 355 for (OWLIndividual next: ((OWLSameIndividualAxiom) axiom).getIndividuals()) {
356 if (firstIndividual == null) firstIndividual = previousIndividual = next; 356 if(firstIndividual == null) firstIndividual = previousIndividual = next;
357 else 357 else
358 manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, previousIndividual, next)); 358 manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, previousIndividual, next));
359 previousIndividual = lastIndividual = next; 359 previousIndividual = lastIndividual = next;
360 } 360 }
361 manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, lastIndividual, firstIndividual)); 361 manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, lastIndividual, firstIndividual));
362 } 362 }
363 else if (axiom instanceof OWLDifferentIndividualsAxiom) { 363 else if (axiom instanceof OWLDifferentIndividualsAxiom) {
364 int index1 = 0, index2; 364 int index1 = 0, index2;
365 for (OWLIndividual individual1: ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) { 365 for (OWLIndividual individual1: ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) {
366 ++index1; 366 ++index1;
367 index2 = 0; 367 index2 = 0;
368 for (OWLIndividual individual2: ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) { 368 for (OWLIndividual individual2: ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) {
369 if (index2++ < index1) { 369 if (index2++ < index1) {
370 manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(differentFrom, individual1, individual2)); 370 manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(differentFrom, individual1, individual2));
371 } 371 } else break;
372 else break;
373 } 372 }
374 } 373 }
375 } 374 } else
376 else
377 manager.addAxiom(tBox, axiom); 375 manager.addAxiom(tBox, axiom);
378 } 376 }
379 377
380 return flag; 378 return flag;
381 } 379 }
382 380
@@ -384,15 +382,15 @@ public class RLPlusOntology implements KnowledgeBase {
384 OWL2RLProfile profile = new OWL2RLProfile(); 382 OWL2RLProfile profile = new OWL2RLProfile();
385 OWLProfileReport report = profile.checkOntology(tBox); 383 OWLProfileReport report = profile.checkOntology(tBox);
386 Set<OWLAxiom> rlAxioms = tBox.getAxioms(); 384 Set<OWLAxiom> rlAxioms = tBox.getAxioms();
387 OWLAxiom axiom; 385 OWLAxiom axiom;
388 386
389 for (OWLProfileViolation violation: report.getViolations()) { 387 for (OWLProfileViolation violation: report.getViolations()) {
390 manager.addAxiom(restOntology, axiom = violation.getAxiom()); 388 manager.addAxiom(restOntology, axiom = violation.getAxiom());
391 rlAxioms.remove(axiom); 389 rlAxioms.remove(axiom);
392 } 390 }
393 391
394 for (Iterator<OWLAxiom> iter = rlAxioms.iterator(); iter.hasNext(); ) 392 for (Iterator<OWLAxiom> iter = rlAxioms.iterator(); iter.hasNext(); )
395 addAxiom2output(iter.next(), null); 393 addAxiom2output(iter.next(), null);
396 } 394 }
397 395
398 private void clausify() { 396 private void clausify() {
@@ -407,8 +405,6 @@ public class RLPlusOntology implements KnowledgeBase {
407 if (correspondingAxiom != null) 405 if (correspondingAxiom != null)
408 correspondence.put(axiom, correspondingAxiom); 406 correspondence.put(axiom, correspondingAxiom);
409 } 407 }
410
411 private Map<OWLClass, OWLClass> atomic2negation = new HashMap<OWLClass, OWLClass>();
412 408
413 private OWLClassExpression transform(OWLClassExpression exp, Set<OWLAxiom> addedAxioms) { 409 private OWLClassExpression transform(OWLClassExpression exp, Set<OWLAxiom> addedAxioms) {
414 if (exp instanceof OWLClass) 410 if (exp instanceof OWLClass)
diff --git a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java
index 8b73abb..fd20af1 100644
--- a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java
+++ b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java
@@ -77,7 +77,7 @@ public class QueryRecord {
77 } 77 }
78 78
79 public AnswerTuples getAnswers() { 79 public AnswerTuples getAnswers() {
80 if(processed()) 80 if(isProcessed())
81 return getLowerBoundAnswers(); 81 return getLowerBoundAnswers();
82 82
83 return getUpperBoundAnswers(); 83 return getUpperBoundAnswers();
@@ -155,7 +155,8 @@ public class QueryRecord {
155 HashSet<AnswerTuple> difference = new HashSet<>(soundAnswerTuples); 155 HashSet<AnswerTuple> difference = new HashSet<>(soundAnswerTuples);
156 difference.removeAll(namedAnswerTuples); 156 difference.removeAll(namedAnswerTuples);
157 if(!difference.isEmpty()) 157 if(!difference.isEmpty())
158 throw new IllegalArgumentException("The upper bound does not contain the lower bound!"); 158 throw new IllegalArgumentException("The upper bound does not contain the lower bound! Missing answers: " + difference
159 .size());
159 } 160 }
160 /*** END: debugging ***/ 161 /*** END: debugging ***/
161 162
@@ -192,7 +193,7 @@ public class QueryRecord {
192 processed = true; 193 processed = true;
193 } 194 }
194 195
195 public boolean processed() { 196 public boolean isProcessed() {
196 if(gapAnswerTuples != null && gapAnswerTuples.isEmpty()) processed = true; 197 if(gapAnswerTuples != null && gapAnswerTuples.isEmpty()) processed = true;
197 return processed; 198 return processed;
198 } 199 }
@@ -228,7 +229,7 @@ public class QueryRecord {
228 public void outputAnswers(BufferedWriter writer) throws IOException { 229 public void outputAnswers(BufferedWriter writer) throws IOException {
229 230
230 int answerCounter = soundAnswerTuples.size(); 231 int answerCounter = soundAnswerTuples.size();
231 if(!processed()) answerCounter += gapAnswerTuples.size(); 232 if(!isProcessed()) answerCounter += gapAnswerTuples.size();
232 233
233 Utility.logInfo("The number of answer tuples: " + answerCounter); 234 Utility.logInfo("The number of answer tuples: " + answerCounter);
234 235
@@ -254,7 +255,7 @@ public class QueryRecord {
254 writer.write(tuple.toString()); 255 writer.write(tuple.toString());
255 writer.newLine(); 256 writer.newLine();
256 } 257 }
257 if (!processed()) 258 if(!isProcessed())
258 for (AnswerTuple tuple: gapAnswerTuples) { 259 for (AnswerTuple tuple: gapAnswerTuples) {
259 writer.write("*"); 260 writer.write("*");
260 writer.write(tuple.toString()); 261 writer.write(tuple.toString());
@@ -269,7 +270,7 @@ public class QueryRecord {
269 public void outputAnswerStatistics() { 270 public void outputAnswerStatistics() {
270 271
271 int answerCounter = soundAnswerTuples.size(); 272 int answerCounter = soundAnswerTuples.size();
272 if (!processed()) answerCounter += gapAnswerTuples.size(); 273 if(!isProcessed()) answerCounter += gapAnswerTuples.size();
273 274
274 Utility.logInfo("The number of answer tuples: " + answerCounter); 275 Utility.logInfo("The number of answer tuples: " + answerCounter);
275// if (jsonAnswers != null) { 276// if (jsonAnswers != null) {
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java
index 409a2c9..ef9338a 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java
@@ -30,43 +30,42 @@ public class ConsistencyManager {
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 false; 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 true; 66 return true;
68 } 67 }
69 return true; 68 return true;
70 } 69 }
71 70
72 boolean checkUpper(BasicQueryEngine upperStore) { 71 boolean checkUpper(BasicQueryEngine upperStore) {
@@ -91,65 +90,64 @@ public class ConsistencyManager {
91 fullQueryRecord.dispose(); 90 fullQueryRecord.dispose();
92 } 91 }
93 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
94 boolean check() { 105 boolean check() {
95// if (!checkRLLowerBound()) return false; 106// if (!checkRLLowerBound()) return false;
96// if (!checkELLowerBound()) return false; 107// if (!checkELLowerBound()) return false;
97// if (checkLazyUpper()) return true; 108// if (checkLazyUpper()) return true;
98 AnswerTuples iter = null; 109 AnswerTuples iter = null;
99 110
100 try { 111 try {
101 iter = m_reasoner.trackingStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); 112 iter =
113 m_reasoner.trackingStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables());
102 fullQueryRecord.updateUpperBoundAnswers(iter); 114 fullQueryRecord.updateUpperBoundAnswers(iter);
103 } finally { 115 } finally {
104 if (iter != null) iter.dispose(); 116 if(iter != null) iter.dispose();
105 } 117 }
106 118
107 if (fullQueryRecord.getNoOfCompleteAnswers() == 0) 119 if(fullQueryRecord.getNoOfCompleteAnswers() == 0)
108 return true; 120 return true;
109 121
110 extractBottomFragment(); 122 extractBottomFragment();
111 123
112 try { 124 try {
113 extractAxioms4Full(); 125 extractAxioms4Full();
114 } catch (OWLOntologyCreationException e) { 126 } catch(OWLOntologyCreationException e) {
115 e.printStackTrace(); 127 e.printStackTrace();
116 } 128 }
117// fullQueryRecord.saveRelevantClause(); 129// fullQueryRecord.saveRelevantClause();
118 130
119 boolean satisfiability; 131 boolean satisfiability;
120 132
121 Checker checker; 133 Checker checker;
122 for (QueryRecord r: getQueryRecords()) { 134 for(QueryRecord r : getQueryRecords()) {
123 // TODO to be removed ... 135 // TODO to be removed ...
124// r.saveRelevantOntology("bottom" + r.getQueryID() + ".owl"); 136// r.saveRelevantOntology("bottom" + r.getQueryID() + ".owl");
125 checker = new HermitSummaryFilter(r, true); // m_reasoner.factory.getSummarisedReasoner(r); 137 checker = new HermitSummaryFilter(r, true); // m_reasoner.factory.getSummarisedReasoner(r);
126 satisfiability = checker.isConsistent(); 138 satisfiability = checker.isConsistent();
127 checker.dispose(); 139 checker.dispose();
128 if (!satisfiability) return false; 140 if(!satisfiability) return false;
129 } 141 }
130 142
131// Checker checker = m_reasoner.factory.getSummarisedReasoner(fullQueryRecord); 143// Checker checker = m_reasoner.factory.getSummarisedReasoner(fullQueryRecord);
132// boolean satisfiable = checker.isConsistent(); 144// boolean satisfiable = checker.isConsistent();
133// checker.dispose(); 145// checker.dispose();
134// if (!satisfiable) return unsatisfiability(t.duration()); 146// if (!satisfiable) return unsatisfiability(t.duration());
135 147
136 return true; 148 return true;
137 } 149 }
138 150
139// protected boolean unsatisfiability(double duration) {
140// fullQueryRecord.dispose();
141// Utility.logDebug("The ontology and dataset is unsatisfiable.");
142// return false;
143// }
144
145// protected boolean satisfiability(double duration) {
146// fullQueryRecord.dispose();
147// Utility.logDebug("The ontology and dataset is satisfiable.");
148// return true;
149// }
150
151 boolean fragmentExtracted = false;
152
153 public void extractBottomFragment() { 151 public void extractBottomFragment() {
154 if (fragmentExtracted) return ; 152 if (fragmentExtracted) return ;
155 fragmentExtracted = true; 153 fragmentExtracted = true;
@@ -179,7 +177,7 @@ public class ConsistencyManager {
179 int[] group = new int[number - 1]; 177 int[] group = new int[number - 1];
180 for (int i = 0; i < number - 1; ++i) group[i] = i; 178 for (int i = 0; i < number - 1; ++i) group[i] = i;
181 for (int i = 0; i < number - 1; ++i) 179 for (int i = 0; i < number - 1; ++i)
182 if (tempQueryRecords[i].processed()) tempQueryRecords[i].dispose(); 180 if(tempQueryRecords[i].isProcessed()) tempQueryRecords[i].dispose();
183 else if (group[i] == i) { 181 else if (group[i] == i) {
184 ++bottomNumber; 182 ++bottomNumber;
185 record = tempQueryRecords[i]; 183 record = tempQueryRecords[i];
@@ -193,8 +191,8 @@ public class ConsistencyManager {
193 int bottomCounter = 0; 191 int bottomCounter = 0;
194 botQueryRecords = new QueryRecord[bottomNumber]; 192 botQueryRecords = new QueryRecord[bottomNumber];
195 Variable X = Variable.create("X"); 193 Variable X = Variable.create("X");
196 for (int i = 0; i < number - 1; ++i) 194 for (int i = 0; i < number - 1; ++i)
197 if (!tempQueryRecords[i].processed()) 195 if(!tempQueryRecords[i].isProcessed())
198 if (group[i] == i) { 196 if (group[i] == i) {
199 botQueryRecords[bottomCounter] = record = tempQueryRecords[i]; 197 botQueryRecords[bottomCounter] = record = tempQueryRecords[i];
200 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);
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java
index 34742c8..c74ea58 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java
@@ -68,7 +68,7 @@ class ELHOUQueryReasoner extends QueryReasoner {
68 } 68 }
69 queryRecord.addProcessingTime(Step.UPPER_BOUND, t.duration()); 69 queryRecord.addProcessingTime(Step.UPPER_BOUND, t.duration());
70 70
71 if (queryRecord.processed()) { 71 if(queryRecord.isProcessed()) {
72 queryRecord.setDifficulty(Step.UPPER_BOUND); 72 queryRecord.setDifficulty(Step.UPPER_BOUND);
73 return; 73 return;
74 } 74 }
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 @@
1package uk.ac.ox.cs.pagoda.reasoner; 1package uk.ac.ox.cs.pagoda.reasoner;
2 2
3import java.io.File;
4
5import org.semanticweb.owlapi.model.OWLOntology; 3import org.semanticweb.owlapi.model.OWLOntology;
6
7import uk.ac.ox.cs.pagoda.constraints.BottomStrategy; 4import uk.ac.ox.cs.pagoda.constraints.BottomStrategy;
8import uk.ac.ox.cs.pagoda.constraints.UpperUnaryBottom; 5import uk.ac.ox.cs.pagoda.constraints.UpperUnaryBottom;
9import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; 6import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine;
@@ -14,6 +11,8 @@ import uk.ac.ox.cs.pagoda.rules.GeneralProgram;
14import uk.ac.ox.cs.pagoda.tracking.QueryTracker; 11import uk.ac.ox.cs.pagoda.tracking.QueryTracker;
15import uk.ac.ox.cs.pagoda.util.Utility; 12import uk.ac.ox.cs.pagoda.util.Utility;
16 13
14import java.io.File;
15
17public class IterativeRefinement { 16public 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 cc0e647..b5b9534 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
@@ -23,7 +23,6 @@ import uk.ac.ox.cs.pagoda.util.Utility;
23import uk.ac.ox.cs.pagoda.util.tuples.Tuple; 23import uk.ac.ox.cs.pagoda.util.tuples.Tuple;
24 24
25import java.util.Collection; 25import java.util.Collection;
26import java.util.HashMap;
27 26
28class MyQueryReasoner extends QueryReasoner { 27class MyQueryReasoner extends QueryReasoner {
29 28
@@ -33,7 +32,7 @@ class MyQueryReasoner extends QueryReasoner {
33// String additonalDataFile; 32// String additonalDataFile;
34 BasicQueryEngine rlLowerStore = null; 33 BasicQueryEngine rlLowerStore = null;
35 BasicQueryEngine lazyUpperStore = null; 34 BasicQueryEngine lazyUpperStore = null;
36 BasicQueryEngine limitedSkolemUpperStore; 35 // BasicQueryEngine limitedSkolemUpperStore;
37 OWLOntology elho_ontology; 36 OWLOntology elho_ontology;
38// boolean[] namedIndividuals_lazyUpper; 37// boolean[] namedIndividuals_lazyUpper;
39 KarmaQueryEngine elLowerStore = null; 38 KarmaQueryEngine elLowerStore = null;
@@ -99,7 +98,7 @@ class MyQueryReasoner extends QueryReasoner {
99 useUpperStores = multiStageTag && !program.getGeneral().isHorn(); 98 useUpperStores = multiStageTag && !program.getGeneral().isHorn();
100 if(useUpperStores) { 99 if(useUpperStores) {
101 lazyUpperStore = getUpperStore("lazy-upper-bound", true); 100 lazyUpperStore = getUpperStore("lazy-upper-bound", true);
102 limitedSkolemUpperStore = getUpperStore("limited-skolem-upper-bound", true); 101// limitedSkolemUpperStore = getUpperStore("limited-skolem-upper-bound", true);
103 } 102 }
104 103
105 importData(program.getAdditionalDataFile()); 104 importData(program.getAdditionalDataFile());
@@ -147,20 +146,20 @@ class MyQueryReasoner extends QueryReasoner {
147 Utility.logInfo("time for satisfiability checking: " + t.duration()); 146 Utility.logInfo("time for satisfiability checking: " + t.duration());
148 } 147 }
149 148
150 if(limitedSkolemUpperStore != null) { 149// if(limitedSkolemUpperStore != null) {
151 limitedSkolemUpperStore.importRDFData(name, datafile); 150// limitedSkolemUpperStore.importRDFData(name, datafile);
152 limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram); 151// limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram);
153 int tag = limitedSkolemUpperStore.materialiseSkolemly(program, null); 152// int tag = limitedSkolemUpperStore.materialiseSkolemly(program, null);
154 if(tag != 1) { 153// if(tag != 1) {
155 limitedSkolemUpperStore.dispose(); 154// limitedSkolemUpperStore.dispose();
156 limitedSkolemUpperStore = null; 155// limitedSkolemUpperStore = null;
157 } 156// }
158 if(tag == -1) return false; 157// if(tag == -1) return false;
159 } 158// }
160 if(satisfiable == SatisfiabilityStatus.UNCHECKED && consistency.checkUpper(limitedSkolemUpperStore)) { 159// if(satisfiable == SatisfiabilityStatus.UNCHECKED && consistency.checkUpper(limitedSkolemUpperStore)) {
161 satisfiable = SatisfiabilityStatus.SATISFIABLE; 160// satisfiable = SatisfiabilityStatus.SATISFIABLE;
162 Utility.logInfo("time for satisfiability checking: " + t.duration()); 161// Utility.logInfo("time for satisfiability checking: " + t.duration());
163 } 162// }
164 163
165 trackingStore.importRDFData(name, datafile); 164 trackingStore.importRDFData(name, datafile);
166 trackingStore.materialise("saturate named individuals", originalMarkProgram); 165 trackingStore.materialise("saturate named individuals", originalMarkProgram);
@@ -214,7 +213,7 @@ class MyQueryReasoner extends QueryReasoner {
214 queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); 213 queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables());
215 214
216 queryRecord.addProcessingTime(step, t.duration()); 215 queryRecord.addProcessingTime(step, t.duration());
217 if(queryRecord.processed()) { 216 if(queryRecord.isProcessed()) {
218 queryRecord.setDifficulty(step); 217 queryRecord.setDifficulty(step);
219 return true; 218 return true;
220 } 219 }
@@ -224,7 +223,7 @@ class MyQueryReasoner extends QueryReasoner {
224 /** 223 /**
225 * Returns the part of the ontology relevant for Hermit, while computing the bound answers. 224 * Returns the part of the ontology relevant for Hermit, while computing the bound answers.
226 * */ 225 * */
227 private OWLOntology relevantPart(QueryRecord queryRecord) { 226 private boolean queryBounds(QueryRecord queryRecord) {
228 AnswerTuples rlAnswer = null, elAnswer = null; 227 AnswerTuples rlAnswer = null, elAnswer = null;
229 228
230 t.reset(); 229 t.reset();
@@ -243,15 +242,15 @@ class MyQueryReasoner extends QueryReasoner {
243 242
244 Utility.logDebug("Tracking store"); 243 Utility.logDebug("Tracking store");
245 if(queryUpperStore(trackingStore, queryRecord, extendedQueryTexts, Step.SIMPLE_UPPER_BOUND)) 244 if(queryUpperStore(trackingStore, queryRecord, extendedQueryTexts, Step.SIMPLE_UPPER_BOUND))
246 return null; 245 return true;
247 246
248 if(!queryRecord.isBottom()) { 247 if(!queryRecord.isBottom()) {
249 Utility.logDebug("Lazy store"); 248 Utility.logDebug("Lazy store");
250 if(lazyUpperStore != null && queryUpperStore(lazyUpperStore, queryRecord, extendedQueryTexts, Step.LAZY_UPPER_BOUND)) 249 if(lazyUpperStore != null && queryUpperStore(lazyUpperStore, queryRecord, extendedQueryTexts, Step.LAZY_UPPER_BOUND))
251 return null; 250 return true;
252 Utility.logDebug("Skolem store"); 251// Utility.logDebug("Skolem store");
253 if(limitedSkolemUpperStore != null && queryUpperStore(limitedSkolemUpperStore, queryRecord, extendedQueryTexts, Step.L_SKOLEM_UPPER_BOUND)) 252// if(limitedSkolemUpperStore != null && queryUpperStore(limitedSkolemUpperStore, queryRecord, extendedQueryTexts, Step.L_SKOLEM_UPPER_BOUND))
254 return null; 253// return null;
255 } 254 }
256 255
257 t.reset(); 256 t.reset();
@@ -266,52 +265,23 @@ class MyQueryReasoner extends QueryReasoner {
266 } 265 }
267 queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration()); 266 queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration());
268 267
269 if (queryRecord.processed()) { 268 if(queryRecord.isProcessed()) {
270 queryRecord.setDifficulty(Step.EL_LOWER_BOUND); 269 queryRecord.setDifficulty(Step.EL_LOWER_BOUND);
271 return null; 270 return true;
272 } 271 }
273 272
273 return false;
274 }
275
276 private OWLOntology extractRelevantOntologySubset(QueryRecord queryRecord) {
274 t.reset(); 277 t.reset();
275 278
276 QueryTracker tracker = new QueryTracker(encoder, rlLowerStore, queryRecord); 279 QueryTracker tracker = new QueryTracker(encoder, rlLowerStore, queryRecord);
280 OWLOntology relevantOntologySubset = tracker.extract(trackingStore, consistency.getQueryRecords(), true);
277 281
278 OWLOntology knowledgeBase;
279 t.reset();
280// if (program.getGeneral().isHorn()) {
281// knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true);
282// queryRecord.addProcessingTime(Step.Fragment, t.duration());
283// return knowledgebase;
284// }
285// else {
286 knowledgeBase = tracker.extract(trackingStore, consistency.getQueryRecords(), true);
287 queryRecord.addProcessingTime(Step.FRAGMENT, t.duration()); 282 queryRecord.addProcessingTime(Step.FRAGMENT, t.duration());
288// }
289
290 if(knowledgeBase.isEmpty() || queryRecord.isBottom())
291 return knowledgeBase;
292
293 if(program.getGeneral().isHorn()) return knowledgeBase;
294 283
295// t.reset(); 284 return relevantOntologySubset;
296// if (queryRecord.isHorn() && lazyUpperStore != null) {
297//// knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true);
298// } else if (queryRecord.getArity() < 3) {
299// IterativeRefinement iterativeRefinement = new IterativeRefinement(queryRecord, tracker, trackingStore, consistency.getQueryRecords());
300// knowledgebase = iterativeRefinement.extractWithFullABox(importedData.toString(), program.getUpperBottomStrategy());
301// }
302//
303// queryRecord.addProcessingTime(Step.FRAGMENT_REFINEMENT, t.duration());
304//
305// if (knowledgebase == null)
306// queryRecord.setDifficulty(Step.FRAGMENT_REFINEMENT);
307
308 return knowledgeBase;
309 }
310
311 private String toJsonKeyValuePair(String key, Object value) {
312 HashMap<String, Object> map = new HashMap<>();
313 map.put(key, value);
314 return QueryRecord.GsonCreator.getInstance().toJson(map);
315 } 285 }
316 286
317 private void queryUpperBound(BasicQueryEngine upperStore, QueryRecord queryRecord, String queryText, String[] answerVariables) { 287 private void queryUpperBound(BasicQueryEngine upperStore, QueryRecord queryRecord, String queryText, String[] answerVariables) {
@@ -323,35 +293,59 @@ class MyQueryReasoner extends QueryReasoner {
323 queryRecord.updateUpperBoundAnswers(rlAnswer); 293 queryRecord.updateUpperBoundAnswers(rlAnswer);
324 } finally { 294 } finally {
325 if(rlAnswer != null) rlAnswer.dispose(); 295 if(rlAnswer != null) rlAnswer.dispose();
326 rlAnswer = null;
327 } 296 }
328 } 297 }
329 298
330// int counter = 0;
331
332 @Override 299 @Override
333 public void evaluate(QueryRecord queryRecord) { 300 public void evaluate(QueryRecord queryRecord) {
334 OWLOntology knowledgeBase = relevantPart(queryRecord); 301 if(queryBounds(queryRecord))
335
336 if(knowledgeBase == null) {
337 Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty());
338 return; 302 return;
339 }
340 303
341 int aBoxCount = knowledgeBase.getABoxAxioms(true).size(); 304 OWLOntology relevantOntologySubset = extractRelevantOntologySubset(queryRecord);
342 Utility.logDebug("ABox axioms: " + aBoxCount + " TBox axioms: " + (knowledgeBase.getAxiomCount() - aBoxCount)); 305
306 int aBoxCount = relevantOntologySubset.getABoxAxioms(true).size();
307 Utility.logInfo("Relevant ontology subset: ABox_axioms=" + aBoxCount + " TBox_axioms=" + (relevantOntologySubset
308 .getAxiomCount() - aBoxCount));
343// queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl"); 309// queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl");
344 310
311 if(querySkolemisedRelevantSubset(relevantOntologySubset, queryRecord))
312 return;
313
345 Timer t = new Timer(); 314 Timer t = new Timer();
346 Checker summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT()); 315 Checker summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT());
347// int validNumber =
348 summarisedChecker.check(queryRecord.getGapAnswers()); 316 summarisedChecker.check(queryRecord.getGapAnswers());
349 summarisedChecker.dispose(); 317 summarisedChecker.dispose();
350 Utility.logDebug("Total time for full reasoner: " + t.duration()); 318 Utility.logDebug("Total time for full reasoner: " + t.duration());
351// if (validNumber == 0) {
352 queryRecord.markAsProcessed(); 319 queryRecord.markAsProcessed();
353 Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); 320 Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty());
354// } 321 }
322
323 private boolean querySkolemisedRelevantSubset(OWLOntology relevantSubset, QueryRecord queryRecord) {
324 MultiStageQueryEngine relevantStore =
325 new MultiStageQueryEngine("Relevant-store", true); // checkValidity is true
326 DatalogProgram relevantProgram = new DatalogProgram(relevantSubset, false); // toClassify is false
327
328// relevantStore.importRDFData("data", importedData.toString()); // 2 answers more
329 relevantStore.importDataFromABoxOf(relevantSubset);
330
331 int materialisationResult = relevantStore.materialiseSkolemly(relevantProgram, null);
332 if(materialisationResult != 1)
333 throw new RuntimeException("Skolemised materialisation error"); // TODO check consistency
334// relevantStore.materialiseRestrictedly(relevantProgram, null); // it has been tried
335
336 return queryUpperStore(relevantStore, queryRecord, queryRecord.getExtendedQueryText(), Step.L_SKOLEM_UPPER_BOUND);
337
338 // the following has been tried
339// Tuple<String> extendedQueryText = queryRecord.getExtendedQueryText();
340// if(queryRecord.hasNonAnsDistinguishedVariables()) {
341// queryUpperBound(relevantStore, queryRecord, extendedQueryText.get(0), queryRecord.getAnswerVariables());
342// queryUpperBound(relevantStore, queryRecord, extendedQueryText.get(1), queryRecord.getDistinguishedVariables());
343// }
344// else
345// queryUpperBound(relevantStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables());
346//
347// return queryRecord.isProcessed();
348
355 } 349 }
356 350
357 @Override 351 @Override
@@ -375,7 +369,8 @@ class MyQueryReasoner extends QueryReasoner {
375 if (lazyUpperStore != null) lazyUpperStore.dispose(); 369 if (lazyUpperStore != null) lazyUpperStore.dispose();
376 if (elLowerStore != null) elLowerStore.dispose(); 370 if (elLowerStore != null) elLowerStore.dispose();
377 if (trackingStore != null) trackingStore.dispose(); 371 if (trackingStore != null) trackingStore.dispose();
378 if(limitedSkolemUpperStore != null) limitedSkolemUpperStore.dispose(); 372
373// if(limitedSkolemUpperStore != null) limitedSkolemUpperStore.dispose();
379 super.dispose(); 374 super.dispose();
380 } 375 }
381 376
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
index 64945e8..118c1b2 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
@@ -147,7 +147,7 @@ PagodaProperties properties;
147 if (forFacetGeneration) { 147 if (forFacetGeneration) {
148 QueryRecord record = m_queryManager.create(queryText); 148 QueryRecord record = m_queryManager.create(queryText);
149 Utility.logInfo("---------- start evaluating upper bound for Query " + record.getQueryID() + " ----------", queryText); 149 Utility.logInfo("---------- start evaluating upper bound for Query " + record.getQueryID() + " ----------", queryText);
150 if(!record.processed()) 150 if(!record.isProcessed())
151 evaluateUpper(record); 151 evaluateUpper(record);
152// AnswerTuples tuples = record.getUpperBoundAnswers(); 152// AnswerTuples tuples = record.getUpperBoundAnswers();
153// for (AnswerTuple tuple; tuples.isValid(); tuples.moveNext()) { 153// for (AnswerTuple tuple; tuples.isValid(); tuples.moveNext()) {
@@ -167,7 +167,7 @@ PagodaProperties properties;
167 public AnswerTuples evaluate(String queryText) { 167 public AnswerTuples evaluate(String queryText) {
168 QueryRecord record = m_queryManager.create(queryText); 168 QueryRecord record = m_queryManager.create(queryText);
169 Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); 169 Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText);
170 if(!record.processed()) 170 if(!record.isProcessed())
171 evaluate(record); 171 evaluate(record);
172 AnswerTuples answer = record.getAnswers(); 172 AnswerTuples answer = record.getAnswers();
173 record.dispose(); 173 record.dispose();
@@ -178,7 +178,7 @@ PagodaProperties properties;
178 public void evaluate_shell(String queryText) { 178 public void evaluate_shell(String queryText) {
179 QueryRecord record = m_queryManager.create(queryText); 179 QueryRecord record = m_queryManager.create(queryText);
180 Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); 180 Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText);
181 if(!record.processed()) 181 if(!record.isProcessed())
182 evaluate(record); 182 evaluate(record);
183 Utility.logInfo("Answers to this query: ", record.outputSoundAnswerTuple()); 183 Utility.logInfo("Answers to this query: ", record.outputSoundAnswerTuple());
184 record.dispose(); 184 record.dispose();
@@ -206,12 +206,12 @@ PagodaProperties properties;
206// if (Integer.parseInt(record.getQueryID()) != 218) continue; 206// if (Integer.parseInt(record.getQueryID()) != 218) continue;
207 Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", 207 Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------",
208 record.getQueryText()); 208 record.getQueryText());
209 if (!record.processed()) { 209 if(!record.isProcessed()) {
210 t.reset(); 210 t.reset();
211 if (!record.processed()) 211 if(!record.isProcessed())
212 evaluate(record); 212 evaluate(record);
213 Utility.logInfo("Total time to answer this query: " + t.duration()); 213 Utility.logInfo("Total time to answer this query: " + t.duration());
214 if (!fullReasoner && !record.processed()) { 214 if(!fullReasoner && !record.isProcessed()) {
215 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.");
216 continue; 216 continue;
217 } 217 }
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java
index bdef436..547140a 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java
@@ -53,8 +53,8 @@ class RLUQueryReasoner extends QueryReasoner {
53 if (ans != null) ans.dispose(); 53 if (ans != null) ans.dispose();
54 } 54 }
55 queryRecord.addProcessingTime(Step.UPPER_BOUND, t.duration()); 55 queryRecord.addProcessingTime(Step.UPPER_BOUND, t.duration());
56 56
57 if (queryRecord.processed()) 57 if(queryRecord.isProcessed())
58 queryRecord.setDifficulty(Step.UPPER_BOUND); 58 queryRecord.setDifficulty(Step.UPPER_BOUND);
59 } 59 }
60 60
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 63773d9..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,5 +1,7 @@
1package uk.ac.ox.cs.pagoda.reasoner.light; 1package uk.ac.ox.cs.pagoda.reasoner.light;
2 2
3import org.semanticweb.owlapi.model.OWLOntology;
4import org.semanticweb.owlapi.model.OWLOntologyCreationException;
3import uk.ac.ox.cs.JRDFox.JRDFStoreException; 5import uk.ac.ox.cs.JRDFox.JRDFStoreException;
4import uk.ac.ox.cs.JRDFox.Prefixes; 6import uk.ac.ox.cs.JRDFox.Prefixes;
5import uk.ac.ox.cs.JRDFox.store.DataStore; 7import uk.ac.ox.cs.JRDFox.store.DataStore;
@@ -18,32 +20,44 @@ import java.util.Collection;
18public abstract class RDFoxQueryEngine implements QueryEngine { 20public 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
22 public String getName() {
23 return name;
24 }
25
26 protected String name; 23 protected String name;
27 protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes(); 24 protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes();
28 25
29 public RDFoxQueryEngine(String name) { 26 public RDFoxQueryEngine(String name) {
30 this.name = name; 27 this.name = name;
31 } 28 }
32 29
33 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 }
34 42
35 public abstract void dispose(); 43 public String getName() {
44 return name;
45 }
36 46
47 public abstract DataStore getDataStore();
48
49 public abstract void dispose();
50
37 public void importRDFData(String fileName, String importedFile) { 51 public void importRDFData(String fileName, String importedFile) {
38 if (importedFile == null || importedFile.isEmpty()) return ; 52 if(importedFile == null || importedFile.isEmpty()) return;
39 Timer t = new Timer(); 53 Timer t = new Timer();
40 DataStore store = getDataStore(); 54 DataStore store = getDataStore();
41 try { 55 try {
42 long oldTripleCount = store.getTriplesCount(), tripleCount; 56 long oldTripleCount = store.getTriplesCount(), tripleCount;
43 for (String file: importedFile.split(QueryReasoner.ImportDataFileSeparator)) { 57 for (String file: importedFile.split(QueryReasoner.ImportDataFileSeparator)) {
44 store.importTurtleFile(new File(file), prefixes); 58 store.importTurtleFile(new File(file), prefixes);
45 } 59 }
46 tripleCount = store.getTriplesCount(); 60 tripleCount = store.getTriplesCount();
47 Utility.logDebug(name + " store after importing " + fileName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); 61 Utility.logDebug(name + " store after importing " + fileName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)");
48 store.clearRulesAndMakeFactsExplicit(); 62 store.clearRulesAndMakeFactsExplicit();
49 } catch (JRDFStoreException e) { 63 } catch (JRDFStoreException e) {
@@ -51,17 +65,32 @@ public abstract class RDFoxQueryEngine implements QueryEngine {
51 } 65 }
52 Utility.logDebug(name + " store finished importing " + fileName + " in " + t.duration() + " seconds."); 66 Utility.logDebug(name + " store finished importing " + fileName + " in " + t.duration() + " seconds.");
53 } 67 }
54 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
55 public void materialise(String programName, String programText) { 84 public void materialise(String programName, String programText) {
56 if (programText == null) return ; 85 if(programText == null) return;
57 Timer t = new Timer(); 86 Timer t = new Timer();
58 DataStore store = getDataStore(); 87 DataStore store = getDataStore();
59 try { 88 try {
60 long oldTripleCount = store.getTriplesCount(), tripleCount; 89 long oldTripleCount = store.getTriplesCount(), tripleCount;
61// store.addRules(new String[] {programText}); 90// store.addRules(new String[] {programText});
62 store.importRules(programText); 91 store.importRules(programText);
63 store.applyReasoning(); 92 store.applyReasoning();
64 tripleCount = store.getTriplesCount(); 93 tripleCount = store.getTriplesCount();
65 Utility.logDebug(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); 94 Utility.logDebug(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)");
66 store.clearRulesAndMakeFactsExplicit(); 95 store.clearRulesAndMakeFactsExplicit();
67 } catch (JRDFStoreException e) { 96 } catch (JRDFStoreException e) {
@@ -74,17 +103,17 @@ public abstract class RDFoxQueryEngine implements QueryEngine {
74 public void evaluate(Collection<String> queryTexts, String answerFile) { 103 public void evaluate(Collection<String> queryTexts, String answerFile) {
75 if (queryTexts == null) 104 if (queryTexts == null)
76 return ; 105 return ;
77 106
78 int queryID = 0; 107 int queryID = 0;
79 AnswerTuplesWriter answerWriter = new AnswerTuplesWriter(answerFile); 108 AnswerTuplesWriter answerWriter = new AnswerTuplesWriter(answerFile);
80 AnswerTuples answerTuples; 109 AnswerTuples answerTuples;
81 Timer t = new Timer(); 110 Timer t = new Timer();
82 try { 111 try {
83 for (String query: queryTexts) { 112 for (String query: queryTexts) {
84 t.reset(); 113 t.reset();
85 answerTuples = null; 114 answerTuples = null;
86 try { 115 try {
87 answerTuples = evaluate(query); 116 answerTuples = evaluate(query);
88 Utility.logDebug("time to answer Query " + ++queryID + ": " + t.duration()); 117 Utility.logDebug("time to answer Query " + ++queryID + ": " + t.duration());
89 answerWriter.write(answerTuples.getAnswerVariables(), answerTuples); 118 answerWriter.write(answerTuples.getAnswerVariables(), answerTuples);
90 } finally { 119 } finally {
@@ -94,22 +123,9 @@ public abstract class RDFoxQueryEngine implements QueryEngine {
94 } finally { 123 } finally {
95 answerWriter.close(); 124 answerWriter.close();
96 } 125 }
97 126
98 Utility.logDebug("done computing query answers by RDFox."); 127 Utility.logDebug("done computing query answers by RDFox.");
99 128
100 }
101
102 public static DataStore createDataStore() {
103 DataStore instance = null;
104 try {
105// instance = new DataStore("par-head-n");
106 instance = new DataStore(StoreType.NarrowParallelHead);
107 instance.setNumberOfThreads(matNoOfThreads);
108 instance.initialize();
109 } catch (JRDFStoreException e) {
110 e.printStackTrace();
111 }
112 return instance;
113 } 129 }
114 130
115} 131}
diff --git a/src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java b/src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java
index 663c716..90a2ed4 100644
--- a/src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java
+++ b/src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java
@@ -154,7 +154,7 @@ public class HermitSummaryFilter implements Checker {
154 154
155 m_record.removeUpperBoundAnswers(falsified); 155 m_record.removeUpperBoundAnswers(falsified);
156 156
157 if (m_record.processed()) { 157 if(m_record.isProcessed()) {
158 m_record.setDifficulty(Step.SUMMARISATION); 158 m_record.setDifficulty(Step.SUMMARISATION);
159 m_record.addProcessingTime(Step.SUMMARISATION, t.duration()); 159 m_record.addProcessingTime(Step.SUMMARISATION, t.duration());
160 return 0; 160 return 0;
diff --git a/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java b/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java
index f836212..ee55be7 100644
--- a/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java
+++ b/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java
@@ -1,24 +1,13 @@
1package uk.ac.ox.cs.pagoda.tracking; 1package uk.ac.ox.cs.pagoda.tracking;
2 2
3import java.util.HashSet;
4import java.util.Iterator;
5import java.util.LinkedList;
6import java.util.Set;
7
8import org.semanticweb.HermiT.model.DLClause; 3import org.semanticweb.HermiT.model.DLClause;
9import org.semanticweb.owlapi.model.IRI; 4import org.semanticweb.owlapi.model.*;
10import org.semanticweb.owlapi.model.OWLAxiom; 5import uk.ac.ox.cs.JRDFox.JRDFStoreException;
11import org.semanticweb.owlapi.model.OWLClass; 6import uk.ac.ox.cs.JRDFox.model.Datatype;
12import org.semanticweb.owlapi.model.OWLDataFactory; 7import uk.ac.ox.cs.JRDFox.store.DataStore;
13import org.semanticweb.owlapi.model.OWLDataProperty; 8import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType;
14import org.semanticweb.owlapi.model.OWLLiteral; 9import uk.ac.ox.cs.JRDFox.store.Resource;
15import org.semanticweb.owlapi.model.OWLIndividual; 10import uk.ac.ox.cs.JRDFox.store.TupleIterator;
16import org.semanticweb.owlapi.model.OWLObject;
17import org.semanticweb.owlapi.model.OWLObjectProperty;
18import org.semanticweb.owlapi.model.OWLOntology;
19import org.semanticweb.owlapi.model.OWLOntologyCreationException;
20import org.semanticweb.owlapi.model.OWLOntologyManager;
21
22import uk.ac.ox.cs.pagoda.MyPrefixes; 11import uk.ac.ox.cs.pagoda.MyPrefixes;
23import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; 12import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper;
24import uk.ac.ox.cs.pagoda.owl.OWLHelper; 13import uk.ac.ox.cs.pagoda.owl.OWLHelper;
@@ -30,12 +19,11 @@ import uk.ac.ox.cs.pagoda.util.Namespace;
30import uk.ac.ox.cs.pagoda.util.Timer; 19import uk.ac.ox.cs.pagoda.util.Timer;
31import uk.ac.ox.cs.pagoda.util.UFS; 20import uk.ac.ox.cs.pagoda.util.UFS;
32import uk.ac.ox.cs.pagoda.util.Utility; 21import uk.ac.ox.cs.pagoda.util.Utility;
33import uk.ac.ox.cs.JRDFox.JRDFStoreException; 22
34import uk.ac.ox.cs.JRDFox.model.Datatype; 23import java.util.HashSet;
35import uk.ac.ox.cs.JRDFox.store.DataStore; 24import java.util.Iterator;
36import uk.ac.ox.cs.JRDFox.store.Resource; 25import java.util.LinkedList;
37import uk.ac.ox.cs.JRDFox.store.TupleIterator; 26import java.util.Set;
38import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType;
39 27
40public class QueryTracker { 28public class QueryTracker {
41 29
@@ -85,7 +73,7 @@ public class QueryTracker {
85 store.applyReasoning(incrementally); 73 store.applyReasoning(incrementally);
86 tripleCount = store.getTriplesCount(); 74 tripleCount = store.getTriplesCount();
87 75
88 Utility.logDebug("tracking store after materialising tracking program: " 76 Utility.logInfo("tracking store after materialising tracking program: "
89 + tripleCount 77 + tripleCount
90 + " (" 78 + " ("
91 + (tripleCount - oldTripleCount) 79 + (tripleCount - oldTripleCount)