内.owl
文件,我声明了一些这样的前缀:
Prefix(:=<http://default.ont/my_ont/>)
Prefix(ex:=<http://example.org/ex#>)
Prefix(ex2:=<http://example2.org/ex#>)
...
并在这样的 Java 项目中使用我的本体:OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File(resourceFullPath(ontologyFilename)));
现在我想建一个 Map<String, String>
以编程方式包含以下内容:{
"" -> "http://default.ont/my_ont/",
"ex" -> "http://example.org/ex#",
"ex2" -> "http://example2.org/ex#"
}
我怎样才能用 OWL API 做到这一点(即没有自己解析 .owl
文件)?
最佳答案
解析过程中发现的前缀作为 OWLDocumentFormat
的一部分保存。与本体关联的实例:
OWLDocumentFormat format = manager.getOntologyFormat(ontology);
if (format.isPrefixOWLDocumentFormat()) {
// this is the map you need
Map<String, String> map = format.asPrefixOWLDocumentFormat().getPrefixName2PrefixMap();
}
关于java - 使用 OWL API 提取本体命名空间/前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65480889/