001 package org.dllearner.test;
002
003 import org.semanticweb.owl.apibinding.OWLManager;
004 import org.semanticweb.owl.inference.OWLReasoner;
005 import org.semanticweb.owl.model.*;
006 import org.semanticweb.owl.util.SimpleURIMapper;
007
008 import java.io.File;
009 import java.net.URI;
010 import java.util.HashSet;
011 import java.util.Set;
012
013 public class OWLAPIBugDemo {
014
015 public static void main(String[] args) {
016 try {
017
018 OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
019 URI ontologyURI = URI.create("http://www.examples.com/test");
020 // File f = new File("test.owl");
021
022 File f = new File("src/dl-learner/org/dllearner/tools/ore/inconsistent.owl");
023 URI physicalURI = f.toURI();
024 SimpleURIMapper mapper = new SimpleURIMapper(ontologyURI, physicalURI);
025 manager.addURIMapper(mapper);
026
027 OWLOntology ontology = manager.createOntology(ontologyURI);
028 OWLDataFactory factory = manager.getOWLDataFactory();
029
030 // create a set of two individuals
031 OWLIndividual a = factory.getOWLIndividual(URI.create(ontologyURI + "#a"));
032 OWLIndividual b = factory.getOWLIndividual(URI.create(ontologyURI + "#b"));
033 Set<OWLIndividual> inds = new HashSet<OWLIndividual>();
034 inds.add(a);
035 inds.add(b);
036
037 // create a set of two classes
038 OWLClass c = factory.getOWLClass(URI.create(ontologyURI + "#c"));
039 OWLClass d = factory.getOWLClass(URI.create(ontologyURI + "#d"));
040 Set<OWLClass> classes = new HashSet<OWLClass>();
041 classes.add(c);
042 classes.add(d);
043
044 // state that a and b are different
045 OWLAxiom axiom = factory.getOWLDifferentIndividualsAxiom(inds);
046 AddAxiom addAxiom = new AddAxiom(ontology, axiom);
047 manager.applyChange(addAxiom);
048
049 // state that c and d are disjoint
050 OWLAxiom axiom2 = factory.getOWLDisjointClassesAxiom(classes);
051 AddAxiom addAxiom2 = new AddAxiom(ontology, axiom2);
052 manager.applyChange(addAxiom2);
053
054 // add property p with domain c
055 OWLObjectProperty p = factory.getOWLObjectProperty(URI.create(ontologyURI + "#p"));
056 OWLAxiom axiom3 = factory.getOWLObjectPropertyDomainAxiom(p, c);
057 AddAxiom addAxiom3 = new AddAxiom(ontology, axiom3);
058 manager.applyChange(addAxiom3);
059
060 Set<OWLOntology> ontologies = new HashSet<OWLOntology>();
061 ontologies.add(ontology);
062
063 OWLReasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager);
064 reasoner.loadOntologies(ontologies);
065
066 // class cast exception
067 Set<Set<OWLDescription>> test = reasoner.getDomains(p);
068 // OWLClass oc = (OWLClass) test.iterator().next();
069 // System.out.println(oc);
070 for(Set<OWLDescription> test2 : test) {
071 System.out.println(test2);
072 }
073
074 // save ontology
075 manager.saveOntology(ontology);
076 }
077 catch (OWLException e) {
078 e.printStackTrace();
079 }
080 }
081 }