NoSuchMethodError OWLDisjointClassesAxioms.getOperandAsList ()

NoSuchMethodError OWLDisjointClassesAxioms.getOperandAsList ()

NoSuchMethodError : org.semanticweb.owlapi.model.OWLDisjointClassesAxiom.getOperandsAsList()

我想创建一个无法满足的 class 并使用 HermiT 推理器列出它。我浏览了一些示例代码并设法编写了一个。

源代码:

package owlapi.tutorial;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import org.semanticweb.HermiT.ReasonerFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.formats.OWLXMLDocumentFormat;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;

public class OWLAPIUnsatisfiableAssignment {

    public static void main(String[] args) {

        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        IRI ontIri = IRI.create("http://owl.api.tutorial");
        File fileOut = new File("src/main/resources/curriculum.owl");

        try {
            OWLOntology ont = manager.createOntology(ontIri);
            OWLDataFactory df = ont.getOWLOntologyManager().getOWLDataFactory();

            OWLClass student = df.getOWLClass(ontIri+"#Student");
            OWLClass teacher = df.getOWLClass(ontIri+"#Teacher");
            OWLClass demonst = df.getOWLClass(ontIri+"#Demonstrator");

            /*
            Set<OWLClass> disjoint = new HashSet<OWLClass>();
            disjoint.add(student);
            disjoint.add(teacher);
            */

            OWLDisjointClassesAxiom disAx1 = df.getOWLDisjointClassesAxiom(student, teacher);
            ont.add(disAx1);
            OWLSubClassOfAxiom subAx1 = df.getOWLSubClassOfAxiom(demonst, df.getOWLObjectIntersectionOf(student, teacher));
            ont.add(subAx1);

            OWLReasonerFactory rf = new ReasonerFactory();
            OWLReasoner r = rf.createReasoner(ont);

            //Checking consistency of ontology
            if(r.isConsistent()) {
                System.out.println("The ontology is consistent");
            }
            else {
                System.out.println("The ontology is inconsistent.Check the unsatisfiable classes below.");
            }

            r.getUnsatisfiableClasses().forEach(System.out::println);
            manager.saveOntology(ont, new OWLXMLDocumentFormat(), new FileOutputStream(fileOut));   
        }
        catch(OWLOntologyStorageException e) {
            e.printStackTrace();
        }
        catch (OWLOntologyCreationException e) {
            e.printStackTrace();
        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}

控制台输出:

Exception in thread "main" java.lang.NoSuchMethodError: org.semanticweb.owlapi.model.OWLDisjointClassesAxiom.getOperandsAsList()Ljava/util/List;
    at org.semanticweb.HermiT.structural.OWLNormalization$AxiomVisitor.visit(OWLNormalization.java:444)
    at org.semanticweb.owlapi.model.OWLDisjointClassesAxiom.accept(OWLDisjointClassesAxiom.java:53)
    at org.semanticweb.HermiT.structural.OWLNormalization.lambda$processAxioms[=12=](OWLNormalization.java:165)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
    at java.util.Collections.tryAdvance(Collections.java:4717)
    at java.util.Collections.forEachRemaining(Collections.java:4725)
    at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
    at java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:270)
    at java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:193)
    at java.util.Iterator.forEachRemaining(Iterator.java:116)
    at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
    at java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:270)
    at java.util.Iterator.forEachRemaining(Iterator.java:116)
    at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
    at org.semanticweb.HermiT.structural.OWLNormalization.processAxioms(OWLNormalization.java:165)
    at org.semanticweb.HermiT.structural.OWLNormalization.processOntology(OWLNormalization.java:158)
    at org.semanticweb.HermiT.structural.OWLClausification.preprocessAndClausify(OWLClausification.java:81)
    at org.semanticweb.HermiT.Reasoner.loadOntology(Reasoner.java:212)
    at org.semanticweb.HermiT.Reasoner.<init>(Reasoner.java:203)
    at org.semanticweb.HermiT.Reasoner.<init>(Reasoner.java:177)
    at org.semanticweb.HermiT.ReasonerFactory.createHermiTOWLReasoner(ReasonerFactory.java:51)
    at org.semanticweb.HermiT.ReasonerFactory.createReasoner(ReasonerFactory.java:19)
    at org.semanticweb.HermiT.ReasonerFactory.createReasoner(ReasonerFactory.java:15)
    at owlapi.tutorial.X.main(X.java:50)

当我试图查看文件的行号时,发现源附件中缺少一些文件,例如:

java.util.stream.ForEachOps
java.util.stream.AbstractPipeLine

POM 文件:

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>owlapi.tutorial</groupId>
  <artifactId>msc</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>msc</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>net.sourceforge.owlapi</groupId>
      <artifactId>owlapi-distribution</artifactId>
      <version>5.1.0</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-nop</artifactId>
      <version>1.7.10</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>net.sourceforge.owlapi</groupId>
      <artifactId>org.semanticweb.hermit</artifactId>
      <version>1.4.1.513</version>
    </dependency>
  </dependencies>
</project>

我将 eclipse 配置为使用 java-8-openjdk-amd64.I 是 OWLAPI 和 Java 8 流的新手。任何人都可以解释导致此问题的原因以及如何解决它吗?

尝试将 owlapi-distribution 升级到 5.1.3 或更高版本,如下所示:

<dependency>
  <groupId>net.sourceforge.owlapi</groupId>
  <artifactId>owlapi-distribution</artifactId>
  <version>5.1.3</version>
</dependency>

getOperandsAsList() 自 5.1.3 起由 this commit 引入。