VIVO-778 Remove Pellet from SimpleReasoner unit tests.

This commit is contained in:
Jim Blake 2014-12-31 14:47:27 -05:00
parent 08efbe2735
commit 51f537f0bc
5 changed files with 519 additions and 575 deletions

View file

@ -6,7 +6,6 @@ import org.apache.log4j.Level;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mindswap.pellet.jena.PelletReasonerFactory;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.ontology.OntModelSpec;
@ -16,10 +15,9 @@ import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.OWL;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
public class SimpleReasonerInversePropertyTest extends AbstractTestClass { public class SimpleReasonerInversePropertyTest extends SimpleReasonerTBoxHelper {
long delay = 50; long delay = 50;
@ -46,21 +44,16 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
* basic scenarios around adding abox data * basic scenarios around adding abox data
* *
* Create a Tbox with property P inverseOf property Q. * Create a Tbox with property P inverseOf property Q.
* Pellet will compute TBox inferences. Add a statement * Add a statement a P b, and verify that b Q a is inferred.
* 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.
* Add a statement c Q d and verify that d Q c
* is inferred.
*/ */
public void addABoxAssertion1(boolean sameAs ) { public void addABoxAssertion1(boolean sameAs ) {
// set up the tbox // set up the tbox
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntProperty P = tBox.createOntProperty("http://test.vivo/P"); OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
P.setLabel("property P", "en-US"); OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); setInverse(P, Q);
Q.setLabel("property Q", "en-US");
P.addInverseOf(Q);
// this is the model to receive abox inferences // this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -109,14 +102,11 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
public void addABoxAssertion2(boolean sameAs ) { public void addABoxAssertion2(boolean sameAs ) {
// set up the tbox // set up the tbox
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty P = tBox.createOntProperty("http://test.vivo/P"); OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
P.setLabel("property P", "en-US"); setInverse(P, Q);
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
Q.setLabel("property Q", "en-US");
P.addInverseOf(Q);
// this is the model to receive abox inferences // this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -153,13 +143,11 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
public void addABoxAssertion3(boolean sameAs) { public void addABoxAssertion3(boolean sameAs) {
// set up the tbox // set up the tbox
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntProperty P = tBox.createOntProperty("http://test.vivo/P"); OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
P.setLabel("property P", "en-US"); OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); setInverse(P, Q);
Q.setLabel("property Q", "en-US");
P.addInverseOf(Q);
// this is the model to receive abox inferences // this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -197,16 +185,13 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
public void addABoxAssertion4( boolean sameAs ) { public void addABoxAssertion4( boolean sameAs ) {
// set up the tbox // set up the tbox
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntProperty P = tBox.createOntProperty("http://test.vivo/P"); OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
P.setLabel("property P", "en-US"); OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty R = tBox.createOntProperty("http://test.vivo/R"); OntProperty R = createObjectProperty(tBox, "http://test.vivo/R", "property R");
R.setLabel("property R", "en-US"); setInverse(P, Q);
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); setInverse(R, Q);
Q.setLabel("property Q", "en-US"); setEquivalent(R, P);
R.addEquivalentProperty(P);
P.addInverseOf(Q);
// this is the model to receive abox inferences // this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -250,15 +235,12 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
public void removedABoxAssertion1(boolean sameAs) { public void removedABoxAssertion1(boolean sameAs) {
// set up the tbox // set up the tbox
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntProperty P = tBox.createOntProperty("http://test.vivo/P"); OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
P.setLabel("property P", "en-US"); OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T");
Q.setLabel("property Q", "en-US"); setInverse(P, Q);
OntProperty T = tBox.createOntProperty("http://test.vivo/T"); setInverse(P, T);
Q.setLabel("property T", "en-US");
P.addInverseOf(Q);
P.addInverseOf(T);
// this is the model to receive abox inferences // this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -307,20 +289,14 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
public void removedABoxAssertion2(boolean sameAs) { public void removedABoxAssertion2(boolean sameAs) {
// set up the tbox // set up the tbox
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntProperty P = tBox.createOntProperty("http://test.vivo/P"); OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
P.setLabel("property P", "en-US"); OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T");
Q.setLabel("property Q", "en-US"); setInverse(P, Q);
OntProperty T = tBox.createOntProperty("http://test.vivo/T"); setInverse(T, Q);
Q.setLabel("property T", "en-US"); setEquivalent(P, T);
P.addInverseOf(Q);
P.addEquivalentProperty(T);
// not clear what these will do
tBox.rebind();
tBox.prepare();
// this is the model to receive abox inferences // this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -360,16 +336,12 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
*/ */
public void removedABoxAssertion3(boolean sameAs) { public void removedABoxAssertion3(boolean sameAs) {
//set up the tbox // set up the tbox
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntProperty P = tBox.createOntProperty("http://test.vivo/P"); OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
P.setLabel("property P", "en-US"); OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); setInverse(P, Q);
Q.setLabel("property Q", "en-US");
P.addInverseOf(Q);
tBox.rebind(); // not sure what effect this has
// this is the model to receive abox inferences // this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -410,12 +382,10 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
*/ */
public void addTBoxInverseAssertion1(boolean sameAs) throws InterruptedException { public void addTBoxInverseAssertion1(boolean sameAs) throws InterruptedException {
// Set up the TBox. // set up the tbox
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntProperty P = tBox.createOntProperty("http://test.vivo/P"); OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
P.setLabel("property P", "en-US"); OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
Q.setLabel("property Q", "en-US");
// this is the model to receive abox inferences // this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -444,7 +414,7 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
// Assert P and Q as inverses and wait for // Assert P and Q as inverses and wait for
// SimpleReasonerTBoxListener thread to end // SimpleReasonerTBoxListener thread to end
Q.addInverseOf(P); setInverse(P, Q);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
@ -473,14 +443,11 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
*/ */
public void removeTBoxInverseAssertion1(boolean sameAs) throws InterruptedException { public void removeTBoxInverseAssertion1(boolean sameAs) throws InterruptedException {
// set up the tbox. // set up the tbox
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty P = tBox.createOntProperty("http://test.vivo/propP"); OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
P.setLabel("property P", "en-US"); setInverse(P, Q);
OntProperty Q = tBox.createOntProperty("http://test.vivo/propQ");
Q.setLabel("property Q", "en-US");
Q.addInverseOf(P);
// this is the model to receive abox inferences // this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -505,7 +472,7 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
// Remove P and Q inverse relationship and wait for // Remove P and Q inverse relationship and wait for
// SimpleReasoner TBox thread to end. // SimpleReasoner TBox thread to end.
Q.removeInverseProperty(P); removeInverse(P, Q);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
@ -532,20 +499,14 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
*/ */
public void recomputeABox1(boolean sameAs) throws InterruptedException { public void recomputeABox1(boolean sameAs) throws InterruptedException {
// set up tbox // set up the tbox
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty P = tBox.createOntProperty("http://test.vivo/propP"); OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
P.setLabel("property P", "en-US"); setInverse(P, Q);
OntProperty Q = tBox.createOntProperty("http://test.vivo/propQ"); OntProperty X = createObjectProperty(tBox, "http://test.vivo/X", "property X");
Q.setLabel("property Q", "en-US"); OntProperty Y = createObjectProperty(tBox, "http://test.vivo/Y", "property Y");
Q.addInverseOf(P); setInverse(X, Y);
OntProperty X = tBox.createOntProperty("http://test.vivo/propX");
P.setLabel("property X", "en-US");
OntProperty Y = tBox.createOntProperty("http://test.vivo/propY");
Q.setLabel("property Y", "en-US");
X.addInverseOf(Y);
// create abox and abox inf model and register simplereasoner // create abox and abox inf model and register simplereasoner
// with abox. // with abox.
@ -565,8 +526,8 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
aBox.add(c,X,d); aBox.add(c,X,d);
Assert.assertTrue(inf.contains(b,Q,a)); Assert.assertTrue(inf.contains(b,Q,a));
Assert.assertTrue(inf.contains(d,Y,c)); Assert.assertTrue(inf.contains(d,Y,c));
inf.remove(b,Q,a); inf.remove(b,Q,a);
inf.remove(d,Y,c); inf.remove(d,Y,c);
@ -581,7 +542,7 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
Assert.assertTrue(inf.contains(b,Q,a)); Assert.assertTrue(inf.contains(b,Q,a));
Assert.assertTrue(inf.contains(d,Y,c)); Assert.assertTrue(inf.contains(d,Y,c));
} }
//==================================== Utility methods ==================== //==================================== Utility methods ====================
SimpleReasonerTBoxListener getTBoxListener(SimpleReasoner simpleReasoner) { SimpleReasonerTBoxListener getTBoxListener(SimpleReasoner simpleReasoner) {
return new SimpleReasonerTBoxListener(simpleReasoner, new Exception().getStackTrace()[1].getMethodName()); return new SimpleReasonerTBoxListener(simpleReasoner, new Exception().getStackTrace()[1].getMethodName());

View file

@ -9,7 +9,6 @@ import org.apache.log4j.Level;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mindswap.pellet.jena.PelletReasonerFactory;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.ontology.OntModelSpec;
@ -23,9 +22,7 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass; public class SimpleReasonerPluginTest extends SimpleReasonerTBoxHelper {
public class SimpleReasonerPluginTest extends AbstractTestClass {
long delay = 50; long delay = 50;
private final static String DEFAULT_NS = "http://vivoweb.org/individual/"; private final static String DEFAULT_NS = "http://vivoweb.org/individual/";
@ -53,7 +50,7 @@ public class SimpleReasonerPluginTest extends AbstractTestClass {
*/ */
@Test @Test
public void test1() { public void test1() {
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntProperty authorInAuthorship = tBox.createObjectProperty(authorInAuthorship_URI); OntProperty authorInAuthorship = tBox.createObjectProperty(authorInAuthorship_URI);
OntProperty linkedAuthor = tBox.createObjectProperty(linkedAuthor_URI); OntProperty linkedAuthor = tBox.createObjectProperty(linkedAuthor_URI);

View file

@ -6,7 +6,6 @@ import org.apache.log4j.Level;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mindswap.pellet.jena.PelletReasonerFactory;
import com.hp.hpl.jena.ontology.AnnotationProperty; import com.hp.hpl.jena.ontology.AnnotationProperty;
import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntClass;
@ -21,10 +20,9 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDF;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
public class SimpleReasonerSameAsTest extends AbstractTestClass { public class SimpleReasonerSameAsTest extends SimpleReasonerTBoxHelper {
long delay = 50; long delay = 50;
private static final String mostSpecificTypePropertyURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType"; private static final String mostSpecificTypePropertyURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType";
@ -43,21 +41,11 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
//*/ //*/
@Test @Test
public void addSameAsABoxAssertion1() { public void addSameAsABoxAssertion1() {
OntModel tBox = createTBoxModel();
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty P = tBox.createObjectProperty("http://test.vivo/P"); OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S");
P.setLabel("property P", "en-US"); OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T");
OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q");
Q.setLabel("property Q", "en-US");
OntProperty S = tBox.createDatatypeProperty("http://test.vivo/");
S.setLabel("property S", "en-US");
OntProperty T = tBox.createDatatypeProperty("http://test.vivo/");
T.setLabel("property T", "en-US");
Literal literal1 = tBox.createLiteral("Literal value 1"); Literal literal1 = tBox.createLiteral("Literal value 1");
Literal literal2 = tBox.createLiteral("Literal value 2"); Literal literal2 = tBox.createLiteral("Literal value 2");
@ -129,21 +117,11 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
*/ */
@Test @Test
public void removeSameAsABoxAssertion1() { public void removeSameAsABoxAssertion1() {
OntModel tBox = createTBoxModel();
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty P = tBox.createObjectProperty("http://test.vivo/P"); OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S");
P.setLabel("property P", "en-US"); OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T");
OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q");
Q.setLabel("property Q", "en-US");
OntProperty S = tBox.createDatatypeProperty("http://test.vivo/data1");
S.setLabel("property S", "en-US");
OntProperty T = tBox.createDatatypeProperty("http://test.vivo/data2");
T.setLabel("property T", "en-US");
Literal literal1 = tBox.createLiteral("Literal value 1"); Literal literal1 = tBox.createLiteral("Literal value 1");
Literal literal2 = tBox.createLiteral("Literal value 2"); Literal literal2 = tBox.createLiteral("Literal value 2");
@ -186,21 +164,11 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
*/ */
@Test @Test
public void addABoxAssertion1() { public void addABoxAssertion1() {
OntModel tBox = createTBoxModel();
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty P = tBox.createObjectProperty("http://test.vivo/P"); OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S");
P.setLabel("property P", "en-US"); OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T");
OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q");
Q.setLabel("property Q", "en-US");
OntProperty S = tBox.createDatatypeProperty("http://test.vivo/");
S.setLabel("property S", "en-US");
OntProperty T = tBox.createDatatypeProperty("http://test.vivo/");
T.setLabel("property T", "en-US");
Literal literal1 = tBox.createLiteral("Literal value 1"); Literal literal1 = tBox.createLiteral("Literal value 1");
Literal literal2 = tBox.createLiteral("Literal value 2"); Literal literal2 = tBox.createLiteral("Literal value 2");
@ -283,21 +251,11 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
*/ */
@Test @Test
public void disabledSameAs() { public void disabledSameAs() {
OntModel tBox = createTBoxModel();
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty P = tBox.createObjectProperty("http://test.vivo/P"); OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S");
P.setLabel("property P", "en-US"); OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T");
OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q");
Q.setLabel("property Q", "en-US");
OntProperty S = tBox.createDatatypeProperty("http://test.vivo/");
S.setLabel("property S", "en-US");
OntProperty T = tBox.createDatatypeProperty("http://test.vivo/");
T.setLabel("property T", "en-US");
Literal literal1 = tBox.createLiteral("Literal value 1"); Literal literal1 = tBox.createLiteral("Literal value 1");
Literal literal2 = tBox.createLiteral("Literal value 2"); Literal literal2 = tBox.createLiteral("Literal value 2");
@ -369,7 +327,7 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
*/ */
@Test @Test
public void addABoxAssertion2() { public void addABoxAssertion2() {
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntProperty desc = tBox.createDatatypeProperty("http://test.vivo/desc"); OntProperty desc = tBox.createDatatypeProperty("http://test.vivo/desc");
desc.setLabel("property desc", "en-US"); desc.setLabel("property desc", "en-US");
@ -403,21 +361,11 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
*/ */
@Test @Test
public void removeABoxAssertion1() { public void removeABoxAssertion1() {
OntModel tBox = createTBoxModel();
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty P = tBox.createObjectProperty("http://test.vivo/P"); OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S");
P.setLabel("property P", "en-US"); OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T");
OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q");
Q.setLabel("property Q", "en-US");
OntProperty S = tBox.createDatatypeProperty("http://test.vivo/");
S.setLabel("property S", "en-US");
OntProperty T = tBox.createDatatypeProperty("http://test.vivo/");
T.setLabel("property T", "en-US");
Literal literal1 = tBox.createLiteral("Literal value 1"); Literal literal1 = tBox.createLiteral("Literal value 1");
Literal literal2 = tBox.createLiteral("Literal value 2"); Literal literal2 = tBox.createLiteral("Literal value 2");
@ -453,18 +401,12 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
*/ */
@Test @Test
public void tBoxInverseAssertion1() throws InterruptedException { public void tBoxInverseAssertion1() throws InterruptedException {
OntModel tBox = createTBoxModel();
// Create TBox, ABox and Inference models and register OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
// the ABox reasoner listeners with the ABox and TBox OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
// Pellet will compute TBox inferences
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"); // Create ABox and Inference models and register
Q.setLabel("property Q", "en-US"); // the ABox reasoner listeners with the ABox and TBox
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -482,7 +424,7 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
aBox.add(a,P,b); aBox.add(a,P,b);
aBox.add(a, OWL.sameAs,b); aBox.add(a, OWL.sameAs,b);
Q.addInverseOf(P); setInverse(Q, P);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
@ -492,8 +434,8 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
Assert.assertTrue(inf.contains(b,OWL.sameAs,a)); Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
Assert.assertTrue(inf.contains(b,P,b)); Assert.assertTrue(inf.contains(b,P,b));
Assert.assertTrue(inf.contains(a,Q,a)); Assert.assertTrue(inf.contains(a,Q,a));
Q.removeInverseProperty(P); removeInverse(Q, P);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
@ -513,19 +455,12 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
* a sameAs individual. * a sameAs individual.
*/ */
//@Test //@Test
public void tBoxTypeAssertion1() throws InterruptedException { public void tBoxTypeAssertion1() {
// Create a Tbox with a simple class hierarchy. B is a subclass of A. // Create a Tbox with a simple class hierarchy. B is a subclass of A.
// Pellet will compute TBox inferences OntModel tBox = createTBoxModel();
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntClass classB = createClass(tBox, "http://test.vivo/B", "class B");
OntClass classA = tBox.createClass("http://test.vivo/A"); addSubclass(classA, classB);
classA.setLabel("class A", "en-US");
OntClass classB = tBox.createClass("http://test.vivo/B");
classB.setLabel("class B", "en-US");
classA.addSubClass(classB);
// this is the model to receive inferences // this is the model to receive inferences
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -560,17 +495,13 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
*/ */
//@Test //@Test
public void tBoxSubclassAssertion1() throws InterruptedException { public void tBoxSubclassAssertion1() throws InterruptedException {
// Create a Tbox with a simple class hierarchy. B is a subclass of A.
//create aBox and tBox, and SimpleReasoner to listen to them OntModel tBox = createTBoxModel();
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
// set up TBox OntClass classB = createClass(tBox, "http://test.vivo/B", "class B");
OntClass classA = tBox.createClass("http://test.vivo/A"); OntClass classC = createClass(tBox, "http://test.vivo/C", "class C");
classA.setLabel("class A", "en-US");
OntClass classB = tBox.createClass("http://test.vivo/B"); //create aBox and SimpleReasoner to listen to them
classB.setLabel("class B", "en-US");
OntClass classC = tBox.createClass("http://test.vivo/C");
classC.setLabel("class C", "en-US");
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -589,17 +520,14 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
aBox.add(c, OWL.sameAs, a); aBox.add(c, OWL.sameAs, a);
// update TBox // update TBox
classA.addSubClass(classB); addSubclass(classA, classB);
// wait for SimpleReasonerTBoxListener thread to end // wait for SimpleReasonerTBoxListener thread to end
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
} }
classB.addSubClass(classC); addSubclass(classB, classC);
classA.addSubClass(classC); // simulate what Pellet would infer, and
// thus what the SimpleReasonerTBoxListener
// would be notified of.
// wait for SimpleReasonerTBoxListener thread to end // wait for SimpleReasonerTBoxListener thread to end
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
@ -620,10 +548,7 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
Assert.assertTrue(inf.contains(c, RDF.type, classA)); Assert.assertTrue(inf.contains(c, RDF.type, classA));
// update TBox // update TBox
classA.removeSubClass(classB); removeSubclass(classA, classB);
classA.removeSubClass(classC); // simulate what Pellet would infer, and
// thus what the SimpleReasonerTBoxListener
// would be notified of.
// wait for SimpleReasonerTBoxListener thread to end // wait for SimpleReasonerTBoxListener thread to end
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
@ -643,8 +568,8 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
Assert.assertTrue(inf.contains(c, RDF.type, classB)); Assert.assertTrue(inf.contains(c, RDF.type, classB));
Assert.assertFalse(inf.contains(c, RDF.type, classA)); Assert.assertFalse(inf.contains(c, RDF.type, classA));
// update TBox // update TBox
classB.removeSubClass(classC); removeSubclass(classB, classC);
// wait for SimpleReasonerTBoxListener thread to end // wait for SimpleReasonerTBoxListener thread to end
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
@ -672,24 +597,19 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
* individuals * individuals
*/ */
//@Test //@Test
public void mostSpecificTypeTest1() throws InterruptedException { public void mostSpecificTypeTest1() {
// Create a Tbox with a simple class hierarchy. B is a subclass of A.
OntModel tBox = createTBoxModel();
OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntClass classC = createClass(tBox, "http://test.vivo/B", "class C");
OntClass classD = createClass(tBox, "http://test.vivo/B", "class D");
OntClass classE = createClass(tBox, "http://test.vivo/B", "class E");
addSubclass(classA, classC);
addSubclass(classC, classD);
addSubclass(classC, classE);
// set up tbox. Pellet is reasoning; SimpleReasonerTBoxListener is not being used. // SimpleReasonerTBoxListener is not being used.
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI); 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);
// this will receive the abox inferences // this will receive the abox inferences
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -755,21 +675,11 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
*/ */
@Test @Test
public void recomputeABox1() throws InterruptedException { public void recomputeABox1() throws InterruptedException {
OntModel tBox = createTBoxModel();
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
OntProperty P = tBox.createObjectProperty("http://test.vivo/P"); OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S");
P.setLabel("property P", "en-US"); OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T");
OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q");
Q.setLabel("property Q", "en-US");
OntProperty S = tBox.createDatatypeProperty("http://test.vivo/");
S.setLabel("property S", "en-US");
OntProperty T = tBox.createDatatypeProperty("http://test.vivo/");
T.setLabel("property T", "en-US");
Literal literal1 = tBox.createLiteral("Literal value 1"); Literal literal1 = tBox.createLiteral("Literal value 1");
Literal literal2 = tBox.createLiteral("Literal value 2"); Literal literal2 = tBox.createLiteral("Literal value 2");

View file

@ -0,0 +1,232 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.reasoner;
import java.util.HashSet;
import java.util.Set;
import com.hp.hpl.jena.ontology.ObjectProperty;
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.ModelFactory;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
/**
* We're using a simple OntModel as the TBox in the SimpleReasoner tests, so we
* don't get tied to a particular TBox reasoner (like Pellet).
*
* But the SimpleReasoner expects certain elementary reasoning, so these methods
* impose that reasoning on the model.
*
* On the model: Thing is a class.
*
* On classes: Every class is equivalent to itself, a subclass of itself, and a
* subclass of Thing. Every class is a subclass of all its ancestors and a
* superclass of all its descendants. Every class has the same superclasses and
* subclasses as do all of its equivalent classes.
*
* On object properties: Every object property is equivalent to itself and a
* subproperty of itself. Every object property has the same inverses as do all
* of its equivalent properties.
*
* ----------------------
*
* It's a little silly to implement this as a parent class of the unit tests. It
* would have been nicer to find a way that is more object-oriented but still
* explicit in what "reasoning" is performed. This will do for now.
*/
public class SimpleReasonerTBoxHelper extends AbstractTestClass {
private static String URI_THING = "http://www.w3.org/2002/07/owl#Thing";
// ----------------------------------------------------------------------
// The model
// ----------------------------------------------------------------------
protected OntModel createTBoxModel() {
OntModel tBox = ModelFactory
.createOntologyModel(OntModelSpec.OWL_DL_MEM);
createClass(tBox, URI_THING, "OWL Thing");
return tBox;
}
// ----------------------------------------------------------------------
// Classes
// ----------------------------------------------------------------------
protected OntClass createClass(OntModel tBox, String uri, String label) {
OntClass s = tBox.createClass(uri);
s.setLabel(label, "en-US");
s.addEquivalentClass(s);
s.addSubClass(s);
thing(tBox).addSubClass(s);
return s;
}
private OntClass thing(OntModel tBox) {
return tBox.getOntClass(URI_THING);
}
/**
* Make sure that you establish subclass relationships before setting
* equivalent classes.
*/
protected void setEquivalent(OntClass c1, OntClass c2) {
setEquivalentClasses(equivalences(c1), equivalences(c2));
setEquivalentClasses(equivalences(c2), equivalences(c1));
c1.addEquivalentClass(c2);
c2.addEquivalentClass(c1);
copySubClasses(c1, c2);
copySubClasses(c2, c1);
copySuperClasses(c1, c2);
copySuperClasses(c2, c1);
}
private void setEquivalentClasses(Set<OntClass> equivalences1,
Set<OntClass> equivalences2) {
for (OntClass c1 : equivalences1) {
for (OntClass c2 : equivalences2) {
c1.addEquivalentClass(c2);
}
}
}
private void copySubClasses(OntClass c1, OntClass c2) {
for (OntClass sub : c1.listSubClasses().toList()) {
c2.addSubClass(sub);
}
}
private void copySuperClasses(OntClass c1, OntClass c2) {
for (OntClass sup : c1.listSuperClasses().toList()) {
c2.addSuperClass(sup);
}
}
private Set<OntClass> equivalences(OntClass c1) {
return new HashSet<OntClass>(c1.listEquivalentClasses().toList());
}
protected void addSubclass(OntClass parent, OntClass child) {
addSubclass(equivalences(parent), equivalences(child));
}
private void addSubclass(Set<OntClass> equivalentParents,
Set<OntClass> equivalentChildren) {
for (OntClass parent : equivalentParents) {
for (OntClass child : equivalentChildren) {
parent.addSubClass(child);
for (OntClass ancestor : parent.listSuperClasses().toList()) {
ancestor.addSubClass(child);
}
for (OntClass descendant : child.listSubClasses().toList()) {
parent.addSubClass(descendant);
}
}
}
}
protected void removeSubclass(OntClass parent, OntClass child) {
removeSubclass(equivalences(parent), equivalences(child));
}
/**
* This has the potential for problems if we set this up:
*
* <pre>
* A -> B -> C
*
* explicit add A -> C
*
* remove A -> B
* </pre>
*
* But why would we do that?
*/
private void removeSubclass(Set<OntClass> equivalentParents,
Set<OntClass> equivalentChildren) {
for (OntClass parent : equivalentParents) {
for (OntClass child : equivalentChildren) {
parent.removeSubClass(child);
for (OntClass ancestor : parent.listSuperClasses().toList()) {
ancestor.removeSubClass(child);
}
for (OntClass descendant : child.listSubClasses().toList()) {
parent.removeSubClass(descendant);
}
}
}
}
// ----------------------------------------------------------------------
// Object properties
// ----------------------------------------------------------------------
protected ObjectProperty createObjectProperty(OntModel tBox, String uri,
String label) {
ObjectProperty p = tBox.createObjectProperty(uri);
p.setLabel(label, "en-US");
p.addEquivalentProperty(p);
p.addSubProperty(p);
return p;
}
protected void setEquivalent(OntProperty p1, OntProperty p2) {
setEquivalentProperty(equivalences(p1), equivalences(p2));
setEquivalentProperty(equivalences(p2), equivalences(p1));
copyInverses(p1, p2);
copyInverses(p2, p1);
}
private void setEquivalentProperty(Set<OntProperty> equivalences1,
Set<OntProperty> equivalences2) {
for (OntProperty p1 : equivalences1) {
for (OntProperty p2 : equivalences2) {
p1.addEquivalentProperty(p2);
}
}
}
private void copyInverses(OntProperty p1, OntProperty p2) {
for (OntProperty inv : p1.listInverse().toList()) {
p2.addInverseOf(inv);
}
}
protected void setInverse(OntProperty p1, OntProperty p2) {
setInverse(equivalences(p1), equivalences(p2));
setInverse(equivalences(p2), equivalences(p1));
}
private void setInverse(Set<OntProperty> equivalences1,
Set<OntProperty> equivalences2) {
for (OntProperty p1 : equivalences1) {
for (OntProperty p2 : equivalences2) {
p1.addInverseOf(p2);
}
}
}
protected void removeInverse(OntProperty p1, OntProperty p2) {
removeInverse(equivalences(p1), equivalences(p2));
removeInverse(equivalences(p2), equivalences(p1));
}
private void removeInverse(Set<OntProperty> equivalences1,
Set<OntProperty> equivalences2) {
for (OntProperty p1 : equivalences1) {
for (OntProperty p2 : equivalences2) {
p1.removeInverseProperty(p2);
}
}
}
private Set<OntProperty> equivalences(OntProperty p) {
return new HashSet<OntProperty>(p.listEquivalentProperties().toSet());
}
}

View file

@ -7,7 +7,6 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.mindswap.pellet.jena.PelletReasonerFactory;
import com.hp.hpl.jena.ontology.AnnotationProperty; import com.hp.hpl.jena.ontology.AnnotationProperty;
import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntClass;
@ -21,11 +20,10 @@ import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDF;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
public class SimpleReasonerTest extends AbstractTestClass { public class SimpleReasonerTest extends SimpleReasonerTBoxHelper {
private static final String mostSpecificTypePropertyURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType"; private static final String mostSpecificTypePropertyURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType";
long delay = 50; long delay = 50;
@ -54,15 +52,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
public void addABoxTypeAssertion1( boolean sameAsEnabled ){ public void addABoxTypeAssertion1( boolean sameAsEnabled ){
// Create a Tbox with a simple class hierarchy. B is a subclass of A. // Create a Tbox with a simple class hierarchy. B is a subclass of A.
// Pellet will compute TBox inferences OntModel tBox = createTBoxModel();
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntClass classB = createClass(tBox, "http://test.vivo/B", "class 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.addSubClass(classB); classA.addSubClass(classB);
// this is the model to receive inferences // this is the model to receive inferences
@ -101,30 +93,18 @@ public class SimpleReasonerTest extends AbstractTestClass {
public void addABoxTypeAssertion2(boolean enableSameAs){ public void addABoxTypeAssertion2(boolean enableSameAs){
// Create a Tbox with a simple class hierarchy. D and E are subclasses // 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. // of C. B and C are subclasses of A.
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntClass classB = createClass(tBox, "http://test.vivo/B", "class B");
OntClass classC = createClass(tBox, "http://test.vivo/C", "class C");
OntClass classD = createClass(tBox, "http://test.vivo/D", "class D");
OntClass classE = createClass(tBox, "http://test.vivo/E", "class E");
addSubclass(classA, classB);
addSubclass(classA, classC);
addSubclass(classC, classD);
addSubclass(classC, classE);
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");
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");
classC.addSubClass(classD);
classC.addSubClass(classE);
classA.addSubClass(classB);
classA.addSubClass(classC);
// this is the model to receive inferences // this is the model to receive inferences
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -159,12 +139,17 @@ public class SimpleReasonerTest extends AbstractTestClass {
* Test inference based on class equivalence * Test inference based on class equivalence
*/ */
public void addABoxTypeAssertion3(boolean enableSameAs) throws InterruptedException { public void addABoxTypeAssertion3(boolean enableSameAs) throws InterruptedException {
// Create TBox, ABox and Inference models and register // Add classes A, B and C to the TBox
// the ABox reasoner listeners with the ABox and TBox // A is equivalent to B
// Pellet will compute TBox inferences // C is a subclass of A
OntModel tBox = createTBoxModel();
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntClass classB = createClass(tBox, "http://test.vivo/B", "class B");
OntClass classC = createClass(tBox, "http://test.vivo/C", "class C");
addSubclass(classA, classC);
setEquivalent(classA, classB);
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -175,22 +160,6 @@ public class SimpleReasonerTest extends AbstractTestClass {
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
tBox.register(simpleReasonerTBoxListener); tBox.register(simpleReasonerTBoxListener);
// 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);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
} }
@ -223,11 +192,13 @@ public class SimpleReasonerTest extends AbstractTestClass {
*/ */
public void addABoxTypeAssertion4(boolean enableSameAs) throws InterruptedException { public void addABoxTypeAssertion4(boolean enableSameAs) throws InterruptedException {
// Create TBox, ABox and Inference models and register // Add classes A and B to the TBox
// the ABox reasoner listeners with the ABox and TBox // A is equivalent to B
// Pellet will compute TBox inferences OntModel tBox = createTBoxModel();
OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntClass classB = createClass(tBox, "http://test.vivo/B", "class B");
setEquivalent(classA, classB);
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -238,17 +209,6 @@ public class SimpleReasonerTest extends AbstractTestClass {
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
tBox.register(simpleReasonerTBoxListener); tBox.register(simpleReasonerTBoxListener);
// 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);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
} }
@ -277,12 +237,14 @@ public class SimpleReasonerTest extends AbstractTestClass {
* Test inference based on class equivalence * Test inference based on class equivalence
*/ */
public void addABoxTypeAssertion5(boolean enableSameAs) throws InterruptedException { public void addABoxTypeAssertion5(boolean enableSameAs) throws InterruptedException {
// Create TBox, ABox and Inference models and register // Add classes classes A and B to the TBox
// the ABox reasoner listeners with the ABox and TBox // A is equivalent to B
// Pellet will compute TBox inferences OntModel tBox = createTBoxModel();
OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntClass classB = createClass(tBox, "http://test.vivo/B", "class B");
setEquivalent(classA, classB);
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -293,17 +255,6 @@ public class SimpleReasonerTest extends AbstractTestClass {
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
tBox.register(simpleReasonerTBoxListener); tBox.register(simpleReasonerTBoxListener);
// 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);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
} }
@ -326,11 +277,11 @@ public class SimpleReasonerTest extends AbstractTestClass {
} }
@Test @Test
public void removeABoxTypeAssertion1Test()throws InterruptedException{ public void removeABoxTypeAssertion1Test() {
removeABoxTypeAssertion1(true); removeABoxTypeAssertion1(true);
} }
@Test @Test
public void removeABoxTypeAssertion1NoSameAs()throws InterruptedException{ public void removeABoxTypeAssertion1NoSameAs() {
removeABoxTypeAssertion1(false); removeABoxTypeAssertion1(false);
} }
/* /*
@ -344,22 +295,15 @@ public class SimpleReasonerTest extends AbstractTestClass {
public void removeABoxTypeAssertion1(boolean enableSameAs){ public void removeABoxTypeAssertion1(boolean enableSameAs){
// Create a Tbox with a simple class hierarchy. C is a subclass of B // 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. // and B is a subclass of A.
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel tBox = createTBoxModel();
OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntClass classA = tBox.createClass("http://test.vivo/A"); OntClass classB = createClass(tBox, "http://test.vivo/B", "class B");
classA.setLabel("class A", "en-US"); OntClass classC = createClass(tBox, "http://test.vivo/C", "class C");
addSubclass(classB, classC);
OntClass classB = tBox.createClass("http://test.vivo/B"); addSubclass(classA, classB);
classB.setLabel("class B", "en-US");
OntClass classC = tBox.createClass("http://test.vivo/C");
classC.setLabel("class C", "en-US");
classB.addSubClass(classC);
classA.addSubClass(classB);
// this is the model to receive inferences // this is the model to receive inferences
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -415,12 +359,15 @@ public class SimpleReasonerTest extends AbstractTestClass {
* as a test of equivalentClass statements also. * as a test of equivalentClass statements also.
*/ */
public void addTBoxSubClassAssertion1(boolean enableSameAs) throws InterruptedException { public void addTBoxSubClassAssertion1(boolean enableSameAs) throws InterruptedException {
// Create the TBox and add classes A, B, C and D
// Create TBox, ABox and Inference models and register OntModel tBox = createTBoxModel();
// the ABox reasoner listeners with the ABox and TBox OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
// Pellet will compute TBox inferences OntClass classB = createClass(tBox, "http://test.vivo/B", "class B");
OntClass classC = createClass(tBox, "http://test.vivo/C", "class C");
OntClass classD = createClass(tBox, "http://test.vivo/D", "class D");
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); // Create ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -431,27 +378,12 @@ public class SimpleReasonerTest extends AbstractTestClass {
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
tBox.register(simpleReasonerTBoxListener); tBox.register(simpleReasonerTBoxListener);
// Add classes classes A, B, C and D to the 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");
OntClass classD = tBox.createClass("http://test.vivo/D");
classD.setLabel("class D", "en-US");
// Add a statement that individual x is of type C to the ABox // Add a statement that individual x is of type C to the ABox
Resource ind_x = aBox.createResource("http://test.vivo/x"); Resource ind_x = aBox.createResource("http://test.vivo/x");
aBox.add(ind_x, RDF.type, classC); aBox.add(ind_x, RDF.type, classC);
// Add a statement that C is a subclass of A to the TBox // Add a statement that C is a subclass of A to the TBox
addSubclass(classA, classC);
classA.addSubClass(classC);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
@ -498,11 +430,17 @@ public class SimpleReasonerTest extends AbstractTestClass {
*/ */
public void addTBoxSubClassAssertion2(boolean enableSameAs) throws InterruptedException { public void addTBoxSubClassAssertion2(boolean enableSameAs) throws InterruptedException {
// Create TBox, ABox and Inference models and register // Create the TBox and add classes A, B, C and D.
// the ABox reasoner listeners with the ABox and TBox // D is a subclass of C.
// Pellet will compute TBox inferences OntModel tBox = createTBoxModel();
OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntClass classB = createClass(tBox, "http://test.vivo/B", "class B");
OntClass classC = createClass(tBox, "http://test.vivo/C", "class C");
OntClass classD = createClass(tBox, "http://test.vivo/D", "class D");
addSubclass(classC, classD);
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); // Create ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -513,23 +451,6 @@ public class SimpleReasonerTest extends AbstractTestClass {
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
tBox.register(simpleReasonerTBoxListener); tBox.register(simpleReasonerTBoxListener);
// Add classes classes A, B, C and D to the TBox
// D is a subclass of C
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");
OntClass classD = tBox.createClass("http://test.vivo/D");
classD.setLabel("class D", "en-US");
classC.addSubClass(classD);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
} }
@ -539,7 +460,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
aBox.add(ind_x, RDF.type, classD); aBox.add(ind_x, RDF.type, classD);
// Add a statement that C is a subclass of A to the TBox // Add a statement that C is a subclass of A to the TBox
classA.addSubClass(classC); addSubclass(classA, classC);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
@ -569,11 +490,30 @@ public class SimpleReasonerTest extends AbstractTestClass {
* *
*/ */
public void removeTBoxSubClassAssertion1(boolean enableSameAs) throws InterruptedException { public void removeTBoxSubClassAssertion1(boolean enableSameAs) throws InterruptedException {
// Create TBox, ABox and Inference models and register // Create the TBox and add classes A, B, C, D, E, F, G and H.
// the ABox reasoner listeners with the ABox and TBox // B, C and D are subclasses of A.
// Pellet will compute TBox inferences // E is a subclass of B.
// F and G are subclasses of C.
// H is a subclass of D.
OntModel tBox = createTBoxModel();
OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntClass classB = createClass(tBox, "http://test.vivo/B", "class B");
OntClass classC = createClass(tBox, "http://test.vivo/C", "class C");
OntClass classD = createClass(tBox, "http://test.vivo/D", "class D");
OntClass classE = createClass(tBox, "http://test.vivo/E", "class E");
OntClass classF = createClass(tBox, "http://test.vivo/F", "class F");
OntClass classG = createClass(tBox, "http://test.vivo/G", "class G");
OntClass classH = createClass(tBox, "http://test.vivo/H", "class H");
addSubclass(classA, classB);
addSubclass(classA, classC);
addSubclass(classA, classD);
addSubclass(classB, classE);
addSubclass(classC, classF);
addSubclass(classC, classG);
addSubclass(classD, classH);
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); // Create ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -584,44 +524,6 @@ public class SimpleReasonerTest extends AbstractTestClass {
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
tBox.register(simpleReasonerTBoxListener); tBox.register(simpleReasonerTBoxListener);
// Add classes A, B, C, D, E, F, G and H to the TBox.
// B, C and D are subclasses of A.
// E is a subclass of B.
// F and G are subclasses of C.
// H is a subclass of D.
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");
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");
OntClass classF = tBox.createClass("http://test.vivo/F");
classF.setLabel("class F", "en-US");
OntClass classG = tBox.createClass("http://test.vivo/G");
classG.setLabel("class G", "en-US");
OntClass classH = tBox.createClass("http://test.vivo/H");
classH.setLabel("class H", "en-US");
classA.addSubClass(classB);
classA.addSubClass(classC);
classA.addSubClass(classD);
classB.addSubClass(classE);
classC.addSubClass(classF);
classC.addSubClass(classG);
classD.addSubClass(classH);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
} }
@ -631,7 +533,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
aBox.add(ind_x, RDF.type, classE); aBox.add(ind_x, RDF.type, classE);
// Remove the statement that B is a subclass of A from the TBox // Remove the statement that B is a subclass of A from the TBox
classA.removeSubClass(classB); removeSubclass(classA, classB);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
@ -664,13 +566,13 @@ public class SimpleReasonerTest extends AbstractTestClass {
simpleReasonerTBoxListener.setStopRequested(); simpleReasonerTBoxListener.setStopRequested();
} }
@Ignore(" needs PelletListener infrastructure which is not in this suite.") @Ignore(" needs TBoxReasoner infrastructure which is not in this suite.")
@Test @Test
public void bcdTest()throws InterruptedException{ public void bcdTest()throws InterruptedException{
bcd(true); bcd(true);
} }
@Ignore(" needs PelletListener infrastructure which is not in this suite.") @Ignore(" needs TBoxReasoner infrastructure which is not in this suite.")
@Test @Test
public void bcdNoSameAsTest()throws InterruptedException{ public void bcdNoSameAsTest()throws InterruptedException{
bcd(false); bcd(false);
@ -682,17 +584,16 @@ public class SimpleReasonerTest extends AbstractTestClass {
* inference graph. * inference graph.
* *
*/ */
// this test would need PelletListener infrastructure, which we're not // this test would need TBoxReasoner infrastructure, which we're not
// testing in this suite. The reason it doesn't work as it is because // testing in this suite. The reason it doesn't work as it is because
// the SimpleReasonerTBoxListener is not listening to the tBox inference // the SimpleReasonerTBoxListener is not listening to the tBox inference
// model as Pellet is updating it. I could simulate it by adding to the // model as the TBoxReasoner is updating it. I could simulate it by adding to the
// tBox assertions what we can count on Pellet to infer. // tBox assertions what we can count on the TBoxReasoner to infer.
public void bcd(boolean enableSameAs) throws InterruptedException { public void bcd(boolean enableSameAs) throws InterruptedException {
// Create TBox, ABox and Inference models and register OntModel tBox = createTBoxModel();
// Create ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox // 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); OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -704,18 +605,11 @@ public class SimpleReasonerTest extends AbstractTestClass {
// Add classes LivingThing, Flora, Brassica to the TBox // Add classes LivingThing, Flora, Brassica to the TBox
// Brassica is a subClass of Flora and Flora is a subclass of Brassica // Brassica is a subClass of Flora and Flora is a subclass of Brassica
OntClass LivingThing = createClass(tBox, "http://test.vivo/LivingThing", "Living Thing");
OntClass LivingThing = tBox.createClass("http://test.vivo/LivingThing"); OntClass Flora = createClass(tBox, "http://test.vivo/Flora", "Flora");
LivingThing.setLabel("Living Thing", "en-US"); OntClass Brassica = createClass(tBox, "http://test.vivo/Brassica", "Brassica");
addSubclass(LivingThing, Flora);
OntClass Flora = tBox.createClass("http://test.vivo/Flora"); addSubclass(Flora, Brassica);
Flora.setLabel("Flora", "en-US");
OntClass Brassica = tBox.createClass("http://test.vivo/Brassica");
Brassica.setLabel("Brassica", "en-US");
LivingThing.addSubClass(Flora);
Flora.addSubClass(Brassica);
tBox.rebind(); tBox.rebind();
tBox.prepare(); tBox.prepare();
@ -761,11 +655,23 @@ public class SimpleReasonerTest extends AbstractTestClass {
* to an added/removed ABox type assertion. * to an added/removed ABox type assertion.
*/ */
public void mstTest1(boolean enableSameAs) throws InterruptedException { public void mstTest1(boolean enableSameAs) throws InterruptedException {
// Create TBox, ABox and Inference models and register // Set up the Tbox with a class hierarchy. C is a subclass of A
// and Y. D and E are subclasses of C. B is a subclass of D.
OntModel tBox = createTBoxModel();
OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntClass classB = createClass(tBox, "http://test.vivo/B", "class B");
OntClass classC = createClass(tBox, "http://test.vivo/C", "class C");
OntClass classD = createClass(tBox, "http://test.vivo/D", "class D");
OntClass classE = createClass(tBox, "http://test.vivo/E", "class E");
OntClass classY = createClass(tBox, "http://test.vivo/Y", "class Y");
addSubclass(classA, classC);
addSubclass(classY, classC);
addSubclass(classC, classD);
addSubclass(classC, classE);
addSubclass(classD, classB);
// Create ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox // 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); OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -776,38 +682,8 @@ public class SimpleReasonerTest extends AbstractTestClass {
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
tBox.register(simpleReasonerTBoxListener); tBox.register(simpleReasonerTBoxListener);
// Set up the Tbox with a class hierarchy. C is a subclass of A
// and Y. D and E are subclasses C. B is a subclass of D.
// Pellet will compute TBox inferences.
AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI); AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI);
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");
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");
OntClass classY = tBox.createClass("http://test.vivo/Y");
classE.setLabel("class Y", "en-US");
classY.addSubClass(classC);
classA.addSubClass(classC);
classC.addSubClass(classD);
classC.addSubClass(classE);
classD.addSubClass(classB);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
} }
@ -848,11 +724,17 @@ public class SimpleReasonerTest extends AbstractTestClass {
* to an added ABox type assertion. * to an added ABox type assertion.
*/ */
public void mstTest2(boolean enableSameAs) throws InterruptedException { public void mstTest2(boolean enableSameAs) throws InterruptedException {
// Create TBox, ABox and Inference models and register // Set up the Tbox with a class hierarchy. A, B, and C are all equivalent.
// This implies that they are all subclasses of each other.
OntModel tBox = createTBoxModel();
OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntClass classB = createClass(tBox, "http://test.vivo/B", "class B");
OntClass classC = createClass(tBox, "http://test.vivo/C", "class C");
setEquivalent(classA, classB);
setEquivalent(classB, classC);
// Create ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox // 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); OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -863,25 +745,8 @@ public class SimpleReasonerTest extends AbstractTestClass {
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
tBox.register(simpleReasonerTBoxListener); tBox.register(simpleReasonerTBoxListener);
// Set up the Tbox with a class hierarchy. B is a subclass of A,
// C is a subclass of B, and A is a subclass of C.
// Pellet should infer these three classes to be equivalent.
AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI); AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI);
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.addSubClass(classB);
classB.addSubClass(classC);
classC.addSubClass(classA);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
} }
@ -911,11 +776,18 @@ public class SimpleReasonerTest extends AbstractTestClass {
* to an added/removed TBox assertions. * to an added/removed TBox assertions.
*/ */
public void mstTest3(boolean enableSameAs) throws InterruptedException { public void mstTest3(boolean enableSameAs) throws InterruptedException {
// Create TBox, ABox and Inference models and register // Set up the Tbox with classes A, B, C, D, E, F and G
OntModel tBox = createTBoxModel();
OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
OntClass classB = createClass(tBox, "http://test.vivo/B", "class B");
OntClass classC = createClass(tBox, "http://test.vivo/C", "class C");
OntClass classD = createClass(tBox, "http://test.vivo/D", "class D");
OntClass classE = createClass(tBox, "http://test.vivo/E", "class E");
OntClass classF = createClass(tBox, "http://test.vivo/F", "class F");
OntClass classG = createClass(tBox, "http://test.vivo/G", "class G");
// Create ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox // 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); OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model inf = ModelFactory.createDefaultModel(); Model inf = ModelFactory.createDefaultModel();
@ -928,30 +800,6 @@ public class SimpleReasonerTest extends AbstractTestClass {
OntClass OWL_THING = tBox.createClass(OWL.Thing.getURI()); OntClass OWL_THING = tBox.createClass(OWL.Thing.getURI());
AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI); AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI);
// Set up the Tbox with classes A, B, C, D,
// E, F and G
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");
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");
OntClass classF = tBox.createClass("http://test.vivo/F");
classF.setLabel("class F", "en-US");
OntClass classG = tBox.createClass("http://test.vivo/G");
classE.setLabel("class G", "en-US");
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
@ -975,17 +823,13 @@ public class SimpleReasonerTest extends AbstractTestClass {
Assert.assertTrue(inf.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI()))); Assert.assertTrue(inf.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
Assert.assertTrue(inf.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classF.getURI()))); Assert.assertTrue(inf.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classF.getURI())));
// Set up a class hierarchy. // Set up a class hierarchy.
// Pellet will compute TBox inferences. addSubclass(classA, classB);
addSubclass(classA, classC);
classA.addSubClass(classB); addSubclass(classA, classD);
classA.addSubClass(classC); addSubclass(classC, classE);
classA.addSubClass(classD); addSubclass(classD, classF);
addSubclass(classD, classG);
classC.addSubClass(classE);
classD.addSubClass(classF);
classD.addSubClass(classG);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);
@ -996,7 +840,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
// If F is removed as a subclass of D, then D should once again be a most specific type // If F is removed as a subclass of D, then D should once again be a most specific type
// for y. // for y.
classD.removeSubClass(classF); removeSubclass(classD, classF);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay); Thread.sleep(delay);