我面临的情况如下:
individuals: A, B
object properties: R, inverseOfR
axiom A-R-B or B-inverseOfR-A
我想要做的是删除A和B之间的关系,无论它是如何声明的。
我希望这会奏效:
reasoner.equivalentObjectProperties(inverseR)
.forEach(equivalent -> ontology.remove(factory.getOWLObjectPropertyAssertionAxiom(equivalent, b, a)));
但它似乎没有。
我可以明确地检查反向,但它似乎更像是一种解决方法,而不是一个正确的解决方案。
我正在使用owlapi-api 5.1.0和jfact 5.0.2。完整的测试代码:
import java.util.Optional;
import org.junit.Assert;
import org.junit.Test;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import uk.ac.manchester.cs.jfact.JFactFactory;
public class RemoveAxiomTest {
@Test
public void test() throws Exception {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.createOntology();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLClass elementClass = factory.getOWLClass("element");
OWLObjectProperty r = factory.getOWLObjectProperty("R");
OWLObjectProperty inverseR = factory.getOWLObjectProperty("inverseR");
manager.addAxiom(ontology, factory.getOWLInverseObjectPropertiesAxiom(r, inverseR));
OWLNamedIndividual a = factory.getOWLNamedIndividual("A");
OWLNamedIndividual b = factory.getOWLNamedIndividual("B");
manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(elementClass, a));
manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(elementClass, b));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(r, a, b));
OWLReasoner reasoner = new JFactFactory().createReasoner(ontology);
Assert.assertTrue(reasoner.getObjectPropertyValues(a, r).containsEntity(b));
Assert.assertTrue(reasoner.getObjectPropertyValues(b, inverseR).containsEntity(a));
ontology.remove(factory.getOWLObjectPropertyAssertionAxiom(inverseR, b, a));
Optional<OWLObjectPropertyExpression> optionalInverse = reasoner.inverseObjectProperties(inverseR).findAny();
if (optionalInverse.isPresent()) {
ontology.remove(factory.getOWLObjectPropertyAssertionAxiom(optionalInverse.get(), a, b));
}
reasoner.flush();
Assert.assertFalse(reasoner.getObjectPropertyValues(a, r).containsEntity(b));
Assert.assertFalse(reasoner.getObjectPropertyValues(b, inverseR).containsEntity(a));
}
}
答案 0 :(得分:0)
这可能是一个JFact错误。您可以尝试使用HermiT 1.3.8.500或Openllet吗?两者都与OWLAPI 5兼容。
答案 1 :(得分:0)
我在getSimplified上幸运了,碰巧解决了我的问题。这是我正在寻找的解决方案:
reasoner.equivalentObjectProperties(inverseR)
.map(equivalent -> factory.getOWLObjectPropertyAssertionAxiom(equivalent, b, a))
.map(axiom -> axiom.getSimplified())
.forEach(axiom -> ontology.remove(axiom));
我试图移除的公理:ObjectPropertyAssertion(ObjectInverseOf(<R>) <B> <A>)
不存在,getSimplified
将其转换为ObjectPropertyAssertion(<R> <A> <B>)