aboutsummaryrefslogtreecommitdiff
path: root/test/uk/ac/ox/cs/pagoda/ore/PagodaOWLReasoner.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/ore/PagodaOWLReasoner.java')
-rw-r--r--test/uk/ac/ox/cs/pagoda/ore/PagodaOWLReasoner.java464
1 files changed, 464 insertions, 0 deletions
diff --git a/test/uk/ac/ox/cs/pagoda/ore/PagodaOWLReasoner.java b/test/uk/ac/ox/cs/pagoda/ore/PagodaOWLReasoner.java
new file mode 100644
index 0000000..4b0c1d4
--- /dev/null
+++ b/test/uk/ac/ox/cs/pagoda/ore/PagodaOWLReasoner.java
@@ -0,0 +1,464 @@
1package uk.ac.ox.cs.pagoda.ore;
2
3import java.util.HashMap;
4import java.util.HashSet;
5import java.util.List;
6import java.util.Map;
7import java.util.Set;
8
9import org.semanticweb.owlapi.model.AxiomType;
10import org.semanticweb.owlapi.model.IRI;
11import org.semanticweb.owlapi.model.OWLAxiom;
12import org.semanticweb.owlapi.model.OWLClass;
13import org.semanticweb.owlapi.model.OWLClassExpression;
14import org.semanticweb.owlapi.model.OWLDataFactory;
15import org.semanticweb.owlapi.model.OWLDataProperty;
16import org.semanticweb.owlapi.model.OWLDataPropertyExpression;
17import org.semanticweb.owlapi.model.OWLLiteral;
18import org.semanticweb.owlapi.model.OWLNamedIndividual;
19import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
20import org.semanticweb.owlapi.model.OWLOntology;
21import org.semanticweb.owlapi.model.OWLOntologyChange;
22import org.semanticweb.owlapi.reasoner.AxiomNotInProfileException;
23import org.semanticweb.owlapi.reasoner.BufferingMode;
24import org.semanticweb.owlapi.reasoner.ClassExpressionNotInProfileException;
25import org.semanticweb.owlapi.reasoner.FreshEntitiesException;
26import org.semanticweb.owlapi.reasoner.FreshEntityPolicy;
27import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
28import org.semanticweb.owlapi.reasoner.IndividualNodeSetPolicy;
29import org.semanticweb.owlapi.reasoner.InferenceType;
30import org.semanticweb.owlapi.reasoner.Node;
31import org.semanticweb.owlapi.reasoner.NodeSet;
32import org.semanticweb.owlapi.reasoner.OWLReasoner;
33import org.semanticweb.owlapi.reasoner.ReasonerInterruptedException;
34import org.semanticweb.owlapi.reasoner.TimeOutException;
35import org.semanticweb.owlapi.reasoner.UnsupportedEntailmentTypeException;
36import org.semanticweb.owlapi.reasoner.impl.OWLClassNodeSet;
37import org.semanticweb.owlapi.util.Version;
38
39import uk.ac.ox.cs.JRDFox.model.GroundTerm;
40import uk.ac.ox.cs.JRDFox.model.Individual;
41import uk.ac.ox.cs.pagoda.query.AnswerTuples;
42import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner;
43
44public class PagodaOWLReasoner implements OWLReasoner {
45
46 QueryReasoner reasoner;
47 OWLOntology ontology;
48 OWLDataFactory factory;
49 boolean sat;
50
51 public PagodaOWLReasoner(OWLOntology ontology) {
52 this.ontology = ontology;
53 factory = ontology.getOWLOntologyManager().getOWLDataFactory();
54 reasoner = QueryReasoner.getInstance(ontology);
55 reasoner.setToClassify(false);
56 reasoner.loadOntology(ontology);
57 sat = reasoner.preprocess();
58 thing = new OWLClassNodeSet(factory.getOWLThing());
59 }
60
61 @Override
62 public String getReasonerName() {
63 return "PAGOdA";
64 }
65
66 @Override
67 public Version getReasonerVersion() {
68 return null;
69 }
70
71 @Override
72 public BufferingMode getBufferingMode() {
73 // TODO Auto-generated method stub
74 return null;
75 }
76
77 @Override
78 public void flush() {
79 // TODO Auto-generated method stub
80
81 }
82
83 @Override
84 public List<OWLOntologyChange> getPendingChanges() {
85 // TODO Auto-generated method stub
86 return null;
87 }
88
89 @Override
90 public Set<OWLAxiom> getPendingAxiomAdditions() {
91 // TODO Auto-generated method stub
92 return null;
93 }
94
95 @Override
96 public Set<OWLAxiom> getPendingAxiomRemovals() {
97 // TODO Auto-generated method stub
98 return null;
99 }
100
101 @Override
102 public OWLOntology getRootOntology() {
103 return ontology;
104 }
105
106 @Override
107 public void interrupt() {
108 // TODO Auto-generated method stub
109
110 }
111
112 @Override
113 public void precomputeInferences(InferenceType... inferenceTypes) throws ReasonerInterruptedException, TimeOutException, InconsistentOntologyException {
114 if (inferenceTypes.length == 1 && inferenceTypes[0].equals(InferenceType.CLASS_ASSERTIONS) && types.isEmpty()) {
115 Set<OWLClass> queriedClasses = new HashSet<OWLClass>();
116 for (OWLOntology onto: ontology.getImportsClosure())
117 for (OWLClass cls: onto.getClassesInSignature(true)) {
118// if (cls.toStringID().equals("http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#Meritage"));
119// else continue;
120 if (!cls.equals(factory.getOWLThing()) && !queriedClasses.contains(cls)) {
121 queriedClasses.add(cls);
122 AnswerTuples tuples = null;
123 try {
124 tuples = reasoner.evaluate(String.format("select distinct ?x where { ?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <%s> .}", cls.toStringID()));
125 int cnt = 0;
126 for (GroundTerm t; tuples.isValid(); tuples.moveNext()) {
127 t = tuples.getTuple().getGroundTerm(0);
128 if (t instanceof Individual) {
129 addType(((Individual) t).getIRI(), cls);
130 ++cnt;
131 }
132 }
133 System.out.println("The number of answers: " + cnt);
134 } finally {
135 if (tuples != null) tuples.dispose();
136 }
137 }
138 }
139 }
140 }
141
142 private void addType(String iri, OWLClass cls) {
143 OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI.create(iri));
144 OWLClassNodeSet set;
145 if (types.containsKey(ind)) {
146 set = types.get(ind);
147 }
148 else {
149 set = new OWLClassNodeSet(factory.getOWLThing());
150 types.put(ind, set);
151 }
152 set.addEntity(cls);
153 }
154
155 @Override
156 public boolean isPrecomputed(InferenceType inferenceType) {
157 // TODO Auto-generated method stub
158 return false;
159 }
160
161 @Override
162 public Set<InferenceType> getPrecomputableInferenceTypes() {
163 return java.util.Collections.singleton(InferenceType.CLASS_ASSERTIONS);
164 }
165
166 @Override
167 public boolean isConsistent() throws ReasonerInterruptedException, TimeOutException {
168 return sat;
169 }
170
171 @Override
172 public boolean isSatisfiable(OWLClassExpression classExpression) throws ReasonerInterruptedException, TimeOutException, ClassExpressionNotInProfileException, FreshEntitiesException, InconsistentOntologyException {
173 // TODO Auto-generated method stub
174 return false;
175 }
176
177 @Override
178 public Node<OWLClass> getUnsatisfiableClasses() throws ReasonerInterruptedException, TimeOutException, InconsistentOntologyException {
179 // TODO Auto-generated method stub
180 return null;
181 }
182
183 @Override
184 public boolean isEntailed(OWLAxiom axiom)
185 throws ReasonerInterruptedException,
186 UnsupportedEntailmentTypeException, TimeOutException,
187 AxiomNotInProfileException, FreshEntitiesException,
188 InconsistentOntologyException {
189 // TODO Auto-generated method stub
190 return false;
191 }
192
193 @Override
194 public boolean isEntailed(Set<? extends OWLAxiom> axioms)
195 throws ReasonerInterruptedException,
196 UnsupportedEntailmentTypeException, TimeOutException,
197 AxiomNotInProfileException, FreshEntitiesException,
198 InconsistentOntologyException {
199 // TODO Auto-generated method stub
200 return false;
201 }
202
203 @Override
204 public boolean isEntailmentCheckingSupported(AxiomType<?> axiomType) {
205 // TODO Auto-generated method stub
206 return false;
207 }
208
209 @Override
210 public Node<OWLClass> getTopClassNode() {
211 // TODO Auto-generated method stub
212 return null;
213 }
214
215 @Override
216 public Node<OWLClass> getBottomClassNode() {
217 // TODO Auto-generated method stub
218 return null;
219 }
220
221 @Override
222 public NodeSet<OWLClass> getSubClasses(OWLClassExpression ce, boolean direct)
223 throws ReasonerInterruptedException, TimeOutException,
224 FreshEntitiesException, InconsistentOntologyException,
225 ClassExpressionNotInProfileException {
226 // TODO Auto-generated method stub
227 return null;
228 }
229
230 @Override
231 public NodeSet<OWLClass> getSuperClasses(OWLClassExpression ce,
232 boolean direct) throws InconsistentOntologyException,
233 ClassExpressionNotInProfileException, FreshEntitiesException,
234 ReasonerInterruptedException, TimeOutException {
235 // TODO Auto-generated method stub
236 return null;
237 }
238
239 @Override
240 public Node<OWLClass> getEquivalentClasses(OWLClassExpression ce)
241 throws InconsistentOntologyException,
242 ClassExpressionNotInProfileException, FreshEntitiesException,
243 ReasonerInterruptedException, TimeOutException {
244 // TODO Auto-generated method stub
245 return null;
246 }
247
248 @Override
249 public NodeSet<OWLClass> getDisjointClasses(OWLClassExpression ce)
250 throws ReasonerInterruptedException, TimeOutException,
251 FreshEntitiesException, InconsistentOntologyException {
252 // TODO Auto-generated method stub
253 return null;
254 }
255
256 @Override
257 public Node<OWLObjectPropertyExpression> getTopObjectPropertyNode() {
258 // TODO Auto-generated method stub
259 return null;
260 }
261
262 @Override
263 public Node<OWLObjectPropertyExpression> getBottomObjectPropertyNode() {
264 // TODO Auto-generated method stub
265 return null;
266 }
267
268 @Override
269 public NodeSet<OWLObjectPropertyExpression> getSubObjectProperties(
270 OWLObjectPropertyExpression pe, boolean direct)
271 throws InconsistentOntologyException, FreshEntitiesException,
272 ReasonerInterruptedException, TimeOutException {
273 // TODO Auto-generated method stub
274 return null;
275 }
276
277 @Override
278 public NodeSet<OWLObjectPropertyExpression> getSuperObjectProperties(
279 OWLObjectPropertyExpression pe, boolean direct)
280 throws InconsistentOntologyException, FreshEntitiesException,
281 ReasonerInterruptedException, TimeOutException {
282 // TODO Auto-generated method stub
283 return null;
284 }
285
286 @Override
287 public Node<OWLObjectPropertyExpression> getEquivalentObjectProperties(
288 OWLObjectPropertyExpression pe)
289 throws InconsistentOntologyException, FreshEntitiesException,
290 ReasonerInterruptedException, TimeOutException {
291 // TODO Auto-generated method stub
292 return null;
293 }
294
295 @Override
296 public NodeSet<OWLObjectPropertyExpression> getDisjointObjectProperties(
297 OWLObjectPropertyExpression pe)
298 throws InconsistentOntologyException, FreshEntitiesException,
299 ReasonerInterruptedException, TimeOutException {
300 // TODO Auto-generated method stub
301 return null;
302 }
303
304 @Override
305 public Node<OWLObjectPropertyExpression> getInverseObjectProperties(
306 OWLObjectPropertyExpression pe)
307 throws InconsistentOntologyException, FreshEntitiesException,
308 ReasonerInterruptedException, TimeOutException {
309 // TODO Auto-generated method stub
310 return null;
311 }
312
313 @Override
314 public NodeSet<OWLClass> getObjectPropertyDomains(
315 OWLObjectPropertyExpression pe, boolean direct)
316 throws InconsistentOntologyException, FreshEntitiesException,
317 ReasonerInterruptedException, TimeOutException {
318 // TODO Auto-generated method stub
319 return null;
320 }
321
322 @Override
323 public NodeSet<OWLClass> getObjectPropertyRanges(
324 OWLObjectPropertyExpression pe, boolean direct)
325 throws InconsistentOntologyException, FreshEntitiesException,
326 ReasonerInterruptedException, TimeOutException {
327 // TODO Auto-generated method stub
328 return null;
329 }
330
331 @Override
332 public Node<OWLDataProperty> getTopDataPropertyNode() {
333 // TODO Auto-generated method stub
334 return null;
335 }
336
337 @Override
338 public Node<OWLDataProperty> getBottomDataPropertyNode() {
339 // TODO Auto-generated method stub
340 return null;
341 }
342
343 @Override
344 public NodeSet<OWLDataProperty> getSubDataProperties(OWLDataProperty pe,
345 boolean direct) throws InconsistentOntologyException,
346 FreshEntitiesException, ReasonerInterruptedException,
347 TimeOutException {
348 // TODO Auto-generated method stub
349 return null;
350 }
351
352 @Override
353 public NodeSet<OWLDataProperty> getSuperDataProperties(OWLDataProperty pe,
354 boolean direct) throws InconsistentOntologyException,
355 FreshEntitiesException, ReasonerInterruptedException,
356 TimeOutException {
357 // TODO Auto-generated method stub
358 return null;
359 }
360
361 @Override
362 public Node<OWLDataProperty> getEquivalentDataProperties(OWLDataProperty pe)
363 throws InconsistentOntologyException, FreshEntitiesException,
364 ReasonerInterruptedException, TimeOutException {
365 // TODO Auto-generated method stub
366 return null;
367 }
368
369 @Override
370 public NodeSet<OWLDataProperty> getDisjointDataProperties(
371 OWLDataPropertyExpression pe) throws InconsistentOntologyException,
372 FreshEntitiesException, ReasonerInterruptedException,
373 TimeOutException {
374 // TODO Auto-generated method stub
375 return null;
376 }
377
378 @Override
379 public NodeSet<OWLClass> getDataPropertyDomains(OWLDataProperty pe,
380 boolean direct) throws InconsistentOntologyException,
381 FreshEntitiesException, ReasonerInterruptedException,
382 TimeOutException {
383 // TODO Auto-generated method stub
384 return null;
385 }
386
387 private Map<OWLNamedIndividual, OWLClassNodeSet> types = new HashMap<OWLNamedIndividual, OWLClassNodeSet>();
388 private OWLClassNodeSet thing;
389
390 @Override
391 public NodeSet<OWLClass> getTypes(OWLNamedIndividual ind, boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException {
392 if (types.containsKey(ind)) return types.get(ind);
393 return thing;
394 }
395
396 @Override
397 public NodeSet<OWLNamedIndividual> getInstances(OWLClassExpression ce,
398 boolean direct) throws InconsistentOntologyException,
399 ClassExpressionNotInProfileException, FreshEntitiesException,
400 ReasonerInterruptedException, TimeOutException {
401 // TODO Auto-generated method stub
402 return null;
403 }
404
405 @Override
406 public NodeSet<OWLNamedIndividual> getObjectPropertyValues(
407 OWLNamedIndividual ind, OWLObjectPropertyExpression pe)
408 throws InconsistentOntologyException, FreshEntitiesException,
409 ReasonerInterruptedException, TimeOutException {
410 // TODO Auto-generated method stub
411 return null;
412 }
413
414 @Override
415 public Set<OWLLiteral> getDataPropertyValues(OWLNamedIndividual ind,
416 OWLDataProperty pe) throws InconsistentOntologyException,
417 FreshEntitiesException, ReasonerInterruptedException,
418 TimeOutException {
419 // TODO Auto-generated method stub
420 return null;
421 }
422
423 @Override
424 public Node<OWLNamedIndividual> getSameIndividuals(OWLNamedIndividual ind)
425 throws InconsistentOntologyException, FreshEntitiesException,
426 ReasonerInterruptedException, TimeOutException {
427 // TODO Auto-generated method stub
428 return null;
429 }
430
431 @Override
432 public NodeSet<OWLNamedIndividual> getDifferentIndividuals(
433 OWLNamedIndividual ind) throws InconsistentOntologyException,
434 FreshEntitiesException, ReasonerInterruptedException,
435 TimeOutException {
436 // TODO Auto-generated method stub
437 return null;
438 }
439
440 @Override
441 public long getTimeOut() {
442 // TODO Auto-generated method stub
443 return 0;
444 }
445
446 @Override
447 public FreshEntityPolicy getFreshEntityPolicy() {
448 // TODO Auto-generated method stub
449 return null;
450 }
451
452 @Override
453 public IndividualNodeSetPolicy getIndividualNodeSetPolicy() {
454 // TODO Auto-generated method stub
455 return null;
456 }
457
458 @Override
459 public void dispose() {
460 // TODO Auto-generated method stub
461
462 }
463
464}