OWL 替换对象和数据属性值

问题描述

我编写了这段代码来替换对象属性值:

 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,newValueInd);

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

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

我想知道这是否是替换值的正确方法,以及 OWLAPI 库中是否有方法可以执行此操作?

解决方法

这是正确的 - 也是在 OWL API 中进行此类更改的唯一方法。公理是不可变的对象,因此除了重新创建公理并更改过程中需要修改的部分外,没有其他方法可以修改公理。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...