java - 获取导入本体列表--OWL API

标签 java protege owl-api

我正在使用 OWL API 来从本体获取信息。我需要检索加载本体中使用的所有导入本体的列表。

OWL API 中是否有方法可以完成此任务?

我加载本体的代码是:

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLImportsDeclaration;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;

public class NSExtractor {

@SuppressWarnings("deprecation")
public static void main(String[] args) throws FileNotFoundException, OWLOntologyCreationException {

    @SuppressWarnings("resource")       
    File testFile= new File("C:\\acco.n3");

    OWLOntologyManager m = OWLManager.createOWLOntologyManager();
    OWLDataFactory f = OWLManager.getOWLDataFactory();
    OWLOntology o; 
    o = m.loadOntologyFromOntologyDocument(testFile);

最佳答案

经过大量搜索,我找到了解决此任务的方法。我使用了 OWLOntologyXMLNamespaceManager(我使用的是 OWL API 5.1.6)。 然后,使用 getPrefixes 和 getNameSpaces 可以分别为加载的本体提取前缀和命名空间,如下所示:

OWLDocumentFormat format = m.getOntologyFormat(ontology);

OWLOntologyXMLNamespaceManager nsManager = new OWLOntologyXMLNamespaceManager(ontology, format);

        for (String prefix : nsManager.getPrefixes()) {
            System.out.println(prefix);
        }
        for (String ns : nsManager.getNamespaces()) {
            System.out.println(ns);
        }

关于java - 获取导入本体列表--OWL API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52137237/

相关文章:

java - 无法从容器外部运行的 Spring Boot 应用程序连接到容器中运行的 Kafka

java - 为什么不允许在 Java 实例初始化 block 中抛出异常?

Azure Cosmos 文档数据库的 Java Api (SQL Api)

owl - 如何在 Protégé 中输入电子邮件地址作为对象?

rdf - 在 Protege 本体中扩展 DBpedia 实体

java - 将 RDF-triple 添加到 owl 本体中 (OWL API 4.3.0)

java - HermiT 推理机的数据类型为 “UnsupportedDatatypeException”

java - 如何在点击图像时生成事件?

java - 使用 Jena 读取限制值

java - 如何区分推断公理和显式公理?