NIHVIVO-1755 unit tests for SimpleReasoner - adding some to verify inferencing based on equivalent class
This commit is contained in:
parent
3fa7b24f2a
commit
24d7c25fc7
1 changed files with 129 additions and 1 deletions
|
@ -5,7 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.reasoner;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mindswap.pellet.jena.PelletReasonerFactory;
|
import org.mindswap.pellet.jena.PelletReasonerFactory;
|
||||||
|
|
||||||
|
@ -308,6 +307,135 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test inference based on class equivalence
|
||||||
|
//
|
||||||
|
@Test
|
||||||
|
public void equivClass1(){
|
||||||
|
|
||||||
|
// 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, 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 equivClass2(){
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Test inference based on class equivalence
|
||||||
|
//
|
||||||
|
@Test
|
||||||
|
public void equivClass3(){
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// To help in debugging the unit test
|
// To help in debugging the unit test
|
||||||
void printModels(OntModel ontModel) {
|
void printModels(OntModel ontModel) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue