Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check stackoverflow issue #17

Open
ignazio1977 opened this issue Jun 28, 2017 · 1 comment
Open

check stackoverflow issue #17

ignazio1977 opened this issue Jun 28, 2017 · 1 comment

Comments

@ignazio1977
Copy link
Contributor

https://stackoverflow.com/questions/44788355/remove-object-property-axiom-using-a-reasoner/

@ignazio1977
Copy link
Contributor Author

remove object property axiom using a reasoner

The situation I'm facing is the following:

individuals: A, B
object properties: R, inverseOfR
axiom A-R-B or B-inverseOfR-A
What I want to do is remove the relation between A and B regardless of how it's declared.

I was hoping that this would work:

reasoner.equivalentObjectProperties(inverseR)
        .forEach(equivalent -> ontology.remove(factory.getOWLObjectPropertyAssertionAxiom(equivalent, b, a)));

But it doesn't seem to.

I can check explicitly for an inverse instead but it seems more like a workaround than a proper solution.

I'm using owlapi-api 5.1.0 and jfact 5.0.2. The complete test code:

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));
}
}

Nina

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant