// Path: src/main/java/org/semanticweb/owl/explanation/api/ExplanationException.java
// public class ExplanationException extends OWLRuntimeException {
// 
// 
//     public ExplanationException(Throwable cause) {
//         super(cause);
//     }
// 
// 
//     public ExplanationException(String message) {
//         super(message);
//     }
// 
// 
//     public ExplanationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: src/main/java/org/semanticweb/owl/explanation/api/RootDerivedReasoner.java
// public interface RootDerivedReasoner {
// 
//     /**
//      * Gets the root unsatisfiable classes.
//      * @return A set of classes that represent the root unsatisfiable classes
//      */
//     Set<OWLClass> getRootUnsatisfiableClasses() throws ExplanationException;
// 
//     Set<OWLClass> getDependentChildClasses(OWLClass cls);
// 
// 
//     Set<OWLClass> getDependentDescendantClasses(OWLClass cls);
// }


import org.semanticweb.owl.explanation.api.ExplanationException;
import org.semanticweb.owl.explanation.api.RootDerivedReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.search.EntitySearcher;
import java.util.*;
package org.semanticweb.owl.explanation.impl.rootderived;


/*
 * Copyright (C) 2008, University of Manchester
 *
 * Modifications to the initial code base are copyright of their
 * respective authors, or their employers as appropriate.  Authorship
 * of the modifications may be determined from the ChangeLog placed at
 * the end of this file.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */


/**
 * Author: Matthew Horridge<br> The University Of Manchester<br> Information Management Group<br> Date:
 * 07-Sep-2008<br><br>
 */
public class StructuralRootDerivedReasoner implements RootDerivedReasoner {

    private OWLOntologyManager man;

    private OWLReasoner reasoner;

    private OWLReasonerFactory reasonerFactory;

    private OWLOntology mergedOntology;

    private Map<OWLClass, Set<OWLClass>> child2Parent;

    private Map<OWLClass, Set<OWLClass>> parent2Child;

    private Set<OWLClass> roots;

    private boolean dirty;


    public StructuralRootDerivedReasoner(OWLOntologyManager man, OWLReasoner reasoner, OWLReasonerFactory reasonerFactory) {
        this.man = man;
        this.reasonerFactory = reasonerFactory;
        this.reasoner = reasoner;
        this.child2Parent = new HashMap<OWLClass, Set<OWLClass>>();
        this.parent2Child = new HashMap<OWLClass, Set<OWLClass>>();
        roots = new HashSet<OWLClass>();

        try {
            getMergedOntology();
        }
// Path: src/main/java/org/semanticweb/owl/explanation/api/ExplanationException.java
// public class ExplanationException extends OWLRuntimeException {
// 
// 
//     public ExplanationException(Throwable cause) {
//         super(cause);
//     }
// 
// 
//     public ExplanationException(String message) {
//         super(message);
//     }
// 
// 
//     public ExplanationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: src/main/java/org/semanticweb/owl/explanation/api/RootDerivedReasoner.java
// public interface RootDerivedReasoner {
// 
//     /**
//      * Gets the root unsatisfiable classes.
//      * @return A set of classes that represent the root unsatisfiable classes
//      */
//     Set<OWLClass> getRootUnsatisfiableClasses() throws ExplanationException;
// 
//     Set<OWLClass> getDependentChildClasses(OWLClass cls);
// 
// 
//     Set<OWLClass> getDependentDescendantClasses(OWLClass cls);
// }


// Path: src/main/java/org/semanticweb/owl/explanation/impl/rootderived/StructuralRootDerivedReasoner.java
import org.semanticweb.owl.explanation.api.ExplanationException;
import org.semanticweb.owl.explanation.api.RootDerivedReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.search.EntitySearcher;
import java.util.*;

package org.semanticweb.owl.explanation.impl.rootderived;


/*
 * Copyright (C) 2008, University of Manchester
 *
 * Modifications to the initial code base are copyright of their
 * respective authors, or their employers as appropriate.  Authorship
 * of the modifications may be determined from the ChangeLog placed at
 * the end of this file.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */


/**
 * Author: Matthew Horridge<br> The University Of Manchester<br> Information Management Group<br> Date:
 * 07-Sep-2008<br><br>
 */
public class StructuralRootDerivedReasoner implements RootDerivedReasoner {

    private OWLOntologyManager man;

    private OWLReasoner reasoner;

    private OWLReasonerFactory reasonerFactory;

    private OWLOntology mergedOntology;

    private Map<OWLClass, Set<OWLClass>> child2Parent;

    private Map<OWLClass, Set<OWLClass>> parent2Child;

    private Set<OWLClass> roots;

    private boolean dirty;


    public StructuralRootDerivedReasoner(OWLOntologyManager man, OWLReasoner reasoner, OWLReasonerFactory reasonerFactory) {
        this.man = man;
        this.reasonerFactory = reasonerFactory;
        this.reasoner = reasoner;
        this.child2Parent = new HashMap<OWLClass, Set<OWLClass>>();
        this.parent2Child = new HashMap<OWLClass, Set<OWLClass>>();
        roots = new HashSet<OWLClass>();

        try {
            getMergedOntology();
        }
        catch (ExplanationException e) {