Reputation: 1
My OWL API java program needs to change the value of a data property in my ontology (written in protege), so I am trying to remove the property already in the file and add a new axiom, but it only adds the new one, does not delete anything. What am I doing wrong?
OWLEntityRemover remover = new OWLEntityRemover(o);
OWLDataPropertyAssertionAxiom oldOpt1 = df.getOWLDataPropertyAssertionAxiom(property1, user, r.getDataPropertyValues(user, property1).toString());
OWLDataPropertyAssertionAxiom oldOpt2 = df.getOWLDataPropertyAssertionAxiom(property2, user, r.getDataPropertyValues(user, property2).toString());
ArrayList<RemoveAxiom> oldOptions = new ArrayList<RemoveAxiom>();
oldOptions.add(new RemoveAxiom(o,oldOpt1));
oldOptions.add(new RemoveAxiom(o,oldOpt2));
man.applyChanges(oldOptions);
// Add new preference
OWLDataPropertyAssertionAxiom newOpt1= df.getOWLDataPropertyAssertionAxiom(property1, user, opt1);
OWLDataPropertyAssertionAxiom newOpt2= df.getOWLDataPropertyAssertionAxiom(property2, user, opt2);
man.addAxiom(o, newOpt1);
man.addAxiom(o, newOpt2);
try {
man.saveOntology(o);
} catch (OWLOntologyStorageException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Upvotes: 0
Views: 227
Reputation: 10659
df.getOWLDataPropertyAssertionAxiom(shareLocation, user, ` r.getDataPropertyValues(user, shareLocation).toString());
This code's intent is to create an axiom that's equal to the axiom you wish to remove, but it is not using the original value of the data property you wish to remove, it is using the toString()
result of the returned value, which is not the same as the literal (or literals) that you wish to use. That's why the old axioms are not getting removed - you're trying to remove axioms that do not exist in the ontology.
Upvotes: 1