From 39b60d4225f5efa4e0287a2c6ce69d90391c69db Mon Sep 17 00:00:00 2001 From: RncLsn Date: Fri, 3 Jul 2015 19:09:31 +0100 Subject: Many little changes. --- test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java | 184 +++++++++++++++++++++ .../global_tests/MinimumCardinalityTest.java | 101 ----------- .../ox/cs/pagoda/global_tests/TestPagodaFLY.java | 6 +- .../ox/cs/pagoda/global_tests/TestPagodaLUBM.java | 10 +- .../ox/cs/pagoda/global_tests/TestPagodaUOBM.java | 26 +-- .../ox/cs/pagoda/util/SimpleProgressBarTester.java | 16 ++ 6 files changed, 219 insertions(+), 124 deletions(-) create mode 100644 test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java delete mode 100644 test/uk/ac/ox/cs/pagoda/global_tests/MinimumCardinalityTest.java create mode 100644 test/uk/ac/ox/cs/pagoda/util/SimpleProgressBarTester.java (limited to 'test/uk/ac/ox/cs/pagoda') diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java b/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java new file mode 100644 index 0000000..19e0b2a --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java @@ -0,0 +1,184 @@ +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.query.QueryRecord; +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 BugTests { + + public static final String NS = "http://example.org/test#%s"; + + private IRI getEntityIRI(String name) { + return IRI.create(String.format(NS, name)); + } + + @Test + public void minimumCardinalityAxiom() 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(); + } + + /** + * Bug: the relevant ontology is not a subset of the original one. + * + * @throws OWLOntologyCreationException + * @throws IOException + * @throws OWLOntologyStorageException + */ + @Test + public void rTest() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { + + /* + * Build test ontology + * */ + + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLDataFactory factory = manager.getOWLDataFactory(); + OWLOntology ontology = manager.createOntology(); + + OWLClass classA = factory.getOWLClass(getEntityIRI("A")); + manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classA)); + OWLClass classB = factory.getOWLClass(getEntityIRI("B")); + manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(classB)); + OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); + OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); + OWLNamedIndividual c = factory.getOWLNamedIndividual(getEntityIRI("c")); + OWLObjectProperty roleR = factory.getOWLObjectProperty(IRI.create(String.format(NS, "R"))); + manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleR)); + OWLObjectProperty roleP = factory.getOWLObjectProperty(IRI.create(String.format(NS, "P"))); + manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleP)); + + // Class assertions + manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, a)); // A(a) + manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(classA, b)); // A(b) + manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(roleP, c, a)); // P(c,a) + + // Axioms + // subsetOf(A someValuesFrom(R owl:Thing)) + manager.addAxiom(ontology, + factory.getOWLSubClassOfAxiom(classA, + factory.getOWLObjectSomeValuesFrom(roleR, + factory.getOWLThing()))); + + // inverseFunctional(R) + manager.addAxiom(ontology, + factory.getOWLInverseFunctionalObjectPropertyAxiom(roleR)); + + // subsetOf(someValuesFrom(inverseOf(P) owl:thing) B) + manager.addAxiom(ontology, + factory.getOWLSubClassOfAxiom(factory.getOWLObjectSomeValuesFrom(roleP.getInverseProperty(), + factory.getOWLThing()), + classB)); + /* + * Save the ontology + * */ + +// 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 queryStr = "PREFIX rdf: " + + "select distinct ?x" + + " where { " + + " ?x rdf:type " + classB + + " }"; + QueryRecord queryRecord = pagoda.getQueryManager().create(queryStr); + System.out.println(queryRecord); + pagoda.evaluate(queryRecord); + AnswerTuples answers = queryRecord.getAnswers(); + System.out.println("Difficulty: " + queryRecord.getDifficulty()); + for(AnswerTuple ans; answers.isValid(); answers.moveNext()) { + ans = answers.getTuple(); + TestUtil.logInfo(ans); + } + } + pagoda.dispose(); + } +} diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/MinimumCardinalityTest.java b/test/uk/ac/ox/cs/pagoda/global_tests/MinimumCardinalityTest.java deleted file mode 100644 index 71c20c1..0000000 --- a/test/uk/ac/ox/cs/pagoda/global_tests/MinimumCardinalityTest.java +++ /dev/null @@ -1,101 +0,0 @@ -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 31d2eac..0ce3d69 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaFLY.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaFLY.java @@ -25,7 +25,6 @@ public class TestPagodaFLY { .query(Paths.get(ontoDir, "fly/queries/fly.sparql")) .answer(answers) .classify(false) - .hermit(true) .build(); pagoda.run(); @@ -45,7 +44,6 @@ public class TestPagodaFLY { .answer(answers) // .answer(Paths.get("/home/alessandro/Desktop/answers.json")) .classify(false) - .hermit(true) .build(); pagoda.run(); @@ -57,8 +55,8 @@ public class TestPagodaFLY { String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); Pagoda.builder() - .ontology(Paths.get(ontoDir, "fly/fly_rolledUp.owl")) -// .ontology(Paths.get(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl")) +// .ontology(Paths.get(ontoDir, "fly/fly_rolledUp.owl")) + .ontology(Paths.get(ontoDir, "fly/fly_anatomy_XP_with_GJ_FC_individuals.owl")) .query(Paths.get(ontoDir, "fly/queries/new_queries.sparql")) // .answer(Paths.get("/home/alessandro/Desktop/answers.json")) .classify(false) 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 fdbfc42..c893f96 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaLUBM.java @@ -23,8 +23,6 @@ public class TestPagodaLUBM { .data(Paths.get(ontoDir, "lubm/data/lubm" + number + ".ttl")) .query(Paths.get(ontoDir, "lubm/queries/test.sparql")) .answer(answers) - .classify(true) - .hermit(true) .build(); pagoda.run(); @@ -45,11 +43,9 @@ public class TestPagodaLUBM { Pagoda pagoda = Pagoda.builder() .ontology(Paths.get(ontoDir, "lubm/univ-bench.owl")) .data(Paths.get(ontoDir, "lubm/data/lubm" + number + ".ttl")) - .query(Paths.get(ontoDir, "lubm/queries/lubm_sygenia.sparql")) + .query(Paths.get(ontoDir, "lubm/queries/lubm_sygenia.sparql")) // .answer(answers) - .classify(true) - .hermit(true) - .build(); + .build(); pagoda.run(); // CheckAnswers.assertSameAnswers(answers, givenAnswers); @@ -71,8 +67,6 @@ public class TestPagodaLUBM { .data(Paths.get(ontoDir, "lubm/data/lubm" + number + ".ttl")) .query(Paths.get(ontoDir, "lubm/queries/lubm_sygenia_all-blanks.sparql")) // .answer(answers) - .classify(true) - .hermit(true) .build(); pagoda.run(); 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 9fb6cbe..c5b272c 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java @@ -41,8 +41,6 @@ public class TestPagodaUOBM { .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl")) .query(Paths.get(ontoDir, "uobm/queries/test.sparql")) .answer(answers) - .classify(true) - .hermit(true) .build(); pagoda.run(); @@ -65,8 +63,6 @@ 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")) - .classify(true) - .hermit(true) .build(); pagoda.run(); @@ -85,22 +81,30 @@ 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_all-blanks.sparql")) - .classify(true) - .hermit(true) + .build() + .run(); + } + + @Test(groups = {"justExecute", "heavy", "nonOriginal"}) + public void justExecute_modifiedUOBM() throws IOException { + String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); + + Pagoda.builder() + .ontology(Paths.get(ontoDir, "uobm_modified/univ-bench-dl-modified.owl")) + .data(Paths.get(ontoDir, "uobm_modified/data/uobm1.ttl")) + .query(Paths.get(ontoDir, "uobm_modified/queries/additional_queries.sparql")) .build() .run(); } @Test(groups = {"justExecute"}) - public void justExecute_existentialQueries() throws IOException { + public void justExecute_additionalQueries() throws IOException { String ontoDir = TestUtil.getConfig().getProperty("ontoDir"); Pagoda.builder() - .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl-modified.owl")) + .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl")) .data(Paths.get(ontoDir, "uobm/data/uobm1.ttl")) - .query(Paths.get(ontoDir, "uobm/queries/existential_queries.sparql")) - .classify(true) - .hermit(true) + .query(Paths.get(ontoDir, "uobm/queries/additional_queries.sparql")) .build() .run(); } diff --git a/test/uk/ac/ox/cs/pagoda/util/SimpleProgressBarTester.java b/test/uk/ac/ox/cs/pagoda/util/SimpleProgressBarTester.java new file mode 100644 index 0000000..3de30e4 --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/util/SimpleProgressBarTester.java @@ -0,0 +1,16 @@ +package uk.ac.ox.cs.pagoda.util; + +import org.testng.annotations.Test; + +public class SimpleProgressBarTester { + + @Test + public void test() throws InterruptedException { + SimpleProgressBar simpleProgressBar = new SimpleProgressBar("TestBar", 1000); + for(int i = 0; i < 1000; i++) { + simpleProgressBar.update(i); + Thread.sleep(10); + } + simpleProgressBar.dispose(); + } +} -- cgit v1.2.3