0

I have two questions:

  1. What is the reasoner of OWL API? Is it Hermit? So when I have:
OWLReasonerFactory reasoner_factory = new ReasonerFactory();
OWLReasoner reasoner = reasoner_factory.createReasoner(ontology);

Which reasoner is called?

  1. When I perform materialization I also get for any individuals a, b appearing the the ABox the assertion: owl:topObjectProperty(a,b), which is true, but also redundant, and explodes the size of the KB.

So how can I prevent this from happening?

The method I used is as follows:

public static Ontology materialization(Ontology ontology, File inferredOntologyFile) throws OWLOntologyStorageException, IOException, OWLOntologyCreationException {
           Configuration config=new Configuration();
           OntologyManager manager=  OntManagers.createManager(); 
           Ontology inf_ontology = manager.loadOntologyFromOntologyDocument(inferredOntologyFile);
            OutputStream outputStream=new FileOutputStream(inferredOntologyFile);
   
           OWLDataFactory data_factory = ontology.getOWLOntologyManager().getOWLDataFactory();

            OWLReasonerFactory reasoner_factory = new ReasonerFactory();
            OWLReasoner reasoner = reasoner_factory.createReasoner(ontology);
        
            if (reasoner.isConsistent() == false) {
                System.out.println("INCONSISTENT ONTOLOGY!");
            }

            InferredOntologyGenerator inference = new  InferredOntologyGenerator(reasoner);
            
            inference.fillOntology(data_factory, ontology);

            manager.saveOntology(ontology, new NTriplesDocumentFormat(), outputStream);

            return ontology;
            
    }

owlapi-distribution version: 5.1.14 Hermit version: 1.3.8.510

Also a very simple test ontology after materialization is here: https://drive.google.com/file/d/1EKm8uD1zuMfIjstCAZMperZFFv4-kCtD/view?usp=sharing

or you can see it below:

<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Ontology> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#r> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> <http://www.w3.org/2002/07/owl#topObjectProperty> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#r> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#A> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#A> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#B> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#B> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
<http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ReflexiveProperty> .
<http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#SymmetricProperty> .
<http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.w3.org/2002/07/owl#inverseOf> <http://www.w3.org/2002/07/owl#topObjectProperty> .
<http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#q> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> <http://www.w3.org/2002/07/owl#topObjectProperty> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#q> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .
Eleni T
  • 3
  • 3
  • OWL API does not include a reasoner. In the ode example above, ReasonerFactory is a class in a reasoner compatibile with OWL API. HermiT is one such reasoner and has a class named like that, but we'd need the import statements to be sure. – Ignazio Jul 28 '23 at 06:40
  • thank you @Ignazio, I have imported the following: import org.semanticweb.owlapi.reasoner.InferenceDepth; import org.semanticweb.owlapi.reasoner.InferenceType; import org.semanticweb.owlapi.reasoner.OWLReasoner; import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; import org.semanticweb.HermiT.Configuration; import org.semanticweb.HermiT.Reasoner; – Eleni T Jul 28 '23 at 10:57
  • 1
    That confirms you are using HermiT. Please add the following to the question so it's possible to give it an answer: full class you're using, OWL API version and HermiT version. If you can share the ontology you're using, that would also help. If not, please provide an ontology that replicates the problem (i.e., an ontology with two individuals that shows the extra triples being generated.) – Ignazio Jul 28 '23 at 11:08
  • Thank you @Ignazio, I edited the question. – Eleni T Jul 28 '23 at 14:48
  • Hi @Ignazio is there some obvious mistake that I miss? Many thanks. – Eleni T Jul 31 '23 at 12:04
  • Nothing obvious, I need to run your code to figure it out. – Ignazio Jul 31 '23 at 14:54

1 Answers1

1

Two items: I recommend updating the versions you're using because they are old, and it seems there is an issue in your input ontology.

Suggested version updates: use OWLAPI 5.1.20 and HermiT 1.4.5.519 (they don't directly affect this issue but they're more recent versions than the ones you're using.

Example Maven config:

<dependencies>
    <dependency>
        <groupId>net.sourceforge.owlapi</groupId>
        <artifactId>owlapi-distribution</artifactId>
        <version>5.1.20</version>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.owlapi</groupId>
        <artifactId>org.semanticweb.hermit</artifactId>
        <version>1.4.5.519</version>
        <exclusions>
            <exclusion>
                <groupId>net.sourceforge.owlapi</groupId>
                <artifactId>owlapi-distribution</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

Regarding your input ontology, if I feed it as is in the code you show (after amending to remove ONTAPI references, which are not relevant to the problem and in which I'm not an expert), I have the following code replicating the problem:

package teststack;

import java.io.*;

import org.semanticweb.HermiT.ReasonerFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.formats.NTriplesDocumentFormat;
import org.semanticweb.owlapi.io.StringDocumentSource;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.*;
import org.semanticweb.owlapi.util.*;

public class Check {
    static OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    static OWLDataFactory data_factory = manager.getOWLDataFactory();

    public static void main(String[] args)
            throws OWLOntologyCreationException, OWLOntologyStorageException, IOException {
        String notWorking="<urn:test:onto> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Ontology> .\n"
                + "<urn:test:onto#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .\n"
                + "<urn:test:onto#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n"
                + "<urn:test:onto#r> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> <http://www.w3.org/2002/07/owl#topObjectProperty> .\n"
                + "<urn:test:onto#r> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .\n"
                + "<urn:test:onto#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .\n"
                + "<urn:test:onto#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n"
                + "<urn:test:onto#A> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .\n"
                + "<urn:test:onto#A> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .\n"
                + "<urn:test:onto#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .\n"
                + "<urn:test:onto#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n"
                + "<urn:test:onto#B> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .\n"
                + "<urn:test:onto#B> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .\n"
                + "<urn:test:onto#q> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> <http://www.w3.org/2002/07/owl#topObjectProperty> .\n"
                + "<urn:test:onto#q> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .\n";
        OWLOntology o = manager.loadOntologyFromOntologyDocument(new StringDocumentSource(
                notWorking,
                IRI.create("urn:test:onto"), new NTriplesDocumentFormat(), null));
        materialization(o, new File("result.txt"));
    }

    public static OWLOntology materialization(OWLOntology ontology, File inferredOntologyFile)
            throws OWLOntologyStorageException, IOException, OWLOntologyCreationException {
        OutputStream outputStream = new FileOutputStream(inferredOntologyFile);

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

        if (reasoner.isConsistent() == false) {
            System.out.println("INCONSISTENT ONTOLOGY!");
        }

        InferredOntologyGenerator inference = new InferredOntologyGenerator(reasoner);

        inference.fillOntology(data_factory, ontology);

        manager.saveOntology(ontology, new NTriplesDocumentFormat(), outputStream);

        return ontology;

    }
}

Note: I've removed all axioms relating individuals with topObjectProperty from this ontology. These axioms are replicated by the code.

However, removing the type assertions that state the properties are subproperties of topObjectProperties, the problem goes away. As the declarations are redundant, it looks like them being in the ontology tricks the reasoner into generating those axioms. Such unnecessary declarations should be ignored, so this might be a bug. However, workaround for you is to filter out any declaration axioms where the type is topObjectProperty from your input file.

<urn:test:onto> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Ontology> .
<urn:test:onto#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<urn:test:onto#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<urn:test:onto#r> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .
<urn:test:onto#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<urn:test:onto#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<urn:test:onto#A> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .
<urn:test:onto#A> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
<urn:test:onto#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<urn:test:onto#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<urn:test:onto#B> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .
<urn:test:onto#B> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
<urn:test:onto#q> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .
Ignazio
  • 10,504
  • 1
  • 14
  • 25