1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
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 static uk.ac.ox.cs.pagoda.util.TestUtil.getEntityIRI;
public class MadeUpCases {
@Test(groups = {"existential"})
public void someTest() throws OWLOntologyCreationException, IOException, OWLOntologyStorageException {
/*
* Build test ontology
* */
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology();
OWLClass A1 = factory.getOWLClass(getEntityIRI("A1"));
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A1));
OWLClass A2 = factory.getOWLClass(getEntityIRI("A2"));
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A2));
OWLClass A3 = factory.getOWLClass(getEntityIRI("A3"));
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A3));
OWLClass A4 = factory.getOWLClass(getEntityIRI("A4"));
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(A4));
OWLNamedIndividual a = factory.getOWLNamedIndividual(getEntityIRI("a"));
OWLNamedIndividual b = factory.getOWLNamedIndividual(getEntityIRI("b"));
OWLObjectProperty R = factory.getOWLObjectProperty(IRI.create(String.format(TestUtil.NS, "R")));
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(R));
// Class assertions
manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(A1, a));
manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(A1, b));
// Minimum cardinality axiom
manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A1, factory.getOWLObjectSomeValuesFrom(R, A2)));
manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A2, factory.getOWLObjectSomeValuesFrom(R, A3)));
manager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(A3, factory.getOWLObjectSomeValuesFrom(R, A4)));
manager.addAxiom(ontology, factory.getOWLTransitiveObjectPropertyAxiom(R));
// 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 <" + R.toStringID() + "> _:z . "
+ " ?y <" + R.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();
}
}
|