0

I am working on this project which requires to perform ontology reasoning in code, so far I have written this rule. I am implementing this in java with the help of owlapi, and clarkparsia.pellet.owlapiv3.PelletReasoner.

//dexpi:Pump(?pump) ^ swrlb:greaterThan(?value, "10.0"^^xsd:double) ^ rdl:datumValue(?pump, ?value) -> dexpi:EjectorPump(?pump)
// Rule created using SWRLClassAtoms and DataPropertyAtoms
ontologyManager.applyChange(new AddAxiom(ontology, rule1));

So this section of code adds the rule to the ontology. I know the rules are defined correctly, since I can see this rule in protege, but How do I update the ontology according to the rule, i.e. change class type of all Pump instances whose datumValue is greaterThan 10 to EjectorPump.

I have tried these approaches so far.

Approach-1

// These lines uses pellet reasoner to perform reasoning
PelletReasoner reasoner = PelletReasonerFactory.getInstance().createReasoner(ontology);     
InferredOntologyGenerator iog = new  InferredOntologyGenerator(reasoner);
iog.fillOntology(factory, ontology);        

Approach-2

List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<>();
gens.add(new InferredClassAssertionAxiomGenerator());
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
iog.fillOntology(factory, ontology);

Both of the approaches works perfectly fine but the problem is when they generate inference there is too much information I just want reclassification to be done like this if possible (This one is generated by protege. desired inference (generated by protege)

but instead, these codes reclassify like this code generated inference

Additionally, if you can direct me on how I can generate and show an explanation of reasoning, it will be a huge help. Thank you.

10
  • The axiom generator is computing all (named) classes an instance belongs to by means of inference. Adding a rule will never remove any asserted nor inferred data of the previous ontology - so I'm a bit confused what exactly you're asking for. As far as I can see, you have an SWRL rule which you add to an existing ontology, right? and this leads to another inferred class for the individual in your screenshot, right? Commented Jul 31, 2023 at 14:12
  • explanations can be computed via this API: github.com/ignazio1977/owlexplanation/tree/version5 Commented Jul 31, 2023 at 14:13
  • Protege inferences like that are not determined with an axiom generator and a reasoner but computed by hand (historical reasons: the desired display could not be built with standard inferences at acceptable speeds) Commented Jul 31, 2023 at 14:53
  • This question was asked recently and it covers a very similar topic: how to get certain inferences included in an ontology via axiom generators, and the response I've posted there might help. stackoverflow.com/questions/76779956/… There's an example of code to create certain axioms provided by the OP and my recommendations on amendments to the input and OWLAPI versions to use. Note: Protege uses OWLAPI 4, that question uses OWLAPI 5, but these are broadly similar functionally. OWLAPI 3 is ancient, and I'm not aware of a newer Pellet. Commented Jul 31, 2023 at 19:47
  • re Pellet, there's an OWLAPI 5 compatible fork named Openllet, which you could use if you want to stick to that reasoner. Commented Jul 31, 2023 at 19:48

1 Answer 1

0

Extending the discussion from the comments above:

Openllet and OWLAPI versions: 2.6.5 of Openllet was released three years back, I have just tried it with OWLAPI 5.1.20 (released a year and a half ago) and got no errors. However, I do not have your ontology, so this might not be a sufficient test.

With either setup, you can be more selective about which axioms to generate by writing your own generator. This example introduces a generator that creates assertion axioms for only one class, i.e., it will not add any other type to individuals:

    List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<>();
    gens.add(new InferredEntityAxiomGenerator<OWLClass, OWLClassAssertionAxiom>() {
        @Override
        protected Stream<OWLClass> getEntities(OWLOntology ont) {
            return Stream.of(factory.getOWLClass(IRI.create("urn:test:onto#A")));
        }

        @Override
        protected void addAxioms(OWLClass entity, OWLReasoner reasoner, OWLDataFactory dataFactory,
                Set<OWLClassAssertionAxiom> result) {
            reasoner.getInstances(entity).entities().map(x -> factory.getOWLClassAssertionAxiom(entity, x))
                    .forEach(result::add);
        }

        @Override
        public String getLabel() {
            // TODO Auto-generated method stub
            return "Instances of A";
        }

    });
    InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
    iog.fillOntology(factory, ontology);

The approach can be followed for older OWLAPI versions, but you will have to adjust it to compile correctly with whichever version you're using.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the solution sir, as my understanding goes, this solution is for, if we want to generate inferences for only urn:test:onto#A. But the solution doesn't seem to work in my case. For reference, I have shared the link to the code along with a sample rdf here code+sample-rdf. I am using openllet v2.6.5 and owlapi v5.1.20. Thank you.
@SatyamG in your example code you're using IRI.create("dexpi:EjectorPump")). That will not work (IRI.create expects a full IRI not a shortened one). Replacing that line with return Stream.of(clsRotaryPump); works. The problem was the class being used didn't match the class in your ontology.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.