如何解决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 中进行此类更改的唯一方法。公理是不可变的对象,因此除了重新创建公理并更改过程中需要修改的部分外,没有其他方法可以修改公理。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。