Reputation: 115
I read a method of deleting classes from the examples of sourceforge.net even though it is very clear to delete all the individuals of an ontology. I have also seen methods of deleting one specific individuals but still I am unable to do the right thing. I want to delete individuals of a specific class. I have applied the code below but still I cannot see the changes in the protege. I think somehow they are overwriting in the protege but the previous ones are also visible. One more thing I have assigned many axioms to these individuals.
removerToDeleteAlreadyAssignedInds = new OWLEntityRemover(man, Collections.singleton(target_Ontology));
OWLClass classWithAlreadyAssignedInds = factory.getOWLClass(destinationclassname,pm_Target_Ontology);
for(OWLNamedIndividual indsToDelete : classWithAlreadyAssignedInds.getIndividualsInSignature())
{
indsToDelete.accept(removerToDeleteAlreadyAssignedInds);
}
man.applyChanges(removerToDeleteAlreadyAssignedInds.getChanges());
removerToDeleteAlreadyAssignedInds.reset();
man.saveOntology(target_Ontology);
Upvotes: 1
Views: 894
Reputation: 10659
You're using getIndividualsInSignature()
on an OWLClass object. There are no individuals in the signature of that object.
If you use
target_Ontology.getClassAssertionAxioms(classWithAlreadyAssignedInds)
for your loop you should be able to remove the individuals asserted to belong to that class. However some individuals might be inferred to belong to that class, in which case you'll have to find them manually, or use a reasoner on the ontology to get all the instances of the class:
OWLReasoner r...
r.getInstances(classWithAlreadyAssignedInds, false)
This will require you to use an actual reasoner; the usual list is HermiT, Pellet, FaCT++, JFact, but there are a few more.
Upvotes: 1