diff options
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/global_tests')
| -rw-r--r-- | test/uk/ac/ox/cs/pagoda/global_tests/SkolemisationTests.java | 269 | ||||
| -rw-r--r-- | test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaReactome.java | 14 |
2 files changed, 283 insertions, 0 deletions
diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/SkolemisationTests.java b/test/uk/ac/ox/cs/pagoda/global_tests/SkolemisationTests.java new file mode 100644 index 0000000..2fc682b --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/global_tests/SkolemisationTests.java | |||
| @@ -0,0 +1,269 @@ | |||
| 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 | public class SkolemisationTests { | ||
| 18 | |||
| 19 | public static final String NS = "http://example.org/test#%s"; | ||
| 20 | |||
| 21 | private IRI getEntityIRI(String name) { | ||
| 22 | return IRI.create(String.format(NS, name)); | ||
| 23 | } | ||
| 24 | |||
| 25 | // @Test | ||
| 26 | public void commonSuccessorTest() 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 classA = factory.getOWLClass(getEntityIRI("A")); | ||
| 37 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classA)); | ||
| 38 | OWLClass classB = factory.getOWLClass(getEntityIRI("B")); | ||
| 39 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classB)); | ||
| 40 | OWLClass classC = factory.getOWLClass(getEntityIRI("C")); | ||
| 41 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classC)); | ||
| 42 | OWLNamedIndividual c = factory.getOWLNamedIndividual(getEntityIRI("c")); | ||
| 43 | OWLNamedIndividual d = factory.getOWLNamedIndividual(getEntityIRI("d")); | ||
| 44 | OWLObjectProperty roleR = factory.getOWLObjectProperty(IRI.create(String.format(NS, "R"))); | ||
| 45 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleR)); | ||
| 46 | |||
| 47 | // Class assertions | ||
| 48 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, c)); // A(c) | ||
| 49 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, d)); // A(d) | ||
| 50 | |||
| 51 | // Minimum cardinality axiom | ||
| 52 | manager.addAxiom(ontology, | ||
| 53 | factory.getOWLSubClassOfAxiom(classA, | ||
| 54 | factory.getOWLObjectUnionOf( | ||
| 55 | factory.getOWLObjectSomeValuesFrom(roleR, classB), | ||
| 56 | factory.getOWLObjectSomeValuesFrom(roleR, classC)))); | ||
| 57 | |||
| 58 | /* | ||
| 59 | * Save the ontology | ||
| 60 | * */ | ||
| 61 | |||
| 62 | // manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 63 | |||
| 64 | /* | ||
| 65 | * Test one query | ||
| 66 | * */ | ||
| 67 | |||
| 68 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 69 | pagoda.loadOntology(ontology); | ||
| 70 | if(pagoda.preprocess()) { | ||
| 71 | String queryStr = "select distinct ?x ?y " + | ||
| 72 | " where { " | ||
| 73 | + " ?x <" + roleR.toStringID() + "> _:z . " | ||
| 74 | + " ?y <" + roleR.toStringID() + "> _:z " + | ||
| 75 | " }"; | ||
| 76 | QueryRecord queryRecord = pagoda.getQueryManager().create(queryStr); | ||
| 77 | pagoda.evaluate(queryRecord); | ||
| 78 | AnswerTuples answers = queryRecord.getAnswers(); | ||
| 79 | System.out.println("Difficulty: " + queryRecord.getDifficulty()); | ||
| 80 | int count = 0; | ||
| 81 | for(AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 82 | ans = answers.getTuple(); | ||
| 83 | TestUtil.logInfo(ans); | ||
| 84 | count++; | ||
| 85 | } | ||
| 86 | Assert.assertEquals(count, 2); | ||
| 87 | } | ||
| 88 | pagoda.dispose(); | ||
| 89 | } | ||
| 90 | |||
| 91 | // @Test | ||
| 92 | public void yTest() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 93 | |||
| 94 | /* | ||
| 95 | * Build test ontology | ||
| 96 | * */ | ||
| 97 | |||
| 98 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 99 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 100 | OWLOntology ontology = manager.createOntology(); | ||
| 101 | |||
| 102 | OWLClass classA = factory.getOWLClass(getEntityIRI("A")); | ||
| 103 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classA)); | ||
| 104 | OWLClass classB = factory.getOWLClass(getEntityIRI("B")); | ||
| 105 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classB)); | ||
| 106 | OWLClass classC = factory.getOWLClass(getEntityIRI("C")); | ||
| 107 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classC)); | ||
| 108 | OWLClass classD = factory.getOWLClass(getEntityIRI("D")); | ||
| 109 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classD)); | ||
| 110 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 111 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 112 | OWLNamedIndividual c = factory.getOWLNamedIndividual(getEntityIRI("c")); | ||
| 113 | OWLNamedIndividual d = factory.getOWLNamedIndividual(getEntityIRI("d")); | ||
| 114 | OWLObjectProperty roleR = factory.getOWLObjectProperty(IRI.create(String.format(NS, "R"))); | ||
| 115 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleR)); | ||
| 116 | OWLObjectProperty roleS = factory.getOWLObjectProperty(IRI.create(String.format(NS, "S"))); | ||
| 117 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleS)); | ||
| 118 | OWLObjectProperty roleP = factory.getOWLObjectProperty(IRI.create(String.format(NS, "P"))); | ||
| 119 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleP)); | ||
| 120 | |||
| 121 | // Class assertions | ||
| 122 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classD, a)); // D(a) | ||
| 123 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classD, b)); // D(b) | ||
| 124 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(roleS, c, a)); // S(c,a) | ||
| 125 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(roleP, d, b)); // P(d,b) | ||
| 126 | |||
| 127 | // Axioms | ||
| 128 | // subsetOf(D someValuesFrom(R owl:Thing)) | ||
| 129 | manager.addAxiom(ontology, | ||
| 130 | factory.getOWLSubClassOfAxiom(classD, | ||
| 131 | factory.getOWLObjectSomeValuesFrom(roleR, | ||
| 132 | factory.getOWLThing()))); | ||
| 133 | // subsetOf(someValuesFrom(inverseOf(S) owl:Thing) allValuesFrom(R A)) | ||
| 134 | manager.addAxiom(ontology, | ||
| 135 | factory.getOWLSubClassOfAxiom(factory.getOWLObjectSomeValuesFrom(roleS.getInverseProperty(), | ||
| 136 | factory.getOWLThing()), | ||
| 137 | factory.getOWLObjectAllValuesFrom(roleR, classA))); | ||
| 138 | // subsetOf(someValuesFrom(inverseOf(P) owl:Thing) B) | ||
| 139 | manager.addAxiom(ontology, | ||
| 140 | factory.getOWLSubClassOfAxiom(factory.getOWLObjectSomeValuesFrom(roleP.getInverseProperty(), | ||
| 141 | factory.getOWLThing()), | ||
| 142 | classB)); | ||
| 143 | // subsetOf(someValuesFrom(R A) C) | ||
| 144 | manager.addAxiom(ontology, | ||
| 145 | factory.getOWLSubClassOfAxiom(factory.getOWLObjectSomeValuesFrom(roleR, classA), classC)); | ||
| 146 | |||
| 147 | /* | ||
| 148 | * Save the ontology | ||
| 149 | * */ | ||
| 150 | |||
| 151 | manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 152 | |||
| 153 | /* | ||
| 154 | * Test one query | ||
| 155 | * */ | ||
| 156 | |||
| 157 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 158 | pagoda.loadOntology(ontology); | ||
| 159 | if(pagoda.preprocess()) { | ||
| 160 | String queryStr = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + | ||
| 161 | "select distinct ?x" + | ||
| 162 | " where { " | ||
| 163 | // + " ?x rdf:type " + classB + " ." | ||
| 164 | // + " ?x " + roleR + " "+ "_:y . " | ||
| 165 | + " ?x rdf:type " + classC + | ||
| 166 | " }"; | ||
| 167 | QueryRecord queryRecord = pagoda.getQueryManager().create(queryStr); | ||
| 168 | System.out.println(queryRecord); | ||
| 169 | pagoda.evaluate(queryRecord); | ||
| 170 | AnswerTuples answers = queryRecord.getAnswers(); | ||
| 171 | System.out.println("Difficulty: " + queryRecord.getDifficulty()); | ||
| 172 | int count = 0; | ||
| 173 | for(AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 174 | ans = answers.getTuple(); | ||
| 175 | TestUtil.logInfo(ans); | ||
| 176 | count++; | ||
| 177 | } | ||
| 178 | // Assert.assertEquals(count, 1); | ||
| 179 | } | ||
| 180 | pagoda.dispose(); | ||
| 181 | } | ||
| 182 | |||
| 183 | @Test | ||
| 184 | public void rTest() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 185 | |||
| 186 | /* | ||
| 187 | * Build test ontology | ||
| 188 | * */ | ||
| 189 | |||
| 190 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 191 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 192 | OWLOntology ontology = manager.createOntology(); | ||
| 193 | |||
| 194 | OWLClass classA = factory.getOWLClass(getEntityIRI("A")); | ||
| 195 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classA)); | ||
| 196 | OWLClass classB = factory.getOWLClass(getEntityIRI("B")); | ||
| 197 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classB)); | ||
| 198 | // OWLClass classC = factory.getOWLClass(getEntityIRI("C")); | ||
| 199 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classC)); | ||
| 200 | // OWLClass classD = factory.getOWLClass(getEntityIRI("D")); | ||
| 201 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classD)); | ||
| 202 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 203 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 204 | OWLNamedIndividual c = factory.getOWLNamedIndividual(getEntityIRI("c")); | ||
| 205 | // OWLNamedIndividual d = factory.getOWLNamedIndividual(getEntityIRI("d")); | ||
| 206 | OWLObjectProperty roleR = factory.getOWLObjectProperty(IRI.create(String.format(NS, "R"))); | ||
| 207 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleR)); | ||
| 208 | // OWLObjectProperty roleF = factory.getOWLObjectProperty(IRI.create(String.format(NS, "F"))); | ||
| 209 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleF)); | ||
| 210 | OWLObjectProperty roleP = factory.getOWLObjectProperty(IRI.create(String.format(NS, "P"))); | ||
| 211 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleP)); | ||
| 212 | // OWLObjectProperty roleL = factory.getOWLObjectProperty(IRI.create(String.format(NS, "L"))); | ||
| 213 | // manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleL)); | ||
| 214 | |||
| 215 | // Class assertions | ||
| 216 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, a)); // A(a) | ||
| 217 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, b)); // A(b) | ||
| 218 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(roleP, c, a)); // P(c,a) | ||
| 219 | |||
| 220 | // Axioms | ||
| 221 | // subsetOf(A someValuesFrom(R owl:Thing)) | ||
| 222 | manager.addAxiom(ontology, | ||
| 223 | factory.getOWLSubClassOfAxiom(classA, | ||
| 224 | factory.getOWLObjectSomeValuesFrom(roleR, | ||
| 225 | factory.getOWLThing()))); | ||
| 226 | |||
| 227 | // inverseFunctional(R) | ||
| 228 | manager.addAxiom(ontology, | ||
| 229 | factory.getOWLInverseFunctionalObjectPropertyAxiom(roleR)); | ||
| 230 | |||
| 231 | // subsetOf(someValuesFrom(inverseOf(P) owl:thing) B) | ||
| 232 | manager.addAxiom(ontology, | ||
| 233 | factory.getOWLSubClassOfAxiom(factory.getOWLObjectSomeValuesFrom(roleP.getInverseProperty(), | ||
| 234 | factory.getOWLThing()), | ||
| 235 | classB)); | ||
| 236 | /* | ||
| 237 | * Save the ontology | ||
| 238 | * */ | ||
| 239 | |||
| 240 | manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 241 | |||
| 242 | /* | ||
| 243 | * Test one query | ||
| 244 | * */ | ||
| 245 | |||
| 246 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 247 | pagoda.loadOntology(ontology); | ||
| 248 | if(pagoda.preprocess()) { | ||
| 249 | String queryStr = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + | ||
| 250 | "select distinct ?x" + | ||
| 251 | " where { " | ||
| 252 | + " ?x rdf:type " + classB + | ||
| 253 | " }"; | ||
| 254 | QueryRecord queryRecord = pagoda.getQueryManager().create(queryStr); | ||
| 255 | System.out.println(queryRecord); | ||
| 256 | pagoda.evaluate(queryRecord); | ||
| 257 | AnswerTuples answers = queryRecord.getAnswers(); | ||
| 258 | System.out.println("Difficulty: " + queryRecord.getDifficulty()); | ||
| 259 | int count = 0; | ||
| 260 | for(AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 261 | ans = answers.getTuple(); | ||
| 262 | TestUtil.logInfo(ans); | ||
| 263 | count++; | ||
| 264 | } | ||
| 265 | // Assert.assertEquals(count, 1); | ||
| 266 | } | ||
| 267 | pagoda.dispose(); | ||
| 268 | } | ||
| 269 | } | ||
diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaReactome.java b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaReactome.java index 5c05b94..30f3d93 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaReactome.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaReactome.java | |||
| @@ -23,4 +23,18 @@ public class TestPagodaReactome { | |||
| 23 | .run(); | 23 | .run(); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | @Test(groups = {"sygenia"}) | ||
| 27 | public void justExecute_sygenia() throws IOException { | ||
| 28 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | ||
| 29 | |||
| 30 | Pagoda.builder() | ||
| 31 | .ontology(Paths.get(ontoDir, "reactome/biopax-level3-processed.owl")) | ||
| 32 | .data(Paths.get(ontoDir, "reactome/data/sample_10.ttl")) | ||
| 33 | .query(Paths.get(ontoDir, "reactome/reactome_sygenia_queries.sparql")) | ||
| 34 | .classify(true) | ||
| 35 | .hermit(true) | ||
| 36 | .build() | ||
| 37 | .run(); | ||
| 38 | } | ||
| 39 | |||
| 26 | } | 40 | } |
