owlcs / owlapi

OWL API main repository
822 stars 315 forks source link

Using multiple inference types #1030

Closed MajlindaLlugiqi closed 2 years ago

MajlindaLlugiqi commented 2 years ago

I am trying to save an inferred ontology with:

    OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
    OWLReasoner reasoner = reasonerFactory.createReasoner(localUni);
    reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
    List<InferredAxiomGenerator<? extends OWLAxiom>> gens = Collections.singletonList(
            new InferredSubClassAxiomGenerator());
    OWLOntology infOnt = manager.createOntology();
    InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
    OWLDataFactory f = OWLManager.getOWLDataFactory();
    iog.fillOntology(manager.getOWLDataFactory(), infOnt);

//     Save the inferred ontology.
    manager.saveOntology(infOnt, new FunctionalSyntaxDocumentFormat(), IRI.create((new File("lib/kidney_ontology-inferred-ELK.owl").toURI())));

Is there a way I can use multiple inference types, because when I do this the inferred ontology has less axioms than the original ontology?

ignazio1977 commented 2 years ago

You can use multiple inference generators by adding them to the gens list (in the snippet above, the code uses just one generator).

However, the number of generated axioms being less than the number of axioms in the original ontology is not really an important metric - the proportion might vary a lot depending on the ontology and the axiom types it contains, e.g., an ontology with few logical axioms and many annotation axioms might always have few inferences, compared to the total number of axioms in input.

That said, the code above cannot remove axioms from the ontology, so you should never get fewer axioms out than there were in - do you have an example ontology where that happens?