0

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. I'm using Eclipse with Maven project, dependencies written in the pom file are copied from the hermit examples, same is for OWLapi dependencies.

The error in the java console is:

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();
    }
DiegLuthor
  • 195
  • 1
  • 14
  • Hi, the configuration object passed as first parameter cannot be null. Easier to build the reasoner objects through the ReasonerFactory class. – Ignazio Dec 05 '18 at 07:29

1 Answers1

4

You have to use a ReasonerFactory, i.e. for HermiT you have to import the following:

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.

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

Your pom.xml needs to include:

<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>
Henriette Harmse
  • 4,167
  • 1
  • 13
  • 22
  • The lines you suggested didn't worked: OWLReasonerFactory reasonerFactory = new ReasonerFactory(); ask to create a ReasonerFactory class. If i change ReasonerFactory to OWLReasonerFactory it shows the error "cannot instantiate the class" – DiegLuthor Dec 03 '18 at 08:27
  • Please post the exact dependencies that you have added to your 'pom.xml' for HermiT and the OWL API. Thanks – Henriette Harmse Dec 03 '18 at 08:55
  • hermiT dependency: com.hermit-reasoner org.semanticweb.hermit 1.3.8.4 OWLApi dependency: net.sourceforge.owlapi owlapi-distribution 5.0.0 – DiegLuthor Dec 03 '18 at 09:02
  • Updated answer with required imports and correct pom.xml dependencies. – Henriette Harmse Dec 03 '18 at 15:41
  • 2
    I would recomend HermiT 1.4.3.517, since you're suggesting OWLAPI 5.1.8. It's the most recent release compatible with the most recent OWLAPI release. – Ignazio Dec 05 '18 at 07:27
  • @Ignazio I did not know! Thanks for pointing that out! I amended my answer to reflect this. – Henriette Harmse Dec 05 '18 at 09:50