【问题标题】:Extracting ontology namespaces/prefixes with OWL API使用 OWL API 提取本体命名空间/前缀
【发布时间】:2021-04-05 10:02:22
【问题描述】:

.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&lt;String, String&gt;,内容如下:

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

如何使用OWL API 执行此操作(即,无需自己解析.owl 文件)?

【问题讨论】:

    标签: java namespaces ontology prefix owl-api


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-12
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多