java - 使用 OWL API 提取本体命名空间/前缀
问题描述
在一个.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();
}
推荐阅读
- javascript - 带有条件输出/应用的 Javascript 数组过滤器
- java - 在 java 程序中使用来自 hub.KerasLayer 和 python 和 tensorflow 2.1.0 的模型时,“图中没有名为 [input] 的操作”
- dataframe - 如何识别列pysapk中的第一条记录
- ios - Swift 5:更改 REST API 查询的 url,在 UILabel 中显示响应
- python - 了解 PyTorch LSTM 的输入形状
- javascript - Highcharts 更新功能无法正常工作
- ios - 如何在 react-native-community Google Signin for ios 中实现 openURL?
- c++ - 按值类型和常量重载的 C++ 函数(完整详细信息)
- api - 我需要支持非洲说话 api 的国家列表
- powershell - 使用 powershell 导出证书