2017-05-08 9 views
2

Drools API로 SWRLAPI 또는 SWRL을 추가하려고 할 때 문제가 있습니다. Maven에 DROols 및 OWLAPI 종속성이있는 SWRLAPI, SWRLAPI를 추가했습니다. SWRLAPIFactory.createSWRLRuleEngine (o)에 문제가있는 것 같습니다. 여기 내 주요 클래스SWRLAPI를 추가하여 Java에서 swrl 규칙을 조작 할 때 예외가 발생했습니다.

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 파일입니다 :

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 

해결책이 있습니까 :

<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> 

내가이 예외를 얻을? 감사합니다.

답변

0

클래스 경로에는 두 개의 owlapi 버전이 있습니다. 하나는 펠릿 계열이고 다른 하나는 종속성에 명시 적입니다. 런타임에 하나의 버전 만 있는지 확인하십시오.

1

그래서 문제가 모두를 위해, 여기에 수정 프로그램입니다 :

 <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의 API v4를 이용하여 펠렛의 포크있다 : https://github.com/ignazio1977/pellet은.

여기 OWLAPI 5를 사용하는 Pellet 포크가 있습니다. https://github.com/Galigator/openllet