001 package org.dllearner.test;
002
003 import org.semanticweb.owl.model.*;
004 import org.semanticweb.owl.apibinding.OWLManager;
005 import org.semanticweb.owl.inference.OWLReasoner;
006 import org.semanticweb.owl.inference.OWLReasonerException;
007
008 import java.net.URI;
009 import java.util.HashSet;
010 import java.util.Set;
011 import java.io.File;
012
013 public class FaCTBugDemo {
014
015 public static void main(String[] args) {
016
017 try {
018 URI uri = new File("examples/father.owl").toURI();
019
020 // Create our ontology manager in the usual way.
021 OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
022
023 // Load a copy of the pizza ontology. We'll load the ontology from the web.
024 OWLOntology ont = manager.loadOntologyFromPhysicalURI(uri);
025
026 OWLReasoner reasoner = new uk.ac.manchester.cs.factplusplus.owlapi.Reasoner(manager);
027 // OWLReasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager);
028
029 // seems to be needed for some reason although no ontology is imported
030 Set<OWLOntology> importsClosure = manager.getImportsClosure(ont);
031 reasoner.loadOntologies(importsClosure);
032
033 reasoner.classify();
034 reasoner.realise();
035
036 OWLDataFactory factory = manager.getOWLDataFactory();
037
038 OWLClass male = factory.getOWLClass(URI.create("http://example.com/father#male"));
039 OWLObjectProperty hasChild = factory.getOWLObjectProperty(URI.create("http://example.com/father#hasChild"));
040 OWLObjectSomeRestriction hasSomeChild = factory.getOWLObjectSomeRestriction(hasChild, factory.getOWLThing());
041 Set<OWLDescription> set = new HashSet<OWLDescription>();
042 set.add(male);
043 set.add(hasSomeChild);
044 OWLDescription father = factory.getOWLObjectIntersectionOf(set);
045 OWLIndividual martin = factory.getOWLIndividual(URI.create("http://example.com/father#martin"));
046
047 if(reasoner.hasType(martin, father, false))
048 System.out.println("positive result"); // Pellet 1.5.1 (correct)
049 else
050 System.out.println("negative result"); // FaCT++ 1.10
051
052 }
053 catch(UnsupportedOperationException exception) {
054 System.out.println("Unsupported reasoner operation.");
055 }
056 catch(OWLReasonerException ex) {
057 System.out.println("Reasoner error: " + ex.getMessage());
058 }
059 catch (OWLOntologyCreationException e) {
060 System.out.println("Could not load the pizza ontology: " + e.getMessage());
061 } catch (Exception e) {
062 e.printStackTrace();
063 }
064 }
065 }