Search in sources :

Example 1 with OntProperty

use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.

the class PropertyInstanceDaoJena method deleteObjectPropertyStatement.

public void deleteObjectPropertyStatement(String subjectURI, String propertyURI, String objectURI, OntModelSelector ontModelSelector) {
    OntModel ontModel = ontModelSelector.getABoxModel();
    OntModel tboxModel = ontModelSelector.getTBoxModel();
    ontModel.enterCriticalSection(Lock.WRITE);
    try {
        Resource subjRes = ontModel.getResource(subjectURI);
        Property pred = tboxModel.getProperty(propertyURI);
        OntProperty invPred = null;
        if (pred.canAs(OntProperty.class)) {
            invPred = pred.as(OntProperty.class).getInverse();
        }
        Resource objRes = ontModel.getResource(objectURI);
        Model baseModel = getOntModel().getBaseModel();
        String userUri = getWebappDaoFactory().getUserURI();
        if ((subjRes != null) && (pred != null) && (objRes != null)) {
            baseModel.notifyEvent(new IndividualUpdateEvent(userUri, true, subjectURI));
            try {
                ontModel.remove(subjRes, pred, objRes);
            } finally {
                baseModel.notifyEvent(new IndividualUpdateEvent(userUri, false, subjectURI));
            }
            try {
                baseModel.notifyEvent(new IndividualDeletionEvent(userUri, true, objectURI));
                List<Statement> depResStmts = DependentResourceDeleteJena.getDependentResourceDeleteList(ResourceFactory.createStatement(subjRes, pred, objRes), ontModel);
                ontModel.remove(depResStmts);
            } finally {
                baseModel.notifyEvent(new IndividualDeletionEvent(userUri, false, objectURI));
            }
            if (invPred != null) {
                baseModel.notifyEvent(new IndividualUpdateEvent(userUri, true, objectURI));
                try {
                    ontModel.remove(objRes, invPred, subjRes);
                } finally {
                    baseModel.notifyEvent(new IndividualUpdateEvent(userUri, false, subjectURI));
                }
            }
        }
    } finally {
        ontModel.leaveCriticalSection();
    }
}
Also used : IndividualDeletionEvent(edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualDeletionEvent) OntProperty(org.apache.jena.ontology.OntProperty) Statement(org.apache.jena.rdf.model.Statement) ObjectPropertyStatement(edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement) Resource(org.apache.jena.rdf.model.Resource) OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) OntModel(org.apache.jena.ontology.OntModel) IndividualUpdateEvent(edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualUpdateEvent) OntProperty(org.apache.jena.ontology.OntProperty) Property(org.apache.jena.rdf.model.Property)

Example 2 with OntProperty

use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.

the class SimpleReasonerSameAsTest method addABoxAssertion2.

/*
	* sameAs with datatype properties
	*/
@Test
public void addABoxAssertion2() {
    OntModel tBox = createTBoxModel();
    OntProperty desc = tBox.createDatatypeProperty("http://test.vivo/desc");
    desc.setLabel("property desc", "en-US");
    Literal desc1 = tBox.createLiteral("individual 1");
    Literal desc2 = tBox.createLiteral("individual 2");
    // this is the model to receive inferences
    Model inf = ModelFactory.createDefaultModel();
    // create an ABox and register the SimpleReasoner listener with it
    OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
    aBox.register(new SimpleReasoner(tBox, aBox, inf));
    // Individuals a and b
    Resource a = aBox.createResource("http://test.vivo/a");
    Resource b = aBox.createResource("http://test.vivo/b");
    aBox.add(a, desc, desc1);
    aBox.add(b, desc, desc2);
    aBox.add(a, OWL.sameAs, b);
    Assert.assertTrue(inf.contains(a, desc, desc2));
    Assert.assertTrue(inf.contains(b, desc, desc1));
    Assert.assertTrue(inf.contains(b, OWL.sameAs, a));
}
Also used : OntProperty(org.apache.jena.ontology.OntProperty) Literal(org.apache.jena.rdf.model.Literal) OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) OntModel(org.apache.jena.ontology.OntModel) Test(org.junit.Test)

Example 3 with OntProperty

use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.

the class SimpleReasonerSameAsTest method removeSameAsABoxAssertion1.

/*
	* basic scenario of removing an abox sameAs assertion
	*/
@Test
public void removeSameAsABoxAssertion1() {
    OntModel tBox = createTBoxModel();
    OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
    OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
    OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S");
    OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T");
    Literal literal1 = tBox.createLiteral("Literal value 1");
    Literal literal2 = tBox.createLiteral("Literal value 2");
    // this is the model to receive inferences
    Model inf = ModelFactory.createDefaultModel();
    // create an ABox and register the SimpleReasoner listener with it
    OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
    aBox.register(new SimpleReasoner(tBox, aBox, inf));
    // Individuals a, b, c and d
    Resource a = aBox.createResource("http://test.vivo/a");
    Resource b = aBox.createResource("http://test.vivo/b");
    Resource c = aBox.createResource("http://test.vivo/c");
    Resource d = aBox.createResource("http://test.vivo/d");
    aBox.add(a, P, c);
    aBox.add(a, S, literal1);
    aBox.add(b, Q, d);
    aBox.add(b, T, literal2);
    aBox.add(a, OWL.sameAs, b);
    Assert.assertTrue(inf.contains(b, OWL.sameAs, a));
    Assert.assertTrue(inf.contains(b, P, c));
    Assert.assertTrue(inf.contains(b, S, literal1));
    Assert.assertTrue(inf.contains(a, Q, d));
    Assert.assertTrue(inf.contains(a, T, literal2));
    aBox.remove(a, OWL.sameAs, b);
    Assert.assertFalse(inf.contains(b, OWL.sameAs, a));
    Assert.assertFalse(inf.contains(b, P, c));
    Assert.assertFalse(inf.contains(b, S, literal1));
    Assert.assertFalse(inf.contains(a, Q, d));
    Assert.assertFalse(inf.contains(a, T, literal2));
}
Also used : OntProperty(org.apache.jena.ontology.OntProperty) Literal(org.apache.jena.rdf.model.Literal) OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) OntModel(org.apache.jena.ontology.OntModel) Test(org.junit.Test)

Example 4 with OntProperty

use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.

the class SimpleReasonerSameAsTest method recomputeABox1.

/*
	 * Basic scenario around recomputing the ABox inferences
	 */
@Test
public void recomputeABox1() throws InterruptedException {
    OntModel tBox = createTBoxModel();
    OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
    OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
    OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S");
    OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T");
    Literal literal1 = tBox.createLiteral("Literal value 1");
    Literal literal2 = tBox.createLiteral("Literal value 2");
    // this is the model to receive inferences
    Model inf = ModelFactory.createDefaultModel();
    // create an ABox and register the SimpleReasoner listener with it
    OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
    SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
    aBox.register(simpleReasoner);
    // Individuals a, b, c and d
    Resource a = aBox.createIndividual("http://test.vivo/a", OWL.Thing);
    Resource b = aBox.createIndividual("http://test.vivo/b", OWL.Thing);
    Resource c = aBox.createIndividual("http://test.vivo/c", OWL.Thing);
    Resource d = aBox.createIndividual("http://test.vivo/d", OWL.Thing);
    aBox.add(a, P, c);
    aBox.add(a, S, literal1);
    aBox.add(b, Q, d);
    aBox.add(b, T, literal2);
    aBox.add(a, OWL.sameAs, b);
    Assert.assertTrue(inf.contains(b, OWL.sameAs, a));
    Assert.assertTrue(inf.contains(b, P, c));
    Assert.assertTrue(inf.contains(b, S, literal1));
    Assert.assertTrue(inf.contains(a, Q, d));
    Assert.assertTrue(inf.contains(a, T, literal2));
    inf.remove(b, OWL.sameAs, a);
    inf.remove(b, P, c);
    inf.remove(b, S, literal1);
    inf.remove(a, Q, d);
    inf.remove(a, T, literal2);
    simpleReasoner.recompute();
    while (simpleReasoner.isRecomputing()) {
        Thread.sleep(delay);
    }
    // Verify inferences
    Assert.assertTrue(inf.contains(b, OWL.sameAs, a));
    Assert.assertTrue(inf.contains(b, P, c));
    Assert.assertTrue(inf.contains(b, S, literal1));
    Assert.assertTrue(inf.contains(a, Q, d));
    Assert.assertTrue(inf.contains(a, T, literal2));
}
Also used : OntProperty(org.apache.jena.ontology.OntProperty) Literal(org.apache.jena.rdf.model.Literal) OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) OntModel(org.apache.jena.ontology.OntModel) Test(org.junit.Test)

Example 5 with OntProperty

use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.

the class SimpleReasonerSameAsTest method addABoxAssertion1.

/*
	* adding abox assertion for individual in sameAs chain.
	*/
@Test
public void addABoxAssertion1() {
    OntModel tBox = createTBoxModel();
    OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
    OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
    OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S");
    OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T");
    Literal literal1 = tBox.createLiteral("Literal value 1");
    Literal literal2 = tBox.createLiteral("Literal value 2");
    // this is the model to receive inferences
    Model inf = ModelFactory.createDefaultModel();
    // create an ABox and register the SimpleReasoner listener with it
    OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
    aBox.register(new SimpleReasoner(tBox, aBox, inf));
    // Individuals a, b, c and d
    Resource a = aBox.createResource("http://test.vivo/a");
    Resource b = aBox.createResource("http://test.vivo/b");
    Resource c = aBox.createResource("http://test.vivo/c");
    Resource d = aBox.createResource("http://test.vivo/d");
    Resource e = aBox.createResource("http://test.vivo/e");
    Resource f = aBox.createResource("http://test.vivo/f");
    aBox.add(a, OWL.sameAs, b);
    aBox.add(b, OWL.sameAs, e);
    aBox.add(e, OWL.sameAs, f);
    Assert.assertTrue(inf.contains(b, OWL.sameAs, a));
    Assert.assertTrue(inf.contains(e, OWL.sameAs, a));
    Assert.assertTrue(inf.contains(e, OWL.sameAs, b));
    Assert.assertTrue(inf.contains(a, OWL.sameAs, e));
    Assert.assertTrue(inf.contains(f, OWL.sameAs, e));
    Assert.assertTrue(inf.contains(f, OWL.sameAs, b));
    Assert.assertTrue(inf.contains(f, OWL.sameAs, a));
    Assert.assertTrue(inf.contains(b, OWL.sameAs, f));
    Assert.assertTrue(inf.contains(a, OWL.sameAs, f));
    aBox.add(a, P, c);
    aBox.add(a, S, literal1);
    aBox.add(b, Q, d);
    aBox.add(b, T, literal2);
    Assert.assertTrue(inf.contains(b, P, c));
    Assert.assertTrue(inf.contains(b, S, literal1));
    Assert.assertTrue(inf.contains(a, Q, d));
    Assert.assertTrue(inf.contains(a, T, literal2));
    Assert.assertTrue(inf.contains(e, P, c));
    Assert.assertTrue(inf.contains(e, S, literal1));
    Assert.assertTrue(inf.contains(e, Q, d));
    Assert.assertTrue(inf.contains(e, T, literal2));
    Assert.assertTrue(inf.contains(f, P, c));
    Assert.assertTrue(inf.contains(f, S, literal1));
    Assert.assertTrue(inf.contains(f, Q, d));
    Assert.assertTrue(inf.contains(f, T, literal2));
    aBox.remove(b, OWL.sameAs, e);
    Assert.assertTrue(inf.contains(b, OWL.sameAs, a));
    Assert.assertFalse(inf.contains(e, OWL.sameAs, a));
    Assert.assertFalse(inf.contains(e, OWL.sameAs, b));
    Assert.assertFalse(inf.contains(a, OWL.sameAs, e));
    Assert.assertTrue(inf.contains(f, OWL.sameAs, e));
    Assert.assertFalse(inf.contains(f, OWL.sameAs, b));
    Assert.assertFalse(inf.contains(f, OWL.sameAs, a));
    Assert.assertFalse(inf.contains(b, OWL.sameAs, f));
    Assert.assertFalse(inf.contains(a, OWL.sameAs, f));
    Assert.assertTrue(inf.contains(b, P, c));
    Assert.assertTrue(inf.contains(b, S, literal1));
    Assert.assertTrue(inf.contains(a, Q, d));
    Assert.assertTrue(inf.contains(a, T, literal2));
    Assert.assertFalse(inf.contains(e, P, c));
    Assert.assertFalse(inf.contains(e, S, literal1));
    Assert.assertFalse(inf.contains(e, Q, d));
    Assert.assertFalse(inf.contains(e, T, literal2));
    Assert.assertFalse(inf.contains(f, P, c));
    Assert.assertFalse(inf.contains(f, S, literal1));
    Assert.assertFalse(inf.contains(f, Q, d));
    Assert.assertFalse(inf.contains(f, T, literal2));
}
Also used : OntProperty(org.apache.jena.ontology.OntProperty) Literal(org.apache.jena.rdf.model.Literal) OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) OntModel(org.apache.jena.ontology.OntModel) Test(org.junit.Test)

Aggregations

OntProperty (org.apache.jena.ontology.OntProperty)44 Resource (org.apache.jena.rdf.model.Resource)34 OntModel (org.apache.jena.ontology.OntModel)31 Model (org.apache.jena.rdf.model.Model)25 StmtIterator (org.apache.jena.rdf.model.StmtIterator)13 Literal (org.apache.jena.rdf.model.Literal)12 Test (org.junit.Test)10 Statement (org.apache.jena.rdf.model.Statement)9 RDFNode (org.apache.jena.rdf.model.RDFNode)8 ArrayList (java.util.ArrayList)7 OntClass (org.apache.jena.ontology.OntClass)7 OntResource (org.apache.jena.ontology.OntResource)7 Iterator (java.util.Iterator)6 ObjectPropertyStatement (edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement)5 LinkedList (java.util.LinkedList)5 ProfileException (org.apache.jena.ontology.ProfileException)5 Restriction (org.apache.jena.ontology.Restriction)5 ObjectProperty (edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty)4 InsertException (edu.cornell.mannlib.vitro.webapp.dao.InsertException)4 RDFServiceException (edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException)4