001    package org.dllearner.tools.ore;
002    
003    import java.io.IOException;
004    import java.io.PrintWriter;
005    import java.net.URI;
006    import java.util.Set;
007    
008    import org.mindswap.pellet.owlapi.Reasoner;
009    import org.semanticweb.owl.apibinding.OWLManager;
010    import org.semanticweb.owl.model.OWLAxiom;
011    import org.semanticweb.owl.model.OWLClass;
012    import org.semanticweb.owl.model.OWLDataFactory;
013    import org.semanticweb.owl.model.OWLException;
014    import org.semanticweb.owl.model.OWLOntology;
015    import org.semanticweb.owl.model.OWLOntologyCreationException;
016    import org.semanticweb.owl.model.OWLOntologyManager;
017    
018    
019    @SuppressWarnings("unused")
020    public class ExplanationTest {
021    
022    //      private static final String     file    = "file:examples/ore/inconsistent.owl";
023            private static final String     file    = "file:examples/ore/buggyPolicy.owl";
024            private static final String     NS              = "http://cohse.semanticweb.org/ontologies/people#";
025            
026            /**
027             * @param args
028             */
029            public static void main(String[] args) {
030                    /*
031                            try {
032                                    PelletExplanation.setup();
033                                    
034                                    // The renderer is used to pretty print explanation
035                                    ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer();
036                                    // The writer used for the explanation rendered
037                                    PrintWriter out = new PrintWriter( System.out );
038                                    renderer.startRendering( out );
039    
040                                    // Create an OWLAPI manager that allows to load an ontology file and
041                                    // create OWLEntities
042                                    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
043                                    OWLOntology ontology = manager.loadOntology( URI.create( file ) );
044                                    OWLDataFactory factory = manager.getOWLDataFactory();
045                                    
046                                    // Create the reasoner and load the ontology
047                                    Reasoner reasoner = new Reasoner( manager );
048                                    reasoner.loadOntology( ontology );
049                                    
050                                    // Create an explanation generator
051                                    PelletExplanation expGen = new PelletExplanation( reasoner );
052                                    
053                                    // Create some concepts
054                                    OWLClass madCow = factory.getOWLClass( URI.create( NS + "mad+cow" ) );
055                                    OWLClass animalLover = factory.getOWLClass( URI.create( NS + "animal+lover" ) );
056                                    OWLClass petOwner = factory.getOWLClass( URI.create( NS + "pet+owner" ) );
057                                    
058                                    //Explain why ontology is inconsistent
059                                    out.println( "Why is ontology inconsistent?" ); 
060                                    renderer.render(expGen.getInconsistencyExplanations());
061                                    
062                                    out.println( "unsatisfiable classes:" );                
063                                    for(OWLClass cl : reasoner.getClasses()){
064                                            if(!reasoner.isSatisfiable(cl)){
065                                                    out.println(cl);
066                                                    renderer.render(expGen.getUnsatisfiableExplanations(cl));
067                                            }
068                                    }
069                                    
070                                    
071                                    
072                                    
073                                    // Explain why mad cow is an unsatisfiable concept
074                                    Set<Set<OWLAxiom>> exp = expGen.getUnsatisfiableExplanations( madCow );
075                                    out.println( "Why is " + madCow + " concept unsatisfiable?" );          
076                                    renderer.render( exp );
077    
078                                    // Now explain why animal lover is a sub class of pet owner
079                                    exp = expGen.getSubClassExplanations( animalLover, petOwner );
080                                    out.println( "Why is " + animalLover + " subclass of " + petOwner + "?" );
081                                    renderer.render( exp );
082                                    
083                                    renderer.endRendering();
084                            } catch (OWLOntologyCreationException e) {
085                                    // TODO Auto-generated catch block
086                                    e.printStackTrace();
087                            } catch (UnsupportedOperationException e) {
088                                    // TODO Auto-generated catch block
089                                    e.printStackTrace();
090                            } catch (OWLException e) {
091                                    // TODO Auto-generated catch block
092                                    e.printStackTrace();
093                            } catch (IOException e) {
094                                    // TODO Auto-generated catch block
095                                    e.printStackTrace();
096                            }
097                            */
098                    }
099                    
100    }
101    
102