I am using OWL API in order to get information from ontologies. I need to retrieve the list of all imported ontologies used in the loaded ontology.
Is there a method in OWL API can do this task?
my code that load an ontology is:
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLImportsDeclaration;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
public class NSExtractor {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws FileNotFoundException, OWLOntologyCreationException {
@SuppressWarnings("resource")
File testFile= new File("C:\\acco.n3");
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
OWLDataFactory f = OWLManager.getOWLDataFactory();
OWLOntology o;
o = m.loadOntologyFromOntologyDocument(testFile);
o.importsDeclarations()
will give you a stream of imports declarations for this ontology. This is the list of IRIs declared with owl:imports
properties.
Note: these are the declared imports, not the imports closure - the difference is that the imports closure includes the ontologies imported in your ontology and the ontologies imported by these ontologies - recursively including the imported ontologies.
o.importsClosure()
will provide all ontologies that were loaded during parsing of your ontology.