aboutsummaryrefslogtreecommitdiff
path: root/src/uk/ac/ox/cs/pagoda
diff options
context:
space:
mode:
authorRncLsn <rnc.lsn@gmail.com>2015-05-20 18:52:47 +0100
committerRncLsn <rnc.lsn@gmail.com>2015-05-20 18:52:47 +0100
commitd81b086fe329fa69891eba0a4b1f73e44183620d (patch)
tree7c55c80678660cdbd3dae18e94c4baf5b0680e11 /src/uk/ac/ox/cs/pagoda
parent7a68441a541b12b22587fb53072193e1130049ff (diff)
downloadACQuA-d81b086fe329fa69891eba0a4b1f73e44183620d.tar.gz
ACQuA-d81b086fe329fa69891eba0a4b1f73e44183620d.zip
Added more tests.
Querying of the upper bound is currently unstable.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda')
-rw-r--r--src/uk/ac/ox/cs/pagoda/Pagoda.java6
-rw-r--r--src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java14
-rw-r--r--src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java21
-rw-r--r--src/uk/ac/ox/cs/pagoda/query/QueryRecord.java157
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java6
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java8
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java72
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java12
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java4
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java6
-rw-r--r--src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java226
-rw-r--r--src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java126
-rw-r--r--src/uk/ac/ox/cs/pagoda/util/Properties.java66
13 files changed, 407 insertions, 317 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/Pagoda.java b/src/uk/ac/ox/cs/pagoda/Pagoda.java
index 04920c4..aeb85a7 100644
--- a/src/uk/ac/ox/cs/pagoda/Pagoda.java
+++ b/src/uk/ac/ox/cs/pagoda/Pagoda.java
@@ -2,7 +2,7 @@ package uk.ac.ox.cs.pagoda;
2 2
3import org.apache.commons.cli.*; 3import org.apache.commons.cli.*;
4import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; 4import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner;
5import uk.ac.ox.cs.pagoda.util.Properties; 5import uk.ac.ox.cs.pagoda.util.PagodaProperties;
6import uk.ac.ox.cs.pagoda.util.Timer; 6import uk.ac.ox.cs.pagoda.util.Timer;
7import uk.ac.ox.cs.pagoda.util.Utility; 7import uk.ac.ox.cs.pagoda.util.Utility;
8 8
@@ -19,13 +19,13 @@ public class Pagoda implements Runnable {
19 private static final String OPTION_ANSWER = "a"; 19 private static final String OPTION_ANSWER = "a";
20 private static final String OPTION_CLASSIFY = "c"; 20 private static final String OPTION_CLASSIFY = "c";
21 private static final String OPTION_HERMIT = "f"; 21 private static final String OPTION_HERMIT = "f";
22 private final Properties properties; 22 private final PagodaProperties properties;
23 23
24 /** 24 /**
25 * Do not use it 25 * Do not use it
26 * */ 26 * */
27 private Pagoda() { 27 private Pagoda() {
28 properties = new Properties(); 28 properties = new PagodaProperties();
29 } 29 }
30 30
31 public static void main(String... args) { 31 public static void main(String... args) {
diff --git a/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java b/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java
index 202021d..19d567a 100644
--- a/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java
+++ b/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java
@@ -1,13 +1,7 @@
1package uk.ac.ox.cs.pagoda.endomorph.plan; 1package uk.ac.ox.cs.pagoda.endomorph.plan;
2 2
3import java.util.Collection; 3import uk.ac.ox.cs.pagoda.endomorph.Clique;
4import java.util.Deque; 4import uk.ac.ox.cs.pagoda.endomorph.DependencyGraph;
5import java.util.HashSet;
6import java.util.LinkedList;
7import java.util.Map;
8import java.util.Set;
9
10import uk.ac.ox.cs.pagoda.endomorph.*;
11import uk.ac.ox.cs.pagoda.query.AnswerTuple; 5import uk.ac.ox.cs.pagoda.query.AnswerTuple;
12import uk.ac.ox.cs.pagoda.query.QueryRecord; 6import uk.ac.ox.cs.pagoda.query.QueryRecord;
13import uk.ac.ox.cs.pagoda.query.QueryRecord.Step; 7import uk.ac.ox.cs.pagoda.query.QueryRecord.Step;
@@ -16,6 +10,8 @@ import uk.ac.ox.cs.pagoda.summary.NodeTuple;
16import uk.ac.ox.cs.pagoda.util.Timer; 10import uk.ac.ox.cs.pagoda.util.Timer;
17import uk.ac.ox.cs.pagoda.util.Utility; 11import uk.ac.ox.cs.pagoda.util.Utility;
18 12
13import java.util.*;
14
19public class OpenEndPlan implements CheckPlan { 15public class OpenEndPlan implements CheckPlan {
20 16
21 public static final int TIME_OUT_MIN = 1; 17 public static final int TIME_OUT_MIN = 1;
@@ -91,7 +87,7 @@ public class OpenEndPlan implements CheckPlan {
91 } 87 }
92 88
93 m_record.addLowerBoundAnswers(validAnswers); 89 m_record.addLowerBoundAnswers(validAnswers);
94 m_record.addProcessingTime(Step.FullReasoning, t.duration()); 90 m_record.addProcessingTime(Step.FULL_REASONING, t.duration());
95 return count; 91 return count;
96 } 92 }
97 93
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java b/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java
index 84798ce..e652f66 100644
--- a/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java
+++ b/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java
@@ -8,16 +8,17 @@ import uk.ac.ox.cs.pagoda.rules.DatalogProgram;
8import uk.ac.ox.cs.pagoda.util.Utility; 8import uk.ac.ox.cs.pagoda.util.Utility;
9 9
10public abstract class StageQueryEngine extends BasicQueryEngine { 10public abstract class StageQueryEngine extends BasicQueryEngine {
11 11
12 protected boolean checkValidity; 12 protected boolean checkValidity;
13 13 Boolean validMaterialisation = null;
14
14 public StageQueryEngine(String name, boolean checkValidity) { 15 public StageQueryEngine(String name, boolean checkValidity) {
15 super(name); 16 super(name);
16 this.checkValidity = checkValidity; 17 this.checkValidity = checkValidity;
17 } 18 }
18 19
19 public abstract void materialiseFoldedly(DatalogProgram dProgram, GapByStore4ID gap); 20 public abstract void materialiseFoldedly(DatalogProgram dProgram, GapByStore4ID gap);
20 21
21 public abstract int materialiseRestrictedly(DatalogProgram dProgram, GapByStore4ID gap); 22 public abstract int materialiseRestrictedly(DatalogProgram dProgram, GapByStore4ID gap);
22 23
23 public abstract int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap); 24 public abstract int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap);
@@ -25,8 +26,6 @@ public abstract class StageQueryEngine extends BasicQueryEngine {
25 public void dispose() { 26 public void dispose() {
26 super.dispose(); 27 super.dispose();
27 } 28 }
28
29 Boolean validMaterialisation = null;
30 29
31 public boolean isValid() { 30 public boolean isValid() {
32 if (!checkValidity) return true; 31 if (!checkValidity) return true;
@@ -45,9 +44,9 @@ public abstract class StageQueryEngine extends BasicQueryEngine {
45 } 44 }
46 45
47 if (validMaterialisation) 46 if (validMaterialisation)
48 Utility.logInfo("The lazy-upper-bound store is valid."); 47 Utility.logInfo("The " + name + " store is valid.");
49 else 48 else
50 Utility.logInfo("The lazy-upper-bound store is not valid."); 49 Utility.logInfo("The " + name + " store is not valid.");
51 return validMaterialisation; 50 return validMaterialisation;
52 } 51 }
53 52
diff --git a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java
index 4998a19..1ecd867 100644
--- a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java
+++ b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java
@@ -9,6 +9,7 @@ import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxAnswerTuples;
9import uk.ac.ox.cs.pagoda.rules.GeneralProgram; 9import uk.ac.ox.cs.pagoda.rules.GeneralProgram;
10import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper; 10import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper;
11import uk.ac.ox.cs.pagoda.util.Namespace; 11import uk.ac.ox.cs.pagoda.util.Namespace;
12import uk.ac.ox.cs.pagoda.util.PagodaProperties;
12import uk.ac.ox.cs.pagoda.util.Utility; 13import uk.ac.ox.cs.pagoda.util.Utility;
13import uk.ac.ox.cs.pagoda.util.tuples.Tuple; 14import uk.ac.ox.cs.pagoda.util.tuples.Tuple;
14import uk.ac.ox.cs.pagoda.util.tuples.TupleBuilder; 15import uk.ac.ox.cs.pagoda.util.tuples.TupleBuilder;
@@ -101,7 +102,13 @@ public class QueryRecord {
101 update = true; 102 update = true;
102 } 103 }
103 } 104 }
104 Utility.logInfo("The number of answers in the lower bound: " + soundAnswerTuples.size()); 105
106 if(soundAnswerTuples.isEmpty())
107 Utility.logInfo("Lower bound answers empty");
108 else if(update)
109 Utility.logInfo("Lower bound answers updated: " + soundAnswerTuples.size());
110 else
111 Utility.logInfo("Lower bound answers unchanged");
105 112
106 return update; 113 return update;
107 } 114 }
@@ -111,69 +118,98 @@ public class QueryRecord {
111 } 118 }
112 119
113 public boolean updateUpperBoundAnswers(AnswerTuples answerTuples, boolean toCheckAux) { 120 public boolean updateUpperBoundAnswers(AnswerTuples answerTuples, boolean toCheckAux) {
114 RDFoxAnswerTuples rdfAnswerTuples; 121 if(!(answerTuples instanceof RDFoxAnswerTuples)) {
115 if(answerTuples instanceof RDFoxAnswerTuples) 122 String msg = "The upper bound must be computed by RDFox!";
116 rdfAnswerTuples = (RDFoxAnswerTuples) answerTuples; 123 Utility.logError(msg);
117 else { 124 throw new IllegalArgumentException(msg);
118 Utility.logError("The upper bound must be computed by RDFox!");
119 return false;
120 } 125 }
121 126
122 if(soundAnswerTuples.size() > 0) { 127 RDFoxAnswerTuples rdfoxAnswerTuples = (RDFoxAnswerTuples) answerTuples;
123 int number = 0;
124 for(; rdfAnswerTuples.isValid(); rdfAnswerTuples.moveNext()) {
125 ++number;
126 }
127 Utility.logInfo("The number of answers returned by an upper bound: " + number);
128 if(number == soundAnswerTuples.size()) {
129 if(gapAnswerTuples != null) gapAnswerTuples.clear();
130 else gapAnswerTuples = new HashSet<AnswerTuple>();
131 128
132 Utility.logInfo("The number of upper bound answers: " + (soundAnswerTuples.size() + gapAnswerTuples.size())); 129// if(soundAnswerTuples.size() > 0) {
133 return false; 130// int number = 0;
134 } else if(number < soundAnswerTuples.size()) 131// for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) {
135 throw new IllegalArgumentException("The upper bound answers must contain all the lower bound ones!"); 132// ++number;
136 rdfAnswerTuples.reset(); 133// }
137 } 134// Utility.logInfo("The number of answers returned by an upper bound: " + number);
135// if(number == soundAnswerTuples.size()) {
136// if(gapAnswerTuples != null) gapAnswerTuples.clear();
137// else gapAnswerTuples = new HashSet<AnswerTuple>();
138//
139// Utility.logInfo("The number of upper bound answers: " + (soundAnswerTuples.size() + gapAnswerTuples.size()));
140// return false;
141// } else if(number < soundAnswerTuples.size())
142// throw new IllegalArgumentException("The upper bound answers must contain all the lower bound ones!");
143// rdfoxAnswerTuples.reset();
144// }
138 145
139 boolean justCheck = (rdfAnswerTuples.getArity() != answerVariables[1].length); 146// boolean justCheck = (rdfoxAnswerTuples.getArity() < getDistinguishedVariables().length);
147// boolean justCheck = (rdfoxAnswerTuples.getArity() != getDistinguishedVariables().length);
148// if(justCheck) throw new Error("justCheck!");
149 boolean justCheck = false;
140 150
141 Set<AnswerTuple> tupleSet = new HashSet<AnswerTuple>(); 151 Set<AnswerTuple> candidateGapAnswerTuples = new HashSet<AnswerTuple>();
142 AnswerTuple tuple, extendedTuple; 152 AnswerTuple tuple, extendedTuple;
143 for(; rdfAnswerTuples.isValid(); rdfAnswerTuples.moveNext()) { 153 for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) {
144 extendedTuple = rdfAnswerTuples.getTuple(); 154 extendedTuple = rdfoxAnswerTuples.getTuple();
145 if(isBottom() || !extendedTuple.hasAnonymousIndividual()) { 155 if(isBottom() || !extendedTuple.hasAnonymousIndividual()) {
146 tuple = AnswerTuple.create(extendedTuple, answerVariables[0].length); 156 tuple = AnswerTuple.create(extendedTuple, getAnswerVariables().length);
147 if((!toCheckAux || !tuple.hasAuxPredicate()) && !soundAnswerTuples.contains(tuple)) { 157 if((!toCheckAux || !tuple.hasAuxPredicate()) && !soundAnswerTuples.contains(tuple)) {
148 if(!toCheckAux && justCheck) return false; 158 if(!toCheckAux && justCheck) return false;
149 // TODO check 159 // TODO check
150// tupleSet.add(extendedTuple); 160 candidateGapAnswerTuples.add(extendedTuple);
151 tupleSet.add(tuple); 161// candidateGapAnswerTuples.add(tuple);
152 } 162 }
153 } 163 }
154 } 164 }
155 165
156 if(gapAnswerTuples == null) { 166 /*** START: debugging ***/
157 gapAnswerTuples = tupleSet; 167 if(PagodaProperties.isDebuggingMode()) {
158 168 Set<AnswerTuple> projectedAnswerTuples = new HashSet<>();
159 Utility.logInfo("The number of answers in the upper bound: " + (soundAnswerTuples.size() + gapAnswerTuples.size())); 169 rdfoxAnswerTuples.reset();
160 return true; 170 for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) {
171 extendedTuple = rdfoxAnswerTuples.getTuple();
172 if(isBottom() || !extendedTuple.hasAnonymousIndividual()) {
173 tuple = AnswerTuple.create(extendedTuple, getAnswerVariables().length);
174 projectedAnswerTuples.add(tuple);
175 }
176 }
177 HashSet<AnswerTuple> difference = new HashSet<>(soundAnswerTuples);
178 difference.removeAll(projectedAnswerTuples);
179 if(!difference.isEmpty())
180 throw new IllegalArgumentException("The upper bound does not contain the lower bound!");
161 } 181 }
182 /*** END: debugging ***/
162 183
163 boolean update = false; 184 boolean update;
164 for(Iterator<AnswerTuple> iter = gapAnswerTuples.iterator(); iter.hasNext(); ) { 185 if(gapAnswerTuples == null) {
165 tuple = iter.next(); 186 gapAnswerTuples = candidateGapAnswerTuples;
166 if(!tupleSet.contains(tuple)) { 187 update = true;
167 iter.remove(); 188 } else {
168 update = true; 189 update = gapAnswerTuples.retainAll(candidateGapAnswerTuples);
169 }
170 } 190 }
171 191
172 Utility.logInfo("The number of answers in the upper bound: " + (soundAnswerTuples.size() + gapAnswerTuples.size())); 192 if(update)
193 Utility.logInfo("Upper bound answers updated: " + getNumberOfAnswers());
194 else
195 Utility.logInfo("Upper bound answers unchanged");
173 196
174 return update; 197 return update;
198
199// boolean update = false;
200// for(Iterator<AnswerTuple> iter = gapAnswerTuples.iterator(); iter.hasNext(); ) {
201// tuple = iter.next();
202// if(!candidateGapAnswerTuples.contains(tuple)) {
203// iter.remove();
204// update = true;
205// }
206// }
175 } 207 }
176 208
209 public int getNumberOfAnswers() {
210 return soundAnswerTuples.size() + gapAnswerTuples.size();
211 }
212
177 public void markAsProcessed() { 213 public void markAsProcessed() {
178 processed = true; 214 processed = true;
179 } 215 }
@@ -567,26 +603,33 @@ public class QueryRecord {
567 /** 603 /**
568 * Two <tt>QueryRecords</tt> are equal iff 604 * Two <tt>QueryRecords</tt> are equal iff
569 * they have the same <tt>queryText</tt>, 605 * they have the same <tt>queryText</tt>,
570 * <tt>soundAnswerTuples</tt> 606 * <tt>soundAnswerTuples</tt>.
571 * and <tt>gapAnswerTuples</tt>.
572 */ 607 */
573 @Override 608 @Override
574 public boolean equals(Object o) { 609 public boolean equals(Object o) {
575 if(!o.getClass().equals(getClass())) return false; 610 if(!o.getClass().equals(getClass())) return false;
576 QueryRecord that = (QueryRecord) o; 611 QueryRecord that = (QueryRecord) o;
577 return this.queryText.equals(that.queryText) 612 return this.queryText.equals(that.queryText)
578 && soundAnswerTuples.equals(that.soundAnswerTuples) 613 && soundAnswerTuples.equals(that.soundAnswerTuples);
579 && gapAnswerTuples.equals(that.gapAnswerTuples);
580 } 614 }
581 615
582 @Override 616 @Override
583 public int hashCode() { 617 public int hashCode() {
584 return Objects.hash(queryText, soundAnswerTuples, gapAnswerTuples); 618 return Objects.hash(queryText, soundAnswerTuples);
585 } 619 }
586 620
587 public enum Step { 621 public enum Step {
588 LowerBound, UpperBound, ELLowerBound, 622 LOWER_BOUND,
589 Fragment, FragmentRefinement, Summarisation, Dependency, FullReasoning 623 UPPER_BOUND,
624 SIMPLE_UPPER_BOUND,
625 LAZY_UPPER_BOUND,
626 L_SKOLEM_UPPER_BOUND,
627 EL_LOWER_BOUND,
628 FRAGMENT,
629 FRAGMENT_REFINEMENT,
630 SUMMARISATION,
631 DEPENDENCY,
632 FULL_REASONING
590 } 633 }
591 634
592 /** 635 /**
@@ -598,11 +641,11 @@ public class QueryRecord {
598 JsonObject object = new JsonObject(); 641 JsonObject object = new JsonObject();
599 object.addProperty("queryID", src.queryID); 642 object.addProperty("queryID", src.queryID);
600 object.addProperty("queryText", src.queryText); 643 object.addProperty("queryText", src.queryText);
601 object.addProperty("difficulty", src.difficulty != null ? src.difficulty.toString() : ""); 644// object.addProperty("difficulty", src.difficulty != null ? src.difficulty.toString() : "");
602 645
603 object.add("answerVariables", context.serialize(src.getAnswerVariables())); 646 object.add("answerVariables", context.serialize(src.getAnswerVariables()));
604 object.add("answers", context.serialize(src.soundAnswerTuples)); 647 object.add("answers", context.serialize(src.soundAnswerTuples));
605 object.add("gapAnswers", context.serialize(src.gapAnswerTuples)); 648// object.add("gapAnswers", context.serialize(src.gapAnswerTuples));
606 649
607 return object; 650 return object;
608 } 651 }
@@ -619,7 +662,7 @@ public class QueryRecord {
619 JsonObject object = json.getAsJsonObject(); 662 JsonObject object = json.getAsJsonObject();
620 record.queryID = object.getAsJsonPrimitive("queryID").getAsInt(); 663 record.queryID = object.getAsJsonPrimitive("queryID").getAsInt();
621 record.queryText = object.getAsJsonPrimitive("queryText").getAsString(); 664 record.queryText = object.getAsJsonPrimitive("queryText").getAsString();
622 record.difficulty = Step.valueOf(object.getAsJsonPrimitive("difficulty").getAsString()); 665// record.difficulty = Step.valueOf(object.getAsJsonPrimitive("difficulty").getAsString());
623 666
624 JsonArray answerVariablesJson = object.getAsJsonArray("answerVariables"); 667 JsonArray answerVariablesJson = object.getAsJsonArray("answerVariables");
625 record.answerVariables = new String[2][]; 668 record.answerVariables = new String[2][];
@@ -628,14 +671,14 @@ public class QueryRecord {
628 record.answerVariables[0][i] = answerVariablesJson.get(i).getAsString(); 671 record.answerVariables[0][i] = answerVariablesJson.get(i).getAsString();
629 672
630 record.soundAnswerTuples = new HashSet<>(); 673 record.soundAnswerTuples = new HashSet<>();
631 record.gapAnswerTuples = new HashSet<>(); 674// record.gapAnswerTuples = new HashSet<>();
632 Type type = new TypeToken<AnswerTuple>() { }.getType(); 675 Type type = new TypeToken<AnswerTuple>() { }.getType();
633 for (JsonElement answer : object.getAsJsonArray("answers")) { 676 for (JsonElement answer : object.getAsJsonArray("answers")) {
634 record.soundAnswerTuples.add(context.deserialize(answer, type)); 677 record.soundAnswerTuples.add(context.deserialize(answer, type));
635 } 678 }
636 for (JsonElement answer : object.getAsJsonArray("gapAnswers")) { 679// for (JsonElement answer : object.getAsJsonArray("gapAnswers")) {
637 record.soundAnswerTuples.add(context.deserialize(answer, type)); 680// record.soundAnswerTuples.add(context.deserialize(answer, type));
638 } 681// }
639 682
640 return record; 683 return record;
641 } 684 }
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java
index 2285b5f..f5a8093 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java
@@ -34,9 +34,9 @@ class ELHOQueryReasoner extends QueryReasoner {
34 } finally { 34 } finally {
35 if (elAnswer != null) elAnswer.dispose(); 35 if (elAnswer != null) elAnswer.dispose();
36 } 36 }
37 queryRecord.addProcessingTime(Step.ELLowerBound, t.duration()); 37 queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration());
38 38
39 queryRecord.setDifficulty(Step.ELLowerBound); 39 queryRecord.setDifficulty(Step.EL_LOWER_BOUND);
40 queryRecord.markAsProcessed(); 40 queryRecord.markAsProcessed();
41 } 41 }
42 42
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java
index a4fa7c3..34742c8 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java
@@ -50,7 +50,7 @@ class ELHOUQueryReasoner extends QueryReasoner {
50 } finally { 50 } finally {
51 if(rlAnswer != null) rlAnswer.dispose(); 51 if(rlAnswer != null) rlAnswer.dispose();
52 } 52 }
53 queryRecord.addProcessingTime(Step.LowerBound, t.duration()); 53 queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration());
54 54
55 String extendedQueryText = queryRecord.getExtendedQueryText().get(0); 55 String extendedQueryText = queryRecord.getExtendedQueryText().get(0);
56 String[] toQuery = queryRecord.getQueryText().equals(extendedQueryText) ? 56 String[] toQuery = queryRecord.getQueryText().equals(extendedQueryText) ?
@@ -66,10 +66,10 @@ class ELHOUQueryReasoner extends QueryReasoner {
66 } finally { 66 } finally {
67 if(rlAnswer != null) rlAnswer.dispose(); 67 if(rlAnswer != null) rlAnswer.dispose();
68 } 68 }
69 queryRecord.addProcessingTime(Step.UpperBound, t.duration()); 69 queryRecord.addProcessingTime(Step.UPPER_BOUND, t.duration());
70 70
71 if (queryRecord.processed()) { 71 if (queryRecord.processed()) {
72 queryRecord.setDifficulty(Step.UpperBound); 72 queryRecord.setDifficulty(Step.UPPER_BOUND);
73 return; 73 return;
74 } 74 }
75 } 75 }
@@ -83,7 +83,7 @@ class ELHOUQueryReasoner extends QueryReasoner {
83 } finally { 83 } finally {
84 if (elAnswer != null) elAnswer.dispose(); 84 if (elAnswer != null) elAnswer.dispose();
85 } 85 }
86 queryRecord.addProcessingTime(Step.ELLowerBound, t.duration()); 86 queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration());
87 } 87 }
88 88
89 @Override 89 @Override
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
index 6adbd37..2a49e24 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
@@ -198,26 +198,31 @@ class MyQueryReasoner extends QueryReasoner {
198 return satisfiable == SatisfiabilityStatus.SATISFIABLE; 198 return satisfiable == SatisfiabilityStatus.SATISFIABLE;
199 } 199 }
200 200
201 // TODO why the following??? 201 /**
202 private void queryUpperStore(BasicQueryEngine upperStore, QueryRecord queryRecord, Tuple<String> extendedQuery) { 202 * It deals with blanks nodes differently from variables
203 * according to SPARQL semantics for OWL2 Entailment Regime.
204 * <p>
205 * In particular variables are matched only against named individuals,
206 * and blank nodes against named and anonymous individuals.
207 */
208 private boolean queryUpperStore(BasicQueryEngine upperStore, QueryRecord queryRecord,
209 Tuple<String> extendedQuery, Step step) {
210
211 queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables());
212
213 if(queryRecord.hasNonAnsDistinguishedVariables()) {
214 if(!queryRecord.processed())
215 queryUpperBound(upperStore, queryRecord, extendedQuery.get(0), queryRecord.getAnswerVariables());
216 if(!queryRecord.processed())
217 queryUpperBound(upperStore, queryRecord, extendedQuery.get(1), queryRecord.getDistinguishedVariables());
218 }
203 219
204// Utility.logInfo("1"); 220 queryRecord.addProcessingTime(step, t.duration());
205// queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); 221 if(queryRecord.processed()) {
206// 222 queryRecord.setDifficulty(step);
207// boolean conditionA = !queryRecord.processed() && !queryRecord.getQueryText().equals(extendedQuery.get(0)); 223 return true;
208// boolean conditionB = !queryRecord.processed() && queryRecord.hasNonAnsDistinguishedVariables(); 224 }
209// 225 return false;
210// if(conditionA ^ conditionB)
211// throw new Error("It really happened! I thought it was impossible");
212//
213// if (conditionA) {
214// Utility.logInfo("2");
215 queryUpperBound(upperStore, queryRecord, extendedQuery.get(0), queryRecord.getAnswerVariables());
216// }
217// if (conditionB) {
218// Utility.logInfo("3");
219// queryUpperBound(upperStore, queryRecord, extendedQuery.get(1), queryRecord.getDistinguishedVariables());
220// }
221 } 226 }
222 227
223 /** 228 /**
@@ -234,7 +239,7 @@ class MyQueryReasoner extends QueryReasoner {
234 } finally { 239 } finally {
235 if (rlAnswer != null) rlAnswer.dispose(); 240 if (rlAnswer != null) rlAnswer.dispose();
236 } 241 }
237 queryRecord.addProcessingTime(Step.LowerBound, t.duration()); 242 queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration());
238 243
239 t.reset(); 244 t.reset();
240 245
@@ -249,17 +254,14 @@ class MyQueryReasoner extends QueryReasoner {
249// queryUpperStore(trackingStore, queryRecord, extendedQueryTexts); 254// queryUpperStore(trackingStore, queryRecord, extendedQueryTexts);
250// else { 255// else {
251 256
252 queryUpperStore(trackingStore, queryRecord, extendedQueryTexts); 257 if(queryUpperStore(trackingStore, queryRecord, extendedQueryTexts, Step.SIMPLE_UPPER_BOUND))
253 if(!(queryRecord.isBottom() || (lazyUpperStore == null && limitedSkolemUpperStore == null))) {
254 if(lazyUpperStore != null) queryUpperStore(lazyUpperStore, queryRecord, extendedQueryTexts);
255 if(limitedSkolemUpperStore != null)
256 queryUpperStore(limitedSkolemUpperStore, queryRecord, extendedQueryTexts);
257 }
258
259 queryRecord.addProcessingTime(Step.UpperBound, t.duration());
260 if (queryRecord.processed()) {
261 queryRecord.setDifficulty(Step.UpperBound);
262 return null; 258 return null;
259
260 if(!queryRecord.isBottom()) {
261 if(lazyUpperStore != null && queryUpperStore(lazyUpperStore, queryRecord, extendedQueryTexts, Step.LAZY_UPPER_BOUND))
262 return null;
263 if(limitedSkolemUpperStore != null && queryUpperStore(limitedSkolemUpperStore, queryRecord, extendedQueryTexts, Step.L_SKOLEM_UPPER_BOUND))
264 return null;
263 } 265 }
264 266
265 t.reset(); 267 t.reset();
@@ -271,10 +273,10 @@ class MyQueryReasoner extends QueryReasoner {
271 } finally { 273 } finally {
272 if (elAnswer != null) elAnswer.dispose(); 274 if (elAnswer != null) elAnswer.dispose();
273 } 275 }
274 queryRecord.addProcessingTime(Step.ELLowerBound, t.duration()); 276 queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration());
275 277
276 if (queryRecord.processed()) { 278 if (queryRecord.processed()) {
277 queryRecord.setDifficulty(Step.ELLowerBound); 279 queryRecord.setDifficulty(Step.EL_LOWER_BOUND);
278 return null; 280 return null;
279 } 281 }
280 282
@@ -291,7 +293,7 @@ class MyQueryReasoner extends QueryReasoner {
291// } 293// }
292// else { 294// else {
293 knowledgeBase = tracker.extract(trackingStore, consistency.getQueryRecords(), true); 295 knowledgeBase = tracker.extract(trackingStore, consistency.getQueryRecords(), true);
294 queryRecord.addProcessingTime(Step.Fragment, t.duration()); 296 queryRecord.addProcessingTime(Step.FRAGMENT, t.duration());
295// } 297// }
296 298
297 if(knowledgeBase.isEmpty() || queryRecord.isBottom()) 299 if(knowledgeBase.isEmpty() || queryRecord.isBottom())
@@ -307,10 +309,10 @@ class MyQueryReasoner extends QueryReasoner {
307// knowledgebase = iterativeRefinement.extractWithFullABox(importedData.toString(), program.getUpperBottomStrategy()); 309// knowledgebase = iterativeRefinement.extractWithFullABox(importedData.toString(), program.getUpperBottomStrategy());
308// } 310// }
309// 311//
310// queryRecord.addProcessingTime(Step.FragmentRefinement, t.duration()); 312// queryRecord.addProcessingTime(Step.FRAGMENT_REFINEMENT, t.duration());
311// 313//
312// if (knowledgebase == null) 314// if (knowledgebase == null)
313// queryRecord.setDifficulty(Step.FragmentRefinement); 315// queryRecord.setDifficulty(Step.FRAGMENT_REFINEMENT);
314 316
315 return knowledgeBase; 317 return knowledgeBase;
316 } 318 }
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
index d4f4596..64945e8 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
@@ -6,7 +6,7 @@ import uk.ac.ox.cs.pagoda.owl.OWLHelper;
6import uk.ac.ox.cs.pagoda.query.AnswerTuples; 6import uk.ac.ox.cs.pagoda.query.AnswerTuples;
7import uk.ac.ox.cs.pagoda.query.QueryManager; 7import uk.ac.ox.cs.pagoda.query.QueryManager;
8import uk.ac.ox.cs.pagoda.query.QueryRecord; 8import uk.ac.ox.cs.pagoda.query.QueryRecord;
9import uk.ac.ox.cs.pagoda.util.Properties; 9import uk.ac.ox.cs.pagoda.util.PagodaProperties;
10import uk.ac.ox.cs.pagoda.util.Timer; 10import uk.ac.ox.cs.pagoda.util.Timer;
11import uk.ac.ox.cs.pagoda.util.Utility; 11import uk.ac.ox.cs.pagoda.util.Utility;
12 12
@@ -26,11 +26,11 @@ public abstract class QueryReasoner {
26 public boolean fullReasoner = this instanceof MyQueryReasoner; 26 public boolean fullReasoner = this instanceof MyQueryReasoner;
27 protected StringBuilder importedData = new StringBuilder(); 27 protected StringBuilder importedData = new StringBuilder();
28// protected boolean forSemFacet = false; 28// protected boolean forSemFacet = false;
29 Properties properties; 29PagodaProperties properties;
30 BufferedWriter answerWriter = null; 30 BufferedWriter answerWriter = null;
31 private QueryManager m_queryManager = new QueryManager(); 31 private QueryManager m_queryManager = new QueryManager();
32 32
33 public static QueryReasoner getInstance(Properties p) { 33 public static QueryReasoner getInstance(PagodaProperties p) {
34 OWLOntology ontology = OWLHelper.loadOntology(p.getOntologyPath()); 34 OWLOntology ontology = OWLHelper.loadOntology(p.getOntologyPath());
35 QueryReasoner pagoda = getInstance(ontology, p); 35 QueryReasoner pagoda = getInstance(ontology, p);
36 pagoda.properties = p; 36 pagoda.properties = p;
@@ -49,11 +49,11 @@ public abstract class QueryReasoner {
49 49
50 public static QueryReasoner getInstance(OWLOntology o) { 50 public static QueryReasoner getInstance(OWLOntology o) {
51 QueryReasoner pagoda = getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES); 51 QueryReasoner pagoda = getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES);
52 pagoda.properties = new Properties(); 52 pagoda.properties = new PagodaProperties();
53 return pagoda; 53 return pagoda;
54 } 54 }
55 55
56 private static QueryReasoner getInstance(OWLOntology o, Properties p) { 56 private static QueryReasoner getInstance(OWLOntology o, PagodaProperties p) {
57 return getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES); 57 return getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES);
58 } 58 }
59 59
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java
index 60f34c6..bea5bbf 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java
@@ -31,8 +31,8 @@ class RLQueryReasoner extends QueryReasoner {
31 } finally { 31 } finally {
32 if (rlAnswer != null) rlAnswer.dispose(); 32 if (rlAnswer != null) rlAnswer.dispose();
33 } 33 }
34 queryRecord.addProcessingTime(Step.LowerBound, t.duration()); 34 queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration());
35 queryRecord.setDifficulty(Step.LowerBound); 35 queryRecord.setDifficulty(Step.LOWER_BOUND);
36 queryRecord.markAsProcessed(); 36 queryRecord.markAsProcessed();
37 } 37 }
38 38
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java
index e5564d9..bdef436 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java
@@ -41,7 +41,7 @@ class RLUQueryReasoner extends QueryReasoner {
41 } finally { 41 } finally {
42 if (ans != null) ans.dispose(); 42 if (ans != null) ans.dispose();
43 } 43 }
44 queryRecord.addProcessingTime(Step.LowerBound, t.duration()); 44 queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration());
45 45
46 ans = null; 46 ans = null;
47 t.reset(); 47 t.reset();
@@ -52,10 +52,10 @@ class RLUQueryReasoner extends QueryReasoner {
52 } finally { 52 } finally {
53 if (ans != null) ans.dispose(); 53 if (ans != null) ans.dispose();
54 } 54 }
55 queryRecord.addProcessingTime(Step.UpperBound, t.duration()); 55 queryRecord.addProcessingTime(Step.UPPER_BOUND, t.duration());
56 56
57 if (queryRecord.processed()) 57 if (queryRecord.processed())
58 queryRecord.setDifficulty(Step.UpperBound); 58 queryRecord.setDifficulty(Step.UPPER_BOUND);
59 } 59 }
60 60
61 @Override 61 @Override
diff --git a/src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java b/src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java
index a0ecce8..663c716 100644
--- a/src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java
+++ b/src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java
@@ -1,16 +1,6 @@
1package uk.ac.ox.cs.pagoda.summary; 1package uk.ac.ox.cs.pagoda.summary;
2 2
3import java.util.HashSet; 3import org.semanticweb.owlapi.model.*;
4import java.util.Set;
5
6import org.semanticweb.owlapi.model.IRI;
7import org.semanticweb.owlapi.model.OWLAxiom;
8import org.semanticweb.owlapi.model.OWLClass;
9import org.semanticweb.owlapi.model.OWLDataFactory;
10import org.semanticweb.owlapi.model.OWLOntology;
11import org.semanticweb.owlapi.model.OWLOntologyCreationException;
12import org.semanticweb.owlapi.model.OWLOntologyManager;
13
14import uk.ac.ox.cs.JRDFox.model.Individual; 4import uk.ac.ox.cs.JRDFox.model.Individual;
15import uk.ac.ox.cs.pagoda.endomorph.Endomorph; 5import uk.ac.ox.cs.pagoda.endomorph.Endomorph;
16import uk.ac.ox.cs.pagoda.owl.OWLHelper; 6import uk.ac.ox.cs.pagoda.owl.OWLHelper;
@@ -25,166 +15,166 @@ import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoder;
25import uk.ac.ox.cs.pagoda.util.Timer; 15import uk.ac.ox.cs.pagoda.util.Timer;
26import uk.ac.ox.cs.pagoda.util.Utility; 16import uk.ac.ox.cs.pagoda.util.Utility;
27 17
18import java.util.HashSet;
19import java.util.Set;
20
28public class HermitSummaryFilter implements Checker { 21public class HermitSummaryFilter implements Checker {
29 22
30 QueryRecord m_record; 23 public static final String QueryAnswerTermPrefix = TrackingRuleEncoder.QueryPredicate + "_term";
24 QueryRecord m_record;
31 Summary summary = null; 25 Summary summary = null;
32 HermitChecker summarisedHermiT = null; 26 HermitChecker summarisedHermiT = null;
33 boolean summarisedConsistency; 27 boolean summarisedConsistency;
34
35 Endomorph endomorphismChecker = null; 28 Endomorph endomorphismChecker = null;
36 29
37 public HermitSummaryFilter(QueryRecord record, boolean toCallHermiT) { 30 public HermitSummaryFilter(QueryRecord record, boolean toCallHermiT) {
38 m_record = record; 31 m_record = record;
39 HermitChecker hermitChecker = new HermitChecker(record.getRelevantOntology(), record, toCallHermiT); 32 HermitChecker hermitChecker = new HermitChecker(record.getRelevantOntology(), record, toCallHermiT);
40 endomorphismChecker = new Endomorph(record, hermitChecker); 33 endomorphismChecker = new Endomorph(record, hermitChecker);
41 hermitChecker.setDependencyGraph(endomorphismChecker.getDependencyGraph()); 34 hermitChecker.setDependencyGraph(endomorphismChecker.getDependencyGraph());
35 }
36
37 public static OWLOntology addOntologyWithQueryPreciate(OWLOntology ontology, QueryRecord record, AnswerTuples answers) {
38 OWLOntology newOntology = null;
39 OWLOntologyManager manager = ontology.getOWLOntologyManager();
40 OWLDataFactory factory = manager.getOWLDataFactory();
41 try {
42 newOntology = manager.createOntology();
43 manager.addAxioms(newOntology, ontology.getAxioms());
44
45 OWLClass[] queryClass = new OWLClass[answers.getArity()];
46 int arity = answers.getArity();
47 for(int i = 0; i < arity; ++i)
48 queryClass[i] = factory.getOWLClass(IRI.create(QueryAnswerTermPrefix + i));
49 AnswerTuple answer;
50 for(; answers.isValid(); answers.moveNext()) {
51 answer = answers.getTuple();
52 for(int i = 0; i < arity; ++i)
53 if(answer.getGroundTerm(i) instanceof Individual) {
54 String iri = ((Individual) answer.getGroundTerm(i)).getIRI();
55 if(!record.isPredicate(answer, i)) {
56 manager.addAxiom(newOntology,
57 factory.getOWLClassAssertionAxiom(
58 queryClass[i],
59 factory.getOWLNamedIndividual(IRI.create(iri))));
60 }
61 }
62 }
63 answers.reset();
64 } catch(OWLOntologyCreationException e) {
65 e.printStackTrace();
66 }
67
68 return newOntology;
69 }
70
71 public static void printRelatedABoxAxioms(OWLOntology onto, String str) {
72 if(!str.startsWith("<")) str = OWLHelper.addAngles(str);
73
74 System.out.println("Axioms in " + onto.getOntologyID().getOntologyIRI() + " related to " + str);
75
76 for(OWLAxiom axiom : onto.getABoxAxioms(true))
77 if(axiom.toString().contains(str))
78 System.out.println(axiom);
79
80 System.out.println("-----------------------------");
81 }
82
83 public static void printRelatedTBoxAxioms(OWLOntology onto, String str) {
84
85 System.out.println("Axioms in " + onto.getOntologyID().getOntologyIRI() + " related to " + str);
86
87 for(OWLAxiom axiom : onto.getTBoxAxioms(true))
88 if(axiom.toString().contains(str))
89 System.out.println(axiom);
90
91 for(OWLAxiom axiom : onto.getRBoxAxioms(true))
92 if(axiom.toString().contains(str))
93 System.out.println(axiom);
94
95 System.out.println("-----------------------------");
42 } 96 }
43 97
44 @Override 98 @Override
45 public boolean isConsistent() { 99 public boolean isConsistent() {
46 if (summary == null) 100 if (summary == null)
47 summary = new Summary(endomorphismChecker.getOntology(), endomorphismChecker.getGraph()); 101 summary = new Summary(endomorphismChecker.getOntology(), endomorphismChecker.getGraph());
48 102
49 if (summarisedHermiT == null) 103 if(summarisedHermiT == null)
50 initialiseSummarisedReasoner(); 104 initialiseSummarisedReasoner();
51 105
52 if (summarisedConsistency) return true; 106 if(summarisedConsistency) return true;
53 return endomorphismChecker.isConsistent(); 107 return endomorphismChecker.isConsistent();
54 } 108 }
55 109
56 private void initialiseSummarisedReasoner() { 110 private void initialiseSummarisedReasoner() {
57 Timer t = new Timer(); 111 Timer t = new Timer();
58 summarisedHermiT = new HermitChecker(summary.getSummary(), summary.getSummary(m_record)); 112 summarisedHermiT = new HermitChecker(summary.getSummary(), summary.getSummary(m_record));
59// summary.save("summarised_query" + m_record.getQueryID() + ".owl"); 113// summary.save("summarised_query" + m_record.getQueryID() + ".owl");
60 if (summarisedConsistency = summarisedHermiT.isConsistent()) 114 if(summarisedConsistency = summarisedHermiT.isConsistent())
61 Utility.logDebug("The summary of ABox is consistent with the TBox."); 115 Utility.logDebug("The summary of ABox is consistent with the TBox.");
62 else 116 else
63 Utility.logDebug("The summary of ABox is NOT consistent with the TBox."); 117 Utility.logDebug("The summary of ABox is NOT consistent with the TBox.");
64 m_record.addProcessingTime(Step.Summarisation, t.duration()); 118 m_record.addProcessingTime(Step.SUMMARISATION, t.duration());
65 } 119 }
66 120
67 @Override 121 @Override
68 public int check(AnswerTuples answers) { 122 public int check(AnswerTuples answers) {
69 Timer t = new Timer(); 123 Timer t = new Timer();
70 OWLOntology newOntology = addOntologyWithQueryPreciate(endomorphismChecker.getOntology(), m_record, answers); 124 OWLOntology newOntology = addOntologyWithQueryPreciate(endomorphismChecker.getOntology(), m_record, answers);
71 summary = new Summary(newOntology); 125 summary = new Summary(newOntology);
72 initialiseSummarisedReasoner(); 126 initialiseSummarisedReasoner();
73 127
74 if (summarisedConsistency) { 128 if (summarisedConsistency) {
75 Set<AnswerTuple> passed = new HashSet<AnswerTuple>(), succ = new HashSet<AnswerTuple>(); 129 Set<AnswerTuple> passed = new HashSet<AnswerTuple>(), succ = new HashSet<AnswerTuple>();
76 Set<AnswerTuple> falsified = new HashSet<AnswerTuple>(), fail = new HashSet<AnswerTuple>(); 130 Set<AnswerTuple> falsified = new HashSet<AnswerTuple>(), fail = new HashSet<AnswerTuple>();
77 131
78 int counter = 0; 132 int counter = 0;
79 AnswerTuple representative; 133 AnswerTuple representative;
80 for (AnswerTuple answer; answers.isValid(); answers.moveNext()) { 134 for (AnswerTuple answer; answers.isValid(); answers.moveNext()) {
81 ++counter; 135 ++counter;
82 answer = answers.getTuple(); 136 answer = answers.getTuple();
83 representative = summary.getSummary(answer); 137 representative = summary.getSummary(answer);
84 if (fail.contains(representative)) 138 if(fail.contains(representative))
85 falsified.add(answer); 139 falsified.add(answer);
86 else if (succ.contains(representative)) 140 else if(succ.contains(representative))
87 passed.add(answer); 141 passed.add(answer);
88 else 142 else if(summarisedHermiT.check(representative)) {
89 if (summarisedHermiT.check(representative)) {
90 succ.add(representative); 143 succ.add(representative);
91 passed.add(answer); 144 passed.add(answer);
92 } 145 }
93 else { 146 else {
94 fail.add(representative); 147 fail.add(representative);
95 falsified.add(answer); 148 falsified.add(answer);
96 } 149 }
97 } 150 }
98 answers.dispose(); 151 answers.dispose();
99 152
100 Utility.logDebug("@TIME to filter out non-answers by summarisation: " + t.duration()); 153 Utility.logDebug("@TIME to filter out non-answers by summarisation: " + t.duration());
101 154
102 m_record.removeUpperBoundAnswers(falsified); 155 m_record.removeUpperBoundAnswers(falsified);
103 156
104 if (m_record.processed()) { 157 if (m_record.processed()) {
105 m_record.setDifficulty(Step.Summarisation); 158 m_record.setDifficulty(Step.SUMMARISATION);
106 m_record.addProcessingTime(Step.Summarisation, t.duration()); 159 m_record.addProcessingTime(Step.SUMMARISATION, t.duration());
107 return 0; 160 return 0;
108 } 161 }
109 162
110 Utility.logDebug("The number of answers to be checked with HermiT: " + passed.size() + "/" + counter); 163 Utility.logDebug("The number of answers to be checked with HermiT: " + passed.size() + "/" + counter);
111 164
112 m_record.setDifficulty(Step.FullReasoning); 165 m_record.setDifficulty(Step.FULL_REASONING);
113 m_record.addProcessingTime(Step.Summarisation, t.duration()); 166 m_record.addProcessingTime(Step.SUMMARISATION, t.duration());
114 167
115 return endomorphismChecker.check(new AnswerTuplesImp(m_record.getAnswerVariables(), passed)); 168 return endomorphismChecker.check(new AnswerTuplesImp(m_record.getAnswerVariables(), passed));
116 } 169 }
117 else { 170 else {
118 m_record.addProcessingTime(Step.Summarisation, t.duration()); 171 m_record.addProcessingTime(Step.SUMMARISATION, t.duration());
119// m_record.saveRelevantOntology("fragment.owl"); 172// m_record.saveRelevantOntology("fragment.owl");
120 m_record.setDifficulty(Step.FullReasoning); 173 m_record.setDifficulty(Step.FULL_REASONING);
121 return endomorphismChecker.check(answers); 174 return endomorphismChecker.check(answers);
122 } 175 }
123 } 176 }
124 177
125 public static final String QueryAnswerTermPrefix = TrackingRuleEncoder.QueryPredicate + "_term";
126
127 public static OWLOntology addOntologyWithQueryPreciate(OWLOntology ontology, QueryRecord record, AnswerTuples answers) {
128 OWLOntology newOntology = null;
129 OWLOntologyManager manager = ontology.getOWLOntologyManager();
130 OWLDataFactory factory = manager.getOWLDataFactory();
131 try {
132 newOntology = manager.createOntology();
133 manager.addAxioms(newOntology, ontology.getAxioms());
134
135 OWLClass[] queryClass = new OWLClass[answers.getArity()];
136 int arity = answers.getArity();
137 for (int i = 0; i < arity; ++i)
138 queryClass[i] = factory.getOWLClass(IRI.create(QueryAnswerTermPrefix + i));
139 AnswerTuple answer;
140 for (; answers.isValid(); answers.moveNext()) {
141 answer = answers.getTuple();
142 for (int i = 0; i < arity; ++i)
143 if (answer.getGroundTerm(i) instanceof Individual) {
144 String iri = ((Individual) answer.getGroundTerm(i)).getIRI();
145 if (!record.isPredicate(answer, i)) {
146 manager.addAxiom(newOntology,
147 factory.getOWLClassAssertionAxiom(
148 queryClass[i],
149 factory.getOWLNamedIndividual(IRI.create(iri))));
150 }
151 }
152 }
153 answers.reset();
154 } catch (OWLOntologyCreationException e) {
155 e.printStackTrace();
156 }
157
158 return newOntology;
159 }
160
161 public static void printRelatedABoxAxioms(OWLOntology onto, String str) {
162 if (!str.startsWith("<")) str = OWLHelper.addAngles(str);
163
164 System.out.println("Axioms in " + onto.getOntologyID().getOntologyIRI() + " related to " + str);
165
166 for (OWLAxiom axiom: onto.getABoxAxioms(true))
167 if (axiom.toString().contains(str))
168 System.out.println(axiom);
169
170 System.out.println("-----------------------------");
171 }
172
173 public static void printRelatedTBoxAxioms(OWLOntology onto, String str) {
174
175 System.out.println("Axioms in " + onto.getOntologyID().getOntologyIRI() + " related to " + str);
176
177 for (OWLAxiom axiom: onto.getTBoxAxioms(true))
178 if (axiom.toString().contains(str))
179 System.out.println(axiom);
180
181 for (OWLAxiom axiom: onto.getRBoxAxioms(true))
182 if (axiom.toString().contains(str))
183 System.out.println(axiom);
184
185 System.out.println("-----------------------------");
186 }
187
188 @Override 178 @Override
189 public boolean check(AnswerTuple answer) { 179 public boolean check(AnswerTuple answer) {
190 AnswerTuple representative = summary.getSummary(answer); 180 AnswerTuple representative = summary.getSummary(answer);
diff --git a/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java b/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java
new file mode 100644
index 0000000..be6627a
--- /dev/null
+++ b/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java
@@ -0,0 +1,126 @@
1package uk.ac.ox.cs.pagoda.util;
2
3import java.io.FileInputStream;
4import java.io.IOException;
5import java.io.InputStream;
6import java.util.Properties;
7
8public class PagodaProperties {
9
10 public static final String CONFIG_FILE = "pagoda.properties";
11
12 public static final boolean DEFAULT_DEBUG = false;
13 public static boolean shellModeDefault = false;
14 private static boolean debug = DEFAULT_DEBUG;
15
16 static {
17 try(InputStream in = PagodaProperties.class.getClassLoader().getResourceAsStream(CONFIG_FILE)) {
18 Properties config = new Properties();
19 config.load(in);
20 in.close();
21 if(config.containsKey("debug")) {
22 debug = Boolean.parseBoolean(config.getProperty("debug"));
23 }
24 } catch(IOException e) {
25 e.printStackTrace();
26 }
27 }
28
29 String dataPath = null;
30 String ontologyPath;
31 String queryPath = null;
32 String answerPath = null;
33 boolean toClassify = true;
34 boolean toCallHermiT = true;
35 boolean shellMode = shellModeDefault;
36
37 public PagodaProperties(String path) {
38 java.util.Properties m_properties = new java.util.Properties();
39 InputStream inputStream = null;
40 try {
41 inputStream = new FileInputStream(path);
42 m_properties.load(inputStream);
43
44 setOntologyPath(m_properties.getProperty("ONTOLOGY"));
45 setDataPath(m_properties.getProperty("DATA"));
46 setQueryPath(m_properties.getProperty("QUERY"));
47 setAnswerPath(m_properties.getProperty("ANSWER"));
48 setToClassify(Boolean.parseBoolean(m_properties.getProperty("TO_CLASSIFY")));
49 setToCallHermiT(Boolean.parseBoolean(m_properties.getProperty("CALL_HERMIT")));
50
51 } catch (IOException e) {
52 e.printStackTrace();
53 } finally {
54 if (inputStream != null)
55 try {
56 inputStream.close();
57 } catch (IOException e) {
58 e.printStackTrace();
59 }
60 }
61 }
62
63 public PagodaProperties() {
64 }
65
66 public static boolean isDebuggingMode() {
67 return debug;
68 }
69
70 public String getDataPath() {
71 return dataPath;
72 }
73
74 public void setDataPath(String path) {
75 dataPath = path;
76 }
77
78 public String getOntologyPath() {
79 return ontologyPath;
80 }
81
82 public void setOntologyPath(String path) {
83 ontologyPath = path;
84 }
85
86 public String getQueryPath() {
87 return queryPath;
88 }
89
90 public void setQueryPath(String path) {
91 queryPath = path;
92 }
93
94 public String getAnswerPath() {
95 return answerPath;
96 }
97
98 public void setAnswerPath(String path) {
99 answerPath = path;
100 }
101
102 public boolean getToClassify() {
103 return toClassify;
104 }
105
106 public void setToClassify(boolean flag) {
107 toClassify = flag;
108 }
109
110 public boolean getToCallHermiT() {
111 return toCallHermiT;
112 }
113
114 public void setToCallHermiT(boolean flag) {
115 toCallHermiT = flag;
116 }
117
118 public boolean getShellMode() {
119 return shellMode;
120 }
121
122 public void setShellMode(boolean flag) {
123 shellMode = flag;
124 }
125
126}
diff --git a/src/uk/ac/ox/cs/pagoda/util/Properties.java b/src/uk/ac/ox/cs/pagoda/util/Properties.java
deleted file mode 100644
index 9ebebb6..0000000
--- a/src/uk/ac/ox/cs/pagoda/util/Properties.java
+++ /dev/null
@@ -1,66 +0,0 @@
1package uk.ac.ox.cs.pagoda.util;
2
3import java.io.FileInputStream;
4import java.io.IOException;
5import java.io.InputStream;
6
7public class Properties {
8
9 String dataPath = null;
10 public String getDataPath() { return dataPath; }
11 public void setDataPath(String path) { dataPath = path; }
12
13 String ontologyPath;
14 public String getOntologyPath() { return ontologyPath; }
15 public void setOntologyPath(String path) { ontologyPath = path; }
16
17 String queryPath = null;
18 public String getQueryPath() { return queryPath; }
19 public void setQueryPath(String path) { queryPath = path; }
20
21 String answerPath = null;
22 public String getAnswerPath() { return answerPath; }
23 public void setAnswerPath(String path) { answerPath = path; }
24
25 boolean toClassify = true;
26 public boolean getToClassify() { return toClassify; }
27 public void setToClassify(boolean flag) { toClassify = flag; }
28
29 boolean toCallHermiT = true;
30 public boolean getToCallHermiT() { return toCallHermiT; }
31 public void setToCallHermiT(boolean flag) { toCallHermiT = flag; }
32
33 public static boolean shellModeDefault = false;
34
35 boolean shellMode = shellModeDefault;
36 public boolean getShellMode() { return shellMode; }
37 public void setShellMode(boolean flag) { shellMode = flag; }
38
39 public Properties(String path) {
40 java.util.Properties m_properties = new java.util.Properties();
41 InputStream inputStream = null;
42 try {
43 inputStream = new FileInputStream(path);
44 m_properties.load(inputStream);
45
46 setOntologyPath(m_properties.getProperty("ONTOLOGY"));
47 setDataPath(m_properties.getProperty("DATA"));
48 setQueryPath(m_properties.getProperty("QUERY"));
49 setAnswerPath(m_properties.getProperty("ANSWER"));
50 setToClassify(Boolean.parseBoolean(m_properties.getProperty("TO_CLASSIFY")));
51 setToCallHermiT(Boolean.parseBoolean(m_properties.getProperty("CALL_HERMIT")));
52
53 } catch (IOException e) {
54 e.printStackTrace();
55 } finally {
56 if (inputStream != null)
57 try {
58 inputStream.close();
59 } catch (IOException e) {
60 e.printStackTrace();
61 }
62 }
63 }
64 public Properties() { }
65
66}