Get explanations with OWL API + Pellet

143 Views Asked by At

I am trying to get the explanations for inferences (like in Protégé) using OWL API and Pellet Reasoner. But I am stuck with the OWLAxiom. Maybe someone knows how to get the inferences.

enter image description here enter image description here

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;
import org.semanticweb.owlapi.model.*;
import com.clarkparsia.owlapi.explanation.PelletExplanation;
import com.clarkparsia.owlapi.explanation.io.manchester.ManchesterSyntaxExplanationRenderer;
import com.clarkparsia.owlapiv3.OWL;
import com.clarkparsia.pellet.owlapiv3.PelletReasoner;
import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;

public class Main {

    private static final String file = "file:/folder/ontology.owl";
    private static final String NS = "http://www.semanticweb.org/oliver/ontologies/ontology.owl#";

    public static void main(String[] args) throws OWLOntologyCreationException, OWLException, IOException {
        PelletExplanation.setup();

        ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer();
        PrintWriter out = new PrintWriter(System.out);
        renderer.startRendering(out);

        OWLOntologyManager manager = OWL.manager;
        OWLOntology ontology = manager.loadOntology(IRI.create(file));

        PelletReasoner reasoner = PelletReasonerFactory.getInstance().createReasoner(ontology);

        PelletExplanation expGen = new PelletExplanation(reasoner);

        OWLIndividual angle = OWL.Individual(NS + "angle_C");
        OWLDataProperty hasAngle = OWL.DataProperty(NS + "has_angle_of");

        OWLAxiom axiom; // I don't understand what should be here

        Set<Set<OWLAxiom>> explanations = expGen.getEntailmentExplanations(axiom); // is .getEntailmentExplanations the right method? 
        out.println("Why " + angle + " " + hasAngle + " - ");

        renderer.render(explanations);
        renderer.endRendering();
    }
}
0

There are 0 best solutions below