aboutsummaryrefslogtreecommitdiff
path: root/test/uk/ac/ox/cs/pagoda/global_tests
diff options
context:
space:
mode:
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/global_tests')
-rw-r--r--test/uk/ac/ox/cs/pagoda/global_tests/MinimumCardinalityTest.java101
-rw-r--r--test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java37
2 files changed, 114 insertions, 24 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 @@
1package uk.ac.ox.cs.pagoda.global_tests;
2
3import org.semanticweb.owlapi.apibinding.OWLManager;
4import org.semanticweb.owlapi.model.*;
5import org.testng.Assert;
6import org.testng.annotations.Test;
7import uk.ac.ox.cs.pagoda.query.AnswerTuple;
8import uk.ac.ox.cs.pagoda.query.AnswerTuples;
9import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner;
10import uk.ac.ox.cs.pagoda.util.TestUtil;
11
12import java.io.IOException;
13import java.nio.file.Files;
14import java.nio.file.Paths;
15
16public 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/TestPagodaUOBM.java b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java
index 1d9f1e6..6daeacc 100644
--- a/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java
+++ b/test/uk/ac/ox/cs/pagoda/global_tests/TestPagodaUOBM.java
@@ -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
89 Pagoda pagoda = Pagoda.builder()
90 .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl"))
91 .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl"))
92 .query(Paths.get(ontoDir, "uobm/queries/uobm_sygenia_all-blanks.sparql"))
93// .answer(answers)
94 .classify(true)
95 .hermit(true)
96 .build();
97 83
98 pagoda.run(); 84 Pagoda.builder()
99// CheckAnswers.assertSameAnswers(answers, givenAnswers); 85 .ontology(Paths.get(ontoDir, "uobm/univ-bench-dl.owl"))
86 .data(Paths.get(ontoDir, "uobm/data/uobm" + number + ".ttl"))
87 .query(Paths.get(ontoDir, "uobm/queries/uobm_sygenia_all-blanks.sparql"))
88 .classify(true)
89 .hermit(true)
90 .build().run();
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}