Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获取导入的本体的列表——OWLAPI_Java_Protege_Owl Api - Fatal编程技术网

Java 获取导入的本体的列表——OWLAPI

Java 获取导入的本体的列表——OWLAPI,java,protege,owl-api,Java,Protege,Owl Api,我使用OWLAPI是为了从本体中获取信息。我需要检索加载的本体中使用的所有导入本体的列表 OWLAPI中是否有方法可以完成此任务 我加载本体的代码是: import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAnnotationProperty; import org.semanticwe

我使用OWLAPI是为了从本体中获取信息。我需要检索加载的本体中使用的所有导入本体的列表

OWLAPI中是否有方法可以完成此任务

我加载本体的代码是:

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);

经过多次搜索,我找到了如何解决这项任务。我使用了owlontologyxmlnamspacemanager(我使用的是owlapi5.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);
        }

o.importsDeclarations()
将为您提供此本体的导入声明流。这是使用
owl:imports
属性声明的IRI列表

注意:这些是声明的导入,而不是导入闭包-区别在于导入闭包包括在本体中导入的本体和由这些本体导入的本体-递归地包括导入的本体


o.importClosure()
将提供在本体解析过程中加载的所有本体。

前缀和名称空间与导入的本体不同。据我所知,在加载本体时,我可以使用
o.importsDeclarations()
。但在我的例子中,有一些与导入本体论的非直接联系。我想处理这些链接,并将本体文件下载到本地目录,以使用一组SimpleRimApper。那么,如何在不加载本体的情况下从导入声明中获取IRIs呢?或者是否有其他方法(使用MissingImportListener等)使用非直接(甚至中断)导入链接加载本体?。。。因此,似乎我必须实现定制的
OWLOntologyIRIMapper