diff options
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java | 165 |
1 files changed, 85 insertions, 80 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java b/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java index d2d041f..27d3a53 100644 --- a/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java +++ b/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java | |||
| @@ -73,7 +73,7 @@ public class QueryTracker { | |||
| 73 | store.applyReasoning(incrementally); | 73 | store.applyReasoning(incrementally); |
| 74 | tripleCount = store.getTriplesCount(); | 74 | tripleCount = store.getTriplesCount(); |
| 75 | 75 | ||
| 76 | Utility.logInfo("tracking store after materialising tracking program: " | 76 | Utility.logDebug("tracking store after materialising tracking program: " |
| 77 | + tripleCount | 77 | + tripleCount |
| 78 | + " (" | 78 | + " (" |
| 79 | + (tripleCount - oldTripleCount) | 79 | + (tripleCount - oldTripleCount) |
| @@ -149,28 +149,47 @@ public class QueryTracker { | |||
| 149 | 149 | ||
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | public void addRelatedAxiomsAndClauses(QueryRecord[] botQueryRecords) { | ||
| 153 | LinkedList<QueryRecord> toAddedRecords = new LinkedList<QueryRecord>(); | ||
| 154 | |||
| 155 | for(QueryRecord botQueryRecord : botQueryRecords) | ||
| 156 | if(overlappingDisjunctiveClauses(botQueryRecord) != null) | ||
| 157 | toAddedRecords.add(botQueryRecord); | ||
| 158 | |||
| 159 | for(QueryRecord botQueryRecord : toAddedRecords) { | ||
| 160 | m_manager.addAxioms(m_record.getRelevantOntology(), botQueryRecord.getRelevantOntology().getAxioms()); | ||
| 161 | for(DLClause clause : botQueryRecord.getRelevantClauses()) | ||
| 162 | m_record.addRelevantClauses(clause); | ||
| 163 | } | ||
| 164 | |||
| 165 | if(!toAddedRecords.isEmpty()) | ||
| 166 | Utility.logDebug("Part of bottom fragments is added for this query."); | ||
| 167 | else | ||
| 168 | Utility.logDebug("None of bottom fragments is added for this query."); | ||
| 169 | } | ||
| 170 | |||
| 152 | private int extractBinaryTuples(BasicQueryEngine trackingStore, OWLDataFactory factory, Set<String> binaryPredicates) { | 171 | private int extractBinaryTuples(BasicQueryEngine trackingStore, OWLDataFactory factory, Set<String> binaryPredicates) { |
| 153 | OWLOntology fragment = m_record.getRelevantOntology(); | 172 | OWLOntology fragment = m_record.getRelevantOntology(); |
| 154 | int count; | 173 | int count; |
| 155 | int aboxAxiomCounter = 0; | 174 | int aboxAxiomCounter = 0; |
| 156 | Resource sub, obj; | 175 | Resource sub, obj; |
| 157 | OWLAxiom aboxAxiom; | 176 | OWLAxiom aboxAxiom; |
| 158 | String trackingIRI; | 177 | String trackingIRI; |
| 159 | Set<Integer> trackedIDEqualities = new HashSet<Integer>(); | 178 | Set<Integer> trackedIDEqualities = new HashSet<Integer>(); |
| 160 | Set<String> trackedEntityEqualities = new HashSet<String>(); | 179 | Set<String> trackedEntityEqualities = new HashSet<String>(); |
| 161 | TupleIterator trackingAnswers, lowerAnswers; | 180 | TupleIterator trackingAnswers, lowerAnswers; |
| 162 | 181 | ||
| 163 | for (Iterator<String> iter = binaryPredicates.iterator(); iter.hasNext(); ) { | 182 | for (Iterator<String> iter = binaryPredicates.iterator(); iter.hasNext(); ) { |
| 164 | trackingIRI = iter.next(); | 183 | trackingIRI = iter.next(); |
| 165 | String propIRI = m_encoder.getOriginalPredicate(trackingIRI); | 184 | String propIRI = m_encoder.getOriginalPredicate(trackingIRI); |
| 166 | if (propIRI == null) continue; | 185 | if(propIRI == null) continue; |
| 167 | if (!propIRI.equals(Namespace.EQUALITY_QUOTED)) continue; | 186 | if (!propIRI.equals(Namespace.EQUALITY_QUOTED)) continue; |
| 168 | trackingAnswers = null; | 187 | trackingAnswers = null; |
| 169 | try { | 188 | try { |
| 170 | trackingAnswers = trackingStore.internal_evaluateAgainstIDBs(getSPARQLQuery4Binary(trackingIRI)); | 189 | trackingAnswers = trackingStore.internal_evaluateAgainstIDBs(getSPARQLQuery4Binary(trackingIRI)); |
| 171 | for (long multi = trackingAnswers.open(); multi != 0; multi = trackingAnswers.getNext()) { | 190 | for (long multi = trackingAnswers.open(); multi != 0; multi = trackingAnswers.getNext()) { |
| 172 | if (trackingAnswers.getResourceID(0) != trackingAnswers.getResourceID(1)) { | 191 | if (trackingAnswers.getResourceID(0) != trackingAnswers.getResourceID(1)) { |
| 173 | for (int i = 0; i < 2; ++i) | 192 | for(int i = 0; i < 2; ++i) |
| 174 | if (trackedIDEqualities.add(trackingAnswers.getResourceID(i))) { | 193 | if (trackedIDEqualities.add(trackingAnswers.getResourceID(i))) { |
| 175 | trackedEntityEqualities.add(trackingAnswers.getResource(i).m_lexicalForm); | 194 | trackedEntityEqualities.add(trackingAnswers.getResource(i).m_lexicalForm); |
| 176 | } | 195 | } |
| @@ -179,71 +198,74 @@ public class QueryTracker { | |||
| 179 | } catch (JRDFStoreException e) { | 198 | } catch (JRDFStoreException e) { |
| 180 | e.printStackTrace(); | 199 | e.printStackTrace(); |
| 181 | } finally { | 200 | } finally { |
| 182 | if (trackingAnswers != null) trackingAnswers.dispose(); | 201 | if(trackingAnswers != null) trackingAnswers.dispose(); |
| 183 | } | 202 | } |
| 184 | iter.remove(); | 203 | iter.remove(); |
| 185 | break; | 204 | break; |
| 186 | } | 205 | } |
| 187 | 206 | ||
| 188 | String sub_rep, obj_rep; | 207 | String sub_rep, obj_rep; |
| 189 | 208 | ||
| 190 | for (Iterator<String> iter = binaryPredicates.iterator(); iter.hasNext(); ) { | 209 | for (Iterator<String> iter = binaryPredicates.iterator(); iter.hasNext(); ) { |
| 191 | trackingIRI = iter.next(); | 210 | trackingIRI = iter.next(); |
| 192 | count = 0; | 211 | count = 0; |
| 193 | String propIRI = m_encoder.getOriginalPredicate(trackingIRI); | 212 | String propIRI = m_encoder.getOriginalPredicate(trackingIRI); |
| 194 | if (propIRI == null) continue; | 213 | if(propIRI == null) continue; |
| 195 | iter.remove(); | 214 | iter.remove(); |
| 196 | lowerAnswers = null; trackingAnswers = null; | 215 | lowerAnswers = null; |
| 216 | trackingAnswers = null; | ||
| 197 | Set<String> lower = new HashSet<String>(); | 217 | Set<String> lower = new HashSet<String>(); |
| 198 | OWLObject prop = null; | 218 | OWLObject prop = null; |
| 199 | try { | 219 | try { |
| 200 | trackingAnswers = trackingStore.internal_evaluateAgainstIDBs(getSPARQLQuery4Binary(trackingIRI)); | 220 | trackingAnswers = trackingStore.internal_evaluateAgainstIDBs(getSPARQLQuery4Binary(trackingIRI)); |
| 201 | trackingAnswers.open(); | 221 | trackingAnswers.open(); |
| 202 | if (trackingAnswers.getMultiplicity() == 0) continue; | 222 | if(trackingAnswers.getMultiplicity() == 0) continue; |
| 203 | 223 | ||
| 204 | lowerAnswers = m_dataStore.internal_evaluateNotExpanded(getSPARQLQuery4Binary(propIRI)); | 224 | lowerAnswers = m_dataStore.internal_evaluateNotExpanded(getSPARQLQuery4Binary(propIRI)); |
| 205 | lowerAnswers.open(); | 225 | lowerAnswers.open(); |
| 206 | if (lowerAnswers.getMultiplicity() == 0) continue; | 226 | if(lowerAnswers.getMultiplicity() == 0) continue; |
| 207 | 227 | ||
| 208 | StringBuilder builder = new StringBuilder(); | 228 | StringBuilder builder = new StringBuilder(); |
| 209 | for (long multi = lowerAnswers.getMultiplicity(); multi != 0; multi = lowerAnswers.getNext()) { | 229 | for (long multi = lowerAnswers.getMultiplicity(); multi != 0; multi = lowerAnswers.getNext()) { |
| 210 | sub = lowerAnswers.getResource(0); | 230 | sub = lowerAnswers.getResource(0); |
| 211 | obj = lowerAnswers.getResource(1); | 231 | obj = lowerAnswers.getResource(1); |
| 212 | builder.setLength(0); | 232 | builder.setLength(0); |
| 213 | builder.append(equalityGroups.find(sub.m_lexicalForm)).append(AnswerTuple.SEPARATOR).append(equalityGroups.find(obj.m_lexicalForm)); | 233 | builder.append(equalityGroups.find(sub.m_lexicalForm)) |
| 234 | .append(AnswerTuple.SEPARATOR) | ||
| 235 | .append(equalityGroups.find(obj.m_lexicalForm)); | ||
| 214 | lower.add(builder.toString()); | 236 | lower.add(builder.toString()); |
| 215 | } | 237 | } |
| 216 | 238 | ||
| 217 | for (long multi = trackingAnswers.getMultiplicity(); multi != 0; multi = trackingAnswers.getNext()) { | 239 | for (long multi = trackingAnswers.getMultiplicity(); multi != 0; multi = trackingAnswers.getNext()) { |
| 218 | sub = trackingAnswers.getResource(0); | 240 | sub = trackingAnswers.getResource(0); |
| 219 | obj = trackingAnswers.getResource(1); | 241 | obj = trackingAnswers.getResource(1); |
| 220 | builder.setLength(0); | 242 | builder.setLength(0); |
| 221 | sub_rep = equalityGroups.find(sub.m_lexicalForm); | 243 | sub_rep = equalityGroups.find(sub.m_lexicalForm); |
| 222 | obj_rep = equalityGroups.find(obj.m_lexicalForm); | 244 | obj_rep = equalityGroups.find(obj.m_lexicalForm); |
| 223 | if (!sub_rep.equals(sub.m_lexicalForm) || !obj_rep.equals(obj.m_lexicalForm)) continue; | 245 | if (!sub_rep.equals(sub.m_lexicalForm) || !obj_rep.equals(obj.m_lexicalForm)) continue; |
| 224 | 246 | ||
| 225 | builder.append(sub_rep).append(AnswerTuple.SEPARATOR).append(obj_rep); | 247 | builder.append(sub_rep).append(AnswerTuple.SEPARATOR).append(obj_rep); |
| 226 | if (lower.contains(builder.toString())) { | 248 | if (lower.contains(builder.toString())) { |
| 227 | OWLObject owlObj = getOWLObject(obj, factory); | 249 | OWLObject owlObj = getOWLObject(obj, factory); |
| 228 | if (owlObj instanceof OWLIndividual) { | 250 | if (owlObj instanceof OWLIndividual) { |
| 229 | if (prop == null) | 251 | if (prop == null) |
| 230 | prop = factory.getOWLObjectProperty(IRI.create(propIRI.startsWith("<") ? OWLHelper.removeAngles(propIRI) : propIRI)); | 252 | prop = factory.getOWLObjectProperty(IRI.create(propIRI.startsWith("<") ? OWLHelper.removeAngles(propIRI) : propIRI)); |
| 231 | aboxAxiom = factory.getOWLObjectPropertyAssertionAxiom( | 253 | aboxAxiom = factory.getOWLObjectPropertyAssertionAxiom( |
| 232 | (OWLObjectProperty) prop, | 254 | (OWLObjectProperty) prop, |
| 233 | factory.getOWLNamedIndividual(IRI.create(sub_rep)), | 255 | factory.getOWLNamedIndividual(IRI.create(sub_rep)), |
| 234 | factory.getOWLNamedIndividual(IRI.create(obj_rep))); | 256 | factory.getOWLNamedIndividual(IRI.create(obj_rep))); |
| 235 | } | 257 | } |
| 236 | else if (owlObj instanceof OWLLiteral) { | 258 | else if (owlObj instanceof OWLLiteral) { |
| 237 | if (prop == null) | 259 | if (prop == null) |
| 238 | prop = factory.getOWLDataProperty(IRI.create(propIRI.startsWith("<") ? OWLHelper.removeAngles(propIRI) : propIRI)); | 260 | prop = factory.getOWLDataProperty(IRI.create(propIRI.startsWith("<") ? OWLHelper.removeAngles(propIRI) : propIRI)); |
| 239 | aboxAxiom = factory.getOWLDataPropertyAssertionAxiom( | 261 | aboxAxiom = factory.getOWLDataPropertyAssertionAxiom( |
| 240 | (OWLDataProperty) prop, | 262 | (OWLDataProperty) prop, |
| 241 | factory.getOWLNamedIndividual(IRI.create(sub_rep)), | 263 | factory.getOWLNamedIndividual(IRI.create(sub_rep)), |
| 242 | (OWLLiteral) owlObj); | 264 | (OWLLiteral) owlObj); |
| 243 | } | 265 | } |
| 244 | else { | 266 | else { |
| 245 | Utility.logError("There might be an error here ... "); | 267 | Utility.logError("There might be an error here ... "); |
| 246 | continue; | 268 | continue; |
| 247 | } | 269 | } |
| 248 | if (!fragment.containsAxiom(aboxAxiom)) { | 270 | if (!fragment.containsAxiom(aboxAxiom)) { |
| 249 | m_manager.addAxiom(fragment, aboxAxiom); | 271 | m_manager.addAxiom(fragment, aboxAxiom); |
| @@ -259,30 +281,30 @@ public class QueryTracker { | |||
| 259 | if (lowerAnswers != null) lowerAnswers.dispose(); | 281 | if (lowerAnswers != null) lowerAnswers.dispose(); |
| 260 | lower.clear(); | 282 | lower.clear(); |
| 261 | } | 283 | } |
| 262 | Utility.logDebug("property: " + propIRI + " " + count); | 284 | Utility.logDebug("property: " + propIRI + " " + count); |
| 263 | } | 285 | } |
| 264 | 286 | ||
| 265 | count = 0; | 287 | count = 0; |
| 266 | String value; | 288 | String value; |
| 267 | OWLObjectProperty sameAs = factory.getOWLObjectProperty(IRI.create(Namespace.EQUALITY)); | 289 | OWLObjectProperty sameAs = factory.getOWLObjectProperty(IRI.create(Namespace.EQUALITY)); |
| 268 | for (String key: equalityGroups.keySet()) { | 290 | for (String key: equalityGroups.keySet()) { |
| 269 | if (!trackedEntityEqualities.contains(key)) continue; | 291 | if(!trackedEntityEqualities.contains(key)) continue; |
| 270 | value = equalityGroups.find(key); | 292 | value = equalityGroups.find(key); |
| 271 | m_manager.addAxiom(fragment, factory.getOWLObjectPropertyAssertionAxiom( | 293 | m_manager.addAxiom(fragment, factory.getOWLObjectPropertyAssertionAxiom( |
| 272 | sameAs, | 294 | sameAs, |
| 273 | factory.getOWLNamedIndividual(IRI.create(key)), | 295 | factory.getOWLNamedIndividual(IRI.create(key)), |
| 274 | factory.getOWLNamedIndividual(IRI.create(value)))); | 296 | factory.getOWLNamedIndividual(IRI.create(value)))); |
| 275 | ++aboxAxiomCounter; | 297 | ++aboxAxiomCounter; |
| 276 | ++count; | 298 | ++count; |
| 277 | } | 299 | } |
| 278 | Utility.logDebug("property: " + Namespace.EQUALITY_QUOTED + " " + count); | 300 | Utility.logDebug("property: " + Namespace.EQUALITY_QUOTED + " " + count); |
| 279 | 301 | ||
| 280 | trackedEntityEqualities.clear(); | 302 | trackedEntityEqualities.clear(); |
| 281 | trackedIDEqualities.clear(); | 303 | trackedIDEqualities.clear(); |
| 282 | Utility.logTrace(Namespace.EQUALITY_QUOTED + " " + count); | 304 | Utility.logTrace(Namespace.EQUALITY_QUOTED + " " + count); |
| 283 | 305 | ||
| 284 | Utility.logDebug("ABox extraction Done"); | 306 | Utility.logDebug("ABox extraction Done"); |
| 285 | return aboxAxiomCounter; | 307 | return aboxAxiomCounter; |
| 286 | } | 308 | } |
| 287 | 309 | ||
| 288 | private OWLObject getOWLObject(Resource rdfoxTerm, OWLDataFactory factory) { | 310 | private OWLObject getOWLObject(Resource rdfoxTerm, OWLDataFactory factory) { |
| @@ -298,15 +320,17 @@ public class QueryTracker { | |||
| 298 | // rdfoxTerm.m_datatype.equals(Datatype.XSD_UNSIGNED_BYTE)) | 320 | // rdfoxTerm.m_datatype.equals(Datatype.XSD_UNSIGNED_BYTE)) |
| 299 | if (rdfoxTerm.m_datatype.equals(Datatype.XSD_DATE)) | 321 | if (rdfoxTerm.m_datatype.equals(Datatype.XSD_DATE)) |
| 300 | return factory.getOWLLiteral(rdfoxTerm.m_lexicalForm, factory.getOWLDatatype(IRI.create(Namespace.XSD_STRING))); | 322 | return factory.getOWLLiteral(rdfoxTerm.m_lexicalForm, factory.getOWLDatatype(IRI.create(Namespace.XSD_STRING))); |
| 301 | 323 | ||
| 302 | else return factory.getOWLLiteral(rdfoxTerm.m_lexicalForm, factory.getOWLDatatype(IRI.create(rdfoxTerm.m_datatype.getIRI()))); | 324 | else |
| 325 | return factory.getOWLLiteral(rdfoxTerm.m_lexicalForm, factory.getOWLDatatype(IRI.create(rdfoxTerm.m_datatype | ||
| 326 | .getIRI()))); | ||
| 303 | } | 327 | } |
| 304 | 328 | ||
| 305 | private int extractUnaryTuples(BasicQueryEngine trackingStore, OWLDataFactory factory, Set<String> unaryPredicates) { | 329 | private int extractUnaryTuples(BasicQueryEngine trackingStore, OWLDataFactory factory, Set<String> unaryPredicates) { |
| 306 | OWLOntology fragment = m_record.getRelevantOntology(); | 330 | OWLOntology fragment = m_record.getRelevantOntology(); |
| 307 | int count; | 331 | int count; |
| 308 | int aboxAxiomCounter = 0; | 332 | int aboxAxiomCounter = 0; |
| 309 | String answer; | 333 | String answer; |
| 310 | OWLAxiom aboxAxiom; | 334 | OWLAxiom aboxAxiom; |
| 311 | for (String trackingIRI : unaryPredicates) { | 335 | for (String trackingIRI : unaryPredicates) { |
| 312 | count = 0; | 336 | count = 0; |
| @@ -319,12 +343,12 @@ public class QueryTracker { | |||
| 319 | try { | 343 | try { |
| 320 | answers = trackingStore.internal_evaluateAgainstIDBs(getSPARQLQuery4Unary(trackingIRI)); | 344 | answers = trackingStore.internal_evaluateAgainstIDBs(getSPARQLQuery4Unary(trackingIRI)); |
| 321 | answers.open(); | 345 | answers.open(); |
| 322 | if (answers.getMultiplicity() == 0) continue; | 346 | if(answers.getMultiplicity() == 0) continue; |
| 323 | 347 | ||
| 324 | lowerAnswers = m_dataStore.internal_evaluateNotExpanded(getSPARQLQuery4Unary(clsIRI)); | 348 | lowerAnswers = m_dataStore.internal_evaluateNotExpanded(getSPARQLQuery4Unary(clsIRI)); |
| 325 | lowerAnswers.open(); | 349 | lowerAnswers.open(); |
| 326 | if (lowerAnswers.getMultiplicity() == 0) continue; | 350 | if (lowerAnswers.getMultiplicity() == 0) continue; |
| 327 | 351 | ||
| 328 | for (long multi = lowerAnswers.getMultiplicity(); multi != 0; multi = lowerAnswers.getNext()) | 352 | for (long multi = lowerAnswers.getMultiplicity(); multi != 0; multi = lowerAnswers.getNext()) |
| 329 | lower.add(equalityGroups.find(lowerAnswers.getResource(0).m_lexicalForm)); | 353 | lower.add(equalityGroups.find(lowerAnswers.getResource(0).m_lexicalForm)); |
| 330 | 354 | ||
| @@ -386,25 +410,6 @@ public class QueryTracker { | |||
| 386 | } | 410 | } |
| 387 | } | 411 | } |
| 388 | 412 | ||
| 389 | public void addRelatedAxiomsAndClauses(QueryRecord[] botQueryRecords) { | ||
| 390 | LinkedList<QueryRecord> toAddedRecords = new LinkedList<QueryRecord>(); | ||
| 391 | |||
| 392 | for (QueryRecord botQueryRecord : botQueryRecords) | ||
| 393 | if (overlappingDisjunctiveClauses(botQueryRecord) != null) | ||
| 394 | toAddedRecords.add(botQueryRecord); | ||
| 395 | |||
| 396 | for (QueryRecord botQueryRecord : toAddedRecords) { | ||
| 397 | m_manager.addAxioms(m_record.getRelevantOntology(), botQueryRecord.getRelevantOntology().getAxioms()); | ||
| 398 | for (DLClause clause : botQueryRecord.getRelevantClauses()) | ||
| 399 | m_record.addRelevantClauses(clause); | ||
| 400 | } | ||
| 401 | |||
| 402 | if (!toAddedRecords.isEmpty()) | ||
| 403 | Utility.logDebug("Part of bottom fragments is added for this query."); | ||
| 404 | else | ||
| 405 | Utility.logDebug("None of bottom fragments is added for this query."); | ||
| 406 | } | ||
| 407 | |||
| 408 | private Set<DLClause> overlappingDisjunctiveClauses( | 413 | private Set<DLClause> overlappingDisjunctiveClauses( |
| 409 | QueryRecord botQueryRecord) { | 414 | QueryRecord botQueryRecord) { |
| 410 | if (m_tBoxAxioms == null) | 415 | if (m_tBoxAxioms == null) |
