我有一个本体,由两个单独的文件组成:
((后者仅包含实例)
我的想法是使用曼彻斯特OWL API 5读取Abox并获取签名中的所有对象属性(例如)。
Abox使用owl:imports
来包含Tbox。但是-根据我的理解-首先,我必须将Tbox的远程IRI(例如http://mywebsite.com/ontology/artists.owl
)映射到系统中的本地文件。
这是我尝试过的:
// Create an ontology manager
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// Manually map imports
IRI remoteIRI = IRI.create("http://mywebsite.com/ontology/tbox.owl");
IRI localIRI = IRI.create(new File("tbox.owl"));
SimpleIRIMapper mapper = new SimpleIRIMapper(remoteIRI, localIRI);
manager.getIRIMappers().add(mapper);
// Read individuals (i.e. ABox)
File file = new File("abox.owl");
OWLOntology ABox = manager.loadOntologyFromOntologyDocument(file);
这是它引发的异常:
Exception in thread "main" org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException: Ontology already exists. OntologyID(OntologyIRI(<http://mywebsite.com/ontology/tbox.owl>) VersionIRI(<null>))
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.load(OWLOntologyManagerImpl.java:1122)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOntologyManagerImpl.java:1057)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:1007)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:1020)
at examples.PopulateDatabaseWithPropIndividuals.main(PopulateDatabaseWithPropIndividuals.java:71)
Caused by: org.semanticweb.owlapi.model.OWLOntologyRenameException: Could not rename ontology. An ontology with this ID already exists: OntologyID(OntologyIRI(<http://mywebsite.com/ontology/tbox.owl>) VersionIRI(<null>))
有什么想法吗?
这两个本体不能具有相同的IRI,因为这会在持有它们的管理器中以及从重用的角度更普遍地造成歧义。如果要公开您的本体,或者即使它们是私有的,但是您希望在其他项目中使用它们,则另一个本体就不可能唯一地标识要导入的本体。
我建议的解决方法是修改abox本体IRI并向其中添加owl:imports
语句,以导入tbox本体。尽管这不是最常见的模式,但也可以从另一个方向完成(tbox可以导入abox)。您还可以添加第三个本体,其目的仅是将两个本体聚合在一起,并且仅包含两个import语句,分别指向abox和tbox。