NIHVIVO-2314 add support for property-based inferencing to the SimpleReasoner

This commit is contained in:
stellamit 2011-04-26 18:16:31 +00:00
parent a1e87a10b9
commit 87b87c8edf
2 changed files with 896 additions and 275 deletions

View file

@ -11,6 +11,7 @@ import org.mindswap.pellet.jena.PelletReasonerFactory;
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;
@ -24,17 +25,21 @@ import edu.cornell.mannlib.vitro.webapp.reasoner.support.SimpleReasonerTBoxListe
public class SimpleReasonerTest extends AbstractTestClass {
private Resource objectProperty = ResourceFactory.createResource("http://www.w3.org/2002/07/owl#ObjectProperty");
@Before
public void suppressErrorOutput() {
suppressSyserr();
}
/*
* Test that when an individual is asserted to be of a type,
* its asserted type is not added to the inference graph
*/
@Test
public void addType(){
// Test that when a new instance is asserted, its asserted type is not added to the
// inference graph
public void addABoxTypeAssertion1(){
// Create a Tbox with a simple class hierarchy. B is a subclass of A.
// Pellet will compute TBox inferences
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
@ -50,7 +55,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
// this is the model to receive 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));
@ -64,12 +69,17 @@ public class SimpleReasonerTest extends AbstractTestClass {
// Verify that "x is of type B" was not inferred
Assert.assertFalse(inf.contains(xisb));
}
/*
* Test that when an individual is asserted have a type,
* that inferences are materialized that it has the types
* of its superclasses
*/
@Test
public void addTypes(){
public void addABoxTypeAssertion2(){
// Create a Tbox with a simple class hierarchy. D and E are subclasses of C. B and C are subclasses of A.
// Pellet will compute TBox inferences
// Create a Tbox with a simple class hierarchy. D and E are subclasses
// of C. B and C are subclasses of A. Pellet will compute TBox inferences.
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
OntClass classA = tBox.createClass("http://test.vivo/A");
@ -113,13 +123,150 @@ public class SimpleReasonerTest extends AbstractTestClass {
Assert.assertTrue(inf.contains(xisa));
}
/*
* Test inference based on class equivalence
*/
@Test
public void removeTypes(){
// Create a Tbox with a simple class hierarchy. C is a subclass of B and B is a subclass of A.
public void addABoxTypeAssertion3(){
// 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);
tBox.register(new SimpleReasonerTBoxListener(simpleReasoner));
// Add classes A, B and C to the TBox
// A is equivalent to B
// C is a subclass of A
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");
classA.addEquivalentClass(classB);
classA.addSubClass(classC);
// Add a statement that individual x is of type C to the ABox
Resource ind_x = aBox.createResource("http://test.vivo/x");
aBox.add(ind_x, RDF.type, classC);
// Verify that "x is of type A" was inferred
Statement xisa = ResourceFactory.createStatement(ind_x, RDF.type, classA);
Assert.assertTrue(inf.contains(xisa));
// Verify that "x is of type B" was inferred
Statement xisb = ResourceFactory.createStatement(ind_x, RDF.type, classB);
Assert.assertTrue(inf.contains(xisb));
}
/*
* Test inference based on class equivalence
*/
@Test
public void addABoxTypeAssertion4() {
// 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);
tBox.register(new SimpleReasonerTBoxListener(simpleReasoner));
// Add classes A and B to the TBox
// A is equivalent to B
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");
classA.addEquivalentClass(classB);
// Add a statement that individual x is of type B to the ABox
Resource ind_x = aBox.createResource("http://test.vivo/x");
aBox.add(ind_x, RDF.type, classB);
// Verify that "x is of type A" was inferred
Statement xisa = ResourceFactory.createStatement(ind_x, RDF.type, classA);
Assert.assertTrue(inf.contains(xisa));
}
/*
* Test inference based on class equivalence
*/
@Test
public void addABoxTypeAssertion5() {
// 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);
tBox.register(new SimpleReasonerTBoxListener(simpleReasoner));
// Add classes classes A and B to the TBox
// A is equivalent to B
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");
classA.addEquivalentClass(classB);
// Add a statement that individual x is of type B to the ABox
Resource ind_x = aBox.createResource("http://test.vivo/x");
aBox.add(ind_x, RDF.type, classB);
// Verify that "x is of type A" was inferred
Statement xisa = ResourceFactory.createStatement(ind_x, RDF.type, classA);
Assert.assertTrue(inf.contains(xisa));
// Remove the statement that x is of type B from the ABox
aBox.remove(ind_x, RDF.type, classB);
// Verify that "x is of type A" was removed from the inference graph
Assert.assertFalse(inf.contains(xisa));
}
/*
* Test that when it is retracted that an individual is of a type,
* that the inferences that it is of the type of all superclasses
* of the retracted type are retracted from the inference graph.
* However, any assertions that are otherwise entailed (by the
* TBox, ABox and inference graph minus the retracted type statement)
* should not be retracted.
*/
@Test
public void removeABoxTypeAssertion1(){
// Create a Tbox with a simple class hierarchy. C is a subclass of B
// and B is a subclass of A. Pellet will compute TBox inferences.
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
OntClass classA = tBox.createClass("http://test.vivo/A");
@ -154,14 +301,32 @@ public class SimpleReasonerTest extends AbstractTestClass {
// Verify that the inference graph contains the statement that x is of type A.
Statement xisa = ResourceFactory.createStatement(ind_x, RDF.type, classA);
Assert.assertTrue(inf.contains(xisa));
// Hopefully the assertion that x is b got removed from
// the inference graph
Statement xisb = ResourceFactory.createStatement(ind_x, RDF.type, classB);
Assert.assertFalse(inf.contains(xisb));
}
// This tests added TBox subClassOf and equivalentClass statements.
// The ABox data that will be the basis for the inference will
// be in the ABox graph.
/*
* Test the addition of a subClassOf statement to
* the TBox. The instance data that is the basis
* for the inference is in the ABox. The existing
* instance of the newly declared subclass should
* be inferred to have the type of the superclass.
* There are also a few checks that the instance
* is not inferred to have the types of some other
* random classes.
*
* Since the addition of an owl:equivalentClass
* statement is implemented as two calls to the
* method that handles the addition of an
* rdfs:subClassOf statement, this test serves
* as a test of equivalentClass statements also.
*/
@Test
public void addSubClass1(){
public void addTBoxSubClassAssertion1(){
// Create TBox, ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox
@ -211,12 +376,24 @@ public class SimpleReasonerTest extends AbstractTestClass {
}
// this tests added TBox subClassOf and equivalentClass statements.
// The ABox data that is the basis for the inference will be
// in the inferred graph
/*
* Test the addition of a subClassOf statement to
* the TBox. The instance data that is the basis
* for the inference is in the ABox graph and the
* inference graph. The existing instance of the
* subclass of the newly added subclass should
* be inferred to have the type of the superclass
* of the newly added subclass.
*
* Since the addition of an owl:equivalentClass
* statement is implemented as two calls to the
* method that handles the addition of an
* rdfs:subClassOf statement, this test serves
* as some test of equivalentClass statements also.
*
*/
@Test
public void addSubClass2(){
public void addTBoxSubClassAssertion2() {
// Create TBox, ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox
@ -260,9 +437,23 @@ public class SimpleReasonerTest extends AbstractTestClass {
}
@Test
// this tests incremental reasoning as a result of the removal of a subClassOf
// or equivalentClass statement from the TBox.
public void removeSubClass(){
/*
* Test the removal of a subClassOf statement from
* the TBox. The instance data that is the basis
* for the inference is in the ABox graph and the
* inference graph. The existing instance of the
* subclass of the newly added subclass should
* be inferred to have the type of the superclass
* of the newly added subclass.
*
* Since the addition of an owl:equivalentClass
* statement is implemented as two calls to the
* method that handles the addition of an
* rdfs:subClassOf statement, this test serves
* as a test of equivalentClass assertions also.
*
*/
public void removeTBoxSubClassAssertion1(){
// Create TBox, ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox
// Pellet will compute TBox inferences
@ -323,7 +514,6 @@ public class SimpleReasonerTest extends AbstractTestClass {
// Verify that "x is of type A" is not in the inference graph
Statement xisa = ResourceFactory.createStatement(ind_x, RDF.type, classA);
Assert.assertFalse(inf.contains(xisa));
// Verify that "x is of type B" is in the inference graph
Statement xisb = ResourceFactory.createStatement(ind_x, RDF.type, classB);
@ -340,13 +530,14 @@ public class SimpleReasonerTest extends AbstractTestClass {
// Verify that "y is of type A" is in the inference graph
Statement yisa = ResourceFactory.createStatement(ind_y, RDF.type, classA);
Assert.assertTrue(inf.contains(yisa));
}
// Test inference based on class equivalence
//
/*
* tests rdfs:subPropertyOf materialization for object properties.
*/
@Test
public void equivClass1(){
public void addABoxAssertion1(){
// Create TBox, ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox
@ -360,40 +551,130 @@ public class SimpleReasonerTest extends AbstractTestClass {
aBox.register(simpleReasoner);
tBox.register(new SimpleReasonerTBoxListener(simpleReasoner));
// Add classes classes A, B and C to the TBox
// 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
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);
tBox.register(new SimpleReasonerTBoxListener(simpleReasoner));
// 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
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);
tBox.register(new SimpleReasonerTBoxListener(simpleReasoner));
// Add properties A, B and C to the TBox
// A is equivalent to B
// C is a subclass of A
OntClass classA = tBox.createClass("http://test.vivo/A");
classA.setLabel("class A", "en-US");
OntProperty propA = tBox.createOntProperty("http://test.vivo/A");
tBox.add(propA, RDF.type, objectProperty);
propA.setLabel("property A", "en-US");
OntClass classB = tBox.createClass("http://test.vivo/B");
classB.setLabel("class B", "en-US");
OntProperty propB = tBox.createOntProperty("http://test.vivo/B");
tBox.add(propB, RDF.type, objectProperty);
propB.setLabel("property B", "en-US");
OntClass classC = tBox.createClass("http://test.vivo/C");
classC.setLabel("class C", "en-US");
OntProperty propC = tBox.createOntProperty("http://test.vivo/C");
tBox.add(propC, RDF.type, objectProperty);
propC.setLabel("property C", "en-US");
classA.addEquivalentClass(classB);
classA.addSubClass(classC);
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");
aBox.add(ind_x, RDF.type, classC);
// Verify that "x is of type A" was inferred
Statement xisa = ResourceFactory.createStatement(ind_x, RDF.type, classA);
Assert.assertTrue(inf.contains(xisa));
Resource ind_y = aBox.createResource("http://test.vivo/y");
// Verify that "x is of type B" was inferred
Statement xisb = ResourceFactory.createStatement(ind_x, RDF.type, classB);
Assert.assertTrue(inf.contains(xisb));
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));
}
// Test inference based on class equivalence
//
/*
* The sub-property is not of the same type as the super
* property so no inference should be materialized.
*/
@Test
public void equivClass2(){
public void addABoxAssertion5(){
// Create TBox, ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox
@ -407,31 +688,35 @@ public class SimpleReasonerTest extends AbstractTestClass {
aBox.register(simpleReasoner);
tBox.register(new SimpleReasonerTBoxListener(simpleReasoner));
// Add classes classes A and B to the TBox
// A is equivalent to B
// Add object properties propA and propB to the TBox.
// propB is a sub-property of propA.
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");
classA.addEquivalentClass(classB);
OntProperty propA = tBox.createOntProperty("http://test.vivo/propA");
tBox.add(propA, RDF.type, objectProperty);
propA.setLabel("propA", "en-US");
// Add a statement that individual x is of type B to the ABox
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");
aBox.add(ind_x, RDF.type, classB);
// Verify that "x is of type A" was inferred
Statement xisa = ResourceFactory.createStatement(ind_x, RDF.type, classA);
Assert.assertTrue(inf.contains(xisa));
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 class equivalence
//
/*
* Test inference based on property equivalence
*/
@Test
public void equivClass3(){
public void addABoxAssertion6() {
// Create TBox, ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox
@ -445,31 +730,203 @@ public class SimpleReasonerTest extends AbstractTestClass {
aBox.register(simpleReasoner);
tBox.register(new SimpleReasonerTBoxListener(simpleReasoner));
// Add classes classes A and B to the TBox
// Add properties A and B to the TBox
// A is equivalent to B
OntClass classA = tBox.createClass("http://test.vivo/A");
classA.setLabel("class A", "en-US");
OntProperty propA = tBox.createOntProperty("http://test.vivo/A");
tBox.add(propA, RDF.type, objectProperty);
propA.setLabel("property A", "en-US");
OntClass classB = tBox.createClass("http://test.vivo/B");
classB.setLabel("class B", "en-US");
OntProperty propB = tBox.createOntProperty("http://test.vivo/B");
tBox.add(propB, RDF.type, objectProperty);
propB.setLabel("property B", "en-US");
classA.addEquivalentClass(classB);
propA.addEquivalentProperty(propB);
// Add a statement that individual x is of type B to the ABox
// Add the statement x B y to the ABox
Resource ind_x = aBox.createResource("http://test.vivo/x");
aBox.add(ind_x, RDF.type, classB);
Resource ind_y = aBox.createResource("http://test.vivo/y");
aBox.add(ind_x, propB, ind_y);
// Verify that "x is of type A" was inferred
Statement xisa = ResourceFactory.createStatement(ind_x, RDF.type, classA);
Assert.assertTrue(inf.contains(xisa));
// 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 is of type B from the ABox
aBox.remove(ind_x, RDF.type, classB);
// 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(xisa));
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
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);
tBox.register(new SimpleReasonerTBoxListener(simpleReasoner));
// 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
/*
* 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.
*
*/
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);
tBox.register(new SimpleReasonerTBoxListener(simpleReasoner));
// 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));
}
@ -480,5 +937,5 @@ public class SimpleReasonerTest extends AbstractTestClass {
System.out.println("---------------------------------------------------");
ontModel.writeAll(System.out,"N3",null);
}
}
}