All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clarkparsia.owlapi.explanation.PelletExplanation Maven / Gradle / Ivy

There is a newer version: 2.3.6-ansell
Show newest version
// Copyright (c) 2006 - 2008, Clark & Parsia, LLC. 
// This source code is available under the terms of the Affero General Public License v3.
//
// Please see LICENSE.txt for full license terms, including the availability of proprietary exceptions.
// Questions, comments, or requests for clarification: [email protected]

package com.clarkparsia.owlapi.explanation;

import java.util.Set;

import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;

import com.clarkparsia.pellet.owlapiv3.PelletReasoner;
import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;

/**
 * @author Evren Sirin
 */
public class PelletExplanation {
	static {
		setup();
	}

	/**
	 * Very important initialization step that needs to be called once before a
	 * reasoner is created. This function will be called automatically when
	 * GlassBoxExplanation is loaded by the class loader. This function simply
	 * calls the {@link GlassBoxExplanation#setup()} function.
	 */
	public static void setup() {
		GlassBoxExplanation.setup();
	}
	
	private OWLDataFactory factory;
	
	private HSTExplanationGenerator expGen;
	
	private SatisfiabilityConverter converter;
	
	public PelletExplanation(OWLOntology ontology) {
		this( ontology, true );
	}
	
	public PelletExplanation(OWLOntology ontology, boolean useGlassBox) {
		this( new PelletReasonerFactory().createReasoner( ontology ), useGlassBox );
	}

	public PelletExplanation(PelletReasoner reasoner) {
		this( reasoner, true );
	}
	
	private PelletExplanation(PelletReasoner reasoner, boolean useGlassBox) {
		// Get the factory object
		factory = reasoner.getManager().getOWLDataFactory();
		
		// Create a single explanation generator
		TransactionAwareSingleExpGen singleExp = useGlassBox 
			? new GlassBoxExplanation( reasoner )
			: new BlackBoxExplanation( reasoner.getRootOntology(), new PelletReasonerFactory(), reasoner );
		
		// Create multiple explanation generator
		expGen = new HSTExplanationGenerator( singleExp );		
		
		// Create the converter that will translate axioms into class expressions
		converter = new SatisfiabilityConverter( factory );
	}
	
	
	 public Set getEntailmentExplanation(OWLAxiom axiom) {
    	OWLClassExpression unsatClass = converter.convert( axiom );
    	return getUnsatisfiableExplanation( unsatClass );
    }
    
    public Set> getEntailmentExplanations(OWLAxiom axiom) {
    	OWLClassExpression unsatClass = converter.convert( axiom );
    	return getUnsatisfiableExplanations( unsatClass );
    }


    public Set> getEntailmentExplanations(OWLAxiom axiom, int maxExplanations) {
    	OWLClassExpression unsatClass = converter.convert( axiom );
    	return getUnsatisfiableExplanations( unsatClass, maxExplanations );
    }
    
    
    public Set getInconsistencyExplanation() {
    	return getUnsatisfiableExplanation( factory.getOWLThing() );
    }
    
    public Set> getInconsistencyExplanations() {
    	return getUnsatisfiableExplanations( factory.getOWLThing() );
    }
    
    public Set> getInconsistencyExplanations(int maxExplanations) {
    	return getUnsatisfiableExplanations( factory.getOWLThing(), maxExplanations );
    }
    
    public Set getInstanceExplanation(OWLIndividual ind, OWLClassExpression cls) {
    	OWLClassAssertionAxiom classAssertion = factory.getOWLClassAssertionAxiom( cls, ind );
    	return getEntailmentExplanation( classAssertion );
    }
    
    public Set> getInstanceExplanations(OWLIndividual ind, OWLClassExpression cls) {
    	OWLClassAssertionAxiom classAssertion = factory.getOWLClassAssertionAxiom( cls, ind );
    	return getEntailmentExplanations( classAssertion );
    }
    
    public Set> getInstanceExplanations(OWLIndividual ind, OWLClassExpression cls, int maxExplanations) {
    	OWLClassAssertionAxiom classAssertion = factory.getOWLClassAssertionAxiom( cls, ind );
    	return getEntailmentExplanations( classAssertion, maxExplanations );
    }
    
    public Set getSubClassExplanation(OWLClassExpression subClass, OWLClassExpression superClass) {
    	OWLSubClassOfAxiom subClassAxiom = factory.getOWLSubClassOfAxiom( subClass, superClass );
    	return getEntailmentExplanation( subClassAxiom );
    }
    
    public Set> getSubClassExplanations(OWLClassExpression subClass, OWLClassExpression superClass) {
    	OWLSubClassOfAxiom subClassAxiom = factory.getOWLSubClassOfAxiom( subClass, superClass );
    	return getEntailmentExplanations( subClassAxiom );    	
    }
    
    public Set> getSubClassExplanations(OWLClassExpression subClass, OWLClassExpression superClass, int maxExplanations) {
    	OWLSubClassOfAxiom subClassAxiom = factory.getOWLSubClassOfAxiom( subClass, superClass );
    	return getEntailmentExplanations( subClassAxiom, maxExplanations );
    }
    
    /**
     * Returns a single explanation for an arbitrary class expression, or empty set
     * if the given expression is satisfiable.
     * @param unsatClass an unsatisfiabile class expression which is  will be
     *                   explained
     * @return set of axioms explaining the unsatisfiability of given class
     *         expression, or empty set if the given expression is satisfiable.
     */
    public Set getUnsatisfiableExplanation(OWLClassExpression unsatClass) {
    	return expGen.getExplanation( unsatClass );
    }
    
    /**
     * Returns all the explanations for the given unsatisfiable class.
     * @param unsatClass The class that is unsatisfiable for which an explanation
     * will be generated.
     * @return All explanations for the given unsatisfiable class, or an empty
     *         set if the concept is satisfiable
     */
    public Set> getUnsatisfiableExplanations(OWLClassExpression unsatClass) {
    	return expGen.getExplanations( unsatClass );
    }
    
    /**
     * Return a specified number of explanations for the given unsatisfiable
     * class. A smaller number of explanations can be returned if there are not
     * as many explanations for the given concept. The returned set will be
     * empty if the given class is satisfiable,
     * 
     * @param unsatClass The class that is unsatisfiable for which an explanation
     * will be generated. 
     * @param maxExplanations Maximum number of explanations requested, or 0 to get all the
     *                        explanations
     * @return A specified number of explanations for the given unsatisfiable
     *         class, or an empty set if the concept is satisfiable
     */
    public Set> getUnsatisfiableExplanations(OWLClassExpression unsatClass, int maxExplanations) {
    	return expGen.getExplanations( unsatClass, maxExplanations );
    }    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy