NoSuchMethodError OWLDisjointClassesAxioms.getOperandAsList () - PullRequest
0 голосов
/ 06 июня 2018

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

Я хотел создать неудовлетворительный класс и отобразить его с помощью рассуждения 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$0(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$2.tryAdvance(Collections.java:4717)
    at java.util.Collections$2.forEachRemaining(Collections.java:4725)
    at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
    at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:270)
    at java.util.stream.ReferencePipeline$3$1.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$7$1.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>

Я настроил затмение для использования java-8-openjdk-amd64. Я новичок в OWLAPI и потоке Java 8.Может кто-нибудь объяснить, что вызывает эту проблему и как ее решить?

1 Ответ

0 голосов
/ 07 июня 2018

Попробуйте обновить 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 с помощью этого коммита .

...