alex
alex

Reputation: 7895

OWL replace object and data property value

I've written this code to replace object property value:

 public void changeObjectPropertyValue(String ind, String propertyFragment, String newValueFragment) {

        OWLNamedIndividual individualToReplaceValueOn = factory.getOWLNamedIndividual(prefix + ind);
        OWLNamedIndividual newValueInd = factory.getOWLNamedIndividual(prefix + newValueFragment);
        OWLObjectProperty theObjectProperty = factory.getOWLObjectProperty(prefix + propertyFragment);
        OWLIndividual theOldValue = EntitySearcher.getObjectPropertyValues(individualToReplaceValueOn, theObjectProperty, ont).findFirst().get();

        OWLAxiom oldAxiom = factory.getOWLObjectPropertyAssertionAxiom(
                theObjectProperty,
                individualToReplaceValueOn,
                theOldValue);

        OWLAxiom newAxiom = factory.getOWLObjectPropertyAssertionAxiom(
                theObjectProperty,
                individualToReplaceValueOn,
                newValueInd);

        List<OWLOntologyChange> changes = new Vector<OWLOntologyChange>();

        changes.add(new RemoveAxiom(ont, oldAxiom));
        changes.add(new AddAxiom(ont, newAxiom));
        manager.applyChanges(changes);
    }

I want to know if this is a correct way to replace value and if there is a method in OWLAPI library to do this?

Upvotes: 0

Views: 151

Answers (1)

Ignazio
Ignazio

Reputation: 10659

This is correct - and the only way to do this sort of changes in OWL API. Axioms are immutable objects, so there is no other way to modify an axiom than recreating it and changing the parts that need modifying in the process.

Upvotes: 1

Related Questions