加载 ontology 以提取所有导入的名称空间

Loading ontology to extract all the imported name spaces

我正在尝试加载保存在我 PC 上的 ontology。文件格式为 .n3。 经过大量工作并寻找可能的解决方案后,我没有找到合适的方法来加载 ontology.

我尝试了以下代码:

import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.model.OWLModel;

public class Extractor {

public static void main(String[] args) {
    String ontologyURI = "file:///C:/acco.n3";
    try {

        OWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI(ontologyURI);       
        System.out.println("Worked");

    }catch (Exception exception) {  
        System.out.println("Error can't upload the ontologie ");
    }
}
}

但它总是给我这个错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at com.hp.hpl.jena.graph.Node.<clinit>(Node.java:35)
at com.hp.hpl.jena.rdf.model.impl.ResourceImpl.fresh(ResourceImpl.java:108)
at com.hp.hpl.jena.rdf.model.impl.ResourceImpl.<init>(ResourceImpl.java:68)
at com.hp.hpl.jena.rdf.model.ResourceFactory$Impl.createResource(ResourceFactory.java:176)
at com.hp.hpl.jena.rdf.model.ResourceFactory.createResource(ResourceFactory.java:69)
at com.hp.hpl.jena.vocabulary.RDF.resource(RDF.java:29)
at com.hp.hpl.jena.vocabulary.RDF.<clinit>(RDF.java:37)
at com.hp.hpl.jena.datatypes.xsd.impl.XMLLiteralType.<clinit>(XMLLiteralType.java:30)
at com.hp.hpl.jena.datatypes.TypeMapper.<clinit>(TypeMapper.java:52)
at edu.stanford.smi.protegex.owl.model.impl.OWLSystemFrames.createRDFSDatatypes(Unknown Source)
at edu.stanford.smi.protegex.owl.model.impl.OWLSystemFrames.createOWLInstances(Unknown Source)
at edu.stanford.smi.protegex.owl.model.impl.OWLSystemFrames.createOWLMetaModel(Unknown Source)
at edu.stanford.smi.protegex.owl.model.impl.OWLSystemFrames.<init>(Unknown Source)
at edu.stanford.smi.protegex.owl.swrl.SWRLSystemFrames.<init>(Unknown Source)
at edu.stanford.smi.protegex.owl.model.impl.AbstractOWLModel.createSystemFrames(Unknown Source)
at edu.stanford.smi.protegex.owl.model.impl.AbstractOWLModel.createSystemFrames(Unknown Source)
at edu.stanford.smi.protege.model.DefaultKnowledgeBase.<init>(DefaultKnowledgeBase.java:79)
at edu.stanford.smi.protegex.owl.model.impl.AbstractOWLModel.<init>(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.JenaOWLModel.<init>(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.JenaKnowledgeBaseFactory.createKnowledgeBase(Unknown Source)
at edu.stanford.smi.protege.model.Project.createDomainKB(Project.java:429)
at edu.stanford.smi.protege.model.Project.createDomainKnowledgeBase(Project.java:447)
at edu.stanford.smi.protegex.owl.jena.creator.OwlProjectFromUriCreator.create(Unknown Source)
at edu.stanford.smi.protegex.owl.ProtegeOWL.createJenaOWLModelFromURI(Unknown Source)
at Extractor.main(Extractor.java:28)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 25 more

我需要你的帮助来解决这个错误,或者找到一种方法来加载本体以从中提取知识。 提前致谢。


更新:

我按照@Roddy of the Frozen Peas 的建议将缺少的依赖项添加到class 路径。

但它给了我以下错误:

WARNING: [Local Folder Repository] The specified file must be a directory. (C:\eclipse-workspace\NewEx\plugins\edu.stanford.smi.protegex.owl) -- LocalFolderRepository.update()
Exception in thread "main" java.lang.NoClassDefFoundError: org/protege/editor/owl/model/hierarchy/roots/Relation
at edu.stanford.smi.protegex.owl.jena.parser.TripleProcessor.<init>(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.parser.GlobalParserCache.getTripleProcessor(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.parser.ProtegeOWLParser.loadTriples(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.parser.ProtegeOWLParser.run(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.JenaKnowledgeBaseFactory.loadKnowledgeBase(Unknown Source)
at edu.stanford.smi.protege.model.Project.loadDomainKB(Project.java:1346)
at edu.stanford.smi.protege.model.Project.createDomainKnowledgeBase(Project.java:456)
at edu.stanford.smi.protegex.owl.jena.creator.OwlProjectFromUriCreator.create(Unknown Source)
at edu.stanford.smi.protegex.owl.ProtegeOWL.createJenaOWLModelFromURI(Unknown Source)
at Extractor.main(Extractor.java:10)
Caused by: java.lang.ClassNotFoundException: org.protege.editor.owl.model.hierarchy.roots.Relation
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 10 more

有什么建议吗?

java.lang.ClassNotFoundException: org.protege.editor.owl.model.hierarchy.roots.Relation

您还需要其他依赖项。与其零敲碎打,不如使用可以为您解决依赖闭包问题的构建系统,例如 Maven、Gradle 或类似的系统。

这里的问题不是 Protege 特有的或 ontology 相关,它只是类路径中缺少 Java 个库。

请注意,您的代码不使用 OWL API。这些 类 是 Jena 类 和 Protege 类(我认为来自 Protege 3.x)。请注意,Protege 3.x 是一个非常过时的 API。考虑使用较新的版本(5.2.0 或更新版本),或直接使用实际的 OWL API。参见 https://github.com/owlcs/owlapi/wiki/Documentation

OWL API 也有包含所有依赖项的 zip 文件,这可能会简化您的工作(Maven 仍然比手动解决依赖项更好)。参见 https://github.com/owlcs/releases/tree/master/owlapi/5