首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在java中添加SWRLAPI以操作swrl规则时出现异常。

在java中添加SWRLAPI以操作swrl规则时出现异常。
EN

Stack Overflow用户
提问于 2017-05-08 14:40:53
回答 2查看 405关注 0票数 2

当我想用Drools添加SWRLAPI或SWRL时,我遇到了问题。我用Drools添加了SWRLAPI、SWRLAPI,用maven添加了OWLAPI依赖项。SWRLAPIFactory.createSWRLRuleEngine(O)似乎有问题,这是我的主要课程

代码语言:javascript
复制
    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:

代码语言:javascript
复制
<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>

我明白这一例外:

代码语言:javascript
复制
    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

有解决办法吗?谢谢你。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-05-09 05:32:50

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

票数 1
EN

Stack Overflow用户

发布于 2017-05-09 07:59:15

因此,对于所有有问题的人,以下是解决办法:

代码语言:javascript
复制
        <dependency>
        <groupId>com.github.ansell.pellet</groupId>
        <artifactId>pellet-owlapiv3</artifactId>
        <version>2.3.6-ansell</version>
        <exclusions>
            <exclusion>
                <groupId>com.github.ansell.owlapi</groupId>
                <artifactId>owlapi-api</artifactId>
            </exclusion>
            <exclusion>
                    <groupId>com.github.ansell.owlapi</groupId> 
                    <artifactId>owlapi-impl</artifactId>
            </exclusion>
            <exclusion>
                    <groupId>com.github.ansell.owlapi</groupId>
                    <artifactId>owlapi-parsers</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

或者这里有一个使用OWL v4的小球叉:https://github.com/ignazio1977/pellet

这里有一个使用OWLAPI 5的小球叉:https://github.com/Galigator/openllet

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43850526

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档