java - 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,
individualToReplaceValueOn,
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 中进行此类更改的唯一方法。公理是不可变的对象,因此除了重新创建公理并更改过程中需要修改的部分之外,没有其他方法可以修改公理。
推荐阅读
- jenkins - Jenkins JIRA 插件,成功构建多个服务后更新工单状态
- scala - Spark SQL 中没有 UDF 的“地图划分”
- android - 无论语言如何,如何将文本 XAlign 设置为左?
- html - li 项目不会按应有的方式显示
- kubernetes - GCP 副本数中的 Kubernetes GKE 不匹配
- mongodb - mongoose 和 mongo db 使用 updateMany 函数进行多次插入或更新
- vba - Userform1 中的复选框以显示是和否。VBA 代码
- django - 用 Django 数据库中的新表替换旧表?
- javascript - 如何使用 Drupal 在另一个页面中调用我的 CSS 或 JavaScript 文件并将它们包含在多个页面中
- java - 当我们尝试使用 BeanIO 读取多个输入格式时如何编写 mapping.xml 文件