gpt4 book ai didi

java - 可卸载导入异常 : Could not load imported ontology

转载 作者:搜寻专家 更新时间:2023-10-31 20:00:33 25 4
gpt4 key购买 nike

我有一个在 Protege 4.3.0 中创建并存储在 OWL 文件中的本体。为了使用 OWL API 加载这个本体,我使用以下代码示例。

public class MySampleClass {
private final OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
private final OWLDataFactory df = manager.getOWLDataFactory();

private final OWLReasonerFactory rf = new StructuralReasonerFactory();

private final OWLOntology ontology;
private final OWLOntologyID id;
private final IRI iri;
private final PrefixManager pm;

private final OWLReasoner reasoner;

/**
*
* @param file
*/
public MySampleClass(File file) {
try {
ontology = manager.loadOntologyFromOntologyDocument(file);
} catch (OWLOntologyInputSourceException | OWLOntologyCreationException ex) {
// throw custom exception
}

id = ontology.getOntologyID();
iri = id.getOntologyIRI();

pm = new DefaultPrefixManager(iri.toString().concat("#"));

reasoner = rf.createReasoner(ontology);
reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_ASSERTIONS);
}
}

但是,如果我尝试加载包含一个或多个导入的本体,如果这些导入不可用,则会抛出 UnloadableImportException,如下例所示:

org.semanticweb.owlapi.model.UnloadableImportException: Could not load imported ontology: http://www.w3.org/2004/02/skos/core Cause: connection timed out

如何解决这个问题?如果导入的本体离线可用,如何在我的本体加载时导入这个本体?

最佳答案

您可以使用 AutoIRIMapper 指向包含本体本地副本的本地文件夹。

AutoIRIMapper mapper=new AutoIRIMapper(folder, true);
manager.addIRIMapper(mapper);

在开始加载本体之前执行此操作。

关于java - 可卸载导入异常 : Could not load imported ontology,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38230527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com