diff options
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/global_tests')
4 files changed, 120 insertions, 30 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 | } | ||
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 a0ccb1a..caaad35 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaFLY.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaFLY.java | |||
| @@ -32,7 +32,7 @@ public class TestPagodaFLY { | |||
| 32 | CheckAnswers.assertSameAnswers(answers, givenAnswers); | 32 | CheckAnswers.assertSameAnswers(answers, givenAnswers); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | @Test(groups = {"light"}) | 35 | @Test(groups = {"light", "correctness"}) |
| 36 | public void answersCorrectness_rolledUp() throws IOException { | 36 | public void answersCorrectness_rolledUp() throws IOException { |
| 37 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | 37 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); |
| 38 | Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); | 38 | Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); |
| @@ -43,7 +43,7 @@ public class TestPagodaFLY { | |||
| 43 | .ontology(Paths.get(ontoDir, "fly/fly_rolledUp.owl")) | 43 | .ontology(Paths.get(ontoDir, "fly/fly_rolledUp.owl")) |
| 44 | .query(Paths.get(ontoDir, "fly/queries/fly_rolledUp.sparql")) | 44 | .query(Paths.get(ontoDir, "fly/queries/fly_rolledUp.sparql")) |
| 45 | .answer(answers) | 45 | .answer(answers) |
| 46 | .answer(Paths.get("/home/alessandro/Desktop/answers.json")) | 46 | // .answer(Paths.get("/home/alessandro/Desktop/answers.json")) |
| 47 | .classify(false) | 47 | .classify(false) |
| 48 | .hermit(true) | 48 | .hermit(true) |
| 49 | .build(); | 49 | .build(); |
| @@ -68,7 +68,7 @@ public class TestPagodaFLY { | |||
| 68 | .run(); | 68 | .run(); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | @Test(groups = {"light", "comparison"}) | 71 | @Test(groups = {"comparison"}) |
| 72 | public void compare_newQueries() throws IOException { | 72 | public void compare_newQueries() throws IOException { |
| 73 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | 73 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); |
| 74 | 74 | ||
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 089a7d2..fdbfc42 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java | |||
| @@ -31,7 +31,7 @@ public class TestPagodaLUBM { | |||
| 31 | CheckAnswers.assertSameAnswers(answers, givenAnswers); | 31 | CheckAnswers.assertSameAnswers(answers, givenAnswers); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | @Test(groups = {"light"}) | 34 | @Test(groups = {"light", "correctness"}) |
| 35 | public void answersCorrectness_1() throws IOException { | 35 | public void answersCorrectness_1() throws IOException { |
| 36 | answersCorrectness(1); | 36 | answersCorrectness(1); |
| 37 | } | 37 | } |
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 1d9f1e6..d0f0b9a 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java | |||
| @@ -24,12 +24,12 @@ public class TestPagodaUOBM { | |||
| 24 | return integers; | 24 | return integers; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | @Test(groups = {"light"}) | 27 | @Test(groups = {"light", "correctness"}) |
| 28 | public void answersCorrectness_1() throws IOException { | 28 | public void answersCorrectness_1() throws IOException { |
| 29 | answersCorrectness(1); | 29 | answersCorrectness(1); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | @Test(groups = {"heavy"}, dataProvider = "UOBMNumbers") | 32 | @Test(groups = {"heavy", "correctness"}, dataProvider = "UOBMNumbers") |
| 33 | public void answersCorrectness(int number) throws IOException { | 33 | public void answersCorrectness(int number) throws IOException { |
| 34 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | 34 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); |
| 35 | Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); | 35 | Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); |
| @@ -65,13 +65,11 @@ public class TestPagodaUOBM { | |||
| 65 | .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) | 65 | .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) |
| 66 | .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl")) | 66 | .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl")) |
| 67 | .query(Paths.get(ontoDir, "uobm/queries/uobm_sygenia.sparql")) | 67 | .query(Paths.get(ontoDir, "uobm/queries/uobm_sygenia.sparql")) |
| 68 | // .answer(answers) | ||
| 69 | .classify(true) | 68 | .classify(true) |
| 70 | .hermit(true) | 69 | .hermit(true) |
| 71 | .build(); | 70 | .build(); |
| 72 | 71 | ||
| 73 | pagoda.run(); | 72 | pagoda.run(); |
| 74 | // CheckAnswers.assertSameAnswers(answers, givenAnswers); | ||
| 75 | } | 73 | } |
| 76 | 74 | ||
| 77 | @Test(groups = {"sygenia"}) | 75 | @Test(groups = {"sygenia"}) |
| @@ -82,21 +80,14 @@ public class TestPagodaUOBM { | |||
| 82 | @Test(groups = {"heavy"}, dataProvider = "UOBMNumbers") | 80 | @Test(groups = {"heavy"}, dataProvider = "UOBMNumbers") |
| 83 | public void answersCorrectness_sygenia_allBlanks(int number) throws IOException { | 81 | public void answersCorrectness_sygenia_allBlanks(int number) throws IOException { |
| 84 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | 82 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); |
| 85 | // Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); | ||
| 86 | // new File(answers.toString()).deleteOnExit(); | ||
| 87 | // Path givenAnswers = TestUtil.getAnswersFilePath("answers/pagoda-uobm" + number + ".json"); | ||
| 88 | 83 | ||
| 89 | Pagoda pagoda = Pagoda.builder() | 84 | Pagoda.builder() |
| 90 | .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) | 85 | .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) |
| 91 | .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl")) | 86 | .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl")) |
| 92 | .query(Paths.get(ontoDir, "uobm/queries/uobm_sygenia_all-blanks.sparql")) | 87 | .query(Paths.get(ontoDir, "uobm/queries/uobm_sygenia_all-blanks.sparql")) |
| 93 | // .answer(answers) | 88 | .classify(true) |
| 94 | .classify(true) | 89 | .hermit(true) |
| 95 | .hermit(true) | 90 | .build().run(); |
| 96 | .build(); | ||
| 97 | |||
| 98 | pagoda.run(); | ||
| 99 | // CheckAnswers.assertSameAnswers(answers, givenAnswers); | ||
| 100 | } | 91 | } |
| 101 | 92 | ||
| 102 | @Test(groups = {"justExecute"}) | 93 | @Test(groups = {"justExecute"}) |
| @@ -104,14 +95,12 @@ public class TestPagodaUOBM { | |||
| 104 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); | 95 | String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); |
| 105 | 96 | ||
| 106 | Pagoda.builder() | 97 | Pagoda.builder() |
| 107 | .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) | 98 | .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl-modified.owl")) |
| 108 | .data(Paths.get(ontoDir, "uobm/data/uobm1.ttl")) | 99 | .data(Paths.get(ontoDir, "uobm/data/uobm1.ttl")) |
| 109 | .query(Paths.get(ontoDir, "uobm/queries/existential_queries.sparql")) | 100 | .query(Paths.get(ontoDir, "uobm/queries/existential_queries.sparql")) |
| 110 | // .answer(answers) | 101 | .classify(true) |
| 111 | .classify(true) | 102 | .hermit(true) |
| 112 | .hermit(true) | 103 | .build() |
| 113 | .skolem(false) | 104 | .run(); |
| 114 | .build() | ||
| 115 | .run(); | ||
| 116 | } | 105 | } |
| 117 | } | 106 | } |
