java - OWLApi : Failed to create a hermit reasoner instance

标签 java owl-api hermit

早上好,我正在尝试编写一个可以管理本体的java类,特别是我想找到单个OWLClass的所有属性(名称,子类,父类(super class),ecc..),但我不'无法以隐士为例,我不明白为什么。 我正在将 Eclipse 与 Maven 项目一起使用,pom 文件中编写的依赖项是从隐士示例中复制的,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)

特别是,执行失败的行是:

Reasoner hermit = new Reasoner(null, ontologia);

这是来自不起作用的方法的代码,我已经检查了隐士文档和各种示例,但没有帮助。

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();
    }

最佳答案

您必须使用 ReasonerFactory,即对于 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>

关于java - OWLApi : Failed to create a hermit reasoner instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53582644/

相关文章:

jena - Hermit Reasoner - SPARQL 查询

ontology - HermiT 似乎没有显示推断的 DataProperties ?

java - 在Java中通过数据报发送桌面流

java - System.out 未刷新

java - 简单的命令行Java编译

java - 用隐士推理机进行 owlex 解释

semantic-web - Stardog和Protege推理结果不同

java - 如何比较字符串?

java - 猫头鹰 API : Good substitution for isSubclassOf method

java - 如果推理器一致且发生更改,则 OWL API 保存本体