user1298416
user1298416

Reputation: 341

Deleting specific class and axioms in OWLAPI

I'm trying to delete a class and axioms for that class. I've tried different options, could not get them to work the way I want. Here is the code I have (it deletes nothing...):

if(clazz.toString().contains("2381")) {
        Stream<OWLClassAssertionAxiom> axiomstodelete = ontology.classAssertionAxioms(clazz);
        OWLEntityRemover remover = new OWLEntityRemover(Collections.singleton(ontology));
        axiomstodelete.forEach(i -> i.individualsInSignature().forEach(j -> j.accept(remover)));
        manager.applyChanges(remover.getChanges());
    }

Update: This code seems to work for a class and associated axioms removal:

OWLEntityRemover remover = new OWLEntityRemover(Collections.singleton(ontology));
currentClass.accept(remover);
manager.applyChanges(remover.getChanges());

Now, there is a condition, based on which I want to delete all subclasses (branches) of a particular class. The problem is I have to go from the bottom up, because I need to find the "lowest" class in the hierarchy for which the condition is true. I use this code:

currentClass = class_stack.pop();
removeClass(manager, clazz);
prevClass = class_stack.peek();
while(isBottom(reasoner, prevClass) && !class_stack.isEmpty() && !checkCondition(prevClass)) {
  currentClass = class_stack.pop();
  removeClass(manager, currentClass);
  prevClass = class_stack.peek();
}

It works for one leaf, but it does not for the parent of the leaf, because isBottom condition for the parent is not true, even after all its children are deleted. I have a workaround for now - after leaf is deleted, save the ontology, then reload again and delete next leaf etc. Would be nice to make it in one run.

For Ignazio - this is an example of a branch that shows why I'm checking for the bottom (C is for class with the true condition, L - for other classes). If I go up the left branch: L (bottom?->yes->delete) -> L(bottom?->yes->delete) -> L (bottom?->NO->leave for now). Then check the right branch: C (bottom?->yes && condition?->yes -> leave!)

    C
    |
    L
   / \
  L   L
 /     \
L       C

The result I need should be:

C
|
L
|
L
|
C

Upvotes: 0

Views: 617

Answers (1)

Ignazio
Ignazio

Reputation: 10659

You have already selected the axioms to remove. Skip the entity removed and use the remove method on the ontology.

Upvotes: 1

Related Questions