简体   繁体   English

OWLApi:无法创建隐士推理机实例

[英]OWLApi: Failed to create a hermit reasoner instance

Good morning, I'm trying to write a java class that could manage an ontology, in particular I want to find all the properties (name, subclasses, superclasses, ecc..) of a single OWLClass, but i don't manage to instance Hermit and I can't understand why. 早上好,我正在尝试编写一个可以管理本体的Java类,尤其是我想查找单个OWLClass的所有属性(名称,子类,超类等),但是我无法做到例隐士,我不明白为什么。 I'm using Eclipse with Maven project, dependencies written in the pom file are copied from the hermit examples, same is for OWLapi dependencies. 我在Maven项目中使用Eclipse,从pom文件中复制了pom文件中编写的依赖项,这与OWLapi依赖项相同。

The error in the java console is: Java控制台中的错误是:

Exception in thread "main" java.lang.NullPointerException
    at org.semanticweb.HermiT.Reasoner.<init>(Reasoner.java:210)
    at org.semanticweb.HermiT.Reasoner.<init>(Reasoner.java:187)
    at OntologyManager.retrieve_property_class(OntologyManager.java:105)

In particular, the line that fail to execute is: 特别是,执行失败的行是:

Reasoner hermit = new Reasoner(null, ontologia);

This is the code from the method that is not working, I already checked the hermit documentation and various example, but didn't help. 这是无法使用的方法中的代码,我已经检查了隐士文档和各种示例,但没有帮助。

public void retrieve_property_class(OWLOntology ontology) {
        //creo il reasoner per svolgere recupero informazioni
        Reasoner hermit = new Reasoner(null, ontologia);

        //richiesta del nome della classe di cui si vogliono le proprietà
        String classe;
        System.out.print("Inserire il nome della classe di cui si vogliono le proprietà: ");
        classe = scannerNome.nextLine();

        //check per vedere se la classe esiste
        Set<OWLClass> classi = ontology.getClassesInSignature();
        for (OWLClass e : classi) { //scorro le classe OWL del set comparandone l'IRI con il nome della classe desiderata
            if(e.getIRI().getFragment().equals(classe)) { //se una classe soddisfa l'uguaglianza ne vengono stampate le proprietà
                System.out.println("Le informazioni della classe sono le seguenti: ");
                //nome classe
                System.out.println("Nome classe: \n"
                        + "\t"+ classe);
                //display superclassi
                System.out.println("Superclassi:");
                for(Node<OWLClass> superclasse: hermit.getSuperClasses(e)) {
                    System.out.println("\t"+ superclasse.getRepresentativeElement().getIRI().getFragment());
                }
                //display sottoclassi
                System.out.println("Sottoclassi:");
                for(Node<OWLClass> sottoclasse : hermit.getSubClasses(e)) {
                    System.out.println("\t"+ sottoclasse.getRepresentativeElement().getIRI().getFragment());
                }
                //display classi disgiunte
                System.out.println("Classi disgiunte:");
                for(Node<OWLClass> disgiunta : hermit.getDisjointClasses(e)) {
                    System.out.println("\t"+ disgiunta.getRepresentativeElement().getIRI().getFragment());
                }
                //display istanze della classe
                System.out.println("Istanze:");
                for(Node<OWLNamedIndividual> individuo : hermit.getInstances(e)) {
                    System.out.println("\t"+ individuo);
                }
            }
        }
        hermit.dispose();
    }

You have to use a ReasonerFactory , ie for HermiT you have to import the following: 您必须使用ReasonerFactory ,即对于HermiT,您必须导入以下内容:

import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.HermiT.ReasonerFactory;

The the following code will create a HermiT reasoner. 以下代码将创建一个HermiT推理程序。

OWLReasonerFactory reasonerFactory = new ReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);

Your pom.xml needs to include: 您的pom.xml需要包括:

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

<dependency>
    <groupId>net.sourceforge.owlapi</groupId>
    <artifactId>org.semanticweb.hermit</artifactId>
    <version>1.4.3.517</version>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM