diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-06-16 15:54:53 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-06-26 12:04:49 +0100 |
| commit | 29eecb27c7f91de92b21bbd646d8b7a55e526833 (patch) | |
| tree | 233481bccd68e4b718598320f121024db16ff0e5 /src/uk/ac/ox/cs | |
| parent | 3a276b7c7836e56a171ab753b018913ce022ba8e (diff) | |
| download | ACQuA-29eecb27c7f91de92b21bbd646d8b7a55e526833.tar.gz ACQuA-29eecb27c7f91de92b21bbd646d8b7a55e526833.zip | |
Maybe fixed bug in internalisation.
Diffstat (limited to 'src/uk/ac/ox/cs')
12 files changed, 335 insertions, 250 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/endomorph/Endomorph.java b/src/uk/ac/ox/cs/pagoda/endomorph/Endomorph.java index cde0895..1c853d7 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/Endomorph.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/Endomorph.java | |||
| @@ -85,10 +85,18 @@ public class Endomorph extends Checker { | |||
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | @Override | 87 | @Override |
| 88 | public int getNoOfCalls() { | ||
| 89 | return fullReasoner.getNoOfCalls(); | ||
| 90 | } | ||
| 91 | |||
| 92 | @Override | ||
| 88 | public void dispose() { | 93 | public void dispose() { |
| 89 | super.dispose(); | 94 | super.dispose(); |
| 90 | 95 | ||
| 91 | fullReasoner.dispose(); | 96 | if(fullReasoner != null) { |
| 97 | // Utility.logInfo("Hermit was called " + fullReasoner.getNoOfCalls() + " times"); | ||
| 98 | fullReasoner.dispose(); | ||
| 99 | } | ||
| 92 | } | 100 | } |
| 93 | 101 | ||
| 94 | public Graph getGraph() { | 102 | public Graph getGraph() { |
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java b/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java index 2471c80..33f9f03 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java | |||
| @@ -83,21 +83,6 @@ public class MultiStageQueryEngine extends StageQueryEngine { | |||
| 83 | return materialise(program, treatment, gap); | 83 | return materialise(program, treatment, gap); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | /** | ||
| 87 | * delta-chase with fixed mad term depth | ||
| 88 | */ | ||
| 89 | @Override | ||
| 90 | public int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap) { | ||
| 91 | if(isDisposed()) throw new DisposedException(); | ||
| 92 | |||
| 93 | materialise("lower program", dProgram.getLower().toString()); | ||
| 94 | Program generalProgram = dProgram.getGeneral(); | ||
| 95 | LimitedSkolemisationApplication program = | ||
| 96 | new LimitedSkolemisationApplication(generalProgram, dProgram.getUpperBottomStrategy()); | ||
| 97 | Treatment treatment = new Pick4NegativeConceptNaive(this, program); | ||
| 98 | return materialise(program, treatment, gap); | ||
| 99 | } | ||
| 100 | |||
| 101 | public int materialise4SpecificQuery(Program generalProgram, QueryRecord record, BottomStrategy upperBottom) { | 86 | public int materialise4SpecificQuery(Program generalProgram, QueryRecord record, BottomStrategy upperBottom) { |
| 102 | if(isDisposed()) throw new DisposedException(); | 87 | if(isDisposed()) throw new DisposedException(); |
| 103 | 88 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java b/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java index ffca55a..65184ee 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java | |||
| @@ -21,8 +21,6 @@ public abstract class StageQueryEngine extends BasicQueryEngine { | |||
| 21 | 21 | ||
| 22 | public abstract int materialiseRestrictedly(DatalogProgram dProgram, GapByStore4ID gap); | 22 | public abstract int materialiseRestrictedly(DatalogProgram dProgram, GapByStore4ID gap); |
| 23 | 23 | ||
| 24 | public abstract int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap); | ||
| 25 | |||
| 26 | public boolean isValid() { | 24 | public boolean isValid() { |
| 27 | if (!checkValidity) return true; | 25 | if (!checkValidity) return true; |
| 28 | if (validMaterialisation != null) return validMaterialisation; | 26 | if (validMaterialisation != null) return validMaterialisation; |
diff --git a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java index 5878a57..291af27 100644 --- a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java +++ b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java | |||
| @@ -188,6 +188,10 @@ public class QueryRecord extends Disposable { | |||
| 188 | return new AnswerTuplesImp(answerVariables[0], gapAnswerTuples); | 188 | return new AnswerTuplesImp(answerVariables[0], gapAnswerTuples); |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | public int getGapAnswersCount() { | ||
| 192 | return gapAnswerTuples.size(); | ||
| 193 | } | ||
| 194 | |||
| 191 | public String toString() { | 195 | public String toString() { |
| 192 | if(isDisposed()) throw new DisposedException(); | 196 | if(isDisposed()) throw new DisposedException(); |
| 193 | 197 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/query/rollup/QueryGraph.java b/src/uk/ac/ox/cs/pagoda/query/rollup/QueryGraph.java index a567699..a09cf5b 100644 --- a/src/uk/ac/ox/cs/pagoda/query/rollup/QueryGraph.java +++ b/src/uk/ac/ox/cs/pagoda/query/rollup/QueryGraph.java | |||
| @@ -81,6 +81,44 @@ public class QueryGraph { | |||
| 81 | return axioms; | 81 | return axioms; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | // public Set<OWLClassExpression> getExistentialConditions(Map<Variable, Term> assignment) { | ||
| 85 | // if(!rollable_edges.isEmpty()) return null; | ||
| 86 | // | ||
| 87 | // OWLIndividual sub; | ||
| 88 | // Visitor visitor = new Visitor(factory, assignment); | ||
| 89 | // Set<OWLClassExpression> axioms = new HashSet<>(); | ||
| 90 | // for(Map.Entry<Term, Set<OWLClassExpression>> entry : concepts.map.entrySet()) { | ||
| 91 | // // TODO check correctness!!! | ||
| 92 | // if(existVars.contains(entry.getKey())) { | ||
| 93 | // OWLClassExpression conjunction = | ||
| 94 | // factory.getOWLObjectIntersectionOf(factory.getOWLThing()); | ||
| 95 | // for(OWLClassExpression owlClassExpression : entry.getValue()) { | ||
| 96 | // conjunction = factory.getOWLObjectIntersectionOf(conjunction, owlClassExpression.accept(visitor)); | ||
| 97 | // } | ||
| 98 | // axioms.add(conjunction); | ||
| 99 | //// continue; // previously the "then" contained only this | ||
| 100 | // } | ||
| 101 | // } | ||
| 102 | // return axioms; | ||
| 103 | // } | ||
| 104 | |||
| 105 | public Set<OWLAxiom> getExistentialAxioms() { | ||
| 106 | if(!rollable_edges.isEmpty()) return null; | ||
| 107 | |||
| 108 | Set<OWLAxiom> axioms = new HashSet<>(); | ||
| 109 | for(Map.Entry<Term, Set<OWLClassExpression>> entry : concepts.map.entrySet()) { | ||
| 110 | if(existVars.contains(entry.getKey())) { | ||
| 111 | OWLClassExpression conjunction = | ||
| 112 | factory.getOWLObjectIntersectionOf(factory.getOWLThing()); | ||
| 113 | for(OWLClassExpression owlClassExpression : entry.getValue()) { | ||
| 114 | conjunction = factory.getOWLObjectIntersectionOf(conjunction, owlClassExpression); | ||
| 115 | } | ||
| 116 | axioms.add(factory.getOWLSubClassOfAxiom(conjunction, factory.getOWLNothing())); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | return axioms; | ||
| 120 | } | ||
| 121 | |||
| 84 | public Set<OWLAxiom> getAssertions(Map<Variable, Term> assignment) { | 122 | public Set<OWLAxiom> getAssertions(Map<Variable, Term> assignment) { |
| 85 | if(!rollable_edges.isEmpty()) return null; | 123 | if(!rollable_edges.isEmpty()) return null; |
| 86 | 124 | ||
| @@ -88,10 +126,21 @@ public class QueryGraph { | |||
| 88 | Visitor visitor = new Visitor(factory, assignment); | 126 | Visitor visitor = new Visitor(factory, assignment); |
| 89 | Set<OWLAxiom> axioms = getPropertyAssertions(assignment); | 127 | Set<OWLAxiom> axioms = getPropertyAssertions(assignment); |
| 90 | for(Map.Entry<Term, Set<OWLClassExpression>> entry : concepts.map.entrySet()) { | 128 | for(Map.Entry<Term, Set<OWLClassExpression>> entry : concepts.map.entrySet()) { |
| 91 | if(existVars.contains(entry.getKey())) continue; | 129 | // TODO check correctness!!! |
| 92 | sub = factory.getOWLNamedIndividual(IRI.create(getIndividual(entry.getKey(), assignment).getIRI())); | 130 | if(existVars.contains(entry.getKey())) { |
| 93 | for(OWLClassExpression clsExp : entry.getValue()) { | 131 | // OWLClassExpression conjunction = |
| 94 | axioms.add(factory.getOWLClassAssertionAxiom(clsExp.accept(visitor), sub)); | 132 | // factory.getOWLObjectIntersectionOf(factory.getOWLThing()); |
| 133 | // for(OWLClassExpression owlClassExpression : entry.getValue()) { | ||
| 134 | // conjunction = factory.getOWLObjectIntersectionOf(conjunction, owlClassExpression.accept(visitor)); | ||
| 135 | // } | ||
| 136 | // axioms.add(factory.getOWLSubClassOfAxiom(conjunction, factory.getOWLNothing())); | ||
| 137 | continue; // previously the "then" contained only this | ||
| 138 | } | ||
| 139 | else { | ||
| 140 | sub = factory.getOWLNamedIndividual(IRI.create(getIndividual(entry.getKey(), assignment).getIRI())); | ||
| 141 | for(OWLClassExpression clsExp : entry.getValue()) { | ||
| 142 | axioms.add(factory.getOWLClassAssertionAxiom(clsExp.accept(visitor), sub)); | ||
| 143 | } | ||
| 95 | } | 144 | } |
| 96 | } | 145 | } |
| 97 | return axioms; | 146 | return axioms; |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java index 93fbc98..51cb44d 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java | |||
| @@ -10,7 +10,6 @@ import uk.ac.ox.cs.pagoda.query.GapByStore4ID; | |||
| 10 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID2; | 10 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID2; |
| 11 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | 11 | import uk.ac.ox.cs.pagoda.query.QueryRecord; |
| 12 | import uk.ac.ox.cs.pagoda.query.QueryRecord.Step; | 12 | import uk.ac.ox.cs.pagoda.query.QueryRecord.Step; |
| 13 | import uk.ac.ox.cs.pagoda.reasoner.full.Checker; | ||
| 14 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | 13 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; |
| 15 | import uk.ac.ox.cs.pagoda.reasoner.light.KarmaQueryEngine; | 14 | import uk.ac.ox.cs.pagoda.reasoner.light.KarmaQueryEngine; |
| 16 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; | 15 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; |
| @@ -189,19 +188,21 @@ class MyQueryReasoner extends QueryReasoner { | |||
| 189 | return; | 188 | return; |
| 190 | 189 | ||
| 191 | OWLOntology relevantOntologySubset = extractRelevantOntologySubset(queryRecord); | 190 | OWLOntology relevantOntologySubset = extractRelevantOntologySubset(queryRecord); |
| 192 | // queryRecord.saveRelevantOntology("./fragment_query" + queryRecord.getQueryID() + ".owl"); | 191 | // queryRecord.saveRelevantOntology("/home/alessandro/Desktop/test-relevant-ontology.owl"); |
| 193 | 192 | ||
| 194 | if(properties.getUseSkolemUpperBound() && | 193 | if(properties.getUseSkolemUpperBound() && |
| 195 | querySkolemisedRelevantSubset(relevantOntologySubset, queryRecord)) | 194 | querySkolemisedRelevantSubset(relevantOntologySubset, queryRecord)) { |
| 196 | return; | 195 | return; |
| 196 | } | ||
| 197 | 197 | ||
| 198 | Timer t = new Timer(); | 198 | Timer t = new Timer(); |
| 199 | Checker summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT()); | 199 | HermitSummaryFilter summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT()); |
| 200 | summarisedChecker.check(queryRecord.getGapAnswers()); | 200 | summarisedChecker.check(queryRecord.getGapAnswers()); |
| 201 | summarisedChecker.dispose(); | 201 | // summarisedChecker.checkByFullReasoner(queryRecord.getGapAnswers()); |
| 202 | Utility.logDebug("Total time for full reasoner: " + t.duration()); | 202 | Utility.logDebug("Total time for full reasoner: " + t.duration()); |
| 203 | |||
| 203 | queryRecord.markAsProcessed(); | 204 | queryRecord.markAsProcessed(); |
| 204 | Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); | 205 | summarisedChecker.dispose(); |
| 205 | } | 206 | } |
| 206 | 207 | ||
| 207 | @Override | 208 | @Override |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java index 3a057ec..e8daa3b 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java | |||
| @@ -206,7 +206,7 @@ public abstract class QueryReasoner extends Disposable { | |||
| 206 | if you call twice, you will end up with a json file with multiple roots */ | 206 | if you call twice, you will end up with a json file with multiple roots */ |
| 207 | if(answerWriter != null) gson.toJson(queryRecords, answerWriter); | 207 | if(answerWriter != null) gson.toJson(queryRecords, answerWriter); |
| 208 | // queryRecords.stream().forEach(record -> Utility.logDebug(gson.toJson(record))); | 208 | // queryRecords.stream().forEach(record -> Utility.logDebug(gson.toJson(record))); |
| 209 | queryRecords.stream().forEach(record -> record.dispose()); | 209 | queryRecords.stream().forEach(QueryRecord::dispose); |
| 210 | } | 210 | } |
| 211 | 211 | ||
| 212 | @Override | 212 | @Override |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/full/Checker.java b/src/uk/ac/ox/cs/pagoda/reasoner/full/Checker.java index fd620a5..07adc6d 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/full/Checker.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/full/Checker.java | |||
| @@ -12,4 +12,6 @@ public abstract class Checker extends Disposable { | |||
| 12 | 12 | ||
| 13 | public abstract boolean isConsistent(); | 13 | public abstract boolean isConsistent(); |
| 14 | 14 | ||
| 15 | public abstract int getNoOfCalls(); | ||
| 16 | |||
| 15 | } | 17 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java b/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java index 35db0f2..cfae88b 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java | |||
| @@ -24,228 +24,255 @@ import java.util.Map; | |||
| 24 | import java.util.Set; | 24 | import java.util.Set; |
| 25 | 25 | ||
| 26 | public class HermitChecker extends Checker { | 26 | public class HermitChecker extends Checker { |
| 27 | 27 | ||
| 28 | protected OWLDataFactory factory; | 28 | protected OWLDataFactory factory; |
| 29 | protected String[][] answerVariable; | 29 | protected String[][] answerVariable; |
| 30 | protected OWLOntology ontology; | 30 | protected OWLOntology ontology; |
| 31 | protected QueryRecord record; | 31 | protected QueryRecord record; |
| 32 | protected QueryGraph qGraph = null; | 32 | protected QueryGraph qGraph = null; |
| 33 | boolean toCheck = true; | 33 | boolean toCheck = true; |
| 34 | AnswerTuple topAnswerTuple = null, botAnswerTuple = null; | 34 | AnswerTuple topAnswerTuple = null, botAnswerTuple = null; |
| 35 | private String queryText; | 35 | private String queryText; |
| 36 | private DLClause queryClause; | 36 | private DLClause queryClause; |
| 37 | private Reasoner hermit; | 37 | private Reasoner hermit; |
| 38 | private int tag = 0; | 38 | private int tag = 0; |
| 39 | private int counter = 0; | 39 | |
| 40 | private DependencyGraph dGraph = null; | 40 | public int getNoOfCalls() { |
| 41 | public HermitChecker(Checker checker) { | 41 | if(isDisposed()) throw new DisposedException(); |
| 42 | if (checker instanceof HermitChecker) { | 42 | return noOfCalls; |
| 43 | HermitChecker other = (HermitChecker) checker; | 43 | } |
| 44 | factory = other.factory; | 44 | |
| 45 | queryText = other.queryText; | 45 | private int noOfCalls = 0; |
| 46 | queryClause = other.queryClause; | 46 | private DependencyGraph dGraph = null; |
| 47 | answerVariable = other.answerVariable; | 47 | |
| 48 | ontology = other.ontology; | 48 | public HermitChecker(Checker checker) { |
| 49 | if(checker instanceof HermitChecker) { | ||
| 50 | HermitChecker other = (HermitChecker) checker; | ||
| 51 | factory = other.factory; | ||
| 52 | queryText = other.queryText; | ||
| 53 | queryClause = other.queryClause; | ||
| 54 | answerVariable = other.answerVariable; | ||
| 55 | ontology = other.ontology; | ||
| 49 | // record = other.record; | 56 | // record = other.record; |
| 50 | } | 57 | } |
| 51 | 58 | ||
| 52 | hermit = new Reasoner(ontology); | 59 | hermit = new Reasoner(ontology); |
| 53 | } | 60 | } |
| 54 | 61 | ||
| 55 | public HermitChecker(OWLOntology ontology, QueryRecord record, boolean toCheck) { | 62 | public HermitChecker(OWLOntology ontology, QueryRecord record, boolean toCheck) { |
| 56 | this.ontology = ontology; | 63 | this.ontology = ontology; |
| 57 | queryText = record.getQueryText(); | 64 | queryText = record.getQueryText(); |
| 58 | answerVariable = record.getVariables(); | 65 | answerVariable = record.getVariables(); |
| 59 | queryClause = record.getClause(); | 66 | queryClause = record.getClause(); |
| 60 | // this.record = record; | 67 | // this.record = record; |
| 61 | this.toCheck = toCheck; | 68 | this.toCheck = toCheck; |
| 62 | } | 69 | } |
| 63 | 70 | ||
| 64 | public HermitChecker(OWLOntology ontology, String queryText) { | 71 | public HermitChecker(OWLOntology ontology, String queryText) { |
| 65 | this.ontology = ontology; | 72 | this.ontology = ontology; |
| 66 | this.queryText = queryText; | 73 | this.queryText = queryText; |
| 67 | answerVariable = queryText == null ? null : ConjunctiveQueryHelper.getAnswerVariables(queryText); | 74 | answerVariable = queryText == null ? null : ConjunctiveQueryHelper.getAnswerVariables(queryText); |
| 68 | queryClause = DLClauseHelper.getQuery(queryText, null); | 75 | queryClause = DLClauseHelper.getQuery(queryText, null); |
| 69 | // this.record = null; | 76 | // this.record = null; |
| 70 | } | 77 | } |
| 71 | 78 | ||
| 72 | @Override | 79 | @Override |
| 73 | public int check(AnswerTuples answers) { | 80 | public int check(AnswerTuples answers) { |
| 74 | if(isDisposed()) throw new DisposedException(); | 81 | if(isDisposed()) throw new DisposedException(); |
| 75 | 82 | ||
| 76 | if(hermit == null) initialiseReasoner(); | 83 | if(hermit == null) initialiseReasoner(); |
| 77 | int answerCounter = 0, counter = 0; | 84 | int answerCounter = 0, counter = 0; |
| 78 | for(; answers.isValid(); answers.moveNext()) { | 85 | for(; answers.isValid(); answers.moveNext()) { |
| 79 | ++counter; | 86 | ++counter; |
| 80 | if(check(answers.getTuple())) ++answerCounter; | 87 | if(check(answers.getTuple())) ++answerCounter; |
| 81 | } | 88 | } |
| 82 | answers.dispose(); | 89 | answers.dispose(); |
| 83 | 90 | ||
| 84 | Utility.logDebug("The number of individuals to be checked by HermiT: " + counter, | 91 | Utility.logDebug("The number of individuals to be checked by HermiT: " + counter, |
| 85 | "The number of correct answers: " + answerCounter); | 92 | "The number of correct answers: " + answerCounter); |
| 86 | return answerCounter; | 93 | return answerCounter; |
| 87 | } | 94 | } |
| 88 | 95 | ||
| 89 | @Override | 96 | @Override |
| 90 | public boolean check(AnswerTuple answerTuple) { | 97 | public boolean check(AnswerTuple answerTuple) { |
| 91 | if(isDisposed()) throw new DisposedException(); | 98 | if(isDisposed()) throw new DisposedException(); |
| 92 | 99 | ||
| 93 | if(!toCheck) return false; | 100 | if(!toCheck) return false; |
| 94 | 101 | ++noOfCalls; | |
| 95 | if(hermit == null) initialiseReasoner(); | 102 | |
| 96 | if(tag != 0) return tag == 1; | 103 | if(tag != 0) return tag == 1; |
| 97 | ++counter; | 104 | if(hermit == null) initialiseReasoner(); |
| 98 | Timer t = new Timer(); | 105 | |
| 99 | Map<Variable, Term> sub = answerTuple.getAssignment(answerVariable[1]); | 106 | Timer t = new Timer(); |
| 100 | Set<OWLAxiom> toCheckAxioms = qGraph.getAssertions(sub); | 107 | Map<Variable, Term> sub = answerTuple.getAssignment(answerVariable[1]); |
| 108 | Set<OWLAxiom> toCheckAxioms = qGraph.getAssertions(sub); | ||
| 109 | |||
| 110 | // TODO complete | ||
| 111 | Set<OWLAxiom> toCheckExistentialAxioms = qGraph.getExistentialAxioms(); | ||
| 112 | |||
| 113 | // TODO possibly inefficient | ||
| 114 | for(OWLAxiom subclassAxiom : toCheckExistentialAxioms) { | ||
| 115 | Utility.logDebug("Checking consistency of ontology union " + subclassAxiom); | ||
| 116 | ontology.getOWLOntologyManager().addAxiom(ontology, subclassAxiom); | ||
| 117 | if(hermit.isConsistent()) { | ||
| 118 | Utility.logDebug("@TIME to check one tuple: " + t.duration()); | ||
| 119 | return false; | ||
| 120 | } | ||
| 121 | ontology.getOWLOntologyManager().removeAxiom(ontology, subclassAxiom); | ||
| 122 | } | ||
| 123 | |||
| 101 | 124 | ||
| 102 | // for (OWLAxiom axiom: toCheckAxioms) System.out.println(axiom.toString()); | 125 | // for (OWLAxiom axiom: toCheckAxioms) System.out.println(axiom.toString()); |
| 103 | 126 | ||
| 104 | if(hermit.isEntailed(toCheckAxioms)) { | 127 | // Utility.logInfo(toCheckAxioms); |
| 105 | Utility.logDebug("@TIME to check one tuple: " + t.duration()); | 128 | |
| 106 | return true; | 129 | if(hermit.isEntailed(toCheckAxioms)) { |
| 107 | } | 130 | Utility.logDebug("@TIME to check one tuple: " + t.duration()); |
| 108 | Utility.logDebug("@TIME to check one tuple: " + t.duration()); | 131 | return true; |
| 109 | return false; | 132 | } |
| 110 | } | 133 | Utility.logDebug("@TIME to check one tuple: " + t.duration()); |
| 111 | 134 | return false; | |
| 112 | @Override | 135 | } |
| 113 | public boolean isConsistent() { | 136 | |
| 114 | if(isDisposed()) throw new DisposedException(); | 137 | @Override |
| 115 | 138 | public boolean isConsistent() { | |
| 116 | if(hermit == null) initialiseReasoner(); | 139 | if(isDisposed()) throw new DisposedException(); |
| 117 | return hermit.isConsistent(); | 140 | |
| 118 | } | 141 | if(hermit == null) initialiseReasoner(); |
| 119 | 142 | return hermit.isConsistent(); | |
| 120 | public void dispose() { | 143 | } |
| 121 | super.dispose(); | 144 | |
| 122 | 145 | public void dispose() { | |
| 123 | Utility.logInfo("Hermit was called " + counter + " times."); | 146 | super.dispose(); |
| 124 | if(hermit != null) hermit.dispose(); | 147 | |
| 125 | hermit = null; | 148 | Utility.logDebug("Disposing of an instance of Hermit after " + noOfCalls + " calls"); |
| 126 | } | 149 | if(hermit != null) hermit.dispose(); |
| 127 | 150 | hermit = null; | |
| 128 | public void setDependencyGraph(DependencyGraph dGraph) { | 151 | } |
| 129 | if(isDisposed()) throw new DisposedException(); | 152 | |
| 130 | 153 | public void setDependencyGraph(DependencyGraph dGraph) { | |
| 131 | this.dGraph = dGraph; | 154 | if(isDisposed()) throw new DisposedException(); |
| 132 | } | 155 | |
| 133 | 156 | this.dGraph = dGraph; | |
| 134 | private void initialiseReasoner() { | 157 | } |
| 135 | qGraph = new QueryGraph(queryClause.getBodyAtoms(), answerVariable[1], ontology); | 158 | |
| 136 | OWLOntologyManager manager = ontology.getOWLOntologyManager(); | 159 | private void initialiseReasoner() { |
| 137 | factory = manager.getOWLDataFactory(); | 160 | qGraph = new QueryGraph(queryClause.getBodyAtoms(), answerVariable[1], ontology); |
| 138 | 161 | OWLOntologyManager manager = ontology.getOWLOntologyManager(); | |
| 139 | if(hermit != null) hermit.dispose(); | 162 | factory = manager.getOWLDataFactory(); |
| 140 | 163 | ||
| 141 | if(dGraph != null && answerVariable[1].length == 1 && (dGraph.getExits().size() > 1 || dGraph.getEntrances() | 164 | if(hermit != null) hermit.dispose(); |
| 142 | .size() > 1)) { | 165 | |
| 143 | Set<OWLAxiom> topAxioms = new HashSet<OWLAxiom>(); | 166 | if(dGraph != null && answerVariable[1].length == 1 && (dGraph.getExits().size() > 1 || dGraph.getEntrances() |
| 144 | Set<OWLAxiom> botAxioms = new HashSet<OWLAxiom>(); | 167 | .size() > 1)) { |
| 145 | addTopAndBotTuple(topAxioms, botAxioms); | 168 | Set<OWLAxiom> topAxioms = new HashSet<OWLAxiom>(); |
| 146 | manager.addAxioms(ontology, topAxioms); | 169 | Set<OWLAxiom> botAxioms = new HashSet<OWLAxiom>(); |
| 147 | manager.addAxioms(ontology, botAxioms); | 170 | addTopAndBotTuple(topAxioms, botAxioms); |
| 148 | hermit = new Reasoner(ontology); | 171 | manager.addAxioms(ontology, topAxioms); |
| 149 | boolean topValid = true; | 172 | manager.addAxioms(ontology, botAxioms); |
| 150 | if(!hermit.isConsistent() || topAnswerTuple != null && (topValid = check(topAnswerTuple))) { | 173 | hermit = new Reasoner(ontology); |
| 151 | hermit.dispose(); | 174 | boolean topValid = true; |
| 152 | manager.removeAxioms(ontology, topAxioms); | 175 | if(!hermit.isConsistent() || topAnswerTuple != null && (topValid = check(topAnswerTuple))) { |
| 153 | hermit = new Reasoner(ontology); | 176 | hermit.dispose(); |
| 154 | } | 177 | manager.removeAxioms(ontology, topAxioms); |
| 155 | else { | 178 | hermit = new Reasoner(ontology); |
| 156 | if(!topValid) tag = -1; | 179 | } |
| 157 | else if(botAnswerTuple != null && check(botAnswerTuple)) tag = 1; | 180 | else { |
| 158 | } | 181 | if(!topValid) tag = -1; |
| 159 | } | 182 | else if(botAnswerTuple != null && check(botAnswerTuple)) tag = 1; |
| 160 | else | 183 | } |
| 161 | hermit = new Reasoner(ontology); | 184 | } |
| 162 | } | 185 | else |
| 163 | 186 | hermit = new Reasoner(ontology); | |
| 164 | private void addTopAndBotTuple(Set<OWLAxiom> topAxioms, Set<OWLAxiom> botAxioms) { | 187 | } |
| 165 | String top_str = Namespace.PAGODA_ANONY + "top", bot_str = Namespace.PAGODA_ANONY + "bot"; | 188 | |
| 166 | topAnswerTuple = | 189 | private void addTopAndBotTuple(Set<OWLAxiom> topAxioms, Set<OWLAxiom> botAxioms) { |
| 167 | new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[]{uk.ac.ox.cs.JRDFox.model.Individual.create(top_str)}); | 190 | String top_str = Namespace.PAGODA_ANONY + "top", bot_str = Namespace.PAGODA_ANONY + "bot"; |
| 168 | botAnswerTuple = | 191 | topAnswerTuple = |
| 169 | new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[]{uk.ac.ox.cs.JRDFox.model.Individual.create(bot_str)}); | 192 | new AnswerTuple( |
| 170 | OWLIndividual top_ind = factory.getOWLNamedIndividual(IRI.create(top_str)), bot_ind = | 193 | new uk.ac.ox.cs.JRDFox.model.Individual[]{uk.ac.ox.cs.JRDFox.model.Individual.create(top_str)}); |
| 171 | factory.getOWLNamedIndividual(IRI.create(bot_str)); | 194 | botAnswerTuple = |
| 172 | Map<OWLAxiom, Integer> counter = new HashMap<OWLAxiom, Integer>(); | 195 | new AnswerTuple( |
| 173 | 196 | new uk.ac.ox.cs.JRDFox.model.Individual[]{uk.ac.ox.cs.JRDFox.model.Individual.create(bot_str)}); | |
| 174 | Set<String> topAnswers = new HashSet<String>(), botAnswers = new HashSet<String>(); | 197 | OWLIndividual top_ind = factory.getOWLNamedIndividual(IRI.create(top_str)), bot_ind = |
| 175 | OWLIndividual sub, obj; | 198 | factory.getOWLNamedIndividual(IRI.create(bot_str)); |
| 176 | if(dGraph.getExits().size() > 1) { | 199 | Map<OWLAxiom, Integer> counter = new HashMap<OWLAxiom, Integer>(); |
| 177 | for(Clique answerClique : dGraph.getExits()) | 200 | |
| 178 | topAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative() | 201 | Set<String> topAnswers = new HashSet<String>(), botAnswers = new HashSet<String>(); |
| 179 | .getAnswerTuple() | 202 | OWLIndividual sub, obj; |
| 180 | .getGroundTerm(0)).getIRI()); | 203 | if(dGraph.getExits().size() > 1) { |
| 181 | } | 204 | for(Clique answerClique : dGraph.getExits()) |
| 182 | else topAnswerTuple = null; | 205 | topAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative() |
| 183 | 206 | .getAnswerTuple() | |
| 184 | if(dGraph.getEntrances().size() > 1) { | 207 | .getGroundTerm(0)).getIRI()); |
| 185 | for(Clique answerClique : dGraph.getEntrances()) | 208 | } |
| 186 | botAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative() | 209 | else topAnswerTuple = null; |
| 187 | .getAnswerTuple() | 210 | |
| 188 | .getGroundTerm(0)).getIRI()); | 211 | if(dGraph.getEntrances().size() > 1) { |
| 189 | } | 212 | for(Clique answerClique : dGraph.getEntrances()) |
| 190 | else botAnswerTuple = null; | 213 | botAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative() |
| 191 | 214 | .getAnswerTuple() | |
| 192 | for(OWLAxiom axiom : ontology.getABoxAxioms(true)) | 215 | .getGroundTerm(0)).getIRI()); |
| 193 | if(axiom instanceof OWLClassAssertionAxiom) { | 216 | } |
| 194 | OWLClassAssertionAxiom ca = (OWLClassAssertionAxiom) axiom; | 217 | else botAnswerTuple = null; |
| 195 | sub = ca.getIndividual(); | 218 | |
| 196 | if(topAnswers.contains(sub.toStringID())) | 219 | for(OWLAxiom axiom : ontology.getABoxAxioms(true)) |
| 197 | topAxioms.add(factory.getOWLClassAssertionAxiom(ca.getClassExpression(), top_ind)); | 220 | if(axiom instanceof OWLClassAssertionAxiom) { |
| 198 | if(botAnswers.contains(sub.toStringID())) | 221 | OWLClassAssertionAxiom ca = (OWLClassAssertionAxiom) axiom; |
| 199 | inc(counter, factory.getOWLClassAssertionAxiom(ca.getClassExpression(), bot_ind)); | 222 | sub = ca.getIndividual(); |
| 200 | } | 223 | if(topAnswers.contains(sub.toStringID())) |
| 201 | else if(axiom instanceof OWLObjectPropertyAssertionAxiom) { | 224 | topAxioms.add(factory.getOWLClassAssertionAxiom(ca.getClassExpression(), top_ind)); |
| 202 | OWLObjectPropertyAssertionAxiom oa = (OWLObjectPropertyAssertionAxiom) axiom; | 225 | if(botAnswers.contains(sub.toStringID())) |
| 203 | sub = oa.getSubject(); | 226 | inc(counter, factory.getOWLClassAssertionAxiom(ca.getClassExpression(), bot_ind)); |
| 204 | obj = oa.getObject(); | 227 | } |
| 205 | if(topAnswers.contains(sub.toStringID())) | 228 | else if(axiom instanceof OWLObjectPropertyAssertionAxiom) { |
| 206 | if(topAnswers.contains(obj.toStringID())) | 229 | OWLObjectPropertyAssertionAxiom oa = (OWLObjectPropertyAssertionAxiom) axiom; |
| 207 | topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, top_ind)); | 230 | sub = oa.getSubject(); |
| 208 | else | 231 | obj = oa.getObject(); |
| 209 | topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, obj)); | 232 | if(topAnswers.contains(sub.toStringID())) |
| 210 | else { | 233 | if(topAnswers.contains(obj.toStringID())) |
| 211 | if(topAnswers.contains(obj.toStringID())) | 234 | topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, top_ind)); |
| 212 | topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, top_ind)); | 235 | else |
| 213 | } | 236 | topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, obj)); |
| 214 | 237 | else { | |
| 215 | if(botAnswers.contains(sub.toStringID())) | 238 | if(topAnswers.contains(obj.toStringID())) |
| 216 | if(botAnswers.contains(obj.toStringID())) | 239 | topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, top_ind)); |
| 217 | inc(counter, factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), bot_ind, bot_ind)); | 240 | } |
| 218 | else | 241 | |
| 219 | inc(counter, factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), bot_ind, obj)); | 242 | if(botAnswers.contains(sub.toStringID())) |
| 220 | else { | 243 | if(botAnswers.contains(obj.toStringID())) |
| 221 | if(botAnswers.contains(obj.toStringID())) | 244 | inc(counter, factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), bot_ind, bot_ind)); |
| 222 | inc(counter, factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, bot_ind)); | 245 | else |
| 223 | } | 246 | inc(counter, factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), bot_ind, obj)); |
| 224 | 247 | else { | |
| 225 | } | 248 | if(botAnswers.contains(obj.toStringID())) |
| 226 | else if(axiom instanceof OWLDataPropertyAssertionAxiom) { | 249 | inc(counter, factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, bot_ind)); |
| 227 | OWLDataPropertyAssertionAxiom da = (OWLDataPropertyAssertionAxiom) axiom; | 250 | } |
| 228 | sub = da.getSubject(); | 251 | |
| 229 | if(topAnswers.contains(sub.toStringID())) | 252 | } |
| 230 | topAxioms.add(factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), top_ind, da.getObject())); | 253 | else if(axiom instanceof OWLDataPropertyAssertionAxiom) { |
| 231 | 254 | OWLDataPropertyAssertionAxiom da = (OWLDataPropertyAssertionAxiom) axiom; | |
| 232 | if(botAnswers.contains(sub.toStringID())) | 255 | sub = da.getSubject(); |
| 233 | inc(counter, factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), bot_ind, da.getObject())); | 256 | if(topAnswers.contains(sub.toStringID())) |
| 234 | } | 257 | topAxioms.add(factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), top_ind, da.getObject())); |
| 235 | 258 | ||
| 236 | int number = botAnswers.size(); | 259 | if(botAnswers.contains(sub.toStringID())) |
| 237 | for(Map.Entry<OWLAxiom, Integer> entry : counter.entrySet()) { | 260 | inc(counter, factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), bot_ind, da.getObject())); |
| 238 | if(entry.getValue() == number) | 261 | } |
| 239 | botAxioms.add(entry.getKey()); | 262 | |
| 240 | } | 263 | int number = botAnswers.size(); |
| 241 | } | 264 | for(Map.Entry<OWLAxiom, Integer> entry : counter.entrySet()) { |
| 242 | 265 | if(entry.getValue() == number) | |
| 243 | private void inc(Map<OWLAxiom, Integer> counter, OWLAxiom newAxiom) { | 266 | botAxioms.add(entry.getKey()); |
| 244 | if(isDisposed()) throw new DisposedException(); | 267 | } |
| 245 | 268 | } | |
| 246 | Integer number = counter.get(newAxiom); | 269 | |
| 247 | if(number == null) counter.put(newAxiom, 1); | 270 | private void inc(Map<OWLAxiom, Integer> counter, OWLAxiom newAxiom) { |
| 248 | else counter.put(newAxiom, number + 1); | 271 | if(isDisposed()) throw new DisposedException(); |
| 249 | } | 272 | |
| 273 | Integer number = counter.get(newAxiom); | ||
| 274 | if(number == null) counter.put(newAxiom, 1); | ||
| 275 | else counter.put(newAxiom, number + 1); | ||
| 276 | } | ||
| 250 | 277 | ||
| 251 | } | 278 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/rules/Program.java b/src/uk/ac/ox/cs/pagoda/rules/Program.java index afc32d4..85000e3 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/Program.java +++ b/src/uk/ac/ox/cs/pagoda/rules/Program.java | |||
| @@ -119,7 +119,7 @@ protected PredicateDependency dependencyGraph; | |||
| 119 | } catch(IOException e) { | 119 | } catch(IOException e) { |
| 120 | e.printStackTrace(); | 120 | e.printStackTrace(); |
| 121 | } | 121 | } |
| 122 | Utility.logDebug("The rules are saved in " + getOutputPath() + "."); | 122 | Utility.logInfo("The rules are saved in " + getOutputPath() + "."); |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | @Override | 125 | @Override |
diff --git a/src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java b/src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java index f3f08e9..95f2cbb 100644 --- a/src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java +++ b/src/uk/ac/ox/cs/pagoda/summary/HermitSummaryFilter.java | |||
| @@ -111,6 +111,11 @@ public class HermitSummaryFilter extends Checker { | |||
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | @Override | 113 | @Override |
| 114 | public int getNoOfCalls() { | ||
| 115 | return summarisedHermiT.getNoOfCalls() + endomorphismChecker.getNoOfCalls(); | ||
| 116 | } | ||
| 117 | |||
| 118 | @Override | ||
| 114 | public int check(AnswerTuples answers) { | 119 | public int check(AnswerTuples answers) { |
| 115 | if(isDisposed()) throw new DisposedException(); | 120 | if(isDisposed()) throw new DisposedException(); |
| 116 | 121 | ||
| @@ -183,8 +188,14 @@ public class HermitSummaryFilter extends Checker { | |||
| 183 | public void dispose() { | 188 | public void dispose() { |
| 184 | super.dispose(); | 189 | super.dispose(); |
| 185 | 190 | ||
| 186 | if(summarisedHermiT != null) summarisedHermiT.dispose(); | 191 | if(summarisedHermiT != null) { |
| 187 | endomorphismChecker.dispose(); | 192 | Utility.logInfo("SummarisedHermit was called " + summarisedHermiT.getNoOfCalls() + " times"); |
| 193 | summarisedHermiT.dispose(); | ||
| 194 | } | ||
| 195 | if(endomorphismChecker != null) { | ||
| 196 | Utility.logInfo("Hermit was called " + endomorphismChecker.getNoOfCalls() + " times"); | ||
| 197 | endomorphismChecker.dispose(); | ||
| 198 | } | ||
| 188 | } | 199 | } |
| 189 | 200 | ||
| 190 | private void initialiseSummarisedReasoner() { | 201 | private void initialiseSummarisedReasoner() { |
diff --git a/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java b/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java index e501821..4991d0d 100644 --- a/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java +++ b/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java | |||
| @@ -43,14 +43,14 @@ public class PagodaProperties { | |||
| 43 | defaultUseAlwaysSimpleUpperBound = | 43 | defaultUseAlwaysSimpleUpperBound = |
| 44 | Boolean.parseBoolean(config.getProperty("useAlwaysSimpleUpperBound")); | 44 | Boolean.parseBoolean(config.getProperty("useAlwaysSimpleUpperBound")); |
| 45 | if(defaultUseAlwaysSimpleUpperBound) | 45 | if(defaultUseAlwaysSimpleUpperBound) |
| 46 | logger.info("By default the simple upper bound is always used"); | 46 | logger.debug("By default the simple upper bound is always used"); |
| 47 | } | 47 | } |
| 48 | if(config.containsKey("useSkolemUpperBound")) { | 48 | if(config.containsKey("useSkolemUpperBound")) { |
| 49 | defaultUseSkolemUpperBound = Boolean.parseBoolean(config.getProperty("useSkolemUpperBound")); | 49 | defaultUseSkolemUpperBound = Boolean.parseBoolean(config.getProperty("useSkolemUpperBound")); |
| 50 | if(defaultUseSkolemUpperBound) | 50 | if(defaultUseSkolemUpperBound) |
| 51 | logger.info("By default the Skolem upper bound is enabled"); | 51 | logger.debug("By default the Skolem upper bound is enabled"); |
| 52 | else | 52 | else |
| 53 | logger.info("By default the Skolem upper bound is disabled"); | 53 | logger.debug("By default the Skolem upper bound is disabled"); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | } catch(IOException e) { | 56 | } catch(IOException e) { |
