ontology - 在java中添加SWRLAPI来操作swrl规则时出现异常

标签 ontology owl-api swrlapi

当我想使用 Drools API 添加 SWRLAPI 或 SWRL 时遇到问题。 我添加了 SWRLAPI、带有 Drools 的 SWRLAPI 和带有 Maven 的 OWLAPI 依赖项。 SWRLAPIFactory.createSWRLRuleEngine(o); 似乎有问题 这是我的主要类(class)

    OWLOntologyManager m = OWLManager.createOWLOntologyManager();
    File file = new File("OoEI.owl");
    OWLOntology o = m.loadOntologyFromOntologyDocument(file);
     // Create a SWRL rule engine using the SWRLAPI  
    SWRLRuleEngine ruleEngine = SWRLAPIFactory.createSWRLRuleEngine(o);
    PelletReasoner reasoner = com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory.getInstance().createReasoner( o );

这是我的 pom.xml :

<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>OWLAPITest</groupId>
<artifactId>OWLAPITest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
        <resource>
            <directory>src</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>


<dependencies>
    <!-- https://mvnrepository.com/artifact/net.sourceforge.owlapi/owlapi-distribution -->
    <dependency>
        <groupId>net.sourceforge.owlapi</groupId>
        <artifactId>owlapi-distribution</artifactId>
        <version>5.1.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.github.ansell.pellet/pellet-owlapiv3 -->
    <dependency>
        <groupId>com.github.ansell.pellet</groupId>
        <artifactId>pellet-owlapiv3</artifactId>
        <version>2.3.3</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/edu.stanford.swrl/swrlapi-drools-engine -->
    <dependency>
        <groupId>edu.stanford.swrl</groupId>
        <artifactId>swrlapi-drools-engine</artifactId>
        <version>2.0.0</version>
    </dependency>


    <dependency>
        <groupId>edu.stanford.swrl</groupId>
        <artifactId>swrlapi</artifactId>
        <version>2.0.0</version>
    </dependency>






</dependencies>

我得到这个异常:

    Exception in thread "main" org.swrlapi.exceptions.SWRLRuleEngineException: Error creating rule engine Drools. Exception: java.lang.NoSuchMethodError. Message: org.semanticweb.owlapi.model.OWLOntologyManager.getIRIMappers()Lorg/semanticweb/owlapi/util/PriorityCollection;
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:73)
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:43)
    at org.swrlapi.factory.SWRLAPIFactory.createSWRLRuleEngine(SWRLAPIFactory.java:39)
    at OWLAPITest.main(OWLAPITest.java:45)
Caused by: java.lang.NoSuchMethodError: org.semanticweb.owlapi.model.OWLOntologyManager.getIRIMappers()Lorg/semanticweb/owlapi/util/PriorityCollection;
    at org.swrlapi.factory.DefaultSWRLAPIOWLOntology.addSWRLAPIOntologies(DefaultSWRLAPIOWLOntology.java:1740)
    at org.swrlapi.factory.DefaultSWRLAPIOWLOntology.<init>(DefaultSWRLAPIOWLOntology.java:161)
    at org.swrlapi.factory.SWRLAPIInternalFactory.createSWRLAPIOntology(SWRLAPIInternalFactory.java:248)
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:55)
    ... 3 more

有解决办法吗? 感谢您 。

最佳答案

类路径上有两个 owlapi 版本,一个来自pellet,另一个在依赖项中显式显示。确保运行时只有一个版本。

关于ontology - 在java中添加SWRLAPI来操作swrl规则时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43850526/

相关文章:

java - 将字符串转换为复杂的 OWL 公理

import - 如何定义猫头鹰 :imports with OWL API v3?

java - Tomcat启动时实例化对象

rdf - OWL RDF/TTL 根据属性创建类的实例成员

apache - 无法在 Jena Fuseki docker 容器中创建或访问数据集

owl - 获取本体IRI

java - 使用 Reasoner 对象提取披萨本体中的直接父类(super class)