diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-06-16 15:54:53 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-06-16 15:54:53 +0100 |
| commit | 7cd962751db2a88f426b8b9d7b9dd0d76e2cc1b5 (patch) | |
| tree | a271283211f9a156e7cb04f578a94a3ca5d0d0f7 /test/uk/ac/ox/cs/pagoda/global_tests/MinimumCardinalityTest.java | |
| parent | 3a276b7c7836e56a171ab753b018913ce022ba8e (diff) | |
| download | ACQuA-7cd962751db2a88f426b8b9d7b9dd0d76e2cc1b5.tar.gz ACQuA-7cd962751db2a88f426b8b9d7b9dd0d76e2cc1b5.zip | |
Maybe fixed bug in internalisation.
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/global_tests/MinimumCardinalityTest.java')
| -rw-r--r-- | test/uk/ac/ox/cs/pagoda/global_tests/MinimumCardinalityTest.java | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/MinimumCardinalityTest.java b/test/uk/ac/ox/cs/pagoda/global_tests/MinimumCardinalityTest.java new file mode 100644 index 0000000..71c20c1 --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/global_tests/MinimumCardinalityTest.java | |||
| @@ -0,0 +1,101 @@ | |||
| 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.reasoner.QueryReasoner; | ||
| 10 | import uk.ac.ox.cs.pagoda.util.TestUtil; | ||
| 11 | |||
| 12 | import java.io.IOException; | ||
| 13 | import java.nio.file.Files; | ||
| 14 | import java.nio.file.Paths; | ||
| 15 | |||
| 16 | public class MinimumCardinalityTest { | ||
| 17 | |||
| 18 | public static final String NS = "http://example.org/test#%s"; | ||
| 19 | |||
| 20 | private IRI getEntityIRI(String name) { | ||
| 21 | return IRI.create(String.format(NS, name)); | ||
| 22 | } | ||
| 23 | |||
| 24 | @Test(groups = {"BugTesters"}) | ||
| 25 | public void test() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { | ||
| 26 | |||
| 27 | /* | ||
| 28 | * Build test ontology | ||
| 29 | * */ | ||
| 30 | |||
| 31 | OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
| 32 | OWLDataFactory factory = manager.getOWLDataFactory(); | ||
| 33 | OWLOntology ontology = manager.createOntology(); | ||
| 34 | |||
| 35 | OWLClass student = factory.getOWLClass(getEntityIRI("Student")); | ||
| 36 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(student)); | ||
| 37 | OWLClass course = factory.getOWLClass(getEntityIRI("Course")); | ||
| 38 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(course)); | ||
| 39 | OWLClass hardWorkingStudent = factory.getOWLClass(getEntityIRI("HardWorkingStudent")); | ||
| 40 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(hardWorkingStudent)); | ||
| 41 | OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); | ||
| 42 | OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); | ||
| 43 | OWLNamedIndividual c1 = factory.getOWLNamedIndividual(getEntityIRI("c1")); | ||
| 44 | OWLNamedIndividual c2 = factory.getOWLNamedIndividual(getEntityIRI("c2")); | ||
| 45 | OWLNamedIndividual c3 = factory.getOWLNamedIndividual(getEntityIRI("c3")); | ||
| 46 | OWLNamedIndividual d1 = factory.getOWLNamedIndividual(getEntityIRI("d1")); | ||
| 47 | OWLNamedIndividual d2 = factory.getOWLNamedIndividual(getEntityIRI("d2")); | ||
| 48 | OWLNamedIndividual d3 = factory.getOWLNamedIndividual(getEntityIRI("d3")); | ||
| 49 | OWLObjectProperty takesCourse = factory.getOWLObjectProperty(IRI.create(String.format(NS, "takesCourse"))); | ||
| 50 | manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(takesCourse)); | ||
| 51 | |||
| 52 | // Class assertions | ||
| 53 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(student, a)); // Student(a) | ||
| 54 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(student, b)); // Student(b) | ||
| 55 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, c1)); // Course(c1) | ||
| 56 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, c2)); // Course(c2) | ||
| 57 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, c3)); // Course(c3) | ||
| 58 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, d1)); // Course(d1) | ||
| 59 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, d2)); // Course(d2) | ||
| 60 | manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, d3)); // Course(d3) | ||
| 61 | |||
| 62 | // Role assertions | ||
| 63 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, a, c1)); // takesCourse(a,c1) | ||
| 64 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, a, c2)); // takesCourse(a,c2) | ||
| 65 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, a, c3)); // takesCourse(a,c3) | ||
| 66 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, b, d1)); // takesCourse(b,d1) | ||
| 67 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, b, d2)); // takesCourse(b,d2) | ||
| 68 | manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, b, d3)); // takesCourse(b,d3) | ||
| 69 | |||
| 70 | // Minimum cardinality axiom | ||
| 71 | manager.addAxiom(ontology, | ||
| 72 | factory.getOWLEquivalentClassesAxiom(hardWorkingStudent, | ||
| 73 | factory.getOWLObjectMinCardinality(3, | ||
| 74 | takesCourse))); | ||
| 75 | |||
| 76 | manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); | ||
| 77 | |||
| 78 | /* | ||
| 79 | * Test one query | ||
| 80 | * */ | ||
| 81 | |||
| 82 | QueryReasoner pagoda = QueryReasoner.getInstance(ontology); | ||
| 83 | pagoda.loadOntology(ontology); | ||
| 84 | if (pagoda.preprocess()) { | ||
| 85 | String query = "select distinct ?x ?y " + | ||
| 86 | " where { " | ||
| 87 | + " ?x <" + takesCourse.toStringID() + "> _:z . " | ||
| 88 | + " ?y <" + takesCourse.toStringID() + "> _:z " + | ||
| 89 | " }"; | ||
| 90 | AnswerTuples answers = pagoda.evaluate(query); | ||
| 91 | int count = 0; | ||
| 92 | for (AnswerTuple ans; answers.isValid(); answers.moveNext()) { | ||
| 93 | ans = answers.getTuple(); | ||
| 94 | TestUtil.logInfo(ans); | ||
| 95 | count++; | ||
| 96 | } | ||
| 97 | Assert.assertEquals(count, 2); | ||
| 98 | } | ||
| 99 | pagoda.dispose(); | ||
| 100 | } | ||
| 101 | } | ||
