diff options
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/global_tests')
5 files changed, 71 insertions, 35 deletions
diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswers.java b/test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswers.java deleted file mode 100644 index 14050ce..0000000 --- a/test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswers.java +++ /dev/null | |||
| @@ -1,35 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import com.google.gson.Gson; | ||
| 4 | import com.google.gson.reflect.TypeToken; | ||
| 5 | import org.testng.Assert; | ||
| 6 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 7 | |||
| 8 | import java.io.BufferedReader; | ||
| 9 | import java.io.IOException; | ||
| 10 | import java.lang.reflect.Type; | ||
| 11 | import java.nio.file.Files; | ||
| 12 | import java.nio.file.Path; | ||
| 13 | import java.util.Set; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * It provides auxiliary methods for checking answers. | ||
| 17 | * */ | ||
| 18 | public class CheckAnswers { | ||
| 19 | |||
| 20 | private CheckAnswers() { | ||
| 21 | } | ||
| 22 | |||
| 23 | public static void assertSameAnswers(Path computedAnswersFile, Path givenAnswersFile) throws IOException { | ||
| 24 | BufferedReader computedReader = Files.newBufferedReader(computedAnswersFile); | ||
| 25 | BufferedReader givenReader = Files.newBufferedReader(givenAnswersFile); | ||
| 26 | |||
| 27 | Gson gson = QueryRecord.GsonCreator.getInstance(); | ||
| 28 | |||
| 29 | Type cqType = new TypeToken<Set<QueryRecord>>() {}.getType(); | ||
| 30 | Set<QueryRecord> computedAnswers = gson.fromJson(computedReader, cqType); | ||
| 31 | Set<QueryRecord> givenAnswers = gson.fromJson(givenReader, cqType); | ||
| 32 | |||
| 33 | Assert.assertEquals(computedAnswers, givenAnswers); | ||
| 34 | } | ||
| 35 | } | ||
diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/TestGapMappedToLower.java b/test/uk/ac/ox/cs/pagoda/global_tests/TestGapMappedToLower.java new file mode 100644 index 0000000..4b1ec6d --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestGapMappedToLower.java | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import junit.framework.Assert; | ||
| 4 | import org.semanticweb.owlapi.apibinding.OWLManager; | ||
| 5 | import org.semanticweb.owlapi.model.*; | ||
| 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.reasoner.QueryReasoner; | ||
| 10 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 11 | |||
| 12 | public class TestGapMappedToLower { | ||
| 13 | |||
| 14 | public static final String ns = "http://example.org/test#%s"; | ||
| 15 | |||
| 16 | public IRI getEntityIRI(String name) { | ||
| 17 | return IRI.create(String.format(ns, name)); | ||
| 18 | } | ||
| 19 | |||
| 20 | @Test | ||
| 21 | public void test() throws OWLOntologyCreationException { | ||
| 22 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 23 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 24 | OWLOntology ontology = manager.createOntology(); | ||
| 25 | OWLClass A = factory.getOWLClass(getEntityIRI("A")); | ||
| 26 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A)); | ||
| 27 | OWLClass B = factory.getOWLClass(getEntityIRI("B")); | ||
| 28 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(B)); | ||
| 29 | OWLClass C = factory.getOWLClass(getEntityIRI("C")); | ||
| 30 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(C)); | ||
| 31 | OWLClass A1 = factory.getOWLClass(getEntityIRI("A1")); | ||
| 32 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A1)); | ||
| 33 | OWLClass A2 = factory.getOWLClass(getEntityIRI("A2")); | ||
| 34 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A2)); | ||
| 35 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 36 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 37 | OWLNamedIndividual c = factory.getOWLNamedIndividual(getEntityIRI("c")); | ||
| 38 | OWLObjectProperty r = factory.getOWLObjectProperty(IRI.create(String.format(ns, "r"))); | ||
| 39 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(r)); | ||
| 40 | |||
| 41 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(A, a)); // A(a) | ||
| 42 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(B, b)); // B(b) | ||
| 43 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(C, c)); // C(c) | ||
| 44 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(r, a, b)); // r(a,b) | ||
| 45 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(r, a, c)); // r(a,c) | ||
| 46 | manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A, factory.getOWLObjectUnionOf(A1, A2))); // A \sqsubseteq A1 \sqcup A2 | ||
| 47 | manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A1, factory.getOWLObjectMaxCardinality(1, r))); // A1 \sqsubseteq \leq 1 r.\top | ||
| 48 | manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A2, factory.getOWLObjectMaxCardinality(1, r))); // A2 \sqsubseteq \leq 1 r.\top | ||
| 49 | |||
| 50 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 51 | pagoda.loadOntology(ontology); | ||
| 52 | if (pagoda.preprocess()) { | ||
| 53 | String sparql = "select ?x where { " | ||
| 54 | + "?x <" + r.toStringID() + "> ?y . " | ||
| 55 | + "?y " + Namespace.RDF_TYPE_QUOTED + " <" + B.toStringID() + "> . " | ||
| 56 | + "?y " + Namespace.RDF_TYPE_QUOTED + " <" + C.toStringID() + "> . } "; | ||
| 57 | AnswerTuples rs = pagoda.evaluate(sparql); | ||
| 58 | int count = 0; | ||
| 59 | for (AnswerTuple ans; rs.isValid(); rs.moveNext()) { | ||
| 60 | ans = rs.getTuple(); | ||
| 61 | System.out.println(ans.getGroundTerm(0)); | ||
| 62 | ++count; | ||
| 63 | } | ||
| 64 | Assert.assertEquals(1, count); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | } | ||
diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaFLY.java b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaFLY.java index d8d2b76..352bcba 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaFLY.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaFLY.java | |||
| @@ -2,6 +2,7 @@ package uk.ac.ox.cs.pagoda.global_tests; | |||
| 2 | 2 | ||
| 3 | import org.testng.annotations.Test; | 3 | import org.testng.annotations.Test; |
| 4 | import uk.ac.ox.cs.pagoda.Pagoda; | 4 | import uk.ac.ox.cs.pagoda.Pagoda; |
| 5 | import uk.ac.ox.cs.pagoda.query.CheckAnswers; | ||
| 5 | import uk.ac.ox.cs.pagoda.util.TestUtil; | 6 | import uk.ac.ox.cs.pagoda.util.TestUtil; |
| 6 | 7 | ||
| 7 | import java.io.File; | 8 | import java.io.File; |
diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java index d261d84..1db4a43 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java | |||
| @@ -2,6 +2,7 @@ package uk.ac.ox.cs.pagoda.global_tests; | |||
| 2 | 2 | ||
| 3 | import org.testng.annotations.Test; | 3 | import org.testng.annotations.Test; |
| 4 | import uk.ac.ox.cs.pagoda.Pagoda; | 4 | import uk.ac.ox.cs.pagoda.Pagoda; |
| 5 | import uk.ac.ox.cs.pagoda.query.CheckAnswers; | ||
| 5 | import uk.ac.ox.cs.pagoda.util.TestUtil; | 6 | import uk.ac.ox.cs.pagoda.util.TestUtil; |
| 6 | 7 | ||
| 7 | import java.io.File; | 8 | import java.io.File; |
diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java index 558ac1f..4f49fe0 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java | |||
| @@ -3,6 +3,7 @@ package uk.ac.ox.cs.pagoda.global_tests; | |||
| 3 | import org.testng.annotations.DataProvider; | 3 | import org.testng.annotations.DataProvider; |
| 4 | import org.testng.annotations.Test; | 4 | import org.testng.annotations.Test; |
| 5 | import uk.ac.ox.cs.pagoda.Pagoda; | 5 | import uk.ac.ox.cs.pagoda.Pagoda; |
| 6 | import uk.ac.ox.cs.pagoda.query.CheckAnswers; | ||
| 6 | import uk.ac.ox.cs.pagoda.util.TestUtil; | 7 | import uk.ac.ox.cs.pagoda.util.TestUtil; |
| 7 | 8 | ||
| 8 | import java.io.File; | 9 | import java.io.File; |
