aboutsummaryrefslogtreecommitdiff
path: root/src/uk/ac/ox/cs/pagoda/query
diff options
context:
space:
mode:
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/query')
-rw-r--r--src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java5
-rw-r--r--src/uk/ac/ox/cs/pagoda/query/QueryRecord.java101
2 files changed, 48 insertions, 58 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java b/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java
index 7220533..54e4837 100644
--- a/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java
+++ b/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java
@@ -50,7 +50,10 @@ public class AnswerTuple {
50 for(int i = 0; i < arity; ++i) m_tuple[i] = sup.m_tuple[i]; 50 for(int i = 0; i < arity; ++i) m_tuple[i] = sup.m_tuple[i];
51 } 51 }
52 52
53 public static AnswerTuple create(AnswerTuple extendedTuple, int length) { 53 /**
54 * It returns the first argument if its arity equals length, a new AnswerTuple otherwise.
55 */
56 public static AnswerTuple getInstance(AnswerTuple extendedTuple, int length) {
54 if(length == extendedTuple.getArity()) return extendedTuple; 57 if(length == extendedTuple.getArity()) return extendedTuple;
55 else return new AnswerTuple(extendedTuple, length); 58 else return new AnswerTuple(extendedTuple, length);
56 } 59 }
diff --git a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java
index 1ecd867..8b73abb 100644
--- a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java
+++ b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java
@@ -22,6 +22,7 @@ public class QueryRecord {
22 22
23 public static final String botQueryText = "SELECT ?X WHERE { ?X <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Nothing> }"; 23 public static final String botQueryText = "SELECT ?X WHERE { ?X <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Nothing> }";
24 public static final String SEPARATOR = "----------------------------------------"; 24 public static final String SEPARATOR = "----------------------------------------";
25 private static final String RDF_TYPE = "a"; //"rdf:type"; //RDF.type.toString();
25 boolean processed = false; 26 boolean processed = false;
26 String stringQueryID = null; 27 String stringQueryID = null;
27 OWLOntology relevantOntology = null; 28 OWLOntology relevantOntology = null;
@@ -39,18 +40,18 @@ public class QueryRecord {
39 40
40 private QueryRecord() { 41 private QueryRecord() {
41 } 42 }
42
43 public QueryRecord(QueryManager manager, String text, int id, int subID) {
44 m_manager = manager;
45 resetInfo(text, id, subID);
46 resetTimer();
47 }
48 43
49// private boolean containsAuxPredicate(String str) { 44// private boolean containsAuxPredicate(String str) {
50// return str.contains(Namespace.PAGODA_AUX) || str.contains("_AUX") || str.contains("owl#Nothing") || 45// return str.contains(Namespace.PAGODA_AUX) || str.contains("_AUX") || str.contains("owl#Nothing") ||
51// str.contains("internal:def"); 46// str.contains("internal:def");
52// } 47// }
53 48
49 public QueryRecord(QueryManager manager, String text, int id, int subID) {
50 m_manager = manager;
51 resetInfo(text, id, subID);
52 resetTimer();
53 }
54
54 public static Collection<String> collectQueryTexts(Collection<QueryRecord> queryRecords) { 55 public static Collection<String> collectQueryTexts(Collection<QueryRecord> queryRecords) {
55 Collection<String> texts = new LinkedList<String>(); 56 Collection<String> texts = new LinkedList<String>();
56 for(QueryRecord record : queryRecords) 57 for(QueryRecord record : queryRecords)
@@ -126,56 +127,33 @@ public class QueryRecord {
126 127
127 RDFoxAnswerTuples rdfoxAnswerTuples = (RDFoxAnswerTuples) answerTuples; 128 RDFoxAnswerTuples rdfoxAnswerTuples = (RDFoxAnswerTuples) answerTuples;
128 129
129// if(soundAnswerTuples.size() > 0) {
130// int number = 0;
131// for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) {
132// ++number;
133// }
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// }
145
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;
150
151 Set<AnswerTuple> candidateGapAnswerTuples = new HashSet<AnswerTuple>(); 130 Set<AnswerTuple> candidateGapAnswerTuples = new HashSet<AnswerTuple>();
152 AnswerTuple tuple, extendedTuple; 131 AnswerTuple tuple;
153 for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) { 132 for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) {
154 extendedTuple = rdfoxAnswerTuples.getTuple(); 133 tuple = rdfoxAnswerTuples.getTuple();
155 if(isBottom() || !extendedTuple.hasAnonymousIndividual()) { 134 if(isBottom() || !tuple.hasAnonymousIndividual())
156 tuple = AnswerTuple.create(extendedTuple, getAnswerVariables().length); 135 if((!toCheckAux || !tuple.hasAuxPredicate()) && !soundAnswerTuples.contains(tuple))
157 if((!toCheckAux || !tuple.hasAuxPredicate()) && !soundAnswerTuples.contains(tuple)) { 136 candidateGapAnswerTuples.add(tuple);
158 if(!toCheckAux && justCheck) return false;
159 // TODO check
160 candidateGapAnswerTuples.add(extendedTuple);
161// candidateGapAnswerTuples.add(tuple);
162 }
163 }
164 } 137 }
165 138
166 /*** START: debugging ***/ 139 /*** START: debugging ***/
167 if(PagodaProperties.isDebuggingMode()) { 140 if(PagodaProperties.isDebuggingMode()) {
168 Set<AnswerTuple> projectedAnswerTuples = new HashSet<>(); 141 if(rdfoxAnswerTuples.getArity() != getAnswerVariables().length)
142 throw new IllegalArgumentException(
143 "The arity of answers (" + rdfoxAnswerTuples.getArity() + ") " +
144 "is different from the number of answer variables (" +
145 getAnswerVariables().length + ")");
146
147 Set<AnswerTuple> namedAnswerTuples = new HashSet<>();
169 rdfoxAnswerTuples.reset(); 148 rdfoxAnswerTuples.reset();
170 for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) { 149 for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) {
171 extendedTuple = rdfoxAnswerTuples.getTuple(); 150 tuple = rdfoxAnswerTuples.getTuple();
172 if(isBottom() || !extendedTuple.hasAnonymousIndividual()) { 151// if(isBottom() || !tuple.hasAnonymousIndividual()) {
173 tuple = AnswerTuple.create(extendedTuple, getAnswerVariables().length); 152 namedAnswerTuples.add(tuple);
174 projectedAnswerTuples.add(tuple); 153// }
175 }
176 } 154 }
177 HashSet<AnswerTuple> difference = new HashSet<>(soundAnswerTuples); 155 HashSet<AnswerTuple> difference = new HashSet<>(soundAnswerTuples);
178 difference.removeAll(projectedAnswerTuples); 156 difference.removeAll(namedAnswerTuples);
179 if(!difference.isEmpty()) 157 if(!difference.isEmpty())
180 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!");
181 } 159 }
@@ -218,7 +196,7 @@ public class QueryRecord {
218 if(gapAnswerTuples != null && gapAnswerTuples.isEmpty()) processed = true; 196 if(gapAnswerTuples != null && gapAnswerTuples.isEmpty()) processed = true;
219 return processed; 197 return processed;
220 } 198 }
221 199
222 public String[] getDistinguishedVariables() { 200 public String[] getDistinguishedVariables() {
223 return answerVariables[1]; 201 return answerVariables[1];
224 } 202 }
@@ -238,7 +216,7 @@ public class QueryRecord {
238 public String getQueryID() { 216 public String getQueryID() {
239 return stringQueryID; 217 return stringQueryID;
240 } 218 }
241 219
242 public AnswerTuples getGapAnswers() { 220 public AnswerTuples getGapAnswers() {
243 return new AnswerTuplesImp(answerVariables[0], gapAnswerTuples); 221 return new AnswerTuplesImp(answerVariables[0], gapAnswerTuples);
244 } 222 }
@@ -355,7 +333,7 @@ public class QueryRecord {
355 public void setRelevantOntology(OWLOntology knowledgebase) { 333 public void setRelevantOntology(OWLOntology knowledgebase) {
356 relevantOntology = knowledgebase; 334 relevantOntology = knowledgebase;
357 } 335 }
358 336
359 public void saveRelevantOntology(String filename) { 337 public void saveRelevantOntology(String filename) {
360 if(relevantOntology == null) return; 338 if(relevantOntology == null) return;
361 OWLOntologyManager manager = relevantOntology.getOWLOntologyManager(); 339 OWLOntologyManager manager = relevantOntology.getOWLOntologyManager();
@@ -394,7 +372,7 @@ public class QueryRecord {
394 Utility.logError("The answer (" + answer + ") cannot be added, because it is not in the upper bound."); 372 Utility.logError("The answer (" + answer + ") cannot be added, because it is not in the upper bound.");
395 gapAnswerTuples.remove(answer); 373 gapAnswerTuples.remove(answer);
396 374
397 answer = AnswerTuple.create(answer, answerVariables[0].length); 375 answer = AnswerTuple.getInstance(answer, answerVariables[0].length);
398// if (soundAnswerTuples.contains(answer)) 376// if (soundAnswerTuples.contains(answer))
399// Utility.logError("The answer (" + answer + ") cannot be added, because it is in the lower bound."); 377// Utility.logError("The answer (" + answer + ") cannot be added, because it is in the lower bound.");
400 soundAnswerTuples.add(answer); 378 soundAnswerTuples.add(answer);
@@ -412,7 +390,7 @@ public class QueryRecord {
412 public int getArity() { 390 public int getArity() {
413 return answerVariables[0].length; 391 return answerVariables[0].length;
414 } 392 }
415 393
416 public void addRelevantClauses(DLClause clause) { 394 public void addRelevantClauses(DLClause clause) {
417 relevantClauses.add(clause); 395 relevantClauses.add(clause);
418 } 396 }
@@ -477,10 +455,10 @@ public class QueryRecord {
477 } 455 }
478 456
479 public void updateSubID() { 457 public void updateSubID() {
480 ++subID; 458 ++subID;
481 stringQueryID = String.valueOf(queryID) + "_" + subID; 459 stringQueryID = String.valueOf(queryID) + "_" + subID;
482 } 460 }
483 461
484 public DLClause getClause() { 462 public DLClause getClause() {
485 if (queryClause != null) 463 if (queryClause != null)
486 return queryClause; 464 return queryClause;
@@ -498,7 +476,7 @@ public class QueryRecord {
498 public int getSubID() { 476 public int getSubID() {
499 return subID; 477 return subID;
500 } 478 }
501 479
502 public boolean hasSameGapAnswers(QueryRecord that) { 480 public boolean hasSameGapAnswers(QueryRecord that) {
503 return gapAnswerTuples.containsAll(that.gapAnswerTuples) && that.gapAnswerTuples.containsAll(gapAnswerTuples); 481 return gapAnswerTuples.containsAll(that.gapAnswerTuples) && that.gapAnswerTuples.containsAll(gapAnswerTuples);
504 } 482 }
@@ -539,8 +517,9 @@ public class QueryRecord {
539 return false; 517 return false;
540 } 518 }
541 519
520 // TODO remove fully extended query
542 public Tuple<String> getExtendedQueryText() { 521 public Tuple<String> getExtendedQueryText() {
543// String[] ret = new String[2]; 522// String[] ret = new String[2];s
544 int index = queryText.toUpperCase().indexOf(" WHERE"); 523 int index = queryText.toUpperCase().indexOf(" WHERE");
545 String extendedSelect = queryText.substring(0, index); 524 String extendedSelect = queryText.substring(0, index);
546 String extendedWhere= queryText.substring(index + 1), fullyExtendedWhere = queryText.substring(index + 1); 525 String extendedWhere= queryText.substring(index + 1), fullyExtendedWhere = queryText.substring(index + 1);
@@ -564,10 +543,18 @@ public class QueryRecord {
564// if (answerVariables[0] != answerVariables[1]) { 543// if (answerVariables[0] != answerVariables[1]) {
565 for (int i = answerVariables[0].length; i < answerVariables[1].length; ++i) { 544 for (int i = answerVariables[0].length; i < answerVariables[1].length; ++i) {
566// for (int i = 0; i < answerVariables[1].length; ++i) { 545// for (int i = 0; i < answerVariables[1].length; ++i) {
567 fullyExtra.append(" . ?").append(answerVariables[1][i]).append(" a <").append(Namespace.PAGODA_ORIGINAL).append(">"); 546 fullyExtra.append(" . ?")
547 .append(answerVariables[1][i])
548 .append(" " + RDF_TYPE + " <")
549 .append(Namespace.PAGODA_ORIGINAL)
550 .append(">");
568 if ((list = links.get(answerVariables[1][i])) == null || list.size() < 2) ; 551 if ((list = links.get(answerVariables[1][i])) == null || list.size() < 2) ;
569 else { 552 else {
570 extra.append(" . ?").append(answerVariables[1][i]).append(" a <").append(Namespace.PAGODA_ORIGINAL).append(">"); 553 extra.append(" . ?")
554 .append(answerVariables[1][i])
555 .append(" " + RDF_TYPE + " <")
556 .append(Namespace.PAGODA_ORIGINAL)
557 .append(">");
571 } 558 }
572 } 559 }
573 560