diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-07-08 18:53:00 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-07-08 18:53:00 +0100 |
| commit | 8241a535a55508b6c504f4f0b426612fe95d15a5 (patch) | |
| tree | 720a6572bbdf303b9ddfe69dd461b6640b36e6a0 | |
| parent | 77dd8849f8e79d324c8e12cd699912f284a8fdba (diff) | |
| download | ACQuA-8241a535a55508b6c504f4f0b426612fe95d15a5.tar.gz ACQuA-8241a535a55508b6c504f4f0b426612fe95d15a5.zip | |
Internalisation: added condition for existential variables (classes HermitChecker and QueryGraph).
Answer dependencies: found bug, trying to solve; excluding dependency analysis solve the problem.
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/endomorph/DependencyGraph.java | 12 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/endomorph/Endomorph.java | 29 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/query/rollup/QueryGraph.java | 3 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java | 30 | ||||
| -rw-r--r-- | test/resources/MainTests.xml | 8 | ||||
| -rw-r--r-- | test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java | 60 |
6 files changed, 111 insertions, 31 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/endomorph/DependencyGraph.java b/src/uk/ac/ox/cs/pagoda/endomorph/DependencyGraph.java index e7f1c96..8514808 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/DependencyGraph.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/DependencyGraph.java | |||
| @@ -114,23 +114,23 @@ public class DependencyGraph { | |||
| 114 | 114 | ||
| 115 | // print(); | 115 | // print(); |
| 116 | 116 | ||
| 117 | topolocialOrder = null; | 117 | topologicalOrder = null; |
| 118 | Utility.logDebug("link: " + link); | 118 | Utility.logDebug("link: " + link); |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | LinkedList<Clique> topolocialOrder = null; | 121 | LinkedList<Clique> topologicalOrder = null; |
| 122 | 122 | ||
| 123 | public LinkedList<Clique> getTopologicalOrder() { | 123 | public LinkedList<Clique> getTopologicalOrder() { |
| 124 | if (topolocialOrder != null) return topolocialOrder; | 124 | if (topologicalOrder != null) return topologicalOrder; |
| 125 | 125 | ||
| 126 | topolocialOrder = new LinkedList<Clique>(); | 126 | topologicalOrder = new LinkedList<Clique>(); |
| 127 | Queue<Clique> toVisit = new LinkedList<Clique>(entrances); | 127 | Queue<Clique> toVisit = new LinkedList<Clique>(entrances); |
| 128 | Map<Clique, Integer> toVisitedInComingDegree = new HashMap<Clique, Integer>(); | 128 | Map<Clique, Integer> toVisitedInComingDegree = new HashMap<Clique, Integer>(); |
| 129 | 129 | ||
| 130 | int count; | 130 | int count; |
| 131 | while (!toVisit.isEmpty()) { | 131 | while (!toVisit.isEmpty()) { |
| 132 | Clique cu = toVisit.remove(); | 132 | Clique cu = toVisit.remove(); |
| 133 | topolocialOrder.add(cu); | 133 | topologicalOrder.add(cu); |
| 134 | if (outGoingEdges.containsKey(cu)) | 134 | if (outGoingEdges.containsKey(cu)) |
| 135 | for (Clique cv: outGoingEdges.get(cu)) { | 135 | for (Clique cv: outGoingEdges.get(cu)) { |
| 136 | if (toVisitedInComingDegree.containsKey(cv)) { | 136 | if (toVisitedInComingDegree.containsKey(cv)) { |
| @@ -144,7 +144,7 @@ public class DependencyGraph { | |||
| 144 | } | 144 | } |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | return topolocialOrder; | 147 | return topologicalOrder; |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | private void addNodeTuple(NodeTuple u) { | 150 | private void addNodeTuple(NodeTuple u) { |
diff --git a/src/uk/ac/ox/cs/pagoda/endomorph/Endomorph.java b/src/uk/ac/ox/cs/pagoda/endomorph/Endomorph.java index 1c853d7..9ca73a1 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/Endomorph.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/Endomorph.java | |||
| @@ -34,7 +34,11 @@ public class Endomorph extends Checker { | |||
| 34 | graph = new Graph(record.getRelevantOntology()); | 34 | graph = new Graph(record.getRelevantOntology()); |
| 35 | dGraph = new DependencyGraph(graph); | 35 | dGraph = new DependencyGraph(graph); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | /* | ||
| 39 | * FIXME | ||
| 40 | * The result is unsound. The output is not deterministic. | ||
| 41 | * */ | ||
| 38 | @Override | 42 | @Override |
| 39 | public int check(AnswerTuples answerTuples) { | 43 | public int check(AnswerTuples answerTuples) { |
| 40 | if(isDisposed()) throw new DisposedException(); | 44 | if(isDisposed()) throw new DisposedException(); |
| @@ -57,11 +61,26 @@ public class Endomorph extends Checker { | |||
| 57 | Utility.logInfo("The number of individuals to be checked by Homomorphism checker: " + counter); | 61 | Utility.logInfo("The number of individuals to be checked by Homomorphism checker: " + counter); |
| 58 | // CheckPlan plan = new PlainPlan(this.checker, dGraph.cliques); | 62 | // CheckPlan plan = new PlainPlan(this.checker, dGraph.cliques); |
| 59 | // CheckPlan plan = new OpenEndMultiThreadPlan(this.checker, dGraph); | 63 | // CheckPlan plan = new OpenEndMultiThreadPlan(this.checker, dGraph); |
| 60 | CheckPlan plan = new OpenEndPlan(fullReasoner, dGraph, m_record); | 64 | |
| 61 | int answerCounter = plan.check(); | 65 | CheckPlan plan = new OpenEndPlan(fullReasoner, dGraph, m_record); |
| 62 | 66 | int answerCounter = plan.check(); | |
| 67 | |||
| 68 | |||
| 69 | // // BEGIN: debugging code | ||
| 70 | // Set<AnswerTuple> validatedAnswers = new HashSet<>(); | ||
| 71 | // for (answerTuples.reset(); answerTuples.isValid(); answerTuples.moveNext()) { | ||
| 72 | // if(fullReasoner.check(answerTuples.getTuple())) { | ||
| 73 | // validatedAnswers.add(answerTuples.getTuple()); | ||
| 74 | // } | ||
| 75 | // } | ||
| 76 | // m_record.addLowerBoundAnswers(validatedAnswers); | ||
| 77 | // | ||
| 78 | // Utility.logDebug("The number of correct answers: " + validatedAnswers.size()); | ||
| 79 | // return validatedAnswers.size(); | ||
| 80 | //// END: debugging code | ||
| 81 | |||
| 63 | Utility.logDebug("The number of correct answers: " + answerCounter); | 82 | Utility.logDebug("The number of correct answers: " + answerCounter); |
| 64 | return answerCounter; | 83 | return answerCounter; |
| 65 | } | 84 | } |
| 66 | 85 | ||
| 67 | public OWLOntology getOntology() { | 86 | public OWLOntology getOntology() { |
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 116e724..02697b8 100644 --- a/src/uk/ac/ox/cs/pagoda/query/rollup/QueryGraph.java +++ b/src/uk/ac/ox/cs/pagoda/query/rollup/QueryGraph.java | |||
| @@ -109,8 +109,7 @@ public class QueryGraph { | |||
| 109 | Set<OWLAxiom> axioms = new HashSet<>(); | 109 | Set<OWLAxiom> axioms = new HashSet<>(); |
| 110 | for(Map.Entry<Term, Set<OWLClassExpression>> entry : concepts.map.entrySet()) { | 110 | for(Map.Entry<Term, Set<OWLClassExpression>> entry : concepts.map.entrySet()) { |
| 111 | if(existVars.contains(entry.getKey())) { | 111 | if(existVars.contains(entry.getKey())) { |
| 112 | OWLClassExpression conjunction = | 112 | OWLClassExpression conjunction = factory.getOWLThing(); |
| 113 | factory.getOWLObjectIntersectionOf(factory.getOWLThing()); | ||
| 114 | for(OWLClassExpression owlClassExpression : entry.getValue()) { | 113 | for(OWLClassExpression owlClassExpression : entry.getValue()) { |
| 115 | conjunction = factory.getOWLObjectIntersectionOf(conjunction, owlClassExpression.accept(visitor)); | 114 | conjunction = factory.getOWLObjectIntersectionOf(conjunction, owlClassExpression.accept(visitor)); |
| 116 | } | 115 | } |
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 9574845..0362fc2 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java | |||
| @@ -106,19 +106,23 @@ public class HermitChecker extends Checker { | |||
| 106 | Map<Variable, Term> sub = answerTuple.getAssignment(answerVariable[1]); | 106 | Map<Variable, Term> sub = answerTuple.getAssignment(answerVariable[1]); |
| 107 | Set<OWLAxiom> toCheckAxioms = qGraph.getAssertions(sub); | 107 | Set<OWLAxiom> toCheckAxioms = qGraph.getAssertions(sub); |
| 108 | 108 | ||
| 109 | // // TODO complete | 109 | // TODO complete |
| 110 | // Set<OWLAxiom> toCheckExistentialAxioms = qGraph.getExistentialAxioms(sub); | 110 | Set<OWLAxiom> toCheckExistentialAxioms = qGraph.getExistentialAxioms(sub); |
| 111 | // | 111 | |
| 112 | // // TODO possibly inefficient | 112 | // TODO possibly inefficient |
| 113 | // for(OWLAxiom subclassAxiom : toCheckExistentialAxioms) { | 113 | for(OWLAxiom subclassAxiom : toCheckExistentialAxioms) { |
| 114 | // Utility.logInfo("Checking consistency of ontology union " + subclassAxiom); | 114 | Utility.logDebug("Checking consistency of ontology union " + subclassAxiom); |
| 115 | // ontology.getOWLOntologyManager().addAxiom(ontology, subclassAxiom); | 115 | ontology.getOWLOntologyManager().addAxiom(ontology, subclassAxiom); |
| 116 | // if(hermit.isConsistent()) { | 116 | hermit.flush(); |
| 117 | // Utility.logDebug("@TIME to check one tuple: " + t.duration()); | 117 | if(hermit.isConsistent()) { |
| 118 | // return false; | 118 | ontology.getOWLOntologyManager().removeAxiom(ontology, subclassAxiom); |
| 119 | // } | 119 | hermit.flush(); |
| 120 | // ontology.getOWLOntologyManager().removeAxiom(ontology, subclassAxiom); | 120 | Utility.logDebug("@TIME to check one tuple: " + t.duration()); |
| 121 | // } | 121 | return false; |
| 122 | } | ||
| 123 | ontology.getOWLOntologyManager().removeAxiom(ontology, subclassAxiom); | ||
| 124 | hermit.flush(); | ||
| 125 | } | ||
| 122 | 126 | ||
| 123 | 127 | ||
| 124 | // for (OWLAxiom axiom: toCheckAxioms) System.out.println(axiom.toString()); | 128 | // for (OWLAxiom axiom: toCheckAxioms) System.out.println(axiom.toString()); |
diff --git a/test/resources/MainTests.xml b/test/resources/MainTests.xml index cfe6184..db8d977 100644 --- a/test/resources/MainTests.xml +++ b/test/resources/MainTests.xml | |||
| @@ -5,17 +5,17 @@ | |||
| 5 | <test name="main"> | 5 | <test name="main"> |
| 6 | <groups> | 6 | <groups> |
| 7 | <run> | 7 | <run> |
| 8 | <!--<include name="correctness"/>--> | 8 | <include name="correctness"/> |
| 9 | <!--<include name="light"/>--> | 9 | <!--<include name="light"/>--> |
| 10 | <!--<include name="justExecute"/>--> | 10 | <!--<include name="justExecute"/>--> |
| 11 | <!--<!–<include name="heavy"/>–>--> | 11 | <!--<!–<include name="heavy"/>–>--> |
| 12 | <include name="nonOriginal"/> | 12 | <!--<include name="nonOriginal"/>--> |
| 13 | </run> | 13 | </run> |
| 14 | </groups> | 14 | </groups> |
| 15 | <classes> | 15 | <classes> |
| 16 | <!--<class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaReactome"/>--> | 16 | <!--<class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaReactome"/>--> |
| 17 | <class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaUOBM"/> | 17 | <!--<class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaUOBM"/>--> |
| 18 | <!--<class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaLUBM"/>--> | 18 | <class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaLUBM"/> |
| 19 | <!--Fly does not terminate: query-5 looks really hard--> | 19 | <!--Fly does not terminate: query-5 looks really hard--> |
| 20 | <!--<class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaFLY"/>--> | 20 | <!--<class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaFLY"/>--> |
| 21 | <!--<class name="uk.ac.ox.cs.pagoda.global_tests.SkolemisationTests"/>--> | 21 | <!--<class name="uk.ac.ox.cs.pagoda.global_tests.SkolemisationTests"/>--> |
diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java b/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java index 19e0b2a..6e60e24 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java | |||
| @@ -23,6 +23,64 @@ public class BugTests { | |||
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | @Test | 25 | @Test |
| 26 | public void minimumCardinalityAxiom2() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 27 | |||
| 28 | /* | ||
| 29 | * Build test ontology | ||
| 30 | * */ | ||
| 31 | |||
| 32 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 33 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 34 | OWLOntology ontology = manager.createOntology(); | ||
| 35 | |||
| 36 | // OWLClass student = factory.getOWLClass(getEntityIRI("Student")); | ||
| 37 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(student)); | ||
| 38 | // OWLClass course = factory.getOWLClass(getEntityIRI("Course")); | ||
| 39 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(course)); | ||
| 40 | OWLClass hardWorkingStudent = factory.getOWLClass(getEntityIRI("HardWorkingStudent")); | ||
| 41 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(hardWorkingStudent)); | ||
| 42 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 43 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 44 | OWLObjectProperty takesCourse = factory.getOWLObjectProperty(IRI.create(String.format(NS, "takesCourse"))); | ||
| 45 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(takesCourse)); | ||
| 46 | |||
| 47 | // Class assertions | ||
| 48 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(hardWorkingStudent, a)); // HardWorkingStudent(a) | ||
| 49 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(hardWorkingStudent, b)); // HardWorkingStudent(b) | ||
| 50 | |||
| 51 | // Minimum cardinality axiom | ||
| 52 | manager.addAxiom(ontology, | ||
| 53 | factory.getOWLEquivalentClassesAxiom(hardWorkingStudent, | ||
| 54 | factory.getOWLObjectMinCardinality(3, | ||
| 55 | takesCourse))); | ||
| 56 | |||
| 57 | // manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 58 | |||
| 59 | /* | ||
| 60 | * Test one query | ||
| 61 | * */ | ||
| 62 | |||
| 63 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 64 | pagoda.loadOntology(ontology); | ||
| 65 | if (pagoda.preprocess()) { | ||
| 66 | String query = "select distinct ?x ?y " + | ||
| 67 | " where { " | ||
| 68 | + " ?x <" + takesCourse.toStringID() + "> _:z . " | ||
| 69 | + " ?y <" + takesCourse.toStringID() + "> _:z " + | ||
| 70 | " }"; | ||
| 71 | AnswerTuples answers = pagoda.evaluate(query); | ||
| 72 | int count = 0; | ||
| 73 | for (AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 74 | ans = answers.getTuple(); | ||
| 75 | TestUtil.logInfo(ans); | ||
| 76 | count++; | ||
| 77 | } | ||
| 78 | Assert.assertEquals(count, 2); | ||
| 79 | } | ||
| 80 | pagoda.dispose(); | ||
| 81 | } | ||
| 82 | |||
| 83 | // @Test | ||
| 26 | public void minimumCardinalityAxiom() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | 84 | public void minimumCardinalityAxiom() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { |
| 27 | 85 | ||
| 28 | /* | 86 | /* |
| @@ -107,7 +165,7 @@ public class BugTests { | |||
| 107 | * @throws IOException | 165 | * @throws IOException |
| 108 | * @throws OWLOntologyStorageException | 166 | * @throws OWLOntologyStorageException |
| 109 | */ | 167 | */ |
| 110 | @Test | 168 | // @Test |
| 111 | public void rTest() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | 169 | public void rTest() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { |
| 112 | 170 | ||
| 113 | /* | 171 | /* |
