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