我在Java中使用owl api导入owl文件时遇到问题。我可以成功地导入2个owl文件。然而,当我尝试导入3个或更多相互集成的owl文件时,出现了一个问题。例如。
Base.owl -- base ontology
Electronics.owl -- electronics ontology which imports Base.owl
Telephone.owl -- telephone ontology which imports Base.owl and Electronics.owl当我导入Base.owl并运行Electronics.owl时,它工作得很流畅。代码如下:
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);但是,当我想要加载Telephone.owl时,我只需创建一个额外的iriMapper并将其添加到管理器中。附加代码用**表示:
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**);上面显示的代码给出了这个错误:
Could not load import:
Import(url/Electronic.owl>)
Reason: Could not loaded imported ontology:
<url/Base.owl> Cause: null如果有人能帮我一把,我将不胜感激...先谢谢你...
发布于 2012-03-07 17:47:17
我知道这个问题很老了,但这是我第一次在google上搜索类似的问题(加载许多owl-import)。我需要很多时间来找出答案。
因此,对于所有有问题的人,owlapi会说:“无法加载导入的本体”:owlapi提供了一个名为"AutoIRIMapper" (在此处描述:http://owlapi.sourceforge.net/2.x.x/utilityclasses.html和http://owlapi.sourceforge.net/javadoc/index.html)的实用程序类。创建后,可以使用以下代码将"AutoIRIMapper“的实例添加到"OWLOntologyManager”:
"manager.addIRIMapper(autoIRIMapper);"
在此之后,OWLOntologyManager将能够自动加载所有导入的OWL文件。
我希望这会对某些人有所帮助。
发布于 2010-06-17 08:35:32
如果您希望向管理器请求加载在imports语句中声明的本体,则可以使用makeLoadImportRequest方法,该方法接受一个OWLImportsDeclaration作为参数。
看看这是否能解决你的问题。
祝好运!
https://stackoverflow.com/questions/3039097
复制相似问题