diff options
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/junit')
| -rw-r--r-- | test/uk/ac/ox/cs/pagoda/junit/ClauseTester.java | 183 | ||||
| -rw-r--r-- | test/uk/ac/ox/cs/pagoda/junit/TestGapMappedToLower.java | 68 |
2 files changed, 251 insertions, 0 deletions
diff --git a/test/uk/ac/ox/cs/pagoda/junit/ClauseTester.java b/test/uk/ac/ox/cs/pagoda/junit/ClauseTester.java new file mode 100644 index 0000000..ad4b2de --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/junit/ClauseTester.java | |||
| @@ -0,0 +1,183 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.junit; | ||
| 2 | |||
| 3 | import org.junit.Test; | ||
| 4 | import org.semanticweb.HermiT.model.*; | ||
| 5 | import org.semanticweb.owlapi.apibinding.OWLManager; | ||
| 6 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 7 | import org.semanticweb.owlapi.model.OWLOntologyManager; | ||
| 8 | import uk.ac.ox.cs.pagoda.approx.Clause; | ||
| 9 | import uk.ac.ox.cs.pagoda.approx.Clausifier; | ||
| 10 | |||
| 11 | import static org.junit.Assert.fail; | ||
| 12 | |||
| 13 | public class ClauseTester { | ||
| 14 | |||
| 15 | public void test_clause(Atom[] headAtoms, Atom[] bodyAtoms) { | ||
| 16 | OWLOntologyManager m = OWLManager.createOWLOntologyManager(); | ||
| 17 | OWLOntology emptyOntology = null; | ||
| 18 | try { | ||
| 19 | emptyOntology = m.createOntology(); | ||
| 20 | } catch(Exception e) { | ||
| 21 | e.printStackTrace(); | ||
| 22 | fail("failed to create a new ontology"); | ||
| 23 | } | ||
| 24 | Clause c = new Clause(Clausifier.getInstance(emptyOntology), DLClause.create(headAtoms, bodyAtoms)); | ||
| 25 | System.out.println(c.toString()); | ||
| 26 | } | ||
| 27 | |||
| 28 | @Test | ||
| 29 | public void test_nominal() { | ||
| 30 | Variable x = Variable.create("X"); | ||
| 31 | AtomicRole r = AtomicRole.create("r"); | ||
| 32 | Individual o = Individual.create("o"); | ||
| 33 | Atom[] bodyAtoms = new Atom[]{Atom.create(r, x, o)}; | ||
| 34 | AtomicConcept A = AtomicConcept.create("A"); | ||
| 35 | Atom[] headAtoms = new Atom[]{Atom.create(A, x)}; | ||
| 36 | test_clause(headAtoms, bodyAtoms); | ||
| 37 | } | ||
| 38 | |||
| 39 | @Test | ||
| 40 | public void test_simple() { | ||
| 41 | Variable x = Variable.create("X"), y1 = Variable.create("y1"), y2 = Variable.create("y2"); | ||
| 42 | AtomicConcept A = AtomicConcept.create("A"); | ||
| 43 | AtomicRole r = AtomicRole.create("r"); | ||
| 44 | Atom[] bodyAtoms = new Atom[] { | ||
| 45 | Atom.create(A, x), | ||
| 46 | Atom.create(r, x, y1), | ||
| 47 | Atom.create(r, x, y2) | ||
| 48 | }; | ||
| 49 | |||
| 50 | Atom[] headAtoms = new Atom[] { | ||
| 51 | Atom.create(Equality.INSTANCE, y1, y2) | ||
| 52 | }; | ||
| 53 | |||
| 54 | OWLOntologyManager m = OWLManager.createOWLOntologyManager(); | ||
| 55 | OWLOntology emptyOntology = null; | ||
| 56 | try { | ||
| 57 | emptyOntology = m.createOntology(); | ||
| 58 | } catch (Exception e) { | ||
| 59 | e.printStackTrace(); | ||
| 60 | fail("failed to create a new ontology"); | ||
| 61 | } | ||
| 62 | Clause c = new Clause(Clausifier.getInstance(emptyOntology), DLClause.create(headAtoms, bodyAtoms)); | ||
| 63 | System.out.println(c.toString()); | ||
| 64 | } | ||
| 65 | |||
| 66 | @Test | ||
| 67 | public void test_more() { | ||
| 68 | Variable x = Variable.create("X"), y1 = Variable.create("y1"), y2 = Variable.create("y2"), y3 = Variable.create("y3"); | ||
| 69 | AtomicConcept A = AtomicConcept.create("A"); | ||
| 70 | AtomicRole r = AtomicRole.create("r"); | ||
| 71 | Atom[] bodyAtoms = new Atom[] { | ||
| 72 | Atom.create(A, x), | ||
| 73 | Atom.create(r, x, y1), | ||
| 74 | Atom.create(r, x, y2), | ||
| 75 | Atom.create(r, x, y3), | ||
| 76 | }; | ||
| 77 | |||
| 78 | Atom[] headAtoms = new Atom[] { | ||
| 79 | Atom.create(Equality.INSTANCE, y1, y2), | ||
| 80 | Atom.create(Equality.INSTANCE, y1, y3), | ||
| 81 | Atom.create(Equality.INSTANCE, y2, y3) | ||
| 82 | }; | ||
| 83 | |||
| 84 | OWLOntologyManager m = OWLManager.createOWLOntologyManager(); | ||
| 85 | OWLOntology emptyOntology = null; | ||
| 86 | try { | ||
| 87 | emptyOntology = m.createOntology(); | ||
| 88 | } catch (Exception e) { | ||
| 89 | e.printStackTrace(); | ||
| 90 | fail("failed to create a new ontology"); | ||
| 91 | } | ||
| 92 | Clause c = new Clause(Clausifier.getInstance(emptyOntology), DLClause.create(headAtoms, bodyAtoms)); | ||
| 93 | System.out.println(c.toString()); | ||
| 94 | } | ||
| 95 | |||
| 96 | @Test | ||
| 97 | public void test_inverse() { | ||
| 98 | Variable x = Variable.create("X"), y1 = Variable.create("y1"), y2 = Variable.create("y2"); | ||
| 99 | AtomicConcept A = AtomicConcept.create("A"); | ||
| 100 | AtomicRole r = AtomicRole.create("r"); | ||
| 101 | Atom[] bodyAtoms = new Atom[] { | ||
| 102 | Atom.create(A, x), | ||
| 103 | Atom.create(r, y1, x), | ||
| 104 | Atom.create(r, y2, x) | ||
| 105 | }; | ||
| 106 | |||
| 107 | Atom[] headAtoms = new Atom[] { | ||
| 108 | Atom.create(Equality.INSTANCE, y1, y2) | ||
| 109 | }; | ||
| 110 | |||
| 111 | OWLOntologyManager m = OWLManager.createOWLOntologyManager(); | ||
| 112 | OWLOntology emptyOntology = null; | ||
| 113 | try { | ||
| 114 | emptyOntology = m.createOntology(); | ||
| 115 | } catch (Exception e) { | ||
| 116 | e.printStackTrace(); | ||
| 117 | fail("failed to create a new ontology"); | ||
| 118 | } | ||
| 119 | Clause c = new Clause(Clausifier.getInstance(emptyOntology), DLClause.create(headAtoms, bodyAtoms)); | ||
| 120 | System.out.println(c.toString()); | ||
| 121 | } | ||
| 122 | |||
| 123 | @Test | ||
| 124 | public void test_fillter() { | ||
| 125 | Variable x = Variable.create("X"), y1 = Variable.create("y1"), y2 = Variable.create("y2"); | ||
| 126 | AtomicConcept A = AtomicConcept.create("A"); | ||
| 127 | AtomicConcept B = AtomicConcept.create("B"); | ||
| 128 | AtomicRole r = AtomicRole.create("r"); | ||
| 129 | Atom[] bodyAtoms = new Atom[] { | ||
| 130 | Atom.create(A, x), | ||
| 131 | Atom.create(r, y1, x), | ||
| 132 | Atom.create(r, y2, x), | ||
| 133 | Atom.create(B, y1), | ||
| 134 | Atom.create(B, y2) | ||
| 135 | }; | ||
| 136 | |||
| 137 | Atom[] headAtoms = new Atom[] { | ||
| 138 | Atom.create(Equality.INSTANCE, y1, y2) | ||
| 139 | }; | ||
| 140 | |||
| 141 | OWLOntologyManager m = OWLManager.createOWLOntologyManager(); | ||
| 142 | OWLOntology emptyOntology = null; | ||
| 143 | try { | ||
| 144 | emptyOntology = m.createOntology(); | ||
| 145 | } catch (Exception e) { | ||
| 146 | e.printStackTrace(); | ||
| 147 | fail("failed to create a new ontology"); | ||
| 148 | } | ||
| 149 | Clause c = new Clause(Clausifier.getInstance(emptyOntology), DLClause.create(headAtoms, bodyAtoms)); | ||
| 150 | System.out.println(c.toString()); | ||
| 151 | } | ||
| 152 | |||
| 153 | @Test | ||
| 154 | public void test_negFillter() { | ||
| 155 | Variable x = Variable.create("X"), y1 = Variable.create("y1"), y2 = Variable.create("y2"); | ||
| 156 | AtomicConcept A = AtomicConcept.create("A"); | ||
| 157 | AtomicConcept B = AtomicConcept.create("B"); | ||
| 158 | AtomicRole r = AtomicRole.create("r"); | ||
| 159 | Atom[] bodyAtoms = new Atom[] { | ||
| 160 | Atom.create(A, x), | ||
| 161 | Atom.create(r, y1, x), | ||
| 162 | Atom.create(r, y2, x) | ||
| 163 | }; | ||
| 164 | |||
| 165 | Atom[] headAtoms = new Atom[] { | ||
| 166 | Atom.create(Equality.INSTANCE, y1, y2), | ||
| 167 | Atom.create(B, y1), | ||
| 168 | Atom.create(B, y2) | ||
| 169 | }; | ||
| 170 | |||
| 171 | OWLOntologyManager m = OWLManager.createOWLOntologyManager(); | ||
| 172 | OWLOntology emptyOntology = null; | ||
| 173 | try { | ||
| 174 | emptyOntology = m.createOntology(); | ||
| 175 | } catch (Exception e) { | ||
| 176 | e.printStackTrace(); | ||
| 177 | fail("failed to create a new ontology"); | ||
| 178 | } | ||
| 179 | Clause c = new Clause(Clausifier.getInstance(emptyOntology), DLClause.create(headAtoms, bodyAtoms)); | ||
| 180 | System.out.println(c.toString()); | ||
| 181 | } | ||
| 182 | |||
| 183 | } | ||
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..8fae16c --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/junit/TestGapMappedToLower.java | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.junit; | ||
| 2 | |||
| 3 | import junit.framework.Assert; | ||
| 4 | import org.junit.Test; | ||
| 5 | import org.semanticweb.owlapi.apibinding.OWLManager; | ||
| 6 | import org.semanticweb.owlapi.model.*; | ||
| 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 | } | ||
