Java OWLApi:未能创建hermit Reasonier实例

Java OWLApi:未能创建hermit Reasonier实例,java,owl-api,hermit,Java,Owl Api,Hermit,早上好,我正在尝试编写一个可以管理本体的java类,特别是我想找到单个OWLClass的所有属性(名称、子类、超类、ecc…),但我没有设法实例化Hermit,我不明白为什么。 我将Eclipse与Maven项目一起使用,pom文件中编写的依赖项是从hermit示例中复制的,OWLapi依赖项也是如此 java控制台中的错误是: Exception in thread "main" java.lang.NullPointerException at org.semanticweb.Her

早上好,我正在尝试编写一个可以管理本体的java类,特别是我想找到单个OWLClass的所有属性(名称、子类、超类、ecc…),但我没有设法实例化Hermit,我不明白为什么。 我将Eclipse与Maven项目一起使用,pom文件中编写的依赖项是从hermit示例中复制的,OWLapi依赖项也是如此

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)
这是方法中不起作用的代码,我已经检查了hermit文档和各种示例,但没有帮助

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();
    }
公共void检索\u属性\u类(OWLOntology本体){
//根据svolgere Recepero informazioni提供的信息
推理机hermit=新推理机(空,本体论);
//财富是财富的一部分
弦类;
系统输出打印(“文件名称和文件格式:”);
classe=scannerNome.nextLine();
//按照韦迪酒店的等级进行检查
Set classi=ontology.getClassesInSignature();
对于(e类:classi){//scorro le classe OWL del set comparindone l'IRI con il nome della classe desiderata
如果(e.getIRI().getFragment().equals(classe)){//se una classe soddisfa l'uguaglianza ne vengono stampate le proprietá
System.out.println(“leinformazionidella classe sono lesegunti:”);
//诺姆船级社
System.out.println(“Nome类别:\n”
+“\t”+classe);
//显示超类
System.out.println(“超类:”);
for(节点超类:hermit.getSuperClasses(e)){
System.out.println(“\t”+超类.getRepresentativeElement().getIRI().getFragment());
}
//显示sottoclassi
System.out.println(“SottoClasssi:”);
for(节点SottoClass:hermit.getSubclass(e)){
System.out.println(“\t”+sottoclass.getRepresentativeElement().getIRI().getFragment());
}
//显示分类显示
System.out.println(“Classi disgiunte:”);
for(节点disgiunta:hermit.getDisjointClasses(e)){
System.out.println(“\t”+disgiunta.getRepresentativeElement().getIRI().getFragment());
}
//显示istanze della classe
System.out.println(“Istanze:”);
for(Node:hermit.getInstances(e)){
System.out.println(“\t”+individual);
}
}
}
隐士;
}

您必须使用
推理机工厂,即对于HermiT,您必须导入以下内容:

import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.HermiT.ReasonerFactory;
下面的代码将创建一个HermiT推理器

OWLReasonerFactory reasonerFactory = new ReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);
您的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>

net.sourceforge.owlapi
owlapi分布
5.1.8
net.sourceforge.owlapi
org.semanticweb.hermit
1.4.3.517

您必须使用
推理机工厂,即对于HermiT,您必须导入以下内容:

import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.HermiT.ReasonerFactory;
下面的代码将创建一个HermiT推理器

OWLReasonerFactory reasonerFactory = new ReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);
您的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>

net.sourceforge.owlapi
owlapi分布
5.1.8
net.sourceforge.owlapi
org.semanticweb.hermit
1.4.3.517

您建议的行不起作用:OWLReasonerFactory reasonerFactory=new reasonerFactory();要求创建一个ReasonerFactory类。如果我将ReasonerFactory更改为OWLReasonerFactory,则会显示错误“无法实例化类”,请发布您为HermiT和OWL API添加到“pom.xml”中的确切依赖项。ThankshermiT dependency:com.hermit-reasoner org.semanticweb.hermit 1.3.8.4 OWLApi dependency:net.sourceforge.OWLApi distribution 5.0.0使用所需的导入和正确的pom.xml依赖项更新了答案。我建议使用hermit 1.4.3.517,因为您建议使用OWLApi 5.1.8。这是与最新的OWLAPI版本兼容的最新版本。您建议的行不起作用:OWLReasonerFactory reasonerFactory=new reasonerFactory();要求创建一个ReasonerFactory类。如果我将ReasonerFactory更改为OWLReasonerFactory,则会显示错误“无法实例化类”,请发布您为HermiT和OWL API添加到“pom.xml”中的确切依赖项。ThankshermiT dependency:com.hermit-reasoner org.semanticweb.hermit 1.3.8.4 OWLApi dependency:net.sourceforge.OWLApi distribution 5.0.0使用所需的导入和正确的pom.xml依赖项更新了答案。我建议使用hermit 1.4.3.517,因为您建议使用OWLApi 5.1.8。这是与最新的OWLAPI版本兼容的最新版本。您好,作为第一个参数传递的配置对象不能为null。通过ReasonerFactory类更容易构建reasoner对象。您好,作为第一个参数传递的配置对象不能为null。通过ReasonerFactory类更容易构建reasoner对象。