导入owl文件

时间:2010-06-14 16:44:39

标签: api import ontology owl

我在使用Java中的owl api导入owl文件时遇到问题。我成功导入了2个猫头鹰文件。但是,当我尝试导入3个或更多相互集成的owl文件时,会出现问题。 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

当我刚刚导入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

如果有人帮我一把,真的很感激... 提前谢谢......

2 个答案:

答案 0 :(得分:2)

我知道这个问题已经过时了,但这是我第一次尝试google搜索类似的问题(加载许多owl-imports)。我需要很多时间才能找到答案。

因此对于所有有问题的人来说,owlapi会说:“无法加载导入的本体”:owlapi提供了一个名为“AutoIRIMapper”的实用程序类(在此描述:{{3} }和http://owlapi.sourceforge.net/2.x.x/utilityclasses.html)。 创建后,可以使用以下代码将“AutoIRIMapper”实例添加到“OWLOntologyManager”中:

"manager.addIRIMapper(autoIRIMapper);"

之后,OWLOntologyManager将能够自动加载所有导入的OWL文件。

我希望这会对某人有所帮助。

答案 1 :(得分:1)

如果要向管理员发出加载import语句中声明的本体的请求,可以使用makeLoadImportRequest方法,该方法将OWLImportsDeclaration作为参数。

看看是否能解决您的问题。

祝你好运!