0

I'm new in the semantic web field and I'm trying to compare more reasoners. This is my code:

OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
File file = new File(args[0]);
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(file);
Set<OWLClass> classes = ontology.getClassesInSignature();


String inferredFile = args[1];
//test for correctly uploading ontology
OWLDataFactory df = manager.getOWLDataFactory();     
Reasoner jfact = Reasoner.JFACT;
System.out.println(RunReasoner(jfact, df,ontology,manager,inferredFile));



}

//CREATE AN ENUM REASONER
public enum Reasoner{
    HERMIT, 
    PELLET, 
    KONCLUDE,
    JFACT,
    FACT,
    ELK

}   
public static String RunReasoner(Reasoner reasoner, OWLDataFactory df, OWLOntology ontology,                                                         OWLOntologyManager manager, String inferredFile) throws OWLOntologyCreationException, FileNotFoundException, IOException, OWLOntologyStorageException {
String esito = "";
OWLReasoner reasoner_object = null;
if(reasoner == Reasoner.HERMIT) {
    /****************HERMIT****************************************************************************************/

    OWLReasonerFactory rf = new ReasonerFactory();
    TimedConsoleProgressMonitor progressMonitor = new TimedConsoleProgressMonitor();
    Configuration configuration = new Configuration();
    configuration.reasonerProgressMonitor = progressMonitor;
    configuration.ignoreUnsupportedDatatypes = true;
    reasoner_object = rf.createReasoner(ontology, configuration);


}
else if(reasoner == Reasoner.KONCLUDE) {

    // configure the server end-point
    URL url = new URL("http://localhost:8080");
    OWLlinkHTTPXMLReasonerFactory factory = new OWLlinkHTTPXMLReasonerFactory();
    TimedConsoleProgressMonitor progressMonitor = new TimedConsoleProgressMonitor();
    //OWLlinkReasonerConfiguration conf = (OWLlinkReasonerConfiguration) new SimpleConfiguration(progressMonitor);
    reasoner_object = factory.createNonBufferingReasoner(ontology);

}
else if(reasoner == Reasoner.JFACT) {
    TimedConsoleProgressMonitor progressMonitor = new TimedConsoleProgressMonitor();
    OWLReasonerConfiguration conf = new SimpleConfiguration(progressMonitor);
    JFactFactory factory = new JFactFactory();          
    reasoner_object = factory.createNonBufferingReasoner(ontology,conf);
}
//      else if(reasoner == Reasoner.FACT) {
//          TimedConsoleProgressMonitor progressMonitor = new TimedConsoleProgressMonitor();
//          OWLReasonerConfiguration conf = new SimpleConfiguration(progressMonitor);
//          FaCTPlusPlusReasonerFactory factory = new FaCTPlusPlusReasonerFactory();
//          reasoner_object = factory.createNonBufferingReasoner(ontology,conf);
//      }
else if(reasoner == Reasoner.ELK) {
    TimedConsoleProgressMonitor progressMonitor = new TimedConsoleProgressMonitor();
    OWLReasonerConfiguration conf = new SimpleConfiguration(progressMonitor);
    ElkReasonerFactory factory = new ElkReasonerFactory();
    reasoner_object = factory.createNonBufferingReasoner(ontology,conf);
}
else if(reasoner == Reasoner.PELLET) {
    TimedConsoleProgressMonitor progressMonitor = new TimedConsoleProgressMonitor();
    OWLReasonerConfiguration conf = new SimpleConfiguration(progressMonitor);
    reasoner_object = OpenlletReasonerFactory.getInstance().createReasoner(ontology,conf);          
}
else{
    esito = "Reasoner non valido";
}
 boolean consistencyCheck = reasoner_object.isConsistent();
        if (consistencyCheck) {
            reasoner_object.precomputeInferences(InferenceType.CLASS_HIERARCHY,
                InferenceType.CLASS_ASSERTIONS, InferenceType.OBJECT_PROPERTY_HIERARCHY,
                InferenceType.DATA_PROPERTY_HIERARCHY, InferenceType.OBJECT_PROPERTY_ASSERTIONS);
            List<InferredAxiomGenerator<? extends OWLAxiom>> generators = new ArrayList<>();
            generators.add(new InferredSubClassAxiomGenerator());
            generators.add(new InferredClassAssertionAxiomGenerator());
            generators.add(new InferredDataPropertyCharacteristicAxiomGenerator());
            generators.add(new InferredEquivalentClassAxiomGenerator());
            generators.add(new InferredEquivalentDataPropertiesAxiomGenerator());
            generators.add(new InferredEquivalentObjectPropertyAxiomGenerator());
            generators.add(new InferredInverseObjectPropertiesAxiomGenerator());
            generators.add(new InferredObjectPropertyCharacteristicAxiomGenerator());

            // NOTE: InferredPropertyAssertionGenerator significantly slows down
            // inference computation
            generators.add(new org.semanticweb.owlapi.util.InferredPropertyAssertionGenerator());

            generators.add(new InferredSubClassAxiomGenerator());
            generators.add(new InferredSubDataPropertyAxiomGenerator());
            generators.add(new InferredSubObjectPropertyAxiomGenerator());
            List<InferredIndividualAxiomGenerator<? extends OWLIndividualAxiom>> individualAxioms =
                new ArrayList<>();
            generators.addAll(individualAxioms);

            generators.add(new InferredDisjointClassesAxiomGenerator());
            InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner_object, generators); //Generates an ontology based on inferred axioms which are essentially supplied by a reasoner

            OWLOntology inferredAxiomsOntology = manager.createOntology();
            iog.fillOntology(df, inferredAxiomsOntology);
            System.out.println(inferredAxiomsOntology.getAxiomCount());
//                  for(InferredAxiomGenerator<?> i : iog.getAxiomGenerators()) {
//                      System.out.println(i);}
            File inferredOntologyFile = new File(inferredFile);
            // Now we create a stream since the ontology manager can then write to that stream.
            try (OutputStream outputStream = new FileOutputStream(inferredOntologyFile)) {
                // We use the same format as for the input ontology.
                manager.saveOntology(inferredAxiomsOntology, outputStream);
            }
            esito = "done "+ reasoner.toString();
            reasoner_object.dispose();
        } // End if consistencyCheck
        else {
            esito = reasoner.toString() +" -- Inconsistent input Ontology, Please check the OWL File";
        }
return esito;
}     

When I try to run it on a little ontology (40 axioms), my code works perfectly. If instead, I try to run it on a slightly larger ontology (750 axioms), the code continues to go on for hours but never reaches the actual realization. In fact, the inferred axioms file remains empty. I think it’s due to memory overload or some hidden buffer. I hope you can help me solve this problem. Thanks, Rita

Ritulla
  • 33
  • 3
  • Can you share the 750 axiom ontology and create an issue on the jfact reasoner issue page? Jfact is not very scalable but it has worked well with much larger ontologies, so some progress should still be possible. – Ignazio May 05 '20 at 18:06
  • I used wine ontology. I actually have the same problem with all reasoners. That’s why I thought there is an issue in my code. – Ritulla May 06 '20 at 15:45
  • The wine ontology can be challenging but some results should come out. Your code is OK - try with fewer inference generators. Also add which reasoner versions you're using. – Ignazio May 06 '20 at 18:05
  • I find the slowdown in InferredOntologyGenerator.fillOntology(). Is there a way to speed it up? – Ritulla May 07 '20 at 08:40
  • fillOntology is a composite method that goes through all the generators, the complexity is in the generators. That's why I was suggesting to remove a few generators and try again - start with one and see if you get results, then increase from there. – Ignazio May 08 '20 at 19:18
  • I tried to replace fillOntology with this code: for (InferredAxiomGenerator inf : generators ) { System.out.println(inf); Set ax = inf.createAxioms(df, reasoner_object); inferredAxiomsOntology.addAxioms(ax); } But I had problems with Konclude and Elk: - ELK: Cannot check entailment: FunctionalDataProperty - Konclude: An error has occurred while processing 'Process-Knowledge-Base-Query Command', Do you have some suggestion to solve them? – Ritulla May 16 '20 at 17:14

0 Answers0