Importing owl files
I have a problem with importing owl files using owl api in Java. I successfully can import 2 owl files. However, a problem occurs, when I try to import 开发者_运维百科3 or more owl files that are integrated to each other. E.g.
Base.owl -- base ontology
Electronics.owl -- electronics ontology which imports Base.owl
Telephone.owl -- telephone ontology which imports Base.owl and Electronics.owl
When, I just import Base.owl and run Electronics.owl, it works smoothly. The code is given below:
File fileBase = new File("filepath/Base.owl");
File fileElectronic = new File("filePath/Electronic.owl");
SimpleIRIMapper iriMapper = new SimpleIRIMapper(IRI.create("url/Base.owl"),
IRI.create(fileBase));
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
manager.addIRIMapper(iriMapper);
OWLOntology ont = manager.loadOntologyFromOntologyDocument(fileElectronic);
However, when I want to load Telephone.owl, I just create an additional iriMapper and add it to the manager. The additional code is shown with ** :
File fileBase = new File("filepath/Base.owl");
File fileElectronic = new File("filePath/Electronic.owl");
**File fileTelephone = new File("filePath/Telephone.owl");**
SimpleIRIMapper iriMapper = new SimpleIRIMapper(IRI.create("url/Base.owl"),
IRI.create(fileBase));
**SimpleIRIMapper iriMapper2 = new SimpleIRIMapper(IRI.create("url/Electronic.owl"),
IRI.create(fileElectronic));**
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
manager.addIRIMapper(iriMapper);
**manager.addIRIMapper(iriMapper2);**
OWLOntology ont = manager.loadOntologyFromOntologyDocument(**fileTelephone**);
The code shown above gives this error :
Could not load import:
Import(url/Electronic.owl>)
Reason: Could not loaded imported ontology:
<url/Base.owl> Cause: null
It would be really appreciated, if someone gives me a hand... Thanks in advance...
I know this question is old, but it was my first hit on google seraching for a similar problem (loading many owl-imports). And I need a lot of time to find an answer.
So for all who have the problem that the owlapi will say: "Could not loaded imported ontology": The owlapi provides a utility-class named "AutoIRIMapper" (described here: http://owlapi.sourceforge.net/2.x.x/utilityclasses.html and http://owlapi.sourceforge.net/javadoc/index.html). Once created an instance of "AutoIRIMapper" can be addaded to the "OWLOntologyManager" using the following code:
"manager.addIRIMapper(autoIRIMapper);"
After that the OWLOntologyManager will be able to automatically load all imported OWL-Files.
I hope that will help someone.
if you want to make a request to the manager to load an ontology declared in an imports statement, you can use the makeLoadImportRequest method, which takes an OWLImportsDeclaration as a parameter.
See whether that solves your problem.
Good luck!
精彩评论