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

openllet.modularity.ModularityUtils Maven / Gradle / Ivy

// 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 openllet.modularity;

import com.clarkparsia.owlapi.modularity.locality.LocalityClass;
import java.util.Iterator;
import java.util.Set;
import java.util.stream.Collectors;
import openllet.core.utils.iterator.NestedIterator;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLOntology;
import uk.ac.manchester.cs.owlapi.modularity.ModuleType;

/**
 * @author Evren Sirin
 */
public class ModularityUtils
{
	/**
	 * Extract the module from the imports closure of the given ontology for the given signature. Modules contain axioms related to the signature elements that
	 * describe how they relate to each other. There are four module types supported with the following very rough explanations: 
    lower (top) module * contains subclasses of the signature elements
  • upper (bot) module contains superclasses of the signature elements
  • upper-of-lower * (bot_of_top) module extract the upper module from the lower module
  • lower-of-upper (top_of_bot) module - extract the lower module from the upper * module
The module types are closely related to the locality class used. Lower module is extracted with top locality and thus also called top * module. * * @param ontology ontolgoy from which the module is extracted * @param signature set of entities used to extract the module * @param moduleType type of the module * @return a set of axioms representing the relevant axioms for the signature elements */ public static Set extractModule(final OWLOntology ontology, final Set signature, final ModuleType moduleType) { return extractModule(ontology.importsClosure().collect(Collectors.toSet()), signature, moduleType); } /** * Extract the module from a given set of ontologies (but not their imports) for the given signature. Only the axioms in the given set of ontologies is * considered. Only the axioms from the ontologies that explicitly exists in the given set will be included in the module. * * @see #extractModule(OWLOntology, Set, ModuleType) * @param ontologies ontologies from which the module is extracted * @param signature set of entities used to extract the module * @param moduleType type of the module * @return a set of axioms representing the relevant axioms for the signature elements */ public static Set extractModule(final Set ontologies, final Set signature, final ModuleType moduleType) { switch (moduleType) { case TOP: return extractTopModule(axiomIterator(ontologies), signature); case BOT: return extractBottomModule(axiomIterator(ontologies), signature); case STAR: final Set bottomModule = extractBottomModule(axiomIterator(ontologies), signature); return extractTopModule(bottomModule.iterator(), signature); default: throw new UnsupportedOperationException("Unrecognized module type: " + moduleType); } } private static Iterator axiomIterator(final Set ontologies) { return new NestedIterator(ontologies) { @Override public Iterator getInnerIterator(final OWLOntology ont) { return ont.axioms().iterator(); } }; } private static Set extractTopModule(final Iterator axioms, final Set signature) { return extractModule(axioms, signature, LocalityClass.TOP_TOP); } private static Set extractBottomModule(final Iterator axioms, final Set signature) { return extractModule(axioms, signature, LocalityClass.BOTTOM_BOTTOM); } private static Set extractModule(final Iterator axioms, final Set signature, final LocalityClass localityClass) { final ModuleExtractor extractor = new AxiomBasedModuleExtractor(localityClass); while (axioms.hasNext()) extractor.addAxiom(axioms.next()); return extractor.extractModule(signature); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy