From 29eecb27c7f91de92b21bbd646d8b7a55e526833 Mon Sep 17 00:00:00 2001 From: RncLsn Date: Tue, 16 Jun 2015 15:54:53 +0100 Subject: Maybe fixed bug in internalisation. --- .../global_tests/MinimumCardinalityTest.java | 101 +++++++++++++++++++++ .../ox/cs/pagoda/global_tests/TestPagodaFLY.java | 6 +- .../ox/cs/pagoda/global_tests/TestPagodaLUBM.java | 2 +- .../ox/cs/pagoda/global_tests/TestPagodaUOBM.java | 41 +++------ 4 files changed, 120 insertions(+), 30 deletions(-) create mode 100644 test/uk/ac/ox/cs/pagoda/global_tests/MinimumCardinalityTest.java (limited to 'test/uk/ac/ox/cs/pagoda/global_tests') 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 @@ +package uk.ac.ox.cs.pagoda.global_tests; + +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.*; +import org.testng.Assert; +import org.testng.annotations.Test; +import uk.ac.ox.cs.pagoda.query.AnswerTuple; +import uk.ac.ox.cs.pagoda.query.AnswerTuples; +import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; +import uk.ac.ox.cs.pagoda.util.TestUtil; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class MinimumCardinalityTest { + + public static final String NS = "http://example.org/test#%s"; + + private IRI getEntityIRI(String name) { + return IRI.create(String.format(NS, name)); + } + + @Test(groups = {"BugTesters"}) + public void test() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { + + /* + * Build test ontology + * */ + + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLDataFactory factory = manager.getOWLDataFactory(); + OWLOntology ontology = manager.createOntology(); + + OWLClass student = factory.getOWLClass(getEntityIRI("Student")); + manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(student)); + OWLClass course = factory.getOWLClass(getEntityIRI("Course")); + manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(course)); + OWLClass hardWorkingStudent = factory.getOWLClass(getEntityIRI("HardWorkingStudent")); + manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(hardWorkingStudent)); + OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); + OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); + OWLNamedIndividual c1 = factory.getOWLNamedIndividual(getEntityIRI("c1")); + OWLNamedIndividual c2 = factory.getOWLNamedIndividual(getEntityIRI("c2")); + OWLNamedIndividual c3 = factory.getOWLNamedIndividual(getEntityIRI("c3")); + OWLNamedIndividual d1 = factory.getOWLNamedIndividual(getEntityIRI("d1")); + OWLNamedIndividual d2 = factory.getOWLNamedIndividual(getEntityIRI("d2")); + OWLNamedIndividual d3 = factory.getOWLNamedIndividual(getEntityIRI("d3")); + OWLObjectProperty takesCourse = factory.getOWLObjectProperty(IRI.create(String.format(NS, "takesCourse"))); + manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(takesCourse)); + + // Class assertions + manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(student, a)); // Student(a) + manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(student, b)); // Student(b) + manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, c1)); // Course(c1) + manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, c2)); // Course(c2) + manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, c3)); // Course(c3) + manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, d1)); // Course(d1) + manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, d2)); // Course(d2) + manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(course, d3)); // Course(d3) + + // Role assertions + manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, a, c1)); // takesCourse(a,c1) + manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, a, c2)); // takesCourse(a,c2) + manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, a, c3)); // takesCourse(a,c3) + manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, b, d1)); // takesCourse(b,d1) + manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, b, d2)); // takesCourse(b,d2) + manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(takesCourse, b, d3)); // takesCourse(b,d3) + + // Minimum cardinality axiom + manager.addAxiom(ontology, + factory.getOWLEquivalentClassesAxiom(hardWorkingStudent, + factory.getOWLObjectMinCardinality(3, + takesCourse))); + + manager.saveOntology(ontology, Files.newOutputStream(Paths.get("/home/alessandro/Desktop/test-ontology.owl"))); + + /* + * Test one query + * */ + + QueryReasoner pagoda = QueryReasoner.getInstance(ontology); + pagoda.loadOntology(ontology); + if (pagoda.preprocess()) { + String query = "select distinct ?x ?y " + + " where { " + + " ?x <" + takesCourse.toStringID() + "> _:z . " + + " ?y <" + takesCourse.toStringID() + "> _:z " + + " }"; + AnswerTuples answers = pagoda.evaluate(query); + int count = 0; + for (AnswerTuple ans; answers.isValid(); answers.moveNext()) { + ans = answers.getTuple(); + TestUtil.logInfo(ans); + count++; + } + Assert.assertEquals(count, 2); + } + pagoda.dispose(); + } +} 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 { CheckAnswers.assertSameAnswers(answers, givenAnswers); } - @Test(groups = {"light"}) + @Test(groups = {"light", "correctness"}) public void answersCorrectness_rolledUp() throws IOException { String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); @@ -43,7 +43,7 @@ public class TestPagodaFLY { .ontology(Paths.get(ontoDir, "fly/fly_rolledUp.owl")) .query(Paths.get(ontoDir, "fly/queries/fly_rolledUp.sparql")) .answer(answers) - .answer(Paths.get("/home/alessandro/Desktop/answers.json")) +// .answer(Paths.get("/home/alessandro/Desktop/answers.json")) .classify(false) .hermit(true) .build(); @@ -68,7 +68,7 @@ public class TestPagodaFLY { .run(); } - @Test(groups = {"light", "comparison"}) + @Test(groups = {"comparison"}) public void compare_newQueries() throws IOException { String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); 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 { CheckAnswers.assertSameAnswers(answers, givenAnswers); } - @Test(groups = {"light"}) + @Test(groups = {"light", "correctness"}) public void answersCorrectness_1() throws IOException { answersCorrectness(1); } 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 { return integers; } - @Test(groups = {"light"}) + @Test(groups = {"light", "correctness"}) public void answersCorrectness_1() throws IOException { answersCorrectness(1); } - @Test(groups = {"heavy"}, dataProvider = "UOBMNumbers") + @Test(groups = {"heavy", "correctness"}, dataProvider = "UOBMNumbers") public void answersCorrectness(int number) throws IOException { String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); @@ -65,13 +65,11 @@ public class TestPagodaUOBM { .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl")) .query(Paths.get(ontoDir, "uobm/queries/uobm_sygenia.sparql")) -// .answer(answers) .classify(true) .hermit(true) .build(); pagoda.run(); -// CheckAnswers.assertSameAnswers(answers, givenAnswers); } @Test(groups = {"sygenia"}) @@ -82,21 +80,14 @@ public class TestPagodaUOBM { @Test(groups = {"heavy"}, dataProvider = "UOBMNumbers") public void answersCorrectness_sygenia_allBlanks(int number) throws IOException { String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); -// Path answers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); -// new File(answers.toString()).deleteOnExit(); -// Path givenAnswers = TestUtil.getAnswersFilePath("answers/pagoda-uobm" + number + ".json"); - Pagoda pagoda = Pagoda.builder() - .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) - .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl")) - .query(Paths.get(ontoDir, "uobm/queries/uobm_sygenia_all-blanks.sparql")) -// .answer(answers) - .classify(true) - .hermit(true) - .build(); - - pagoda.run(); -// CheckAnswers.assertSameAnswers(answers, givenAnswers); + Pagoda.builder() + .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) + .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl")) + .query(Paths.get(ontoDir, "uobm/queries/uobm_sygenia_all-blanks.sparql")) + .classify(true) + .hermit(true) + .build().run(); } @Test(groups = {"justExecute"}) @@ -104,14 +95,12 @@ public class TestPagodaUOBM { String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); Pagoda.builder() - .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) + .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl-modified.owl")) .data(Paths.get(ontoDir, "uobm/data/uobm1.ttl")) - .query(Paths.get(ontoDir, "uobm/queries/existential_queries.sparql")) -// .answer(answers) - .classify(true) - .hermit(true) - .skolem(false) - .build() - .run(); + .query(Paths.get(ontoDir, "uobm/queries/existential_queries.sparql")) + .classify(true) + .hermit(true) + .build() + .run(); } } -- cgit v1.2.3