Java 用owlapi提取本体名称空间/前缀

Java 用owlapi提取本体名称空间/前缀,java,namespaces,ontology,prefix,owl-api,Java,Namespaces,Ontology,Prefix,Owl Api,在.owl文件中,我声明了一些前缀,如下所示: Prefix(:=<http://default.ont/my_ont/>) Prefix(ex:=<http://example.org/ex#>) Prefix(ex2:=<http://example2.org/ex#>) ... OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology ontology

在.owl文件中,我声明了一些前缀,如下所示:

Prefix(:=<http://default.ont/my_ont/>)
Prefix(ex:=<http://example.org/ex#>)
Prefix(ex2:=<http://example2.org/ex#>)
...
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File(resourceFullPath(ontologyFilename)));
现在,我想以编程方式构建一个包含以下内容的地图:

{
  ""    -> "http://default.ont/my_ont/",
  "ex"  -> "http://example.org/ex#",
  "ex2" -> "http://example2.org/ex#"
}

我如何在没有自己解析.owl文件的情况下实现这一点?

解析过程中找到的前缀作为与本体相关联的OWLDocumentFormat实例的一部分保存:

OWLDocumentFormat format = manager.getOntologyFormat(ontology);
if (format.isPrefixOWLDocumentFormat()) {
    // this is the map you need
    Map<String, String> map = format.asPrefixOWLDocumentFormat().getPrefixName2PrefixMap();
}