use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class SimpleReasonerInversePropertyTest method removeTBoxInverseAssertion1.
/*
* removing an inverseOf assertion from the tbox
*/
public void removeTBoxInverseAssertion1(boolean sameAs) throws InterruptedException {
// set up the tbox
OntModel tBox = createTBoxModel();
OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
setInverse(P, Q);
// this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel();
// abox
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
// set up SimpleReasoner and SimpleReasonerTBox listener,
// register them with abox and tbox
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
simpleReasoner.setSameAsEnabled(sameAs);
aBox.register(simpleReasoner);
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
tBox.register(simpleReasonerTBoxListener);
// add statements to the abox and verify inference
Resource c = aBox.createIndividual("http://test.vivo/c", OWL.Thing);
Resource d = aBox.createIndividual("http://test.vivo/d", OWL.Thing);
aBox.add(c, P, d);
Assert.assertTrue(inf.contains(d, Q, c));
// Remove P and Q inverse relationship and wait for
// SimpleReasoner TBox thread to end.
removeInverse(P, Q);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay);
}
// Verify inference has been removed
Assert.assertFalse(inf.contains(d, Q, c));
simpleReasonerTBoxListener.setStopRequested();
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class SimpleReasonerInversePropertyTest method addABoxAssertion4.
/*
* adding abox data where the property has an inverse and
* and equivalent property.
*/
public void addABoxAssertion4(boolean sameAs) {
// set up the tbox
OntModel tBox = createTBoxModel();
OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty R = createObjectProperty(tBox, "http://test.vivo/R", "property R");
setInverse(P, Q);
setInverse(R, Q);
setEquivalent(R, P);
// this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel();
// create an ABox and register the SimpleReasoner with it
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
sr.setSameAsEnabled(sameAs);
aBox.register(sr);
// add abox statements and verify inferences
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, R, b);
Assert.assertTrue(inf.contains(b, Q, a));
aBox.add(c, Q, d);
Assert.assertTrue(inf.contains(d, P, c));
Assert.assertTrue(inf.contains(d, R, c));
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class SimpleReasonerInversePropertyTest method addABoxAssertion1.
/*
* basic scenarios around adding abox data
*
* Create a Tbox with property P inverseOf property Q.
* Add a statement a P b, and verify that b Q a is inferred.
* Add a statement c Q d and verify that d Q c is inferred.
*/
public void addABoxAssertion1(boolean sameAs) {
// set up the tbox
OntModel tBox = createTBoxModel();
OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
setInverse(P, Q);
// this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel();
// create an abox and register the SimpleReasoner listener with it
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
sr.setSameAsEnabled(sameAs);
aBox.register(sr);
// add assertions to the abox and verify inferences
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, b);
Assert.assertTrue(inf.contains(b, Q, a));
aBox.add(c, Q, d);
Assert.assertTrue(inf.contains(d, P, c));
// delete assertions and verify that inferences go away
aBox.remove(c, Q, d);
Assert.assertFalse(inf.contains(d, P, c));
aBox.remove(a, P, b);
Assert.assertFalse(inf.contains(b, Q, a));
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class SimpleReasonerInversePropertyTest method addABoxAssertion2.
/*
* don't infer statements already in the abox
* (never infer because it's in the abox already)
*/
public void addABoxAssertion2(boolean sameAs) {
// set up the tbox
OntModel tBox = createTBoxModel();
OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
setInverse(P, Q);
// this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel();
// create an ABox and add data (no inferencing happening yet)
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
// Individuals a, b, c and d
Resource a = aBox.createResource("http://test.vivo/a");
Resource b = aBox.createResource("http://test.vivo/b");
aBox.add(b, Q, a);
// register SimpleReasoner
aBox.register(new SimpleReasoner(tBox, aBox, inf));
Assert.assertFalse(inf.contains(b, Q, a));
// add data and verify inferences
aBox.add(a, P, b);
Assert.assertFalse(inf.contains(b, Q, a));
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class JenaOntologyLoader method loadSystemAndUsers.
/**
* This should load the system with classes, data properties and
* object properties that the vitro systems needs.
*
* @throws Exception
*/
OntModel loadSystemAndUsers() throws Exception {
Model model = ModelFactory.createDefaultModel();
for (String ont : systemOnts) {
InputStream in = this.getClass().getResourceAsStream(ont);
model.read(in, null);
in.close();
}
ontModel = ModelFactory.createOntologyModel(ONT_MODEL_SPEC, model);
ontModel.prepare();
return ontModel;
}
Aggregations