/* * #%L * Elk Examples Package * * $Id$ * $HeadURL$ * %% * Copyright (C) 2011 - 2012 Department of Computer Science, University of Oxford * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ package org.semanticweb.elk.owlapi.examples; import java.io.File; import java.util.ArrayList; import java.util.List; import org.semanticweb.elk.owlapi.ElkReasonerFactory; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; import org.semanticweb.owlapi.model.OWLOntologyStorageException; import org.semanticweb.owlapi.reasoner.InferenceType; import org.semanticweb.owlapi.reasoner.OWLReasoner; import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; import org.semanticweb.owlapi.util.InferredAxiomGenerator; import org.semanticweb.owlapi.util.InferredEquivalentClassAxiomGenerator; import org.semanticweb.owlapi.util.InferredOntologyGenerator; import org.semanticweb.owlapi.util.InferredSubClassAxiomGenerator; /** * This example shows how to classify an ontology and save the resulting * taxonomy into a new file. The example is based on the example from the OWL * API documentation. * * * @author Frantisek Simancik * @author Pavel Klinov * * pavel.klinov@uni-ulm.de * */ public class SavingInferredAxioms { public static void main(String[] args) throws OWLOntologyStorageException, OWLOntologyCreationException { OWLOntologyManager man = OWLManager.createOWLOntologyManager(); // Load your ontology. OWLOntology ont = man.loadOntologyFromOntologyDocument(new File( "c:/ontologies/ontology.owl")); // Create an ELK reasoner. OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ont); // Classify the ontology. reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); // To generate an inferred ontology we use implementations of // inferred axiom generators List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>(); gens.add(new InferredSubClassAxiomGenerator()); gens.add(new InferredEquivalentClassAxiomGenerator()); // Put the inferred axioms into a fresh empty ontology. OWLOntology infOnt = man.createOntology(); InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens); iog.fillOntology(man, infOnt); // Save the inferred ontology. man.saveOntology(infOnt, IRI.create((new File("c:/ontologies/result.owl").toURI()))); // Terminate the worker threads used by the reasoner. reasoner.dispose(); } }