Search code examples
rdfowlowl-apipellet

Hermit Inference get all individuals of a class


I am using HermiT » 1.3.8.1 from Maven and OWL API 5.0.2 from maven too. I trying for almost 2 days to get inferences. I checked all examples nothings works for me. It is really frustating that there are so many version of reasoners and APIS. `

OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        File file = new File(PATH_MODEL_ALL_OWL);
        OWLOntology ontology = manager.loadOntologyFromOntologyDocument(file);

        OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
        OWLReasonerConfiguration config = new SimpleConfiguration();
        OWLReasoner reasoner = reasonerFactory.createReasoner(ontology, config);
        reasoner.precompute();
    private void printIndividualsByclass(OWLOntology ontology, OWLReasoner reasoner, String owlClass) {
    for (OWLClass c : ontology.getClassesInSignature()) {
        if (c.getIRI().getShortForm().equals(owlClass)) {
            NodeSet<OWLNamedIndividual> instances = reasoner.getInstances(c, false);
            System.out.println("Class : " + c.getIRI().getShortForm());
            for (OWLNamedIndividual i : instances.getFlattened()) {
                System.out.println(i.getIRI().getShortForm());
            }
        }
    }

I have 3 classes with equivalance reltations: A,B,C. A contains 4 individuals and C 2. If i ask this method to return me all instances of B it should return 6 instances due equivlance relation in any of these classes. I made an experiment and made C Subclass of B and A equivalent B. A got all instances of A and C with reasoner logic. But equivalance does not work with hermit somehow. Help is really appreciated!

edit: i saw i dont use the Hermit reasoner by not calling Reasoner reasoner = new Reasoner. I cant find one example that gives all individuals from one specific class, also inferencing(equivalentTo, Subclass). Please provide the owl api version you are using the version of hermit or any other reasoner. A pom file with depandancies would be really great too. Just one working example with a pom. Im getting really frustrated that none of the examples are working for me.

My pom file:

`<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/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>Exporter</groupId>
        <artifactId>Exporter</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <build>
            <sourceDirectory>src</sourceDirectory>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <dependencies>
            <dependency>
                <groupId>net.sourceforge.owlapi</groupId>
                <artifactId>owlapi-distribution</artifactId>
                <version>5.0.2</version>
            </dependency>
            <dependency>
        <groupId>net.sourceforge.owlapi</groupId>
        <artifactId>org.semanticweb.hermit</artifactId>
        <version>1.3.8.500</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.github.ansell.pellet/pellet-owlapiv3 -->

            <dependency>
                <groupId>net.sourceforge.owlapi</groupId>
                <artifactId>owlapi-apibinding</artifactId>
                <version>5.0.2</version>
            </dependency>
            <dependency>
                <groupId>net.sourceforge.owlapi</groupId>
                <artifactId>owlapi-api</artifactId>
                <version>5.0.2</version>
            </dependency>
        </dependencies>
    </project>`

Solution

  • HermiT 1.3.8.1 is not compatible with owlapi 5. There is a compatible version available on maven, version 1.3.8.500. It is a fork of the main HermiT code base, it updates 1.3.8.x to work with owlapi 5 (I'm maintaining both owlapi 5 and this fork).