diff options
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/junit/TestGapMappedToLower.java')
| -rw-r--r-- | test/uk/ac/ox/cs/pagoda/junit/TestGapMappedToLower.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/test/uk/ac/ox/cs/pagoda/junit/TestGapMappedToLower.java b/test/uk/ac/ox/cs/pagoda/junit/TestGapMappedToLower.java new file mode 100644 index 0000000..3e385e5 --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/junit/TestGapMappedToLower.java | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.junit; | ||
| 2 | |||
| 3 | import junit.framework.Assert; | ||
| 4 | |||
| 5 | import org.junit.Test; | ||
| 6 | import org.semanticweb.owlapi.apibinding.OWLManager; | ||
| 7 | import org.semanticweb.owlapi.model.IRI; | ||
| 8 | import org.semanticweb.owlapi.model.OWLClass; | ||
| 9 | import org.semanticweb.owlapi.model.OWLDataFactory; | ||
| 10 | import org.semanticweb.owlapi.model.OWLNamedIndividual; | ||
| 11 | import org.semanticweb.owlapi.model.OWLObjectProperty; | ||
| 12 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 13 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; | ||
| 14 | import org.semanticweb.owlapi.model.OWLOntologyManager; | ||
| 15 | |||
| 16 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | ||
| 17 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 18 | import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | ||
| 19 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 20 | |||
| 21 | public class TestGapMappedToLower { | ||
| 22 | |||
| 23 | public static final String ns = "http://example.org/test#%s"; | ||
| 24 | |||
| 25 | public IRI getEntityIRI(String name) { | ||
| 26 | return IRI.create(String.format(ns, name)); | ||
| 27 | } | ||
| 28 | |||
| 29 | @Test | ||
| 30 | public void test() throws OWLOntologyCreationException { | ||
| 31 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 32 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 33 | OWLOntology ontology = manager.createOntology(); | ||
| 34 | OWLClass A = factory.getOWLClass(getEntityIRI("A")); | ||
| 35 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A)); | ||
| 36 | OWLClass B = factory.getOWLClass(getEntityIRI("B")); | ||
| 37 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(B)); | ||
| 38 | OWLClass C = factory.getOWLClass(getEntityIRI("C")); | ||
| 39 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(C)); | ||
| 40 | OWLClass A1 = factory.getOWLClass(getEntityIRI("A1")); | ||
| 41 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A1)); | ||
| 42 | OWLClass A2 = factory.getOWLClass(getEntityIRI("A2")); | ||
| 43 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A2)); | ||
| 44 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 45 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 46 | OWLNamedIndividual c = factory.getOWLNamedIndividual(getEntityIRI("c")); | ||
| 47 | OWLObjectProperty r = factory.getOWLObjectProperty(IRI.create(String.format(ns, "r"))); | ||
| 48 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(r)); | ||
| 49 | |||
| 50 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(A, a)); // A(a) | ||
| 51 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(B, b)); // B(b) | ||
| 52 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(C, c)); // C(c) | ||
| 53 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(r, a, b)); // r(a,b) | ||
| 54 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(r, a, c)); // r(a,c) | ||
| 55 | manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A, factory.getOWLObjectUnionOf(A1, A2))); // A \sqsubseteq A1 \sqcup A2 | ||
| 56 | manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A1, factory.getOWLObjectMaxCardinality(1, r))); // A1 \sqsubseteq \leq 1 r.\top | ||
| 57 | manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A2, factory.getOWLObjectMaxCardinality(1, r))); // A2 \sqsubseteq \leq 1 r.\top | ||
| 58 | |||
| 59 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 60 | pagoda.loadOntology(ontology); | ||
| 61 | if (pagoda.preprocess()) { | ||
| 62 | String sparql = "select ?x where { " | ||
| 63 | + "?x <" + r.toStringID() + "> ?y . " | ||
| 64 | + "?y " + Namespace.RDF_TYPE_QUOTED + " <" + B.toStringID() + "> . " | ||
| 65 | + "?y " + Namespace.RDF_TYPE_QUOTED + " <" + C.toStringID() + "> . } "; | ||
| 66 | AnswerTuples rs = pagoda.evaluate(sparql); | ||
| 67 | int count = 0; | ||
| 68 | for (AnswerTuple ans; rs.isValid(); rs.moveNext()) { | ||
| 69 | ans = rs.getTuple(); | ||
| 70 | System.out.println(ans.getGroundTerm(0)); | ||
| 71 | ++count; | ||
| 72 | } | ||
| 73 | Assert.assertEquals(1, count); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | } | ||
