I have created several ontologies and almost all of them can be reasoned using the following code (OWL api and Hermit) except the ontology attached here which is not very different from the other ones in size and structure.
package Reasoning.ReasonRDF;
import java.io.File;
import java.util.*;
import org.semanticweb.HermiT.Configuration;
import org.semanticweb.HermiT.Reasoner;
import org.semanticweb.HermiT.ReasonerFactory;
//import org.semanticweb.HermiT.Reasoner;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.RDFXMLOntologyFormat;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLIndividualAxiom;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.reasoner.*;
import org.semanticweb.owlapi.reasoner.ConsoleProgressMonitor;
import org.semanticweb.owlapi.reasoner.NodeSet;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.owlapi.reasoner.SimpleConfiguration;
import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory;
import org.semanticweb.owlapi.util.InferredAxiomGenerator;
import org.semanticweb.owlapi.util.InferredClassAssertionAxiomGenerator;
import org.semanticweb.owlapi.util.InferredClassAxiomGenerator;
import org.semanticweb.owlapi.util.InferredDataPropertyCharacteristicAxiomGenerator;
import org.semanticweb.owlapi.util.InferredEquivalentClassAxiomGenerator;
import org.semanticweb.owlapi.util.InferredIndividualAxiomGenerator;
import org.semanticweb.owlapi.util.InferredInverseObjectPropertiesAxiomGenerator;
import org.semanticweb.owlapi.util.InferredObjectPropertyCharacteristicAxiomGenerator;
import org.semanticweb.owlapi.util.InferredOntologyGenerator;
import org.semanticweb.owlapi.util.InferredPropertyAssertionGenerator;
import org.semanticweb.owlapi.util.InferredSubClassAxiomGenerator;
import org.semanticweb.owlapi.util.InferredSubDataPropertyAxiomGenerator;
import org.semanticweb.owlapi.util.InferredSubObjectPropertyAxiomGenerator;
public class ReasonRDF {
public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {
// TODO Auto-generated method stub
readRDF("directory/newNDVB4.owl");
}
public static void readRDF(String address) throws OWLOntologyCreationException, OWLOntologyStorageException{
OWLOntologyManager manager =OWLManager.createOWLOntologyManager();
File file = new File (address);
OWLOntology ont = manager.loadOntologyFromOntologyDocument(IRI.create(file));
System.out.println("Ontology Loaded...");
System.out.println("Logical IRI : " + ont.getOntologyID().getOntologyIRI().get());
System.out.println("Format : " + manager.getOntologyFormat(ont));
System.out.println("Runtime memory: " + Runtime.getRuntime().totalMemory());
OWLReasonerFactory reasonerFactory = new ReasonerFactory();
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
Configuration config = new Configuration();
config.ignoreUnsupportedDatatypes=true;
config.reasonerProgressMonitor= progressMonitor;
OWLReasoner reasoner = reasonerFactory.createReasoner(ont, config);
long t0 = System.nanoTime();
OWLDataFactory datafactory = manager.getOWLDataFactory();
List<InferredAxiomGenerator<? extends OWLAxiom>> inferredAxioms = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
inferredAxioms.add(new InferredSubClassAxiomGenerator());
inferredAxioms.add(new InferredClassAssertionAxiomGenerator());
inferredAxioms.add(new InferredEquivalentClassAxiomGenerator());
inferredAxioms.add(new InferredPropertyAssertionGenerator());
inferredAxioms.add(new InferredInverseObjectPropertiesAxiomGenerator());
inferredAxioms.add(new InferredSubDataPropertyAxiomGenerator());
inferredAxioms.add(new InferredSubObjectPropertyAxiomGenerator());
// for writing inferred axioms to the new ontology
OWLOntology infOnt = manager.createOntology(IRI.create(ont.getOntologyID().getOntologyIRI().get()+"_inferred"));
// use generator and reasoner to infer some axioms
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, inferredAxioms);
//InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner);
iog.fillOntology(datafactory,infOnt);
long elapsed_time = System.nanoTime()-t0;
System.out.println(elapsed_time);
// save the ontology
manager.saveOntology(infOnt, IRI.create("file:///C:/Users/Ehsan.abdolmajidi/ontologies/NVDB4_4.rdf"));
System.out.println(reasoner.isConsistent());
}
}
I have given 10GB of memory to JAVA and am not inferring the disjoint classes as I guess it is very time consuming.
Could someone please take a look at my code and see if I can improve the processing time? Or could someone take a look at my ontology and maybe reason it on his or her machine?
Thanks for you help and time in advance!
Regards,
Ehsan