diff options
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java')
| -rw-r--r-- | test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java | 240 |
1 files changed, 0 insertions, 240 deletions
diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java b/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java deleted file mode 100644 index 3f14ec7..0000000 --- a/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java +++ /dev/null | |||
| @@ -1,240 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import org.semanticweb.owlapi.apibinding.OWLManager; | ||
| 4 | import org.semanticweb.owlapi.model.*; | ||
| 5 | import org.testng.Assert; | ||
| 6 | import org.testng.annotations.Test; | ||
| 7 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | ||
| 8 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 9 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 10 | import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | ||
| 11 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 12 | |||
| 13 | import java.io.IOException; | ||
| 14 | import java.nio.file.Files; | ||
| 15 | import java.nio.file.Paths; | ||
| 16 | |||
| 17 | import static uk.ac.ox.cs.pagoda.util.TestUtil.getEntityIRI; | ||
| 18 | |||
| 19 | public class BugTests { | ||
| 20 | |||
| 21 | |||
| 22 | |||
| 23 | @Test | ||
| 24 | public void minimumCardinalityAxiom2() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 25 | |||
| 26 | /* | ||
| 27 | * Build test ontology | ||
| 28 | * */ | ||
| 29 | |||
| 30 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 31 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 32 | OWLOntology ontology = manager.createOntology(); | ||
| 33 | |||
| 34 | // OWLClass student = factory.getOWLClass(getEntityIRI("Student")); | ||
| 35 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(student)); | ||
| 36 | // OWLClass course = factory.getOWLClass(getEntityIRI("Course")); | ||
| 37 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(course)); | ||
| 38 | OWLClass hardWorkingStudent = factory.getOWLClass(getEntityIRI("HardWorkingStudent")); | ||
| 39 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(hardWorkingStudent)); | ||
| 40 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 41 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 42 | OWLObjectProperty takesCourse = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "takesCourse"))); | ||
| 43 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(takesCourse)); | ||
| 44 | |||
| 45 | // Class assertions | ||
| 46 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(hardWorkingStudent, a)); // HardWorkingStudent(a) | ||
| 47 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(hardWorkingStudent, b)); // HardWorkingStudent(b) | ||
| 48 | |||
| 49 | // Minimum cardinality axiom | ||
| 50 | manager.addAxiom(ontology, | ||
| 51 | factory.getOWLEquivalentClassesAxiom(hardWorkingStudent, | ||
| 52 | factory.getOWLObjectMinCardinality(3, | ||
| 53 | takesCourse))); | ||
| 54 | |||
| 55 | // manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 56 | |||
| 57 | /* | ||
| 58 | * Test one query | ||
| 59 | * */ | ||
| 60 | |||
| 61 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 62 | pagoda.loadOntology(ontology); | ||
| 63 | if (pagoda.preprocess()) { | ||
| 64 | String query = "select distinct ?x ?y " + | ||
| 65 | " where { " | ||
| 66 | + " ?x <" + takesCourse.toStringID() + "> _:z . " | ||
| 67 | + " ?y <" + takesCourse.toStringID() + "> _:z " + | ||
| 68 | " }"; | ||
| 69 | AnswerTuples answers = pagoda.evaluate(query); | ||
| 70 | int count = 0; | ||
| 71 | for (AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 72 | ans = answers.getTuple(); | ||
| 73 | TestUtil.logInfo(ans); | ||
| 74 | count++; | ||
| 75 | } | ||
| 76 | Assert.assertEquals(count, 2); | ||
| 77 | } | ||
| 78 | pagoda.dispose(); | ||
| 79 | } | ||
| 80 | |||
| 81 | // @Test | ||
| 82 | public void minimumCardinalityAxiom() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 83 | |||
| 84 | /* | ||
| 85 | * Build test ontology | ||
| 86 | * */ | ||
| 87 | |||
| 88 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 89 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 90 | OWLOntology ontology = manager.createOntology(); | ||
| 91 | |||
| 92 | OWLClass student = factory.getOWLClass(getEntityIRI("Student")); | ||
| 93 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(student)); | ||
| 94 | OWLClass course = factory.getOWLClass(getEntityIRI("Course")); | ||
| 95 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(course)); | ||
| 96 | OWLClass hardWorkingStudent = factory.getOWLClass(getEntityIRI("HardWorkingStudent")); | ||
| 97 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(hardWorkingStudent)); | ||
| 98 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 99 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 100 | OWLNamedIndividual c1 = factory.getOWLNamedIndividual(getEntityIRI("c1")); | ||
| 101 | OWLNamedIndividual c2 = factory.getOWLNamedIndividual(getEntityIRI("c2")); | ||
| 102 | OWLNamedIndividual c3 = factory.getOWLNamedIndividual(getEntityIRI("c3")); | ||
| 103 | OWLNamedIndividual d1 = factory.getOWLNamedIndividual(getEntityIRI("d1")); | ||
| 104 | OWLNamedIndividual d2 = factory.getOWLNamedIndividual(getEntityIRI("d2")); | ||
| 105 | OWLNamedIndividual d3 = factory.getOWLNamedIndividual(getEntityIRI("d3")); | ||
| 106 | OWLObjectProperty takesCourse = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "takesCourse"))); | ||
| 107 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(takesCourse)); | ||
| 108 | |||
| 109 | // Class assertions | ||
| 110 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(student, a)); // Student(a) | ||
| 111 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(student, b)); // Student(b) | ||
| 112 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, c1)); // Course(c1) | ||
| 113 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, c2)); // Course(c2) | ||
| 114 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, c3)); // Course(c3) | ||
| 115 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, d1)); // Course(d1) | ||
| 116 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, d2)); // Course(d2) | ||
| 117 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, d3)); // Course(d3) | ||
| 118 | |||
| 119 | // Role assertions | ||
| 120 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, a, c1)); // takesCourse(a,c1) | ||
| 121 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, a, c2)); // takesCourse(a,c2) | ||
| 122 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, a, c3)); // takesCourse(a,c3) | ||
| 123 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, b, d1)); // takesCourse(b,d1) | ||
| 124 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, b, d2)); // takesCourse(b,d2) | ||
| 125 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, b, d3)); // takesCourse(b,d3) | ||
| 126 | |||
| 127 | // Minimum cardinality axiom | ||
| 128 | manager.addAxiom(ontology, | ||
| 129 | factory.getOWLEquivalentClassesAxiom(hardWorkingStudent, | ||
| 130 | factory.getOWLObjectMinCardinality(3, | ||
| 131 | takesCourse))); | ||
| 132 | |||
| 133 | manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 134 | |||
| 135 | /* | ||
| 136 | * Test one query | ||
| 137 | * */ | ||
| 138 | |||
| 139 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 140 | pagoda.loadOntology(ontology); | ||
| 141 | if (pagoda.preprocess()) { | ||
| 142 | String query = "select distinct ?x ?y " + | ||
| 143 | " where { " | ||
| 144 | + " ?x <" + takesCourse.toStringID() + "> _:z . " | ||
| 145 | + " ?y <" + takesCourse.toStringID() + "> _:z " + | ||
| 146 | " }"; | ||
| 147 | AnswerTuples answers = pagoda.evaluate(query); | ||
| 148 | int count = 0; | ||
| 149 | for (AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 150 | ans = answers.getTuple(); | ||
| 151 | TestUtil.logInfo(ans); | ||
| 152 | count++; | ||
| 153 | } | ||
| 154 | Assert.assertEquals(count, 2); | ||
| 155 | } | ||
| 156 | pagoda.dispose(); | ||
| 157 | } | ||
| 158 | |||
| 159 | /** | ||
| 160 | * Bug: the relevant ontology is not a subset of the original one. | ||
| 161 | * | ||
| 162 | * @throws OWLOntologyCreationException | ||
| 163 | * @throws IOException | ||
| 164 | * @throws OWLOntologyStorageException | ||
| 165 | */ | ||
| 166 | // @Test | ||
| 167 | public void rTest() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 168 | |||
| 169 | /* | ||
| 170 | * Build test ontology | ||
| 171 | * */ | ||
| 172 | |||
| 173 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 174 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 175 | OWLOntology ontology = manager.createOntology(); | ||
| 176 | |||
| 177 | OWLClass classA = factory.getOWLClass(getEntityIRI("A")); | ||
| 178 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classA)); | ||
| 179 | OWLClass classB = factory.getOWLClass(getEntityIRI("B")); | ||
| 180 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classB)); | ||
| 181 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 182 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 183 | OWLNamedIndividual c = factory.getOWLNamedIndividual(getEntityIRI("c")); | ||
| 184 | OWLObjectProperty roleR = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "R"))); | ||
| 185 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleR)); | ||
| 186 | OWLObjectProperty roleP = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "P"))); | ||
| 187 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleP)); | ||
| 188 | |||
| 189 | // Class assertions | ||
| 190 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, a)); // A(a) | ||
| 191 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, b)); // A(b) | ||
| 192 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(roleP, c, a)); // P(c,a) | ||
| 193 | |||
| 194 | // Axioms | ||
| 195 | // subsetOf(A someValuesFrom(R owl:Thing)) | ||
| 196 | manager.addAxiom(ontology, | ||
| 197 | factory.getOWLSubClassOfAxiom(classA, | ||
| 198 | factory.getOWLObjectSomeValuesFrom(roleR, | ||
| 199 | factory.getOWLThing()))); | ||
| 200 | |||
| 201 | // inverseFunctional(R) | ||
| 202 | manager.addAxiom(ontology, | ||
| 203 | factory.getOWLInverseFunctionalObjectPropertyAxiom(roleR)); | ||
| 204 | |||
| 205 | // subsetOf(someValuesFrom(inverseOf(P) owl:thing) B) | ||
| 206 | manager.addAxiom(ontology, | ||
| 207 | factory.getOWLSubClassOfAxiom(factory.getOWLObjectSomeValuesFrom(roleP.getInverseProperty(), | ||
| 208 | factory.getOWLThing()), | ||
| 209 | classB)); | ||
| 210 | /* | ||
| 211 | * Save the ontology | ||
| 212 | * */ | ||
| 213 | |||
| 214 | // manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 215 | |||
| 216 | /* | ||
| 217 | * Test one query | ||
| 218 | * */ | ||
| 219 | |||
| 220 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 221 | pagoda.loadOntology(ontology); | ||
| 222 | if(pagoda.preprocess()) { | ||
| 223 | String queryStr = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + | ||
| 224 | "select distinct ?x" + | ||
| 225 | " where { " | ||
| 226 | + " ?x rdf:type " + classB + | ||
| 227 | " }"; | ||
| 228 | QueryRecord queryRecord = pagoda.getQueryManager().create(queryStr); | ||
| 229 | System.out.println(queryRecord); | ||
| 230 | pagoda.evaluate(queryRecord); | ||
| 231 | AnswerTuples answers = queryRecord.getAnswers(); | ||
| 232 | System.out.println("Difficulty: " + queryRecord.getDifficulty()); | ||
| 233 | for(AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 234 | ans = answers.getTuple(); | ||
| 235 | TestUtil.logInfo(ans); | ||
| 236 | } | ||
| 237 | } | ||
| 238 | pagoda.dispose(); | ||
| 239 | } | ||
| 240 | } | ||
