当前位置: 首页 > 知识库问答 >
问题:

执行OWL API时获取错误

夏振国
2023-03-14

我正在尝试执行以下代码。

import java.io.File;

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.AddAxiom;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;

public class Snippet {
public static void main(String[] args) throws OWLOntologyCreationException {
    File file = new File(
            "file:///c/Users/DTN/Desktop/Final SubmissionFilteringMechanism_Ontology.owl");
    OWLOntologyManager m = OWLManager.createOWLOntologyManager();
    OWLDataFactory f = OWLManager.getOWLDataFactory();
    OWLOntology o;
    o = m.loadOntologyFromOntologyDocument(file);
    OWLClass clsA = f.getOWLClass(IRI.create("urn:test#ClassA"));
    OWLClass clsB = f.getOWLClass(IRI.create("urn:test#ClassB"));
    OWLAxiom ax1 = f.getOWLSubClassOfAxiom(clsA, clsB);
    AddAxiom addAxiom1 = new AddAxiom(o, ax1);
    m.applyChange(addAxiom1);
    for (OWLClass cls : o.getClassesInSignature()) {
        System.out.println(cls.getIRI());
    }
    m.removeOntology(o);
}
}

它正在生成以下错误。

线程“main”java.lang.NoClassDeffounder异常错误:com/google/inject/provider在java.lang.ClassLoader.DefineClass1(本机方法)在java.lang.ClassLoader.DefineClass(未知源)在java.net.URLClassLoader.DefineClass(未知源)在java.net.URLClassLoader.DefineClass(未知源)在java.net.URLClassLoader.Access$100(未知源)在java.net.URLClassLoader.Access$1(未知源)在00(未知源)在java.net.URLClassLoader$1处。运行(未知源)在java.net.URLClassLoader$1处运行(未知源)在java.security.AccessController.DOPrivileged(本机方法)在java.net.URLClassLoader.FindClass(未知源)在java.lang.ClassLoader.LoadClass(未知源)在sun.misc.Launcher处$AppClassLoader.LoadClass(未知源)在test.main(test.java:18)处

请有人来帮帮我。提前道谢。

共有1个答案

艾成益
2023-03-14

在类路径中包含哪些JAR?

看起来您缺少了一些google guice依赖项。我建议使用一些依赖管理工具,如maven或gradle

例如,我通过使用maven依赖项来解决这个问题

net.sourceforge.owlapi:owlapi-osgiDistribution:4.0.2

将代码段类作为主类的maven项目。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fake</groupId>
<artifactId>fake</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
  <dependency>
    <groupId>net.sourceforge.owlapi</groupId>
    <artifactId>owlapi-osgidistribution</artifactId>
    <version>4.0.2</version>
  </dependency>
</dependencies>

null

如果您想在不使用依赖项管理器的情况下运行它,请确保在您的类路径中有以下JAR(以下列表是通过maven依赖项树命令获得的)

[INFO] \- net.sourceforge.owlapi:owlapi-osgidistribution:jar:4.0.2:compile
[INFO]    +- org.openrdf.sesame:sesame-model:jar:2.7.12:compile
[INFO]    |  \- org.openrdf.sesame:sesame-util:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-api:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-languages:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-datatypes:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-binary:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-n3:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-nquads:jar:2.7.12:compile
[INFO]    |  \- commons-io:commons-io:jar:2.4:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-ntriples:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-rdfjson:jar:2.7.12:compile
[INFO]    |  \- com.fasterxml.jackson.core:jackson-core:jar:2.2.1:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-rdfxml:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-trix:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-turtle:jar:2.7.12:compile
[INFO]    +- org.openrdf.sesame:sesame-rio-trig:jar:2.7.12:compile
[INFO]    +- com.github.jsonld-java:jsonld-java-sesame:jar:0.5.0:compile
[INFO]    |  \- com.github.jsonld-java:jsonld-java:jar:0.5.0:compile
[INFO]    |     +- com.fasterxml.jackson.core:jackson-databind:jar:2.3.3:compile
[INFO]    |     |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile
[INFO]    |     +- org.apache.httpcomponents:httpclient-cache:jar:4.2.5:compile
[INFO]    |     +- org.apache.httpcomponents:httpclient:jar:4.2.5:compile
[INFO]    |     |  +- org.apache.httpcomponents:httpcore:jar:4.2.4:compile
[INFO]    |     |  \- commons-codec:commons-codec:jar:1.6:compile
[INFO]    |     \- org.slf4j:jcl-over-slf4j:jar:1.7.7:runtime
[INFO]    +- org.semarglproject:semargl-sesame:jar:0.6.1:compile
[INFO]    |  +- org.semarglproject:semargl-core:jar:0.6.1:compile
[INFO]    |  \- org.semarglproject:semargl-rdfa:jar:0.6.1:compile
[INFO]    |     \- org.semarglproject:semargl-rdf:jar:0.6.1:compile
[INFO]    +- com.google.guava:guava:jar:18.0:compile
[INFO]    +- com.google.inject:guice:jar:4.0-beta:compile
[INFO]    |  +- javax.inject:javax.inject:jar:1:compile
[INFO]    |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO]    +- com.google.inject.extensions:guice-multibindings:jar:4.0-beta:compile
[INFO]    +- com.google.code.findbugs:jsr305:jar:2.0.1:compile
[INFO]    +- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO]    +- org.apache.directory.studio:org.apache.commons.io:jar:2.4:compile
[INFO]    \- net.sf.trove4j:trove4j:jar:3.0.3:compile
 类似资料:
  • 我正在尝试执行以下代码。 它正在生成以下错误。 线程“main”java.lang.NoClassDeffounder异常错误:com/google/inject/provider在java.lang.ClassLoader.DefineClass1(本机方法)在java.lang.ClassLoader.DefineClass(未知源)在java.net.URLClassLoader.Defin

  • 有一种方法可以找到类的所有命名子类,而不需要为(OWLClass子类:reasoner.GetSubclasses(clazz,true).GetFlatened())使用推理器

  • 我在build.gradle中使用以下依赖项: } 我已经注释了一行 为了避免不匹配,但仍然得到以下错误: 错误:任务“:app:dexDebug”的执行失败

  • 我正在做一个教程,试图学习基本的java。我99%确信我正确地遵循了教程,但我收到了一系列错误消息: 在本教程中,他们不使用此符号,但代码在本教程中仍然有效。java中是否有一些更新改变了一切,或者我是否缺少了一些软件来实现这一点? 这是汽车的代码。java: 这是main的代码。java: 很抱歉,如果这个问题措辞不当,我仍然不知道所有的技术术语可以很好地解释这个问题。

  • 为什么在Kotlin中生成签名Apk时会出现这个错误?任何知道解决方案的人请发送答案。 Logcat错误: 我正在添加build.gradle文件。我不知道我的代码有什么问题,所以请任何人知道解决方案请回答。Build.Gradle

  • 问题内容: 我有一个带有库的IntelliJ项目:Hibernate-entitymanager 4.3.4和JPA 2.0-2.0。使用postgresql-9.3.1100.jdbc4连接到数据库。如何解决? jpa-ql>从ItemEntity中选择ItemEntity.name; 问题答案: 只需阅读文档: http://docs.oracle.com/javaee/7/api/javax