From 691964863246bbf6ef9f72cc5e82c83df34f135a Mon Sep 17 00:00:00 2001 From: RncLsn Date: Tue, 2 Jun 2015 15:40:29 +0100 Subject: Working query-dependent semi-skolemised upper bound (tested on UOBM1 and LUBM1). --- .../pagoda/multistage/MultiStageQueryEngine.java | 8 +- .../ox/cs/pagoda/multistage/StageQueryEngine.java | 2 +- src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java | 30 ++-- src/uk/ac/ox/cs/pagoda/query/QueryRecord.java | 141 ++++++++++-------- .../ox/cs/pagoda/reasoner/ConsistencyManager.java | 2 +- .../ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java | 132 +++++++++-------- .../cs/pagoda/reasoner/light/RDFoxQueryEngine.java | 2 +- src/uk/ac/ox/cs/pagoda/rules/Program.java | 2 +- src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java | 165 +++++++++++---------- .../ox/cs/pagoda/tracking/TrackingRuleEncoder.java | 2 +- 10 files changed, 254 insertions(+), 232 deletions(-) (limited to 'src/uk/ac/ox/cs') diff --git a/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java b/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java index b708bee..e1be6d2 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java @@ -82,7 +82,6 @@ public class MultiStageQueryEngine extends StageQueryEngine { if(gap != null) treatment.addAdditionalGapTuples(); String programName = "multi-stage upper program"; - Utility.logInfo(name + " store is materialising " + programName + " ..."); Timer t = new Timer(); String datalogProgram = program.getDatalogRuleText(); @@ -101,7 +100,8 @@ public class MultiStageQueryEngine extends StageQueryEngine { long oldTripleCount = store.getTriplesCount(); subTimer.reset(); - Utility.logInfo("Iteration " + ++iteration + ": "); + Utility.logInfo(name + " store is materialising " + + programName + "... (iteration " + ++iteration + ")"); incrementally = (iteration != 1); @@ -143,8 +143,8 @@ public class MultiStageQueryEngine extends StageQueryEngine { subTimer.reset(); if((violations = program.isIntegrated(this, incrementally)) == null || violations.size() == 0) { store.clearRulesAndMakeFactsExplicit(); - Utility.logInfo(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - tripleCountBeforeMat) + " new)"); - Utility.logInfo(name + " store is DONE for multi-stage materialising in " + t.duration() + " seconds."); + Utility.logDebug(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - tripleCountBeforeMat) + " new)"); + Utility.logDebug(name + " store is DONE for multi-stage materialising in " + t.duration() + " seconds."); return isValid() ? 1 : 0; } Utility.logDebug("Time to detect violations: " + subTimer.duration()); diff --git a/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java b/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java index c8776fe..ffca55a 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java @@ -40,7 +40,7 @@ public abstract class StageQueryEngine extends BasicQueryEngine { } if (validMaterialisation) - Utility.logInfo("The " + name + " store is valid."); + Utility.logDebug("The " + name + " store is valid."); else Utility.logInfo("The " + name + " store is not valid."); return validMaterialisation; diff --git a/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java b/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java index 78aced1..9a9d0de 100644 --- a/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java +++ b/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java @@ -16,14 +16,10 @@ import java.lang.reflect.Type; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class AnswerTuple { public static final String SEPARATOR = "\t"; - static final Pattern owlLiteralRegex = - Pattern.compile("^\"(?[^@]+(@(?.+))?)\"(^^<(?.+)>)?$"); String m_str = null; GroundTerm[] m_tuple; @@ -158,32 +154,36 @@ public class AnswerTuple { String tuplesString = json.getAsJsonPrimitive().getAsString(); // StringTokenizer tokenizer = new StringTokenizer(tuplesString, SEPARATOR); StringTokenizer tokenizer = new StringTokenizer(tuplesString); - GroundTerm[] terms = new GroundTerm[tokenizer.countTokens()]; + int tokensCount = tokenizer.countTokens(); + GroundTerm[] terms = new GroundTerm[tokensCount]; // TODO test parsing - for (int i = 0; i < tokenizer.countTokens(); i++) { + for(int i = 0; i < tokensCount; i++) { String token = tokenizer.nextToken(); if (token.charAt(0) == '<') { terms[i] = uk.ac.ox.cs.JRDFox.model.Individual.create(token.substring(1,token.length()-1)); } else if (token.charAt(0) == '"') { - Matcher matcher = owlLiteralRegex.matcher(token); - if(matcher.matches()) { - String lexicalForm = matcher.group("lexicalForm"); - String dataTypeIRI = matcher.group("dataType"); - Datatype dataType; - if(dataTypeIRI == null || dataTypeIRI.isEmpty()) dataType = Datatype.RDF_PLAIN_LITERAL; - else dataType = uk.ac.ox.cs.JRDFox.model.Datatype.value(dataTypeIRI); - terms[i] = uk.ac.ox.cs.JRDFox.model.Literal.create(lexicalForm, dataType); + Datatype datatype; + String lexicalForm; + if(token.contains("^^")) { + String[] lexicalFormAndType = token.split("^^"); + lexicalForm = lexicalFormAndType[0]; + datatype = Datatype.value(lexicalFormAndType[1]); } else { - throw new IllegalArgumentException("The given json does not represent a valid AnswerTuple"); + lexicalForm = token.substring(1, token.length() - 1); + // TODO check +// datatype = token.contains("@") ? Datatype.RDF_PLAIN_LITERAL : Datatype.XSD_STRING; + datatype = Datatype.XSD_STRING; } + terms[i] = uk.ac.ox.cs.JRDFox.model.Literal.create(lexicalForm, datatype); } else { terms[i] = uk.ac.ox.cs.JRDFox.model.BlankNode.create(token); } } + return new AnswerTuple(terms); } } diff --git a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java index 742b7da..516a461 100644 --- a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java +++ b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java @@ -135,74 +135,16 @@ public class QueryRecord extends Disposable { return updateUpperBoundAnswers(answerTuples, false); } - public boolean updateUpperBoundAnswers(AnswerTuples answerTuples, boolean toCheckAux) { + public boolean checkUpperBoundAnswers(AnswerTuples answerTuples) { if(isDisposed()) throw new DisposedException(); - if(!(answerTuples instanceof RDFoxAnswerTuples)) { - String msg = "The upper bound must be computed by RDFox!"; - Utility.logError(msg); - throw new IllegalArgumentException(msg); - } - - RDFoxAnswerTuples rdfoxAnswerTuples = (RDFoxAnswerTuples) answerTuples; - - Set candidateGapAnswerTuples = new HashSet(); - AnswerTuple tuple; - for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) { - tuple = rdfoxAnswerTuples.getTuple(); - if(isBottom() || !tuple.hasAnonymousIndividual()) - if((!toCheckAux || !tuple.hasAuxPredicate()) && !soundAnswerTuples.contains(tuple)) - candidateGapAnswerTuples.add(tuple); - } - - /*** START: debugging ***/ - if(PagodaProperties.isDebuggingMode()) { - if(rdfoxAnswerTuples.getArity() != getAnswerVariables().length) - throw new IllegalArgumentException( - "The arity of answers (" + rdfoxAnswerTuples.getArity() + ") " + - "is different from the number of answer variables (" + - getAnswerVariables().length + ")"); - - Set namedAnswerTuples = new HashSet<>(); - rdfoxAnswerTuples.reset(); - for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) { - tuple = rdfoxAnswerTuples.getTuple(); -// if(isBottom() || !tuple.hasAnonymousIndividual()) { - namedAnswerTuples.add(tuple); -// } - } - HashSet difference = new HashSet<>(soundAnswerTuples); - difference.removeAll(namedAnswerTuples); - if(!difference.isEmpty()) - throw new IllegalArgumentException("The upper bound does not contain the lower bound! Missing answers: " + difference - .size()); - } - /*** END: debugging ***/ - - boolean update; - if(gapAnswerTuples == null) { - gapAnswerTuples = candidateGapAnswerTuples; - update = true; - } - else { - update = gapAnswerTuples.retainAll(candidateGapAnswerTuples); - } - - if(update) - Utility.logInfo("Upper bound answers updated: " + getNumberOfAnswers()); - else - Utility.logInfo("Upper bound answers unchanged"); + return updateUpperBoundAnswers(answerTuples, true, false); + } - return update; + public boolean updateUpperBoundAnswers(AnswerTuples answerTuples, boolean toCheckAux) { + if(isDisposed()) throw new DisposedException(); -// boolean update = false; -// for(Iterator iter = gapAnswerTuples.iterator(); iter.hasNext(); ) { -// tuple = iter.next(); -// if(!candidateGapAnswerTuples.contains(tuple)) { -// iter.remove(); -// update = true; -// } -// } + return updateUpperBoundAnswers(answerTuples, toCheckAux, true); } public int getNumberOfAnswers() { @@ -713,6 +655,77 @@ public class QueryRecord extends Disposable { return Objects.hash(queryText, soundAnswerTuples); } + private boolean updateUpperBoundAnswers(AnswerTuples answerTuples, boolean toCheckAux, boolean _check_containment) { + if(!(answerTuples instanceof RDFoxAnswerTuples)) { + String msg = "The upper bound must be computed by RDFox!"; + Utility.logError(msg); + throw new IllegalArgumentException(msg); + } + + RDFoxAnswerTuples rdfoxAnswerTuples = (RDFoxAnswerTuples) answerTuples; + + Set candidateGapAnswerTuples = new HashSet(); + AnswerTuple tuple; + for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) { + tuple = rdfoxAnswerTuples.getTuple(); + if(isBottom() || !tuple.hasAnonymousIndividual()) + if((!toCheckAux || !tuple.hasAuxPredicate()) && !soundAnswerTuples.contains(tuple)) + candidateGapAnswerTuples.add(tuple); + } + + /*** START: debugging ***/ + if(PagodaProperties.isDebuggingMode() && _check_containment) { + if(rdfoxAnswerTuples.getArity() != getAnswerVariables().length) + throw new IllegalArgumentException( + "The arity of answers (" + rdfoxAnswerTuples.getArity() + ") " + + "is different from the number of answer variables (" + + getAnswerVariables().length + ")"); + + Set namedAnswerTuples = new HashSet<>(); + rdfoxAnswerTuples.reset(); + int numberOfAnswers = 0; + for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) { + tuple = rdfoxAnswerTuples.getTuple(); +// if(isBottom() || !tuple.hasAnonymousIndividual()) { + namedAnswerTuples.add(tuple); +// } + numberOfAnswers++; + } + Utility.logDebug("The number of answers returned by an upper bound: " + numberOfAnswers); + HashSet difference = new HashSet<>(soundAnswerTuples); + difference.removeAll(namedAnswerTuples); + if(!difference.isEmpty()) + throw new IllegalArgumentException("The upper bound does not contain the lower bound! Missing answers: " + difference + .size()); + } + /*** END: debugging ***/ + + boolean update; + if(gapAnswerTuples == null) { + gapAnswerTuples = candidateGapAnswerTuples; + update = true; + } + else { + update = gapAnswerTuples.retainAll(candidateGapAnswerTuples); + } + + if(update) + Utility.logInfo("Upper bound answers updated: " + getNumberOfAnswers()); + else + Utility.logInfo("Upper bound answers unchanged"); + + return update; + +// boolean update = false; +// for(Iterator iter = gapAnswerTuples.iterator(); iter.hasNext(); ) { +// tuple = iter.next(); +// if(!candidateGapAnswerTuples.contains(tuple)) { +// iter.remove(); +// update = true; +// } +// } + } + public enum Step { LOWER_BOUND, UPPER_BOUND, diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java index b4a1775..453b5ca 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java @@ -128,7 +128,7 @@ public class ConsistencyManager extends Disposable { store.applyReasoning(true); tripleCount = store.getTriplesCount(); - Utility.logInfo("tracking store after materialising tracking program: " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)", + Utility.logDebug("tracking store after materialising tracking program: " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)", "tracking store finished the materialisation of tracking program in " + t1.duration() + " seconds."); extractAxioms(); diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java index 8445713..acdb8a3 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java @@ -31,42 +31,29 @@ class MyQueryReasoner extends QueryReasoner { OWLOntology ontology; DatalogProgram program; - // String additonalDataFile; BasicQueryEngine rlLowerStore = null; BasicQueryEngine lazyUpperStore = null; - MultiStageQueryEngine limitedSkolemUpperStore; + // MultiStageQueryEngine limitedSkolemUpperStore; OWLOntology elho_ontology; - // boolean[] namedIndividuals_lazyUpper; KarmaQueryEngine elLowerStore = null; BasicQueryEngine trackingStore = null; - // boolean[] namedIndividuals_tracking; TrackingRuleEncoder encoder; private boolean equalityTag; - private boolean multiStageTag; private Timer t = new Timer(); private Collection predicatesWithGap = null; private SatisfiabilityStatus satisfiable; private ConsistencyManager consistency = new ConsistencyManager(this); - private boolean useUpperStores = false; public MyQueryReasoner() { - setup(true, true); + setup(true); } public MyQueryReasoner(boolean multiStageTag, boolean considerEqualities) { - setup(multiStageTag, considerEqualities); - } + if(!multiStageTag) + throw new IllegalArgumentException( + "Value \"true\" for parameter \"multiStageTag\" is no longer supported"); - public void setup(boolean multiStageTag, boolean considerEqualities) { - if(isDisposed()) throw new DisposedException(); - satisfiable = SatisfiabilityStatus.UNCHECKED; - this.multiStageTag = multiStageTag; - this.equalityTag = considerEqualities; - - rlLowerStore = new BasicQueryEngine("rl-lower-bound"); - elLowerStore = new KarmaQueryEngine("elho-lower-bound"); - - trackingStore = getUpperStore("tracking", false); + setup(considerEqualities); } @Override @@ -84,11 +71,8 @@ class MyQueryReasoner extends QueryReasoner { // program.getUpper().save(); // program.getGeneral().save(); - useUpperStores = multiStageTag && !program.getGeneral().isHorn(); - if(useUpperStores) { - lazyUpperStore = getUpperStore("lazy-upper-bound", true); - limitedSkolemUpperStore = new MultiStageQueryEngine("limited-skolem-upper-bound", true); - } + if(!program.getGeneral().isHorn()) + lazyUpperStore = new MultiStageQueryEngine("lazy-upper-bound", true); importData(program.getAdditionalDataFile()); @@ -104,15 +88,16 @@ class MyQueryReasoner extends QueryReasoner { @Override public boolean preprocess() { if(isDisposed()) throw new DisposedException(); + t.reset(); - Utility.logInfo("Preprocessing... checking satisfiability... "); + Utility.logInfo("Preprocessing (and checking satisfiability)..."); String name = "data", datafile = importedData.toString(); rlLowerStore.importRDFData(name, datafile); rlLowerStore.materialise("lower program", program.getLower().toString()); // program.getLower().save(); if(!consistency.checkRLLowerBound()) return false; - Utility.logInfo("The number of sameAs assertions in RL lower store: " + rlLowerStore.getSameAsNumber()); + Utility.logDebug("The number of sameAs assertions in RL lower store: " + rlLowerStore.getSameAsNumber()); String originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology); @@ -134,22 +119,7 @@ class MyQueryReasoner extends QueryReasoner { } if(consistency.checkUpper(lazyUpperStore)) { satisfiable = SatisfiabilityStatus.SATISFIABLE; - Utility.logInfo("time for satisfiability checking: " + t.duration()); - } - - if(limitedSkolemUpperStore != null) { - limitedSkolemUpperStore.importRDFData(name, datafile); - limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram); - int tag = limitedSkolemUpperStore.materialiseSkolemly(program, null); - if(tag != 1) { - limitedSkolemUpperStore.dispose(); - limitedSkolemUpperStore = null; - } - if(tag == -1) return false; - } - if(satisfiable == SatisfiabilityStatus.UNCHECKED && consistency.checkUpper(limitedSkolemUpperStore)) { - satisfiable = SatisfiabilityStatus.SATISFIABLE; - Utility.logInfo("time for satisfiability checking: " + t.duration()); + Utility.logDebug("time for satisfiability checking: " + t.duration()); } trackingStore.importRDFData(name, datafile); @@ -194,14 +164,11 @@ class MyQueryReasoner extends QueryReasoner { @Override public void evaluate(QueryRecord queryRecord) { if(isDisposed()) throw new DisposedException(); - if(queryBounds(queryRecord)) + + if(queryLowerAndUpperBounds(queryRecord)) return; OWLOntology relevantOntologySubset = extractRelevantOntologySubset(queryRecord); - - int aBoxCount = relevantOntologySubset.getABoxAxioms(true).size(); - Utility.logInfo("Relevant ontology subset: ABox_axioms=" + aBoxCount + " TBox_axioms=" + (relevantOntologySubset - .getAxiomCount() - aBoxCount)); // queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl"); if(querySkolemisedRelevantSubset(relevantOntologySubset, queryRecord)) @@ -240,16 +207,18 @@ class MyQueryReasoner extends QueryReasoner { if(lazyUpperStore != null) lazyUpperStore.dispose(); if(elLowerStore != null) elLowerStore.dispose(); if(trackingStore != null) trackingStore.dispose(); - if(limitedSkolemUpperStore != null) limitedSkolemUpperStore.dispose(); - +// if(limitedSkolemUpperStore != null) limitedSkolemUpperStore.dispose(); } - private BasicQueryEngine getUpperStore(String name, boolean checkValidity) { - if(multiStageTag) - return new MultiStageQueryEngine(name, checkValidity); -// return new TwoStageQueryEngine(name, checkValidity); - else - return new BasicQueryEngine(name); + private void setup(boolean considerEqualities) { + if(isDisposed()) throw new DisposedException(); + satisfiable = SatisfiabilityStatus.UNCHECKED; + this.equalityTag = considerEqualities; + + rlLowerStore = new BasicQueryEngine("rl-lower-bound"); + elLowerStore = new KarmaQueryEngine("elho-lower-bound"); + + trackingStore = new MultiStageQueryEngine("tracking", false); } protected void internal_importDataFile(String name, String datafile) { @@ -284,10 +253,37 @@ class MyQueryReasoner extends QueryReasoner { return false; } + private boolean checkGapAnswers(BasicQueryEngine relevantStore, QueryRecord queryRecord) { + Tuple extendedQueries = queryRecord.getExtendedQueryText(); + if(queryRecord.hasNonAnsDistinguishedVariables()) + checkGapAnswers(relevantStore, queryRecord, extendedQueries.get(0), queryRecord.getAnswerVariables()); + else + checkGapAnswers(relevantStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); + + queryRecord.addProcessingTime(Step.L_SKOLEM_UPPER_BOUND, t.duration()); + if(queryRecord.isProcessed()) { + queryRecord.setDifficulty(Step.L_SKOLEM_UPPER_BOUND); + return true; + } + return false; + } + + private void checkGapAnswers(BasicQueryEngine relevantStore, QueryRecord queryRecord, String queryText, String[] answerVariables) { + AnswerTuples rlAnswer = null; + try { + Utility.logDebug(queryText); + rlAnswer = relevantStore.evaluate(queryText, answerVariables); + Utility.logDebug(t.duration()); + queryRecord.checkUpperBoundAnswers(rlAnswer); + } finally { + if(rlAnswer != null) rlAnswer.dispose(); + } + } + /** * Returns the part of the ontology relevant for Hermit, while computing the bound answers. */ - private boolean queryBounds(QueryRecord queryRecord) { + private boolean queryLowerAndUpperBounds(QueryRecord queryRecord) { AnswerTuples rlAnswer = null, elAnswer = null; t.reset(); @@ -312,9 +308,6 @@ class MyQueryReasoner extends QueryReasoner { Utility.logDebug("Lazy store"); if(lazyUpperStore != null && queryUpperStore(lazyUpperStore, queryRecord, extendedQueryTexts, Step.LAZY_UPPER_BOUND)) return true; -// Utility.logDebug("Skolem store"); -// if(limitedSkolemUpperStore != null && queryUpperStore(limitedSkolemUpperStore, queryRecord, extendedQueryTexts, Step.L_SKOLEM_UPPER_BOUND)) -// return null; } t.reset(); @@ -338,6 +331,8 @@ class MyQueryReasoner extends QueryReasoner { } private OWLOntology extractRelevantOntologySubset(QueryRecord queryRecord) { + Utility.logInfo("Extracting relevant ontology-subset..."); + t.reset(); QueryTracker tracker = new QueryTracker(encoder, rlLowerStore, queryRecord); @@ -345,6 +340,14 @@ class MyQueryReasoner extends QueryReasoner { queryRecord.addProcessingTime(Step.FRAGMENT, t.duration()); + // just statistics + int numOfABoxAxioms = relevantOntologySubset.getABoxAxioms(true).size(); + int numOfTBoxAxioms = relevantOntologySubset.getAxiomCount() - numOfABoxAxioms; + int originalNumOfABoxAxioms = ontology.getABoxAxioms(true).size(); + int originalNumOfTBoxAxioms = ontology.getAxiomCount() - originalNumOfABoxAxioms; + Utility.logInfo("Relevant ontology-subset has been extracted: |ABox|=" + + numOfABoxAxioms + ", |TBox|=" + numOfTBoxAxioms); + return relevantOntologySubset; } @@ -361,22 +364,23 @@ class MyQueryReasoner extends QueryReasoner { } private boolean querySkolemisedRelevantSubset(OWLOntology relevantSubset, QueryRecord queryRecord) { + Utility.logInfo("Evaluating semi-Skolemised relevant upper store..."); + DatalogProgram relevantProgram = new DatalogProgram(relevantSubset, false); // toClassify is false MultiStageQueryEngine relevantStore = new MultiStageQueryEngine("Relevant-store", true); // checkValidity is true -// relevantStore.importRDFData("data", relevantProgram.getAdditionalDataFile()); // tried, doesn't work + relevantStore.importDataFromABoxOf(relevantSubset); int materialisationResult = relevantStore.materialiseSkolemly(relevantProgram, null); -// int materialisationResult = relevantStore.materialiseRestrictedly(relevantProgram, null); // DOESN'T WORK!!! if(materialisationResult != 1) throw new RuntimeException("Skolemised materialisation error"); // TODO check consistency -// relevantStore.materialiseRestrictedly(relevantProgram, null); // it has been tried - return queryUpperStore(relevantStore, queryRecord, queryRecord.getExtendedQueryText(), Step.L_SKOLEM_UPPER_BOUND); + boolean isFullyProcessed = checkGapAnswers(relevantStore, queryRecord); -// return queryUpperStore(limitedSkolemUpperStore, queryRecord, queryRecord.getExtendedQueryText(), Step.L_SKOLEM_UPPER_BOUND); + Utility.logInfo("Semi-Skolemised relevant upper store has been evaluated"); + return isFullyProcessed; } enum SatisfiabilityStatus {SATISFIABLE, UNSATISFIABLE, UNCHECKED} 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 f835ba9..8b22919 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java @@ -74,7 +74,7 @@ public abstract class RDFoxQueryEngine extends QueryEngine { long prevTriplesCount = store.getTriplesCount(); store.importOntology(ontology.getOWLOntologyManager().createOntology(ontology.getABoxAxioms(true))); long loadedTriples = store.getTriplesCount() - prevTriplesCount; - Utility.logInfo(name + ": loaded " + loadedTriples + " triples from " + ontology.getABoxAxioms(true) + Utility.logDebug(name + ": loaded " + loadedTriples + " triples from " + ontology.getABoxAxioms(true) .size() + " ABox axioms"); } catch(JRDFStoreException | OWLOntologyCreationException e) { e.printStackTrace(); diff --git a/src/uk/ac/ox/cs/pagoda/rules/Program.java b/src/uk/ac/ox/cs/pagoda/rules/Program.java index 4e147bb..afc32d4 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/Program.java +++ b/src/uk/ac/ox/cs/pagoda/rules/Program.java @@ -106,7 +106,7 @@ protected PredicateDependency dependencyGraph; clauses.addAll(botStrategy.process(botRelated)); if(this instanceof GeneralProgram) - Utility.logInfo("The number of rules: " + (clauses.size() - 1)); + Utility.logDebug("The number of rules: " + (clauses.size() - 1)); } @Override 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 { store.applyReasoning(incrementally); tripleCount = store.getTriplesCount(); - Utility.logInfo("tracking store after materialising tracking program: " + Utility.logDebug("tracking store after materialising tracking program: " + tripleCount + " (" + (tripleCount - oldTripleCount) @@ -149,28 +149,47 @@ public class QueryTracker { } + public void addRelatedAxiomsAndClauses(QueryRecord[] botQueryRecords) { + LinkedList toAddedRecords = new LinkedList(); + + for(QueryRecord botQueryRecord : botQueryRecords) + if(overlappingDisjunctiveClauses(botQueryRecord) != null) + toAddedRecords.add(botQueryRecord); + + for(QueryRecord botQueryRecord : toAddedRecords) { + m_manager.addAxioms(m_record.getRelevantOntology(), botQueryRecord.getRelevantOntology().getAxioms()); + for(DLClause clause : botQueryRecord.getRelevantClauses()) + m_record.addRelevantClauses(clause); + } + + if(!toAddedRecords.isEmpty()) + Utility.logDebug("Part of bottom fragments is added for this query."); + else + Utility.logDebug("None of bottom fragments is added for this query."); + } + private int extractBinaryTuples(BasicQueryEngine trackingStore, OWLDataFactory factory, Set binaryPredicates) { - OWLOntology fragment = m_record.getRelevantOntology(); - int count; - int aboxAxiomCounter = 0; - Resource sub, obj; + OWLOntology fragment = m_record.getRelevantOntology(); + int count; + int aboxAxiomCounter = 0; + Resource sub, obj; OWLAxiom aboxAxiom; - String trackingIRI; - Set trackedIDEqualities = new HashSet(); - Set trackedEntityEqualities = new HashSet(); + String trackingIRI; + Set trackedIDEqualities = new HashSet(); + Set trackedEntityEqualities = new HashSet(); TupleIterator trackingAnswers, lowerAnswers; - + for (Iterator iter = binaryPredicates.iterator(); iter.hasNext(); ) { - trackingIRI = iter.next(); + trackingIRI = iter.next(); String propIRI = m_encoder.getOriginalPredicate(trackingIRI); - if (propIRI == null) continue; + if(propIRI == null) continue; if (!propIRI.equals(Namespace.EQUALITY_QUOTED)) continue; - trackingAnswers = null; + trackingAnswers = null; try { trackingAnswers = trackingStore.internal_evaluateAgainstIDBs(getSPARQLQuery4Binary(trackingIRI)); for (long multi = trackingAnswers.open(); multi != 0; multi = trackingAnswers.getNext()) { if (trackingAnswers.getResourceID(0) != trackingAnswers.getResourceID(1)) { - for (int i = 0; i < 2; ++i) + for(int i = 0; i < 2; ++i) if (trackedIDEqualities.add(trackingAnswers.getResourceID(i))) { trackedEntityEqualities.add(trackingAnswers.getResource(i).m_lexicalForm); } @@ -179,71 +198,74 @@ public class QueryTracker { } catch (JRDFStoreException e) { e.printStackTrace(); } finally { - if (trackingAnswers != null) trackingAnswers.dispose(); + if(trackingAnswers != null) trackingAnswers.dispose(); } iter.remove(); - break; + break; } - - String sub_rep, obj_rep; - + + String sub_rep, obj_rep; + for (Iterator iter = binaryPredicates.iterator(); iter.hasNext(); ) { - trackingIRI = iter.next(); - count = 0; + trackingIRI = iter.next(); + count = 0; String propIRI = m_encoder.getOriginalPredicate(trackingIRI); - if (propIRI == null) continue; - iter.remove(); - lowerAnswers = null; trackingAnswers = null; + if(propIRI == null) continue; + iter.remove(); + lowerAnswers = null; + trackingAnswers = null; Set lower = new HashSet(); OWLObject prop = null; try { trackingAnswers = trackingStore.internal_evaluateAgainstIDBs(getSPARQLQuery4Binary(trackingIRI)); trackingAnswers.open(); - if (trackingAnswers.getMultiplicity() == 0) continue; - + if(trackingAnswers.getMultiplicity() == 0) continue; + lowerAnswers = m_dataStore.internal_evaluateNotExpanded(getSPARQLQuery4Binary(propIRI)); - lowerAnswers.open(); - if (lowerAnswers.getMultiplicity() == 0) continue; - + lowerAnswers.open(); + if(lowerAnswers.getMultiplicity() == 0) continue; + StringBuilder builder = new StringBuilder(); for (long multi = lowerAnswers.getMultiplicity(); multi != 0; multi = lowerAnswers.getNext()) { - sub = lowerAnswers.getResource(0); + sub = lowerAnswers.getResource(0); obj = lowerAnswers.getResource(1); builder.setLength(0); - builder.append(equalityGroups.find(sub.m_lexicalForm)).append(AnswerTuple.SEPARATOR).append(equalityGroups.find(obj.m_lexicalForm)); + builder.append(equalityGroups.find(sub.m_lexicalForm)) + .append(AnswerTuple.SEPARATOR) + .append(equalityGroups.find(obj.m_lexicalForm)); lower.add(builder.toString()); } - + for (long multi = trackingAnswers.getMultiplicity(); multi != 0; multi = trackingAnswers.getNext()) { sub = trackingAnswers.getResource(0); obj = trackingAnswers.getResource(1); builder.setLength(0); sub_rep = equalityGroups.find(sub.m_lexicalForm); - obj_rep = equalityGroups.find(obj.m_lexicalForm); + obj_rep = equalityGroups.find(obj.m_lexicalForm); if (!sub_rep.equals(sub.m_lexicalForm) || !obj_rep.equals(obj.m_lexicalForm)) continue; - - builder.append(sub_rep).append(AnswerTuple.SEPARATOR).append(obj_rep); + + builder.append(sub_rep).append(AnswerTuple.SEPARATOR).append(obj_rep); if (lower.contains(builder.toString())) { - OWLObject owlObj = getOWLObject(obj, factory); + OWLObject owlObj = getOWLObject(obj, factory); if (owlObj instanceof OWLIndividual) { if (prop == null) prop = factory.getOWLObjectProperty(IRI.create(propIRI.startsWith("<") ? OWLHelper.removeAngles(propIRI) : propIRI)); aboxAxiom = factory.getOWLObjectPropertyAssertionAxiom( - (OWLObjectProperty) prop, - factory.getOWLNamedIndividual(IRI.create(sub_rep)), + (OWLObjectProperty) prop, + factory.getOWLNamedIndividual(IRI.create(sub_rep)), factory.getOWLNamedIndividual(IRI.create(obj_rep))); } else if (owlObj instanceof OWLLiteral) { if (prop == null) prop = factory.getOWLDataProperty(IRI.create(propIRI.startsWith("<") ? OWLHelper.removeAngles(propIRI) : propIRI)); aboxAxiom = factory.getOWLDataPropertyAssertionAxiom( - (OWLDataProperty) prop, - factory.getOWLNamedIndividual(IRI.create(sub_rep)), + (OWLDataProperty) prop, + factory.getOWLNamedIndividual(IRI.create(sub_rep)), (OWLLiteral) owlObj); } else { - Utility.logError("There might be an error here ... "); - continue; + Utility.logError("There might be an error here ... "); + continue; } if (!fragment.containsAxiom(aboxAxiom)) { m_manager.addAxiom(fragment, aboxAxiom); @@ -259,30 +281,30 @@ public class QueryTracker { if (lowerAnswers != null) lowerAnswers.dispose(); lower.clear(); } - Utility.logDebug("property: " + propIRI + " " + count); + Utility.logDebug("property: " + propIRI + " " + count); } - + count = 0; - String value; - OWLObjectProperty sameAs = factory.getOWLObjectProperty(IRI.create(Namespace.EQUALITY)); + String value; + OWLObjectProperty sameAs = factory.getOWLObjectProperty(IRI.create(Namespace.EQUALITY)); for (String key: equalityGroups.keySet()) { - if (!trackedEntityEqualities.contains(key)) continue; + if(!trackedEntityEqualities.contains(key)) continue; value = equalityGroups.find(key); m_manager.addAxiom(fragment, factory.getOWLObjectPropertyAssertionAxiom( - sameAs, - factory.getOWLNamedIndividual(IRI.create(key)), + sameAs, + factory.getOWLNamedIndividual(IRI.create(key)), factory.getOWLNamedIndividual(IRI.create(value)))); - ++aboxAxiomCounter; - ++count; + ++aboxAxiomCounter; + ++count; } Utility.logDebug("property: " + Namespace.EQUALITY_QUOTED + " " + count); - - trackedEntityEqualities.clear(); + + trackedEntityEqualities.clear(); trackedIDEqualities.clear(); Utility.logTrace(Namespace.EQUALITY_QUOTED + " " + count); - - Utility.logDebug("ABox extraction Done"); - return aboxAxiomCounter; + + Utility.logDebug("ABox extraction Done"); + return aboxAxiomCounter; } private OWLObject getOWLObject(Resource rdfoxTerm, OWLDataFactory factory) { @@ -298,15 +320,17 @@ public class QueryTracker { // rdfoxTerm.m_datatype.equals(Datatype.XSD_UNSIGNED_BYTE)) if (rdfoxTerm.m_datatype.equals(Datatype.XSD_DATE)) return factory.getOWLLiteral(rdfoxTerm.m_lexicalForm, factory.getOWLDatatype(IRI.create(Namespace.XSD_STRING))); - - else return factory.getOWLLiteral(rdfoxTerm.m_lexicalForm, factory.getOWLDatatype(IRI.create(rdfoxTerm.m_datatype.getIRI()))); + + else + return factory.getOWLLiteral(rdfoxTerm.m_lexicalForm, factory.getOWLDatatype(IRI.create(rdfoxTerm.m_datatype + .getIRI()))); } private int extractUnaryTuples(BasicQueryEngine trackingStore, OWLDataFactory factory, Set unaryPredicates) { OWLOntology fragment = m_record.getRelevantOntology(); int count; int aboxAxiomCounter = 0; - String answer; + String answer; OWLAxiom aboxAxiom; for (String trackingIRI : unaryPredicates) { count = 0; @@ -319,12 +343,12 @@ public class QueryTracker { try { answers = trackingStore.internal_evaluateAgainstIDBs(getSPARQLQuery4Unary(trackingIRI)); answers.open(); - if (answers.getMultiplicity() == 0) continue; + if(answers.getMultiplicity() == 0) continue; lowerAnswers = m_dataStore.internal_evaluateNotExpanded(getSPARQLQuery4Unary(clsIRI)); - lowerAnswers.open(); + lowerAnswers.open(); if (lowerAnswers.getMultiplicity() == 0) continue; - + for (long multi = lowerAnswers.getMultiplicity(); multi != 0; multi = lowerAnswers.getNext()) lower.add(equalityGroups.find(lowerAnswers.getResource(0).m_lexicalForm)); @@ -386,25 +410,6 @@ public class QueryTracker { } } - public void addRelatedAxiomsAndClauses(QueryRecord[] botQueryRecords) { - LinkedList toAddedRecords = new LinkedList(); - - for (QueryRecord botQueryRecord : botQueryRecords) - if (overlappingDisjunctiveClauses(botQueryRecord) != null) - toAddedRecords.add(botQueryRecord); - - for (QueryRecord botQueryRecord : toAddedRecords) { - m_manager.addAxioms(m_record.getRelevantOntology(), botQueryRecord.getRelevantOntology().getAxioms()); - for (DLClause clause : botQueryRecord.getRelevantClauses()) - m_record.addRelevantClauses(clause); - } - - if (!toAddedRecords.isEmpty()) - Utility.logDebug("Part of bottom fragments is added for this query."); - else - Utility.logDebug("None of bottom fragments is added for this query."); - } - private Set overlappingDisjunctiveClauses( QueryRecord botQueryRecord) { if (m_tBoxAxioms == null) diff --git a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoder.java b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoder.java index d8ebc55..d05731a 100644 --- a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoder.java +++ b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoder.java @@ -311,7 +311,7 @@ public abstract class TrackingRuleEncoder extends Disposable { } } - Utility.logInfo(addedData.size() + " triples are added into the store."); + Utility.logDebug(addedData.size() + " triples are added into the store."); } protected DLPredicate getGapDLPredicate(DLPredicate dlPredicate) { -- cgit v1.2.3