From 3d44aee6069175038266c65f945147569e6343f6 Mon Sep 17 00:00:00 2001 From: RncLsn Date: Thu, 9 Jul 2015 16:01:01 +0100 Subject: Bug-fix for answer dependencies analysis: now it checks whether the endomorphism makes the first tuple identical to the second one. --- .../cs/pagoda/endomorph/DependencyGraphTest.java | 59 ++++++++++++++++++++++ test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java | 14 +++-- test/uk/ac/ox/cs/pagoda/util/TestUtil.java | 7 +++ 3 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 test/uk/ac/ox/cs/pagoda/endomorph/DependencyGraphTest.java (limited to 'test/uk') diff --git a/test/uk/ac/ox/cs/pagoda/endomorph/DependencyGraphTest.java b/test/uk/ac/ox/cs/pagoda/endomorph/DependencyGraphTest.java new file mode 100644 index 0000000..eec1e8f --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/endomorph/DependencyGraphTest.java @@ -0,0 +1,59 @@ +package uk.ac.ox.cs.pagoda.endomorph; + +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.*; +import org.testng.annotations.Test; +import uk.ac.ox.cs.JRDFox.model.GroundTerm; +import uk.ac.ox.cs.JRDFox.model.Individual; +import uk.ac.ox.cs.pagoda.query.AnswerTuple; +import uk.ac.ox.cs.pagoda.summary.Graph; +import uk.ac.ox.cs.pagoda.summary.NodeTuple; +import uk.ac.ox.cs.pagoda.util.TestUtil; + +import java.util.HashSet; + +import static uk.ac.ox.cs.pagoda.util.TestUtil.getEntityIRI; + +public class DependencyGraphTest { + + private OWLOntology getOntology() throws OWLOntologyCreationException { + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLDataFactory factory = manager.getOWLDataFactory(); + OWLOntology ontology = manager.createOntology(); + + OWLClass hardWorkingStudent = factory.getOWLClass(getEntityIRI("HardWorkingStudent")); + manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(hardWorkingStudent)); + OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); + OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); + OWLObjectProperty takesCourse = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "takesCourse"))); + manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(takesCourse)); + + // Class assertions + manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(hardWorkingStudent, a)); // HardWorkingStudent(a) + manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(hardWorkingStudent, b)); // HardWorkingStudent(b) + + // Minimum cardinality axiom + manager.addAxiom(ontology, + factory.getOWLEquivalentClassesAxiom(hardWorkingStudent, + factory.getOWLObjectMinCardinality(3, + takesCourse))); + return ontology; + } + + @Test + public void test() throws OWLOntologyCreationException { + OWLOntology ontology = getOntology(); + Graph graph = new Graph(ontology); + DependencyGraph dependencyGraph = new DependencyGraph(graph); + + HashSet tuples = new HashSet<>(); + tuples.add(graph.getNodeTuple(new AnswerTuple(new GroundTerm[]{Individual.create(String.format(TestUtil.NS, "a")), Individual.create(String.format(TestUtil.NS, "a"))}))); + tuples.add(graph.getNodeTuple(new AnswerTuple(new GroundTerm[]{Individual.create(String.format(TestUtil.NS, "a")), Individual.create(String.format(TestUtil.NS, "b"))}))); + tuples.add(graph.getNodeTuple(new AnswerTuple(new GroundTerm[]{Individual.create(String.format(TestUtil.NS, "b")), Individual.create(String.format(TestUtil.NS, "a"))}))); + tuples.add(graph.getNodeTuple(new AnswerTuple(new GroundTerm[]{Individual.create(String.format(TestUtil.NS, "b")), Individual.create(String.format(TestUtil.NS, "b"))}))); + + dependencyGraph.build(tuples); + + System.out.println(dependencyGraph.getTopologicalOrder()); + } +} diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java b/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java index 6e60e24..3f14ec7 100644 --- a/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java +++ b/test/uk/ac/ox/cs/pagoda/global_tests/BugTests.java @@ -14,13 +14,11 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import static uk.ac.ox.cs.pagoda.util.TestUtil.getEntityIRI; + 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 minimumCardinalityAxiom2() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { @@ -41,7 +39,7 @@ public class BugTests { manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(hardWorkingStudent)); OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a")); OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b")); - OWLObjectProperty takesCourse = factory.getOWLObjectProperty(IRI.create(String.format(NS, "takesCourse"))); + OWLObjectProperty takesCourse = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "takesCourse"))); manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(takesCourse)); // Class assertions @@ -105,7 +103,7 @@ public class BugTests { 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"))); + OWLObjectProperty takesCourse = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "takesCourse"))); manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(takesCourse)); // Class assertions @@ -183,9 +181,9 @@ public class BugTests { 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"))); + OWLObjectProperty roleR = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "R"))); manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleR)); - OWLObjectProperty roleP = factory.getOWLObjectProperty(IRI.create(String.format(NS, "P"))); + OWLObjectProperty roleP = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "P"))); manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(roleP)); // Class assertions diff --git a/test/uk/ac/ox/cs/pagoda/util/TestUtil.java b/test/uk/ac/ox/cs/pagoda/util/TestUtil.java index fdd242a..c7f024a 100644 --- a/test/uk/ac/ox/cs/pagoda/util/TestUtil.java +++ b/test/uk/ac/ox/cs/pagoda/util/TestUtil.java @@ -3,6 +3,7 @@ package uk.ac.ox.cs.pagoda.util; import org.apache.log4j.Appender; import org.apache.log4j.FileAppender; import org.apache.log4j.Logger; +import org.semanticweb.owlapi.model.IRI; import java.io.File; import java.io.IOException; @@ -87,4 +88,10 @@ public class TestUtil { LOGGER.error(msg, t); } + public static final String NS = "http://example.org/test#%s"; + + public static IRI getEntityIRI(String name) { + return IRI.create(String.format(NS, name)); + } + } -- cgit v1.2.3