NIHVIVO-3697 sameAs support in SimpleReasoner
This commit is contained in:
parent
2b15e7211c
commit
de081579af
5 changed files with 857 additions and 1173 deletions
File diff suppressed because it is too large
Load diff
|
@ -49,12 +49,14 @@ public class SimpleReasonerTBoxListener extends StatementListener {
|
|||
|
||||
@Override
|
||||
public void addedStatement(Statement statement) {
|
||||
|
||||
ModelUpdate mu = new ModelUpdate(statement, ModelUpdate.Operation.ADD, JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL);
|
||||
processUpdate(mu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removedStatement(Statement statement) {
|
||||
|
||||
ModelUpdate mu = new ModelUpdate(statement, ModelUpdate.Operation.RETRACT, JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL);
|
||||
processUpdate(mu);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
|
||||
@Before
|
||||
public void suppressErrorOutput() {
|
||||
//suppressSyserr();
|
||||
suppressSyserr();
|
||||
//Turn off log messages to console
|
||||
setLoggerLevel(SimpleReasoner.class, Level.OFF);
|
||||
setLoggerLevel(SimpleReasonerTBoxListener.class, Level.OFF);
|
||||
|
@ -42,44 +42,42 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
@Test
|
||||
public void addABoxAssertion1() {
|
||||
|
||||
// set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||
P.setLabel("property P", "en-US");
|
||||
|
||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
||||
Q.setLabel("property Q", "en-US");
|
||||
|
||||
P.addInverseOf(Q);
|
||||
|
||||
// this is the model to receive inferences
|
||||
// this is the model to receive abox inferences
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
// create an ABox and register the SimpleReasoner listener with it
|
||||
// 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
|
||||
// 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");
|
||||
|
||||
// b Q a is inferred from a P b
|
||||
aBox.add(a,P,b);
|
||||
Assert.assertTrue(inf.contains(b,Q,a));
|
||||
|
||||
// d P c is inferred from c Q d.
|
||||
aBox.add(c,Q,d);
|
||||
Assert.assertTrue(inf.contains(d,P,c));
|
||||
}
|
||||
|
||||
/*
|
||||
* don't infer if it's already in the abox
|
||||
* don't infer statements already in the abox
|
||||
* (never infer because it's in the abox already)
|
||||
*/
|
||||
@Test
|
||||
public void addABoxAssertion2() {
|
||||
|
||||
// set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||
|
@ -88,10 +86,10 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
Q.setLabel("property Q", "en-US");
|
||||
P.addInverseOf(Q);
|
||||
|
||||
// this is the model to receive inferences
|
||||
// this is the model to receive abox inferences
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
// create an ABox and add statement b Q a
|
||||
// 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");
|
||||
|
@ -101,38 +99,42 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
// register SimpleReasoner
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
|
||||
// b Q a is inferred from a P b, but it is already in the abox
|
||||
Assert.assertFalse(inf.contains(b,Q,a));
|
||||
|
||||
// add data and verify inferences
|
||||
aBox.add(a,P,b);
|
||||
Assert.assertFalse(inf.contains(b,Q,a));
|
||||
}
|
||||
|
||||
/*
|
||||
* don't infer if it's already in the abox
|
||||
* don't infer statements already in the abox
|
||||
* (remove the inference when it is asserted)
|
||||
*/
|
||||
@Test
|
||||
public void addABoxAssertion3() {
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
||||
// set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||
P.setLabel("property P", "en-US");
|
||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
||||
Q.setLabel("property Q", "en-US");
|
||||
P.addInverseOf(Q);
|
||||
|
||||
// this is the model to receive inferences
|
||||
// this is the model to receive abox inferences
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
// create an ABox and register SimpleReasoner
|
||||
// create abox and register SimpleReasoner
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
|
||||
// Individuals a, b, c and d
|
||||
// add statements to the abox and verify inferences
|
||||
Resource a = aBox.createResource("http://test.vivo/a");
|
||||
Resource b = aBox.createResource("http://test.vivo/b");
|
||||
|
||||
// b Q a is inferred from a P b, but it is already in the abox
|
||||
aBox.add(a,P,b);
|
||||
aBox.add(b,Q,a);
|
||||
Assert.assertTrue(inf.contains(b,Q,a));
|
||||
aBox.add(b,Q,a); // this should cause the inference to be removed
|
||||
Assert.assertFalse(inf.contains(b,Q,a));
|
||||
}
|
||||
|
||||
|
@ -143,8 +145,8 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
@Test
|
||||
public void addABoxAssertion4() {
|
||||
|
||||
// set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||
P.setLabel("property P", "en-US");
|
||||
OntProperty R = tBox.createOntProperty("http://test.vivo/R");
|
||||
|
@ -153,27 +155,24 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
Q.setLabel("property Q", "en-US");
|
||||
|
||||
R.addEquivalentProperty(P);
|
||||
P.addEquivalentProperty(R);
|
||||
P.addInverseOf(Q);
|
||||
|
||||
// this is the model to receive inferences
|
||||
// this is the model to receive abox inferences
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
// create an ABox and register the SimpleReasoner listener with it
|
||||
// create an ABox and register the SimpleReasoner with it
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
|
||||
// a, b, c and d
|
||||
// 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");
|
||||
|
||||
// b Q a is inferred from a R b.
|
||||
aBox.add(a,R,b);
|
||||
Assert.assertTrue(inf.contains(b,Q,a));
|
||||
|
||||
// d P c is inferred from c Q d.
|
||||
aBox.add(c,Q,d);
|
||||
Assert.assertTrue(inf.contains(d,P,c));
|
||||
Assert.assertTrue(inf.contains(d,R,c));
|
||||
|
@ -181,11 +180,14 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
|
||||
/*
|
||||
* basic scenarios around removing abox data
|
||||
* don't remove an inference if it's still
|
||||
* entailed by something else in the abox.
|
||||
*/
|
||||
@Test
|
||||
public void removedABoxAssertion1() {
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
||||
// set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||
P.setLabel("property P", "en-US");
|
||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
||||
|
@ -195,24 +197,23 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
P.addInverseOf(Q);
|
||||
P.addInverseOf(T);
|
||||
|
||||
// this is the model to receive inferences
|
||||
// this is the model to receive abox inferences
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
// create an ABox and register the SimpleReasoner listener with it
|
||||
// create an ABox and register the SimpleReasoner with it
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
|
||||
// Individuals a, b, c and d
|
||||
// add statements 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");
|
||||
|
||||
// b Q a is inferred from a P b.
|
||||
aBox.add(a,P,b);
|
||||
Assert.assertTrue(inf.contains(b,Q,a));
|
||||
|
||||
// d P c is inferred from c Q d and from c T d
|
||||
// d P c is inferred from c Q d and also from c T d
|
||||
aBox.add(c,Q,d);
|
||||
aBox.add(c,T,d);
|
||||
Assert.assertTrue(inf.contains(d,P,c));
|
||||
|
@ -221,16 +222,18 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
Assert.assertFalse(inf.contains(b,Q,a));
|
||||
|
||||
aBox.remove(c,Q,d);
|
||||
Assert.assertTrue(inf.contains(d,P,c));
|
||||
Assert.assertTrue(inf.contains(d,P,c)); // still inferred from c T d
|
||||
}
|
||||
|
||||
/*
|
||||
* removing abox data with equivalent and inverse properties
|
||||
* don't remove inference if it's still inferred.
|
||||
*/
|
||||
@Test
|
||||
public void removedABoxAssertion2() {
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
||||
// set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||
P.setLabel("property P", "en-US");
|
||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
||||
|
@ -238,26 +241,29 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
OntProperty T = tBox.createOntProperty("http://test.vivo/T");
|
||||
Q.setLabel("property T", "en-US");
|
||||
P.addInverseOf(Q);
|
||||
Q.addInverseOf(P);
|
||||
P.addEquivalentProperty(T);
|
||||
T.addEquivalentProperty(P);
|
||||
|
||||
// this is the model to receive inferences
|
||||
// not clear what these will do
|
||||
tBox.rebind();
|
||||
tBox.prepare();
|
||||
|
||||
// this is the model to receive abox inferences
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
// create an ABox and register the SimpleReasoner listener with it
|
||||
// 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
|
||||
// add abox data and verify inferences
|
||||
Resource a = aBox.createResource("http://test.vivo/a");
|
||||
Resource b = aBox.createResource("http://test.vivo/b");
|
||||
|
||||
// b Q a is inferred from a P b and a T b.
|
||||
// b Q a is inferred from a P b and also from a T b.
|
||||
aBox.add(a,P,b);
|
||||
aBox.add(a,T,b);
|
||||
Assert.assertTrue(inf.contains(b,Q,a));
|
||||
Assert.assertFalse(inf.contains(a,P,b));
|
||||
Assert.assertFalse(inf.contains(a,T,b));
|
||||
|
||||
aBox.remove(a,P,b);
|
||||
Assert.assertTrue(inf.contains(b,Q,a));
|
||||
|
@ -268,80 +274,81 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
*/
|
||||
@Test
|
||||
public void removedABoxAssertion3() {
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
||||
//set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||
P.setLabel("property P", "en-US");
|
||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
||||
Q.setLabel("property Q", "en-US");
|
||||
P.addInverseOf(Q);
|
||||
|
||||
// this is the model to receive inferences
|
||||
tBox.rebind(); // not sure what effect this has
|
||||
|
||||
// this is the model to receive abox inferences
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
// create an ABox and register the SimpleReasoner listener with it
|
||||
// create the abox and add some data - no reasoning is happening yet
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
|
||||
Resource a = aBox.createResource("http://test.vivo/a");
|
||||
Resource b = aBox.createResource("http://test.vivo/b");
|
||||
aBox.add(a,P,b);
|
||||
|
||||
// register the SimpleReasoner
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
|
||||
// add abox statements and verify inferences
|
||||
aBox.add(b,Q,a);
|
||||
|
||||
Assert.assertFalse(inf.contains(b,Q,a));
|
||||
Assert.assertFalse(inf.contains(a,P,b));
|
||||
|
||||
Assert.assertFalse(inf.contains(a,P,b)); // this could be inferred from b Q a, but
|
||||
// it's already in the abox
|
||||
aBox.remove(a,P,b);
|
||||
Assert.assertTrue(inf.contains(a,P,b));
|
||||
Assert.assertTrue(inf.contains(a,P,b)); // now it gets added to inference model
|
||||
// when it's removed from the abox
|
||||
}
|
||||
|
||||
/*
|
||||
* Basic scenario around adding an inverseOf assertion to the
|
||||
* TBox
|
||||
* adding an inverseOf assertion to the tbox
|
||||
*/
|
||||
@Test
|
||||
public void addTBoxInverseAssertion1() throws InterruptedException {
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
||||
// Set up the TBox.
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||
P.setLabel("property P", "en-US");
|
||||
|
||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
||||
Q.setLabel("property Q", "en-US");
|
||||
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
// this is the model to receive abox inferences
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
// abox
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
|
||||
// set up SimpleReasoner and register it with abox. register
|
||||
// SimpleReasonerTBoxListener with the tbox.
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
||||
// Individuals a, b, c and d
|
||||
// add abox data
|
||||
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 statements
|
||||
aBox.add(a,P,b);
|
||||
aBox.add(c,P,d);
|
||||
aBox.add(b,Q,a);
|
||||
|
||||
// Assert P and Q as inverses and wait for SimpleReasoner TBox
|
||||
// thread to end
|
||||
// Assert P and Q as inverses and wait for
|
||||
// SimpleReasonerTBoxListener thread to end
|
||||
|
||||
Q.addInverseOf(P);
|
||||
|
||||
tBox.rebind();
|
||||
tBox.prepare();
|
||||
|
||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
|
@ -349,47 +356,43 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
// Verify inferences
|
||||
Assert.assertTrue(inf.contains(d,Q,c));
|
||||
Assert.assertFalse(inf.contains(b,Q,a));
|
||||
Assert.assertFalse(inf.contains(a,P,b));
|
||||
|
||||
simpleReasonerTBoxListener.setStopRequested();
|
||||
}
|
||||
|
||||
/*
|
||||
* Basic scenario around removing an inverseOf assertion to the
|
||||
* TBox
|
||||
* removing an inverseOf assertion from the tbox
|
||||
*/
|
||||
@Test
|
||||
public void removeTBoxInverseAssertion1() throws InterruptedException {
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
||||
// set up the tbox.
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
||||
// set up TBox and Abox
|
||||
|
||||
OntProperty P = tBox.createOntProperty("http://test.vivo/propP");
|
||||
P.setLabel("property P", "en-US");
|
||||
|
||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/propQ");
|
||||
Q.setLabel("property Q", "en-US");
|
||||
|
||||
Q.addInverseOf(P);
|
||||
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
// 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);
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
// Individuals a, b, c and d
|
||||
|
||||
// add statements to the abox and verify inference
|
||||
Resource c = aBox.createResource("http://test.vivo/c");
|
||||
Resource d = aBox.createResource("http://test.vivo/d");
|
||||
|
||||
// abox statements
|
||||
aBox.add(c,P,d);
|
||||
|
||||
Assert.assertTrue(inf.contains(d,Q,c));
|
||||
|
||||
// Remove P and Q inverse relationship and wait for
|
||||
|
@ -397,14 +400,11 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
|
||||
Q.removeInverseProperty(P);
|
||||
|
||||
tBox.rebind();
|
||||
tBox.prepare();
|
||||
|
||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
|
||||
// Verify inferences
|
||||
// Verify inference has been removed
|
||||
Assert.assertFalse(inf.contains(d,Q,c));
|
||||
|
||||
simpleReasonerTBoxListener.setStopRequested();
|
||||
|
@ -416,12 +416,9 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
@Test
|
||||
public void recomputeABox1() throws InterruptedException {
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
// set up tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
||||
// set up TBox and Abox
|
||||
OntProperty P = tBox.createOntProperty("http://test.vivo/propP");
|
||||
P.setLabel("property P", "en-US");
|
||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/propQ");
|
||||
|
@ -434,21 +431,23 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
Q.setLabel("property Y", "en-US");
|
||||
X.addInverseOf(Y);
|
||||
|
||||
// create abox and abox inf model and register simplereasoner
|
||||
// with abox.
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
aBox.register(simpleReasoner);
|
||||
// Individuals a, b, c and d
|
||||
|
||||
// abox statements
|
||||
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 statements
|
||||
aBox.add(a,P,b);
|
||||
aBox.add(c,X,d);
|
||||
|
||||
//recompute whole abox
|
||||
simpleReasoner.recompute();
|
||||
|
||||
while (simpleReasoner.isRecomputing()) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.mindswap.pellet.jena.PelletReasonerFactory;
|
||||
|
||||
import com.hp.hpl.jena.ontology.AnnotationProperty;
|
||||
import com.hp.hpl.jena.ontology.OntClass;
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
|
@ -16,6 +17,7 @@ import com.hp.hpl.jena.rdf.model.Literal;
|
|||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.vocabulary.OWL;
|
||||
import com.hp.hpl.jena.vocabulary.RDF;
|
||||
|
||||
|
@ -25,10 +27,11 @@ import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
|
|||
public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||
|
||||
long delay = 50;
|
||||
private static final String mostSpecificTypePropertyURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType";
|
||||
|
||||
@Before
|
||||
public void suppressErrorOutput() {
|
||||
//suppressSyserr();
|
||||
suppressSyserr();
|
||||
//Turn off log messages to console
|
||||
setLoggerLevel(SimpleReasoner.class, Level.OFF);
|
||||
setLoggerLevel(SimpleReasonerTBoxListener.class, Level.OFF);
|
||||
|
@ -363,9 +366,6 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
|||
|
||||
Q.addInverseOf(P);
|
||||
|
||||
tBox.rebind();
|
||||
tBox.prepare();
|
||||
|
||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
|
@ -377,9 +377,6 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
|||
|
||||
Q.removeInverseProperty(P);
|
||||
|
||||
tBox.rebind();
|
||||
tBox.prepare();
|
||||
|
||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
|
@ -429,22 +426,127 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
|||
|
||||
Assert.assertTrue(inf.contains(y,RDF.type,classB));
|
||||
Assert.assertTrue(inf.contains(y,RDF.type,classA));
|
||||
// Assert.assertTrue(inf.contains(z,RDF.type,classB));
|
||||
// Assert.assertTrue(inf.contains(z,RDF.type,classA));
|
||||
Assert.assertTrue(inf.contains(z,RDF.type,classB));
|
||||
Assert.assertTrue(inf.contains(z,RDF.type,classA));
|
||||
|
||||
aBox.remove(x,RDF.type,classB);
|
||||
Assert.assertFalse(inf.contains(y,RDF.type,classB));
|
||||
Assert.assertFalse(inf.contains(y,RDF.type,classA));
|
||||
Assert.assertFalse(inf.contains(z,RDF.type,classB));
|
||||
Assert.assertFalse(inf.contains(z,RDF.type,classA));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* adding and removing subclass assertion when there is an
|
||||
* individual member who has a sameAs individual.
|
||||
*/
|
||||
//@Test
|
||||
@Test
|
||||
public void tBoxSubclassAssertion1() throws InterruptedException {
|
||||
|
||||
//create aBox and tBox, and SimpleReasoner to listen to them
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
||||
// set up TBox
|
||||
OntClass classA = tBox.createClass("http://test.vivo/A");
|
||||
classA.setLabel("class A", "en-US");
|
||||
OntClass classB = tBox.createClass("http://test.vivo/B");
|
||||
classB.setLabel("class B", "en-US");
|
||||
OntClass classC = tBox.createClass("http://test.vivo/C");
|
||||
classC.setLabel("class C", "en-US");
|
||||
|
||||
// set up ABox
|
||||
Resource a = aBox.createResource("http://test.vivo/a");
|
||||
Resource b = aBox.createResource("http://test.vivo/b");
|
||||
Resource c = aBox.createResource("http://test.vivo/c");
|
||||
|
||||
aBox.add(a, RDF.type, classC);
|
||||
aBox.add(a, OWL.sameAs, b);
|
||||
aBox.add(c, OWL.sameAs, a);
|
||||
|
||||
// update TBox
|
||||
classA.addSubClass(classB);
|
||||
|
||||
// wait for SimpleReasonerTBoxListener thread to end
|
||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
|
||||
classB.addSubClass(classC);
|
||||
classA.addSubClass(classC); // simulate what Pellet would infer, and
|
||||
// thus what the SimpleReasonerTBoxListener
|
||||
// would be notified of.
|
||||
|
||||
// wait for SimpleReasonerTBoxListener thread to end
|
||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
|
||||
// Verify inferences
|
||||
Assert.assertFalse(inf.contains(a, RDF.type, classC));
|
||||
Assert.assertTrue(inf.contains(a, RDF.type, classB));
|
||||
Assert.assertTrue(inf.contains(a, RDF.type, classA));
|
||||
|
||||
Assert.assertTrue(inf.contains(b, RDF.type, classC));
|
||||
Assert.assertTrue(inf.contains(b, RDF.type, classB));
|
||||
Assert.assertTrue(inf.contains(b, RDF.type, classA));
|
||||
|
||||
Assert.assertTrue(inf.contains(c, RDF.type, classC));
|
||||
Assert.assertTrue(inf.contains(c, RDF.type, classB));
|
||||
Assert.assertTrue(inf.contains(c, RDF.type, classA));
|
||||
|
||||
// update TBox
|
||||
classA.removeSubClass(classB);
|
||||
classA.removeSubClass(classC); // simulate what Pellet would infer, and
|
||||
// thus what the SimpleReasonerTBoxListener
|
||||
// would be notified of.
|
||||
|
||||
// wait for SimpleReasonerTBoxListener thread to end
|
||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
|
||||
// Verify inferences
|
||||
Assert.assertFalse(inf.contains(a, RDF.type, classC));
|
||||
Assert.assertTrue(inf.contains(a, RDF.type, classB));
|
||||
Assert.assertFalse(inf.contains(a, RDF.type, classA));
|
||||
|
||||
Assert.assertTrue(inf.contains(b, RDF.type, classC));
|
||||
Assert.assertTrue(inf.contains(b, RDF.type, classB));
|
||||
Assert.assertFalse(inf.contains(b, RDF.type, classA));
|
||||
|
||||
Assert.assertTrue(inf.contains(c, RDF.type, classC));
|
||||
Assert.assertTrue(inf.contains(c, RDF.type, classB));
|
||||
Assert.assertFalse(inf.contains(c, RDF.type, classA));
|
||||
|
||||
// update TBox
|
||||
classB.removeSubClass(classC);
|
||||
|
||||
// wait for SimpleReasonerTBoxListener thread to end
|
||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
|
||||
// Verify inferences
|
||||
Assert.assertFalse(inf.contains(a, RDF.type, classC));
|
||||
Assert.assertFalse(inf.contains(a, RDF.type, classB));
|
||||
Assert.assertFalse(inf.contains(a, RDF.type, classA));
|
||||
|
||||
Assert.assertTrue(inf.contains(b, RDF.type, classC));
|
||||
Assert.assertFalse(inf.contains(b, RDF.type, classB));
|
||||
Assert.assertFalse(inf.contains(b, RDF.type, classA));
|
||||
|
||||
Assert.assertTrue(inf.contains(c, RDF.type, classC));
|
||||
Assert.assertFalse(inf.contains(c, RDF.type, classB));
|
||||
Assert.assertFalse(inf.contains(c, RDF.type, classA));
|
||||
|
||||
simpleReasonerTBoxListener.setStopRequested();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -453,19 +555,91 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
|||
*/
|
||||
//@Test
|
||||
public void mostSpecificTypeTest1() throws InterruptedException {
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
||||
// Set up the Tbox with a class hierarchy. C is a
|
||||
// subclass of A. D and E are subclasses C.
|
||||
// Pellet will compute TBox inferences.
|
||||
AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI);
|
||||
|
||||
OntClass classA = tBox.createClass("http://test.vivo/A");
|
||||
classA.setLabel("class A", "en-US");
|
||||
OntClass classC = tBox.createClass("http://test.vivo/C");
|
||||
classC.setLabel("class C", "en-US");
|
||||
OntClass classD = tBox.createClass("http://test.vivo/D");
|
||||
classD.setLabel("class D", "en-US");
|
||||
OntClass classE = tBox.createClass("http://test.vivo/E");
|
||||
classE.setLabel("class E", "en-US");
|
||||
|
||||
classA.addSubClass(classC);
|
||||
classC.addSubClass(classD);
|
||||
classC.addSubClass(classE);
|
||||
|
||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
|
||||
/*
|
||||
* there is a sameAs chain and one sameAs statement is removed.
|
||||
*
|
||||
*/
|
||||
//@Test
|
||||
public void sameAsChain1() throws InterruptedException {
|
||||
// add & remove ABox type 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, OWL.sameAs, b);
|
||||
aBox.add(c, OWL.sameAs, b);
|
||||
aBox.add(d, OWL.sameAs, a);
|
||||
|
||||
aBox.add(a, RDF.type, classD);
|
||||
aBox.add(d, RDF.type, classC);
|
||||
Assert.assertFalse(inf.contains(a,RDF.type,classD));
|
||||
Assert.assertTrue(inf.contains(a,RDF.type,classC));
|
||||
Assert.assertTrue(inf.contains(b,RDF.type, classD));
|
||||
Assert.assertTrue(inf.contains(b,RDF.type, classC));
|
||||
Assert.assertTrue(inf.contains(c,RDF.type, classD));
|
||||
Assert.assertTrue(inf.contains(c,RDF.type, classC));
|
||||
Assert.assertTrue(inf.contains(d,RDF.type, classD));
|
||||
Assert.assertFalse(inf.contains(d,RDF.type, classC));
|
||||
|
||||
Assert.assertTrue(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertTrue(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertTrue(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertTrue(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertFalse(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||
Assert.assertFalse(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||
Assert.assertFalse(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||
Assert.assertFalse(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||
|
||||
aBox.remove(a, RDF.type, classD);
|
||||
Assert.assertFalse(inf.contains(a,RDF.type,classD));
|
||||
Assert.assertTrue(inf.contains(a,RDF.type,classC));
|
||||
Assert.assertFalse(inf.contains(b,RDF.type, classD));
|
||||
Assert.assertTrue(inf.contains(b,RDF.type, classC));
|
||||
Assert.assertFalse(inf.contains(c,RDF.type, classD));
|
||||
Assert.assertTrue(inf.contains(c,RDF.type, classC));
|
||||
Assert.assertFalse(inf.contains(d,RDF.type, classD));
|
||||
Assert.assertFalse(inf.contains(d,RDF.type, classC));
|
||||
Assert.assertTrue(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||
Assert.assertTrue(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||
Assert.assertTrue(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||
Assert.assertTrue(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||
Assert.assertFalse(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertFalse(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertFalse(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertFalse(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
|
||||
simpleReasonerTBoxListener.setStopRequested();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Basic scenario around recomputing the ABox inferences
|
||||
*/
|
||||
|
|
|
@ -13,7 +13,6 @@ import com.hp.hpl.jena.ontology.AnnotationProperty;
|
|||
import com.hp.hpl.jena.ontology.OntClass;
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.ontology.OntProperty;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
|
@ -28,7 +27,6 @@ import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
|
|||
|
||||
public class SimpleReasonerTest extends AbstractTestClass {
|
||||
|
||||
private Resource objectProperty = ResourceFactory.createResource("http://www.w3.org/2002/07/owl#ObjectProperty");
|
||||
private static final String mostSpecificTypePropertyURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType";
|
||||
long delay = 50;
|
||||
|
||||
|
@ -591,8 +589,12 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
* inference graph.
|
||||
*
|
||||
*/
|
||||
//@Test - enable this in 1.5 - will need to add in PelletListener infrastructure
|
||||
public void removeTBoxSubClassAssertion2() throws InterruptedException {
|
||||
//@Test - this test would need PelletListener infrastructure, which we're not
|
||||
// testing in this suite. The reason it doesn't work as it is because
|
||||
// the SimpleReasonerTBoxListener is not listening to the tBox inference
|
||||
// model as Pellet is updating it. I could simulate it by adding to the
|
||||
// tBox assertions what we can count on Pellet to infer.
|
||||
public void bcdTest() throws InterruptedException {
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
@ -621,6 +623,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
LivingThing.addSubClass(Flora);
|
||||
Flora.addSubClass(Brassica);
|
||||
|
||||
tBox.rebind();
|
||||
tBox.prepare();
|
||||
|
||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
|
@ -632,6 +637,8 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
// Remove the statement that Brassica is a subclass of Flora from the TBox
|
||||
Flora.removeSubClass(Brassica);
|
||||
|
||||
tBox.rebind();
|
||||
tBox.prepare();
|
||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
|
@ -647,411 +654,6 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
simpleReasonerTBoxListener.setStopRequested();
|
||||
}
|
||||
|
||||
/*
|
||||
* tests rdfs:subPropertyOf materialization for object properties.
|
||||
*/
|
||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
||||
public void addABoxAssertion1() throws InterruptedException {
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
||||
// Add object properties propA and propB to the TBox.
|
||||
// propB is a sub-property of propA.
|
||||
|
||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/propA");
|
||||
tBox.add(propA, RDF.type, objectProperty);
|
||||
propA.setLabel("propA", "en-US");
|
||||
|
||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/propB");
|
||||
tBox.add(propB, RDF.type, objectProperty);
|
||||
propB.setLabel("propB", "en-US");
|
||||
|
||||
propA.addSubProperty(propB);
|
||||
|
||||
// Add the assertion that x propB y to the ABox
|
||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
||||
aBox.add(ind_x, propB, ind_y);
|
||||
|
||||
// Verify that x propA y was inferred
|
||||
Statement xay = ResourceFactory.createStatement(ind_x, propA, ind_y);
|
||||
Assert.assertTrue(inf.contains(xay));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test that when a statement is asserted, that it not
|
||||
* added to the inference graph.
|
||||
*/
|
||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
||||
public void addABoxAssertion2(){
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
||||
// Add object properties propA and propB to the TBox.
|
||||
// propB is a sub-property of propA.
|
||||
|
||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/propA");
|
||||
tBox.add(propA, RDF.type, objectProperty);
|
||||
propA.setLabel("propA", "en-US");
|
||||
|
||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/propB");
|
||||
tBox.add(propB, RDF.type, objectProperty);
|
||||
propB.setLabel("propB", "en-US");
|
||||
|
||||
propA.addSubProperty(propB);
|
||||
|
||||
// Add the assertion that x propB y to the ABox
|
||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
||||
aBox.add(ind_x, propB, ind_y);
|
||||
|
||||
// Verify that x propA y was inferred
|
||||
Statement xby = ResourceFactory.createStatement(ind_x, propB, ind_y);
|
||||
Assert.assertFalse(inf.contains(xby));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test inference based on property equivalence
|
||||
*/
|
||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
||||
public void addABoxAssertion4(){
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
||||
// Add properties A, B and C to the TBox
|
||||
// A is equivalent to B
|
||||
// C is a subclass of A
|
||||
|
||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/A");
|
||||
tBox.add(propA, RDF.type, objectProperty);
|
||||
propA.setLabel("property A", "en-US");
|
||||
|
||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/B");
|
||||
tBox.add(propB, RDF.type, objectProperty);
|
||||
propB.setLabel("property B", "en-US");
|
||||
|
||||
OntProperty propC = tBox.createOntProperty("http://test.vivo/C");
|
||||
tBox.add(propC, RDF.type, objectProperty);
|
||||
propC.setLabel("property C", "en-US");
|
||||
|
||||
propA.addEquivalentProperty(propB);
|
||||
propA.addSubProperty(propC);
|
||||
|
||||
// Add a statement that individual x is of type C to the ABox
|
||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
||||
|
||||
aBox.add(ind_x, propC, ind_y);
|
||||
|
||||
// Verify that "x A y" was inferred
|
||||
Statement xAy = ResourceFactory.createStatement(ind_x, propA, ind_y);
|
||||
Assert.assertTrue(inf.contains(xAy));
|
||||
|
||||
// Verify that "x B y" was inferred
|
||||
Statement xBy = ResourceFactory.createStatement(ind_x, propB, ind_y);
|
||||
Assert.assertTrue(inf.contains(xBy));
|
||||
}
|
||||
|
||||
/*
|
||||
* The sub-property is not of the same type as the super
|
||||
* property so no inference should be materialized.
|
||||
*/
|
||||
|
||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
||||
public void addABoxAssertion5(){
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
||||
// Add object properties propA and propB to the TBox.
|
||||
// propB is a sub-property of propA.
|
||||
|
||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/propA");
|
||||
tBox.add(propA, RDF.type, objectProperty);
|
||||
propA.setLabel("propA", "en-US");
|
||||
|
||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/propB");
|
||||
Resource datatypeProperty = ResourceFactory.createResource("http://www.w3.org/2002/07/owl#DatatypeProperty");
|
||||
tBox.add(propB, RDF.type, datatypeProperty);
|
||||
propB.setLabel("propB", "en-US");
|
||||
|
||||
propA.addSubProperty(propB);
|
||||
|
||||
// Add the assertion that x propB y to the ABox
|
||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
||||
aBox.add(ind_x, propB, ind_y);
|
||||
|
||||
// Verify that x propA y was not inferred
|
||||
Statement xay = ResourceFactory.createStatement(ind_x, propA, ind_y);
|
||||
Assert.assertFalse(inf.contains(xay));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test inference based on property equivalence
|
||||
*/
|
||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
||||
public void addABoxAssertion6() {
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
||||
// Add properties A and B to the TBox
|
||||
// A is equivalent to B
|
||||
|
||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/A");
|
||||
tBox.add(propA, RDF.type, objectProperty);
|
||||
propA.setLabel("property A", "en-US");
|
||||
|
||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/B");
|
||||
tBox.add(propB, RDF.type, objectProperty);
|
||||
propB.setLabel("property B", "en-US");
|
||||
|
||||
propA.addEquivalentProperty(propB);
|
||||
|
||||
// Add the statement x B y to the ABox
|
||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
||||
aBox.add(ind_x, propB, ind_y);
|
||||
|
||||
// Verify that "x A y" was inferred
|
||||
Statement xAy = ResourceFactory.createStatement(ind_x, propA, ind_y);
|
||||
Assert.assertTrue(inf.contains(xAy));
|
||||
|
||||
// Remove the statement that x B y from the ABox
|
||||
aBox.remove(ind_x, propB, ind_y);
|
||||
|
||||
// Verify that "x is of type A" was removed from the inference graph
|
||||
Assert.assertFalse(inf.contains(xAy));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Test the addition of a subPropertyOf statement to
|
||||
* the TBox. The instance data that is the basis
|
||||
* for the inference is in the ABox.
|
||||
*
|
||||
* Since the addition of an owl:equivalentProperty
|
||||
* statement is implemented as two calls to the
|
||||
* method that handles the addition of an
|
||||
* rdfs:subPropetyOf statement, this test serves
|
||||
* as a test of equivalentProperty assertions also.
|
||||
*/
|
||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
||||
public void addTBoxSubPropertyAssertion1(){
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
||||
// Add properties A, B, C and D to the TBox
|
||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/A");
|
||||
tBox.add(propA, RDF.type, objectProperty);
|
||||
propA.setLabel("property A", "en-US");
|
||||
|
||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/B");
|
||||
tBox.add(propB, RDF.type, objectProperty);
|
||||
propB.setLabel("property B", "en-US");
|
||||
|
||||
OntProperty propC = tBox.createOntProperty("http://test.vivo/C");
|
||||
tBox.add(propC, RDF.type, objectProperty);
|
||||
propB.setLabel("property C", "en-US");
|
||||
|
||||
OntProperty propD = tBox.createOntProperty("http://test.vivo/D");
|
||||
tBox.add(propD, RDF.type, objectProperty);
|
||||
propB.setLabel("property D", "en-US");
|
||||
|
||||
// Add the statement "x C y" to the ABox
|
||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
||||
aBox.add(ind_x, propC, ind_y);
|
||||
|
||||
// Add a statement that C is a sub-property of A to the TBox
|
||||
|
||||
propA.addSubProperty(propC);
|
||||
|
||||
// Verify that "x A y" was inferred
|
||||
Statement xAy = ResourceFactory.createStatement(ind_x, propA, ind_y);
|
||||
Assert.assertTrue(inf.contains(xAy));
|
||||
|
||||
// Verify that "x B y" was not inferred
|
||||
Statement xBy = ResourceFactory.createStatement(ind_x, propB, ind_y);
|
||||
Assert.assertFalse(inf.contains(xBy));
|
||||
|
||||
// Verify that "x D y" was not inferred
|
||||
Statement xDy = ResourceFactory.createStatement(ind_x, propD, ind_y);
|
||||
Assert.assertFalse(inf.contains(xDy));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Test the removal of a subPropertyOf statement from
|
||||
* the TBox. The instance data that is the basis
|
||||
* for the inference is in the ABox graph and the
|
||||
* inference graph.
|
||||
*
|
||||
* Since the addition of an owl:equivalentProperty
|
||||
* statement is implemented as two calls to the
|
||||
* method that handles the addition of an
|
||||
* rdfs:subPropertyOf statement, this test serves
|
||||
* as a test of equivalentProperty assertions also.
|
||||
*
|
||||
*/
|
||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
||||
public void removeTBoxSubPropertyAssertion1(){
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
||||
// Add properties A, B, C, D, E, F, G and H to the TBox.
|
||||
// B, C and D are subproperties of A.
|
||||
// E is a subproperty of B.
|
||||
// F and G are subproperties of C.
|
||||
// H is a subproperty of D.
|
||||
|
||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/A");
|
||||
tBox.add(propA, RDF.type, objectProperty);
|
||||
propA.setLabel("property A", "en-US");
|
||||
|
||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/B");
|
||||
tBox.add(propB, RDF.type, objectProperty);
|
||||
propB.setLabel("property B", "en-US");
|
||||
|
||||
OntProperty propC = tBox.createOntProperty("http://test.vivo/C");
|
||||
tBox.add(propC, RDF.type, objectProperty);
|
||||
propB.setLabel("property C", "en-US");
|
||||
|
||||
OntProperty propD = tBox.createOntProperty("http://test.vivo/D");
|
||||
tBox.add(propD, RDF.type, objectProperty);
|
||||
propB.setLabel("property D", "en-US");
|
||||
|
||||
OntProperty propE = tBox.createOntProperty("http://test.vivo/E");
|
||||
tBox.add(propE, RDF.type, objectProperty);
|
||||
propB.setLabel("property E", "en-US");
|
||||
|
||||
OntProperty propF = tBox.createOntProperty("http://test.vivo/F");
|
||||
tBox.add(propF, RDF.type, objectProperty);
|
||||
propB.setLabel("property F", "en-US");
|
||||
|
||||
OntProperty propG = tBox.createOntProperty("http://test.vivo/G");
|
||||
tBox.add(propG, RDF.type, objectProperty);
|
||||
propB.setLabel("property G", "en-US");
|
||||
|
||||
OntProperty propH = tBox.createOntProperty("http://test.vivo/H");
|
||||
tBox.add(propH, RDF.type, objectProperty);
|
||||
propB.setLabel("property H", "en-US");
|
||||
|
||||
propA.addSubProperty(propB);
|
||||
propA.addSubProperty(propC);
|
||||
propA.addSubProperty(propD);
|
||||
propB.addSubProperty(propE);
|
||||
propC.addSubProperty(propF);
|
||||
propC.addSubProperty(propG);
|
||||
propD.addSubProperty(propH);
|
||||
|
||||
// Add the statement "x E y" to the ABox
|
||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
||||
aBox.add(ind_x, propE, ind_y);
|
||||
|
||||
// Remove the statement that B is a subproperty of A from the TBox
|
||||
propA.removeSubProperty(propB);
|
||||
|
||||
// Verify that "x A y" is not in the inference graph
|
||||
Statement xAy = ResourceFactory.createStatement(ind_x, propA, ind_y);
|
||||
Assert.assertFalse(inf.contains(xAy));
|
||||
|
||||
// Verify that "x B y" is in the inference graph
|
||||
Statement xBy = ResourceFactory.createStatement(ind_x, propB, ind_y);
|
||||
Assert.assertTrue(inf.contains(xBy));
|
||||
|
||||
// Add statements "w F z" and "w H z" to the ABox
|
||||
Resource ind_z = aBox.createResource("http://test.vivo/z");
|
||||
Resource ind_w = aBox.createResource("http://test.vivo/w");
|
||||
aBox.add(ind_w, propF, ind_z);
|
||||
aBox.add(ind_w, propH, ind_z);
|
||||
|
||||
// Remove the statement that C is a subproperty of A from the TBox
|
||||
propA.removeSubProperty(propC);
|
||||
|
||||
// Verify that "w A z" is in the inference graph
|
||||
Statement wAz = ResourceFactory.createStatement(ind_w, propA, ind_z);
|
||||
Assert.assertTrue(inf.contains(wAz));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Test computation of mostSpecificType annotations in response
|
||||
* to an added/removed ABox type assertion.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue